# zero means to take the child's branch; a pid means to take the
# parent's branch.
-# First set gdb to follow the child.
-# The result should be that each of the 4 forks returns zero.
-
-clean_restart ${binfile}
-runto_main
-gdb_test_no_output "set follow-fork child"
-continue_to_exit_bp_loc
-
-gdb_test "print pids" "\\$.* = \\{0, 0, 0, 0\\}.*" "follow child, print pids"
-
-# Now set gdb to follow the parent.
-# Result should be that none of the 4 forks returns zero.
-
-clean_restart ${binfile}
-runto_main
-gdb_test_no_output "set follow-fork parent" ""
-continue_to_exit_bp_loc
-
-gdb_test "print pids\[0\]==0 || pids\[1\]==0 || pids\[2\]==0 || pids\[3\]==0" \
- " = 0" "follow parent, print pids"
+foreach mode { "child" "parent" } {
+ clean_restart ${binfile}
+ runto_main
+
+ gdb_test_no_output "set follow-fork $mode"
+ with_test_prefix "follow $mode" {
+ continue_to_exit_bp_loc
+
+ set test "print pids"
+ if { $mode eq "child" } {
+ # Gdb is set to follow the child.
+ # The result should be that each of the 4 forks returns zero.
+ gdb_test "print pids" "\\$.* = \\{0, 0, 0, 0\\}.*" $test
+ } else {
+ # Gdb is set to follow the parent.
+ # Result should be that none of the 4 forks returns zero.
+ set val \
+ [join [list \
+ "pids\[0\]==0" \
+ "pids\[1\]==0" \
+ "pids\[2\]==0" \
+ "pids\[3\]==0"] " || "]
+ gdb_test "print $val" " = 0" $test
+ }
+ }
+}
#
# Now test with detach-on-fork off.