]> xenbits.xensource.com Git - xtf.git/commitdiff
Basic console and printk() infrastructure
authorAndrew Cooper <andrew.cooper3@citrix.com>
Sat, 23 May 2015 22:23:42 +0000 (23:23 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 28 Sep 2015 13:53:02 +0000 (14:53 +0100)
printk() can currently only deal with a plain string, and the output goes
nowhere.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Doxyfile
common/console.c [new file with mode: 0644]
common/libc/string.c [new file with mode: 0644]
common/setup.c
config/files.mk
include/xtf/compiler.h
include/xtf/console.h [new file with mode: 0644]
include/xtf/lib.h [new file with mode: 0644]
include/xtf/libc.h [new file with mode: 0644]

index 7247d53a0a4e6e844c112faa7c948ba02b813d5d..99e9d24b91d7d8c9038cd352e58c9452952490a0 100644 (file)
--- a/Doxyfile
+++ b/Doxyfile
@@ -1986,6 +1986,7 @@ INCLUDE_FILE_PATTERNS  =
 # This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
 
 PREDEFINED             = __attribute__(x)= \
+                         __printf(x,y)= \
                          __noreturn \
 
 
diff --git a/common/console.c b/common/console.c
new file mode 100644 (file)
index 0000000..0f907fe
--- /dev/null
@@ -0,0 +1,35 @@
+#include <xtf/types.h>
+#include <xtf/console.h>
+#include <xtf/lib.h>
+#include <xtf/libc.h>
+
+/*
+ * Output functions, registered if/when available.
+ * Possibilities:
+ */
+static cons_output_cb output_fns[1];
+static unsigned int nr_cons_cb;
+
+void register_console_callback(cons_output_cb fn)
+{
+    if ( nr_cons_cb < ARRAY_SIZE(output_fns) )
+        output_fns[nr_cons_cb++] = fn;
+}
+
+void printk(const char *fmt, ...)
+{
+    unsigned int i;
+
+    for ( i = 0; i < nr_cons_cb; ++i )
+        output_fns[i](fmt, strlen(fmt));
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/common/libc/string.c b/common/libc/string.c
new file mode 100644 (file)
index 0000000..c35a84c
--- /dev/null
@@ -0,0 +1,21 @@
+#include <string.h>
+
+size_t strlen(const char *str)
+{
+    const char *s = str;
+
+    while ( *s != '\0' )
+        ++s;
+
+    return s - str;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index a3e609f4d5664d37453b04c95042ff8c77cce791..0fc3d24364ed03fcbe5ebebb8cb94e29e88f1380 100644 (file)
@@ -8,6 +8,7 @@
 #include <xtf/hypercall.h>
 #include <xtf/framework.h>
 #include <xtf/test.h>
+#include <xtf/console.h>
 
 /**
  * Entry point into C.
@@ -18,6 +19,8 @@ void __noreturn xtf_main(void)
 {
     arch_setup();
 
+    printk("--- Xen Test Framework ---\n");
+
     test_main();
 
     hypercall_shutdown(SHUTDOWN_poweroff);
index 7ca9f2a4fe17bce3e9c2364078fac715d61237b0..58286a66407ed1a4de68ed9a4b3411dd509a85e2 100644 (file)
@@ -4,6 +4,8 @@
 # obj-perenv   get get compiled once for each environment
 # obj-$(env)   are objects unique to a specific environment
 
+obj-perarch += $(ROOT)/common/console.o
+obj-perarch += $(ROOT)/common/libc/string.o
 obj-perarch += $(ROOT)/common/setup.o
 
 obj-perenv += $(ROOT)/arch/x86/setup.o
index efeed58d76a89585b4d34b0e542ce71011ede18c..a6dc0b72bfbd10d758ec0516db45196ae9c65705 100644 (file)
@@ -4,6 +4,8 @@
 #define __noreturn            __attribute__((noreturn))
 #define unreachable()         __builtin_unreachable()
 
+#define __printf(f, v)        __attribute__((format(__printf__, f, v)))
+
 #endif /* XTF_COMPILER_H */
 
 /*
diff --git a/include/xtf/console.h b/include/xtf/console.h
new file mode 100644 (file)
index 0000000..f6b2f94
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef XTF_CONSOLE_H
+#define XTF_CONSOLE_H
+
+#include <xtf/compiler.h>
+
+/* Console output callback. */
+typedef void (*cons_output_cb)(const char *buf, size_t len);
+
+/*
+ * Register a console callback.  Several callbacks can be registered for usful
+ * destinations of console text.
+ */
+void register_console_callback(cons_output_cb cb);
+
+void printk(const char *fmt, ...) __printf(1, 2);
+
+#endif /* XTF_CONSOLE_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xtf/lib.h b/include/xtf/lib.h
new file mode 100644 (file)
index 0000000..819322b
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef XTF_LIB_H
+#define XTF_LIB_H
+
+#define ARRAY_SIZE(a)    (sizeof(a) / sizeof(*a))
+
+#endif /* XTF_LIB_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xtf/libc.h b/include/xtf/libc.h
new file mode 100644 (file)
index 0000000..ae5ede9
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef XTF_LIBC_H
+#define XTF_LIBC_H
+
+#include <xtf/types.h>
+
+/*
+ * Local declaration of bits of libc
+ *
+ * Use __builtin_???() wherever possible, to allow gcc to perform certain
+ * optimisations (e.g. constant folding) otherwise prevented by -fno-builtin.
+ *
+ * Where optimisations are not possible, the __builtin_???() varient will emit
+ * a call to ???(), which needs implementing in common/libc/
+ */
+
+#define strlen(s)                   __builtin_strlen(s)
+
+size_t strlen(const char *str);
+
+#endif /* XTF_LIBC_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */