qemu/tests/tcg/multiarch/gdbstub/prot-none.py
Ilya Leoshkevich cb241df412 tests/tcg: Stop using exit() in the gdbstub testcases
GDB 15 does not like exit() anymore:

    (gdb) python exit(0)
    Python Exception <class 'SystemExit'>: 0
    Error occurred in Python: 0

Use the GDB's own exit command, like it's already done in a couple
places, everywhere. This is the same fix as commit 93a3048dcf
("tests: Gently exit from GDB when tests complete"), but applied to
more places.

Acked-by: Gustavo Romero <gustavo.romero@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Message-Id: <20241022113939.19989-1-iii@linux.ibm.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2024-11-18 15:54:34 +00:00

36 lines
998 B
Python

"""Test that GDB can access PROT_NONE pages.
This runs as a sourced script (via -x, via run-test.py).
SPDX-License-Identifier: GPL-2.0-or-later
"""
import ctypes
from test_gdbstub import gdb_exit, main, report
def probe_proc_self_mem():
buf = ctypes.create_string_buffer(b'aaa')
try:
with open("/proc/self/mem", "rb") as fp:
fp.seek(ctypes.addressof(buf))
return fp.read(3) == b'aaa'
except OSError:
return False
def run_test():
"""Run through the tests one by one"""
if not probe_proc_self_mem():
print("SKIP: /proc/self/mem is not usable")
gdb_exit(0)
gdb.Breakpoint("break_here")
gdb.execute("continue")
val = gdb.parse_and_eval("*(char[2] *)q").string()
report(val == "42", "{} == 42".format(val))
gdb.execute("set *(char[3] *)q = \"24\"")
gdb.execute("continue")
exitcode = int(gdb.parse_and_eval("$_exitcode"))
report(exitcode == 0, "{} == 0".format(exitcode))
main(run_test)