summaryrefslogtreecommitdiff
path: root/test/libtest/lib/test.h
diff options
context:
space:
mode:
Diffstat (limited to 'test/libtest/lib/test.h')
-rw-r--r--test/libtest/lib/test.h159
1 files changed, 159 insertions, 0 deletions
diff --git a/test/libtest/lib/test.h b/test/libtest/lib/test.h
new file mode 100644
index 000000000000..86f91463993b
--- /dev/null
+++ b/test/libtest/lib/test.h
@@ -0,0 +1,159 @@
+/*-
+ * Copyright (c) 2018, Joseph Koshy
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LIBTEST_TEST_H_
+#define _LIBTEST_TEST_H_
+
+/*
+ * The return values from test functions.
+ *
+ * - TEST_PASS : The assertion(s) in the test function passed.
+ * - TEST_FAIL : At least one assertion in the test function failed.
+ * - TEST_UNRESOLVED : The assertions in the test function could not be
+ * checked for some reason.
+ */
+enum test_result {
+ TEST_PASS = 0,
+ TEST_FAIL = 1,
+ TEST_UNRESOLVED = 2
+};
+
+/*
+ * The return values from test case set up and tear down functions.
+ *
+ * - TESTCASE_OK : The set up or tear down function was successful.
+ * - TESTCASE_ERROR : Set up or tear down actions could not be completed.
+ *
+ * If a test case set up function returns TESTCASE_ERROR then:
+ * - The test functions in the test case will not be run.
+ * - The test case's tear down function will not be invoked.
+ * - The test run as a whole will be treated as being in error.
+ *
+ * If a test case tear down function returns a TESTCASE_ERROR, then
+ * the test run as a whole be treated as being in error.
+ */
+enum testcase_status {
+ TESTCASE_OK = 0,
+ TESTCASE_ERROR = 1
+};
+
+/*
+ * A testcase_state denotes resources that are shared by the test
+ * functions that are part of a test case. A testcase_state is allocated
+ * by the set up function for a test case. Conversely the test case's
+ * tear down function is responsible for deallocating the resources
+ * allocated by the set up function.
+ *
+ * The test(3) framework treats a testcase_state as an opaque value.
+ */
+typedef void *testcase_state;
+
+/*
+ * Test case and test function descriptions, and convenience macros
+ * to define these.
+ */
+typedef const char testcase_description[];
+
+#if !defined(TEST_DESCRIPTION)
+#define TEST_DESCRIPTION(NAME) test_description tf_description_##NAME
+#endif
+
+typedef const char test_description[];
+
+#if !defined(TESTCASE_DESCRIPTION)
+#define TESTCASE_DESCRIPTION(NAME) testcase_description tc_description_##NAME
+#endif
+
+/*
+ * Test case and test function tags, and convenience macros to define
+ * these.
+ */
+typedef const char *testcase_tags[];
+
+#if !defined(TESTCASE_TAGS)
+#define TESTCASE_TAGS(NAME) testcase_tags tc_tags_##NAME
+#endif
+
+typedef const char *test_tags[];
+#if !defined(TEST_TAGS)
+#define TEST_TAGS(NAME) test_tags tf_tags_##NAME
+#endif
+
+/*
+ * A test case set up function.
+ *
+ * If defined for a test case, this function will be called prior to
+ * the execution of an of the test functions within the test cae. Test
+ * case execution will be aborted if the function returns any value other
+ * than TESTCASE_OK.
+ *
+ * The function can set '*state' to a memory area holding test state to be
+ * passed to test functions.
+ *
+ * If the test case does not define a set up function, then a default
+ * no-op set up function will be used.
+ */
+typedef enum testcase_status (test_case_setup_function)
+ (testcase_state *state);
+
+/*
+ * A test function.
+ *
+ * This function will be invoked with the state that had been set by the
+ * test case set up function. The function returns TEST_PASS to report that
+ * its test succeeded or TEST_FAIL otherwise. In the event the test could
+ * not be executed, it can return TEST_UNRESOLVED.
+ */
+typedef enum test_result (test_function)(testcase_state state);
+
+/*
+ * A test case tear down function.
+ *
+ * If defined for a test case, this function will be called after the
+ * execution of the test functions in the test case. It is passed the
+ * state that had been allocated by the test case set up function, and is
+ * responsible for deallocating the resources that the set up function
+ * had allocated.
+ */
+typedef enum testcase_status (test_case_teardown_function)(testcase_state state);
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Write a progress report to the test log.
+ *
+ * This function takes a printf(3)-like format string and associated
+ * arguments.
+ */
+int test_report_progress(const char *format, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LIBTEST_TEST_H_ */