]> git.proxmox.com Git - mirror_qemu.git/blob - tests/guest-debug/run-test.py
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2020-03-17' into staging
[mirror_qemu.git] / tests / guest-debug / run-test.py
1 #!/usr/bin/env python3
2 #
3 # Run a gdbstub test case
4 #
5 # Copyright (c) 2019 Linaro
6 #
7 # Author: Alex Bennée <alex.bennee@linaro.org>
8 #
9 # This work is licensed under the terms of the GNU GPL, version 2 or later.
10 # See the COPYING file in the top-level directory.
11 #
12 # SPDX-License-Identifier: GPL-2.0-or-later
13
14 import argparse
15 import subprocess
16 import shutil
17 import shlex
18
19 def get_args():
20 parser = argparse.ArgumentParser(description="A gdbstub test runner")
21 parser.add_argument("--qemu", help="Qemu binary for test",
22 required=True)
23 parser.add_argument("--qargs", help="Qemu arguments for test")
24 parser.add_argument("--binary", help="Binary to debug",
25 required=True)
26 parser.add_argument("--test", help="GDB test script",
27 required=True)
28 parser.add_argument("--gdb", help="The gdb binary to use", default=None)
29
30 return parser.parse_args()
31
32 if __name__ == '__main__':
33 args = get_args()
34
35 # Search for a gdb we can use
36 if not args.gdb:
37 args.gdb = shutil.which("gdb-multiarch")
38 if not args.gdb:
39 args.gdb = shutil.which("gdb")
40 if not args.gdb:
41 print("We need gdb to run the test")
42 exit(-1)
43
44 # Launch QEMU with binary
45 if "system" in args.qemu:
46 cmd = "%s %s %s -s -S" % (args.qemu, args.qargs, args.binary)
47 else:
48 cmd = "%s %s -g 1234 %s" % (args.qemu, args.qargs, args.binary)
49
50 inferior = subprocess.Popen(shlex.split(cmd))
51
52 # Now launch gdb with our test and collect the result
53 gdb_cmd = "%s %s -ex 'target remote localhost:1234' -x %s" % (args.gdb, args.binary, args.test)
54
55 result = subprocess.call(gdb_cmd, shell=True);
56
57 exit(result)