Lines Matching full:test
3 * KUnit test for the assertion formatting functions.
6 #include <kunit/test.h>
11 #define ASSERT_TEST_EXPECT_CONTAIN(test, str, substr) KUNIT_EXPECT_TRUE(test, strstr(str, substr)) argument
12 #define ASSERT_TEST_EXPECT_NCONTAIN(test, str, substr) KUNIT_EXPECT_FALSE(test, strstr(str, substr)) argument
14 static void kunit_test_is_literal(struct kunit *test) in kunit_test_is_literal() argument
16 KUNIT_EXPECT_TRUE(test, is_literal("5", 5)); in kunit_test_is_literal()
17 KUNIT_EXPECT_TRUE(test, is_literal("0", 0)); in kunit_test_is_literal()
18 KUNIT_EXPECT_TRUE(test, is_literal("1234567890", 1234567890)); in kunit_test_is_literal()
19 KUNIT_EXPECT_TRUE(test, is_literal("-1234567890", -1234567890)); in kunit_test_is_literal()
20 KUNIT_EXPECT_FALSE(test, is_literal("05", 5)); in kunit_test_is_literal()
21 KUNIT_EXPECT_FALSE(test, is_literal("", 0)); in kunit_test_is_literal()
22 KUNIT_EXPECT_FALSE(test, is_literal("-0", 0)); in kunit_test_is_literal()
23 KUNIT_EXPECT_FALSE(test, is_literal("12#45", 1245)); in kunit_test_is_literal()
26 static void kunit_test_is_str_literal(struct kunit *test) in kunit_test_is_str_literal() argument
28 KUNIT_EXPECT_TRUE(test, is_str_literal("\"Hello, World!\"", "Hello, World!")); in kunit_test_is_str_literal()
29 KUNIT_EXPECT_TRUE(test, is_str_literal("\"\"", "")); in kunit_test_is_str_literal()
30 KUNIT_EXPECT_TRUE(test, is_str_literal("\"\"\"", "\"")); in kunit_test_is_str_literal()
31 KUNIT_EXPECT_FALSE(test, is_str_literal("", "")); in kunit_test_is_str_literal()
32 KUNIT_EXPECT_FALSE(test, is_str_literal("\"", "\"")); in kunit_test_is_str_literal()
33 KUNIT_EXPECT_FALSE(test, is_str_literal("\"Abacaba", "Abacaba")); in kunit_test_is_str_literal()
34 KUNIT_EXPECT_FALSE(test, is_str_literal("Abacaba\"", "Abacaba")); in kunit_test_is_str_literal()
35 KUNIT_EXPECT_FALSE(test, is_str_literal("\"Abacaba\"", "\"Abacaba\"")); in kunit_test_is_str_literal()
41 static char *get_str_from_stream(struct kunit *test, struct string_stream *stream) in get_str_from_stream() argument
45 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, str); in get_str_from_stream()
46 kunit_add_action(test, kfree_wrapper, (void *)str); in get_str_from_stream()
51 static void kunit_test_assert_prologue(struct kunit *test) in kunit_test_assert_prologue() argument
60 stream = kunit_alloc_string_stream(test, GFP_KERNEL); in kunit_test_assert_prologue()
61 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, stream); in kunit_test_assert_prologue()
63 /* Test an expectation fail prologue */ in kunit_test_assert_prologue()
65 str = get_str_from_stream(test, stream); in kunit_test_assert_prologue()
66 ASSERT_TEST_EXPECT_CONTAIN(test, str, "EXPECTATION"); in kunit_test_assert_prologue()
67 ASSERT_TEST_EXPECT_CONTAIN(test, str, "testfile.c"); in kunit_test_assert_prologue()
68 ASSERT_TEST_EXPECT_CONTAIN(test, str, "1337"); in kunit_test_assert_prologue()
70 /* Test an assertion fail prologue */ in kunit_test_assert_prologue()
73 str = get_str_from_stream(test, stream); in kunit_test_assert_prologue()
74 ASSERT_TEST_EXPECT_CONTAIN(test, str, "ASSERTION"); in kunit_test_assert_prologue()
75 ASSERT_TEST_EXPECT_CONTAIN(test, str, "testfile.c"); in kunit_test_assert_prologue()
76 ASSERT_TEST_EXPECT_CONTAIN(test, str, "1337"); in kunit_test_assert_prologue()
83 static void verify_assert_print_msg(struct kunit *test, in verify_assert_print_msg() argument
96 KUNIT_EXPECT_STREQ(test, get_str_from_stream(test, stream), expected); in verify_assert_print_msg()
99 static void kunit_test_assert_print_msg(struct kunit *test) in kunit_test_assert_print_msg() argument
103 stream = kunit_alloc_string_stream(test, GFP_KERNEL); in kunit_test_assert_print_msg()
104 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, stream); in kunit_test_assert_print_msg()
106 verify_assert_print_msg(test, stream, "\nTest", "Test"); in kunit_test_assert_print_msg()
107 verify_assert_print_msg(test, stream, "\nAbacaba -123 234", "%s %d %u", in kunit_test_assert_print_msg()
109 verify_assert_print_msg(test, stream, "", NULL); in kunit_test_assert_print_msg()
118 static void validate_assert(assert_format_t format_func, struct kunit *test, in validate_assert() argument
133 ASSERT_TEST_EXPECT_CONTAIN(test, get_str_from_stream(test, stream), cur_substr_exp); in validate_assert()
137 static void kunit_test_unary_assert_format(struct kunit *test) in kunit_test_unary_assert_format() argument
147 stream = kunit_alloc_string_stream(test, GFP_KERNEL); in kunit_test_unary_assert_format()
148 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, stream); in kunit_test_unary_assert_format()
150 validate_assert(kunit_unary_assert_format, test, &un_assert.assert, in kunit_test_unary_assert_format()
154 validate_assert(kunit_unary_assert_format, test, &un_assert.assert, in kunit_test_unary_assert_format()
158 static void kunit_test_ptr_not_err_assert_format(struct kunit *test) in kunit_test_ptr_not_err_assert_format() argument
168 stream = kunit_alloc_string_stream(test, GFP_KERNEL); in kunit_test_ptr_not_err_assert_format()
169 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, stream); in kunit_test_ptr_not_err_assert_format()
172 validate_assert(kunit_ptr_not_err_assert_format, test, in kunit_test_ptr_not_err_assert_format()
178 validate_assert(kunit_ptr_not_err_assert_format, test, in kunit_test_ptr_not_err_assert_format()
183 static void kunit_test_binary_assert_format(struct kunit *test) in kunit_test_binary_assert_format() argument
199 stream = kunit_alloc_string_stream(test, GFP_KERNEL); in kunit_test_binary_assert_format()
200 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, stream); in kunit_test_binary_assert_format()
206 validate_assert(kunit_binary_assert_format, test, &binary_assert.assert, in kunit_test_binary_assert_format()
210 validate_assert(kunit_binary_assert_format, test, &binary_assert.assert, in kunit_test_binary_assert_format()
214 validate_assert(kunit_binary_assert_format, test, &binary_assert.assert, in kunit_test_binary_assert_format()
218 validate_assert(kunit_binary_assert_format, test, &binary_assert.assert, in kunit_test_binary_assert_format()
222 static void kunit_test_binary_ptr_assert_format(struct kunit *test) in kunit_test_binary_ptr_assert_format() argument
241 addr_var_a = kunit_kzalloc(test, TEST_PTR_EXPECTED_BUF_SIZE, GFP_KERNEL); in kunit_test_binary_ptr_assert_format()
242 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, addr_var_a); in kunit_test_binary_ptr_assert_format()
243 addr_var_b = kunit_kzalloc(test, TEST_PTR_EXPECTED_BUF_SIZE, GFP_KERNEL); in kunit_test_binary_ptr_assert_format()
244 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, addr_var_b); in kunit_test_binary_ptr_assert_format()
253 stream = kunit_alloc_string_stream(test, GFP_KERNEL); in kunit_test_binary_ptr_assert_format()
254 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, stream); in kunit_test_binary_ptr_assert_format()
255 validate_assert(kunit_binary_ptr_assert_format, test, &binary_ptr_assert.assert, in kunit_test_binary_ptr_assert_format()
259 static void kunit_test_binary_str_assert_format(struct kunit *test) in kunit_test_binary_str_assert_format() argument
277 stream = kunit_alloc_string_stream(test, GFP_KERNEL); in kunit_test_binary_str_assert_format()
278 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, stream); in kunit_test_binary_str_assert_format()
280 validate_assert(kunit_binary_str_assert_format, test, in kunit_test_binary_str_assert_format()
286 validate_assert(kunit_binary_str_assert_format, test, &binary_str_assert.assert, in kunit_test_binary_str_assert_format()
290 validate_assert(kunit_binary_str_assert_format, test, &binary_str_assert.assert, in kunit_test_binary_str_assert_format()
302 static void kunit_test_assert_hexdump(struct kunit *test) in kunit_test_assert_hexdump() argument
309 stream = kunit_alloc_string_stream(test, GFP_KERNEL); in kunit_test_assert_hexdump()
310 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, stream); in kunit_test_assert_hexdump()
313 str = get_str_from_stream(test, stream); in kunit_test_assert_hexdump()
317 ASSERT_TEST_EXPECT_CONTAIN(test, str, buf); in kunit_test_assert_hexdump()
322 str = get_str_from_stream(test, stream); in kunit_test_assert_hexdump()
323 ASSERT_TEST_EXPECT_NCONTAIN(test, str, "<"); in kunit_test_assert_hexdump()
324 ASSERT_TEST_EXPECT_NCONTAIN(test, str, ">"); in kunit_test_assert_hexdump()
327 static void kunit_test_mem_assert_format(struct kunit *test) in kunit_test_mem_assert_format() argument
345 expected_stream = kunit_alloc_string_stream(test, GFP_KERNEL); in kunit_test_mem_assert_format()
346 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, expected_stream); in kunit_test_mem_assert_format()
347 stream = kunit_alloc_string_stream(test, GFP_KERNEL); in kunit_test_mem_assert_format()
348 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, stream); in kunit_test_mem_assert_format()
351 validate_assert(kunit_mem_assert_format, test, &mem_assert.assert, in kunit_test_mem_assert_format()
357 validate_assert(kunit_mem_assert_format, test, &mem_assert.assert, in kunit_test_mem_assert_format()
364 validate_assert(kunit_mem_assert_format, test, &mem_assert.assert, in kunit_test_mem_assert_format()