Lines Matching full:test

3  * Example KUnit test to show how to use KUnit.
9 #include <kunit/test.h>
12 * This is the most fundamental element of KUnit, the test case. A test case
14 * any expectations or assertions are not met, the test fails; otherwise, the
15 * test passes.
17 * In KUnit, a test case is just a function with the signature
19 * information about the current test.
21 static void example_simple_test(struct kunit *test) in example_simple_test() argument
25 * to test a piece of code, you set some expectations about what the in example_simple_test()
26 * code should do. KUnit then runs the test and verifies that the code's in example_simple_test()
29 KUNIT_EXPECT_EQ(test, 1 + 1, 2); in example_simple_test()
33 * This is run once before each test case, see the comment on
36 static int example_test_init(struct kunit *test) in example_test_init() argument
38 kunit_info(test, "initializing\n"); in example_test_init()
44 * This is run once before all test cases in the suite.
55 * This test should always be skipped.
57 static void example_skip_test(struct kunit *test) in example_skip_test() argument
60 kunit_info(test, "You should not see a line below."); in example_skip_test()
62 /* Skip (and abort) the test */ in example_skip_test()
63 kunit_skip(test, "this test should be skipped"); in example_skip_test()
66 KUNIT_FAIL(test, "You should not see this line."); in example_skip_test()
70 * This test should always be marked skipped.
72 static void example_mark_skipped_test(struct kunit *test) in example_mark_skipped_test() argument
75 kunit_info(test, "You should see a line below."); in example_mark_skipped_test()
77 /* Skip (but do not abort) the test */ in example_mark_skipped_test()
78 kunit_mark_skipped(test, "this test should be skipped"); in example_mark_skipped_test()
81 kunit_info(test, "You should see this line."); in example_mark_skipped_test()
85 * This test shows off all the types of KUNIT_EXPECT macros.
87 static void example_all_expect_macros_test(struct kunit *test) in example_all_expect_macros_test() argument
90 KUNIT_EXPECT_TRUE(test, true); in example_all_expect_macros_test()
91 KUNIT_EXPECT_FALSE(test, false); in example_all_expect_macros_test()
94 KUNIT_EXPECT_EQ(test, 1, 1); /* check == */ in example_all_expect_macros_test()
95 KUNIT_EXPECT_GE(test, 1, 1); /* check >= */ in example_all_expect_macros_test()
96 KUNIT_EXPECT_LE(test, 1, 1); /* check <= */ in example_all_expect_macros_test()
97 KUNIT_EXPECT_NE(test, 1, 0); /* check != */ in example_all_expect_macros_test()
98 KUNIT_EXPECT_GT(test, 1, 0); /* check > */ in example_all_expect_macros_test()
99 KUNIT_EXPECT_LT(test, 0, 1); /* check < */ in example_all_expect_macros_test()
102 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, test); in example_all_expect_macros_test()
103 KUNIT_EXPECT_PTR_EQ(test, NULL, NULL); in example_all_expect_macros_test()
104 KUNIT_EXPECT_PTR_NE(test, test, NULL); in example_all_expect_macros_test()
105 KUNIT_EXPECT_NULL(test, NULL); in example_all_expect_macros_test()
106 KUNIT_EXPECT_NOT_NULL(test, test); in example_all_expect_macros_test()
109 KUNIT_EXPECT_STREQ(test, "hi", "hi"); in example_all_expect_macros_test()
110 KUNIT_EXPECT_STRNEQ(test, "hi", "bye"); in example_all_expect_macros_test()
113 * There are also ASSERT variants of all of the above that abort test in example_all_expect_macros_test()
116 KUNIT_ASSERT_GT(test, sizeof(char), 0); in example_all_expect_macros_test()
122 KUNIT_EXPECT_GT_MSG(test, sizeof(int), 0, "Your ints are 0-bit?!"); in example_all_expect_macros_test()
123 KUNIT_ASSERT_GT_MSG(test, sizeof(int), 0, "Your ints are 0-bit?!"); in example_all_expect_macros_test()
127 * Here we make a list of all the test cases we want to add to the test suite
132 * This is a helper to create a test case object from a test case
134 * use KUnit, just know that this is how you associate test cases with a
135 * test suite.
147 * Test cases are defined as belonging to the suite by adding them to
151 * will be used by every test; this is accomplished with an `init` function
152 * which runs before each test case is invoked. Similarly, an `exit` function
153 * may be specified which runs after every test case and can be used to for
154 * cleanup. For clarity, running tests in a test suite would behave as follows:
157 * suite.init(test);
158 * suite.test_case[0](test);
159 * suite.exit(test);
160 * suite.init(test);
161 * suite.test_case[1](test);
162 * suite.exit(test);
174 * This registers the above test suite telling KUnit that this is a suite of