blob: cef6c3407651a3826520d6a62b0a05b3772eace3 [file] [log] [blame]
Jon A. Cruz5a75a412015-07-02 23:36:44 -07001/*
2 * Copyright © 2015 Samsung Electronics Co., Ltd
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26/**
27@page zunitc zunitc
28
29- @ref zunitc_overview
30- @ref zunitc_execution
31 - @ref zunitc_execution_commandline
32 - @ref zunitc_execution_matching
33 - @ref zunitc_execution_wildcards
34 - @ref zunitc_execution_repeat
35 - @ref zunitc_execution_randomize
36- @ref zunitc_fixtures
37- @ref zunitc_functions
38
39@section zunitc_overview Overview
40
41A simple test framework in plain C suitable for basic unit and integration testing.
42
43The main rationale for creating this framework was to have a simple to use testing
44framework with tests implemented in C using common patterns and under a
45compatible license. The structure of the test code and macro use is intended to
46follow common patterns established by frameworks such as Boost Test and Google Test.
47
48
49To get started, one or more tests should be defined via ZUC_TEST() and/or
50ZUC_TEST_F(), which set up automatic test registration via gcc extensions.
51To actually execute tests, ZUC_RUN_TESTS() should be called.
52
53
54Tests can use several ZUC_ASSERT_* or ZUC_ASSERTG_* checks to validate
55conditions. The ZUC_ASSERT_* ones upon failure will mark the current test
56as failing and immediatly execute a return. On the other hand, the
57ZUC_ASSERTG_* tests will mark the current test as failed and then execute a
58'goto' targeting the specified label.
59
60The set of fatal test checks are
61
62- ZUC_ASSERT_TRUE()
63- ZUC_ASSERT_FALSE()
64- ZUC_ASSERT_NULL()
65- ZUC_ASSERT_NOT_NULL()
66- ZUC_ASSERT_EQ()
67- ZUC_ASSERT_NE()
68- ZUC_ASSERT_LT()
69- ZUC_ASSERT_LE()
70- ZUC_ASSERT_GT()
71- ZUC_ASSERT_GE()
72- ZUC_ASSERT_STREQ()
73- ZUC_ASSERT_STRNE()
74
75and
76
77- ZUC_ASSERTG_TRUE()
78- ZUC_ASSERTG_FALSE()
79- ZUC_ASSERTG_NULL()
80- ZUC_ASSERTG_NOT_NULL()
81- ZUC_ASSERTG_EQ()
82- ZUC_ASSERTG_NE()
83- ZUC_ASSERTG_LT()
84- ZUC_ASSERTG_LE()
85- ZUC_ASSERTG_GT()
86- ZUC_ASSERTG_GE()
87- ZUC_ASSERTG_STREQ()
88- ZUC_ASSERTG_STRNE()
89
90Unconditional test values for logging and termination are
91- ZUC_SKIP()
92- ZUC_FATAL()
93
94Unconditional message logging for failure cases only is
95- ZUC_TRACEPOINT()
96
97@section zunitc_execution Controlling Execution
98
Bryce Harrington66f2a382015-07-13 12:22:59 -070099To control execution, the various zuc_set_* functions can be called
100before invoking ZUC_RUN_TESTS().
Jon A. Cruz5a75a412015-07-02 23:36:44 -0700101
102@subsection zunitc_execution_commandline Commandline Parameters
103
Bryce Harrington66f2a382015-07-13 12:22:59 -0700104The current implementation defers processing of command-line parameters
105to the main application hosting the testing. It is possible that a
Bryce Harrington966cc4b2015-07-13 12:23:00 -0700106helper function to process certain parameters may be added.
Jon A. Cruz5a75a412015-07-02 23:36:44 -0700107
108@subsection zunitc_execution_matching Matching Patterns for Tests
109
Bryce Harrington66f2a382015-07-13 12:22:59 -0700110The function zuc_set_filter() can be used to specify a pattern for
111matching or excluding tests from a run. The general form is
Jon A. Cruz5a75a412015-07-02 23:36:44 -0700112 match1[:match2[:match3..n]][:-exclude1[:exclude2[:exclude3..n]]]
113
114@subsection zunitc_execution_wildcards Matching Wildcards
115
Bryce Harrington66f2a382015-07-13 12:22:59 -0700116Wildcards can be used in the match/exclude patterns and recognize the
117following two special characters:
Jon A. Cruz5a75a412015-07-02 23:36:44 -0700118- '*' matches any number of characters including zero.
119- '?' matches any single character.
120
Bryce Harrington66f2a382015-07-13 12:22:59 -0700121Calling zuc_list_tests() after zuc_set_filter() can be done to show the
122effects of the matching without needing to actually run tests.
Jon A. Cruz5a75a412015-07-02 23:36:44 -0700123
124@subsection zunitc_execution_repeat Repeating Tests
125
Bryce Harrington66f2a382015-07-13 12:22:59 -0700126Setting the repeat count higher than 1 ( via zuc_set_repeat() ) will
127cause the tests to be executed several times in a row. This can be
128useful for stress testing, checking for leaks, etc.
Jon A. Cruz5a75a412015-07-02 23:36:44 -0700129
130@subsection zunitc_execution_randomize Randomizing Tests
131
Bryce Harrington66f2a382015-07-13 12:22:59 -0700132Test ordering can be randomized by setting a non-zero positive value to
133zuc_set_random(). Setting it to 1 will cause the framework to pick a
134random seed based on the time. A value greater than 1 will be taken as a
135random seed itself. And setting it to 0 will disable randomization and
Bryce Harrington966cc4b2015-07-13 12:23:00 -0700136allow the tests to be executed in their natural ordering.
Jon A. Cruz5a75a412015-07-02 23:36:44 -0700137
138@section zunitc_fixtures Fixtures
139
Bryce Harrington66f2a382015-07-13 12:22:59 -0700140Per-suite and per-test setup and teardown fixtures can be implemented by
141defining an instance of struct zuc_fixture and using it as the first
142parameter to ZUC_TEST_F().
Jon A. Cruz5a75a412015-07-02 23:36:44 -0700143
144@section zunitc_functions Functions
145
146- ZUC_TEST()
147- ZUC_TEST_F()
148- ZUC_RUN_TESTS()
149- zuc_cleanup()
150- zuc_list_tests()
151- zuc_set_filter()
152- zuc_set_random()
153- zuc_set_spawn()
154- zuc_set_output_tap()
155- zuc_set_output_junit()
156- zuc_has_skip()
157- zuc_has_failure()
158
159*/