]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test: Use positive conditional in test_matches()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 11 Feb 2021 14:40:11 +0000 (16:40 +0200)
committerSimon Glass <sjg@chromium.org>
Thu, 29 Apr 2021 10:23:39 +0000 (03:23 -0700)
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>
Reviewed-by: Simon Glass <sjg@chromium.org>
test/test-main.c

index 1824cce2a6bffc97fb806d1922a2fbf7fa994057..7afe8741cf90ba29ea42257e04df9f3b4a950c9f 100644 (file)
@@ -148,16 +148,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))