tests: bt2: add `--test-case` argument to testrunner.py
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 3 Jul 2019 21:40:52 +0000 (17:40 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 5 Jul 2019 17:11:32 +0000 (13:11 -0400)
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 <francis.deslauriers@efficios.com>
Change-Id: Icc9204d05bac4cef9cc509f2b19a9e515b0a40e7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1612
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
tests/bindings/python/bt2/test_python_bt2
tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info
tests/plugins/src.ctf.fs/query/test_query
tests/utils/python/testrunner.py
tests/utils/utils.sh

index ba39c2d94ecae6fdc35e2cff1dc12f03f010724a..52b3055873ce6268c92ad97cf2aad2afb8d92e41 100755 (executable)
@@ -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_*"
index e5eb8de86fb7bd155648a3568c210980ca0752d5..c1772727bffc97d6604da40f26f422d978a8f125 100755 (executable)
@@ -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"
index 27405735e1282fb85c3d56cf03214ad1c9cb1dab..4ab85cc7656900a661aa8b8f18a45b3f4743ab21 100755 (executable)
@@ -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*
index cb1bdcda3e16f177c0faf744496acb63f78a323f..d3879b6a00ab9ff36e6f2b8b5409e43cca3587a7 100644 (file)
@@ -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))
index b1b6366a0a129714bb43186af40f00d5396c69fa..5b9f0e96d17d9ab31ccdc647da4cb3ddceb6b70d 100644 (file)
@@ -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
This page took 0.02656 seconds and 4 git commands to generate.