binutils-gdb/gdb/testsuite/gdb.fortran/short-circuit-argument-list.f90
Richard Bunt 7b63ad86ab gdbserver short-circuit-argument-list failures
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.
2019-03-04 15:08:51 +00:00

101 lines
3.3 KiB
Fortran

! Copyright 2018-2019 Free Software Foundation, Inc.
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/> .
! 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()
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
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
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
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()
end function function_no_arg
logical function function_no_arg_false()
end function
logical function function_one_arg(x)
logical, intent(in) :: x
end function
logical function function_two_arg(x, y)
logical, intent(in) :: x, y
end function
logical function function_array(logical_array)
logical, dimension(4,2), target, intent(in) :: logical_array
end function function_array
end interface
logical, dimension (4,2) :: truth_table
logical :: a, b, c, d, e
character(2) :: binary_string
binary_string = char(0) // char(1)
truth_table = .FALSE.
truth_table(3:4,1) = .TRUE.
truth_table(2::2,2) = .TRUE.
a = function_no_arg() ! post_truth_table_init
b = function_no_arg_false()
c = function_one_arg(b)
d = function_two_arg(a, b)
e = function_array(truth_table)
print *, truth_table(:, 1), a, b, e
print *, truth_table(:, 2), c, d
end program generate_truth_table