diff mbox series

[v2,2/4] test: Allow simple glob pattern in the test name

Message ID 20210211144012.55676-2-andriy.shevchenko@linux.intel.com
State New
Delegated to: Simon Glass
Headers show
Series [v2,1/4] test: Include /sbin to the PATH when creating ext4 disk image | expand

Commit Message

Andy Shevchenko Feb. 11, 2021, 2:40 p.m. UTC
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>
---
v2: rebased against dm/test-working branch (Simon)
 test/test-main.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Simon Glass Feb. 18, 2021, 4:45 a.m. UTC | #1
On Thu, 11 Feb 2021 at 07:40, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> 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>
> ---
> v2: rebased against dm/test-working branch (Simon)

Sadly that is deferred, but we can pick this patch up later.

>  test/test-main.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/test/test-main.c b/test/test-main.c
index e1b49e091ab6..8fcbc2361214 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -128,10 +128,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) {
@@ -146,7 +153,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;