diff mbox series

[v2,3/4] test: Use positive conditional in test_matches()

Message ID 20210211144012.55676-3-andriy.shevchenko@linux.intel.com
State Accepted
Commit 494a5e126b4de48091a161436839647246b29d29
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
It is easier to read the positive conditional.

While at it, convert hard coded length of "_test_" to strlen("_test_")
which will be converted to a constant bu optimizing compiler.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: new patch
 test/test-main.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 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:
>
> It is easier to read the positive conditional.
>
> While at it, convert hard coded length of "_test_" to strlen("_test_")
> which will be converted to a constant bu optimizing compiler.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v2: new patch
>  test/test-main.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Simon Glass April 29, 2021, 4:03 p.m. UTC | #2
On Thu, 11 Feb 2021 at 07:40, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> It is easier to read the positive conditional.
>
> While at it, convert hard coded length of "_test_" to strlen("_test_")
> which will be converted to a constant bu optimizing compiler.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v2: new patch
>  test/test-main.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

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

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/test/test-main.c b/test/test-main.c
index 8fcbc2361214..344122074e12 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -141,16 +141,16 @@  static bool test_matches(const char *prefix, const char *test_name,
 	if (!strncmp(test_name, select_name, len))
 		return true;
 
-	if (!prefix) {
+	if (prefix) {
+		/* All tests have this prefix */
+		if (!strncmp(test_name, prefix, strlen(prefix)))
+			test_name += strlen(prefix);
+	} else {
 		const char *p = strstr(test_name, "_test_");
 
 		/* convert xxx_test_yyy to yyy, i.e. remove the suite name */
 		if (p)
-			test_name = p + 6;
-	} else {
-		/* All tests have this prefix */
-		if (!strncmp(test_name, prefix, strlen(prefix)))
-			test_name += strlen(prefix);
+			test_name = p + strlen("_test_");
 	}
 
 	if (!strncmp(test_name, select_name, len))