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

kunit: test: Make filter strings in executor_test writable

KUnit's attribute filtering feature needs the filter strings passed in
to be writable, as it modifies them in-place during parsing. This works
for the filters passed on the kernel command line, but the string
literals used in the executor tests are at least theoretically read-only
(though they work on x86_64 for some reason). s390 wasn't fooled, and
crashed when these tests were run.

Use a 'char[]' instead, (and make an explicit variable for the current
filter in parse_filter_attr_test), which will store the string in a
writable segment.

Fixes: 76066f93f1df ("kunit: add tests for filtering attributes")
Closes: https://lore.kernel.org/linux-kselftest/55950256-c00a-4d21-a2c0-cf9f0e5b8a9a@roeck-us.net/
Signed-off-by: David Gow <davidgow@google.com>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Rae Moar <rmoar@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

David Gow and committed by
Shuah Khan
dce19a3f 25e324bc

+8 -5
+8 -5
lib/kunit/executor_test.c
··· 119 119 { 120 120 int j, filter_count; 121 121 struct kunit_attr_filter *parsed_filters; 122 - char *filters = "speed>slow, module!=example"; 122 + char filters[] = "speed>slow, module!=example", *filter = filters; 123 123 int err = 0; 124 124 125 125 filter_count = kunit_get_filter_count(filters); ··· 128 128 parsed_filters = kunit_kcalloc(test, filter_count, sizeof(*parsed_filters), 129 129 GFP_KERNEL); 130 130 for (j = 0; j < filter_count; j++) { 131 - parsed_filters[j] = kunit_next_attr_filter(&filters, &err); 131 + parsed_filters[j] = kunit_next_attr_filter(&filter, &err); 132 132 KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter '%s'", filters[j]); 133 133 } 134 134 ··· 154 154 .start = subsuite, .end = &subsuite[2], 155 155 }; 156 156 struct kunit_suite_set got; 157 + char filter[] = "speed>slow"; 157 158 int err = 0; 158 159 159 160 subsuite[0] = alloc_fake_suite(test, "normal_suite", dummy_attr_test_cases); ··· 169 168 * attribute is unset and thus, the filtering is based on the parent attribute 170 169 * of slow. 171 170 */ 172 - got = kunit_filter_suites(&suite_set, NULL, "speed>slow", NULL, &err); 171 + got = kunit_filter_suites(&suite_set, NULL, filter, NULL, &err); 173 172 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, got.start); 174 173 KUNIT_ASSERT_EQ(test, err, 0); 175 174 kfree_at_end(test, got.start); ··· 192 191 .start = subsuite, .end = &subsuite[2], 193 192 }; 194 193 struct kunit_suite_set got; 194 + char filter[] = "module!=dummy"; 195 195 int err = 0; 196 196 197 197 subsuite[0] = alloc_fake_suite(test, "suite1", dummy_attr_test_cases); 198 198 subsuite[1] = alloc_fake_suite(test, "suite2", dummy_attr_test_cases); 199 199 200 - got = kunit_filter_suites(&suite_set, NULL, "module!=dummy", NULL, &err); 200 + got = kunit_filter_suites(&suite_set, NULL, filter, NULL, &err); 201 201 KUNIT_ASSERT_EQ(test, err, 0); 202 202 kfree_at_end(test, got.start); /* just in case */ 203 203 ··· 213 211 .start = subsuite, .end = &subsuite[1], 214 212 }; 215 213 struct kunit_suite_set got; 214 + char filter[] = "speed>slow"; 216 215 int err = 0; 217 216 218 217 subsuite[0] = alloc_fake_suite(test, "suite", dummy_attr_test_cases); 219 218 220 219 /* Want: suite(slow, normal), NULL -> suite(slow with SKIP, normal), NULL */ 221 - got = kunit_filter_suites(&suite_set, NULL, "speed>slow", "skip", &err); 220 + got = kunit_filter_suites(&suite_set, NULL, filter, "skip", &err); 222 221 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, got.start); 223 222 KUNIT_ASSERT_EQ(test, err, 0); 224 223 kfree_at_end(test, got.start);