]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb testsuite: Introduce allow_fork_tests and use it throughout
authorPedro Alves <pedro@palves.net>
Thu, 1 Jun 2023 15:19:03 +0000 (16:19 +0100)
committerPedro Alves <pedro@palves.net>
Wed, 11 Jun 2025 14:03:25 +0000 (15:03 +0100)
Cygwin debugging does not support follow fork.  There is currently no
interface between the debugger and the Cygwin runtime to be able to
intercept forks and execs.  Consequently, testcases that try to
exercise fork/exec all FAIL, and several hit long cascading timeouts.

Add a new allow_fork_tests procedure, meant to be used with require,
and sprinkle it throughout testcases that exercise fork.

Note that some tests currently are skipped on targets other than
Linux, with something like:

 # Until "set follow-fork-mode" and "catch vfork" are implemented on
 # other targets...
 #
 if {![istarget "*-linux*"]} {
     continue
 }

However, some BSD ports also support fork debugging nowadays, and the
testcases were never adjusted...  That is why the new allow_fork_tests
procedure doesn't look for linux.

With this patch, on Cygwin, I get this:

 $ make check TESTS="*/*fork*.exp"

 ...
 === gdb Summary ===

 # of expected passes            6
 # of untested testcases         1
 # of unsupported tests          31

Reviewed-By: Keith Seitz <keiths@redhat.com>
Change-Id: I0c5e8c574d1f61b28d370c22a0b0b6bc3efaf978

37 files changed:
gdb/testsuite/gdb.base/catch-fork-kill.exp
gdb/testsuite/gdb.base/catch-fork-static.exp
gdb/testsuite/gdb.base/catch-signal-fork.exp
gdb/testsuite/gdb.base/foll-fork-syscall.exp
gdb/testsuite/gdb.base/foll-fork.exp
gdb/testsuite/gdb.base/foll-vfork.exp
gdb/testsuite/gdb.base/fork-no-detach-follow-child-dlopen.exp
gdb/testsuite/gdb.base/fork-print-inferior-events.exp
gdb/testsuite/gdb.base/fork-running-state.exp
gdb/testsuite/gdb.base/inferior-died.exp
gdb/testsuite/gdb.base/interrupt-daemon.exp
gdb/testsuite/gdb.base/jit-elf-fork.exp
gdb/testsuite/gdb.base/multi-forks.exp
gdb/testsuite/gdb.base/pie-fork.exp
gdb/testsuite/gdb.base/step-over-exit.exp
gdb/testsuite/gdb.base/vfork-follow-parent.exp
gdb/testsuite/gdb.base/watch-before-fork.exp
gdb/testsuite/gdb.base/watch-vfork.exp
gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp
gdb/testsuite/gdb.rocm/fork-exec-gpu-to-non-gpu.exp
gdb/testsuite/gdb.rocm/fork-exec-non-gpu-to-gpu.exp
gdb/testsuite/gdb.rocm/precise-memory-fork.exp
gdb/testsuite/gdb.threads/foll-fork-other-thread.exp
gdb/testsuite/gdb.threads/fork-child-threads.exp
gdb/testsuite/gdb.threads/fork-plus-threads.exp
gdb/testsuite/gdb.threads/fork-thread-pending.exp
gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.exp
gdb/testsuite/gdb.threads/next-fork-exec-other-thread.exp
gdb/testsuite/gdb.threads/next-fork-other-thread.exp
gdb/testsuite/gdb.threads/pending-fork-event-detach-ns.exp
gdb/testsuite/gdb.threads/pending-fork-event-detach.exp
gdb/testsuite/gdb.threads/vfork-follow-child-exec.exp
gdb/testsuite/gdb.threads/vfork-follow-child-exit.exp
gdb/testsuite/gdb.threads/vfork-multi-inferior.exp
gdb/testsuite/gdb.threads/vfork-multi-thread.exp
gdb/testsuite/gdb.threads/watchpoint-fork.exp
gdb/testsuite/lib/gdb.exp

