kunit: tool: make --kunitconfig accept dirs, add lib/kunit fragment
PATCH 1/1 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]/
--- lib/kunit/.kunitconfig | 3 +++ tools/testing/kunit/kunit.py | 4 +++- tools/testing/kunit/kunit_kernel.py | 2 ++ tools/testing/kunit/kunit_tool_test.py | 6 ++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 lib/kunit/.kunitconfig
lib/kunit/.kunitconfig new file +3 -0
@@ -0,0 +1,3 @@ +CONFIG_KUNIT=y +CONFIG_KUNIT_TEST=y +CONFIG_KUNIT_EXAMPLE_TEST=y
tools/testing/kunit/kunit.py +3 -1
@@ -184,7 +184,9 @@ def add_common_opts(parser) -> None: help='Run all KUnit tests through allyesconfig', action='store_true') parser.add_argument('--kunitconfig', - help='Path to Kconfig fragment that enables KUnit tests', + help='Path to Kconfig fragment that enables KUnit tests.' + ' If given a directory, (e.g. lib/kunit), "/.kunitconfig" ' + 'will get automatically appended.', metavar='kunitconfig') def add_build_opts(parser) -> None:
tools/testing/kunit/kunit_kernel.py +2 -0
@@ -132,6 +132,8 @@ class LinuxSourceTree(object): return if kunitconfig_path: + if os.path.isdir(kunitconfig_path): + kunitconfig_path = os.path.join(kunitconfig_path, KUNITCONFIG_PATH) if not os.path.exists(kunitconfig_path): raise ConfigError(f'Specified kunitconfig ({kunitconfig_path}) does not exist') else:
tools/testing/kunit/kunit_tool_test.py +6 -0
@@ -251,6 +251,12 @@ class LinuxSourceTreeTest(unittest.TestCase): with tempfile.NamedTemporaryFile('wt') as kunitconfig: tree = kunit_kernel.LinuxSourceTree('', kunitconfig_path=kunitconfig.name) + def test_dir_kunitconfig(self): + with tempfile.TemporaryDirectory('') as dir: + with open(os.path.join(dir, '.kunitconfig'), 'w') as f: + pass + tree = kunit_kernel.LinuxSourceTree('', kunitconfig_path=dir) + # TODO: add more test cases.
base-commit: b12b47249688915e987a9a2a393b522f86f6b7ab
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
Quoted 10 lines · Daniel Latypov
TL;DR
$ ./tools/testing/kunit/kunit.py run --kunitconfig=lib/kunitPer 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
Quoted 8 lines
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]>---
Thanks! I really like this.
I'd assumed we'd check if the path exists, and fall back to appending ".kunitconfig", but checking if it's a directory is better.
I tried this out with all the different combinations I could think of, and it works well.
Cheers,
-- David
Quoted 66 lines
lib/kunit/.kunitconfig | 3 +++ tools/testing/kunit/kunit.py | 4 +++- tools/testing/kunit/kunit_kernel.py | 2 ++ tools/testing/kunit/kunit_tool_test.py | 6 ++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 lib/kunit/.kunitconfiglib/kunit/.kunitconfig new file +3
-0@@ -0,0 +1,3 @@ +CONFIG_KUNIT=y +CONFIG_KUNIT_TEST=y +CONFIG_KUNIT_EXAMPLE_TEST=ytools/testing/kunit/kunit.py +3
-1@@ -184,7 +184,9 @@ def add_common_opts(parser) -> None: help='Run all KUnit tests through allyesconfig', action='store_true') parser.add_argument('--kunitconfig', - help='Path to Kconfig fragment that enables KUnit tests', + help='Path to Kconfig fragment that enables KUnit tests.' + ' If given a directory, (e.g. lib/kunit), "/.kunitconfig" ' + 'will get automatically appended.', metavar='kunitconfig') def add_build_opts(parser) -> None:tools/testing/kunit/kunit_kernel.py +2
-0@@ -132,6 +132,8 @@ class LinuxSourceTree(object): return if kunitconfig_path: + if os.path.isdir(kunitconfig_path): + kunitconfig_path = os.path.join(kunitconfig_path, KUNITCONFIG_PATH) if not os.path.exists(kunitconfig_path): raise ConfigError(f'Specified kunitconfig ({kunitconfig_path}) does not exist') else:tools/testing/kunit/kunit_tool_test.py +6
-0@@ -251,6 +251,12 @@ class LinuxSourceTreeTest(unittest.TestCase): with tempfile.NamedTemporaryFile('wt') as kunitconfig: tree = kunit_kernel.LinuxSourceTree('', kunitconfig_path=kunitconfig.name) + def test_dir_kunitconfig(self): + with tempfile.TemporaryDirectory('') as dir: + with open(os.path.join(dir, '.kunitconfig'), 'w') as f: + pass + tree = kunit_kernel.LinuxSourceTree('', kunitconfig_path=dir) + # TODO: add more test cases.base-commit:
b12b47249688915e987a9a2a393b522f86f6b7ab--
2.30.0.617.g56c4b15f3c-goog
Quoted 9 lines
TL;DR
$ ./tools/testing/kunit/kunit.py run --kunitconfig=lib/kunitPer 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
Quoted 7 lines
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]>
Shuah Khan
maintainerQuoted 13 lines · Brendan Higgins
Quoted 13 lines
TL;DR
$ ./tools/testing/kunit/kunit.py run --kunitconfig=lib/kunitPer 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/ext4Also 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).
Quoted 6 lines
Quoted 3 lines
[1] https://lore.kernel.org/linux-ext4/[email protected]/
Signed-off-by Daniel Latypov <[email protected]>Reviewed-by Brendan Higgins <[email protected]>
Should this be captured in documentation. Especially since this is file is .* file.
Do you want to include doc in this patch? Might be better that way.
thanks,
-- Shuah
Quoted 19 lines · Shuah Khan
Quoted 17 lines · Brendan Higgins
Quoted 16 lines
TL;DR
$ ./tools/testing/kunit/kunit.py run --kunitconfig=lib/kunitPer 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/ext4Also 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]>
Quoted 7 lines
Quoted 2 lines
Reviewed-by Brendan Higgins <[email protected]>Should this be captured in documentation. Especially since this is file is .* file.
Do you want to include doc in this patch? Might be better that way.
It definitely should be documented, yes.
The only real example hadn't landed yet when I sent this patch (fs/ext4/.kunitconfig was going in through the ext4 tree), but now it's in linus/master.
There's still some uncertainties about what best practices for this feature should be, i.e.
* how granular should these be?
* how should configs in parent dirs be handled? Should they be supersets of all the subdirs?
* E.g. should fs/.kunitconfig be a superset offs/ext4/.kunitconfig and any other hypothetical subdir configs?
* Should we wait on saying "you should do this" until we have
"import" statements/other mechanisms to make this less manual?
* how should we handle non-UML tests, like the KASAN tests?
* ideally, kunit.py run will eventually support running tests on x86
(using qemu)
If it's fine with you, I was hoping to come back and add a section to kunit/start.rst when we've had some of those questions more figured out.
Quoted 3 lines
thanks,
-- Shuah
Shuah Khan
maintainerQuoted 46 lines · Daniel Latypov
Quoted 19 lines · Shuah Khan
Quoted 17 lines · Brendan Higgins
Quoted 16 lines
TL;DR
$ ./tools/testing/kunit/kunit.py run --kunitconfig=lib/kunitPer 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/ext4Also 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]>Quoted 7 lines
Quoted 2 lines
Reviewed-by Brendan Higgins <[email protected]>Should this be captured in documentation. Especially since this is file is .* file.
Do you want to include doc in this patch? Might be better that way.
It definitely should be documented, yes.
The only real example hadn't landed yet when I sent this patch (fs/ext4/.kunitconfigwas going in through the ext4 tree), but now it's in linus/master.There's still some uncertainties about what best practices for this feature should be, i.e.
* how granular should these be?
* how should configs in parent dirs be handled? Should they be supersets of all the subdirs?
* E.g. shouldfs/.kunitconfigbe a superset offs/ext4/.kunitconfigand any other hypothetical subdir configs?
* Should we wait on saying "you should do this" until we have
"import" statements/other mechanisms to make this less manual?
* how should we handle non-UML tests, like the KASAN tests?
* ideally,kunit.pyrun will eventually support running tests on x86
(using qemu)
Quoted 4 lines
If it's fine with you, I was hoping to come back and add a section to
kunit/start.rstwhen we've had some of those questions more figured out.
Sound good. I will apply this patch and you can document later.
thanks,
-- Shuah