@@ -38,9 +38,9 @@ static unsigned int total_tests;
38
38
static char * test_buffer ;
39
39
static char * alloced_buffer ;
40
40
41
- static void __printf (5 , 0 )
42
- do_test (struct kunit * kunittest , int bufsize , const char * expect , int elen ,
43
- const char * fmt , va_list ap )
41
+ static void __printf (7 , 0 )
42
+ do_test (struct kunit * kunittest , const char * file , const int line , int bufsize , const char * expect ,
43
+ int elen , const char * fmt , va_list ap )
44
44
{
45
45
va_list aq ;
46
46
int ret , written ;
@@ -53,64 +53,70 @@ do_test(struct kunit *kunittest, int bufsize, const char *expect, int elen,
53
53
va_end (aq );
54
54
55
55
if (ret != elen ) {
56
- KUNIT_FAIL (kunittest , "vsnprintf(buf, %d, \"%s\", ...) returned %d, expected %d\n" ,
57
- bufsize , fmt , ret , elen );
56
+ KUNIT_FAIL (kunittest ,
57
+ "%s:%d: vsnprintf(buf, %d, \"%s\", ...) returned %d, expected %d\n" ,
58
+ file , line , bufsize , fmt , ret , elen );
58
59
return ;
59
60
}
60
61
61
62
if (memchr_inv (alloced_buffer , FILL_CHAR , PAD_SIZE )) {
62
- KUNIT_FAIL (kunittest , "vsnprintf(buf, %d, \"%s\", ...) wrote before buffer\n" ,
63
- bufsize , fmt );
63
+ KUNIT_FAIL (kunittest ,
64
+ "%s:%d: vsnprintf(buf, %d, \"%s\", ...) wrote before buffer\n" ,
65
+ file , line , bufsize , fmt );
64
66
return ;
65
67
}
66
68
67
69
if (!bufsize ) {
68
70
if (memchr_inv (test_buffer , FILL_CHAR , BUF_SIZE + PAD_SIZE )) {
69
- KUNIT_FAIL (kunittest , "vsnprintf(buf, 0, \"%s\", ...) wrote to buffer\n" , fmt );
71
+ KUNIT_FAIL (kunittest ,
72
+ "%s:%d: vsnprintf(buf, 0, \"%s\", ...) wrote to buffer\n" ,
73
+ file , line , fmt );
70
74
}
71
75
return ;
72
76
}
73
77
74
78
written = min (bufsize - 1 , elen );
75
79
if (test_buffer [written ]) {
76
80
KUNIT_FAIL (kunittest ,
77
- "vsnprintf(buf, %d, \"%s\", ...) did not nul-terminate buffer\n" ,
78
- bufsize , fmt );
81
+ "%s:%d: vsnprintf(buf, %d, \"%s\", ...) did not nul-terminate buffer\n" ,
82
+ file , line , bufsize , fmt );
79
83
return ;
80
84
}
81
85
82
86
if (memchr_inv (test_buffer + written + 1 , FILL_CHAR , bufsize - (written + 1 ))) {
83
87
KUNIT_FAIL (kunittest ,
84
- "vsnprintf(buf, %d, \"%s\", ...) wrote beyond the nul-terminator\n" ,
85
- bufsize , fmt );
88
+ "%s:%d: vsnprintf(buf, %d, \"%s\", ...) wrote beyond the nul-terminator\n" ,
89
+ file , line , bufsize , fmt );
86
90
return ;
87
91
}
88
92
89
93
if (memchr_inv (test_buffer + bufsize , FILL_CHAR , BUF_SIZE + PAD_SIZE - bufsize )) {
90
- KUNIT_FAIL (kunittest , "vsnprintf(buf, %d, \"%s\", ...) wrote beyond buffer\n" ,
91
- bufsize , fmt );
94
+ KUNIT_FAIL (kunittest ,
95
+ "%s:%d: vsnprintf(buf, %d, \"%s\", ...) wrote beyond buffer\n" ,
96
+ file , line , bufsize , fmt );
92
97
return ;
93
98
}
94
99
95
100
if (memcmp (test_buffer , expect , written )) {
96
101
KUNIT_FAIL (kunittest ,
97
- "vsnprintf(buf, %d, \"%s\", ...) wrote '%s', expected '%.*s'\n" ,
98
- bufsize , fmt , test_buffer , written , expect );
102
+ "%s:%d: vsnprintf(buf, %d, \"%s\", ...) wrote '%s', expected '%.*s'\n" ,
103
+ file , line , bufsize , fmt , test_buffer , written , expect );
99
104
return ;
100
105
}
101
106
}
102
107
103
- static void __printf (4 , 5 )
104
- __test (struct kunit * kunittest , const char * expect , int elen , const char * fmt , ...)
108
+ static void __printf (6 , 7 )
109
+ __test (struct kunit * kunittest , const char * file , const int line , const char * expect , int elen ,
110
+ const char * fmt , ...)
105
111
{
106
112
va_list ap ;
107
113
int rand ;
108
114
char * p ;
109
115
110
116
if (elen >= BUF_SIZE ) {
111
117
KUNIT_FAIL (kunittest ,
112
- "error in test suite: expected length (%d) >= BUF_SIZE (%d). fmt=\"%s\"\n" ,
113
- elen , BUF_SIZE , fmt );
118
+ "%s:%d: error in test suite: expected length (%d) >= BUF_SIZE (%d). fmt=\"%s\"\n" ,
119
+ file , line , elen , BUF_SIZE , fmt );
114
120
return ;
115
121
}
116
122
@@ -122,27 +128,27 @@ __test(struct kunit *kunittest, const char *expect, int elen, const char *fmt, .
122
128
* enough and 0), and then we also test that kvasprintf would
123
129
* be able to print it as expected.
124
130
*/
125
- do_test (kunittest , BUF_SIZE , expect , elen , fmt , ap );
131
+ do_test (kunittest , file , line , BUF_SIZE , expect , elen , fmt , ap );
126
132
rand = get_random_u32_inclusive (1 , elen + 1 );
127
133
/* Since elen < BUF_SIZE, we have 1 <= rand <= BUF_SIZE. */
128
- do_test (kunittest , rand , expect , elen , fmt , ap );
129
- do_test (kunittest , 0 , expect , elen , fmt , ap );
134
+ do_test (kunittest , file , line , rand , expect , elen , fmt , ap );
135
+ do_test (kunittest , file , line , 0 , expect , elen , fmt , ap );
130
136
131
137
p = kvasprintf (GFP_KERNEL , fmt , ap );
132
138
if (p ) {
133
139
total_tests ++ ;
134
140
if (memcmp (p , expect , elen + 1 )) {
135
141
KUNIT_FAIL (kunittest ,
136
- "kvasprintf(..., \"%s\", ...) returned '%s', expected '%s'\n" ,
137
- fmt , p , expect );
142
+ "%s:%d: kvasprintf(..., \"%s\", ...) returned '%s', expected '%s'\n" ,
143
+ file , line , fmt , p , expect );
138
144
}
139
145
kfree (p );
140
146
}
141
147
va_end (ap );
142
148
}
143
149
144
150
#define test (expect , fmt , ...) \
145
- __test(kunittest, expect, strlen(expect), fmt, ##__VA_ARGS__)
151
+ __test(kunittest, __FILE__, __LINE__, expect, strlen(expect), fmt, ##__VA_ARGS__)
146
152
147
153
static void
148
154
test_basic (struct kunit * kunittest )
@@ -153,7 +159,7 @@ test_basic(struct kunit *kunittest)
153
159
test ("" , & nul );
154
160
test ("100%" , "100%%" );
155
161
test ("xxx%yyy" , "xxx%cyyy" , '%' );
156
- __test (kunittest , "xxx\0yyy" , 7 , "xxx%cyyy" , '\0' );
162
+ __test (kunittest , __FILE__ , __LINE__ , "xxx\0yyy" , 7 , "xxx%cyyy" , '\0' );
157
163
}
158
164
159
165
static void
0 commit comments