index 0fd853b90857226c33ccc9e9c9780277960bc925..224a8dfec89a7daf2ff22c260a095f3d032e1b38 100644 (file)
@@ -32,6 +32,8 @@
 
 standard_testfile
 
+require allow_fork_tests
+
 # Build two programs -- one for fork, and another for vfork.
 set testfile_fork "${testfile}-fork"
 set testfile_vfork "${testfile}-vfork"
index b171a6dbdd2737b89d4305a52639e2af14e4dfac..9d50d5dc4284fbfe66c2958b580d6b9c19561f4d 100644 (file)
@@ -21,9 +21,7 @@
 # ld.so probes before reaching main, and ptrace flags were set then.  But a
 # static executable would just keep running and never catch the fork.
 
-# Until "catch fork" is implemented on other targets...
-#
-require {is_any_target "*-*-linux*" "*-*-openbsd*"}
+require allow_fork_tests
 
 # Reusing foll-fork.c since it's a simple forking program.
 standard_testfile foll-fork.c
index dea0cc48f758330e24e86ba51b04392f67bbdc3a..2a33ee19f60e4fe7438f6f7fbb6c23c7ab55e04f 100644 (file)
@@ -14,6 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 require {!target_info exists gdb,nosignals}
+require allow_fork_tests
 
 standard_testfile
 
index 4aee683c8d180c177a9147bf2e8c1e8e821697bf..21ef3347dc111d1207c123729758868d533e4bff 100644 (file)
@@ -20,6 +20,7 @@
 # enabled because it will be redirected to the log.
 require !gdb_debug_enabled
 require {is_any_target "i?86-*-*" "x86_64-*-*"}
+require allow_fork_tests
 
 standard_testfile
 
index 94755c61186afed6593dbf199afb611c2297d6cd..12db516d58af090211486f45081eaaf316792743 100644 (file)
@@ -17,6 +17,8 @@
 # enabled as it will be redirected to the log.
 require !gdb_debug_enabled
 
+require allow_fork_tests
+
 standard_testfile
 
 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
index 266df46a188e4eae9ec095b06b65976364d413e0..6ca7711fe8113a775796c389efa23f097ab71145 100644 (file)
 # either execs or exits --- since those events take somewhat different
 # code paths in GDB, both variants are exercised.
 
-# Until "set follow-fork-mode" and "catch vfork" are implemented on
-# other targets...
-#
-if {![istarget "*-linux*"]} {
-    continue
-}
+require allow_fork_tests
 
 standard_testfile .c -exit.c vforked-prog.c
 
index 311d7ba62deec6d11d1cf00337c067cb98466bae..2d47d5d2c203d7eb96ae7340e712d57a503adf90 100644 (file)
@@ -23,6 +23,7 @@
 # in the source of the shlib, and "list" should display the source where
 # the program stopped.
 
+require allow_fork_tests
 require allow_shlib_tests
 
 standard_testfile .c -shlib.c
index 26ed2f9765dc2b8de2b1795474bf8db54b149eb4..19ace001b08668138f156cb87bb23f2cf9190640 100644 (file)
@@ -19,6 +19,8 @@
 # inferior-events [on,off]', 'set follow-fork-mode [child,parent]' and
 # 'set detach-on-fork [on,off]' are the correct ones.
 
+require allow_fork_tests
+
 # This test relies on "run", so it cannot run on target remote stubs.
 require !use_gdb_stub
 
index 4b810a65648b9c5dcf6537d42faf78c4b3d7b884..c446800b885fe11eb395838c80baeffcaeea6be6 100644 (file)
@@ -17,6 +17,8 @@
 # in non-stop).  GDB used to miss updating the parent/child running
 # states after a fork.
 
+require allow_fork_tests
+
 standard_testfile
 
 # The test proper.
