Move test utilities to common directory, and use them more widely.
Change-Id: Ib7397eccf811fec6a746254a613936c8466ac9e6
diff --git a/test/vmapi/primary_with_secondaries/inc/util.h b/test/inc/test/vmapi/spci.h
similarity index 100%
rename from test/vmapi/primary_with_secondaries/inc/util.h
rename to test/inc/test/vmapi/spci.h
diff --git a/test/vmapi/arch/aarch64/gicv3/gicv3.c b/test/vmapi/arch/aarch64/gicv3/gicv3.c
index 3d356cd..8127592 100644
--- a/test/vmapi/arch/aarch64/gicv3/gicv3.c
+++ b/test/vmapi/arch/aarch64/gicv3/gicv3.c
@@ -28,6 +28,7 @@
#include "../msr.h"
#include "test/hftest.h"
+#include "test/vmapi/spci.h"
alignas(PAGE_SIZE) uint8_t send_page[PAGE_SIZE];
alignas(PAGE_SIZE) uint8_t recv_page[PAGE_SIZE];
@@ -94,8 +95,7 @@
SERVICE_SELECT(SERVICE_VM1, "read_systemreg_ctlr", send_buffer);
run_res = spci_run(SERVICE_VM1, 0);
- EXPECT_EQ(run_res.func, SPCI_ERROR_32);
- EXPECT_EQ(run_res.arg2, SPCI_ABORTED);
+ EXPECT_SPCI_ERROR(run_res, SPCI_ABORTED);
}
/*
@@ -111,8 +111,7 @@
SERVICE_SELECT(SERVICE_VM1, "write_systemreg_ctlr", send_buffer);
run_res = spci_run(SERVICE_VM1, 0);
- EXPECT_EQ(run_res.func, SPCI_ERROR_32);
- EXPECT_EQ(run_res.arg2, SPCI_ABORTED);
+ EXPECT_SPCI_ERROR(run_res, SPCI_ABORTED);
}
/*
diff --git a/test/vmapi/arch/aarch64/gicv3/services/timer.c b/test/vmapi/arch/aarch64/gicv3/services/timer.c
index 948c746..bb2ff17 100644
--- a/test/vmapi/arch/aarch64/gicv3/services/timer.c
+++ b/test/vmapi/arch/aarch64/gicv3/services/timer.c
@@ -28,6 +28,7 @@
#include "common.h"
#include "test/hftest.h"
+#include "test/vmapi/spci.h"
/*
* Secondary VM that sets timers in response to messages, and sends messages
@@ -111,8 +112,7 @@
} else if (receive) {
struct spci_value res = spci_msg_wait();
- EXPECT_EQ(res.func, SPCI_ERROR_32);
- EXPECT_EQ(res.arg2, SPCI_INTERRUPTED);
+ EXPECT_SPCI_ERROR(res, SPCI_INTERRUPTED);
} else {
/* Busy wait until the timer fires. */
while (!timer_fired) {
diff --git a/test/vmapi/common/BUILD.gn b/test/vmapi/common/BUILD.gn
new file mode 100644
index 0000000..426d10e
--- /dev/null
+++ b/test/vmapi/common/BUILD.gn
@@ -0,0 +1,23 @@
+# Copyright 2018 The Hafnium Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/image/image.gni")
+
+source_set("common") {
+ testonly = true
+ public_configs = [ "//test/hftest:hftest_config" ]
+ sources = [
+ "spci.c",
+ ]
+}
diff --git a/test/vmapi/primary_with_secondaries/util.c b/test/vmapi/common/spci.c
similarity index 97%
rename from test/vmapi/primary_with_secondaries/util.c
rename to test/vmapi/common/spci.c
index 19657c4..a175cea 100644
--- a/test/vmapi/primary_with_secondaries/util.c
+++ b/test/vmapi/common/spci.c
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-#include "util.h"
+#include "hf/spci.h"
#include "hf/mm.h"
-#include "hf/spci.h"
#include "hf/static_assert.h"
#include "vmapi/hf/call.h"
#include "test/hftest.h"
+#include "test/vmapi/spci.h"
static alignas(PAGE_SIZE) uint8_t send_page[PAGE_SIZE];
static alignas(PAGE_SIZE) uint8_t recv_page[PAGE_SIZE];
diff --git a/test/vmapi/primary_only/primary_only.c b/test/vmapi/primary_only/primary_only.c
index a7bf9af..7b4bba1 100644
--- a/test/vmapi/primary_only/primary_only.c
+++ b/test/vmapi/primary_only/primary_only.c
@@ -23,6 +23,7 @@
#include "vmapi/hf/call.h"
#include "test/hftest.h"
+#include "test/vmapi/spci.h"
/*
* TODO: Some of these tests are duplicated between 'primary_only' and
@@ -90,8 +91,7 @@
TEST(spci_run, cannot_run_primary)
{
struct spci_value res = spci_run(HF_PRIMARY_VM_ID, 0);
- EXPECT_EQ(res.func, SPCI_ERROR_32);
- EXPECT_EQ(res.arg2, SPCI_INVALID_PARAMETERS);
+ EXPECT_SPCI_ERROR(res, SPCI_INVALID_PARAMETERS);
}
/**
@@ -100,8 +100,7 @@
TEST(spci_run, cannot_run_absent_secondary)
{
struct spci_value res = spci_run(1, 0);
- EXPECT_EQ(res.func, SPCI_ERROR_32);
- EXPECT_EQ(res.arg2, SPCI_INVALID_PARAMETERS);
+ EXPECT_SPCI_ERROR(res, SPCI_INVALID_PARAMETERS);
}
/**
@@ -201,52 +200,40 @@
struct spci_value ret;
ret = spci_features(0);
- EXPECT_EQ(ret.func, SPCI_ERROR_32);
- EXPECT_EQ(ret.arg2, SPCI_NOT_SUPPORTED);
+ EXPECT_SPCI_ERROR(ret, SPCI_NOT_SUPPORTED);
ret = spci_features(0x84000000);
- EXPECT_EQ(ret.func, SPCI_ERROR_32);
- EXPECT_EQ(ret.arg2, SPCI_NOT_SUPPORTED);
+ EXPECT_SPCI_ERROR(ret, SPCI_NOT_SUPPORTED);
ret = spci_features(SPCI_INTERRUPT_32);
- EXPECT_EQ(ret.func, SPCI_ERROR_32);
- EXPECT_EQ(ret.arg2, SPCI_NOT_SUPPORTED);
+ EXPECT_SPCI_ERROR(ret, SPCI_NOT_SUPPORTED);
ret = spci_features(SPCI_RX_RELEASE_32);
- EXPECT_EQ(ret.func, SPCI_ERROR_32);
- EXPECT_EQ(ret.arg2, SPCI_NOT_SUPPORTED);
+ EXPECT_SPCI_ERROR(ret, SPCI_NOT_SUPPORTED);
ret = spci_features(SPCI_RXTX_MAP_32);
- EXPECT_EQ(ret.func, SPCI_ERROR_32);
- EXPECT_EQ(ret.arg2, SPCI_NOT_SUPPORTED);
+ EXPECT_SPCI_ERROR(ret, SPCI_NOT_SUPPORTED);
ret = spci_features(SPCI_RXTX_UNMAP_32);
- EXPECT_EQ(ret.func, SPCI_ERROR_32);
- EXPECT_EQ(ret.arg2, SPCI_NOT_SUPPORTED);
+ EXPECT_SPCI_ERROR(ret, SPCI_NOT_SUPPORTED);
ret = spci_features(SPCI_PARTITION_INFO_GET_32);
- EXPECT_EQ(ret.func, SPCI_ERROR_32);
- EXPECT_EQ(ret.arg2, SPCI_NOT_SUPPORTED);
+ EXPECT_SPCI_ERROR(ret, SPCI_NOT_SUPPORTED);
ret = spci_features(SPCI_RUN_32);
- EXPECT_EQ(ret.func, SPCI_ERROR_32);
- EXPECT_EQ(ret.arg2, SPCI_NOT_SUPPORTED);
+ EXPECT_SPCI_ERROR(ret, SPCI_NOT_SUPPORTED);
ret = spci_features(SPCI_MSG_SEND_DIRECT_RESP_32);
- EXPECT_EQ(ret.func, SPCI_ERROR_32);
- EXPECT_EQ(ret.arg2, SPCI_NOT_SUPPORTED);
+ EXPECT_SPCI_ERROR(ret, SPCI_NOT_SUPPORTED);
ret = spci_features(SPCI_MSG_SEND_DIRECT_REQ_32);
- EXPECT_EQ(ret.func, SPCI_ERROR_32);
- EXPECT_EQ(ret.arg2, SPCI_NOT_SUPPORTED);
+ EXPECT_SPCI_ERROR(ret, SPCI_NOT_SUPPORTED);
ret = spci_features(SPCI_MSG_SEND_DIRECT_REQ_32);
- EXPECT_EQ(ret.func, SPCI_ERROR_32);
- EXPECT_EQ(ret.arg2, SPCI_NOT_SUPPORTED);
+ EXPECT_SPCI_ERROR(ret, SPCI_NOT_SUPPORTED);
ret = spci_features(SPCI_MSG_SEND_DIRECT_RESP_32);
- EXPECT_EQ(ret.func, SPCI_ERROR_32);
- EXPECT_EQ(ret.arg2, SPCI_NOT_SUPPORTED);
+ EXPECT_SPCI_ERROR(ret, SPCI_NOT_SUPPORTED);
}
/**
diff --git a/test/vmapi/primary_with_secondaries/BUILD.gn b/test/vmapi/primary_with_secondaries/BUILD.gn
index 3a38f26..8554d4b 100644
--- a/test/vmapi/primary_with_secondaries/BUILD.gn
+++ b/test/vmapi/primary_with_secondaries/BUILD.gn
@@ -43,24 +43,13 @@
]
deps = [
- ":util",
"//src/arch/aarch64/hftest:registers",
"//test/hftest:hftest_primary_vm",
+ "//test/vmapi/common",
"//vmlib",
]
}
-source_set("util") {
- testonly = true
- public_configs = [
- ":config",
- "//test/hftest:hftest_config",
- ]
- sources = [
- "util.c",
- ]
-}
-
initrd("primary_with_secondaries_test") {
testonly = true
diff --git a/test/vmapi/primary_with_secondaries/abort.c b/test/vmapi/primary_with_secondaries/abort.c
index dea9611..07eea62 100644
--- a/test/vmapi/primary_with_secondaries/abort.c
+++ b/test/vmapi/primary_with_secondaries/abort.c
@@ -18,7 +18,7 @@
#include "primary_with_secondary.h"
#include "test/hftest.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
/**
* Accessing unmapped memory aborts the VM.
diff --git a/test/vmapi/primary_with_secondaries/boot.c b/test/vmapi/primary_with_secondaries/boot.c
index 7902659..ef97715 100644
--- a/test/vmapi/primary_with_secondaries/boot.c
+++ b/test/vmapi/primary_with_secondaries/boot.c
@@ -20,7 +20,7 @@
#include "primary_with_secondary.h"
#include "test/hftest.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
/**
* The VM gets its memory size on boot, and can access it all.
diff --git a/test/vmapi/primary_with_secondaries/debug_el1.c b/test/vmapi/primary_with_secondaries/debug_el1.c
index 217b149..2dd5312 100644
--- a/test/vmapi/primary_with_secondaries/debug_el1.c
+++ b/test/vmapi/primary_with_secondaries/debug_el1.c
@@ -16,7 +16,7 @@
#include "primary_with_secondary.h"
#include "sysregs.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
/**
* QEMU does not properly handle the trapping of certain system register
diff --git a/test/vmapi/primary_with_secondaries/floating_point.c b/test/vmapi/primary_with_secondaries/floating_point.c
index a12328d..1904d68 100644
--- a/test/vmapi/primary_with_secondaries/floating_point.c
+++ b/test/vmapi/primary_with_secondaries/floating_point.c
@@ -24,7 +24,7 @@
#include "../msr.h"
#include "primary_with_secondary.h"
#include "test/hftest.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
/**
* Test that floating point registers are saved and restored by
diff --git a/test/vmapi/primary_with_secondaries/interrupts.c b/test/vmapi/primary_with_secondaries/interrupts.c
index ac64049..5aaf830 100644
--- a/test/vmapi/primary_with_secondaries/interrupts.c
+++ b/test/vmapi/primary_with_secondaries/interrupts.c
@@ -22,7 +22,7 @@
#include "primary_with_secondary.h"
#include "test/hftest.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
/**
* Send a message to the interruptible VM, which will interrupt itself to send a
diff --git a/test/vmapi/primary_with_secondaries/mailbox.c b/test/vmapi/primary_with_secondaries/mailbox.c
index f08c696..c58115a 100644
--- a/test/vmapi/primary_with_secondaries/mailbox.c
+++ b/test/vmapi/primary_with_secondaries/mailbox.c
@@ -23,7 +23,7 @@
#include "primary_with_secondary.h"
#include "test/hftest.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
/**
* Reverses the order of the elements in the given array.
diff --git a/test/vmapi/primary_with_secondaries/memory_sharing.c b/test/vmapi/primary_with_secondaries/memory_sharing.c
index e6cc222..efe0275 100644
--- a/test/vmapi/primary_with_secondaries/memory_sharing.c
+++ b/test/vmapi/primary_with_secondaries/memory_sharing.c
@@ -23,7 +23,7 @@
#include "primary_with_secondary.h"
#include "test/hftest.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
alignas(PAGE_SIZE) static uint8_t pages[4 * PAGE_SIZE];
diff --git a/test/vmapi/primary_with_secondaries/no_services.c b/test/vmapi/primary_with_secondaries/no_services.c
index 0c83a8b..2e06c78 100644
--- a/test/vmapi/primary_with_secondaries/no_services.c
+++ b/test/vmapi/primary_with_secondaries/no_services.c
@@ -25,7 +25,7 @@
#include "primary_with_secondary.h"
#include "test/hftest.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
static alignas(PAGE_SIZE) uint8_t send_page[PAGE_SIZE];
static alignas(PAGE_SIZE) uint8_t recv_page[PAGE_SIZE];
diff --git a/test/vmapi/primary_with_secondaries/perfmon.c b/test/vmapi/primary_with_secondaries/perfmon.c
index c325190..4edc81b 100644
--- a/test/vmapi/primary_with_secondaries/perfmon.c
+++ b/test/vmapi/primary_with_secondaries/perfmon.c
@@ -19,7 +19,7 @@
#include "../../src/arch/aarch64/hypervisor/sysregs.h"
#include "primary_with_secondary.h"
#include "sysregs.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
/*
* TODO(b/132394973): Devise a way to test exhaustively read/write behavior to
diff --git a/test/vmapi/primary_with_secondaries/run_race.c b/test/vmapi/primary_with_secondaries/run_race.c
index 672815d..f06f2a7 100644
--- a/test/vmapi/primary_with_secondaries/run_race.c
+++ b/test/vmapi/primary_with_secondaries/run_race.c
@@ -26,7 +26,7 @@
#include "primary_with_secondary.h"
#include "test/hftest.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
/**
* Iterates trying to run vCPU of the secondary VM. Returns when a message
diff --git a/test/vmapi/primary_with_secondaries/services/BUILD.gn b/test/vmapi/primary_with_secondaries/services/BUILD.gn
index dc395c0..728692f 100644
--- a/test/vmapi/primary_with_secondaries/services/BUILD.gn
+++ b/test/vmapi/primary_with_secondaries/services/BUILD.gn
@@ -94,7 +94,7 @@
"//test/hftest:hftest_config",
]
deps = [
- "//test/vmapi/primary_with_secondaries:util",
+ "//test/vmapi/common",
"//vmlib",
]
@@ -155,7 +155,7 @@
deps = [
"//src/arch/aarch64:arch",
"//src/arch/aarch64/hftest:interrupts",
- "//test/vmapi/primary_with_secondaries:util",
+ "//test/vmapi/common",
]
}
@@ -204,7 +204,7 @@
"//test/hftest:hftest_config",
]
deps = [
- "//test/vmapi/primary_with_secondaries:util",
+ "//test/vmapi/common",
]
sources = [
diff --git a/test/vmapi/primary_with_secondaries/services/memory.c b/test/vmapi/primary_with_secondaries/services/memory.c
index 524f006..58015e2 100644
--- a/test/vmapi/primary_with_secondaries/services/memory.c
+++ b/test/vmapi/primary_with_secondaries/services/memory.c
@@ -21,7 +21,7 @@
#include "primary_with_secondary.h"
#include "test/hftest.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
alignas(PAGE_SIZE) static uint8_t page[PAGE_SIZE];
diff --git a/test/vmapi/primary_with_secondaries/services/receive_block.c b/test/vmapi/primary_with_secondaries/services/receive_block.c
index 1fa34ab..49ea5f2 100644
--- a/test/vmapi/primary_with_secondaries/services/receive_block.c
+++ b/test/vmapi/primary_with_secondaries/services/receive_block.c
@@ -24,7 +24,7 @@
#include "primary_with_secondary.h"
#include "test/hftest.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
/*
* Secondary VM that enables an interrupt, disables interrupts globally, and
diff --git a/test/vmapi/primary_with_secondaries/services/spci_check.c b/test/vmapi/primary_with_secondaries/services/spci_check.c
index 05715d4..9e342ba 100644
--- a/test/vmapi/primary_with_secondaries/services/spci_check.c
+++ b/test/vmapi/primary_with_secondaries/services/spci_check.c
@@ -21,7 +21,7 @@
#include "primary_with_secondary.h"
#include "test/hftest.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
TEST_SERVICE(spci_check)
{
diff --git a/test/vmapi/primary_with_secondaries/smp.c b/test/vmapi/primary_with_secondaries/smp.c
index 1199d83..ea1fc00 100644
--- a/test/vmapi/primary_with_secondaries/smp.c
+++ b/test/vmapi/primary_with_secondaries/smp.c
@@ -22,7 +22,7 @@
#include "primary_with_secondary.h"
#include "test/hftest.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
/**
* Run a service that starts a second vCPU, and check that both the first and
diff --git a/test/vmapi/primary_with_secondaries/spci.c b/test/vmapi/primary_with_secondaries/spci.c
index 6862333..a3cfbca 100644
--- a/test/vmapi/primary_with_secondaries/spci.c
+++ b/test/vmapi/primary_with_secondaries/spci.c
@@ -24,7 +24,7 @@
#include "primary_with_secondary.h"
#include "test/hftest.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
/**
* Send a message to a secondary VM which checks the validity of the received
diff --git a/test/vmapi/primary_with_secondaries/sysregs.c b/test/vmapi/primary_with_secondaries/sysregs.c
index 3b31d71..f15a692 100644
--- a/test/vmapi/primary_with_secondaries/sysregs.c
+++ b/test/vmapi/primary_with_secondaries/sysregs.c
@@ -19,7 +19,7 @@
#include "hf/arch/vm/interrupts.h"
#include "primary_with_secondary.h"
-#include "util.h"
+#include "test/vmapi/spci.h"
/**
* Tracks the number of times the exception handler has been invoked.