From 1d8568c45b8fadc4330f7c83b67eda19dbc709fb Mon Sep 17 00:00:00 2001 From: Daniel Ebert Date: Sun, 22 Aug 2021 11:59:19 -0700 Subject: [PATCH] generate core just-in-time --- tests/test_loads.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/test_loads.py b/tests/test_loads.py index 4b2c9d58f..083d3c7cb 100644 --- a/tests/test_loads.py +++ b/tests/test_loads.py @@ -90,12 +90,15 @@ def test_loads_binary_without_crashing(): def test_loads_binary_with_core_without_crashing(): if not os.path.isfile(BINARY): compile_binary(BINARY_SOURCE, BINARY) + if not os.path.isfile(CORE): + create_coredump = ['run', f'generate-core-file {CORE}'] + run_gdb_with_script(binary=BINARY, pyafter=create_coredump) + assert os.path.isfile(CORE) output = run_gdb_with_script(binary=BINARY, core=CORE).splitlines() expected = [ 'Reading symbols from %s...' % BINARY, '(No debugging symbols found in %s)' % BINARY, - "Core was generated by `./binary'.", 'Program terminated with signal SIGFPE, Arithmetic exception.', ] expected += HELLO @@ -106,6 +109,10 @@ def test_loads_binary_with_core_without_crashing(): lwp_line = re.compile('^\[New LWP \d+\]$') assert any([lwp_line.match(line) for line in output]) + # matches for example "Core was generated by `./binary'." + binary_line = re.compile("^Core was generated by .+$") + assert any([binary_line.match(line) for line in output]) + # matches for example '#0 0x0000556e99b7913c in main ()' crash_address_line = re.compile('^#0 0x[0-9a-fA-F]+ in main \(\)$') assert any([crash_address_line.match(line) for line in output]) @@ -115,10 +122,13 @@ def test_loads_binary_with_core_without_crashing(): def test_loads_core_without_crashing(): if not os.path.isfile(BINARY): compile_binary(BINARY_SOURCE, BINARY) + if not os.path.isfile(CORE): + create_coredump = ['run', f'generate-core-file {CORE}'] + run_gdb_with_script(binary=BINARY, pyafter=create_coredump) + assert os.path.isfile(CORE) output = run_gdb_with_script(core=CORE).splitlines() expected = [ - "Core was generated by `./binary'.", 'Program terminated with signal SIGFPE, Arithmetic exception.', ] expected += HELLO @@ -129,6 +139,10 @@ def test_loads_core_without_crashing(): lwp_line = re.compile('^\[New LWP \d+\]$') assert any([lwp_line.match(line) for line in output]) + # matches for example "Core was generated by `./binary'." + binary_line = re.compile("^Core was generated by .+$") + assert any([binary_line.match(line) for line in output]) + # matches for example '#0 0x0000556e99b7913c in ?? ()' crash_address_line = re.compile('^#0 0x[0-9a-fA-F]+ in \?\? \(\)$') assert any([crash_address_line.match(line) for line in output])