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

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

+54 -8
+1
include/kunit/platform_device.h
··· 2 2 #ifndef _KUNIT_PLATFORM_DRIVER_H 3 3 #define _KUNIT_PLATFORM_DRIVER_H 4 4 5 + struct completion; 5 6 struct kunit; 6 7 struct platform_device; 7 8 struct platform_driver;
+3 -1
include/kunit/test.h
··· 312 312 } 313 313 314 314 bool kunit_enabled(void); 315 + bool kunit_autorun(void); 315 316 const char *kunit_action(void); 316 317 const char *kunit_filter_glob(void); 317 318 char *kunit_filter(void); ··· 335 334 int *err); 336 335 void kunit_free_suite_set(struct kunit_suite_set suite_set); 337 336 338 - int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites); 337 + int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites, 338 + bool run_tests); 339 339 340 340 void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites); 341 341
+12
lib/kunit/Kconfig
··· 81 81 In most cases this should be left as Y. Only if additional opt-in 82 82 behavior is needed should this be set to N. 83 83 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 + 84 96 endif # KUNIT
+1 -1
lib/kunit/debugfs.c
··· 145 145 struct inode *f_inode = file->f_inode; 146 146 struct kunit_suite *suite = (struct kunit_suite *) f_inode->i_private; 147 147 148 - __kunit_test_suites_init(&suite, 1); 148 + __kunit_test_suites_init(&suite, 1, true); 149 149 150 150 return count; 151 151 }
+19 -2
lib/kunit/executor.c
··· 29 29 return action_param; 30 30 } 31 31 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 + 32 48 static char *filter_glob_param; 33 49 static char *filter_param; 34 50 static char *filter_action_param; ··· 276 260 void kunit_exec_run_tests(struct kunit_suite_set *suite_set, bool builtin) 277 261 { 278 262 size_t num_suites = suite_set->end - suite_set->start; 263 + bool autorun = kunit_autorun(); 279 264 280 - if (builtin || num_suites) { 265 + if (autorun && (builtin || num_suites)) { 281 266 pr_info("KTAP version 1\n"); 282 267 pr_info("1..%zu\n", num_suites); 283 268 } 284 269 285 - __kunit_test_suites_init(suite_set->start, num_suites); 270 + __kunit_test_suites_init(suite_set->start, num_suites, autorun); 286 271 } 287 272 288 273 void kunit_exec_list_tests(struct kunit_suite_set *suite_set, bool include_attr)
+4 -2
lib/kunit/test.c
··· 708 708 return enable_param; 709 709 } 710 710 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) 712 713 { 713 714 unsigned int i; 714 715 ··· 732 731 733 732 for (i = 0; i < num_suites; i++) { 734 733 kunit_init_suite(suites[i]); 735 - kunit_run_tests(suites[i]); 734 + if (run_tests) 735 + kunit_run_tests(suites[i]); 736 736 } 737 737 738 738 static_branch_dec(&kunit_running);
+10 -1
tools/testing/kunit/kunit.py
··· 312 312 return list(map(massage_arg, argv)) 313 313 314 314 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") 316 325 317 326 def add_common_opts(parser: argparse.ArgumentParser) -> None: 318 327 parser.add_argument('--build_dir',
+3
tools/testing/kunit/kunit_kernel.py
··· 125 125 '-append', ' '.join(params + [self._kernel_command_line]), 126 126 '-no-reboot', 127 127 '-nographic', 128 + '-accel', 'kvm', 129 + '-accel', 'hvf', 130 + '-accel', 'tcg', 128 131 '-serial', self._serial] + self._extra_qemu_params 129 132 # Note: shlex.join() does what we want, but requires python 3.8+. 130 133 print('Running tests with:\n$', ' '.join(shlex.quote(arg) for arg in qemu_command))
+1 -1
tools/testing/kunit/qemu_configs/arm64.py
··· 9 9 qemu_arch='aarch64', 10 10 kernel_path='arch/arm64/boot/Image.gz', 11 11 kernel_command_line='console=ttyAMA0', 12 - extra_qemu_params=['-machine', 'virt', '-cpu', 'max,pauth-impdef=on']) 12 + extra_qemu_params=['-machine', 'virt', '-cpu', 'max'])