MMIO access tests use the same test pattern. Let's share the code. Later, we will also reuse it for the SSE test.
Signed-off-by: Ralf Ramsauer <[email protected]> --- inmates/lib/include/test.h | 18 ++++++++++++++++++ inmates/lib/test.c | 28 ++++++++++++++++++++++++++++ inmates/lib/x86/Makefile | 2 +- inmates/tests/x86/mmio-access-32.c | 16 +--------------- inmates/tests/x86/mmio-access.c | 16 +--------------- 5 files changed, 49 insertions(+), 31 deletions(-) create mode 100644 inmates/lib/include/test.h create mode 100644 inmates/lib/test.c diff --git a/inmates/lib/include/test.h b/inmates/lib/include/test.h new file mode 100644 index 00000000..49ce152d --- /dev/null +++ b/inmates/lib/include/test.h @@ -0,0 +1,18 @@ +/* + * + * Jailhouse, a Linux-based partitioning hypervisor + * + * Copyright (c) Siemens AG, 2018 + * + * Authors: + * Jan Kiszka <[email protected]> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#define EXPECT_EQUAL(a, b) __evaluate(a, b, __LINE__) + +extern bool all_passed; + +void __evaluate(u64 a, u64 b, int line); diff --git a/inmates/lib/test.c b/inmates/lib/test.c new file mode 100644 index 00000000..808e2b4f --- /dev/null +++ b/inmates/lib/test.c @@ -0,0 +1,28 @@ +/* + * + * Jailhouse, a Linux-based partitioning hypervisor + * + * Copyright (c) Siemens AG, 2018 + * + * Authors: + * Jan Kiszka <[email protected]> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#include <inmate.h> +#include <test.h> + +bool all_passed = true; + +void __evaluate(u64 a, u64 b, int line) +{ + bool passed = (a == b); + + printk("Test at line #%d %s\n", line, passed ? "passed" : "FAILED"); + if (!passed) { + printk(" %llx != %llx\n", (u64)a, (u64)b); + all_passed = false; + } +} diff --git a/inmates/lib/x86/Makefile b/inmates/lib/x86/Makefile index c75de452..527436ef 100644 --- a/inmates/lib/x86/Makefile +++ b/inmates/lib/x86/Makefile @@ -42,7 +42,7 @@ always := lib.a lib32.a TARGETS := cpu-features.o excp.o header-common.o int.o ioapic.o printk.o TARGETS += setup.o uart.o -TARGETS += ../alloc.o ../pci.o ../string.o ../cmdline.o ../setup.o +TARGETS += ../alloc.o ../pci.o ../string.o ../cmdline.o ../setup.o ../test.o TARGETS += ../uart-8250.o ../printk.o TARGETS_32_ONLY := header-32.o TARGETS_64_ONLY := mem.o pci.o smp.o timing.o header-64.o diff --git a/inmates/tests/x86/mmio-access-32.c b/inmates/tests/x86/mmio-access-32.c index a071f82c..c8a56dcf 100644 --- a/inmates/tests/x86/mmio-access-32.c +++ b/inmates/tests/x86/mmio-access-32.c @@ -11,21 +11,7 @@ */ #include <inmate.h> - -#define EXPECT_EQUAL(a, b) evaluate(a, b, __LINE__) - -static bool all_passed = true; - -static void evaluate(u32 a, u32 b, int line) -{ - bool passed = (a == b); - - printk("Test at line #%d %s\n", line, passed ? "passed" : "FAILED"); - if (!passed) { - printk(" %x != %x\n", a, b); - all_passed = false; - } -} +#include <test.h> void inmate_main(void) { diff --git a/inmates/tests/x86/mmio-access.c b/inmates/tests/x86/mmio-access.c index f1525bc6..ea07fd32 100644 --- a/inmates/tests/x86/mmio-access.c +++ b/inmates/tests/x86/mmio-access.c @@ -11,24 +11,10 @@ */ #include <inmate.h> - -#define EXPECT_EQUAL(a, b) evaluate(a, b, __LINE__) +#include <test.h> extern u8 __reset_entry[]; /* assumed to be at 0 */ -static bool all_passed = true; - -static void evaluate(u64 a, u64 b, int line) -{ - bool passed = (a == b); - - printk("Test at line #%d %s\n", line, passed ? "passed" : "FAILED"); - if (!passed) { - printk(" %llx != %llx\n", a, b); - all_passed = false; - } -} - /* * mmio-access tests different memory access strategies that are intercepted by * the hypervisor. Therefore, it maps a second page right behind the -- 2.22.0 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jailhouse-dev/20190613200442.18984-8-ralf.ramsauer%40oth-regensburg.de. For more options, visit https://groups.google.com/d/optout.
