From a818a6170b4f1ffc61f2a6e48c640b65974fb594 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Wed, 3 Jul 2019 17:40:52 -0400 Subject: [PATCH] tests: bt2: add `--test-case` argument to testrunner.py The `-t/--test-case` argument allows to specify the exact test case to run. Make the `--test-case` and the existing `--pattern` options mutually exclusive and require that one of the two is provided. It can be used like this: ./tests/utils/run_python_bt2 python3 ./tests/utils/python/testrunner.py \ -t test_event.EventTestCase.test_clock_value \ ./tests/bindings/python/bt2 Signed-off-by: Francis Deslauriers Change-Id: Icc9204d05bac4cef9cc509f2b19a9e515b0a40e7 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1612 Reviewed-by: Simon Marchi Reviewed-by: Philippe Proulx Tested-by: jenkins --- tests/bindings/python/bt2/test_python_bt2 | 2 +- .../test_lttng_utils_debug_info | 3 +- tests/plugins/src.ctf.fs/query/test_query | 2 +- tests/utils/python/testrunner.py | 33 +++++++++++++++---- tests/utils/utils.sh | 6 ++-- 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/tests/bindings/python/bt2/test_python_bt2 b/tests/bindings/python/bt2/test_python_bt2 index ba39c2d9..52b30558 100755 --- a/tests/bindings/python/bt2/test_python_bt2 +++ b/tests/bindings/python/bt2/test_python_bt2 @@ -26,4 +26,4 @@ fi # shellcheck source=../../../utils/utils.sh source "$UTILSSH" -run_python_bt2_test "${BT_TESTS_SRCDIR}/bindings/python/bt2" +run_python_bt2_test "${BT_TESTS_SRCDIR}/bindings/python/bt2" "test_*" diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info b/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info index e5eb8de8..c1772727 100755 --- a/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info +++ b/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info @@ -28,4 +28,5 @@ source "$UTILSSH" export BT_DEBUG_INFO_PATH -run_python_bt2_test "${BT_TESTS_SRCDIR}/plugins/flt.lttng-utils.debug-info" "test_lttng_utils_debug_info.py" +run_python_bt2_test "${BT_TESTS_SRCDIR}/plugins/flt.lttng-utils.debug-info" \ + "test_lttng_utils_debug_info.py" diff --git a/tests/plugins/src.ctf.fs/query/test_query b/tests/plugins/src.ctf.fs/query/test_query index 27405735..4ab85cc7 100755 --- a/tests/plugins/src.ctf.fs/query/test_query +++ b/tests/plugins/src.ctf.fs/query/test_query @@ -25,4 +25,4 @@ fi # shellcheck source=../../../utils/utils.sh source "$UTILSSH" -run_python_bt2_test "${BT_TESTS_SRCDIR}/plugins/src.ctf.fs/query" +run_python_bt2_test "${BT_TESTS_SRCDIR}/plugins/src.ctf.fs/query" test_query* diff --git a/tests/utils/python/testrunner.py b/tests/utils/python/testrunner.py index cb1bdcda..d3879b6a 100644 --- a/tests/utils/python/testrunner.py +++ b/tests/utils/python/testrunner.py @@ -31,14 +31,24 @@ if __name__ == '__main__': argparser.add_argument('-f', '--failfast', help='Stop on first fail or error', action='store_true') + argparser.add_argument('start_dir', help='Base directory where to search for tests', type=str) - argparser.add_argument('pattern', - help='Glob-style pattern of tests to run', - type=str, - nargs='?', - default='test*.py') + + mut_exclu_group = argparser.add_mutually_exclusive_group(required=True) + + mut_exclu_group.add_argument('-p', '--pattern', + help='Glob-style pattern of test files to run ' + '(e.g. test_event*.py)', + type=str) + + mut_exclu_group.add_argument('-t', '--test-case', + help='Run a specfic test module name, test class ' + 'name, or test method name ' + '(e.g. test_event.EventTestCase.test_clock_value)', + type=str) + args = argparser.parse_args() @@ -47,8 +57,19 @@ if __name__ == '__main__': start_dir = args.start_dir pattern = args.pattern failfast = args.failfast + test_case = args.test_case + + if test_case: + sys.path.append(start_dir) + tests = loader.loadTestsFromName(test_case) + elif pattern: + tests = loader.discover(start_dir, pattern) + else: + # This will never happen because the mutual exclusion group has the + # `required` parameter set to True. So one or the other must be set or + # else it will fail to parse. + sys.exit(1) - tests = loader.discover(start_dir, pattern) if tests.countTestCases() < 1: print("No tests matching '%s' found in '%s'" % (pattern, start_dir)) diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index b1b6366a..5b9f0e96 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -228,7 +228,7 @@ run_python_bt2() { # $2 : The pattern to match python test script names (optional) run_python_bt2_test() { local test_dir="$1" - local test_pattern="${2:-}" # optional + local test_pattern="${2:-'*'}" # optional, if none default to "*" local ret local test_runner_args=() @@ -247,7 +247,9 @@ run_python_bt2_test() { run_python_bt2 \ "${python_exec}" \ "${BT_TESTS_SRCDIR}/utils/python/testrunner.py" \ - "${test_runner_args[@]}" + --pattern "$test_pattern" \ + "$test_dir" \ + ret=$? if test "x${BT_TESTS_COVERAGE_REPORT:-}" = "x1"; then -- 2.34.1