Skip to content

Commit 94e9223

Browse files
Andrew JonesMarc Zyngier
authored andcommitted
KVM: arm64: selftests: get-reg-list: Prepare to run multiple configs at once
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> Reviewed-by: Ricardo Koller <ricarkol@google.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20210531103344.29325-3-drjones@redhat.com
1 parent 2f9ace5 commit 94e9223

1 file changed

Lines changed: 51 additions & 17 deletions

File tree

tools/testing/selftests/kvm/aarch64/get-reg-list.c

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ struct vcpu_config {
5656
struct reg_sublist sublists[];
5757
};
5858

59-
static struct vcpu_config vregs_config;
60-
static struct vcpu_config sve_config;
59+
static struct vcpu_config *vcpu_configs[];
60+
static int vcpu_configs_n;
6161

6262
#define for_each_sublist(c, s) \
6363
for ((s) = &(c)->sublists[0]; (s)->regs; ++(s))
@@ -400,29 +400,20 @@ static void check_supported(struct vcpu_config *c)
400400
}
401401
}
402402

403-
int main(int ac, char **av)
403+
static bool print_list;
404+
static bool print_filtered;
405+
static bool fixup_core_regs;
406+
407+
static void run_test(struct vcpu_config *c)
404408
{
405-
struct vcpu_config *c = reg_list_sve() ? &sve_config : &vregs_config;
406409
struct kvm_vcpu_init init = { .target = -1, };
407410
int new_regs = 0, missing_regs = 0, i, n;
408411
int failed_get = 0, failed_set = 0, failed_reject = 0;
409-
bool print_list = false, print_filtered = false, fixup_core_regs = false;
410412
struct kvm_vm *vm;
411413
struct reg_sublist *s;
412414

413415
check_supported(c);
414416

415-
for (i = 1; i < ac; ++i) {
416-
if (strcmp(av[i], "--core-reg-fixup") == 0)
417-
fixup_core_regs = true;
418-
else if (strcmp(av[i], "--list") == 0)
419-
print_list = true;
420-
else if (strcmp(av[i], "--list-filtered") == 0)
421-
print_filtered = true;
422-
else
423-
TEST_FAIL("Unknown option: %s\n", av[i]);
424-
}
425-
426417
vm = vm_create(VM_MODE_DEFAULT, DEFAULT_GUEST_PHY_PAGES, O_RDWR);
427418
prepare_vcpu_init(c, &init);
428419
aarch64_vcpu_add_default(vm, 0, &init, NULL);
@@ -442,7 +433,7 @@ int main(int ac, char **av)
442433
print_reg(c, id);
443434
}
444435
putchar('\n');
445-
return 0;
436+
return;
446437
}
447438

448439
/*
@@ -541,6 +532,44 @@ int main(int ac, char **av)
541532
"%d registers failed get; %d registers failed set; %d registers failed reject",
542533
config_name(c), missing_regs, failed_get, failed_set, failed_reject);
543534

535+
pr_info("%s: PASS\n", config_name(c));
536+
blessed_n = 0;
537+
free(blessed_reg);
538+
free(reg_list);
539+
kvm_vm_free(vm);
540+
}
541+
542+
int main(int ac, char **av)
543+
{
544+
struct vcpu_config *c, *sel = NULL;
545+
int i;
546+
547+
for (i = 1; i < ac; ++i) {
548+
if (strcmp(av[i], "--core-reg-fixup") == 0)
549+
fixup_core_regs = true;
550+
else if (strcmp(av[i], "--list") == 0)
551+
print_list = true;
552+
else if (strcmp(av[i], "--list-filtered") == 0)
553+
print_filtered = true;
554+
else
555+
TEST_FAIL("Unknown option: %s\n", av[i]);
556+
}
557+
558+
if (print_list || print_filtered) {
559+
/*
560+
* We only want to print the register list of a single config.
561+
* TODO: Add command line support to pick which config.
562+
*/
563+
sel = vcpu_configs[0];
564+
}
565+
566+
for (i = 0; i < vcpu_configs_n; ++i) {
567+
c = vcpu_configs[i];
568+
if (sel && c != sel)
569+
continue;
570+
run_test(c);
571+
}
572+
544573
return 0;
545574
}
546575

@@ -945,3 +974,8 @@ static struct vcpu_config sve_config = {
945974
{0},
946975
},
947976
};
977+
978+
static struct vcpu_config *vcpu_configs[] = {
979+
reg_list_sve() ? &sve_config : &vregs_config,
980+
};
981+
static int vcpu_configs_n = ARRAY_SIZE(vcpu_configs);

0 commit comments

Comments
 (0)