]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: prefer the use of streq()
authorLucas De Marchi <lucas.demarchi@intel.com>
Wed, 14 Jan 2015 16:22:09 +0000 (14:22 -0200)
committerLucas De Marchi <lucas.demarchi@intel.com>
Wed, 14 Jan 2015 16:32:09 +0000 (14:32 -0200)
testsuite/init_module.c
testsuite/test-blacklist.c
testsuite/test-dependencies.c
testsuite/test-hash.c
testsuite/test-strbuf.c
testsuite/test-testsuite.c
testsuite/testsuite.c

index 1e7573bb3bc90843ee23814381994e2312387656..b7d220b725fbc76fa4dea78128d1f450c89852bb 100644 (file)
@@ -168,7 +168,7 @@ static struct mod *find_module(struct mod *_modules, const char *modname)
        struct mod *mod;
 
        for (mod = _modules; mod != NULL; mod = mod->next) {
        struct mod *mod;
 
        for (mod = _modules; mod != NULL; mod = mod->next) {
-               if (strcmp(mod->name, modname) == 0)
+               if (streq(mod->name, modname))
                        return mod;
        }
 
                        return mod;
        }
 
index 99a86ab171523ccd75ea58a8dd2582f836227923..0b9a30e8fb0b842e52eb5a3034a1b77bdd33c402 100644 (file)
@@ -23,6 +23,8 @@
 #include <string.h>
 #include <unistd.h>
 
 #include <string.h>
 #include <unistd.h>
 
