kunit: tool: make --kunitconfig accept dirs, add lib/kunit fragment
authorDaniel Latypov <dlatypov@google.com>
Mon, 22 Feb 2021 22:52:41 +0000 (14:52 -0800)
committerShuah Khan <skhan@linuxfoundation.org>
Fri, 2 Apr 2021 20:14:36 +0000 (14:14 -0600)
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>
lib/kunit/.kunitconfig [new file with mode: 0644]
tools/testing/kunit/kunit.py
tools/testing/kunit/kunit_kernel.py
tools/testing/kunit/kunit_tool_test.py

diff --git a/lib/kunit/.kunitconfig b/lib/kunit/.kunitconfig
new file mode 100644 (file)
index 0000000..9235b7d
--- /dev/null
@@ -0,0 +1,3 @@
+CONFIG_KUNIT=y
+CONFIG_KUNIT_TEST=y
+CONFIG_KUNIT_EXAMPLE_TEST=y
index d5144fc..5da8fb3 100755 (executable)
@@ -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:
index f309a33..89a7d40 100644 (file)
@@ -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:
index 1ad3049..2e809dd 100755 (executable)
@@ -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.