Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kunit: add is_init test attribute

Add is_init test attribute of type bool. Add to_string, get, and filter
methods to lib/kunit/attributes.c.

Mark each of the tests in the init section with the is_init=true attribute.

Add is_init to the attributes documentation.

Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Rae Moar <rmoar@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Rae Moar and committed by
Shuah Khan
6c4ea2f4 2cf45281

+73 -1
+7
Documentation/dev-tools/kunit/running_tips.rst
··· 428 428 429 429 This attribute is automatically saved as a string and is printed for each suite. 430 430 Tests can also be filtered using this attribute. 431 + 432 + ``is_init`` 433 + 434 + This attribute indicates whether the test uses init data or functions. 435 + 436 + This attribute is automatically saved as a boolean and tests can also be 437 + filtered using this attribute.
+1
include/kunit/test.h
··· 253 253 struct dentry *debugfs; 254 254 struct string_stream *log; 255 255 int suite_init_err; 256 + bool is_init; 256 257 }; 257 258 258 259 /* Stores an array of suites, end points one past the end */
+60
lib/kunit/attributes.c
··· 58 58 return str_list[val]; 59 59 } 60 60 61 + static const char *attr_bool_to_string(void *attr, bool *to_free) 62 + { 63 + bool val = (bool)attr; 64 + 65 + *to_free = false; 66 + if (val) 67 + return "true"; 68 + return "false"; 69 + } 70 + 61 71 static const char *attr_speed_to_string(void *attr, bool *to_free) 62 72 { 63 73 return attr_enum_to_string(attr, speed_str_list, to_free); ··· 176 166 return false; 177 167 } 178 168 169 + static int attr_bool_filter(void *attr, const char *input, int *err) 170 + { 171 + int i, input_int = -1; 172 + long val = (long)attr; 173 + const char *input_str = NULL; 174 + 175 + for (i = 0; input[i]; i++) { 176 + if (!strchr(op_list, input[i])) { 177 + input_str = input + i; 178 + break; 179 + } 180 + } 181 + 182 + if (!input_str) { 183 + *err = -EINVAL; 184 + pr_err("kunit executor: filter value not found: %s\n", input); 185 + return false; 186 + } 187 + 188 + if (!strcmp(input_str, "true")) 189 + input_int = (int)true; 190 + else if (!strcmp(input_str, "false")) 191 + input_int = (int)false; 192 + else { 193 + *err = -EINVAL; 194 + pr_err("kunit executor: invalid filter input: %s\n", input); 195 + return false; 196 + } 197 + 198 + return int_filter(val, input, input_int, err); 199 + } 179 200 180 201 /* Get Attribute Methods */ 181 202 ··· 235 194 return (void *) ""; 236 195 } 237 196 197 + static void *attr_is_init_get(void *test_or_suite, bool is_test) 198 + { 199 + struct kunit_suite *suite = is_test ? NULL : test_or_suite; 200 + struct kunit_case *test = is_test ? test_or_suite : NULL; 201 + 202 + if (test) 203 + return ((void *) NULL); 204 + else 205 + return ((void *) suite->is_init); 206 + } 207 + 238 208 /* List of all Test Attributes */ 239 209 240 210 static struct kunit_attr kunit_attr_list[] = { ··· 263 211 .to_string = attr_string_to_string, 264 212 .filter = attr_string_filter, 265 213 .attr_default = (void *)"", 214 + .print = PRINT_SUITE, 215 + }, 216 + { 217 + .name = "is_init", 218 + .get_attr = attr_is_init_get, 219 + .to_string = attr_bool_to_string, 220 + .filter = attr_bool_filter, 221 + .attr_default = (void *)false, 266 222 .print = PRINT_SUITE, 267 223 } 268 224 };
+5 -1
lib/kunit/executor.c
··· 300 300 struct kunit_suite_set total_suite_set = {NULL, NULL}; 301 301 struct kunit_suite **total_suite_start = NULL; 302 302 size_t init_num_suites, num_suites, suite_size; 303 + int i = 0; 303 304 304 305 init_num_suites = init_suite_set.end - init_suite_set.start; 305 306 num_suites = suite_set.end - suite_set.start; ··· 311 310 if (!total_suite_start) 312 311 return total_suite_set; 313 312 314 - /* Append init suites and then all other kunit suites */ 313 + /* Append and mark init suites and then append all other kunit suites */ 315 314 memcpy(total_suite_start, init_suite_set.start, init_num_suites * suite_size); 315 + for (i = 0; i < init_num_suites; i++) 316 + total_suite_start[i]->is_init = true; 317 + 316 318 memcpy(total_suite_start + init_num_suites, suite_set.start, num_suites * suite_size); 317 319 318 320 /* Set kunit suite set start and end */