Lines Matching full:test

3  * Example KUnit test to show how to use KUnit.
9 #include <kunit/test.h>
13 * This is the most fundamental element of KUnit, the test case. A test case
15 * any expectations or assertions are not met, the test fails; otherwise, the
16 * test passes.
18 * In KUnit, a test case is just a function with the signature
20 * information about the current test.
22 static void example_simple_test(struct kunit *test) in example_simple_test() argument
26 * to test a piece of code, you set some expectations about what the in example_simple_test()
27 * code should do. KUnit then runs the test and verifies that the code's in example_simple_test()
30 KUNIT_EXPECT_EQ(test, 1 + 1, 2); in example_simple_test()
34 * This is run once before each test case, see the comment on
37 static int example_test_init(struct kunit *test) in example_test_init() argument
39 kunit_info(test, "initializing\n"); in example_test_init()
45 * This is run once after each test case, see the comment on
48 static void example_test_exit(struct kunit *test) in example_test_exit() argument
50 kunit_info(test, "cleaning up\n"); in example_test_exit()
55 * This is run once before all test cases in the suite.
66 * This is run once after all test cases in the suite.
76 * This test should always be skipped.
78 static void example_skip_test(struct kunit *test) in example_skip_test() argument
81 kunit_info(test, "You should not see a line below."); in example_skip_test()
83 /* Skip (and abort) the test */ in example_skip_test()
84 kunit_skip(test, "this test should be skipped"); in example_skip_test()
87 KUNIT_FAIL(test, "You should not see this line."); in example_skip_test()
91 * This test should always be marked skipped.
93 static void example_mark_skipped_test(struct kunit *test) in example_mark_skipped_test() argument
96 kunit_info(test, "You should see a line below."); in example_mark_skipped_test()
98 /* Skip (but do not abort) the test */ in example_mark_skipped_test()
99 kunit_mark_skipped(test, "this test should be skipped"); in example_mark_skipped_test()
102 kunit_info(test, "You should see this line."); in example_mark_skipped_test()
106 * This test shows off all the types of KUNIT_EXPECT macros.
108 static void example_all_expect_macros_test(struct kunit *test) in example_all_expect_macros_test() argument
114 KUNIT_EXPECT_TRUE(test, true); in example_all_expect_macros_test()
115 KUNIT_EXPECT_FALSE(test, false); in example_all_expect_macros_test()
118 KUNIT_EXPECT_EQ(test, 1, 1); /* check == */ in example_all_expect_macros_test()
119 KUNIT_EXPECT_GE(test, 1, 1); /* check >= */ in example_all_expect_macros_test()
120 KUNIT_EXPECT_LE(test, 1, 1); /* check <= */ in example_all_expect_macros_test()
121 KUNIT_EXPECT_NE(test, 1, 0); /* check != */ in example_all_expect_macros_test()
122 KUNIT_EXPECT_GT(test, 1, 0); /* check > */ in example_all_expect_macros_test()
123 KUNIT_EXPECT_LT(test, 0, 1); /* check < */ in example_all_expect_macros_test()
126 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, test); in example_all_expect_macros_test()
127 KUNIT_EXPECT_PTR_EQ(test, NULL, NULL); in example_all_expect_macros_test()
128 KUNIT_EXPECT_PTR_NE(test, test, NULL); in example_all_expect_macros_test()
129 KUNIT_EXPECT_NULL(test, NULL); in example_all_expect_macros_test()
130 KUNIT_EXPECT_NOT_NULL(test, test); in example_all_expect_macros_test()
133 KUNIT_EXPECT_STREQ(test, "hi", "hi"); in example_all_expect_macros_test()
134 KUNIT_EXPECT_STRNEQ(test, "hi", "bye"); in example_all_expect_macros_test()
137 KUNIT_EXPECT_MEMEQ(test, array1, array1, sizeof(array1)); in example_all_expect_macros_test()
138 KUNIT_EXPECT_MEMNEQ(test, array1, array2, sizeof(array1)); in example_all_expect_macros_test()
141 * There are also ASSERT variants of all of the above that abort test in example_all_expect_macros_test()
144 KUNIT_ASSERT_GT(test, sizeof(char), 0); in example_all_expect_macros_test()
150 KUNIT_EXPECT_GT_MSG(test, sizeof(int), 0, "Your ints are 0-bit?!"); in example_all_expect_macros_test()
151 KUNIT_ASSERT_GT_MSG(test, sizeof(int), 0, "Your ints are 0-bit?!"); in example_all_expect_macros_test()
172 * This test shows the use of static stubs.
174 static void example_static_stub_test(struct kunit *test) in example_static_stub_test() argument
177 KUNIT_EXPECT_EQ(test, add_one(1), 2); in example_static_stub_test()
180 kunit_activate_static_stub(test, add_one, subtract_one); in example_static_stub_test()
183 KUNIT_EXPECT_EQ(test, add_one(1), 0); in example_static_stub_test()
186 kunit_deactivate_static_stub(test, add_one); in example_static_stub_test()
187 KUNIT_EXPECT_EQ(test, add_one(1), 2); in example_static_stub_test()
206 * This test shows the use of params.
208 static void example_params_test(struct kunit *test) in example_params_test() argument
210 const struct example_param *param = test->param_value; in example_params_test()
213 KUNIT_ASSERT_NOT_NULL(test, param); in example_params_test()
215 /* Test can be skipped on unsupported param values */ in example_params_test()
217 kunit_skip(test, "unsupported param value"); in example_params_test()
220 KUNIT_EXPECT_EQ(test, param->value % param->value, 0); in example_params_test()
224 * This test should always pass. Can be used to practice filtering attributes.
226 static void example_slow_test(struct kunit *test) in example_slow_test() argument
228 KUNIT_EXPECT_EQ(test, 1 + 1, 2); in example_slow_test()
232 * Here we make a list of all the test cases we want to add to the test suite
237 * This is a helper to create a test case object from a test case
239 * use KUnit, just know that this is how you associate test cases with a
240 * test suite.
255 * Test cases are defined as belonging to the suite by adding them to
259 * will be used by every test; this is accomplished with an `init` function
260 * which runs before each test case is invoked. Similarly, an `exit` function
261 * may be specified which runs after every test case and can be used to for
262 * cleanup. For clarity, running tests in a test suite would behave as follows:
265 * suite.init(test);
266 * suite.test_case[0](test);
267 * suite.exit(test);
268 * suite.init(test);
269 * suite.test_case[1](test);
270 * suite.exit(test);
284 * This registers the above test suite telling KUnit that this is a suite of