]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test: Allow simple glob pattern in the test name
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 11 Feb 2021 14:40:10 +0000 (16:40 +0200)
committerSimon Glass <sjg@chromium.org>
Thu, 29 Apr 2021 10:23:39 +0000 (03:23 -0700)
When run `ut dm [test name]` allow to use simple pattern to run all tests
started with given prefix. For example, to run all ACPI test cases:
ut dm acpi*

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
test/test-main.c

index 8c852d72f482bf92bb58cb920dfd6564a80cf5ef..1824cce2a6bffc97fb806d1922a2fbf7fa994057 100644 (file)
@@ -135,10 +135,17 @@ static bool ut_test_run_on_flattree(struct unit_test *test)
 static bool test_matches(const char *prefix, const char *test_name,
                         const char *select_name)
 {
+       size_t len;
+
        if (!select_name)
                return true;
 
-       if (!strcmp(test_name, select_name))
+       /* Allow glob expansion in the test name */
+       len = select_name[strlen(select_name) - 1] == '*' ? strlen(select_name) : 0;
+       if (len-- == 1)
+               return true;
+
+       if (!strncmp(test_name, select_name, len))
                return true;
 
        if (!prefix) {
@@ -153,7 +160,7 @@ static bool test_matches(const char *prefix, const char *test_name,
                        test_name += strlen(prefix);
        }
 
-       if (!strcmp(test_name, select_name))
+       if (!strncmp(test_name, select_name, len))
                return true;
 
        return false;