diff mbox series

[5/7] kvm: selftests: dirty_log_test: improve mode param management

Message ID 20181106135712.9059-6-drjones@redhat.com (mailing list archive)
State New, archived
Headers show
Series kvm: selftests: dirty_log_test: test with high GPAs | expand

Commit Message

Andrew Jones Nov. 6, 2018, 1:57 p.m. UTC
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 tools/testing/selftests/kvm/dirty_log_test.c | 48 ++++++++++----------
 1 file changed, 23 insertions(+), 25 deletions(-)

Comments

Radim Krčmář Dec. 20, 2018, 8:30 p.m. UTC | #1
2018-11-06 14:57+0100, Andrew Jones:
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
> diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
> @@ -353,23 +353,16 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
>  	kvm_vm_free(vm);
>  }
>  
> -static struct vm_guest_modes {
> -	enum vm_guest_mode mode;
> +struct vm_guest_mode_params {
>  	bool supported;
>  	bool enabled;
> -} vm_guest_modes[NUM_VM_MODES] = {
> -#if defined(__x86_64__)
> -	{ VM_MODE_P52V48_4K,	1, 1, },
> -	{ VM_MODE_P52V48_64K,	0, 0, },
> -	{ VM_MODE_P40V48_4K,	0, 0, },
> -	{ VM_MODE_P40V48_64K,	0, 0, },
> -#elif defined(__aarch64__)
> -	{ VM_MODE_P52V48_4K,	0, 0, },
> -	{ VM_MODE_P52V48_64K,	0, 0, },
> -	{ VM_MODE_P40V48_4K,	1, 1, },
> -	{ VM_MODE_P40V48_64K,	1, 1, },
> -#endif
>  };
> +struct vm_guest_mode_params vm_guest_mode_params[NUM_VM_MODES];
> +
> +#define vm_guest_mode_params_init(mode, supported, enabled)					\
> +({												\
> +	vm_guest_mode_params[mode] = (struct vm_guest_mode_params){ supported, enabled };	\
> +})

Backing the modes with a constant array is even uglier now that we don't
hard code it in one place.  The compiler should still protest if we
forget to change the bounds, so I've applied the whole series as the
mode_init interface is simple to improve upon,

thanks.
diff mbox series

Patch

diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
index eaa0b159d5ae..9d3a52562682 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -353,23 +353,16 @@  static void run_test(enum vm_guest_mode mode, unsigned long iterations,
 	kvm_vm_free(vm);
 }
 
-static struct vm_guest_modes {
-	enum vm_guest_mode mode;
+struct vm_guest_mode_params {
 	bool supported;
 	bool enabled;
-} vm_guest_modes[NUM_VM_MODES] = {
-#if defined(__x86_64__)
-	{ VM_MODE_P52V48_4K,	1, 1, },
-	{ VM_MODE_P52V48_64K,	0, 0, },
-	{ VM_MODE_P40V48_4K,	0, 0, },
-	{ VM_MODE_P40V48_64K,	0, 0, },
-#elif defined(__aarch64__)
-	{ VM_MODE_P52V48_4K,	0, 0, },
-	{ VM_MODE_P52V48_64K,	0, 0, },
-	{ VM_MODE_P40V48_4K,	1, 1, },
-	{ VM_MODE_P40V48_64K,	1, 1, },
-#endif
 };
+struct vm_guest_mode_params vm_guest_mode_params[NUM_VM_MODES];
+
+#define vm_guest_mode_params_init(mode, supported, enabled)					\
+({												\
+	vm_guest_mode_params[mode] = (struct vm_guest_mode_params){ supported, enabled };	\
+})
 
 static void help(char *name)
 {
@@ -390,10 +383,8 @@  static void help(char *name)
 	       "     This option may be used multiple times.\n"
 	       "     Guest mode IDs:\n");
 	for (i = 0; i < NUM_VM_MODES; ++i) {
-		printf("         %d:    %s%s\n",
-		       vm_guest_modes[i].mode,
-		       vm_guest_mode_string(vm_guest_modes[i].mode),
-		       vm_guest_modes[i].supported ? " (supported)" : "");
+		printf("         %d:    %s%s\n", i, vm_guest_mode_string(i),
+		       vm_guest_mode_params[i].supported ? " (supported)" : "");
 	}
 	puts("");
 	exit(0);
@@ -408,6 +399,14 @@  int main(int argc, char *argv[])
 	unsigned int mode;
 	int opt, i;
 
+#ifdef __x86_64__
+	vm_guest_mode_params_init(VM_MODE_P52V48_4K, true, true);
+#endif
+#ifdef __aarch64__
+	vm_guest_mode_params_init(VM_MODE_P40V48_4K, true, true);
+	vm_guest_mode_params_init(VM_MODE_P40V48_64K, true, true);
+#endif
+
 	while ((opt = getopt(argc, argv, "hi:I:p:m:")) != -1) {
 		switch (opt) {
 		case 'i':
@@ -422,13 +421,13 @@  int main(int argc, char *argv[])
 		case 'm':
 			if (!mode_selected) {
 				for (i = 0; i < NUM_VM_MODES; ++i)
-					vm_guest_modes[i].enabled = 0;
+					vm_guest_mode_params[i].enabled = false;
 				mode_selected = true;
 			}
 			mode = strtoul(optarg, NULL, 10);
 			TEST_ASSERT(mode < NUM_VM_MODES,
 				    "Guest mode ID %d too big", mode);
-			vm_guest_modes[mode].enabled = 1;
+			vm_guest_mode_params[mode].enabled = true;
 			break;
 		case 'h':
 		default:
@@ -446,13 +445,12 @@  int main(int argc, char *argv[])
 	srandom(time(0));
 
 	for (i = 0; i < NUM_VM_MODES; ++i) {
-		if (!vm_guest_modes[i].enabled)
+		if (!vm_guest_mode_params[i].enabled)
 			continue;
-		TEST_ASSERT(vm_guest_modes[i].supported,
+		TEST_ASSERT(vm_guest_mode_params[i].supported,
 			    "Guest mode ID %d (%s) not supported.",
-			    vm_guest_modes[i].mode,
-			    vm_guest_mode_string(vm_guest_modes[i].mode));
-		run_test(vm_guest_modes[i].mode, iterations, interval, phys_offset);
+			    i, vm_guest_mode_string(i));
+		run_test(i, iterations, interval, phys_offset);
 	}
 
 	return 0;