kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu
Cc: maz@kernel.org, ricarkol@google.com, eric.auger@redhat.com,
	alexandru.elisei@arm.com, pbonzini@redhat.com
Subject: [PATCH 4/6] KVM: arm64: selftests: get-reg-list: Provide config selection option
Date: Fri,  7 May 2021 22:04:14 +0200	[thread overview]
Message-ID: <20210507200416.198055-5-drjones@redhat.com> (raw)
In-Reply-To: <20210507200416.198055-1-drjones@redhat.com>

Add a new command line option that allows the user to select a specific
configuration, e.g. --config:sve will give the sve config. Also provide
help text and the --help/-h options.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 .../selftests/kvm/aarch64/get-reg-list.c      | 76 +++++++++++++++++--
 1 file changed, 70 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/kvm/aarch64/get-reg-list.c b/tools/testing/selftests/kvm/aarch64/get-reg-list.c
index 68d3be86d490..f5e122b6b257 100644
--- a/tools/testing/selftests/kvm/aarch64/get-reg-list.c
+++ b/tools/testing/selftests/kvm/aarch64/get-reg-list.c
@@ -38,6 +38,17 @@
 #define reg_list_sve() (false)
 #endif
 
+enum {
+	VREGS,
+	SVE,
+};
+
+static char * const vcpu_config_names[] = {
+	[VREGS] = "vregs",
+	[SVE] = "sve",
+	NULL
+};
+
 static struct kvm_reg_list *reg_list;
 static __u64 *blessed_reg, blessed_n;
 
@@ -502,34 +513,87 @@ static void run_test(struct vcpu_config *c)
 	kvm_vm_free(vm);
 }
 
+static void help(void)
+{
+	char * const *n;
+
+	printf(
+	"\n"
+	"usage: get-reg-list [--config:<selection>[,<selection>...]] [--list] [--list-filtered] [--core-reg-fixup]\n\n"
+	" --config:<selection>[,<selection>...] Used to select a specific vcpu configuration for the test/listing\n"
+	"                                       '<selection>' may be\n");
+
+	for (n = &vcpu_config_names[0]; *n; ++n)
+	printf("                                         '%s'\n", *n);
+
+	printf(
+	"\n"
+	" --list                                Print the register list rather than test it (requires --config)\n"
+	" --list-filtered                       Print registers that would normally be filtered out (requires --config)\n"
+	" --core-reg-fixup                      Needed when running on old kernels with broken core reg listings\n"
+	"\n"
+	);
+}
+
+static struct vcpu_config *parse_config(const char *config)
+{
+	struct vcpu_config *c = NULL;
+	int i;
+
+	if (config[8] != ':')
+		help(), exit(1);
+
+	for (i = 0; i < ARRAY_SIZE(vcpu_config_names) - 1; ++i) {
+		if (strcmp(vcpu_config_names[i], &config[9]) == 0) {
+			c = vcpu_configs[i];
+			break;
+		}
+	}
+
+	if (!c)
+		help(), exit(1);
+
+	return c;
+}
+
 int main(int ac, char **av)
 {
-	struct vcpu_config *c;
+	struct vcpu_config *c = NULL;
 	bool print_list = false, print_filtered = false;
 	int i;
 
 	for (i = 1; i < ac; ++i) {
 		if (strcmp(av[i], "--core-reg-fixup") == 0)
 			fixup_core_regs = true;
+		else if (strncmp(av[i], "--config", 8) == 0)
+			c = parse_config(av[i]);
 		else if (strcmp(av[i], "--list") == 0)
 			print_list = true;
 		else if (strcmp(av[i], "--list-filtered") == 0)
 			print_filtered = true;
+		else if (strcmp(av[i], "--help") == 0 || strcmp(av[1], "-h") == 0)
+			help(), exit(0);
 		else
-			TEST_FAIL("Unknown option: %s\n", av[i]);
+			help(), exit(1);
 	}
 
 	if (print_list || print_filtered) {
 		/*
 		 * We only want to print the register list of a single config.
-		 * TODO: Add command line support to pick which config.
 		 */
-		c = vcpu_configs[0];
+		if (!c)
+			help(), exit(1);
 		check_supported(c);
 		print_reg_list(c, print_list, print_filtered);
 		return 0;
 	}
 
+	if (c) {
+		check_supported(c);
+		run_test(c);
+		return 0;
+	}
+
 	for (i = 0, c = vcpu_configs[0]; c; ++i, c = vcpu_configs[i]) {
 		check_supported(c);
 		run_test(c);
@@ -917,7 +981,7 @@ static __u64 sve_rejects_set[] = {
 };
 
 static struct vcpu_config vregs_config = {
-	"vregs",
+	vcpu_config_names[VREGS],
 	.sublists = {
 	{ base_regs,	ARRAY_SIZE(base_regs), },
 	{ vregs,	ARRAY_SIZE(vregs), },
@@ -925,7 +989,7 @@ static struct vcpu_config vregs_config = {
 	},
 };
 static struct vcpu_config sve_config = {
-	"sve", .sve = true,
+	vcpu_config_names[SVE], .sve = true,
 	.sublists = {
 	{ base_regs,	ARRAY_SIZE(base_regs), },
 	{ sve_regs,	ARRAY_SIZE(sve_regs),	sve_rejects_set,	ARRAY_SIZE(sve_rejects_set), },
-- 
2.30.2


  parent reply	other threads:[~2021-05-07 20:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-07 20:04 [PATCH 0/6] KVM: arm64: selftests: Fix get-reg-list Andrew Jones
2021-05-07 20:04 ` [PATCH 1/6] KVM: arm64: selftests: get-reg-list: Factor out printing Andrew Jones
2021-05-07 20:04 ` [PATCH 2/6] KVM: arm64: selftests: get-reg-list: Introduce vcpu configs Andrew Jones
2021-05-07 20:04 ` [PATCH 3/6] KVM: arm64: selftests: get-reg-list: Prepare to run multiple configs at once Andrew Jones
2021-05-07 20:04 ` Andrew Jones [this message]
2021-05-10  6:40   ` [PATCH 4/6] KVM: arm64: selftests: get-reg-list: Provide config selection option Andrew Jones
2021-05-07 20:04 ` [PATCH 5/6] KVM: arm64: selftests: get-reg-list: Remove get-reg-list-sve Andrew Jones
2021-05-07 20:04 ` [PATCH 6/6] KVM: arm64: selftests: get-reg-list: Split base and pmu registers Andrew Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210507200416.198055-5-drjones@redhat.com \
    --to=drjones@redhat.com \
    --cc=alexandru.elisei@arm.com \
    --cc=eric.auger@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=maz@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=ricarkol@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).