Commit 7ed397d1 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini
Browse files

KVM: selftests: Add TEST_REQUIRE macros to reduce skipping copy+paste



Add TEST_REQUIRE() and __TEST_REQUIRE() to replace the myriad open coded
instances of selftests exiting with KSFT_SKIP after printing an
informational message.  In addition to reducing the amount of boilerplate
code in selftests, the UPPERCASE macro names make it easier to visually
identify a test's requirements.

Convert usage that erroneously uses something other than print_skip()
and/or "exits" with '0' or some other non-KSFT_SKIP value.

Intentionally drop a kvm_vm_free() in aarch64/debug-exceptions.c as part
of the conversion.  All memory and file descriptors are freed on process
exit, so the explicit free is superfluous.

Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 3ea9b809
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -375,10 +375,7 @@ static struct kvm_vm *test_vm_create(void)
	ucall_init(vm, NULL);
	test_init_timer_irq(vm);
	gic_fd = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
	if (gic_fd < 0) {
		print_skip("Failed to create vgic-v3");
		exit(KSFT_SKIP);
	}
	__TEST_REQUIRE(gic_fd >= 0, "Failed to create vgic-v3");

	/* Make all the test's cmdline args visible to the guest */
	sync_global_to_guest(vm, test_args);
@@ -468,10 +465,8 @@ int main(int argc, char *argv[])
	if (!parse_args(argc, argv))
		exit(KSFT_SKIP);

	if (test_args.migration_freq_ms && get_nprocs() < 2) {
		print_skip("At least two physical CPUs needed for vCPU migration");
		exit(KSFT_SKIP);
	}
	__TEST_REQUIRE(!test_args.migration_freq_ms || get_nprocs() >= 2,
		       "At least two physical CPUs needed for vCPU migration");

	vm = test_vm_create();
	test_run(vm);
+2 −5
Original line number Diff line number Diff line
@@ -259,11 +259,8 @@ int main(int argc, char *argv[])
	vm_init_descriptor_tables(vm);
	vcpu_init_descriptor_tables(vcpu);

	if (debug_version(vcpu) < 6) {
		print_skip("Armv8 debug architecture not supported.");
		kvm_vm_free(vm);
		exit(KSFT_SKIP);
	}
	__TEST_REQUIRE(debug_version(vcpu) >= 6,
		       "Armv8 debug architecture not supported.");

	vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT,
				ESR_EC_BRK_INS, guest_sw_bp_handler);
+6 −4
Original line number Diff line number Diff line
@@ -395,10 +395,12 @@ static void check_supported(struct vcpu_config *c)
	struct reg_sublist *s;

	for_each_sublist(c, s) {
		if (s->capability && !kvm_has_cap(s->capability)) {
			fprintf(stderr, "%s: %s not available, skipping tests\n", config_name(c), s->name);
			exit(KSFT_SKIP);
		}
		if (!s->capability)
			continue;

		__TEST_REQUIRE(kvm_has_cap(s->capability),
			       "%s: %s not available, skipping tests\n",
			       config_name(c), s->name);
	}
}

+1 −4
Original line number Diff line number Diff line
@@ -192,10 +192,7 @@ static void host_test_system_suspend(void)

int main(void)
{
	if (!kvm_check_cap(KVM_CAP_ARM_SYSTEM_SUSPEND)) {
		print_skip("KVM_CAP_ARM_SYSTEM_SUSPEND not supported");
		exit(KSFT_SKIP);
	}
	TEST_REQUIRE(kvm_check_cap(KVM_CAP_ARM_SYSTEM_SUSPEND));

	host_test_cpu_on();
	host_test_system_suspend();
+1 −4
Original line number Diff line number Diff line
@@ -82,10 +82,7 @@ int main(void)
	struct kvm_vm *vm;
	int ret;

	if (!kvm_has_cap(KVM_CAP_ARM_EL1_32BIT)) {
		print_skip("KVM_CAP_ARM_EL1_32BIT is not supported");
		exit(KSFT_SKIP);
	}
	TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_EL1_32BIT));

	/* Get the preferred target type and copy that to init1 for later use */
	vm = vm_create_barebones();
Loading