Skip to content

Commit 97ec971

Browse files
committed
Merge tag 'linux_kselftest-kunit-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull KUnit updates from Shuah Khan: - fix to make kunit_bus_type const - kunit tool change to Print UML command - DRM device creation helpers are now using the new kunit device creation helpers. This change resulted in DRM helpers switching from using a platform_device, to a dedicated bus and device type used by kunit. kunit devices don't set DMA mask and this caused regression on some drm tests as they can't allocate DMA buffers. Fix this problem by setting DMA masks on the kunit device during initialization. - KUnit has several macros which accept a log message, which can contain printf format specifiers. Some of these (the explicit log macros) already use the __printf() gcc attribute to ensure the format specifiers are valid, but those which could fail the test, and hence used __kunit_do_failed_assertion() behind the scenes, did not. These include: KUNIT_EXPECT_*_MSG(), KUNIT_ASSERT_*_MSG(), and KUNIT_FAIL() A nine-patch series adds the __printf() attribute, and fixes all of the issues uncovered. * tag 'linux_kselftest-kunit-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: kunit: Annotate _MSG assertion variants with gnu printf specifiers drm: tests: Fix invalid printf format specifiers in KUnit tests drm/xe/tests: Fix printf format specifiers in xe_migrate test net: test: Fix printf format specifier in skb_segment kunit test rtc: test: Fix invalid format specifier. time: test: Fix incorrect format specifier lib: memcpy_kunit: Fix an invalid format specifier in an assertion msg lib/cmdline: Fix an invalid format specifier in an assertion msg kunit: test: Log the correct filter string in executor_test kunit: Setup DMA masks on the kunit device kunit: make kunit_bus_type const kunit: Mark filter* params as rw kunit: tool: Print UML command
2 parents d451b07 + 806cb22 commit 97ec971

File tree

13 files changed

+36
-31
lines changed

13 files changed

+36
-31
lines changed

drivers/gpu/drm/tests/drm_buddy_test.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,30 +260,30 @@ static void drm_test_buddy_alloc_contiguous(struct kunit *test)
260260
KUNIT_ASSERT_FALSE_MSG(test,
261261
drm_buddy_alloc_blocks(&mm, 0, mm_size,
262262
ps, ps, list, 0),
263-
"buddy_alloc hit an error size=%u\n",
263+
"buddy_alloc hit an error size=%lu\n",
264264
ps);
265265
} while (++i < n_pages);
266266

267267
KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
268268
3 * ps, ps, &allocated,
269269
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
270-
"buddy_alloc didn't error size=%u\n", 3 * ps);
270+
"buddy_alloc didn't error size=%lu\n", 3 * ps);
271271

272272
drm_buddy_free_list(&mm, &middle);
273273
KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
274274
3 * ps, ps, &allocated,
275275
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
276-
"buddy_alloc didn't error size=%u\n", 3 * ps);
276+
"buddy_alloc didn't error size=%lu\n", 3 * ps);
277277
KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
278278
2 * ps, ps, &allocated,
279279
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
280-
"buddy_alloc didn't error size=%u\n", 2 * ps);
280+
"buddy_alloc didn't error size=%lu\n", 2 * ps);
281281

