aboutsummaryrefslogtreecommitdiffstats
path: root/src/include/ipxe/test.h
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2011-10-12 23:50:14 +0100
committerMichael Brown <mcb30@ipxe.org>2011-10-14 14:33:31 +0100
commiteac134f8dc592e665222e69c76ff4553d3a3f614 (patch)
tree2b5f80584a8f7bb0c41eaefde69f555ff0496459 /src/include/ipxe/test.h
parentdc821ca96155121a2aa47b9d67aa4dc95d5068f4 (diff)
downloadipxe-eac134f8dc592e665222e69c76ff4553d3a3f614.tar.gz
[test] Add a basic infrastructure for running self-tests
This self-test mechanism is inspired by Perl's Test::Simple and similar modules. The aim is to encourage the use of self-tests by making it as easy as possible to create self-test code Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/test.h')
-rw-r--r--src/include/ipxe/test.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/include/ipxe/test.h b/src/include/ipxe/test.h
new file mode 100644
index 000000000..8c361d284
--- /dev/null
+++ b/src/include/ipxe/test.h
@@ -0,0 +1,45 @@
+#ifndef _IPXE_TEST_H
+#define _IPXE_TEST_H
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+/** @file
+ *
+ * Self-test infrastructure
+ *
+ */
+
+#include <ipxe/tables.h>
+
+/** A self-test set */
+struct self_test {
+ /** Test set name */
+ const char *name;
+ /** Run self-tests */
+ void ( * exec ) ( void );
+ /** Number of tests run */
+ unsigned int total;
+ /** Number of test failures */
+ unsigned int failures;
+ /** Number of assertion failures */
+ unsigned int assertion_failures;
+};
+
+/** Self-test table */
+#define SELF_TESTS __table ( struct self_test, "self_tests" )
+
+/** Declare a self-test */
+#define __self_test __table_entry ( SELF_TESTS, 01 )
+
+extern void test_ok ( int success, const char *file, unsigned int line );
+
+/**
+ * Report test result
+ *
+ * @v success Test succeeded
+ */
+#define ok( success ) do { \
+ test_ok ( (success), __FILE__, __LINE__ ); \
+ } while ( 0 )
+
+#endif /* _IPXE_TEST_H */