Skip to content

Commit e8f17cb

Browse files
committed
Merge tag 'linux_kselftest-kunit-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kunit updates from Shuah Khan: - fix struct completion warning - introduce autorun option - add fallback for os.sched_getaffinity - enable hardware acceleration when available * tag 'linux_kselftest-kunit-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: kunit: Introduce autorun option kunit: enable hardware acceleration when available kunit: add fallback for os.sched_getaffinity kunit: platform: Resolve 'struct completion' warning
2 parents 8fb1e2e + 3169191 commit e8f17cb

File tree

9 files changed

+54
-8
lines changed

9 files changed

+54
-8
lines changed

include/kunit/platform_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef _KUNIT_PLATFORM_DRIVER_H
33
#define _KUNIT_PLATFORM_DRIVER_H
44

5+
struct completion;
56
struct kunit;
67
struct platform_device;
78
struct platform_driver;

include/kunit/test.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ static inline void kunit_set_failure(struct kunit *test)
312312
}
313313

314314
bool kunit_enabled(void);
315+
bool kunit_autorun(void);
315316
const char *kunit_action(void);
316317
const char *kunit_filter_glob(void);
317318
char *kunit_filter(void);
@@ -334,7 +335,8 @@ kunit_filter_suites(const struct kunit_suite_set *suite_set,
334335
int *err);
335336
void kunit_free_suite_set(struct kunit_suite_set suite_set);
336337

337-
int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites);
338+
int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites,
339+
bool run_tests);
338340

339341
void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites);
340342

lib/kunit/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,16 @@ config KUNIT_DEFAULT_ENABLED
8181
In most cases this should be left as Y. Only if additional opt-in
8282
behavior is needed should this be set to N.
8383

84+
config KUNIT_AUTORUN_ENABLED
85+
bool "Default value of kunit.autorun"
86+
default y
87+
help
88+
Sets the default value of kunit.autorun. If set to N then KUnit
89+
tests will not run after initialization unless kunit.autorun=1 is
90+
passed to the kernel command line. The test can still be run manually
91+
via debugfs interface.
92+
93+
In most cases this should be left as Y. Only if additional opt-in
94+
behavior is needed should this be set to N.
95+
8496
endif # KUNIT

lib/kunit/debugfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static ssize_t debugfs_run(struct file *file,
145145
struct inode *f_inode = file->f_inode;
146146
struct kunit_suite *suite = (struct kunit_suite *) f_inode->i_private;
147147

148-
__kunit_test_suites_init(&suite, 1);
148+
__kunit_test_suites_init(&suite, 1, true);
149149

150150
return count;
151151
}

lib/kunit/executor.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ const char *kunit_action(void)
2929
return action_param;
3030
}
3131

32+
/*
33+
* Run KUnit tests after initialization
34+
*/
35+
#ifdef CONFIG_KUNIT_AUTORUN_ENABLED
36+
static bool autorun_param = true;
37+
#else
38+
static bool autorun_param;
39+
#endif
40+
module_param_named(autorun, autorun_param, bool, 0);
41+
MODULE_PARM_DESC(autorun, "Run KUnit tests after initialization");
42+
43+
bool kunit_autorun(void)
44+
{
45+
return autorun_param;
46+
}
47+
3248
static char *filter_glob_param;
3349
static char *filter_param;
3450
static char *filter_action_param;
@@ -260,13 +276,14 @@ kunit_filter_suites(const struct kunit_suite_set *suite_set,
260276
void kunit_exec_run_tests(struct kunit_suite_set *suite_set, bool builtin)
261277
{
262278
size_t num_suites = suite_set->end - suite_set->start;
279+
bool autorun = kunit_autorun();
263280

264-
if (builtin || num_suites) {
281+
if (autorun && (builtin || num_suites)) {
265282
pr_info("KTAP version 1\n");
266283
pr_info("1..%zu\n", num_suites);
267284
}
268285

269-
__kunit_test_suites_init(suite_set->start, num_suites);
286+
__kunit_test_suites_init(suite_set->start, num_suites, autorun);
270287
}
271288

272289
void kunit_exec_list_tests(struct kunit_suite_set *suite_set, bool include_attr)

lib/kunit/test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ bool kunit_enabled(void)
708708
return enable_param;
709709
}
710710

711-
int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites)
711+
int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites,
712+
bool run_tests)
712713
{
713714
unsigned int i;
714715

@@ -731,7 +732,8 @@ int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_
731732

732733
for (i = 0; i < num_suites; i++) {
733734
kunit_init_suite(suites[i]);
734-
kunit_run_tests(suites[i]);
735+
if (run_tests)
736+
kunit_run_tests(suites[i]);
735737
}
736738

737739
static_branch_dec(&kunit_running);

tools/testing/kunit/kunit.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,16 @@ def massage_arg(arg: str) -> str:
312312
return list(map(massage_arg, argv))
313313

314314
def get_default_jobs() -> int:
315-
return len(os.sched_getaffinity(0))
315+
if sys.version_info >= (3, 13):
316+
if (ncpu := os.process_cpu_count()) is not None:
317+
return ncpu
318+
raise RuntimeError("os.process_cpu_count() returned None")
319+
# See https://github.com/python/cpython/blob/b61fece/Lib/os.py#L1175-L1186.
320+
if sys.platform != "darwin":
321+
return len(os.sched_getaffinity(0))
322+
if (ncpu := os.cpu_count()) is not None:
323+
return ncpu
324+
raise RuntimeError("os.cpu_count() returned None")
316325

317326
def add_common_opts(parser: argparse.ArgumentParser) -> None:
318327
parser.add_argument('--build_dir',

tools/testing/kunit/kunit_kernel.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ def start(self, params: List[str], build_dir: str) -> subprocess.Popen:
125125
'-append', ' '.join(params + [self._kernel_command_line]),
126126
'-no-reboot',
127127
'-nographic',
128+
'-accel', 'kvm',
129+
'-accel', 'hvf',
130+
'-accel', 'tcg',
128131
'-serial', self._serial] + self._extra_qemu_params
129132
# Note: shlex.join() does what we want, but requires python 3.8+.
130133
print('Running tests with:\n$', ' '.join(shlex.quote(arg) for arg in qemu_command))

tools/testing/kunit/qemu_configs/arm64.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
qemu_arch='aarch64',
1010
kernel_path='arch/arm64/boot/Image.gz',
1111
kernel_command_line='console=ttyAMA0',
12-
extra_qemu_params=['-machine', 'virt', '-cpu', 'max,pauth-impdef=on'])
12+
extra_qemu_params=['-machine', 'virt', '-cpu', 'max'])

0 commit comments

Comments
 (0)