kunit: tool: show list of valid --arch options when invalid
PATCH 1/1 kunit: tool: show list of valid --arch options when invalid
Consider this attempt to run KUnit in QEMU:
$ ./tools/testing/kunit/kunit.py run --arch=x86
Before you'd get this error message:
kunit_kernel.ConfigError: x86 is not a valid arch
After:
kunit_kernel.ConfigError: x86 is not a valid arch, options are ['alpha', 'arm', 'arm64', 'i386', 'powerpc', 'riscv', 's390', 'sparc', 'x86_64']
This should make it a bit easier for people to notice when they make typos, etc. Currently, one would have to dive into the python code to figure out what the valid set is.
--- tools/testing/kunit/kunit_kernel.py | 5 +++-- tools/testing/kunit/kunit_tool_test.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-)
tools/testing/kunit/kunit_kernel.py +3 -2
@@ -198,8 +198,9 @@ def get_source_tree_ops(arch: str, cross_compile: Optional[str]) -> LinuxSourceT return LinuxSourceTreeOperationsUml(cross_compile=cross_compile) elif os.path.isfile(config_path): return get_source_tree_ops_from_qemu_config(config_path, cross_compile)[1] - else: - raise ConfigError(arch + ' is not a valid arch') + + options = [f[:-3] for f in os.listdir(QEMU_CONFIGS_DIR) if f.endswith('.py')] + raise ConfigError(arch + ' is not a valid arch, options are ' + str(sorted(options))) def get_source_tree_ops_from_qemu_config(config_path: str, cross_compile: Optional[str]) -> Tuple[
tools/testing/kunit/kunit_tool_test.py +4 -0
@@ -289,6 +289,10 @@ class LinuxSourceTreeTest(unittest.TestCase): pass kunit_kernel.LinuxSourceTree('', kunitconfig_path=dir) + def test_invalid_arch(self): + with self.assertRaisesRegex(kunit_kernel.ConfigError, 'not a valid arch, options are.*x86_64'): + kunit_kernel.LinuxSourceTree('', arch='invalid') + # TODO: add more test cases.
base-commit: 865a0a8025ee0b54d1cc74834c57197d184a441e
Signature · 1 line
2.33.0.685.g46640cef36-goog
Quoted 10 lines · Daniel Latypov
Consider this attempt to run KUnit in QEMU:
$ ./tools/testing/kunit/kunit.py run --arch=x86Before you'd get this error message:
kunit_kernel.ConfigError: x86 is not a valid archAfter:
kunit_kernel.ConfigError: x86 is not a valid arch, options are ['alpha', 'arm', 'arm64', 'i386', 'powerpc', 'riscv', 's390', 'sparc', 'x86_64']
Quoted 6 lines
This should make it a bit easier for people to notice when they make typos, etc. Currently, one would have to dive into the python code to figure out what the valid set is.
Signed-off-by Daniel Latypov <[email protected]>---
This is really nice, particularly given that we've had to reproduce that list in lots of talks, documentation, etc. and it could get out-of-date.
[FYI: this didn't seem to apply cleanly to kselftest/kunit head, but it was a pretty minor issue with kunit_tool_test.py.]
Thanks,
-- David
Quoted 40 lines
tools/testing/kunit/kunit_kernel.py | 5 +++-- tools/testing/kunit/kunit_tool_test.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-)tools/testing/kunit/kunit_kernel.py +3
-2@@ -198,8 +198,9 @@ def get_source_tree_ops(arch: str, cross_compile: Optional[str]) -> LinuxSourceT return LinuxSourceTreeOperationsUml(cross_compile=cross_compile) elif os.path.isfile(config_path): return get_source_tree_ops_from_qemu_config(config_path, cross_compile)[1] - else: - raise ConfigError(arch + ' is not a valid arch') + + options = [f[:-3] for f in os.listdir(QEMU_CONFIGS_DIR) if f.endswith('.py')] + raise ConfigError(arch + ' is not a valid arch, options are ' + str(sorted(options))) def get_source_tree_ops_from_qemu_config(config_path: str, cross_compile: Optional[str]) -> Tuple[tools/testing/kunit/kunit_tool_test.py +4
-0@@ -289,6 +289,10 @@ class LinuxSourceTreeTest(unittest.TestCase): pass kunit_kernel.LinuxSourceTree('', kunitconfig_path=dir) + def test_invalid_arch(self): + with self.assertRaisesRegex(kunit_kernel.ConfigError, 'not a valid arch, options are.*x86_64'): + kunit_kernel.LinuxSourceTree('', arch='invalid') + # TODO: add more test cases.base-commit:
865a0a8025ee0b54d1cc74834c57197d184a441e--
2.33.0.685.g46640cef36-goog
Quoted 19 lines · David Gow
Quoted 10 lines · Daniel Latypov
Consider this attempt to run KUnit in QEMU:
$ ./tools/testing/kunit/kunit.py run --arch=x86Before you'd get this error message:
kunit_kernel.ConfigError: x86 is not a valid archAfter:
kunit_kernel.ConfigError: x86 is not a valid arch, options are ['alpha', 'arm', 'arm64', 'i386', 'powerpc', 'riscv', 's390', 'sparc', 'x86_64']Quoted 6 lines
This should make it a bit easier for people to notice when they make typos, etc. Currently, one would have to dive into the python code to figure out what the valid set is.
Signed-off-by Daniel Latypov <[email protected]>---
Quoted 8 lines
This is really nice, particularly given that we've had to reproduce that list in lots of talks, documentation, etc. and it could get out-of-date.
Reviewed-by David Gow <[email protected]>[FYI: this didn't seem to apply cleanly to kselftest/kunit head, but it was a pretty minor issue with
kunit_tool_test.py.]
Oh, this is on top of
https://lore.kernel.org/linux-kselftest/[email protected]/
I guess this line there
- tree = kunit_kernel.LinuxSourceTree('', kunitconfig_path=dir)
+ kunit_kernel.LinuxSourceTree('', kunitconfig_path=dir) tripped things up a bit.
Quoted 44 lines
Thanks,
-- DavidQuoted 40 lines
tools/testing/kunit/kunit_kernel.py | 5 +++-- tools/testing/kunit/kunit_tool_test.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-)tools/testing/kunit/kunit_kernel.py +3
-2@@ -198,8 +198,9 @@ def get_source_tree_ops(arch: str, cross_compile: Optional[str]) -> LinuxSourceT return LinuxSourceTreeOperationsUml(cross_compile=cross_compile) elif os.path.isfile(config_path): return get_source_tree_ops_from_qemu_config(config_path, cross_compile)[1] - else: - raise ConfigError(arch + ' is not a valid arch') + + options = [f[:-3] for f in os.listdir(QEMU_CONFIGS_DIR) if f.endswith('.py')] + raise ConfigError(arch + ' is not a valid arch, options are ' + str(sorted(options))) def get_source_tree_ops_from_qemu_config(config_path: str, cross_compile: Optional[str]) -> Tuple[tools/testing/kunit/kunit_tool_test.py +4
-0@@ -289,6 +289,10 @@ class LinuxSourceTreeTest(unittest.TestCase): pass kunit_kernel.LinuxSourceTree('', kunitconfig_path=dir) + def test_invalid_arch(self): + with self.assertRaisesRegex(kunit_kernel.ConfigError, 'not a valid arch, options are.*x86_64'): + kunit_kernel.LinuxSourceTree('', arch='invalid') + # TODO: add more test cases.base-commit:
865a0a8025ee0b54d1cc74834c57197d184a441e--
2.33.0.685.g46640cef36-goog
Quoted 7 lines · Daniel Latypov
Consider this attempt to run KUnit in QEMU:
$ ./tools/testing/kunit/kunit.py run --arch=x86Before you'd get this error message:
kunit_kernel.ConfigError: x86 is not a valid arch
Quoted 8 lines
After:
kunit_kernel.ConfigError: x86 is not a valid arch, options are ['alpha', 'arm', 'arm64', 'i386', 'powerpc', 'riscv', 's390', 'sparc', 'x86_64']This should make it a bit easier for people to notice when they make typos, etc. Currently, one would have to dive into the python code to figure out what the valid set is.
Signed-off-by Daniel Latypov <[email protected]>
Yes! Thank you for fixing this!