+#include <shared/util.h>
+
 #include <libkmod/libkmod.h>
 
 /* good luck bulding a kmod_list outside of the library... makes this blacklist
 #include <libkmod/libkmod.h>
 
 /* good luck bulding a kmod_list outside of the library... makes this blacklist
@@ -70,7 +72,7 @@ static int blacklist_1(const struct test *t)
                const char *modname;
                mod = kmod_module_get_module(l);
                modname = kmod_module_get_name(mod);
                const char *modname;
                mod = kmod_module_get_module(l);
                modname = kmod_module_get_name(mod);
-               if (strcmp("pcspkr", modname) == 0 || strcmp("floppy", modname) == 0)
+               if (streq("pcspkr", modname) || streq("floppy", modname))
                        goto fail;
                len++;
                kmod_module_unref(mod);
                        goto fail;
                len++;
                kmod_module_unref(mod);
index ac7a08fd30c570fbf0428a639787a3b31ff2cb0c..bed6ad4f3b9f46aa0ae7c5b5046f1b5ec9179ee8 100644 (file)
@@ -23,6 +23,8 @@
 #include <string.h>
 #include <unistd.h>
 
 #include <string.h>
 #include <unistd.h>
 
+#include <shared/util.h>
+
 #include <libkmod/libkmod.h>
 
 #include "testsuite.h"
 #include <libkmod/libkmod.h>
 
 #include "testsuite.h"
@@ -54,11 +56,11 @@ static int test_dependencies(const struct test *t)
                struct kmod_module *m = kmod_module_get_module(l);
                const char *name = kmod_module_get_name(m);
 
                struct kmod_module *m = kmod_module_get_module(l);
                const char *name = kmod_module_get_name(m);
 
-               if (strcmp(name, "crc16") == 0)
+               if (streq(name, "crc16"))
                        crc16 = 1;
                        crc16 = 1;
-               if (strcmp(name, "mbcache") == 0)
+               if (streq(name, "mbcache"))
                        mbcache = 1;
                        mbcache = 1;
-               else if (strcmp(name, "jbd2") == 0)
+               else if (streq(name, "jbd2"))
                        jbd2 = 1;
 
                kmod_module_unref(m);
                        jbd2 = 1;
 
                kmod_module_unref(m);
index b81df5ef6e0a701a4a27cf3cce87307ef35cafa0..3cf5ba7dff05aef47a57a6c330e56864737b6901 100644 (file)
@@ -23,6 +23,7 @@
 #include <unistd.h>
 
 #include <shared/hash.h>
 #include <unistd.h>
 
 #include <shared/hash.h>
+#include <shared/util.h>
 
 #include "testsuite.h"
 
 
 #include "testsuite.h"
 
@@ -82,7 +83,7 @@ static int test_hash_replace(const struct test *t)
        assert_return(hash_get_count(h) == 3, EXIT_FAILURE);
 
        v = hash_find(h, "k1");
        assert_return(hash_get_count(h) == 3, EXIT_FAILURE);
 
        v = hash_find(h, "k1");
-       assert_return(strcmp(v, v4) == 0, EXIT_FAILURE);
+       assert_return(streq(v, v4), EXIT_FAILURE);
 
        assert_return(freecount == 1, EXIT_FAILURE);
 
 
        assert_return(freecount == 1, EXIT_FAILURE);
 
@@ -113,7 +114,7 @@ static int test_hash_replace_failing(const struct test *t)
        assert_return(hash_get_count(h) == 3, EXIT_FAILURE);
 
        v = hash_find(h, "k1");
        assert_return(hash_get_count(h) == 3, EXIT_FAILURE);
 
        v = hash_find(h, "k1");
-       assert_return(strcmp(v, v1) == 0, EXIT_FAILURE);
+       assert_return(streq(v, v1), EXIT_FAILURE);
 
        assert_return(freecount == 0, EXIT_FAILURE);
 
 
        assert_return(freecount == 0, EXIT_FAILURE);
 
index 972e6a4c4a375545d25739f6a51adc8d45dc6bf3..c98c91d1605668629ed62d12329887486950336f 100644 (file)
@@ -23,6 +23,7 @@
 #include <unistd.h>
 
 #include <shared/strbuf.h>
 #include <unistd.h>
 
 #include <shared/strbuf.h>
+#include <shared/util.h>
 
 #include "testsuite.h"
 
 
 #include "testsuite.h"
 
@@ -42,11 +43,11 @@ static int test_strbuf_pushchar(const struct test *t)
 
        result1 = (char *) strbuf_str(&buf);
        assert_return(result1 == buf.bytes, EXIT_FAILURE);
 
        result1 = (char *) strbuf_str(&buf);
        assert_return(result1 == buf.bytes, EXIT_FAILURE);
-       assert_return(strcmp(result1, TEXT) == 0, EXIT_FAILURE);
+       assert_return(streq(result1, TEXT), EXIT_FAILURE);
        result1 = strdup(result1);
 
        result2 = strbuf_steal(&buf);
        result1 = strdup(result1);
 
        result2 = strbuf_steal(&buf);
-       assert_return(strcmp(result1, result2) == 0, EXIT_FAILURE);
+       assert_return(streq(result1, result2), EXIT_FAILURE);
 
        free(result1);
        free(result2);
 
        free(result1);
        free(result2);
@@ -75,11 +76,11 @@ static int test_strbuf_pushchars(const struct test *t)
        strbuf_popchar(&buf);
        result1 = (char *) strbuf_str(&buf);
        assert_return(result1 == buf.bytes, EXIT_FAILURE);
        strbuf_popchar(&buf);
        result1 = (char *) strbuf_str(&buf);
        assert_return(result1 == buf.bytes, EXIT_FAILURE);
-       assert_return(strcmp(result1, TEXT) == 0, EXIT_FAILURE);
+       assert_return(streq(result1, TEXT), EXIT_FAILURE);
 
        strbuf_popchars(&buf, lastwordlen);
        result2 = strbuf_steal(&buf);
 
        strbuf_popchars(&buf, lastwordlen);
        result2 = strbuf_steal(&buf);
-       assert_return(strcmp(TEXT, result2) != 0, EXIT_FAILURE);
+       assert_return(!streq(TEXT, result2), EXIT_FAILURE);
        assert_return(strncmp(TEXT, result2, strlen(TEXT) - lastwordlen) == 0,
                      EXIT_FAILURE);
        assert_return(result2[strlen(TEXT) - lastwordlen] == '\0',
        assert_return(strncmp(TEXT, result2, strlen(TEXT) - lastwordlen) == 0,
                      EXIT_FAILURE);
        assert_return(result2[strlen(TEXT) - lastwordlen] == '\0',
index 58d312e17b654c440491b7a0a38fae40336bc59d..e6867b5047d39f1d0f965f17dbf5b2b9ffae8b5e 100644 (file)
@@ -26,6 +26,8 @@
 #include <sys/types.h>
 #include <sys/utsname.h>
 
 #include <sys/types.h>
 #include <sys/utsname.h>
 
+#include <shared/util.h>
+
 #include <libkmod/libkmod.h>
 
 #include "testsuite.h"
 #include <libkmod/libkmod.h>
 
 #include "testsuite.h"
@@ -40,7 +42,7 @@ static noreturn int testsuite_uname(const struct test *t)
        if (err < 0)
                exit(EXIT_FAILURE);
 
        if (err < 0)
                exit(EXIT_FAILURE);
 
-       if (strcmp(u.release, TEST_UNAME) != 0) {
+       if (!streq(u.release, TEST_UNAME)) {
                char *ldpreload = getenv("LD_PRELOAD");
                ERR("u.release=%s should be %s\n", u.release, TEST_UNAME);
                ERR("LD_PRELOAD=%s\n", ldpreload);
                char *ldpreload = getenv("LD_PRELOAD");
                ERR("u.release=%s should be %s\n", u.release, TEST_UNAME);
                ERR("LD_PRELOAD=%s\n", ldpreload);
@@ -70,7 +72,7 @@ static int testsuite_rootfs_fopen(const struct test *t)
        if (n != 1)
                return EXIT_FAILURE;
 
        if (n != 1)
                return EXIT_FAILURE;
 
-       if (strcmp(s, "kmod-test-chroot-works") != 0)
+       if (!streq(s, "kmod-test-chroot-works"))
                return EXIT_FAILURE;
 
        return EXIT_SUCCESS;
                return EXIT_FAILURE;
 
        return EXIT_SUCCESS;
@@ -103,7 +105,7 @@ static int testsuite_rootfs_open(const struct test *t)
 
        buf[done] = '\0';
 
 
        buf[done] = '\0';
 
-       if (strcmp(buf, "kmod-test-chroot-works\n") != 0)
+       if (!streq(buf, "kmod-test-chroot-works\n"))
                return EXIT_FAILURE;
 
        return EXIT_SUCCESS;
                return EXIT_FAILURE;
 
        return EXIT_SUCCESS;
index 058d1dd74b223e381700fcc63743ffe1713aa8a8..ca5bfe6c747ba895a2c2a0c445f8fee25b19a6eb 100644 (file)
@@ -139,7 +139,7 @@ const struct test *test_find(const struct test *start,
        const struct test *t;
 
        for (t = start; t < stop; t++) {
        const struct test *t;
 
        for (t = start; t < stop; t++) {
-               if (strcmp(t->name, name) == 0)
+               if (streq(t->name, name))
                        return t;
        }
 
                        return t;
        }
 
@@ -402,7 +402,7 @@ static inline bool test_run_parent_check_outputs(const struct test *t,
 
                                buf[r] = '\0';
                                bufmatch[r] = '\0';
 
                                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);
                                        ERR("Outputs do not match on %s:\n",
                                                fd_match == fd_matchout ? "stdout" : "stderr");
                                        ERR("correct:\n%s\n", bufmatch);