From f3d21c128e5b40acd1f15e3ddcd7fd54ca3a9bed Mon Sep 17 00:00:00 2001 From: "Bjoern B. Brandenburg" Date: Sat, 20 Feb 2010 21:48:29 -0500 Subject: Introduce test framework for LITMUS^RT. This is the beginning of the LITMUS^RT testsuite. The main design goals are flexibility and ease of test writing. To create a new test, simply write a test case in any C file in the tests/ subdirectory. The buildsystem will find the test and hook it up with the testrunner. Have a look at tests/fdso.c and include/tests.h to get an idea for what tests look like. Tests can be executed with the 'runtests' tool. Each testcase is executed in a separate process in order to ensure that tests do not influence each other. --- include/tests.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 include/tests.h (limited to 'include') diff --git a/include/tests.h b/include/tests.h new file mode 100644 index 0000000..3adba18 --- /dev/null +++ b/include/tests.h @@ -0,0 +1,50 @@ +#ifndef TESTS_H +#define TESTS_H + +#include +#include +#include + +#define fail(fmt, args...) \ + do { \ + fprintf(stderr, "\n!! TEST FAILURE " fmt "\n at %s:%d (%s)\n", \ + ## args, __FILE__, __LINE__, __FUNCTION__); \ + fflush(stderr); \ + exit(200); \ + } while (0) + +#define ASSERT(predicate) \ + do { \ + if (!(predicate)) \ + fail("%s", #predicate); \ + } while (0) + +#define SYSCALL(call) \ + do { \ + if ((call) < 0) \ + fail("%s, %m", #call); \ + } while (0) + +#define SYSCALL_FAILS(expected, call) \ + do { \ + if ((call) == 0 || errno != (expected)) \ + fail("%s, %m (expected: %s)", #call, #expected); \ + } while (0) + + +typedef void (*testfun_t)(void); + +struct testcase { + testfun_t function; + const char* description; +}; + +struct testsuite { + const char* plugin; + int* testcases; + int num_cases; +}; + +#define TESTCASE(function, plugins, description) void test_ ## function (void) + +#endif -- cgit v1.2.2