282282
drm_buddy_free_list(&mm, &right);
283283
KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
284284
3 * ps, ps, &allocated,
285285
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
286-
"buddy_alloc didn't error size=%u\n", 3 * ps);
286+
"buddy_alloc didn't error size=%lu\n", 3 * ps);
287287
/*
288288
* At this point we should have enough contiguous space for 2 blocks,
289289
* however they are never buddies (since we freed middle and right) so
@@ -292,13 +292,13 @@ static void drm_test_buddy_alloc_contiguous(struct kunit *test)
292292
KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
293293
2 * ps, ps, &allocated,
294294
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
295-
"buddy_alloc hit an error size=%u\n", 2 * ps);
295+
"buddy_alloc hit an error size=%lu\n", 2 * ps);
296296

297297
drm_buddy_free_list(&mm, &left);
298298
KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
299299
3 * ps, ps, &allocated,
300300
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
301-
"buddy_alloc hit an error size=%u\n", 3 * ps);
301+
"buddy_alloc hit an error size=%lu\n", 3 * ps);
302302

303303
total = 0;
304304
list_for_each_entry(block, &allocated, link)

drivers/gpu/drm/tests/drm_mm_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static void drm_test_mm_init(struct kunit *test)
157157

158158
/* After creation, it should all be one massive hole */
159159
if (!assert_one_hole(test, &mm, 0, size)) {
160-
KUNIT_FAIL(test, "");
160+
KUNIT_FAIL(test, "mm not one hole on creation");
161161
goto out;
162162
}
163163

@@ -171,14 +171,14 @@ static void drm_test_mm_init(struct kunit *test)
171171

172172
/* After filling the range entirely, there should be no holes */
173173
if (!assert_no_holes(test, &mm)) {
174-
KUNIT_FAIL(test, "");
174+
KUNIT_FAIL(test, "mm has holes when filled");
175175
goto out;
176176
}
177177

178178
/* And then after emptying it again, the massive hole should be back */
179179
drm_mm_remove_node(&tmp);
180180
if (!assert_one_hole(test, &mm, 0, size)) {
181-
KUNIT_FAIL(test, "");
181+
KUNIT_FAIL(test, "mm does not have single hole after emptying");
182182
goto out;
183183
}
184184

drivers/gpu/drm/xe/tests/xe_migrate.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,21 @@ static void test_copy(struct xe_migrate *m, struct xe_bo *bo,
114114
region |
115115
XE_BO_NEEDS_CPU_ACCESS);
116116
if (IS_ERR(remote)) {
117-
KUNIT_FAIL(test, "Failed to allocate remote bo for %s: %li\n",
118-
str, PTR_ERR(remote));
117+
KUNIT_FAIL(test, "Failed to allocate remote bo for %s: %pe\n",
118+
str, remote);
119119
return;
120120
}
121121

