kunit_tool: add support to print only sample test
Add a new flag - --print_test_only that only outputs the sample -test.c
file to stdout. This is to facilitate the creation of the corresponding
vim plugin.
Change-Id: Id7b212337472aff27037f00f824f757663f89159
Google-Bug-Id: 117337457
Signed-off-by: Pallav Agarwal <pallavag@google.com>
diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index 34c0eb5d..b9bacd0 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -54,7 +54,8 @@
def print_test_skeletons(cli_args):
kunit_new_template.create_skeletons_from_path(
cli_args.path,
- namespace_prefix=cli_args.namespace_prefix)
+ namespace_prefix=cli_args.namespace_prefix,
+ print_test_only=cli_args.print_test_only)
def main(argv, linux=kunit_kernel.LinuxSourceTree()):
parser = argparse.ArgumentParser(
@@ -83,6 +84,10 @@
new_parser.add_argument('--namespace_prefix',
help='Namespace of the code to be tested.',
type=str)
+ new_parser.add_argument('--print_test_only',
+ help='Skip Kconfig and Makefile while printing sample '
+ 'test.',
+ action='store_true')
cli_args = parser.parse_args(argv)
diff --git a/tools/testing/kunit/kunit_new_template.py b/tools/testing/kunit/kunit_new_template.py
index 1b4516d..06dbf382 100644
--- a/tools/testing/kunit/kunit_new_template.py
+++ b/tools/testing/kunit/kunit_new_template.py
@@ -48,7 +48,7 @@
file_name = os.path.basename(path)
return os.path.splitext(file_name)
-def create_skeletons_from_path(path, namespace_prefix=None):
+def create_skeletons_from_path(path, namespace_prefix=None, print_test_only=False):
dir_name, file_name = os.path.split(path)
file_prefix, _ = os.path.splitext(file_name)
test_path = os.path.join(dir_name, file_prefix + '-test.c')
@@ -58,6 +58,8 @@
skeletons = create_skeletons(namespace_prefix, test_object_file)
print('### In ' + test_path)
print(skeletons.test_skeleton)
+ if print_test_only:
+ return
print('### In Kconfig')
print(skeletons.kconfig_skeleton)
print('### In Makefile')