From patchwork Tue Sep 10 17:38:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 827034 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp430690wrc; Tue, 10 Sep 2024 10:40:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUlbnJM3PtNO5Au9GPQEUg21FNkGpzFeKAqLAFHR6GGxZ4Q1b+AEJUPIKN5RRjR0F5DShNBDA==@linaro.org X-Google-Smtp-Source: AGHT+IHh2694FoZMq7qkYXVy+Ckx60zTeESjzPzrd4JFDG2bZ1fTS4rDzDWOQjdfFWzdwsu1k3kn X-Received: by 2002:a05:622a:1815:b0:458:4aec:2749 with SMTP id d75a77b69052e-4584aec2bcfmr29500871cf.57.1725990035692; Tue, 10 Sep 2024 10:40:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725990035; cv=none; d=google.com; s=arc-20240605; b=TLS2VtTsYS9Wj9UzixrFZCf9s0TrHu8usYnUDkzeuu9n9OSvR3coCg8z1DRFsVXNpz cjr6w17VCNYnWF+rssPJRE0RR0nD1OCzWCSd2sCjbqYAmA/3CWr/lol6YHltuPpa5NAf svHL6PikPVdFENyAVt7PBFLLy9aERNEFCmAf6yn6b4YdFeOM4atKf3wtSjoEJaPAe6dQ V+qgFjS4/WKyjJO2mxnOAVMCSsrkODY1pisQXmV3zbi0JyF1Z5lKt0+kKxeLv7EThsC/ MJKXpwd0gdcqvrYldpge8owCKL+lr2ZDrXxtPDQDRSB5DCcLIety4ZyCj/ZxstJzkpAl YchA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0gsP/ANf70RJH0KlgA0KWCypst2Oh4Yb8PQcZ6VG+qU=; fh=h773y6AOAE/ukr4mRlwaH0i0lfsEFb3Q85tR2q3kvZo=; b=cIzwrsJpS3RB6Q9TM+xnN1uuuI8YJqCcQ3hco39khoHLQTsHaWonkL1+cZQzXdK7Mz YO9IBm8yrnwmGMFmLHO2GRORLvSK1zjFDFoa5wIqd2pg0IPV1tCQh8xyZzHF+BKbxnG4 njMQ4hvhdxO/5MGPdnl/5YAzh+KDN2fInnLfvang6X77xxVQi1otpoJcTwWcrsO2cejm R8pjz+fPItGjgR+qRZAgt4rbBoNMbq0cTaEJ3rUUBLTjr/0OEBBg3VyQxPDrcvKyzqTM 9CJw3oMrdQIupTIRUQeiYim/7wavy6VccSvd/lQGwm/ZvcWawvcu0pHXJxVL+1Jb5QEC ZcrQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFUJVCMA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45822e7ebb4si86186691cf.180.2024.09.10.10.40.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2024 10:40:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFUJVCMA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1so4pk-0005EO-8Y; Tue, 10 Sep 2024 13:39:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1so4pa-0004mh-TV for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:39:11 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4pY-0004Zt-8S for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:39:10 -0400 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a8a7b1c2f2bso167213166b.0 for ; Tue, 10 Sep 2024 10:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725989946; x=1726594746; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0gsP/ANf70RJH0KlgA0KWCypst2Oh4Yb8PQcZ6VG+qU=; b=CFUJVCMA2vm7cJSDLpxCLFDM5b+5sHQYqPquJSiJBUBOqR6fy0Gbvf8mZtKc9u+YO5 LVMh5cPVGOcsdcO9pTnqc8uWVHMS5K/0I1io8hCXWJkPF/FmKCWThgZXzUs7lxg3tyxF h6LnaHTvTA5/ZHvkb84f0QLJbbEUTT8KWYNdsOuDIN+xhjA/4/oGKTMwtGjWG5r/e0tV MiGCVD28NJS04hYUMXurtRqK/H5RTfEPvhWyxfGh4IGAHWDF8DJQf/uK6aaSanZfBcW8 RA3fbKogTmVnS2WcrL/Lx/7GvX5MF4zefoSsbvzcl1dsaig3kwo2FJYp7/GRVYipYT9R kQAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725989946; x=1726594746; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0gsP/ANf70RJH0KlgA0KWCypst2Oh4Yb8PQcZ6VG+qU=; b=ZWCCPyfAK/3KKr/IoMSD/u1UZUQkq1q2goVy8w6yvD4oB0KOvQTQ3AGiNBRz7OBcbA j1fVg0hQqyUk22xQnBSABVL3gpNAzlSuz950I/wOjCs2xvPTM9b3bYHZ30TcKycOTLaz EBbRfdow+pTGlDDHlYLpuyAQINzMKLV2otC9t6g5y4TATusAS60mqY6GT9CS5W4AOAo/ SK3uPkDP9QAJvXUcUah6YcjHeWq/KXB6gKs535XB2BM62qCHmYWchEO2QOGxYuRb1vwJ yNLTE5dkhMEa3i2EiVleZ3UoVQanABaMUSA7nIKE7+XCqbRByaL78DYsvvR8lfZviBnz s7Uw== X-Gm-Message-State: AOJu0Yz8KHuxj4cU+JT3TysXS3i189usksYeqzUm7Fd4sYxaFrwoGgnZ Ulz0XRWh0TYs9PcCBRLWsg9YBhtSMFVo415AaSUwn1iYxc9TeYDwPptkjXavFEY= X-Received: by 2002:a17:907:2d13:b0:a86:aa57:57b8 with SMTP id a640c23a62f3a-a9004aba7c7mr29382466b.63.1725989946197; Tue, 10 Sep 2024 10:39:06 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25ce970csm505277266b.159.2024.09.10.10.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:39:04 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 335A35FA11; Tue, 10 Sep 2024 18:39:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , Zhao Liu , Peter Maydell , Paolo Bonzini , Marcel Apfelbaum , qemu-arm@nongnu.org, devel@lists.libvirt.org, Pierrick Bouvier , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Jiaxun Yang , Beraldo Leal , Eduardo Habkost , Richard Henderson , Mahmoud Mandour , Yanan Wang , Wainer dos Santos Moschetta , Gustavo Romero Subject: [PATCH v2 08/10] tests/guest-debug: Support passing arguments to the GDB test script Date: Tue, 10 Sep 2024 18:38:58 +0100 Message-Id: <20240910173900.4154726-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910173900.4154726-1-alex.bennee@linaro.org> References: <20240910173900.4154726-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Gustavo Romero This commit adds support for passing arguments to the GDB test scripts so it's possible to parse the args in an "argparse way" in the test scripts launched by the runner. The arguments should be preceded by -- when passed to the runner. For example, passing "--help" arg to the GDB_TEST_SCRIPT: run-test.py [...] --test -- --help The test script should not use the argparse module directly but import arg_parser from test_gdbstub module. arg_parser then can be used just like the argparse.ArgumentParser class: from test_gdbstub import arg_parser p = arg_parser(prog="test-mytest.py", description="My test.") p.add_argument("--vowel", help="Select vowel", required=True, choices=['a','e','i','o','u']) [...] The arg_parser allows a smooth and informative exit if, for instance, the caller of the runner script passes an invalid argument or misses a required argument by the test script. Signed-off-by: Gustavo Romero Reviewed-by: Alex Bennée Message-Id: <20240906143316.657436-4-gustavo.romero@linaro.org> Signed-off-by: Alex Bennée --- tests/guest-debug/run-test.py | 6 ++++++ tests/guest-debug/test_gdbstub.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/tests/guest-debug/run-test.py b/tests/guest-debug/run-test.py index 368ff8a890..5a091db8be 100755 --- a/tests/guest-debug/run-test.py +++ b/tests/guest-debug/run-test.py @@ -27,6 +27,10 @@ def get_args(): parser.add_argument("--binary", help="Binary to debug", required=True) parser.add_argument("--test", help="GDB test script") + parser.add_argument('test_args', nargs='*', + help="Additional args for GDB test script. " + "The args should be preceded by -- to avoid confusion " + "with flags for runner script") parser.add_argument("--gdb", help="The gdb binary to use", default=None) parser.add_argument("--gdb-args", help="Additional gdb arguments") @@ -91,6 +95,8 @@ def log(output, msg): gdb_cmd += " -ex 'target remote %s'" % (socket_name) # finally the test script itself if args.test: + if args.test_args: + gdb_cmd += f" -ex \"py sys.argv={args.test_args}\"" gdb_cmd += " -x %s" % (args.test) diff --git a/tests/guest-debug/test_gdbstub.py b/tests/guest-debug/test_gdbstub.py index 46fbf98f0c..a715c0e3f5 100644 --- a/tests/guest-debug/test_gdbstub.py +++ b/tests/guest-debug/test_gdbstub.py @@ -2,6 +2,7 @@ """ from __future__ import print_function +import argparse import gdb import os import sys @@ -9,6 +10,10 @@ fail_count = 0 +class arg_parser(argparse.ArgumentParser): + def exit(self, status=None, message=""): + print("Wrong GDB script test argument! " + message) + gdb.execute("exit 1") def report(cond, msg): """Report success/fail of a test"""