122122
err = xe_bo_validate(remote, NULL, false);
123123
if (err) {
124-
KUNIT_FAIL(test, "Failed to validate system bo for %s: %li\n",
124+
KUNIT_FAIL(test, "Failed to validate system bo for %s: %i\n",
125125
str, err);
126126
goto out_unlock;
127127
}
128128

129129
err = xe_bo_vmap(remote);
130130
if (err) {
131-
KUNIT_FAIL(test, "Failed to vmap system bo for %s: %li\n",
131+
KUNIT_FAIL(test, "Failed to vmap system bo for %s: %i\n",
132132
str, err);
133133
goto out_unlock;
134134
}

drivers/rtc/lib_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static void rtc_time64_to_tm_test_date_range(struct kunit *test)
5454

5555
days = div_s64(secs, 86400);
5656

57-
#define FAIL_MSG "%d/%02d/%02d (%2d) : %ld", \
57+
#define FAIL_MSG "%d/%02d/%02d (%2d) : %lld", \
5858
year, month, mday, yday, days
5959

6060
KUNIT_ASSERT_EQ_MSG(test, year - 1900, result.tm_year, FAIL_MSG);

include/kunit/test.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,12 @@ void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt,
579579

580580
void __noreturn __kunit_abort(struct kunit *test);
581581

582-
void __kunit_do_failed_assertion(struct kunit *test,
583-
const struct kunit_loc *loc,
584-
enum kunit_assert_type type,
585-
const struct kunit_assert *assert,
586-
assert_format_t assert_format,
587-
const char *fmt, ...);
582+
void __printf(6, 7) __kunit_do_failed_assertion(struct kunit *test,
583+
const struct kunit_loc *loc,
584+
enum kunit_assert_type type,
585+
const struct kunit_assert *assert,
586+
assert_format_t assert_format,
587+
const char *fmt, ...);
588588

589589
#define _KUNIT_FAILED(test, assert_type, assert_class, assert_format, INITIALIZER, fmt, ...) do { \
590590
static const struct kunit_loc __loc = KUNIT_CURRENT_LOC; \

kernel/time/time_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static void time64_to_tm_test_date_range(struct kunit *test)
7373

7474
days = div_s64(secs, 86400);
7575

76-
#define FAIL_MSG "%05ld/%02d/%02d (%2d) : %ld", \
76+
#define FAIL_MSG "%05ld/%02d/%02d (%2d) : %lld", \
7777
year, month, mdday, yday, days
7878

7979
KUNIT_ASSERT_EQ_MSG(test, year - 1900, result.tm_year, FAIL_MSG);

lib/cmdline_kunit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void cmdline_do_one_range_test(struct kunit *test, const char *in,
124124
n, e[0], r[0]);
125125

126126
p = memchr_inv(&r[1], 0, sizeof(r) - sizeof(r[0]));
127-
KUNIT_EXPECT_PTR_EQ_MSG(test, p, NULL, "in test %u at %u out of bound", n, p - r);
127+
KUNIT_EXPECT_PTR_EQ_MSG(test, p, NULL, "in test %u at %td out of bound", n, p - r);
128128
}
129129

130130
static void cmdline_test_range(struct kunit *test)

lib/kunit/device.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include <linux/device.h>
13+
#include <linux/dma-mapping.h>
1314

1415
#include <kunit/test.h>
1516
#include <kunit/device.h>
@@ -35,7 +36,7 @@ struct kunit_device {
3536

3637
#define to_kunit_device(d) container_of_const(d, struct kunit_device, dev)
3738

38-
static struct bus_type kunit_bus_type = {
39+
static const struct bus_type kunit_bus_type = {
3940
.name = "kunit",
4041
};
4142

@@ -133,6 +134,9 @@ static struct kunit_device *kunit_device_register_internal(struct kunit *test,
133134
return ERR_PTR(err);
134135
}
135136

137+
kunit_dev->dev.dma_mask = &kunit_dev->dev.coherent_dma_mask;
138+
kunit_dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
139+
136140
kunit_add_action(test, device_unregister_wrapper, &kunit_dev->dev);
137141

138142
return kunit_dev;

lib/kunit/executor.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ static char *filter_glob_param;
3333
static char *filter_param;
3434
static char *filter_action_param;
3535

36-
module_param_named(filter_glob, filter_glob_param, charp, 0400);
36+
module_param_named(filter_glob, filter_glob_param, charp, 0600);
3737
MODULE_PARM_DESC(filter_glob,
3838
"Filter which KUnit test suites/tests run at boot-time, e.g. list* or list*.*del_test");
39-
module_param_named(filter, filter_param, charp, 0400);
39+
module_param_named(filter, filter_param, charp, 0600);
4040
MODULE_PARM_DESC(filter,
4141
"Filter which KUnit test suites/tests run at boot-time using attributes, e.g. speed>slow");
42-
module_param_named(filter_action, filter_action_param, charp, 0400);
42+
module_param_named(filter_action, filter_action_param, charp, 0600);
4343
MODULE_PARM_DESC(filter_action,
4444
"Changes behavior of filtered tests using attributes, valid values are:\n"
4545
"<none>: do not run filtered tests as normal\n"

lib/kunit/executor_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static void parse_filter_attr_test(struct kunit *test)
129129
GFP_KERNEL);
130130
for (j = 0; j < filter_count; j++) {
131131
parsed_filters[j] = kunit_next_attr_filter(&filter, &err);
132-
KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter '%s'", filters[j]);
132+
KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter from '%s'", filters);
133133
}
134134

135135
KUNIT_EXPECT_STREQ(test, kunit_attr_filter_name(parsed_filters[0]), "speed");

0 commit comments

Comments
 (0)