aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2021-11-29 13:52:40 +0000
committerAndrew Burgess <aburgess@redhat.com>2021-11-30 13:05:57 +0000
commitae9aa73767ca46f34ee6ea915bdf13b77d058d4d (patch)
tree877c64847db60e0e365500e558b722fc0eaa3deb
parent1527fe5f584c71dbf006c6646fe2ff729d7b2b48 (diff)
downloadgdb-ae9aa73767ca46f34ee6ea915bdf13b77d058d4d.zip
gdb-ae9aa73767ca46f34ee6ea915bdf13b77d058d4d.tar.gz
gdb-ae9aa73767ca46f34ee6ea915bdf13b77d058d4d.tar.bz2
gdb/testsuite: check the python module is available before using it
The gdb.python/py-inferior-leak.exp test makes use of the tracemalloc module. When running the Python tests with a GDB built against Python 2 I ran into a test failure due to the tracemalloc module not being available. This commit adds a new helper function to lib/gdb-python.exp that checks if a named module is available. Using this we can then skip the py-inferior-leak.exp test when the tracemalloc module is not available.
-rw-r--r--gdb/testsuite/gdb.python/py-inferior-leak.exp6
-rw-r--r--gdb/testsuite/lib/gdb-python.exp25
2 files changed, 31 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-inferior-leak.exp b/gdb/testsuite/gdb.python/py-inferior-leak.exp
index 9cd1ebf..15d7423 100644
--- a/gdb/testsuite/gdb.python/py-inferior-leak.exp
+++ b/gdb/testsuite/gdb.python/py-inferior-leak.exp
@@ -25,6 +25,12 @@ clean_restart
# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }
+# Skip this test if the tracemalloc module is not available.
+if { ![gdb_py_module_available "tracemalloc"] } {
+ unsupported "tracemalloc module not available"
+ continue
+}
+
set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
# Source the Python script, this runs the test (which is written
diff --git a/gdb/testsuite/lib/gdb-python.exp b/gdb/testsuite/lib/gdb-python.exp
index 13a1ab5..60931fe 100644
--- a/gdb/testsuite/lib/gdb-python.exp
+++ b/gdb/testsuite/lib/gdb-python.exp
@@ -51,3 +51,28 @@ proc get_python_valueof { exp default {test ""} } {
}
return ${val}
}
+
+# Return true if Python module NAME is available, otherwise, return
+# false.
+
+proc gdb_py_module_available { name } {
+ set available "unknown"
+ gdb_test_multiple "python import ${name}" "" {
+ -re -wrap "ModuleNotFoundError: No module named '${name}'.*" {
+ set available false
+ }
+ -re -wrap "ImportError: No module named ${name}.*" {
+ set available false
+ }
+ -re -wrap "python import ${name}" {
+ set available true
+ }
+ }
+
+ if { $available == "unknown" } {
+ perror "unexpected output from python import"
+ set available false
+ }
+
+ return ${available}
+}