Skip to content

Commit dce19a3

Browse files
sulixshuahkh
authored andcommitted
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: 76066f9 ("kunit: add tests for filtering attributes") Closes: https://lore.kernel.org/linux-kselftest/[email protected]/ Signed-off-by: David Gow <[email protected]> Tested-by: Guenter Roeck <[email protected]> Reviewed-by: Rae Moar <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 25e324b commit dce19a3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/kunit/executor_test.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static void parse_filter_attr_test(struct kunit *test)
119119
{
120120
int j, filter_count;
121121
struct kunit_attr_filter *parsed_filters;
122-
char *filters = "speed>slow, module!=example";
122+
char filters[] = "speed>slow, module!=example", *filter = filters;
123123
int err = 0;
124124

125125
filter_count = kunit_get_filter_count(filters);
@@ -128,7 +128,7 @@ static void parse_filter_attr_test(struct kunit *test)
128128
parsed_filters = kunit_kcalloc(test, filter_count, sizeof(*parsed_filters),
129129
GFP_KERNEL);
130130
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);
132132
KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter '%s'", filters[j]);
133133
}
134134

@@ -154,6 +154,7 @@ static void filter_attr_test(struct kunit *test)
154154
.start = subsuite, .end = &subsuite[2],
155155
};
156156
struct kunit_suite_set got;
157+
char filter[] = "speed>slow";
157158
int err = 0;
158159

159160
subsuite[0] = alloc_fake_suite(test, "normal_suite", dummy_attr_test_cases);
@@ -168,7 +169,7 @@ static void filter_attr_test(struct kunit *test)
168169
* attribute is unset and thus, the filtering is based on the parent attribute
169170
* of slow.
170171
*/
171-
got = kunit_filter_suites(&suite_set, NULL, "speed>slow", NULL, &err);
172+
got = kunit_filter_suites(&suite_set, NULL, filter, NULL, &err);
172173
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, got.start);
173174
KUNIT_ASSERT_EQ(test, err, 0);
174175
kfree_at_end(test, got.start);
@@ -191,12 +192,13 @@ static void filter_attr_empty_test(struct kunit *test)
191192
.start = subsuite, .end = &subsuite[2],
192193
};
193194
struct kunit_suite_set got;
195+
char filter[] = "module!=dummy";
194196
int err = 0;
195197

196198
subsuite[0] = alloc_fake_suite(test, "suite1", dummy_attr_test_cases);
197199
subsuite[1] = alloc_fake_suite(test, "suite2", dummy_attr_test_cases);
198200

199-
got = kunit_filter_suites(&suite_set, NULL, "module!=dummy", NULL, &err);
201+
got = kunit_filter_suites(&suite_set, NULL, filter, NULL, &err);
200202
KUNIT_ASSERT_EQ(test, err, 0);
201203
kfree_at_end(test, got.start); /* just in case */
202204

@@ -211,12 +213,13 @@ static void filter_attr_skip_test(struct kunit *test)
211213
.start = subsuite, .end = &subsuite[1],
212214
};
213215
struct kunit_suite_set got;
216+
char filter[] = "speed>slow";
214217
int err = 0;
215218

216219
subsuite[0] = alloc_fake_suite(test, "suite", dummy_attr_test_cases);
217220

218221
/* Want: suite(slow, normal), NULL -> suite(slow with SKIP, normal), NULL */
219-
got = kunit_filter_suites(&suite_set, NULL, "speed>slow", "skip", &err);
222+
got = kunit_filter_suites(&suite_set, NULL, filter, "skip", &err);
220223
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, got.start);
221224
KUNIT_ASSERT_EQ(test, err, 0);
222225
kfree_at_end(test, got.start);

0 commit comments

Comments
 (0)