]> git.ipfire.org Git - thirdparty/kmod.git/blobdiff - testsuite/testsuite.c
testsuite: prefer the use of streq()
[thirdparty/kmod.git] / testsuite / testsuite.c
index 9ccdcb78352c7ca60eae66f0e693e28ce207b28b..ca5bfe6c747ba895a2c2a0c445f8fee25b19a6eb 100644 (file)
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <getopt.h>
 #include <limits.h>
-#include <dirent.h>
-#include <stdio.h>
 #include <stdarg.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
@@ -32,7 +31,8 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 
-#include "libkmod-util.h"
+#include <shared/util.h>
+
 #include "testsuite.h"
 
 static const char *ANSI_HIGHLIGHT_GREEN_ON = "\x1B[1;32m";
@@ -87,16 +87,17 @@ static void help(void)
                printf("\t-%c, --%s\n", *itr_short, itr->name);
 }
 
-static void test_list(const struct test *tests[])
+static void test_list(const struct test *start, const struct test *stop)
 {
-       size_t i;
+       const struct test *t;
 
        printf("Available tests:\n");
-       for (i = 0; tests[i] != NULL; i++)
-               printf("\t%s, %s\n", tests[i]->name, tests[i]->description);
+       for (t = start; t < stop; t++)
+               printf("\t%s, %s\n", t->name, t->description);
 }
 
-int test_init(int argc, char *const argv[], const struct test *tests[])
+int test_init(const struct test *start, const struct test *stop,
+             int argc, char *const argv[])
 {
        progname = argv[0];
 
@@ -107,7 +108,7 @@ int test_init(int argc, char *const argv[], const struct test *tests[])
                        break;
                switch (c) {
                case 'l':
-                       test_list(tests);
+                       test_list(start, stop);
                        return 0;
                case 'h':
                        help();
@@ -132,13 +133,14 @@ int test_init(int argc, char *const argv[], const struct test *tests[])
        return optind;
 }
 
-const struct test *test_find(const struct test *tests[], const char *name)
+const struct test *test_find(const struct test *start,
+                            const struct test *stop, const char *name)
 {
-       size_t i;
+       const struct test *t;
 
-       for (i = 0; tests[i] != NULL; i++) {
-               if (strcmp(tests[i]->name, name) == 0)
-                       return tests[i];
+       for (t = start; t < stop; t++) {
+               if (streq(t->name, name))
+                       return t;
        }
 
        return NULL;
@@ -400,7 +402,7 @@ static inline bool test_run_parent_check_outputs(const struct test *t,
 
                                buf[r] = '\0';
                                bufmatch[r] = '\0';
-                               if (strcmp(buf, bufmatch) != 0) {
+                               if (!streq(buf, bufmatch)) {
                                        ERR("Outputs do not match on %s:\n",
                                                fd_match == fd_matchout ? "stdout" : "stderr");
                                        ERR("correct:\n%s\n", bufmatch);
@@ -737,7 +739,8 @@ static inline int test_run_parent(const struct test *t, int fdout[2],
                pid = wait(&err);
                if (pid == -1) {
                        ERR("error waitpid(): %m\n");
-                       return EXIT_FAILURE;
+                       err = EXIT_FAILURE;
+                       goto exit;
                }
        } while (!WIFEXITED(err) && !WIFSIGNALED(err));
 
@@ -751,7 +754,8 @@ static inline int test_run_parent(const struct test *t, int fdout[2],
        } else if (WIFSIGNALED(err)) {
                ERR("'%s' [%u] terminated by signal %d (%s)\n", t->name, pid,
                                WTERMSIG(err), strsignal(WTERMSIG(err)));
-               return t->expected_fail ? EXIT_SUCCESS : EXIT_FAILURE;
+               err = t->expected_fail ? EXIT_SUCCESS : EXIT_FAILURE;
+               goto exit;
        }
 
        if (matchout)
@@ -807,6 +811,8 @@ static inline int test_run_parent(const struct test *t, int fdout[2],
                }
        }
 
+exit:
+       LOG("------\n");
        return err;
 }