public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] gdbserver short-circuit-argument-list failures
@ 2019-01-17 15:38 Richard Bunt
  2019-02-08 11:10 ` Richard Bunt
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Bunt @ 2019-01-17 15:38 UTC (permalink / raw)
  To: gdb-patches; +Cc: nd

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  <richard.bunt@arm.com>

	* 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(-)

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()
-- 
2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] gdbserver short-circuit-argument-list failures
  2019-01-17 15:38 [PATCH v2] gdbserver short-circuit-argument-list failures Richard Bunt
@ 2019-02-08 11:10 ` Richard Bunt
  2019-02-14 22:45   ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Bunt @ 2019-02-08 11:10 UTC (permalink / raw)
  To: gdb-patches; +Cc: nd

Polite ping.

On 1/17/19 3:37 PM, Richard Bunt wrote:
> 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  <richard.bunt@arm.com>
> 
> 	* 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(-)
> 
> 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()
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] gdbserver short-circuit-argument-list failures
  2019-02-08 11:10 ` Richard Bunt
@ 2019-02-14 22:45   ` Tom Tromey
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2019-02-14 22:45 UTC (permalink / raw)
  To: Richard Bunt; +Cc: gdb-patches, nd

>>>>> "Richard" == Richard Bunt <Richard.Bunt@arm.com> writes:

Richard> Polite ping.

Thank you.  This patch is ok.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-14 22:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-17 15:38 [PATCH v2] gdbserver short-circuit-argument-list failures Richard Bunt
2019-02-08 11:10 ` Richard Bunt
2019-02-14 22:45   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).