[kvm-unit-tests PATCH 11/14] x86: Prepare access test for running in L2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Move main out of access.c in preparation for running the test in L2.
This allows access.c to be used as common code that will be
included in a nested tests later in this series.

Signed-off-by: Aaron Lewis <aaronlewis@xxxxxxxxxx>
---
 x86/Makefile.common |  2 ++
 x86/Makefile.x86_64 |  2 +-
 x86/access.c        | 24 +++---------------------
 x86/access.h        |  8 ++++++++
 x86/access_test.c   | 22 ++++++++++++++++++++++
 x86/unittests.cfg   |  4 ++--
 6 files changed, 38 insertions(+), 24 deletions(-)
 create mode 100644 x86/access.h
 create mode 100644 x86/access_test.c

diff --git a/x86/Makefile.common b/x86/Makefile.common
index 52bb7aa..a665854 100644
--- a/x86/Makefile.common
+++ b/x86/Makefile.common
@@ -72,6 +72,8 @@ $(TEST_DIR)/realmode.elf: $(TEST_DIR)/realmode.o
 
 $(TEST_DIR)/realmode.o: bits = $(if $(call cc-option,-m16,""),16,32)
 
+$(TEST_DIR)/access_test.elf: $(TEST_DIR)/access.o
+
 $(TEST_DIR)/kvmclock_test.elf: $(TEST_DIR)/kvmclock.o
 
 $(TEST_DIR)/hyperv_synic.elf: $(TEST_DIR)/hyperv.o
diff --git a/x86/Makefile.x86_64 b/x86/Makefile.x86_64
index 8134952..390d0e9 100644
--- a/x86/Makefile.x86_64
+++ b/x86/Makefile.x86_64
@@ -9,7 +9,7 @@ cflatobjs += lib/x86/setjmp64.o
 cflatobjs += lib/x86/intel-iommu.o
 cflatobjs += lib/x86/usermode.o
 
-tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \
+tests = $(TEST_DIR)/access_test.flat $(TEST_DIR)/apic.flat \
 	  $(TEST_DIR)/emulator.flat $(TEST_DIR)/idt_test.flat \
 	  $(TEST_DIR)/xsave.flat $(TEST_DIR)/rmap_chain.flat \
 	  $(TEST_DIR)/pcid.flat $(TEST_DIR)/debug.flat \
diff --git a/x86/access.c b/x86/access.c
index 8e3a718..de6726e 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -1,9 +1,9 @@
-
 #include "libcflat.h"
 #include "desc.h"
 #include "processor.h"
 #include "asm/page.h"
 #include "x86/vm.h"
+#include "access.h"
 
 #define smp_id() 0
 
@@ -14,7 +14,7 @@ static _Bool verbose = false;
 
 typedef unsigned long pt_element_t;
 static int invalid_mask;
-static int page_table_levels;
+int page_table_levels;
 
 #define PT_BASE_ADDR_MASK ((pt_element_t)((((pt_element_t)1 << 36) - 1) & PAGE_MASK))
 #define PT_PSE_BASE_ADDR_MASK (PT_BASE_ADDR_MASK & ~(1ull << 21))
@@ -1069,7 +1069,7 @@ const ac_test_fn ac_test_cases[] =
 	check_effective_sp_permissions,
 };
 
-static int ac_test_run(void)
+int ac_test_run()
 {
     ac_test_t at;
     ac_pool_t pool;
@@ -1150,21 +1150,3 @@ static int ac_test_run(void)
 
     return successes == tests;
 }
-
-int main(void)
-{
-    int r;
-
-    printf("starting test\n\n");
-    page_table_levels = 4;
-    r = ac_test_run();
-
-    if (this_cpu_has(X86_FEATURE_LA57)) {
-        page_table_levels = 5;
-        printf("starting 5-level paging test.\n\n");
-        setup_5level_page_table();
-        r = ac_test_run();
-    }
-
-    return r ? 0 : 1;
-}
diff --git a/x86/access.h b/x86/access.h
new file mode 100644
index 0000000..4f67b62
--- /dev/null
+++ b/x86/access.h
@@ -0,0 +1,8 @@
+#ifndef X86_ACCESS_H
+#define X86_ACCESS_H
+
+int ac_test_run(void);
+
+extern int page_table_levels;
+
+#endif // X86_ACCESS_H
\ No newline at end of file
diff --git a/x86/access_test.c b/x86/access_test.c
new file mode 100644
index 0000000..497f286
--- /dev/null
+++ b/x86/access_test.c
@@ -0,0 +1,22 @@
+#include "libcflat.h"
+#include "processor.h"
+#include "x86/vm.h"
+#include "access.h"
+
+int main(void)
+{
+    int r;
+
+    printf("starting test\n\n");
+    page_table_levels = 4;
+    r = ac_test_run();
+
+    if (this_cpu_has(X86_FEATURE_LA57)) {
+        page_table_levels = 5;
+        printf("starting 5-level paging test.\n\n");
+        setup_5level_page_table();
+        r = ac_test_run();
+    }
+
+    return r ? 0 : 1;
+}
diff --git a/x86/unittests.cfg b/x86/unittests.cfg
index 3000e53..dbeb8a2 100644
--- a/x86/unittests.cfg
+++ b/x86/unittests.cfg
@@ -114,13 +114,13 @@ groups = vmexit
 extra_params = -cpu qemu64,+x2apic,+tsc-deadline -append tscdeadline_immed
 
 [access]
-file = access.flat
+file = access_test.flat
 arch = x86_64
 extra_params = -cpu max
 timeout = 180
 
 [access-reduced-maxphyaddr]
-file = access.flat
+file = access_test.flat
 arch = x86_64
 extra_params = -cpu IvyBridge,phys-bits=36,host-phys-bits=off
 timeout = 180
-- 
2.34.0.rc1.387.gb447b232ab-goog




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux