[gdb/testsuite] Make gdb.dwarf2/dwzbuildid.exp more robust
authorTom de Vries <tdevries@suse.de>
Fri, 8 Sep 2023 10:27:02 +0000 (12:27 +0200)
committerTom de Vries <tdevries@suse.de>
Fri, 8 Sep 2023 10:27:02 +0000 (12:27 +0200)
I ran test-case gdb.dwarf2/dwzbuildid.exp with target board cc-with-gdb-index,
and noticed that compilation failure for one exec prohibited testing of all
execs.

Fix this by restructuring the test-case, such that we have:
...
PASS: gdb.dwarf2/dwzbuildid.exp: testname=ok: set debug-file-directory
PASS: gdb.dwarf2/dwzbuildid.exp: testname=ok: print the_int
UNSUPPORTED: gdb.dwarf2/dwzbuildid.exp: testname=mismatch: compilation failed
UNSUPPORTED: gdb.dwarf2/dwzbuildid.exp: testname=fallback: compilation failed
...

Tested on x86_64-linux.

gdb/testsuite/gdb.dwarf2/dwzbuildid.exp

index 81cefc60dfc6c63091c19931b891a770aee44dc0..76e3a7d6e4260d261f5be958069f5598a3f3ff83 100644 (file)
@@ -134,46 +134,46 @@ for {set i 2} {$i <= 8} {incr i} {
 # Copy a file into the .build-id place for the "fallback" test.
 file copy -force -- ${binfile}8.o $basedir/$ok_prefix/$ok_suffix2.debug
 
-# Link the executables.
-if {[gdb_compile [list ${binfile}1.o ${binfile}2.o] ${binfile}-ok \
-        executable {}] != ""} {
-    return -1
-}
-
-if {[gdb_compile [list ${binfile}1.o ${binfile}4.o] ${binfile}-mismatch \
-        executable {quiet}] != ""} {
-    return -1
-}
+proc do_test {} {
+    clean_restart
 
-if {[gdb_compile [list ${binfile}1.o ${binfile}6.o] ${binfile}-fallback \
-        executable {}] != ""} {
-    return -1
-}
+    gdb_test_no_output "set debug-file-directory $::debugdir" \
+       "set debug-file-directory"
 
+    gdb_load ${::binfile}-${::testname}
 
-foreach testname {ok mismatch fallback} {
-    with_test_prefix $testname {
-       clean_restart
+    if { $::testname == "mismatch" && [readnow] } {
+       # Main is found in the minimal symbols.  When using readnow, a
+       # failure to read the dwarf also causes the minimal symbols to be
+       # unavailable.
+       # Setup a kfail for "FAIL: gdb_breakpoint: set breakpoint at main".
+       setup_kfail "symtab/26797" *-*-*
+    }
+    if {![runto_main]} {
+       return
+    }
 
-       gdb_test_no_output "set debug-file-directory $debugdir" \
-           "set debug-file-directory"
+    if {$::testname == "mismatch"} {
+       gdb_test "print the_int" \
+           "(No symbol table is loaded|No symbol \"the_int\" in current context).*"
+    } else {
+       gdb_test "print the_int" " = 99"
+    }
+}
 
-       gdb_load ${binfile}-${testname}
+foreach_with_prefix testname { ok mismatch fallback } {
+    if { $testname == "ok" } {
+       set objs [list ${binfile}1.o ${binfile}2.o]
+    } elseif { $testname == "mismatch" } {
+       set objs [list ${binfile}1.o ${binfile}4.o]
+    } elseif { $testname == "fallback" } {
+       set objs [list ${binfile}1.o ${binfile}6.o]
+    }
 
-       if { $testname == "mismatch" && [readnow] } {
-           # Main is found in the minimal symbols.  When using readnow, a
-           # failure to read the dwarf also causes the minimal symbols to be
-           # unavailable.
-           # Setup a kfail for "FAIL: gdb_breakpoint: set breakpoint at main".
-           setup_kfail "symtab/26797" *-*-*
-       }
-       if {[runto_main]} {
-           if {$testname == "mismatch"} {
-               gdb_test "print the_int" \
-                   "(No symbol table is loaded|No symbol \"the_int\" in current context).*"
-           } else {
-               gdb_test "print the_int" " = 99"
-           }
-       }
+    if {[gdb_compile $objs ${binfile}-$testname executable {quiet}] != ""} {
+       unsupported "compilation failed"
+       continue
     }
+
+    do_test
 }