From 5c42c5fcedb3d1ce1de62711870e691cf768f4ca Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Wed, 14 Jan 2015 14:22:09 -0200 Subject: [PATCH] testsuite: prefer the use of streq() --- testsuite/init_module.c | 2 +- testsuite/test-blacklist.c | 4 +++- testsuite/test-dependencies.c | 8 +++++--- testsuite/test-hash.c | 5 +++-- testsuite/test-strbuf.c | 9 +++++---- testsuite/test-testsuite.c | 8 +++++--- testsuite/testsuite.c | 4 ++-- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/testsuite/init_module.c b/testsuite/init_module.c index 1e7573b..b7d220b 100644 --- a/testsuite/init_module.c +++ b/testsuite/init_module.c @@ -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) { - if (strcmp(mod->name, modname) == 0) + if (streq(mod->name, modname)) return mod; } diff --git a/testsuite/test-blacklist.c b/testsuite/test-blacklist.c index 99a86ab..0b9a30e 100644 --- a/testsuite/test-blacklist.c +++ b/testsuite/test-blacklist.c @@ -23,6 +23,8 @@ #include #include +#include + #include /* 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); - if (strcmp("pcspkr", modname) == 0 || strcmp("floppy", modname) == 0) + if (streq("pcspkr", modname) || streq("floppy", modname)) goto fail; len++; kmod_module_unref(mod); diff --git a/testsuite/test-dependencies.c b/testsuite/test-dependencies.c index ac7a08f..bed6ad4 100644 --- a/testsuite/test-dependencies.c +++ b/testsuite/test-dependencies.c @@ -23,6 +23,8 @@ #include #include +#include + #include #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); - if (strcmp(name, "crc16") == 0) + if (streq(name, "crc16")) crc16 = 1; - if (strcmp(name, "mbcache") == 0) + if (streq(name, "mbcache")) mbcache = 1; - else if (strcmp(name, "jbd2") == 0) + else if (streq(name, "jbd2")) jbd2 = 1; kmod_module_unref(m); diff --git a/testsuite/test-hash.c b/testsuite/test-hash.c index b81df5e..3cf5ba7 100644 --- a/testsuite/test-hash.c +++ b/testsuite/test-hash.c @@ -23,6 +23,7 @@ #include #include +#include #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(strcmp(v, v4) == 0, EXIT_FAILURE); + assert_return(streq(v, v4), 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(strcmp(v, v1) == 0, EXIT_FAILURE); + assert_return(streq(v, v1), EXIT_FAILURE); assert_return(freecount == 0, EXIT_FAILURE); diff --git a/testsuite/test-strbuf.c b/testsuite/test-strbuf.c index 972e6a4..c98c91d 100644 --- a/testsuite/test-strbuf.c +++ b/testsuite/test-strbuf.c @@ -23,6 +23,7 @@ #include #include +#include #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); - assert_return(strcmp(result1, TEXT) == 0, EXIT_FAILURE); + assert_return(streq(result1, TEXT), EXIT_FAILURE); 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); @@ -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); - assert_return(strcmp(result1, TEXT) == 0, EXIT_FAILURE); + assert_return(streq(result1, TEXT), EXIT_FAILURE); 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', diff --git a/testsuite/test-testsuite.c b/testsuite/test-testsuite.c index 58d312e..e6867b5 100644 --- a/testsuite/test-testsuite.c +++ b/testsuite/test-testsuite.c @@ -26,6 +26,8 @@ #include #include +#include + #include #include "testsuite.h" @@ -40,7 +42,7 @@ static noreturn int testsuite_uname(const struct test *t) 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); @@ -70,7 +72,7 @@ static int testsuite_rootfs_fopen(const struct test *t) 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; @@ -103,7 +105,7 @@ static int testsuite_rootfs_open(const struct test *t) 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; diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index 058d1dd..ca5bfe6 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -139,7 +139,7 @@ const struct test *test_find(const struct test *start, const struct test *t; for (t = start; t < stop; t++) { - if (strcmp(t->name, name) == 0) + if (streq(t->name, name)) return t; } @@ -402,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); -- 2.39.2