diff mbox series

[kvm-unit-tests,3/4] x86: hyper-v: Use 'goto' instead of putting the whole test in an 'if' branch in hyperv_synic

Message ID 20231025152915.1879661-4-vkuznets@redhat.com (mailing list archive)
State New, archived
Headers show
Series x86: hyper-v: Add support for CONFIG_KVM_HYPERV | expand

Commit Message

Vitaly Kuznetsov Oct. 25, 2023, 3:29 p.m. UTC
Unify 'hyperv_synic' test with other Hyper-V tests by using the:

 if (required-features-missing) {
    report_skip();
    goto done;
 }
 ...

 done:
     return report_summary();

pattern.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 x86/hyperv_synic.c | 61 +++++++++++++++++++++++-----------------------
 1 file changed, 31 insertions(+), 30 deletions(-)
diff mbox series

Patch

diff --git a/x86/hyperv_synic.c b/x86/hyperv_synic.c
index 9d61d8362ebd..ae57f1c5faac 100644
--- a/x86/hyperv_synic.c
+++ b/x86/hyperv_synic.c
@@ -141,45 +141,46 @@  static void synic_test_cleanup(void *ctx)
 
 int main(int ac, char **av)
 {
+    int ncpus, i;
+    bool ok;
 
-    if (synic_supported()) {
-        int ncpus, i;
-        bool ok;
-
-        setup_vm();
-        enable_apic();
+    if (!synic_supported()) {
+	report_skip("Hyper-V SynIC is not supported");
+	goto done;
+    }
 
-        ncpus = cpu_count();
-        if (ncpus > MAX_CPUS)
-            report_abort("number cpus exceeds %d", MAX_CPUS);
-        printf("ncpus = %d\n", ncpus);
+    setup_vm();
+    enable_apic();
 
-        synic_prepare_sint_vecs();
+    ncpus = cpu_count();
+    if (ncpus > MAX_CPUS)
+	report_abort("number cpus exceeds %d", MAX_CPUS);
+    printf("ncpus = %d\n", ncpus);
 
-        printf("prepare\n");
-        on_cpus(synic_test_prepare, (void *)read_cr3());
+    synic_prepare_sint_vecs();
 
-        for (i = 0; i < ncpus; i++) {
-            printf("test %d -> %d\n", i, ncpus - 1 - i);
-            on_cpu_async(i, synic_test, (void *)(ulong)(ncpus - 1 - i));
-        }
-        while (cpus_active() > 1)
-            pause();
+    printf("prepare\n");
+    on_cpus(synic_test_prepare, (void *)read_cr3());
 
-        printf("cleanup\n");
-        on_cpus(synic_test_cleanup, NULL);
+    for (i = 0; i < ncpus; i++) {
+	printf("test %d -> %d\n", i, ncpus - 1 - i);
+	on_cpu_async(i, synic_test, (void *)(ulong)(ncpus - 1 - i));
+    }
+    while (cpus_active() > 1)
+	pause();
 
-        ok = true;
-        for (i = 0; i < ncpus; ++i) {
-            printf("isr_enter_count[%d] = %d\n",
-                   i, atomic_read(&isr_enter_count[i]));
-            ok &= atomic_read(&isr_enter_count[i]) == 16;
-        }
+    printf("cleanup\n");
+    on_cpus(synic_test_cleanup, NULL);
 
-        report(ok, "Hyper-V SynIC test");
-    } else {
-        printf("Hyper-V SynIC is not supported");
+    ok = true;
+    for (i = 0; i < ncpus; ++i) {
+	printf("isr_enter_count[%d] = %d\n",
+	       i, atomic_read(&isr_enter_count[i]));
+	ok &= atomic_read(&isr_enter_count[i]) == 16;
     }
 
+    report(ok, "Hyper-V SynIC test");
+
+done:
     return report_summary();
 }