diff options
author | Tom de Vries <tdevries@suse.de> | 2021-10-19 23:50:50 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2021-10-19 23:50:50 +0200 |
commit | c82f680a94399a0f1c9fdc53ed79a8cf333213a6 (patch) | |
tree | 2f8984a012c205b65b357f93be8f5b02a9977dd5 /gdb/python | |
parent | 5a8edb756a56cdfb563006cbc39561994acf6d2d (diff) | |
download | gdb-c82f680a94399a0f1c9fdc53ed79a8cf333213a6.zip gdb-c82f680a94399a0f1c9fdc53ed79a8cf333213a6.tar.gz gdb-c82f680a94399a0f1c9fdc53ed79a8cf333213a6.tar.bz2 |
[gdb/testsuite] Reimplement gdb.gdb/python-interrupts.exp as unittest
The test-case gdb.gdb/python-interrupts.exp:
- runs to captured_command_loop
- sets a breakpoint at set_active_ext_lang
- calls a python command
- verifies the command triggers the breakpoint
- sends a signal and verifies the result
The test-case is fragile, because (f.i. with -flto) it cannot be guaranteed
that captured_command_loop and set_active_ext_lang are available for setting
breakpoints.
Reimplement the test-case as unittest, using:
- execute_command_to_string to capture the output
- try/catch to catch the "Error while executing Python code" exception
- a new hook selftests::hook_set_active_ext_lang to raise the signal
Tested on x86_64-linux.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/python.c | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/gdb/python/python.c b/gdb/python/python.c index 264f7c8..44ec4b7 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1933,21 +1933,46 @@ test_python () output.clear (); bool saw_exception = false; - scoped_restore reset_gdb_python_initialized - = make_scoped_restore (&gdb_python_initialized, 0); - try - { - CMD (output); - } - catch (const gdb_exception &e) - { - saw_exception = true; - SELF_CHECK (e.reason == RETURN_ERROR); - SELF_CHECK (e.error == GENERIC_ERROR); - SELF_CHECK (*e.message == "Python not initialized"); - } - SELF_CHECK (saw_exception); - SELF_CHECK (output.empty ()); + { + scoped_restore reset_gdb_python_initialized + = make_scoped_restore (&gdb_python_initialized, 0); + try + { + CMD (output); + } + catch (const gdb_exception &e) + { + saw_exception = true; + SELF_CHECK (e.reason == RETURN_ERROR); + SELF_CHECK (e.error == GENERIC_ERROR); + SELF_CHECK (*e.message == "Python not initialized"); + } + SELF_CHECK (saw_exception); + SELF_CHECK (output.empty ()); + } + + saw_exception = false; + { + scoped_restore save_hook + = make_scoped_restore (&hook_set_active_ext_lang, + []() { raise (SIGINT); }); + try + { + CMD (output); + } + catch (const gdb_exception &e) + { + saw_exception = true; + SELF_CHECK (e.reason == RETURN_ERROR); + SELF_CHECK (e.error == GENERIC_ERROR); + SELF_CHECK (*e.message == "Error while executing Python code."); + } + SELF_CHECK (saw_exception); + std::string ref_output("Traceback (most recent call last):\n" + " File \"<string>\", line 1, in <module>\n" + "KeyboardInterrupt\n"); + SELF_CHECK (output == ref_output); + } #undef CMD } |