[1/2] app/test: emit warning for tests not in a test suite

Message ID 20230915115206.132198-2-bruce.richardson@intel.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series add checks for tests not in a suite |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Bruce Richardson Sept. 15, 2023, 11:52 a.m. UTC
  When doing a scan for tests to add to test suites, we can also detect
the tests which have not been added to any suite. By doing so:

a) we can emit a warning informing the developer that the test is not in
   a suite (if developer mode is enabled)
b) we can still register a test for that command making these tests
   callable through "meson test"

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/test/suites/meson.build   | 13 ++++++++++++-
 buildtools/get-test-suites.py | 12 +++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)
  

Patch

diff --git a/app/test/suites/meson.build b/app/test/suites/meson.build
index 19a6b902fa..478f245a54 100644
--- a/app/test/suites/meson.build
+++ b/app/test/suites/meson.build
@@ -21,7 +21,18 @@  foreach suite:test_suites
     suite = suite.split('=')
     suite_name = suite[0]
     suite_tests = suite[1].split(',')
-    if suite_name != 'fast-tests'
+    if suite_name == 'non_suite_tests'
+        # tests not in any suite
+        foreach t: suite_tests
+            if developer_mode
+                warning('Test "@0@" is not defined in any test suite'.format(t))
+            endif
+            test(t, dpdk_test,
+                    env: ['DPDK_TEST=' + t],
+                    timeout: timeout_seconds,
+                    is_parallel: false)
+        endforeach
+    elif suite_name != 'fast-tests'
         # simple cases - tests without parameters or special handling
         foreach t: suite_tests
             test(t, dpdk_test,
diff --git a/buildtools/get-test-suites.py b/buildtools/get-test-suites.py
index 95a9cad4c8..574c233aa8 100644
--- a/buildtools/get-test-suites.py
+++ b/buildtools/get-test-suites.py
@@ -8,18 +8,23 @@ 
 input_list = sys.argv[1:]
 test_def_regex = re.compile("REGISTER_([A-Z]+)_TEST\s*\(\s*([a-z0-9_]+)")
 test_suites = {}
+# track tests not in any test suite.
+non_suite_regex = re.compile("REGISTER_TEST_COMMAND\s*\(\s*([a-z0-9_]+)")
+non_suite_tests = []
 
 def get_fast_test_params(test_name, ln):
     "Extract the extra fast-test parameters from the line"
-    #print(f"ln: {ln.rstrip()}, test_name: {test_name}, split: {ln.split(test_name, 1)}")
     (_, rest_of_line) = ln.split(test_name, 1)
     (_, nohuge, asan, _func) = rest_of_line.split(',', 3)
     return f":{nohuge.strip().lower()}:{asan.strip().lower()}"
 
 for fname in input_list:
     with open(fname) as f:
-        contents = [ln for ln in f.readlines() if test_def_regex.match(ln.strip())]
-    for ln in contents:
+        contents = [ln.strip() for ln in f.readlines()]
+        test_lines = [ln for ln in contents if test_def_regex.match(ln)]
+        non_suite_tests.extend([non_suite_regex.match(ln).group(1)
+                for ln in contents if non_suite_regex.match(ln)])
+    for ln in test_lines:
         (test_suite, test_name) = test_def_regex.match(ln).group(1, 2)
         suite_name = f"{test_suite.lower()}-tests"
         if suite_name in test_suites:
@@ -31,3 +36,4 @@  def get_fast_test_params(test_name, ln):
 
 for suite in test_suites.keys():
     print(f"{suite}={','.join(test_suites[suite])}")
+print(f"non_suite_tests={','.join(non_suite_tests)}")