summaryrefslogtreecommitdiff
path: root/test/libtest/lib
diff options
context:
space:
mode:
Diffstat (limited to 'test/libtest/lib')
-rw-r--r--test/libtest/lib/Makefile5
-rw-r--r--test/libtest/lib/test.320
-rw-r--r--test/libtest/lib/test.h54
-rw-r--r--test/libtest/lib/test_case.h (renamed from test/libtest/lib/test_runner.c)31
-rw-r--r--test/libtest/lib/test_runner.h118
5 files changed, 68 insertions, 160 deletions
diff --git a/test/libtest/lib/Makefile b/test/libtest/lib/Makefile
index 7359ddd76a6c..e36d8fa072ba 100644
--- a/test/libtest/lib/Makefile
+++ b/test/libtest/lib/Makefile
@@ -4,10 +4,9 @@ TOP= ../../..
LIB= test
-SRCS= test.c \
- test_runner.c
+SRCS= test.c
-INCS= test.h
+INCS= test.h test_case.h
WARNS?= 6
diff --git a/test/libtest/lib/test.3 b/test/libtest/lib/test.3
index c7045b4039c4..e170c181595a 100644
--- a/test/libtest/lib/test.3
+++ b/test/libtest/lib/test.3
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2018, Joseph Koshy.
+.\" Copyright (c) 2018,2019 Joseph Koshy.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@@ -24,7 +24,7 @@
.\"
.\" $Id$
.\"
-.Dd December 25, 2018
+.Dd January 21, 2019
.Dt TEST 3
.Os
.Sh NAME
@@ -34,20 +34,20 @@
.Lb libtest
.Sh SYNOPSIS
.In test.h
-.Ft enum testcase_status
-.Fn testcase_setup "testcase_state *state"
-.Ft enum testcase_status
-.Fn testcase_teardown "testcase_state state"
+.Ft enum test_case_status
+.Fn test_case_setup "test_case_state *state"
+.Ft enum test_case_status
+.Fn test_case_teardown "test_case_state state"
.Ft enum test_result
-.Fn test_function "testcase_state state"
+.Fn test_function "test_case_state state"
.Vt "const char"
.Va test_description [] ;
.Vt "const char *"
.Va test_tags [] ;
.Vt "const char"
-.Va testcase_description [] ;
+.Va test_case_description [] ;
.Vt "const char *"
-.Va testcase_tags [] ;
+.Va test_case_tags [] ;
.Sh DESCRIPTION
The
.Lb libtest
@@ -76,7 +76,7 @@ If specified, this set up function would be invoked prior to any test
function contained in the test case.
The set up function can allocate and initialize test-specific state, to be
passed to test functions.
-If no set up function is specified for the test case, a default no-op
+If no set up function is specified for the test case, a default (no-op)
function will be supplied.
.It
An optional test case tear down function.
diff --git a/test/libtest/lib/test.h b/test/libtest/lib/test.h
index 86f91463993b..6928f867a6f4 100644
--- a/test/libtest/lib/test.h
+++ b/test/libtest/lib/test.h
@@ -44,60 +44,59 @@ enum test_result {
/*
* 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.
+ * - TEST_CASE_OK : The set up or tear down function was successful.
+ * - TEST_CASE_ERROR : Set up or tear down actions could not be completed.
*
- * If a test case set up function returns TESTCASE_ERROR then:
+ * If a test case set up function returns TEST_CASE_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
+ * If a test case tear down function returns a TEST_CASE_ERROR, then
* the test run as a whole be treated as being in error.
*/
-enum testcase_status {
- TESTCASE_OK = 0,
- TESTCASE_ERROR = 1
+enum test_case_status {
+ TEST_CASE_OK = 0,
+ TEST_CASE_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.
+ * A 'test_case_state' is a handle to resources shared by the test functions
+ * that make up a test case. A test_case_state is allocated by the test case
+ * set up function and is deallocated by the test case tear down function.
*
- * The test(3) framework treats a testcase_state as an opaque value.
+ * The test(3) framework treats a 'test_case_state' as an opaque value.
*/
-typedef void *testcase_state;
+typedef void *test_case_state;
/*
* Test case and test function descriptions, and convenience macros
* to define these.
*/
-typedef const char testcase_description[];
+typedef const char test_case_description[];
-#if !defined(TEST_DESCRIPTION)
-#define TEST_DESCRIPTION(NAME) test_description tf_description_##NAME
+#if !defined(TEST_CASE_DESCRIPTION)
+#define TEST_CASE_DESCRIPTION(NAME) test_case_description tc_description_##NAME
#endif
typedef const char test_description[];
-#if !defined(TESTCASE_DESCRIPTION)
-#define TESTCASE_DESCRIPTION(NAME) testcase_description tc_description_##NAME
+#if !defined(TEST_DESCRIPTION)
+#define TEST_DESCRIPTION(NAME) test_description tf_description_##NAME
#endif
/*
* Test case and test function tags, and convenience macros to define
* these.
*/
-typedef const char *testcase_tags[];
+typedef const char *test_case_tags[];
-#if !defined(TESTCASE_TAGS)
-#define TESTCASE_TAGS(NAME) testcase_tags tc_tags_##NAME
+#if !defined(TEST_CASE_TAGS)
+#define TEST_CASE_TAGS(NAME) test_case_tags tc_tags_##NAME
#endif
typedef const char *test_tags[];
+
#if !defined(TEST_TAGS)
#define TEST_TAGS(NAME) test_tags tf_tags_##NAME
#endif
@@ -108,7 +107,7 @@ typedef const char *test_tags[];
* 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.
+ * than TEST_CASE_OK.
*
* The function can set '*state' to a memory area holding test state to be
* passed to test functions.
@@ -116,8 +115,8 @@ typedef const char *test_tags[];
* 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);
+typedef enum test_case_status test_case_setup_function(
+ test_case_state *state);
/*
* A test function.
@@ -127,7 +126,7 @@ typedef enum testcase_status (test_case_setup_function)
* 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);
+typedef enum test_result test_function(test_case_state state);
/*
* A test case tear down function.
@@ -138,7 +137,8 @@ typedef enum test_result (test_function)(testcase_state state);
* responsible for deallocating the resources that the set up function
* had allocated.
*/
-typedef enum testcase_status (test_case_teardown_function)(testcase_state state);
+typedef enum test_case_status test_case_teardown_function(
+ test_case_state state);
#ifdef __cplusplus
extern "C" {
diff --git a/test/libtest/lib/test_runner.c b/test/libtest/lib/test_case.h
index 1366ff4a538e..c40b15fb69a1 100644
--- a/test/libtest/lib/test_runner.c
+++ b/test/libtest/lib/test_case.h
@@ -24,8 +24,35 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef _LIBTEST_TEST_CASE_H_
+#define _LIBTEST_TEST_CASE_H_
+
+#include "test.h"
+
/*
- * An implementation of a test driver for test(3) tests.
+ * These structures describe the test cases that are linked into a
+ * test executable.
*/
-/* To be implemented. */
+/* A single test function, with its associated tags and description. */
+struct test_function_descriptor {
+ const char *tf_name; /* Test name. */
+ const char *tf_description; /* Test description. */
+ const char **tf_tags; /* The tags for the test. */
+ test_function *tf_func; /* The function to invoke. */
+};
+
+/* A test case, with its associated tests. */
+struct test_case_descriptor {
+ const char *tc_name; /* Test case name. */
+ const char *tc_description; /* Test case description. */
+ const char **tc_tags; /* Any associated tags. */
+ const struct test_function_descriptor *tc_tests; /* Contained tests. */
+ const int tc_count; /* The number of tests. */
+};
+
+/* All test cases linked into the test binary. */
+extern struct test_case_descriptor test_cases[];
+extern const int test_case_count;
+
+#endif /* _LIBTEST_TEST_CASE_H_ */
diff --git a/test/libtest/lib/test_runner.h b/test/libtest/lib/test_runner.h
deleted file mode 100644
index cbf00f29b44d..000000000000
--- a/test/libtest/lib/test_runner.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*-
- * 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_RUNNER_H_
-#define _LIBTEST_TEST_RUNNER_H_
-
-#include "test.h"
-
-/*
- * These data structures and functions are used by test driver that
- * execute tests.
- */
-
-/*
- * The completion status for a test run:
- *
- * - TESTRUN_PASS : All test cases were successfully invoked and all test
- * purposes in the test cases passed.
- * - TESTRUN_FAIL : All test cases were successfully invoked but at least
- * one test purpose reported a test failure.
- * - TESTRUN_ERROR : At least one test case reported an error during its
- * set up or tear down phase.
- */
-enum testrun_status {
- TESTRUN_PASS = 0,
- TESTRUN_FAIL = 1,
- TESTRUN_ERROR = 2
-};
-
-/*
- * A single test function, with its associated tags and description.
- */
-struct test_descriptor {
- const char *t_name; /* Test name. */
- const char *t_description; /* Test description. */
- const char **t_tags; /* Tags associated with the test. */
- test_function *t_func; /* The function to invoke. */
-};
-
-/*
- * A test case.
- */
-struct test_case_descriptor {
- const char *tc_name; /* Test case name. */
- const char *tc_description; /* Test case description. */
- const char **tc_tags; /* Any associated tags. */
- struct test_descriptor *tc_tests; /* The tests in this test case. */
-};
-
-/*
- * All test cases.
- */
-extern struct test_case_descriptor test_cases[];
-
-enum testrun_style {
- /* Libtest semantics. */
- TESTRUN_STYLE_LIBTEST,
-
- /*
- * Be compatible with the Test Anything Protocol
- * (http://testanything.org/).
- */
- TESTRUN_STYLE_TAP,
-
- /* Be compatible with NetBSD ATF(9). */
- TESTRUN_STYLE_ATF
-};
-
-/*
- * Parameters for the run.
- */
-struct test_run {
- /*
- * An optional name assigned by the user for this test run.
- *
- * This name is reported in test logs and is not interpreted
- * by the test harness.
- */
- char *testrun_name;
-
- /* The source directory for the run. */
- char *testrun_source_directory;
-
- /* The directory in which the test is executing. */
- char *testrun_test_directory;
-};
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _LIBTEST_TEST_RUNNER_H_ */