From patchwork Sun Aug 25 14:52:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 822362 Delivered-To: patch@linaro.org Received: by 2002:adf:e044:0:b0:367:895a:4699 with SMTP id w4csp1172704wrh; Sun, 25 Aug 2024 07:53:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVPgxcYeeizsBQ4ntKMPI4MrtTHVfrmU3rbk3YwdnXaEU6exd9nYhN/QQPznmvemCgN1OQNzA==@linaro.org X-Google-Smtp-Source: AGHT+IGbe7WgEPxCLT/A/gI/OhAhGd+wPr44RizWoQUawcVVLl1DloctJq53oOVD/rNaTcW5e+MP X-Received: by 2002:a05:6358:840b:b0:1b1:a8a6:1630 with SMTP id e5c5f4694b2df-1b5c3b30c45mr896509355d.20.1724597617848; Sun, 25 Aug 2024 07:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724597617; cv=none; d=google.com; s=arc-20160816; b=qVLGBidZLNsfV6vcgSYvx3NQrFb+FSQLnPsEhXh9z35TxD3h2xksOmh5Jgm3Ucj/WT ZaY+b1vuD6TzF5XiM3IF7sLuvfdiotK/JHHs4ZXxdRSKuewnL66+b5VJeaH4tiY7Nrup APNXv+R/7Cwe5/BGFbu8i6Dt3A4veNh9ZOfQPp5XJIKbnvf0pfnBJLPrQknGRdJZ88T2 76ZbpNsx40f3ZihRlcGrHBZ0VOIgJCsikucS1DpdJEA6/GEIqB6o+FTIpD+WwJi5npmd yMnr47Ws86Ow8sfEmJmQD1wzM/HY9XiyGTzhqA+calFDxBOAmuRP0JbxduDFeCI75pyU borA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=NQhqFC3YWlPkCJwXValvIiJxyZnEMyHcDzM+YKLmAFI=; fh=b5q3cJgcc12gnKfUWQQbBLXKRqia4x4Q8oLG+cCF/wU=; b=C9BLq8FjQSjunyzjyoV2MF9l0/R4ZXpY2oi7QnVuFsBSut0E4xxX1t1LKKlfmPyKzm PhwwcM3dAA3AEOm7GWupk0dbwh7KkPw+FJNxBKGpGWZ/peEhgM57nQOcQMCj5C9VAyZE U2FYGuieeAPYd05AmqcKaRdTz+wi7/vEygqCgz4cEDfN9AvSjP5S9gxb2na3xJr/mIZd Noot8eFqowLNTezuBTDEB5iDTEG7fYVME1v2biaYZHHgJC79Gb6BdpqBFR08RItbwyC7 zxqD2QoK4hJTfZXB/0TKLMe+VUfx2b9iHEc/VR/RVROscYCjjEuHRXWkHvg8DwXX8n2H y0Vw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qOAVfv0G; 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 af79cd13be357-7a67f400046si453235385a.412.2024.08.25.07.53.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 25 Aug 2024 07:53:37 -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=qOAVfv0G; 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 1siEc0-0002rV-NY; Sun, 25 Aug 2024 10:53:00 -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 1siEby-0002j8-He for qemu-devel@nongnu.org; Sun, 25 Aug 2024 10:52:58 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1siEbw-0005vb-Su for qemu-devel@nongnu.org; Sun, 25 Aug 2024 10:52:58 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-7141feed424so2908058b3a.2 for ; Sun, 25 Aug 2024 07:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724597575; x=1725202375; 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=NQhqFC3YWlPkCJwXValvIiJxyZnEMyHcDzM+YKLmAFI=; b=qOAVfv0GtWTKRl/q0MSkhCdxJSuAGef44rQOrCYoTj7mRyPUp7JU9G5KX6msxVsACx r1pJdSCjoViSkv+xoHvi3bfZqTn5F/rFyhsFUxhB4fDqbTISQB2X4hxPc3czbPo9rrPq sNDCBh6F+jo2CB8BVG6smYCdQ4k8/ZZ4L5PdAu3JtO0t3HmCW5AXYpH67Aj0NCrTHCiv Tet1hT4xWSGwM5zn72QgSfGC3Tw8T3vCucoKZPnJyICQzzWZMIQxHRr67kwcZKOijDCv eIHdraalqvfGBQVgm0+ahtmBOTTQfpZJ2TXRWYsjy6EwfGT/h7XdrlBmkuRaIjAdRC0Q l/Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724597575; x=1725202375; 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=NQhqFC3YWlPkCJwXValvIiJxyZnEMyHcDzM+YKLmAFI=; b=UQ89UvVVAfpE1j/7fce+sMqNAEECKbQRDMyODb7OiMYMkhuehJKvvl20so5gsRiwXw 6bH7gcYaSNjfgrQjeqXkjcRmn75A4X5BOP2tCWl23TfC2bA+vhzvC33rCascBcMB1C06 diADCejmJ2O53RLLAJgFoqpWJpsT3owlLW+FyUf/sTa6YtbwzU/CpaERXuzAM68ydPr0 Dxkt0XcUmdfkEsf8g0BXvYvndSlBYC3AnRXzCmzNZj01+zswTwz67s+FqPBqb3fGnr/O k0Wzc73svdWguWmo6A4U9FKaF6PKWIrvJ3LW3Pen0tSeaY2F0qyxMH0YII5R9PL9DtXg Z/yg== X-Gm-Message-State: AOJu0Yzw2Ys2V1Ez1XTg/mN1MvzG4P5JuyOVX3Y3bmO4MqT4/FF+VnQ/ jJC7e+PoWnEZABt7UyZruYjFnUyckyYjE4vsik5xsCCNTumEbmyGivCq63tHilGJQx6TdTCkjIr 2WkU= X-Received: by 2002:a05:6a21:3a46:b0:1c6:b0cc:c50f with SMTP id adf61e73a8af0-1cc8b49ba5dmr7208201637.25.1724597574608; Sun, 25 Aug 2024 07:52:54 -0700 (PDT) Received: from amd.. ([2804:7f0:b400:bb79:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203b0e164b8sm24698805ad.236.2024.08.25.07.52.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2024 07:52:54 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: philmd@linaro.org, peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v3 3/4] tests/guest-debug: Support passing arguments to the GDB test script Date: Sun, 25 Aug 2024 14:52:07 +0000 Message-Id: <20240825145208.46774-4-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240825145208.46774-1-gustavo.romero@linaro.org> References: <20240825145208.46774-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x42b.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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 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 --- 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"""