Skip to content

Commit 9854781

Browse files
dlatypovshuahkh
authored andcommitted
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/[email protected]/ Signed-off-by: Daniel Latypov <[email protected]> Reviewed-by: David Gow <[email protected]> Reviewed-by: Brendan Higgins <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent acd9762 commit 9854781

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

lib/kunit/.kunitconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_KUNIT=y
2+
CONFIG_KUNIT_TEST=y
3+
CONFIG_KUNIT_EXAMPLE_TEST=y

tools/testing/kunit/kunit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ def add_common_opts(parser) -> None:
184184
help='Run all KUnit tests through allyesconfig',
185185
action='store_true')
186186
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.',
188190
metavar='kunitconfig')
189191

190192
def add_build_opts(parser) -> None:

tools/testing/kunit/kunit_kernel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ def __init__(self, build_dir: str, load_config=True, kunitconfig_path='') -> Non
132132
return
133133

134134
if kunitconfig_path:
135+
if os.path.isdir(kunitconfig_path):
136+
kunitconfig_path = os.path.join(kunitconfig_path, KUNITCONFIG_PATH)
135137
if not os.path.exists(kunitconfig_path):
136138
raise ConfigError(f'Specified kunitconfig ({kunitconfig_path}) does not exist')
137139
else:

tools/testing/kunit/kunit_tool_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ def test_valid_kunitconfig(self):
251251
with tempfile.NamedTemporaryFile('wt') as kunitconfig:
252252
tree = kunit_kernel.LinuxSourceTree('', kunitconfig_path=kunitconfig.name)
253253

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+
254260
# TODO: add more test cases.
255261

256262

0 commit comments

Comments
 (0)