Home | History | Annotate | Line # | Download | only in gdb.base
signals-state-child.exp revision 1.1.1.2
      1  1.1.1.2  christos # Copyright 2016-2017 Free Software Foundation, Inc.
      2      1.1  christos 
      3      1.1  christos # This program is free software; you can redistribute it and/or modify
      4      1.1  christos # it under the terms of the GNU General Public License as published by
      5      1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6      1.1  christos # (at your option) any later version.
      7      1.1  christos #
      8      1.1  christos # This program is distributed in the hope that it will be useful,
      9      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11      1.1  christos # GNU General Public License for more details.
     12      1.1  christos #
     13      1.1  christos # You should have received a copy of the GNU General Public License
     14      1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15      1.1  christos 
     16      1.1  christos # Test that gdb's (or gdbserver's) own signal handling does not
     17      1.1  christos # interfere with the signal actions (dispositions, etc.) and mask
     18      1.1  christos # their spawned children inherit.
     19      1.1  christos #
     20      1.1  christos # - If gdb inherits some signal set to SIG_IGN, so should the
     21      1.1  christos #   inferior, even if gdb itself chooses not to ignore the signal.
     22      1.1  christos #
     23      1.1  christos # - If gdb inherits some signal set to SIG_DFL, so should the inferior
     24      1.1  christos #   even if gdb itself ignores that signal.
     25      1.1  christos #
     26      1.1  christos # This requires special support in gdb/gdbserver because the exec
     27      1.1  christos # family of functions does not reset the signal disposition of signals
     28      1.1  christos # that are set to SIG_IGN, nor signal masks and flags.
     29      1.1  christos 
     30      1.1  christos standard_testfile
     31      1.1  christos 
     32      1.1  christos if {![is_remote host] && ![is_remote target]} {
     33      1.1  christos     set gdb_txt [standard_output_file gdb.txt]
     34      1.1  christos     set standalone_txt [standard_output_file standalone.txt]
     35      1.1  christos     set purely_local 1
     36      1.1  christos } else {
     37      1.1  christos     set gdb_txt gdb.txt
     38      1.1  christos     set standalone_txt standalone.txt
     39      1.1  christos     set purely_local 0
     40      1.1  christos }
     41      1.1  christos 
     42      1.1  christos remote_file host delete $gdb_txt
     43      1.1  christos remote_file host delete $standalone_txt
     44      1.1  christos remote_file target delete $gdb_txt
     45      1.1  christos remote_file target delete $standalone_txt
     46      1.1  christos 
     47      1.1  christos set options [list debug "additional_flags=-DOUTPUT_TXT=\"$gdb_txt\""]
     48      1.1  christos if {[build_executable $testfile.exp $testfile $srcfile $options]} {
     49  1.1.1.2  christos     untested "failed to compile"
     50      1.1  christos     return -1
     51      1.1  christos }
     52      1.1  christos 
     53      1.1  christos set options [list debug "additional_flags=-DOUTPUT_TXT=\"$standalone_txt\""]
     54      1.1  christos if {[build_executable $testfile.exp $testfile-standalone $srcfile $options]} {
     55  1.1.1.2  christos     untested "failed to compile"
     56      1.1  christos     return -1
     57      1.1  christos }
     58      1.1  christos 
     59      1.1  christos # Run the program directly, and dump its initial signal actions and
     60      1.1  christos # mask in "standalone.txt".
     61      1.1  christos 
     62      1.1  christos # Use remote_spawn instead of remote_exec, like how we spawn gdb.
     63      1.1  christos # This is in order to take the same code code paths in dejagnu
     64      1.1  christos # compared to when running the program through gdb.  E.g., because
     65      1.1  christos # local_exec uses -ignore SIGHUP, while remote_spawn does not, if we
     66      1.1  christos # used remote_exec, the test program would start with SIGHUP ignored
     67      1.1  christos # when run standalone, but not when run through gdb.
     68      1.1  christos set res [remote_spawn target "$binfile-standalone"]
     69      1.1  christos if { $res < 0 || $res == "" } {
     70      1.1  christos     untested "spawning $binfile-standalone failed"
     71      1.1  christos     return 1
     72      1.1  christos } else {
     73      1.1  christos     pass "collect standalone signals state"
     74      1.1  christos }
     75      1.1  christos remote_close target
     76      1.1  christos 
     77      1.1  christos # Now run the program through gdb, and dump its initial signal actions
     78      1.1  christos # and mask in "gdb.txt".
     79      1.1  christos 
     80      1.1  christos clean_restart $binfile
     81      1.1  christos 
     82      1.1  christos if { ! [ runto_main ] } then {
     83  1.1.1.2  christos     untested "failed to compile"
     84      1.1  christos     return -1
     85      1.1  christos }
     86      1.1  christos 
     87      1.1  christos gdb_continue_to_end "collect signals state under gdb"
     88      1.1  christos 
     89      1.1  christos if {!$purely_local} {
     90      1.1  christos     # Copy file from target to host through build.
     91      1.1  christos     remote_download host [remote_upload target gdb.txt] gdb.txt
     92      1.1  christos     remote_download host [remote_upload target standalone.txt] standalone.txt
     93      1.1  christos }
     94      1.1  christos 
     95      1.1  christos # Diff the .txt files.  They should be identical.
     96      1.1  christos gdb_test "shell diff -s $standalone_txt $gdb_txt" \
     97      1.1  christos     "Files .* are identical.*" \
     98      1.1  christos     "signals states are identical"
     99