aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.gdb
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2022-10-02 15:31:16 +0100
committerAndrew Burgess <aburgess@redhat.com>2022-10-19 12:15:08 +0100
commit5ac37f0643aac9faefc3873056f4f2b7df06b46f (patch)
treefd7769db6b428a1bdb39233394fba0d5b1bc3862 /gdb/testsuite/gdb.gdb
parent536ff91bb8ea90c98737571f85827ce6770324c9 (diff)
downloadfsf-binutils-gdb-5ac37f0643aac9faefc3873056f4f2b7df06b46f.zip
fsf-binutils-gdb-5ac37f0643aac9faefc3873056f4f2b7df06b46f.tar.gz
fsf-binutils-gdb-5ac37f0643aac9faefc3873056f4f2b7df06b46f.tar.bz2
gdb/testsuite: avoid temporary file in gdb/testsuite (unittest.exp)
I spotted that the gdb.gdb/unittest.exp script causes a temporary file inserters_extractors-2.txt to be created in build/gdb/testsuite/ instead of in build/gdb/testsuite/output/gdb.gdb/unittest/. This is because some of the 'maint selftest' tests create temporary files in GDB's current directory, specifically, the two source files: gdb/unittests/basic_string_view/inserters/wchar_t/2.cc gdb/unittests/basic_string_view/inserters/char/2.cc both create a temporary file called inserters_extractors-2.txt, though we only run the second of these as part of GDB's selftests. I initially proposed just using GDB's 'cd' command in unittest.exp to switch to the test output directory before running the selftests, however, Pedro pointed out that there was a risk here that, if GDB crashed during shutdown, the generated core file would be left in the test output directory rather than in the testsuite directory. As a result, our clever core file spotting logic would fail to spot the core file and alert the user. Instead, I propose this slightly more involved solution. I've added a new with_gdb_cwd directory proc, used like this: with_gdb_cwd $directory { # Tests here... } The new proc temporarily switches to $directory and then runs the tests within the block. After running the tests the previous current working directory is restored. Additionally, after switching back to the previous cwd, we check that GDB is still responsive. This means that if GDB crashed immediately prior to restoring the previous directory, and left the core file in the wrong place, then the responsiveness check will fail, and a FAIL will be emitted, this should be enough to alert the user that something has gone wrong. With this commit in place the unittest.exp script now leaves its temporary file in the test output directory.
Diffstat (limited to 'gdb/testsuite/gdb.gdb')
-rw-r--r--gdb/testsuite/gdb.gdb/unittest.exp46
1 files changed, 27 insertions, 19 deletions
diff --git a/gdb/testsuite/gdb.gdb/unittest.exp b/gdb/testsuite/gdb.gdb/unittest.exp
index 2967b99..fdae7a2 100644
--- a/gdb/testsuite/gdb.gdb/unittest.exp
+++ b/gdb/testsuite/gdb.gdb/unittest.exp
@@ -40,26 +40,34 @@ proc run_selftests { binfile } {
clean_restart ${binfile}
}
+ # Some of the selftests create temporary files in GDB's current
+ # directory. So, while running the selftests, switch to the
+ # test's output directory to avoid leaving clutter in the
+ # gdb/testsuite root directory.
+ set dir [standard_output_file ""]
set enabled 1
- set test "maintenance selftest"
- gdb_test_multiple $test $test {
- -re ".*Running selftest \[^\n\r\]+\." {
- # The selftests can take some time to complete. To prevent
- # timeout spot the 'Running ...' lines going past, so long as
- # these are produced quickly enough then the overall test will
- # not timeout.
- exp_continue
- }
- -re "Ran ($decimal) unit tests, ($decimal) failed\r\n$gdb_prompt $" {
- set num_ran $expect_out(1,string)
- set num_failed $expect_out(2,string)
- gdb_assert "$num_ran > 0" "$test, ran some tests"
- gdb_assert "$num_failed == 0" "$test, failed none"
- }
- -re "Selftests have been disabled for this build.\r\n$gdb_prompt $" {
- unsupported $test
- set num_ran 0
- set enabled 0
+ set num_ran 0
+ with_gdb_cwd $dir {
+ set test "maintenance selftest"
+ gdb_test_multiple $test $test {
+ -re ".*Running selftest \[^\n\r\]+\." {
+ # The selftests can take some time to complete. To prevent
+ # timeout spot the 'Running ...' lines going past, so long as
+ # these are produced quickly enough then the overall test will
+ # not timeout.
+ exp_continue
+ }
+ -re "Ran ($decimal) unit tests, ($decimal) failed\r\n$gdb_prompt $" {
+ set num_ran $expect_out(1,string)
+ set num_failed $expect_out(2,string)
+ gdb_assert "$num_ran > 0" "$test, ran some tests"
+ gdb_assert "$num_failed == 0" "$test, failed none"
+ }
+ -re "Selftests have been disabled for this build.\r\n$gdb_prompt $" {
+ unsupported $test
+ set num_ran 0
+ set enabled 0
+ }
}
}