Discussion:
[PATCH] gdbserver short-circuit-argument-list failures
Richard Bunt
2018-12-07 11:14:24 UTC
Permalink
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 module 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 "reset_called_flags" has also been added to the test program, so
that any future assertions added to this test can ensure a fresh set of
zeros before proceeding.

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 <***@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 | 50 +++++++++++++++-------
.../gdb.fortran/short-circuit-argument-list.f90 | 33 +++++++++++---
2 files changed, 63 insertions(+), 20 deletions(-)

diff --git a/gdb/testsuite/gdb.fortran/short-circuit-argument-list.exp b/gdb/testsuite/gdb.fortran/short-circuit-argument-list.exp
index 1b948bb19d289e5327cb2caa3bf665e33cd6d98d..7032dbeea2eb487c5b98713bbf1c2b9807b692c9 100644
--- a/gdb/testsuite/gdb.fortran/short-circuit-argument-list.exp
+++ b/gdb/testsuite/gdb.fortran/short-circuit-argument-list.exp
@@ -49,20 +49,32 @@ 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.
+ "\\\$$decimal = .TRUE."
+ gdb_test "p reset_called_flags()" "VOID"
gdb_test "p .TRUE. .OR. function_${arg_lower}_arg($trimmed_args)" \
- "\[^.\]\r\n\\\$$decimal = .TRUE."
+ "\\\$$decimal = .TRUE."
+ # Check that none of the short-circuited functions have been called.
+ gdb_test "p function_no_arg_called" "0"
+ gdb_test "p function_one_arg_called" "0"
+ gdb_test "p function_two_arg_called" "0"
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" {
+ gdb_test "p reset_called_flags()" "VOID"
+ # Check nested calls
+ gdb_test "p function_one_arg(.FALSE. .OR. function_no_arg())" \
+ "\\\$$decimal = .TRUE."
+ gdb_test "p function_no_arg_called" "1"
+ gdb_test "p function_one_arg_called" "1"
+}

-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())" \
+ "\\\$$decimal = .TRUE."
+ gdb_test "p function_no_arg_called" "1"
+ gdb_test "p function_one_arg_called" "2"
+}

# Vary number of components in the expression to skip.
set expression "p .TRUE."
@@ -97,10 +109,18 @@ foreach_with_prefix range1 {"1:2" ":" ":2" "1:"} {
# 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."
+with_test_prefix "binary string skip" {
+ gdb_test "p reset_called_flags()" "VOID"
+ # Function call and substring skip.
+ gdb_test "p .TRUE. .OR. function_one_arg(binary_string(1))" \
+ "\\\$$decimal = .TRUE."
+ gdb_test "p function_one_arg_called" "0"
+}

-# 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.
+ gdb_test "p reset_called_flags()" "VOID"
+ gdb_test "p .TRUE. .OR. function_array(binary_string)" \
+ "\\\$$decimal = .TRUE."
+ gdb_test "p function_array_called" "0"
+}
diff --git a/gdb/testsuite/gdb.fortran/short-circuit-argument-list.f90 b/gdb/testsuite/gdb.fortran/short-circuit-argument-list.f90
index 5d8b9c73a705c598b513fd85a8d710c7a7dabebf..bd1f94ad6db3c43135c9aa4476d33e694fb52405 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_flags
+ implicit none
+ 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
+contains
+ subroutine reset_called_flags
+ function_no_arg_called = 0
+ function_no_arg_false_called = 0
+ function_one_arg_called = 0
+ function_two_arg_called = 0
+ function_array_called = 0
+ end subroutine reset_called_flags
+end module called_flags
+
logical function function_no_arg()
- print *, "No, return true."
+ use called_flags
+ function_no_arg_called = function_no_arg_called + 1
function_no_arg = .TRUE.
end function function_no_arg

logical function function_no_arg_false()
+ use called_flags
+ function_no_arg_false_called = 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_flags
logical, intent(in) :: x
- print *, "One, return true."
+ function_one_arg_called = function_one_arg_called + 1
function_one_arg = .TRUE.
end function function_one_arg

logical function function_two_arg(x, y)
+ use called_flags
logical, intent(in) :: x, y
- print *, "Two, return true."
+ function_two_arg_called = function_two_arg_called + 1
function_two_arg = .TRUE.
end function function_two_arg

logical function function_array(logical_array)
+ use called_flags
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)
+ function_array_called = function_array_called + 1
function_array = .TRUE.
end function function_array

program generate_truth_table
+ use called_flags
implicit none
interface
logical function functi

Loading...