Infrastructure for running tests under Linux in primary VM.

Includes an initial test of simply inserting and removing the Hafnium
kernel module.

Change-Id: I832a30d902f58ca71f89374300ab39b2ba3ab877
diff --git a/test/hftest/inc/hftest_common.h b/test/hftest/inc/hftest_common.h
new file mode 100644
index 0000000..fa35aab
--- /dev/null
+++ b/test/hftest/inc/hftest_common.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2019 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.
+ */
+
+#include "hf/memiter.h"
+
+#include "hftest_impl.h"
+
+void hftest_use_registered_list(void);
+void hftest_use_list(struct hftest_test list[], size_t count);
+
+void hftest_json(void);
+void hftest_run(struct memiter suite_name, struct memiter test_name);
+void hftest_help(void);
diff --git a/test/hftest/inc/hftest_impl.h b/test/hftest/inc/hftest_impl.h
index 0470261..c4df298 100644
--- a/test/hftest/inc/hftest_impl.h
+++ b/test/hftest/inc/hftest_impl.h
@@ -20,6 +20,8 @@
 
 #include "hf/arch/std.h"
 
+#define HFTEST_MAX_TESTS 50
+
 /*
  * Log with the HFTEST_LOG_PREFIX and a new line. The zero is added so there is
  * always at least one variadic argument.
@@ -58,6 +60,12 @@
 	hftest_test_fn_##suite_name##_##test_name
 #define HFTEST_SERVICE_FN(service_name) hftest_service_fn_##service_name
 
+#define HFTEST_SET_UP_CONSTRUCTOR(suite_name) hftest_set_up_ctor_##suite_name
+#define HFTEST_TEAR_DOWN_CONSTRUCTOR(suite_name) \
+	hftest_tear_down_ctor_##suite_name
+#define HFTEST_TEST_CONSTRUCTOR(suite_name, test_name) \
+	hftest_test_ctor_##suite_name##_##test_name
+
 /* Register test functions. */
 #define HFTEST_SET_UP(suite_name)                                           \
 	static void HFTEST_SET_UP_FN(suite_name)(void);                     \
@@ -68,6 +76,11 @@
 				.kind = HFTEST_KIND_SET_UP,                 \
 				.fn = HFTEST_SET_UP_FN(suite_name),         \
 	};                                                                  \
+	static void __attribute__((constructor))                            \
+		HFTEST_SET_UP_CONSTRUCTOR(suite_name)(void)                 \
+	{                                                                   \
+		hftest_register(HFTEST_SET_UP_STRUCT(suite_name));          \
+	}                                                                   \
 	static void HFTEST_SET_UP_FN(suite_name)(void)
 
 #define HFTEST_TEAR_DOWN(suite_name)                                           \
@@ -79,18 +92,28 @@
 				.kind = HFTEST_KIND_TEAR_DOWN,                 \
 				.fn = HFTEST_TEAR_DOWN_FN(suite_name),         \
 	};                                                                     \
+	static void __attribute__((constructor))                               \
+		HFTEST_TEAR_DOWN_CONSTRUCTOR(suite_name)(void)                 \
+	{                                                                      \
+		hftest_register(HFTEST_TEAR_DOWN_STRUCT(suite_name));          \
+	}                                                                      \
 	static void HFTEST_TEAR_DOWN_FN(suite_name)(void)
 
-#define HFTEST_TEST(suite_name, test_name)                             \
-	static void HFTEST_TEST_FN(suite_name, test_name)(void);       \
-	const struct hftest_test __attribute__((used)) __attribute__(  \
-		(section(HFTEST_TEST_SECTION(suite_name, test_name)))) \
-		HFTEST_TEST_STRUCT(suite_name, test_name) = {          \
-			.suite = #suite_name,                          \
-			.kind = HFTEST_KIND_TEST,                      \
-			.name = #test_name,                            \
-			.fn = HFTEST_TEST_FN(suite_name, test_name),   \
-	};                                                             \
+#define HFTEST_TEST(suite_name, test_name)                                  \
+	static void HFTEST_TEST_FN(suite_name, test_name)(void);            \
+	const struct hftest_test __attribute__((used)) __attribute__(       \
+		(section(HFTEST_TEST_SECTION(suite_name, test_name))))      \
+		HFTEST_TEST_STRUCT(suite_name, test_name) = {               \
+			.suite = #suite_name,                               \
+			.kind = HFTEST_KIND_TEST,                           \
+			.name = #test_name,                                 \
+			.fn = HFTEST_TEST_FN(suite_name, test_name),        \
+	};                                                                  \
+	static void __attribute__((constructor))                            \
+		HFTEST_TEST_CONSTRUCTOR(suite_name, test_name)(void)        \
+	{                                                                   \
+		hftest_register(HFTEST_TEST_STRUCT(suite_name, test_name)); \
+	}                                                                   \
 	static void HFTEST_TEST_FN(suite_name, test_name)(void)
 
 #define HFTEST_TEST_SERVICE(service_name)                                      \
@@ -264,3 +287,5 @@
 
 #define HFTEST_SERVICE_SEND_BUFFER() hftest_get_context()->send
 #define HFTEST_SERVICE_RECV_BUFFER() hftest_get_context()->recv
+
+void hftest_register(struct hftest_test test);