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 module attribute

Add module attribute to the test attribute API. This attribute stores the
module name associated with the test using KBUILD_MODNAME.

The name of a test suite and the module name often do not match. A
reference to the module name associated with the suite could be extremely
helpful in running tests as modules without needing to check the codebase.

This attribute will be printed for each suite.

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
a00a7270 02c2d0c2

+33 -5
+8 -5
include/kunit/test.h
··· 131 131 132 132 /* private: internal use only. */ 133 133 enum kunit_status status; 134 + char *module_name; 134 135 char *log; 135 136 }; 136 137 ··· 156 155 * &struct kunit_case object from it. See the documentation for 157 156 * &struct kunit_case for an example on how to use it. 158 157 */ 159 - #define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name } 158 + #define KUNIT_CASE(test_name) \ 159 + { .run_case = test_name, .name = #test_name, \ 160 + .module_name = KBUILD_MODNAME} 160 161 161 162 /** 162 163 * KUNIT_CASE_ATTR - A helper for creating a &struct kunit_case ··· 170 167 */ 171 168 #define KUNIT_CASE_ATTR(test_name, attributes) \ 172 169 { .run_case = test_name, .name = #test_name, \ 173 - .attr = attributes } 170 + .attr = attributes, .module_name = KBUILD_MODNAME} 174 171 175 172 /** 176 173 * KUNIT_CASE_SLOW - A helper for creating a &struct kunit_case ··· 181 178 182 179 #define KUNIT_CASE_SLOW(test_name) \ 183 180 { .run_case = test_name, .name = #test_name, \ 184 - .attr.speed = KUNIT_SPEED_SLOW } 181 + .attr.speed = KUNIT_SPEED_SLOW, .module_name = KBUILD_MODNAME} 185 182 186 183 /** 187 184 * KUNIT_CASE_PARAM - A helper for creation a parameterized &struct kunit_case ··· 202 199 */ 203 200 #define KUNIT_CASE_PARAM(test_name, gen_params) \ 204 201 { .run_case = test_name, .name = #test_name, \ 205 - .generate_params = gen_params } 202 + .generate_params = gen_params, .module_name = KBUILD_MODNAME} 206 203 207 204 /** 208 205 * KUNIT_CASE_PARAM_ATTR - A helper for creating a parameterized &struct ··· 216 213 #define KUNIT_CASE_PARAM_ATTR(test_name, gen_params, attributes) \ 217 214 { .run_case = test_name, .name = #test_name, \ 218 215 .generate_params = gen_params, \ 219 - .attr = attributes } 216 + .attr = attributes, .module_name = KBUILD_MODNAME} 220 217 221 218 /** 222 219 * struct kunit_suite - describes a related collection of &struct kunit_case
+25
lib/kunit/attributes.c
··· 61 61 return attr_enum_to_string(attr, speed_str_list, to_free); 62 62 } 63 63 64 + static const char *attr_string_to_string(void *attr, bool *to_free) 65 + { 66 + *to_free = false; 67 + return (char *) attr; 68 + } 69 + 64 70 /* Get Attribute Methods */ 65 71 66 72 static void *attr_speed_get(void *test_or_suite, bool is_test) ··· 80 74 return ((void *) suite->attr.speed); 81 75 } 82 76 77 + static void *attr_module_get(void *test_or_suite, bool is_test) 78 + { 79 + struct kunit_suite *suite = is_test ? NULL : test_or_suite; 80 + struct kunit_case *test = is_test ? test_or_suite : NULL; 81 + 82 + // Suites get their module attribute from their first test_case 83 + if (test) 84 + return ((void *) test->module_name); 85 + else 86 + return ((void *) suite->test_cases[0].module_name); 87 + } 88 + 83 89 /* List of all Test Attributes */ 84 90 85 91 static struct kunit_attr kunit_attr_list[] = { ··· 102 84 .attr_default = (void *)KUNIT_SPEED_NORMAL, 103 85 .print = PRINT_ALWAYS, 104 86 }, 87 + { 88 + .name = "module", 89 + .get_attr = attr_module_get, 90 + .to_string = attr_string_to_string, 91 + .attr_default = (void *)"", 92 + .print = PRINT_SUITE, 93 + } 105 94 }; 106 95 107 96 /* Helper Functions to Access Attributes */