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 3/6] KVM: arm64: selftests: get-reg-list: Prepare to run multiple configs at once
Date: Fri,  7 May 2021 22:04:13 +0200	[thread overview]
Message-ID: <20210507200416.198055-4-drjones@redhat.com> (raw)
In-Reply-To: <20210507200416.198055-1-drjones@redhat.com>

We don't want to have to create a new binary for each vcpu config, so
prepare to run the test for multiple vcpu configs in a single binary.
We do this by factoring out the test from main() and then looping over
configs. When given '--list' we still never print more than a single
reg-list for a single vcpu config though, because it would be confusing
otherwise.

No functional change intended.

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

diff --git a/tools/testing/selftests/kvm/aarch64/get-reg-list.c b/tools/testing/selftests/kvm/aarch64/get-reg-list.c
index fbbeee634722..68d3be86d490 100644
--- a/tools/testing/selftests/kvm/aarch64/get-reg-list.c
+++ b/tools/testing/selftests/kvm/aarch64/get-reg-list.c
@@ -54,8 +54,7 @@ struct vcpu_config {
 	struct reg_sublist sublists[];
 };
 
-static struct vcpu_config vregs_config;
-static struct vcpu_config sve_config;
+static struct vcpu_config *vcpu_configs[];
 
 #define for_each_sublist(c, s)							\
 	for ((s) = &(c)->sublists[0]; (s)->regs; ++(s))
@@ -386,35 +385,18 @@ static void print_reg_list(struct vcpu_config *c, bool print_list, bool print_fi
 			print_reg(c, id);
 	}
 	putchar('\n');
+
+	free(reg_list);
+	kvm_vm_free(vm);
 }
 
-int main(int ac, char **av)
+static void run_test(struct vcpu_config *c)
 {
-	struct vcpu_config *c = reg_list_sve() ? &sve_config : &vregs_config;
 	int new_regs = 0, missing_regs = 0, i, n;
 	int failed_get = 0, failed_set = 0, failed_reject = 0;
-	bool print_list = false, print_filtered = false;
 	struct kvm_vm *vm;
 	struct reg_sublist *s;
 
-	check_supported(c);
-
-	for (i = 1; i < ac; ++i) {
-		if (strcmp(av[i], "--core-reg-fixup") == 0)
-			fixup_core_regs = true;
-		else if (strcmp(av[i], "--list") == 0)
-			print_list = true;
-		else if (strcmp(av[i], "--list-filtered") == 0)
-			print_filtered = true;
-		else
-			TEST_FAIL("Unknown option: %s\n", av[i]);
-	}
-
-	if (print_list || print_filtered) {
-		print_reg_list(c, print_list, print_filtered);
-		return 0;
-	}
-
 	vm = vm_create(VM_MODE_DEFAULT, DEFAULT_GUEST_PHY_PAGES, O_RDWR);
 	reg_list_init(vm, c);
 
@@ -514,6 +496,45 @@ int main(int ac, char **av)
 		    "%d registers failed get; %d registers failed set; %d registers failed reject",
 		    c->name, missing_regs, failed_get, failed_set, failed_reject);
 
+	blessed_n = 0;
+	free(blessed_reg);
+	free(reg_list);
+	kvm_vm_free(vm);
+}
+
+int main(int ac, char **av)
+{
+	struct vcpu_config *c;
+	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 (strcmp(av[i], "--list") == 0)
+			print_list = true;
+		else if (strcmp(av[i], "--list-filtered") == 0)
+			print_filtered = true;
+		else
+			TEST_FAIL("Unknown option: %s\n", av[i]);
+	}
+
+	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];
+		check_supported(c);
+		print_reg_list(c, print_list, print_filtered);
+		return 0;
+	}
+
+	for (i = 0, c = vcpu_configs[0]; c; ++i, c = vcpu_configs[i]) {
+		check_supported(c);
+		run_test(c);
+	}
+
 	return 0;
 }
 
@@ -911,3 +932,8 @@ static struct vcpu_config sve_config = {
 	{0},
 	},
 };
+
+static struct vcpu_config *vcpu_configs[] = {
+	reg_list_sve() ? &sve_config : &vregs_config,
+	NULL
+};
-- 
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 ` Andrew Jones [this message]
2021-05-07 20:04 ` [PATCH 4/6] KVM: arm64: selftests: get-reg-list: Provide config selection option Andrew Jones
2021-05-10  6:40   ` 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-4-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).