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.
# 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
}
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}
+}