From patchwork Thu Jan 17 15:37:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Bunt X-Patchwork-Id: 31095 Received: (qmail 72309 invoked by alias); 17 Jan 2019 15:38:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 72300 invoked by uid 89); 17 Jan 2019 15:38:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, MIME_BASE64_BLANKS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=vary, reliance, prime, junior X-HELO: EUR04-DB3-obe.outbound.protection.outlook.com Received: from mail-eopbgr60056.outbound.protection.outlook.com (HELO EUR04-DB3-obe.outbound.protection.outlook.com) (40.107.6.56) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 17 Jan 2019 15:38:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G4XJPgWy3jW9F+SGOHwy9qNmu3ylgMvYGSnWldtMOpg=; b=AuPEXKVjIC6B4SuuY/ZbUCBw7VYUl72StK3vwlBXAAjYJS/XQEUluqOvOhfxl61ldIqsIZ2M4D04fNeQmpcXae3IDb57OCX0DKveOGXSrcI3/Xr6ZkiCcOtXRr7yqxTaG4Ra+PWSD/GIxSn4bbrlWUy5NsbAddZ3piH7uDWHWhE= Received: from VI1PR08MB3200.eurprd08.prod.outlook.com (52.133.15.152) by VI1PR08MB3375.eurprd08.prod.outlook.com (20.177.58.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Thu, 17 Jan 2019 15:37:57 +0000 Received: from VI1PR08MB3200.eurprd08.prod.outlook.com ([fe80::1018:106:3294:4220]) by VI1PR08MB3200.eurprd08.prod.outlook.com ([fe80::1018:106:3294:4220%4]) with mapi id 15.20.1516.019; Thu, 17 Jan 2019 15:37:57 +0000 From: Richard Bunt To: "gdb-patches@sourceware.org" CC: nd Subject: [PATCH v2] gdbserver short-circuit-argument-list failures Date: Thu, 17 Jan 2019 15:37:57 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Richard.Bunt@arm.com; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) Content-ID: <5395C645AAF24C4A986017D77F6D515C@eurprd08.prod.outlook.com> MIME-Version: 1.0 X-IsSubscribed: yes This patch fixes test case failures observed when running short-circuit-argument-list.exp with gdb server boards. Thanks to Sergio Durigan Junior for pointing this out. Assertions failed with the native{,-extended}-gdbserver boards as the standard output from the test program appears in a different location than observed on non-gdbserver boards. This standard output was used to determine whether a function, which had been logically short-circuited, was called or not. Since the location of the standard out cannot be relied upon to verify this, a new mechanism was needed. The test program now records function calls in variables named the same as the function with a "_called" suffix. These variables can then be queried from the test case to verify the occurrence of a call. A method to reset the call counts has been included in the test case, so that any future assertions added to this test can ensure a fresh set of initial values before proceeding. Not resetting values between groups of assertions creates a dependency between them, which increases the likelihood that a single failure causes subsequent assertions to fail. Regression tested on x86_64, aarch64 and ppc64le. Regression tested with Ada on x86_64. Regression tested with the native{,-extended}-gdbserver boards on x86_64. gdb/testsuite/ChangeLog: 2018-12-03 Richard Bunt * gdb.fortran/short-circuit-argument-list.exp: Remove reliance on user program standard output. * gdb.fortran/short-circuit-argument-list.f90: Record function calls. --- .../gdb.fortran/short-circuit-argument-list.exp | 75 ++++++++++++++++------ .../gdb.fortran/short-circuit-argument-list.f90 | 33 ++++++++-- 2 files changed, 82 insertions(+), 26 deletions(-) -- 2.7.4 diff --git a/gdb/testsuite/gdb.fortran/short-circuit-argument-list.exp b/gdb/testsuite/gdb.fortran/short-circuit-argument-list.exp index 739df97d0b973dac21c97fddf6b32a1e059139fe..c2fb69044e8e55e22920777a1b9677f5d20eed23 100644 --- a/gdb/testsuite/gdb.fortran/short-circuit-argument-list.exp +++ b/gdb/testsuite/gdb.fortran/short-circuit-argument-list.exp @@ -30,6 +30,20 @@ if {![runto [gdb_get_line_number "post_truth_table_init"]]} then { continue } +# Non-zero value to use as the function call count base. Using zero is avoided +# as this is a common value in memory. +set prime 17 + +# Reset all call counts to the initial value ($prime). +proc reset_called_flags { } { + global prime + foreach counter {no_arg no_arg_false one_arg two_arg array} { + gdb_test_no_output "set var calls%function_${counter}_called=$prime" + } +} + +reset_called_flags + # Vary conditional and input over the standard truth table. # Test that the debugger can evaluate expressions of the form # a(x,y) .OR./.AND. a(a,b) correctly. @@ -49,31 +63,42 @@ foreach_with_prefix arg {"No" "One" "Two"} { set trimmed_args [string trimright $argument_list ,] set arg_lower [string tolower $arg] gdb_test "p function_no_arg_false() .OR. function_${arg_lower}_arg($trimmed_args)" \ - " $arg, return true.\r\n\\\$$decimal = .TRUE." - # Check the skipped function has not printed anything by asserting the - # absence of the full stop from its message. + " = .TRUE." + reset_called_flags gdb_test "p .TRUE. .OR. function_${arg_lower}_arg($trimmed_args)" \ - "\[^.\]\r\n\\\$$decimal = .TRUE." + " = .TRUE." + # Check that none of the short-circuited functions have been called. + gdb_test "p calls" \ + " = \\\( function_no_arg_called = $prime, function_no_arg_false_called = $prime, function_one_arg_called = $prime, function_two_arg_called = $prime, function_array_called = $prime \\\)" append argument_list " .TRUE.," } -# Check nested calls -gdb_test "p function_one_arg(.FALSE. .OR. function_no_arg())" \ - " No, return true.\r\n One, return true.\r\n\\\$$decimal = .TRUE." +with_test_prefix "nested call not skipped" { + reset_called_flags + # Check nested calls + gdb_test "p function_one_arg(.FALSE. .OR. function_no_arg())" \ + " = .TRUE." + gdb_test "p calls" \ + " = \\\( function_no_arg_called = [expr $prime + 1], function_no_arg_false_called = $prime, function_one_arg_called = [expr $prime + 1], function_two_arg_called = $prime, function_array_called = $prime \\\)" +} -gdb_test "p function_one_arg(.TRUE. .OR. function_no_arg())" \ - "\[^.\]\r\n One, return true.\r\n\\\$$decimal = .TRUE." +with_test_prefix "nested call skipped" { + gdb_test "p function_one_arg(.TRUE. .OR. function_no_arg())" \ + " = .TRUE." + gdb_test "p calls" \ + " = \\\( function_no_arg_called = [expr $prime + 1], function_no_arg_false_called = $prime, function_one_arg_called = [expr $prime + 2], function_two_arg_called = $prime, function_array_called = $prime \\\)" +} # Vary number of components in the expression to skip. set expression "p .TRUE." foreach_with_prefix expression_components {1 2 3 4} { set expression "$expression .OR. function_one_arg(.TRUE.)" gdb_test "$expression" \ - "\\\$$decimal = .TRUE." + " = .TRUE." } # Check parsing skipped substring operations. -gdb_test "p .TRUE. .OR. binary_string(1)" "\\\$$decimal = .TRUE." +gdb_test "p .TRUE. .OR. binary_string(1)" " = .TRUE." # Check parsing skipped substring operations with ranges. These should all # return true as the result is > 0. @@ -82,7 +107,7 @@ gdb_test "p .TRUE. .OR. binary_string(1)" "\\\$$decimal = .TRUE." foreach_with_prefix range1 {"1:2" ":" ":2" "1:"} { foreach_with_prefix range2 {"1:2" ":" ":2" "1:"} { gdb_test "p .TRUE. .OR. binary_string($range1) .OR. binary_string($range2)" \ - "\\\$$decimal = .TRUE." + " = .TRUE." } } @@ -90,17 +115,25 @@ foreach_with_prefix range1 {"1:2" ":" ":2" "1:"} { foreach_with_prefix range1 {"1:2" ":" ":2" "1:"} { foreach_with_prefix range2 {"1:2" ":" ":2" "1:"} { gdb_test "p .TRUE. .OR. binary_string($range1) .OR. truth_table($range2, 1)" \ - "\\\$$decimal = .TRUE." + " = .TRUE." } } # Check evaluation of substring operations in logical expressions. -gdb_test "p .FALSE. .OR. binary_string(1)" "\\\$$decimal = .FALSE." - -# Function call and substring skip. -gdb_test "p .TRUE. .OR. function_one_arg(binary_string(1))" \ - "\\\$$decimal = .TRUE." +gdb_test "p .FALSE. .OR. binary_string(1)" " = .FALSE." + +with_test_prefix "binary string skip" { + reset_called_flags + # Function call and substring skip. + gdb_test "p .TRUE. .OR. function_one_arg(binary_string(1))" \ + " = .TRUE." + gdb_test "p calls%function_one_arg_called" " = $prime" +} -# Function call and array skip. -gdb_test "p .TRUE. .OR. function_array(binary_string)" \ - "\\\$$decimal = .TRUE." +with_test_prefix "array skip" { + # Function call and array skip. + reset_called_flags + gdb_test "p .TRUE. .OR. function_array(binary_string)" \ + " = .TRUE." + gdb_test "p calls%function_array_called" " = $prime" +} diff --git a/gdb/testsuite/gdb.fortran/short-circuit-argument-list.f90 b/gdb/testsuite/gdb.fortran/short-circuit-argument-list.f90 index 7c1c917d87ff035e68dc5f488b431544e07bf9e3..d2ce55f46898f2f45d8a4106b3317836386010a2 100644 --- a/gdb/testsuite/gdb.fortran/short-circuit-argument-list.f90 +++ b/gdb/testsuite/gdb.fortran/short-circuit-argument-list.f90 @@ -15,36 +15,59 @@ ! Source code for short-circuit-argument-list.exp. +module called_state + implicit none + type called_counts + integer :: function_no_arg_called = 0 + integer :: function_no_arg_false_called = 0 + integer :: function_one_arg_called = 0 + integer :: function_two_arg_called = 0 + integer :: function_array_called = 0 + end type + type(called_counts) :: calls +end module called_state + logical function function_no_arg() - print *, "No, return true." + use called_state + implicit none + calls%function_no_arg_called = calls%function_no_arg_called + 1 function_no_arg = .TRUE. end function function_no_arg logical function function_no_arg_false() + use called_state + implicit none + calls%function_no_arg_false_called = calls%function_no_arg_false_called + 1 function_no_arg_false = .FALSE. end function function_no_arg_false logical function function_one_arg(x) + use called_state + implicit none logical, intent(in) :: x - print *, "One, return true." + calls%function_one_arg_called = calls%function_one_arg_called + 1 function_one_arg = .TRUE. end function function_one_arg logical function function_two_arg(x, y) + use called_state + implicit none logical, intent(in) :: x, y - print *, "Two, return true." + calls%function_two_arg_called = calls%function_two_arg_called + 1 function_two_arg = .TRUE. end function function_two_arg logical function function_array(logical_array) + use called_state + implicit none logical, dimension(4,2), target, intent(in) :: logical_array logical, dimension(:,:), pointer :: p - p => logical_array - print *, "Array, return true.", p(1,1), logical_array(1,1) + calls%function_array_called = calls%function_array_called + 1 function_array = .TRUE. end function function_array program generate_truth_table + use called_state implicit none interface logical function function_no_arg()