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

kunit: tool: make --kunitconfig accept dirs, add lib/kunit fragment

TL;DR
$ ./tools/testing/kunit/kunit.py run --kunitconfig=lib/kunit

Per suggestion from Ted [1], we can reduce the amount of typing by
assuming a convention that these files are named '.kunitconfig'.

In the case of [1], we now have
$ ./tools/testing/kunit/kunit.py run --kunitconfig=fs/ext4

Also add in such a fragment for kunit itself so we can give that as an
example more close to home (and thus less likely to be accidentally
broken).

[1] https://lore.kernel.org/linux-ext4/YCNF4yP1dB97zzwD@mit.edu/

Signed-off-by: Daniel Latypov <dlatypov@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Daniel Latypov and committed by
Shuah Khan
9854781d acd97625

+14 -1
+3
lib/kunit/.kunitconfig
··· 1 + CONFIG_KUNIT=y 2 + CONFIG_KUNIT_TEST=y 3 + CONFIG_KUNIT_EXAMPLE_TEST=y
+3 -1
tools/testing/kunit/kunit.py
··· 184 184 help='Run all KUnit tests through allyesconfig', 185 185 action='store_true') 186 186 parser.add_argument('--kunitconfig', 187 - help='Path to Kconfig fragment that enables KUnit tests', 187 + help='Path to Kconfig fragment that enables KUnit tests.' 188 + ' If given a directory, (e.g. lib/kunit), "/.kunitconfig" ' 189 + 'will get automatically appended.', 188 190 metavar='kunitconfig') 189 191 190 192 def add_build_opts(parser) -> None:
+2
tools/testing/kunit/kunit_kernel.py
··· 132 132 return 133 133 134 134 if kunitconfig_path: 135 + if os.path.isdir(kunitconfig_path): 136 + kunitconfig_path = os.path.join(kunitconfig_path, KUNITCONFIG_PATH) 135 137 if not os.path.exists(kunitconfig_path): 136 138 raise ConfigError(f'Specified kunitconfig ({kunitconfig_path}) does not exist') 137 139 else:
+6
tools/testing/kunit/kunit_tool_test.py
··· 251 251 with tempfile.NamedTemporaryFile('wt') as kunitconfig: 252 252 tree = kunit_kernel.LinuxSourceTree('', kunitconfig_path=kunitconfig.name) 253 253 254 + def test_dir_kunitconfig(self): 255 + with tempfile.TemporaryDirectory('') as dir: 256 + with open(os.path.join(dir, '.kunitconfig'), 'w') as f: 257 + pass 258 + tree = kunit_kernel.LinuxSourceTree('', kunitconfig_path=dir) 259 + 254 260 # TODO: add more test cases. 255 261 256 262