index 3992561d64ef248f3ab6dc0f6253c523352784af..764a88da8c2882084b8868b7407fadb6fa80ada2 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Until "set follow-fork-mode" and "catch fork" are implemented on
-# other targets...
-#
-require {istarget "*-*-linux*"}
+require allow_fork_tests
 
 require support_displaced_stepping
 
index 161f854ed365e62cd1cbb48bea5bec3975479678..8b8c61d6fc9fe4a1747edc1366a6220595a7f96a 100644 (file)
@@ -16,6 +16,8 @@
 # Make sure that we can interrupt an inferior that forks and moves to
 # its own session.
 
+require allow_fork_tests
+
 standard_testfile
 
 if {[build_executable "failed to build" $testfile $srcfile {debug}]} {
index 81d335024490d8af529ff1ff7001554cec485919..c1fa42833625fdd3e1f5a803f26803290a2fab84 100644 (file)
@@ -15,6 +15,7 @@
 
 # Test fork handling of an inferior that has JIT-ed objfiles.
 
+require allow_fork_tests
 require allow_shlib_tests
 
 load_lib jit-elf-helpers.exp
index 61a240f6cc00fedf69ca9137cef5d371c71e22d4..3facccb6315c08ccc27daaeebc40967a8f04355c 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Until "set follow-fork-mode" and "catch fork" are implemented on
-# other targets...
-#
-require {istarget "*-*-linux*"}
-
+require allow_fork_tests
 
 standard_testfile .c
 
index 48c01d9885e078f0d5be32316927a2e9c626910c..86407b4adad3fee641003f9f1df06a3a86a96e0a 100644 (file)
@@ -16,6 +16,8 @@
 # Test that we can follow forks properly when the executable is
 # position-independent.
 
+require allow_fork_tests
+
 standard_testfile
 
 set opts [list debug pie]
index 2370f973622496d9b0ef71a4210d339efde05063..6dfa7bbb2194645dea622e3fc9dca9206877ff10 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-standard_testfile
-
 # Test a thread is doing step-over a syscall instruction which is exit,
 # and GDBserver should cleanup its state of step-over properly.
 
+# The testcase relies on follow-fork-mode child.
+require allow_fork_tests
+
+standard_testfile
+
 set syscall_insn ""
 
 # Define the syscall instruction for each target.
index fca2993bf0819d935be10a256e2c048f2e98e2ce..8cb785d6c828f39cd197bbf7a368fc0c92fa4fc8 100644 (file)
@@ -19,6 +19,8 @@
 # schedule-multiple on" or "set detach-on-fork on".  Test these two resolution
 # methods.
 
+require allow_fork_tests
+
 standard_testfile .c vforked-prog.c
 
 set binfile ${testfile}-exit
index 074cfbd43664a0ee1438ad481eae666486874df1..509561ea7f4a4d10c30b8ee2a53606618fc8ad69 100644 (file)
@@ -20,6 +20,8 @@
 # This test uses "awatch".
 require allow_hw_watchpoint_access_tests
 
+require allow_fork_tests
+
 standard_testfile
 
 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
index 1bc61bcd19725970255c263d08440c30163391da..503727dbbae3601f1b36145f34c69fc3b1090496 100644 (file)
@@ -17,6 +17,8 @@
 
 standard_testfile .c
 
+require allow_fork_tests
+
 if { [build_executable ${testfile}.exp ${testfile} $srcfile {debug}] } {
     untested "failed to compile"
     return -1
index 70c3da93d4a3e84f4bbcad6204fd7f855ac2dc77..3446296e3fb47741aad70c980326f740055c631d 100644 (file)
@@ -17,6 +17,8 @@
 # watchpoints don't end up with stale locations, preventing resumption
 # of other inferiors.
 
+require allow_fork_tests
+
 standard_testfile
 
 if {[build_executable "failed to build" $testfile $srcfile {debug}]} {
index 7588525081c7a6a88d68308b1a99e1cf8da3a142..22d4b75caa0474d4af1460281c4b6178a387846b 100644 (file)
@@ -21,6 +21,7 @@
 load_lib rocm.exp
 
 require allow_hipcc_tests
+require allow_fork_tests
 
 standard_testfile -execer.cpp -execee.cpp
 
index a6bcf69aa3e3e16507c045330a073b88471dddfb..13860993bdea32811fd810d319e854c9ca3836f1 100644 (file)
@@ -20,6 +20,7 @@
 load_lib rocm.exp
 
 require allow_hipcc_tests
+require allow_fork_tests
 
 standard_testfile -execer.cpp -execee.cpp
 
index d326c2ec55b7007d30fadcd23edf21bbe618191d..23c1ebe6249f3a104d9a9f6aebe4d403d28a7b05 100644 (file)
@@ -21,6 +21,7 @@
 load_lib rocm.exp
 
 require allow_hipcc_tests
+require allow_fork_tests
 
 standard_testfile .c
 
index 52459886a7ad658a39da766011f6461070ec5b5d..8ab540c98c4b4e72ee15e3f52f0e21698d640709 100644 (file)
@@ -17,6 +17,8 @@
 # another thread, in different combinations of "set follow-fork
 # parent/child", and other execution modes.
 
+require allow_fork_tests
+
 standard_testfile
 
 # Line where to stop the main thread.
index abe9769b2de60d1c26f5f56ad61003b3ef7ab0cb..ba9dfc241f6c9f0a2f2609ecc57d1433dffb2777 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Only GNU/Linux is known to support `set follow-fork-mode child'.
-if { ! [istarget "*-*-linux*"] } {
-    return 0
-}
+require allow_fork_tests
 
 standard_testfile
 
index 3a5e66adada76f9a9667a0986e23d99733e83580..4ce88d33293bcca1f81037822df4af42ce6febb1 100644 (file)
@@ -20,6 +20,8 @@
 #
 # See https://sourceware.org/bugzilla/show_bug.cgi?id=18600
 
+require allow_fork_tests
+
 # In remote mode, we cannot continue debugging after all
 # inferiors have terminated, and this test requires that.
 if { [target_info exists gdb_protocol]
index d0a1ca182a3b193be76d1421e8a87693eb05f5bf..538e1ca6f3fbd077714ab43825caf40d8db9ed19 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Only GNU/Linux is known to support `set follow-fork-mode child'.
-#
-if { ! [istarget "*-*-linux*"] } {
-    return 0
-}
+require allow_fork_tests
 
 standard_testfile
 
index 1f768983a453a8728f5676cbf1c9e6b4f819b809..c668a6555226f983dabf88bfaf36c8bec9e0cc56 100644 (file)
@@ -16,6 +16,8 @@
 # This test verifies that several threads forking while another thread
 # is constantly stepping over a breakpoint is properly handled.
 
+require allow_fork_tests
+
 standard_testfile
 
 set linenum [gdb_get_line_number "set break here"]
index bd814382626f9915809ddfc2355070ead1bda6f6..3a971274784253c13f37c83da97ec284266709bf 100644 (file)
@@ -25,6 +25,8 @@
 # 20.04.5 LTS with 32-bit kernel + 32-bit userland.  It was NOT reproducible
 # using a circa 2023 Raspberry Pi OS w/ 64-bit kernel and 32-bit userland.
 
+require allow_fork_tests
+
 standard_testfile
 
 # Line where to stop the main thread.
index 183fda6dd6e6fdf68e286c4e7689adab1c096ba2..1cd6685215c4d14a7ef353d3c458782129374169 100644 (file)
@@ -16,6 +16,8 @@
 # Test doing a "next" on a thread during which forks or vforks happen in other
 # threads.
 
+require allow_fork_tests
+
 standard_testfile
 
 # Line where to stop the main thread.
index e6e311eee0009b9c24209709c97de28424939cf5..29a011e1a7ddfd68015b0054917e3b3d61a5c774 100644 (file)
@@ -29,6 +29,8 @@
 #     parent thread from waitpid'ing it, preventing the main thread from joining
 #     it, prevent it from writing the flag file, failing the test.
 
+require allow_fork_tests
+
 standard_testfile
 
 if { [is_remote target] } {
index 8e77ab0ca7c03080f275cdb87dffda41041a9a6d..e627241caed46fb902663f609b60e516e252dfdd 100644 (file)
@@ -34,6 +34,8 @@
 # event, and erroneously create a new inferior for it.  Once fixed, the child
 # process' thread is hidden by whoever holds the pending fork event.
 
+require allow_fork_tests
+
 standard_testfile .c -touch-file.c
 
 set touch_file_bin $binfile-touch-file
index e23db0a616bbdfeadaf7450d115c011f987ee9ee..0b95a75c132647d3b32ee7f6672cd03f05c7a01b 100644 (file)
@@ -16,6 +16,8 @@
 # Test following a vfork child that execs, when the vfork parent is a
 # threaded program, and it's a non-main thread that vforks.
 
+require allow_fork_tests
+
 standard_testfile
 
 if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}]} {
index a6b7f49627688a81eadc83911a4bf64b163031cf..ced52dfa964643fdd48b915644a6929badd71447 100644 (file)
@@ -16,6 +16,8 @@
 # Test following a vfork child that exits, when the vfork parent is a
 # threaded program, and it's a non-main thread that vforks.
 
+require allow_fork_tests
+
 standard_testfile
 
 if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}]} {
index fd081b3764e8a52accaaebc2df45f258c36feff2..d552039a400cf41e8d55250e23544233a0579821 100644 (file)
@@ -25,6 +25,8 @@
 # To catch the bug, this test verifies that we can hit a breakpoint after a
 # vfork call, while a second inferior runs in the background.
 
+require allow_fork_tests
+
 require !use_gdb_stub
 
 standard_testfile .c -sleep.c
index 2b9294d894f83393ac6af59152ad40ec12609972..61811aed7250572da2aeb38eb00ff6de9377382b 100644 (file)
@@ -30,6 +30,8 @@
 # breakpoints are removed, so the main thread would miss the breakpoint and run
 # until exit.
 
+require allow_fork_tests
+
 standard_testfile
 
 if { [build_executable "failed to prepare" ${testfile} ${srcfile} {debug pthreads}] } {
index 376ca2ab54b0713fabc92f7356cef588d2714fc6..8e9b1c33c9bc9eea14e028f054427d7eae849fa0 100644 (file)
@@ -21,6 +21,8 @@
 # must be done before starting the test so as to not disrupt the execution
 # of the actual test.
 
+require allow_fork_tests
+
 set allow_hw_watchpoint_tests_p [allow_hw_watchpoint_tests]
 
 set testfile watchpoint-fork
index 5cc7e11287b244b49b959fe015154a8344347d30..669068536e9b8056e0d646d690736565e6740204 100644 (file)
@@ -5095,6 +5095,22 @@ proc skip_inline_var_tests {} {
     return 0
 }
 
+# Return whether we allow running fork-related testcases.  Targets
+# that don't even have any concept of fork will just fail to compile
+# the testcases and skip the tests that way if this returns true for
+# them.  Unix targets that do have a fork system call, but don't
+# support intercepting forks will want to return false here, otherwise
+# the testcases that exercise fork may hit a number of long cascading
+# time out sequences.
+
+proc allow_fork_tests {} {
+    if {[istarget "*-*-cygwin*"] || [istarget "*-*-mingw*"]} {
+       return 0
+    }
+
+    return 1
+}
+
 # Return a 1 if we should run tests that require hardware breakpoints
 
 proc allow_hw_breakpoint_tests {} {