88#include <kunit/test.h>
99#include <linux/string.h>
1010
11- /*
12- * tc() - Run a specific test case.
11+ /**
12+ * strscpy_check() - Run a specific test case.
13+ * @test: KUnit test context pointer
1314 * @src: Source string, argument to strscpy_pad()
1415 * @count: Size of destination buffer, argument to strscpy_pad()
1516 * @expected: Expected return value from call to strscpy_pad()
16- * @terminator: 1 if there should be a terminating null byte 0 otherwise.
1717 * @chars: Number of characters from the src string expected to be
1818 * written to the dst buffer.
19+ * @terminator: 1 if there should be a terminating null byte 0 otherwise.
1920 * @pad: Number of pad characters expected (in the tail of dst buffer).
2021 * (@pad does not include the null terminator byte.)
2122 *
2223 * Calls strscpy_pad() and verifies the return value and state of the
2324 * destination buffer after the call returns.
2425 */
25- static void tc (struct kunit * test , char * src , int count , int expected ,
26- int chars , int terminator , int pad )
26+ static void strscpy_check (struct kunit * test , char * src , int count ,
27+ int expected , int chars , int terminator , int pad )
2728{
2829 int nr_bytes_poison ;
2930 int max_expected ;
@@ -79,40 +80,40 @@ static void tc(struct kunit *test, char *src, int count, int expected,
7980 }
8081}
8182
82- static void strscpy_test (struct kunit * test )
83+ static void test_strscpy (struct kunit * test )
8384{
8485 char dest [8 ];
8586
8687 /*
87- * tc () uses a destination buffer of size 6 and needs at
88+ * strscpy_check () uses a destination buffer of size 6 and needs at
8889 * least 2 characters spare (one for null and one to check for
8990 * overflow). This means we should only call tc() with
9091 * strings up to a maximum of 4 characters long and 'count'
9192 * should not exceed 4. To test with longer strings increase
9293 * the buffer size in tc().
9394 */
9495
95- /* tc (test, src, count, expected, chars, terminator, pad) */
96- tc (test , "a" , 0 , - E2BIG , 0 , 0 , 0 );
97- tc (test , "" , 0 , - E2BIG , 0 , 0 , 0 );
96+ /* strscpy_check (test, src, count, expected, chars, terminator, pad) */
97+ strscpy_check (test , "a" , 0 , - E2BIG , 0 , 0 , 0 );
98+ strscpy_check (test , "" , 0 , - E2BIG , 0 , 0 , 0 );
9899
99- tc (test , "a" , 1 , - E2BIG , 0 , 1 , 0 );
100- tc (test , "" , 1 , 0 , 0 , 1 , 0 );
100+ strscpy_check (test , "a" , 1 , - E2BIG , 0 , 1 , 0 );
101+ strscpy_check (test , "" , 1 , 0 , 0 , 1 , 0 );
101102
102- tc (test , "ab" , 2 , - E2BIG , 1 , 1 , 0 );
103- tc (test , "a" , 2 , 1 , 1 , 1 , 0 );
104- tc (test , "" , 2 , 0 , 0 , 1 , 1 );
103+ strscpy_check (test , "ab" , 2 , - E2BIG , 1 , 1 , 0 );
104+ strscpy_check (test , "a" , 2 , 1 , 1 , 1 , 0 );
105+ strscpy_check (test , "" , 2 , 0 , 0 , 1 , 1 );
105106
106- tc (test , "abc" , 3 , - E2BIG , 2 , 1 , 0 );
107- tc (test , "ab" , 3 , 2 , 2 , 1 , 0 );
108- tc (test , "a" , 3 , 1 , 1 , 1 , 1 );
109- tc (test , "" , 3 , 0 , 0 , 1 , 2 );
107+ strscpy_check (test , "abc" , 3 , - E2BIG , 2 , 1 , 0 );
108+ strscpy_check (test , "ab" , 3 , 2 , 2 , 1 , 0 );
109+ strscpy_check (test , "a" , 3 , 1 , 1 , 1 , 1 );
110+ strscpy_check (test , "" , 3 , 0 , 0 , 1 , 2 );
110111
111- tc (test , "abcd" , 4 , - E2BIG , 3 , 1 , 0 );
112- tc (test , "abc" , 4 , 3 , 3 , 1 , 0 );
113- tc (test , "ab" , 4 , 2 , 2 , 1 , 1 );
114- tc (test , "a" , 4 , 1 , 1 , 1 , 2 );
115- tc (test , "" , 4 , 0 , 0 , 1 , 3 );
112+ strscpy_check (test , "abcd" , 4 , - E2BIG , 3 , 1 , 0 );
113+ strscpy_check (test , "abc" , 4 , 3 , 3 , 1 , 0 );
114+ strscpy_check (test , "ab" , 4 , 2 , 2 , 1 , 1 );
115+ strscpy_check (test , "a" , 4 , 1 , 1 , 1 , 2 );
116+ strscpy_check (test , "" , 4 , 0 , 0 , 1 , 3 );
116117
117118 /* Compile-time-known source strings. */
118119 KUNIT_EXPECT_EQ (test , strscpy (dest , "" , ARRAY_SIZE (dest )), 0 );
@@ -127,7 +128,7 @@ static void strscpy_test(struct kunit *test)
127128}
128129
129130static struct kunit_case strscpy_test_cases [] = {
130- KUNIT_CASE (strscpy_test ),
131+ KUNIT_CASE (test_strscpy ),
131132 {}
132133};
133134
0 commit comments