[Skiboot] [PATCH 3/6] core/test: add more test stubs
Oliver O'Halloran
oohall at gmail.com
Mon Jun 19 16:01:35 AEST 2017
Adds a new kind of stub, the no-op stub which does nothing rather than
calling abort(). Also redefines them as weak symbols so that if the
thing being tested changes to require a normally stubbed function we
can just add the actual function to the test.
Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
core/test/Makefile.check | 5 -----
core/test/run-api-test.c | 1 -
core/test/run-msg.c | 3 ---
core/test/stubs.c | 38 +++++++++++++++++++++++++++++++++++++-
4 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/core/test/Makefile.check b/core/test/Makefile.check
index 1467a9f6c27c..813bd0207d8c 100644
--- a/core/test/Makefile.check
+++ b/core/test/Makefile.check
@@ -25,11 +25,6 @@ CORE_TEST := \
HOSTCFLAGS+=-I . -I include
-CORE_TEST_NOSTUB := core/test/run-console-log
-CORE_TEST_NOSTUB += core/test/run-console-log-buf-overrun
-CORE_TEST_NOSTUB += core/test/run-console-log-pr_fmt
-CORE_TEST_NOSTUB += core/test/run-api-test
-
LCOV_EXCLUDE += $(CORE_TEST:%=%.c) core/test/stubs.c
LCOV_EXCLUDE += $(CORE_TEST_NOSTUB:%=%.c) /usr/include/*
diff --git a/core/test/run-api-test.c b/core/test/run-api-test.c
index 583910dfd6c7..10f4cec8f11e 100644
--- a/core/test/run-api-test.c
+++ b/core/test/run-api-test.c
@@ -28,7 +28,6 @@
#include <opal-internal.h>
#define __TEST__
-unsigned long top_of_ram; /* Fake it here */
int main(void)
{
unsigned long addr = 0xd000000000000000;
diff --git a/core/test/run-msg.c b/core/test/run-msg.c
index 3a7b7dd395f2..66b8429729ea 100644
--- a/core/test/run-msg.c
+++ b/core/test/run-msg.c
@@ -23,9 +23,6 @@
static bool zalloc_should_fail = false;
static int zalloc_should_fail_after = 0;
-/* Fake top_of_ram -- needed for API's */
-unsigned long top_of_ram = 16ULL * 1024 * 1024 * 1024;
-
static void *zalloc(size_t size)
{
if (zalloc_should_fail && zalloc_should_fail_after == 0) {
diff --git a/core/test/stubs.c b/core/test/stubs.c
index 39ff18d8f103..426abe2e36e6 100644
--- a/core/test/stubs.c
+++ b/core/test/stubs.c
@@ -17,6 +17,8 @@
#include <stdio.h>
#include <stdarg.h>
+#define __weak __attribute__((weak))
+
#include "../../ccan/list/list.c"
void _prlog(int log_level __attribute__((unused)), const char* fmt, ...) __attribute__((format (printf, 2, 3)));
@@ -24,9 +26,11 @@ void _prlog(int log_level __attribute__((unused)), const char* fmt, ...) __attri
#ifndef pr_fmt
#define pr_fmt(fmt) fmt
#endif
+
+#ifndef prlog
#define prlog(l, f, ...) do { _prlog(l, pr_fmt(f), ##__VA_ARGS__); } while(0)
-void _prlog(int log_level __attribute__((unused)), const char* fmt, ...)
+void __attribute__((weak)) _prlog(int log_level __attribute__((unused)), const char* fmt, ...)
{
va_list ap;
@@ -34,6 +38,7 @@ void _prlog(int log_level __attribute__((unused)), const char* fmt, ...)
vprintf(fmt, ap);
va_end(ap);
}
+#endif
/* Add any stub functions required for linking here. */
static void stub_function(void)
@@ -41,9 +46,17 @@ static void stub_function(void)
abort();
}
+static int noop_function(void)
+{
+ return 0;
+}
+
#define STUB(fnname) \
void fnname(void) __attribute__((weak, alias ("stub_function")))
+#define NOOP_STUB(fnname) \
+ void fnname(void) __attribute__((weak, alias ("noop_function")))
+
STUB(fdt_begin_node);
STUB(fdt_property);
STUB(fdt_end_node);
@@ -61,3 +74,26 @@ STUB(dt_next);
STUB(dt_has_node_property);
STUB(dt_get_address);
STUB(add_chip_dev_associativity);
+
+STUB(__dt_add_property_cells);
+STUB(dt_add_property_string);
+STUB(dt_del_property);
+STUB(dt_find_by_name);
+STUB(__dt_find_property);
+STUB(dt_new);
+STUB(dt_new_addr);
+STUB(opal_add_poller);
+STUB(__opal_register);
+
+/* stop the stubbed lock functions from clashing with the real prototypes */
+#define __LOCK_H
+
+NOOP_STUB(lock_recursive);
+NOOP_STUB(lock);
+NOOP_STUB(unlock);
+NOOP_STUB(opal_update_pending_evt);
+
+unsigned long __weak top_of_ram = 16ULL * 1024 * 1024 * 1024;
+
+struct dt_node *opal_node = NULL;
+struct dt_node *dt_chosen = NULL;
--
2.9.3
More information about the Skiboot
mailing list