Tests: Tidy service partitions common code
Change-Id: I3eb64f45c4130f9a60c4402a069a3842f461f18a
Signed-off-by: J-Alves <joao.alves@arm.com>
diff --git a/test/hftest/BUILD.gn b/test/hftest/BUILD.gn
index 86a9ec2..15c214a 100644
--- a/test/hftest/BUILD.gn
+++ b/test/hftest/BUILD.gn
@@ -68,6 +68,7 @@
deps = [
":mm",
+ ":service_common",
"//src:dlog",
"//src:panic",
"//src:std",
@@ -92,6 +93,7 @@
deps = [
":mm",
+ ":service_common",
"//src:dlog",
"//src:panic",
"//src:std",
@@ -198,6 +200,20 @@
]
}
+source_set("service_common") {
+ visibility = [ ":*" ]
+ testonly = true
+ public_configs = [ ":hftest_config" ]
+ sources = [
+ "service_common.c",
+ ]
+ deps = [
+ "//src:memiter",
+ "//src:panic",
+ "//src:std",
+ ]
+}
+
source_set("device_psci") {
testonly = true
diff --git a/test/hftest/secondary_no_fdt.c b/test/hftest/secondary_no_fdt.c
index c02dc5f..73fe350 100644
--- a/test/hftest/secondary_no_fdt.c
+++ b/test/hftest/secondary_no_fdt.c
@@ -15,6 +15,7 @@
#include "vmapi/hf/call.h"
+#include "test/abort.h"
#include "test/hftest.h"
alignas(4096) uint8_t kstack[4096];
@@ -24,26 +25,8 @@
extern struct hftest_test hftest_begin[];
extern struct hftest_test hftest_end[];
-static struct hftest_context global_context;
-
void test_main_secondary(size_t mem_size);
-struct hftest_context *hftest_get_context(void)
-{
- return &global_context;
-}
-
-noreturn void abort(void)
-{
- HFTEST_LOG("Service contained failures.");
- /* Cause a fault, as a secondary can't power down the machine. */
- *((volatile uint8_t *)1) = 1;
-
- /* This should never be reached, but to make the compiler happy... */
- for (;;) {
- }
-}
-
noreturn void kmain(size_t mem_size)
{
/*
diff --git a/test/hftest/secure_service.c b/test/hftest/secure_service.c
index 4cd1fbf..3a7e246 100644
--- a/test/hftest/secure_service.c
+++ b/test/hftest/secure_service.c
@@ -15,32 +15,13 @@
#include "vmapi/hf/call.h"
+#include "test/abort.h"
#include "test/hftest.h"
alignas(4096) uint8_t kstack[4096];
-HFTEST_ENABLE();
-
-static struct hftest_context global_context;
-
-struct hftest_context *hftest_get_context(void)
-{
- return &global_context;
-}
-
void test_main_sp(void);
-noreturn void abort(void)
-{
- HFTEST_LOG("Service contained failures.");
- /* Cause a fault, as a secondary can't power down the machine. */
- *((volatile uint8_t *)1) = 1;
-
- /* This should never be reached, but to make the compiler happy... */
- for (;;) {
- }
-}
-
noreturn void kmain(void)
{
/*
diff --git a/test/hftest/service_common.c b/test/hftest/service_common.c
new file mode 100644
index 0000000..bd7840d
--- /dev/null
+++ b/test/hftest/service_common.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2021 The Hafnium Authors.
+ *
+ * Use of this source code is governed by a BSD-style
+ * license that can be found in the LICENSE file or at
+ * https://opensource.org/licenses/BSD-3-Clause.
+ */
+
+#include <stdalign.h>
+#include <stdint.h>
+
+#include "hf/mm.h"
+#include "hf/std.h"
+
+#include "test/hftest.h"
+#include "test/hftest_impl.h"
+
+HFTEST_ENABLE();
+
+static struct hftest_context global_context;
+
+struct hftest_context *hftest_get_context(void)
+{
+ return &global_context;
+}
+
+noreturn void abort(void)
+{
+ HFTEST_LOG("Service contained failures.");
+ /* Cause a fault, as a secondary/SP can't power down the machine. */
+ *((volatile uint8_t *)1) = 1;
+
+ /* This should never be reached, but to make the compiler happy... */
+ for (;;) {
+ }
+}