Received: by 2002:ac2:4c03:0:0:0:0:0 with SMTP id t3csp2357821lfq; Fri, 18 Dec 2020 06:45:49 -0800 (PST) X-Received: by 2002:a2e:874d:: with SMTP id q13mr1941696ljj.323.1608302749110; Fri, 18 Dec 2020 06:45:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608302749; cv=none; d=google.com; s=arc-20160816; b=p4BVR0w+nJaugGkvV5N7lHA9/nOYpwT63+CIHwR+vaIfm4H7Ty8QN6QIsESm90n1kY udhhD/gBBPiKsrsh0QwfndLOOPfeiqWhQi6OJHblv/O+Xo6gowHjGv0gWKwbKTf1/3nS 6Uz+M0oSSnpa1CiRqulu/fQS2ywj0nYBLU7rivx2QFlIMZH7hv3hsAAehDMDOvxX51gi GuxWR+dGMwAQOEPlpun85eoe+sMFkk474y3HZpI7cakq7yiw3Rjzs6J0p8udgnky2VFA Y/p+MVmhgEyc/ik3fNpr8023GrypJzmyGkLBcfjUsf6GMjEn4H6BWmm8g6vBy8kwbnOy 9RDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject:sender :dkim-signature; bh=9mk0AlZyqvNzt+BRv+OXsK69rV33wEA+ZfwE8NgOFcw=; b=Y7Z78mATdWOynTuDOtbXSeQeXL3sglx86EEpKH1hdbpUX35SYVlBk+SNIahyxKd948 LvtgH3JJUjbDCv2Oz5IXvWolhQGECIfddpVBOQSdUEnQrIIMr7Z5KxAHtdL5ZBBtRlwy xmSbd21l2OHXWw3laoj3FIhj8M6qbNR8nsgdxLdUbpJYTrnhoQhn4o6wFvuw3tuJ4/QO tbeoVBHKDhs2JJhZDDKcEZry2PyrENAkaQydOp9IOxZHggtRUH3OEpnYA3YfFv1qkrZW Gqv+QBUhl0pqFgF6vaLNayN57cQRpcDPYjwWaRMj0mjqqDtIW5L24Js6mBQQRwW3JyG5 Ht8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CUSGU7uG; spf=pass (google.com: domain of philippe.mathieu.daude@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=amsat.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id k2sor9524668ljb.53.2020.12.18.06.45.49 (Google Transport Security); Fri, 18 Dec 2020 06:45:49 -0800 (PST) Received-SPF: pass (google.com: domain of philippe.mathieu.daude@gmail.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CUSGU7uG; spf=pass (google.com: domain of philippe.mathieu.daude@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=amsat.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=9mk0AlZyqvNzt+BRv+OXsK69rV33wEA+ZfwE8NgOFcw=; b=CUSGU7uG5aJHe1Vm3dpAp+gK6bMblxBvHFtflOwIGN+UMTFS7H5YAXoBL75CQLxR3A QK2MGhZ1cNkRyytVEdeL/1LYNgrGOnl6XkaDh1sFv+VqrzWyrDyiZmuRM1w8R/ascnEr +CSpi+31Yn6pUhS5CiLkLp5f3RO0rD5wx8F/HVO0SYXcJ9Lr0/D1Hgyw0qEChlatq66b /mzT7+bW1Jx9PPWP1GhiKKXv8Dt5Uy2Rlg2DPCP4iUwzEuEtWKZ2rvT8oBSCJoLGF/ar o3/D1rugIEBha4YHo5K10pc76eToYygwlIIQP5Mrkt6MHlh4Jk2x3nLRiBIp9NPBNVUh 5nlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=9mk0AlZyqvNzt+BRv+OXsK69rV33wEA+ZfwE8NgOFcw=; b=piXSERA0BcRiVk7JR477v/BGcHHwuwIKCSViQiJDdtTB23zjlc+o/n8Q3y6JSIavnv klcf8dkC8M4COf4DOr+GRu3Czm5aW0rNtfPyNWWZXYv+doQ8DGSY4B9tFvaBQ9+u+5y3 arRlUXBzKlAE0DVk+ypYm5PKxd1JozEsiMfH4Hs2iXUI1g8LfnFBNWbfl/iyN9I85Ns2 47a2QWtceLLjotCAPk8xXbh1heZ38Bl8HAaKFxw67JEDDhFiFRgDQ7HgH0kO6nlaDb7a eUibR5dW2rmqP1wltoQYNkW/EJQBNedXzl/sR8FYJ2MurIwhBtAhElMCu53pgRJ8dFBj JC+w== X-Gm-Message-State: AOAM5319euUMcA6JcUqLxOup/8LlePSzw1XokolzrQIImk520r+KAhyj ZezjNtvl+eJyExKrEquX+fY= X-Google-Smtp-Source: ABdhPJwpQVRWD8gY3YKXd89hlol4zIW4mUyQbAYEKyFSr3MeEHNGdAdrIcwMKz67tQ4Nzh2xqzv7hA== X-Received: by 2002:a05:651c:48e:: with SMTP id s14mr2064382ljc.159.1608302748755; Fri, 18 Dec 2020 06:45:48 -0800 (PST) Return-Path: Received: from [10.101.1.184] ([185.224.57.162]) by smtp.gmail.com with ESMTPSA id k5sm943995lfo.61.2020.12.18.06.45.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Dec 2020 06:45:47 -0800 (PST) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= Subject: Re: [PATCH v2 4/9] gdbstub: implement a softmmu based test To: =?UTF-8?Q?Alex_Benn=c3=a9e?= , qemu-devel@nongnu.org Cc: Peter Maydell , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "open list:ARM TCG CPUs" References: <20201218112707.28348-1-alex.bennee@linaro.org> <20201218112707.28348-5-alex.bennee@linaro.org> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Message-ID: Date: Fri, 18 Dec 2020 15:45:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <20201218112707.28348-5-alex.bennee@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-TUID: CGSbTSRwIcuY On 12/18/20 12:27 PM, Alex Bennée wrote: > This adds a new tests that allows us to test softmmu only features > including watchpoints. To do achieve this we need to: > > - add _exit: labels to the boot codes > - write a memory.py test case > - plumb the test case into the build system > - tweak the run_test script to: > - re-direct output when asked > - use socket based connection for all tests > - add a small pause before connection > > Signed-off-by: Alex Bennée > --- > tests/guest-debug/run-test.py | 36 +++-- > tests/tcg/aarch64/Makefile.softmmu-target | 1 + > tests/tcg/aarch64/system/boot.S | 1 + > tests/tcg/i386/Makefile.softmmu-target | 1 + > tests/tcg/i386/system/boot.S | 2 +- > tests/tcg/multiarch/gdbstub/memory.py | 130 ++++++++++++++++++ > .../multiarch/system/Makefile.softmmu-target | 19 ++- > tests/tcg/x86_64/Makefile.softmmu-target | 1 + > tests/tcg/x86_64/system/boot.S | 2 +- > 9 files changed, 181 insertions(+), 12 deletions(-) > create mode 100644 tests/tcg/multiarch/gdbstub/memory.py > > diff --git a/tests/guest-debug/run-test.py b/tests/guest-debug/run-test.py > index 0c4f5c3808..8b91ff95af 100755 > --- a/tests/guest-debug/run-test.py > +++ b/tests/guest-debug/run-test.py > @@ -16,6 +16,7 @@ import subprocess > import shutil > import shlex > import os > +from time import sleep > from tempfile import TemporaryDirectory > > def get_args(): > @@ -27,10 +28,21 @@ def get_args(): > required=True) > parser.add_argument("--test", help="GDB test script", > required=True) > - parser.add_argument("--gdb", help="The gdb binary to use", default=None) > + parser.add_argument("--gdb", help="The gdb binary to use", > + default=None) > + parser.add_argument("--output", help="A file to redirect output to") > > return parser.parse_args() > > + > +def log(output, msg): Maybe simplify as: def log(msg, out=sys.stdout): output.write(msg + "\n") output.flush() > + if output: > + output.write(msg + "\n") > + output.flush() > + else: > + print(msg) > + > + > if __name__ == '__main__': > args = get_args() > > @@ -42,18 +54,25 @@ if __name__ == '__main__': > if not args.gdb: > print("We need gdb to run the test") > exit(-1) > + if args.output: > + output = open(args.output, "w") > + else: > + output = None > > socket_dir = TemporaryDirectory("qemu-gdbstub") > socket_name = os.path.join(socket_dir.name, "gdbstub.socket") > > # Launch QEMU with binary > if "system" in args.qemu: > - cmd = "%s %s %s -s -S" % (args.qemu, args.qargs, args.binary) > + cmd = "%s %s %s -gdb unix:path=%s,server" % (args.qemu, > + args.qargs, > + args.binary, > + socket_name) What about Windows hosts? > else: > cmd = "%s %s -g %s %s" % (args.qemu, args.qargs, socket_name, > args.binary) > > - print("QEMU CMD: %s" % (cmd)) > + log(output, "QEMU CMD: %s" % (cmd)) > inferior = subprocess.Popen(shlex.split(cmd)) > > # Now launch gdb with our test and collect the result > @@ -63,16 +82,15 @@ if __name__ == '__main__': > # disable prompts in case of crash > gdb_cmd += " -ex 'set confirm off'" > # connect to remote > - if "system" in args.qemu: > - gdb_cmd += " -ex 'target remote localhost:1234'" > - else: > - gdb_cmd += " -ex 'target remote %s'" % (socket_name) > + gdb_cmd += " -ex 'target remote %s'" % (socket_name) > # finally the test script itself > gdb_cmd += " -x %s" % (args.test) > > - print("GDB CMD: %s" % (gdb_cmd)) > > - result = subprocess.call(gdb_cmd, shell=True); > + sleep(1) > + log(output, "GDB CMD: %s" % (gdb_cmd)) > + > + result = subprocess.call(gdb_cmd, shell=True, stdout=output) > > # A negative result is the result of an internal gdb failure like > # a crash. We force a return of 0 so we don't fail the test on > diff --git a/tests/tcg/aarch64/Makefile.softmmu-target b/tests/tcg/aarch64/Makefile.softmmu-target > index 1057a8ac49..a7286ac295 100644 > --- a/tests/tcg/aarch64/Makefile.softmmu-target > +++ b/tests/tcg/aarch64/Makefile.softmmu-target > @@ -15,6 +15,7 @@ CRT_PATH=$(AARCH64_SYSTEM_SRC) > LINK_SCRIPT=$(AARCH64_SYSTEM_SRC)/kernel.ld > LDFLAGS=-Wl,-T$(LINK_SCRIPT) > TESTS+=$(AARCH64_TESTS) $(MULTIARCH_TESTS) > +EXTRA_RUNS+=$(MULTIARCH_RUNS) > CFLAGS+=-nostdlib -ggdb -O0 $(MINILIB_INC) > LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc > > diff --git a/tests/tcg/aarch64/system/boot.S b/tests/tcg/aarch64/system/boot.S > index b14e94f332..e190b1efa6 100644 > --- a/tests/tcg/aarch64/system/boot.S > +++ b/tests/tcg/aarch64/system/boot.S > @@ -197,6 +197,7 @@ __start: > bl main > > /* pass return value to sys exit */ > +_exit: > mov x1, x0 > ldr x0, =0x20026 /* ADP_Stopped_ApplicationExit */ > stp x0, x1, [sp, #-16]! > diff --git a/tests/tcg/i386/Makefile.softmmu-target b/tests/tcg/i386/Makefile.softmmu-target > index 1c8790eecd..5266f2335a 100644 > --- a/tests/tcg/i386/Makefile.softmmu-target > +++ b/tests/tcg/i386/Makefile.softmmu-target > @@ -19,6 +19,7 @@ CFLAGS+=-nostdlib -ggdb -O0 $(MINILIB_INC) > LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc > > TESTS+=$(MULTIARCH_TESTS) > +EXTRA_RUNS+=$(MULTIARCH_RUNS) > > # building head blobs > .PRECIOUS: $(CRT_OBJS) > diff --git a/tests/tcg/i386/system/boot.S b/tests/tcg/i386/system/boot.S > index 90aa174908..794c2cb0ad 100644 > --- a/tests/tcg/i386/system/boot.S > +++ b/tests/tcg/i386/system/boot.S > @@ -76,7 +76,7 @@ _start: > */ > call main > > - /* output any non-zero result in eax to isa-debug-exit device */ > +_exit: /* output any non-zero result in eax to isa-debug-exit device */ > test %al, %al > jz 1f > out %ax, $0xf4 > diff --git a/tests/tcg/multiarch/gdbstub/memory.py b/tests/tcg/multiarch/gdbstub/memory.py > new file mode 100644 > index 0000000000..67864ad902 > --- /dev/null > +++ b/tests/tcg/multiarch/gdbstub/memory.py > @@ -0,0 +1,130 @@ > +from __future__ import print_function Missing license. > +# > +# Test some of the softmmu debug features with the multiarch memory > +# test. It is a port of the original vmlinux focused test case but > +# using the "memory" test instead. > +# > +# This is launched via tests/guest-debug/run-test.py > +# > + > +import gdb > +import sys > + > +failcount = 0 > + > + > +def report(cond, msg): > + "Report success/fail of test" > + if cond: > + print("PASS: %s" % (msg)) > + else: > + print("FAIL: %s" % (msg)) > + global failcount > + failcount += 1 > + > + > +def check_step(): > + "Step an instruction, check it moved." > + start_pc = gdb.parse_and_eval('$pc') > + gdb.execute("si") > + end_pc = gdb.parse_and_eval('$pc') > + > + return not (start_pc == end_pc) > + > + > +# > +# Currently it's hard to create a hbreak with the pure python API and > +# manually matching PC to symbol address is a bit flaky thanks to > +# function prologues. However internally QEMU's gdbstub treats them > +# the same as normal breakpoints so it will do for now. > +# > +def check_break(sym_name): > + "Setup breakpoint, continue and check we stopped." > + sym, ok = gdb.lookup_symbol(sym_name) > + bp = gdb.Breakpoint(sym_name, gdb.BP_BREAKPOINT) > + > + gdb.execute("c") > + > + # hopefully we came back What if we don't? Not a blocking problem today, we'll figure if we need to improve that later. > + end_pc = gdb.parse_and_eval('$pc') > + report(bp.hit_count == 1, > + "break @ %s (%s %d hits)" % (end_pc, sym.value(), bp.hit_count)) > + > + bp.delete() > + > + > +def do_one_watch(sym, wtype, text): > + > + wp = gdb.Breakpoint(sym, gdb.BP_WATCHPOINT, wtype) > + gdb.execute("c") > + report_str = "%s for %s" % (text, sym) > + > + if wp.hit_count > 0: > + report(True, report_str) > + wp.delete() > + else: > + report(False, report_str) > + > + > +def check_watches(sym_name): > + "Watch a symbol for any access." > + > + # Should hit for any read > + do_one_watch(sym_name, gdb.WP_ACCESS, "awatch") > + > + # Again should hit for reads > + do_one_watch(sym_name, gdb.WP_READ, "rwatch") > + > + # Finally when it is written > + do_one_watch(sym_name, gdb.WP_WRITE, "watch") > + > + > +def run_test(): > + "Run through the tests one by one" > + > + print("Checking we can step the first few instructions") > + step_ok = 0 > + for i in range(3): > + if check_step(): > + step_ok += 1 > + > + report(step_ok == 3, "single step in boot code") > + > + # If we get here we have missed some of the other breakpoints. > + print("Setup catch-all for _exit") > + cbp = gdb.Breakpoint("_exit", gdb.BP_BREAKPOINT) > + > + check_break("main") > + check_watches("test_data[128]") > + > + report(cbp.hit_count == 0, "didn't reach backstop") > + > +# > +# This runs as the script it sourced (via -x, via run-test.py) > +# > +try: > + inferior = gdb.selected_inferior() > + arch = inferior.architecture() > + print("ATTACHED: %s" % arch.name()) > +except (gdb.error, AttributeError): > + print("SKIPPING (not connected)", file=sys.stderr) > + exit(0) > + > +if gdb.parse_and_eval('$pc') == 0: > + print("SKIP: PC not set") > + exit(0) > + > +try: > + # These are not very useful in scripts > + gdb.execute("set pagination off") > + > + # Run the actual tests > + run_test() > +except (gdb.error): > + print("GDB Exception: %s" % (sys.exc_info()[0])) > + failcount += 1 > + pass > + > +# Finally kill the inferior and exit gdb with a count of failures > +gdb.execute("kill") > +exit(failcount) > diff --git a/tests/tcg/multiarch/system/Makefile.softmmu-target b/tests/tcg/multiarch/system/Makefile.softmmu-target > index db4bbeda44..4657f6e4cf 100644 > --- a/tests/tcg/multiarch/system/Makefile.softmmu-target > +++ b/tests/tcg/multiarch/system/Makefile.softmmu-target > @@ -7,8 +7,25 @@ > # complications of building. > # > > -MULTIARCH_SYSTEM_SRC=$(SRC_PATH)/tests/tcg/multiarch/system > +MULTIARCH_SRC=$(SRC_PATH)/tests/tcg/multiarch > +MULTIARCH_SYSTEM_SRC=$(MULTIARCH_SRC)/system > VPATH+=$(MULTIARCH_SYSTEM_SRC) > > MULTIARCH_TEST_SRCS=$(wildcard $(MULTIARCH_SYSTEM_SRC)/*.c) > MULTIARCH_TESTS = $(patsubst $(MULTIARCH_SYSTEM_SRC)/%.c, %, $(MULTIARCH_TEST_SRCS)) > + > +ifneq ($(HAVE_GDB_BIN),) > +GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py > + > +run-gdbstub-memory: memory > + $(call run-test, $@, $(GDB_SCRIPT) \ > + --gdb $(HAVE_GDB_BIN) \ > + --qemu $(QEMU) \ > + --output $<.gdb.out \ > + --qargs \ > + "-monitor none -display none -chardev file$(COMMA)path=$<.out$(COMMA)id=output $(QEMU_OPTS)" \ > + --bin $< --test $(MULTIARCH_SRC)/gdbstub/memory.py, \ > + "softmmu gdbstub support") > + > +MULTIARCH_RUNS += run-gdbstub-memory > +endif > diff --git a/tests/tcg/x86_64/Makefile.softmmu-target b/tests/tcg/x86_64/Makefile.softmmu-target > index df252e761c..1bd763f2e6 100644 > --- a/tests/tcg/x86_64/Makefile.softmmu-target > +++ b/tests/tcg/x86_64/Makefile.softmmu-target > @@ -19,6 +19,7 @@ CFLAGS+=-nostdlib -ggdb -O0 $(MINILIB_INC) > LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc > > TESTS+=$(MULTIARCH_TESTS) > +EXTRA_RUNS+=$(MULTIARCH_RUNS) > > # building head blobs > .PRECIOUS: $(CRT_OBJS) > diff --git a/tests/tcg/x86_64/system/boot.S b/tests/tcg/x86_64/system/boot.S > index 73b19a2bda..f8a2fcc839 100644 > --- a/tests/tcg/x86_64/system/boot.S > +++ b/tests/tcg/x86_64/system/boot.S > @@ -124,7 +124,7 @@ _start: > /* don't worry about stack frame, assume everthing is garbage when we return */ > call main > > - /* output any non-zero result in eax to isa-debug-exit device */ > +_exit: /* output any non-zero result in eax to isa-debug-exit device */ > test %al, %al > jz 1f > out %ax, $0xf4 > LGTM. With license: Reviewed-by: Philippe Mathieu-Daudé