Lines Matching full:test

3  * Test cases for string functions.
8 #include <kunit/test.h>
16 #define STRCMP_TEST_EXPECT_EQUAL(test, fn, ...) KUNIT_EXPECT_EQ(test, fn(__VA_ARGS__), 0) argument
17 #define STRCMP_TEST_EXPECT_LOWER(test, fn, ...) KUNIT_EXPECT_LT(test, fn(__VA_ARGS__), 0) argument
18 #define STRCMP_TEST_EXPECT_GREATER(test, fn, ...) KUNIT_EXPECT_GT(test, fn(__VA_ARGS__), 0) argument
20 static void string_test_memset16(struct kunit *test) in string_test_memset16() argument
25 p = kunit_kzalloc(test, 256 * 2 * 2, GFP_KERNEL); in string_test_memset16()
26 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p); in string_test_memset16()
35 KUNIT_ASSERT_EQ_MSG(test, v, 0xa1a1, in string_test_memset16()
38 KUNIT_ASSERT_EQ_MSG(test, v, 0xb1b2, in string_test_memset16()
41 KUNIT_ASSERT_EQ_MSG(test, v, 0xa1a1, in string_test_memset16()
49 static void string_test_memset32(struct kunit *test) in string_test_memset32() argument
54 p = kunit_kzalloc(test, 256 * 2 * 4, GFP_KERNEL); in string_test_memset32()
55 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p); in string_test_memset32()
64 KUNIT_ASSERT_EQ_MSG(test, v, 0xa1a1a1a1, in string_test_memset32()
67 KUNIT_ASSERT_EQ_MSG(test, v, 0xb1b2b3b4, in string_test_memset32()
70 KUNIT_ASSERT_EQ_MSG(test, v, 0xa1a1a1a1, in string_test_memset32()
78 static void string_test_memset64(struct kunit *test) in string_test_memset64() argument
83 p = kunit_kzalloc(test, 256 * 2 * 8, GFP_KERNEL); in string_test_memset64()
84 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p); in string_test_memset64()
93 KUNIT_ASSERT_EQ_MSG(test, v, 0xa1a1a1a1a1a1a1a1ULL, in string_test_memset64()
96 KUNIT_ASSERT_EQ_MSG(test, v, 0xb1b2b3b4b5b6b7b8ULL, in string_test_memset64()
99 KUNIT_ASSERT_EQ_MSG(test, v, 0xa1a1a1a1a1a1a1a1ULL, in string_test_memset64()
107 static void string_test_strchr(struct kunit *test) in string_test_strchr() argument
116 KUNIT_ASSERT_EQ_MSG(test, result - test_string, i, in string_test_strchr()
121 KUNIT_ASSERT_PTR_EQ(test, result, empty_string); in string_test_strchr()
124 KUNIT_ASSERT_NULL(test, result); in string_test_strchr()
127 KUNIT_ASSERT_NULL(test, result); in string_test_strchr()
130 static void string_test_strnchr(struct kunit *test) in string_test_strnchr() argument
141 KUNIT_ASSERT_NULL_MSG(test, result, in string_test_strnchr()
144 KUNIT_ASSERT_EQ_MSG(test, result - test_string, i, in string_test_strnchr()
151 KUNIT_ASSERT_NULL(test, result); in string_test_strnchr()
154 KUNIT_ASSERT_PTR_EQ(test, result, empty_string); in string_test_strnchr()
157 KUNIT_ASSERT_NULL(test, result); in string_test_strnchr()
160 KUNIT_ASSERT_NULL(test, result); in string_test_strnchr()
163 static void string_test_strspn(struct kunit *test) in string_test_strspn() argument
181 KUNIT_ASSERT_EQ_MSG(test, s->a, strspn(s->str, s->accept), in string_test_strspn()
183 KUNIT_ASSERT_EQ_MSG(test, s->r, strcspn(s->str, s->reject), in string_test_strspn()
199 static void string_test_strcmp(struct kunit *test) in string_test_strcmp() argument
202 STRCMP_TEST_EXPECT_EQUAL(test, strcmp, "Hello, Kernel!", "Hello, Kernel!"); in string_test_strcmp()
204 STRCMP_TEST_EXPECT_LOWER(test, strcmp, "Hello, KUnit!", "Hello, Kernel!"); in string_test_strcmp()
206 STRCMP_TEST_EXPECT_GREATER(test, strcmp, "Hello, Kernel!", "Hello, KUnit!"); in string_test_strcmp()
208 STRCMP_TEST_EXPECT_LOWER(test, strcmp, "", "Non-empty string"); in string_test_strcmp()
210 STRCMP_TEST_EXPECT_EQUAL(test, strcmp, "", ""); in string_test_strcmp()
212 STRCMP_TEST_EXPECT_LOWER(test, strcmp, "Abacaba", "Abadaba"); in string_test_strcmp()
214 STRCMP_TEST_EXPECT_LOWER(test, strcmp, "Just a string", "Just a string and something else"); in string_test_strcmp()
217 static void string_test_strcmp_long_strings(struct kunit *test) in string_test_strcmp_long_strings() argument
220 STRCMP_TEST_EXPECT_EQUAL(test, strcmp, strcmp_buffer1, strcmp_buffer2); in string_test_strcmp_long_strings()
223 STRCMP_TEST_EXPECT_LOWER(test, strcmp, strcmp_buffer1, strcmp_buffer2); in string_test_strcmp_long_strings()
226 STRCMP_TEST_EXPECT_GREATER(test, strcmp, strcmp_buffer1, strcmp_buffer2); in string_test_strcmp_long_strings()
229 static void string_test_strncmp(struct kunit *test) in string_test_strncmp() argument
232 STRCMP_TEST_EXPECT_EQUAL(test, strncmp, "Hello, KUnit!", "Hello, KUnit!", 13); in string_test_strncmp()
234 STRCMP_TEST_EXPECT_LOWER(test, strncmp, "Hello, KUnit!", "Hello, Kernel!", 13); in string_test_strncmp()
236 STRCMP_TEST_EXPECT_EQUAL(test, strncmp, "Hello, Kernel!", "Hello, KUnit!", 0); in string_test_strncmp()
238 STRCMP_TEST_EXPECT_EQUAL(test, strncmp, "Abacaba", "Abadaba", 3); in string_test_strncmp()
240 STRCMP_TEST_EXPECT_LOWER(test, strncmp, "Abacaba", "Abadaba", 4); in string_test_strncmp()
242 STRCMP_TEST_EXPECT_LOWER(test, strncmp, "Just a string", "Just a string and something else", in string_test_strncmp()
248 STRCMP_TEST_EXPECT_EQUAL(test, strncmp, "Just a string", "Just a string and something else", in string_test_strncmp()
252 static void string_test_strncmp_long_strings(struct kunit *test) in string_test_strncmp_long_strings() argument
255 STRCMP_TEST_EXPECT_EQUAL(test, strncmp, strcmp_buffer1, in string_test_strncmp_long_strings()
259 STRCMP_TEST_EXPECT_LOWER(test, strncmp, strcmp_buffer1, in string_test_strncmp_long_strings()
263 STRCMP_TEST_EXPECT_GREATER(test, strncmp, strcmp_buffer1, in string_test_strncmp_long_strings()
266 STRCMP_TEST_EXPECT_EQUAL(test, strncmp, strcmp_buffer1, in string_test_strncmp_long_strings()
268 STRCMP_TEST_EXPECT_GREATER(test, strncmp, strcmp_buffer1, in string_test_strncmp_long_strings()
272 static void string_test_strcasecmp(struct kunit *test) in string_test_strcasecmp() argument
275 STRCMP_TEST_EXPECT_EQUAL(test, strcasecmp, "Hello, Kernel!", "HeLLO, KErNeL!"); in string_test_strcasecmp()
277 STRCMP_TEST_EXPECT_EQUAL(test, strcasecmp, "", ""); in string_test_strcasecmp()
279 STRCMP_TEST_EXPECT_LOWER(test, strcasecmp, "a", "B"); in string_test_strcasecmp()
280 STRCMP_TEST_EXPECT_GREATER(test, strcasecmp, "B", "a"); in string_test_strcasecmp()
282 STRCMP_TEST_EXPECT_EQUAL(test, strcasecmp, "-+**.1230ghTTT~^", "-+**.1230Ghttt~^"); in string_test_strcasecmp()
285 static void string_test_strcasecmp_long_strings(struct kunit *test) in string_test_strcasecmp_long_strings() argument
288 STRCMP_TEST_EXPECT_EQUAL(test, strcasecmp, strcmp_buffer1, strcmp_buffer2); in string_test_strcasecmp_long_strings()
291 STRCMP_TEST_EXPECT_LOWER(test, strcasecmp, strcmp_buffer1, strcmp_buffer2); in string_test_strcasecmp_long_strings()
294 STRCMP_TEST_EXPECT_GREATER(test, strcasecmp, strcmp_buffer1, strcmp_buffer2); in string_test_strcasecmp_long_strings()
297 static void string_test_strncasecmp(struct kunit *test) in string_test_strncasecmp() argument
300 STRCMP_TEST_EXPECT_EQUAL(test, strncasecmp, "AbAcAbA", "Abacaba", strlen("Abacaba")); in string_test_strncasecmp()
302 STRCMP_TEST_EXPECT_EQUAL(test, strncasecmp, "AbaCaBa", "abaCaDa", 5); in string_test_strncasecmp()
303 STRCMP_TEST_EXPECT_LOWER(test, strncasecmp, "a", "B", 1); in string_test_strncasecmp()
304 STRCMP_TEST_EXPECT_GREATER(test, strncasecmp, "B", "a", 1); in string_test_strncasecmp()
306 STRCMP_TEST_EXPECT_EQUAL(test, strncasecmp, "Abacaba", "Not abacaba", 0); in string_test_strncasecmp()
309 static void string_test_strncasecmp_long_strings(struct kunit *test) in string_test_strncasecmp_long_strings() argument
312 STRCMP_TEST_EXPECT_EQUAL(test, strncasecmp, strcmp_buffer1, in string_test_strncasecmp_long_strings()
316 STRCMP_TEST_EXPECT_LOWER(test, strncasecmp, strcmp_buffer1, in string_test_strncasecmp_long_strings()
320 STRCMP_TEST_EXPECT_GREATER(test, strncasecmp, strcmp_buffer1, in string_test_strncasecmp_long_strings()
323 STRCMP_TEST_EXPECT_EQUAL(test, strncasecmp, strcmp_buffer1, in string_test_strncasecmp_long_strings()
325 STRCMP_TEST_EXPECT_GREATER(test, strncasecmp, strcmp_buffer1, in string_test_strncasecmp_long_strings()
330 * strscpy_check() - Run a specific test case.
331 * @test: KUnit test context pointer
344 static void strscpy_check(struct kunit *test, char *src, int count, in strscpy_check() argument
355 KUNIT_ASSERT_TRUE_MSG(test, src != NULL, in strscpy_check()
359 /* Future proofing test suite, validate args */ in strscpy_check()
363 KUNIT_ASSERT_LE_MSG(test, count, max_count, in strscpy_check()
365 KUNIT_EXPECT_LE_MSG(test, expected, max_expected, in strscpy_check()
370 KUNIT_ASSERT_EQ(test, written, expected); in strscpy_check()
373 KUNIT_ASSERT_EQ_MSG(test, 0, strncmp(buf, src, count - 1), in strscpy_check()
375 KUNIT_ASSERT_EQ_MSG(test, buf[count - 1], '\0', in strscpy_check()
380 KUNIT_ASSERT_EQ_MSG(test, buf[i], src[i], in strscpy_check()
384 KUNIT_ASSERT_EQ_MSG(test, buf[count - 1], '\0', in strscpy_check()
389 KUNIT_ASSERT_EQ_MSG(test, buf[index], '\0', in strscpy_check()
396 KUNIT_ASSERT_EQ_MSG(test, buf[index], POISON, in strscpy_check()
401 static void string_test_strscpy(struct kunit *test) in string_test_strscpy() argument
410 * should not exceed 4. To test with longer strings increase in string_test_strscpy()
414 /* strscpy_check(test, src, count, expected, chars, terminator, pad) */ in string_test_strscpy()
415 strscpy_check(test, "a", 0, -E2BIG, 0, 0, 0); in string_test_strscpy()
416 strscpy_check(test, "", 0, -E2BIG, 0, 0, 0); in string_test_strscpy()
418 strscpy_check(test, "a", 1, -E2BIG, 0, 1, 0); in string_test_strscpy()
419 strscpy_check(test, "", 1, 0, 0, 1, 0); in string_test_strscpy()
421 strscpy_check(test, "ab", 2, -E2BIG, 1, 1, 0); in string_test_strscpy()
422 strscpy_check(test, "a", 2, 1, 1, 1, 0); in string_test_strscpy()
423 strscpy_check(test, "", 2, 0, 0, 1, 1); in string_test_strscpy()
425 strscpy_check(test, "abc", 3, -E2BIG, 2, 1, 0); in string_test_strscpy()
426 strscpy_check(test, "ab", 3, 2, 2, 1, 0); in string_test_strscpy()
427 strscpy_check(test, "a", 3, 1, 1, 1, 1); in string_test_strscpy()
428 strscpy_check(test, "", 3, 0, 0, 1, 2); in string_test_strscpy()
430 strscpy_check(test, "abcd", 4, -E2BIG, 3, 1, 0); in string_test_strscpy()
431 strscpy_check(test, "abc", 4, 3, 3, 1, 0); in string_test_strscpy()
432 strscpy_check(test, "ab", 4, 2, 2, 1, 1); in string_test_strscpy()
433 strscpy_check(test, "a", 4, 1, 1, 1, 2); in string_test_strscpy()
434 strscpy_check(test, "", 4, 0, 0, 1, 3); in string_test_strscpy()
437 KUNIT_EXPECT_EQ(test, strscpy(dest, "", ARRAY_SIZE(dest)), 0); in string_test_strscpy()
438 KUNIT_EXPECT_EQ(test, strscpy(dest, "", 3), 0); in string_test_strscpy()
439 KUNIT_EXPECT_EQ(test, strscpy(dest, "", 1), 0); in string_test_strscpy()
440 KUNIT_EXPECT_EQ(test, strscpy(dest, "", 0), -E2BIG); in string_test_strscpy()
441 KUNIT_EXPECT_EQ(test, strscpy(dest, "Fixed", ARRAY_SIZE(dest)), 5); in string_test_strscpy()
442 KUNIT_EXPECT_EQ(test, strscpy(dest, "Fixed", 3), -E2BIG); in string_test_strscpy()
443 KUNIT_EXPECT_EQ(test, strscpy(dest, "Fixed", 1), -E2BIG); in string_test_strscpy()
444 KUNIT_EXPECT_EQ(test, strscpy(dest, "Fixed", 0), -E2BIG); in string_test_strscpy()
445 KUNIT_EXPECT_EQ(test, strscpy(dest, "This is too long", ARRAY_SIZE(dest)), -E2BIG); in string_test_strscpy()
450 static void string_test_strcat(struct kunit *test) in string_test_strcat() argument
456 KUNIT_EXPECT_EQ(test, strlen(dest), 0); in string_test_strcat()
458 KUNIT_EXPECT_TRUE(test, strcat(dest, "") == dest); in string_test_strcat()
459 KUNIT_EXPECT_STREQ(test, dest, ""); in string_test_strcat()
461 KUNIT_EXPECT_TRUE(test, strcat(dest, "four\000123") == dest); in string_test_strcat()
462 KUNIT_EXPECT_STREQ(test, dest, "four"); in string_test_strcat()
463 KUNIT_EXPECT_EQ(test, dest[5], '\0'); in string_test_strcat()
465 KUNIT_EXPECT_TRUE(test, strcat(dest, "AB") == dest); in string_test_strcat()
466 KUNIT_EXPECT_STREQ(test, dest, "fourAB"); in string_test_strcat()
469 static void string_test_strncat(struct kunit *test) in string_test_strncat() argument
475 KUNIT_EXPECT_EQ(test, strlen(dest), 0); in string_test_strncat()
477 KUNIT_EXPECT_TRUE(test, strncat(dest, "", 0 + unconst) == dest); in string_test_strncat()
478 KUNIT_EXPECT_STREQ(test, dest, ""); in string_test_strncat()
480 KUNIT_EXPECT_TRUE(test, strncat(dest, "", 1 + unconst) == dest); in string_test_strncat()
481 KUNIT_EXPECT_STREQ(test, dest, ""); in string_test_strncat()
483 KUNIT_EXPECT_TRUE(test, strncat(dest, "asdf", 0 + unconst) == dest); in string_test_strncat()
484 KUNIT_EXPECT_STREQ(test, dest, ""); in string_test_strncat()
487 KUNIT_EXPECT_TRUE(test, strncat(dest, "four\000123", 8 + unconst) == dest); in string_test_strncat()
488 KUNIT_EXPECT_STREQ(test, dest, "four"); in string_test_strncat()
489 KUNIT_EXPECT_EQ(test, dest[5], '\0'); in string_test_strncat()
490 KUNIT_EXPECT_EQ(test, dest[6], '\0'); in string_test_strncat()
492 KUNIT_EXPECT_TRUE(test, strncat(dest, "ABCD", 2 + unconst) == dest); in string_test_strncat()
493 KUNIT_EXPECT_STREQ(test, dest, "fourAB"); in string_test_strncat()
496 static void string_test_strlcat(struct kunit *test) in string_test_strlcat() argument
502 KUNIT_EXPECT_EQ(test, strlen(dest), 0); in string_test_strlcat()
504 KUNIT_EXPECT_EQ(test, strlcat(dest, "", len), 0); in string_test_strlcat()
505 KUNIT_EXPECT_STREQ(test, dest, ""); in string_test_strlcat()
507 KUNIT_EXPECT_EQ(test, strlcat(dest, "four", 1 + unconst), 4); in string_test_strlcat()
508 KUNIT_EXPECT_STREQ(test, dest, ""); in string_test_strlcat()
511 KUNIT_EXPECT_EQ(test, strlcat(dest, "four", len), 4); in string_test_strlcat()
512 KUNIT_EXPECT_STREQ(test, dest, "four"); in string_test_strlcat()
514 KUNIT_EXPECT_EQ(test, strlcat(dest, "AB", len), 6); in string_test_strlcat()
515 KUNIT_EXPECT_STREQ(test, dest, "fourAB"); in string_test_strlcat()
517 KUNIT_EXPECT_EQ(test, strlcat(dest, "CD", 7 + unconst), 8); in string_test_strlcat()
518 KUNIT_EXPECT_STREQ(test, dest, "fourAB"); in string_test_strlcat()
520 KUNIT_EXPECT_EQ(test, strlcat(dest, "EFG", len), 9); in string_test_strlcat()
521 KUNIT_EXPECT_STREQ(test, dest, "fourABE"); in string_test_strlcat()
523 KUNIT_EXPECT_EQ(test, strlcat(dest, "1234", len), 11); in string_test_strlcat()
524 KUNIT_EXPECT_STREQ(test, dest, "fourABE"); in string_test_strlcat()
527 static void string_test_strtomem(struct kunit *test) in string_test_strtomem() argument
538 KUNIT_EXPECT_EQ_MSG(test, wrap.canary1, ULONG_MAX, in string_test_strtomem()
540 KUNIT_EXPECT_EQ_MSG(test, wrap.canary2, ULONG_MAX, in string_test_strtomem()
545 KUNIT_EXPECT_EQ(test, wrap.canary1, ULONG_MAX); in string_test_strtomem()
546 KUNIT_EXPECT_EQ(test, wrap.output[0], input[0]); in string_test_strtomem()
547 KUNIT_EXPECT_EQ(test, wrap.output[1], input[1]); in string_test_strtomem()
549 KUNIT_EXPECT_EQ(test, wrap.output[i], 0xFF); in string_test_strtomem()
550 KUNIT_EXPECT_EQ(test, wrap.canary2, ULONG_MAX); in string_test_strtomem()
555 KUNIT_EXPECT_EQ(test, wrap.canary1, ULONG_MAX); in string_test_strtomem()
557 KUNIT_EXPECT_EQ(test, wrap.output[i], truncate[i]); in string_test_strtomem()
558 KUNIT_EXPECT_EQ(test, wrap.canary2, ULONG_MAX); in string_test_strtomem()
563 KUNIT_EXPECT_EQ(test, wrap.canary1, ULONG_MAX); in string_test_strtomem()
564 KUNIT_EXPECT_EQ(test, wrap.output[0], input[0]); in string_test_strtomem()
565 KUNIT_EXPECT_EQ(test, wrap.output[1], input[1]); in string_test_strtomem()
567 KUNIT_EXPECT_EQ(test, wrap.output[i], 0xAA); in string_test_strtomem()
568 KUNIT_EXPECT_EQ(test, wrap.canary2, ULONG_MAX); in string_test_strtomem()
573 KUNIT_EXPECT_EQ(test, wrap.canary1, ULONG_MAX); in string_test_strtomem()
575 KUNIT_EXPECT_EQ(test, wrap.output[i], truncate[i]); in string_test_strtomem()
576 KUNIT_EXPECT_EQ(test, wrap.canary2, ULONG_MAX); in string_test_strtomem()
580 static void string_test_memtostr(struct kunit *test) in string_test_memtostr() argument
587 KUNIT_EXPECT_EQ(test, sizeof(dest), sizeof(nonstring) + 1); in string_test_memtostr()
590 KUNIT_EXPECT_STREQ(test, dest, "abcdefg"); in string_test_memtostr()
593 KUNIT_EXPECT_STREQ(test, dest, "abc"); in string_test_memtostr()
594 KUNIT_EXPECT_EQ(test, dest[7], 'X'); in string_test_memtostr()
598 KUNIT_EXPECT_STREQ(test, dest, "abcdefg"); in string_test_memtostr()
601 KUNIT_EXPECT_STREQ(test, dest, "abc"); in string_test_memtostr()
602 KUNIT_EXPECT_EQ(test, dest[7], '\0'); in string_test_memtostr()
636 MODULE_DESCRIPTION("Test cases for string functions");