Re: [PATCH v2 143/144] KVM: selftests: Add TEST_REQUIRE macros to reduce skipping copy+paste

Andrew Jones
2022-06-10T18:29:40Z

On Fri, Jun 03, 2022 at 12:43:30AM +0000, Sean Christopherson wrote:
...
> diff --git a/tools/testing/selftests/kvm/x86_64/get_msr_index_features.c b/tools/testing/selftests/kvm/x86_64/get_msr_index_features.c
> index 1e366fdfe7be..d09b3cbcadc6 100644
> --- a/tools/testing/selftests/kvm/x86_64/get_msr_index_features.c
> +++ b/tools/testing/selftests/kvm/x86_64/get_msr_index_features.c
> @@ -25,10 +25,7 @@ int main(int argc, char *argv[])
> * will cover the "regular" list of MSRs, the coverage here is purely
> * opportunistic and not interesting on its own.
> */
> - if (!kvm_check_cap(KVM_CAP_GET_MSR_FEATURES)) {

I guess this one was missed on the initial conversion of kvm_check_cap to
kvm_has_cap, but it doesn't matter.

> - print_skip("KVM_CAP_GET_MSR_FEATURES not supported");
> - exit(KSFT_SKIP);
> - }
> + TEST_REQUIRE(kvm_has_cap(KVM_CAP_GET_MSR_FEATURES));
>
> (void)kvm_get_msr_index_list();
>
...
> @@ -70,17 +70,12 @@ int main(int argc, char *argv[])
> {
> struct kvm_vcpu *vcpu;
> struct kvm_vm *vm;
> - int rv;
> uint64_t msr_platform_info;
>
> /* Tell stdout not to buffer its content */
> setbuf(stdout, NULL);
>
> - rv = kvm_check_cap(KVM_CAP_MSR_PLATFORM_INFO);

Also missed and also doesn't matter.

> - if (!rv) {
> - print_skip("KVM_CAP_MSR_PLATFORM_INFO not supported");
> - exit(KSFT_SKIP);
> - }
> + TEST_REQUIRE(kvm_has_cap(KVM_CAP_MSR_PLATFORM_INFO));
>
> vm = vm_create_with_one_vcpu(&vcpu, guest_code);
>
> diff --git a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c
> index ffa6a2f93de2..de9ee00d84cf 100644
> --- a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c
> @@ -417,39 +417,24 @@ static bool use_amd_pmu(void)
>
> int main(int argc, char *argv[])
> {
> - void (*guest_code)(void) = NULL;
> + void (*guest_code)(void);
> struct kvm_vcpu *vcpu;
> struct kvm_vm *vm;
> - int r;
>
> /* Tell stdout not to buffer its content */
> setbuf(stdout, NULL);
>
> - r = kvm_check_cap(KVM_CAP_PMU_EVENT_FILTER);

Also missed and ...

> - if (!r) {
> - print_skip("KVM_CAP_PMU_EVENT_FILTER not supported");
> - exit(KSFT_SKIP);
> - }
> + TEST_REQUIRE(kvm_check_cap(KVM_CAP_PMU_EVENT_FILTER));

... got carried into the TEST_REQUIRE, so it sort of matters.

Thanks,
drew