I'm not sure if this is an improvement over the previous patch. If so it should be squashed into it. Not-Signed-off-by --- tools/testing/selftests/nolibc/nolibc-test.c | 115 ++++++++++----------------- 1 file changed, 40 insertions(+), 75 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index b7ed10512d67..754815c142f6 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -127,17 +127,13 @@ static void putcharn(char c, size_t n) fputs(buf, stdout); } -enum RESULT { - OK, - FAIL, - SKIPPED, -}; +#define SKIPPED INT_MIN -static void result(int llen, enum RESULT r) +static void result(int llen, int r) { const char *msg; - if (r == OK) + if (r == 0) msg = " [OK]"; else if (r == SKIPPED) msg = "[SKIPPED]"; @@ -162,7 +158,7 @@ static int expect_zr(int expr, int llen) int ret = !(expr == 0); llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); + result(llen, ret); return ret; } @@ -175,7 +171,7 @@ static int expect_nz(int expr, int llen) int ret = !(expr != 0); llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); + result(llen, ret); return ret; } @@ -188,7 +184,7 @@ static int expect_eq(uint64_t expr, int llen, uint64_t val) int ret = !(expr == val); llen += printf(" = %lld ", (long long)expr); - result(llen, ret ? FAIL : OK); + result(llen, ret); return ret; } @@ -201,7 +197,7 @@ static int expect_ne(int expr, int llen, int val) int ret = !(expr != val); llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); + result(llen, ret); return ret; } @@ -214,7 +210,7 @@ static int expect_ge(int expr, int llen, int val) int ret = !(expr >= val); llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); + result(llen, ret); return ret; } @@ -227,7 +223,7 @@ static int expect_gt(int expr, int llen, int val) int ret = !(expr > val); llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); + result(llen, ret); return ret; } @@ -240,7 +236,7 @@ static int expect_le(int expr, int llen, int val) int ret = !(expr <= val); llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); + result(llen, ret); return ret; } @@ -253,7 +249,7 @@ static int expect_lt(int expr, int llen, int val) int ret = !(expr < val); llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); + result(llen, ret); return ret; } @@ -268,11 +264,10 @@ static int expect_syszr(int expr, int llen) if (expr) { ret = 1; llen += printf(" = %d %s ", expr, errorname(errno)); - result(llen, FAIL); } else { llen += printf(" = %d ", expr); - result(llen, OK); } + result(llen, ret); return ret; } @@ -287,11 +282,10 @@ static int expect_syseq(int expr, int llen, int val) if (expr != val) { ret = 1; llen += printf(" = %d %s ", expr, errorname(errno)); - result(llen, FAIL); } else { llen += printf(" = %d ", expr); - result(llen, OK); } + result(llen, ret); return ret; } @@ -306,11 +300,10 @@ static int expect_sysne(int expr, int llen, int val) if (expr == val) { ret = 1; llen += printf(" = %d %s ", expr, errorname(errno)); - result(llen, FAIL); } else { llen += printf(" = %d ", expr); - result(llen, OK); } + result(llen, ret); return ret; } @@ -333,10 +326,8 @@ static int expect_syserr2(int expr, int expret, int experr1, int experr2, int ll llen += printf(" != (%d %s) ", expret, errorname(experr1)); else llen += printf(" != (%d %s %s) ", expret, errorname(experr1), errorname(experr2)); - result(llen, FAIL); - } else { - result(llen, OK); } + result(llen, ret); return ret; } @@ -349,12 +340,9 @@ static int expect_ptrzr(const void *expr, int llen) int ret = 0; llen += printf(" = <%p> ", expr); - if (expr) { + if (expr) ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } + result(llen, ret); return ret; } @@ -367,12 +355,9 @@ static int expect_ptrnz(const void *expr, int llen) int ret = 0; llen += printf(" = <%p> ", expr); - if (!expr) { + if (!expr) ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } + result(llen, ret); return ret; } @@ -384,12 +369,9 @@ static int expect_ptreq(const void *expr, int llen, const void *cmp) int ret = 0; llen += printf(" = <%p> ", expr); - if (expr != cmp) { + if (expr != cmp) ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } + result(llen, ret); return ret; } @@ -401,12 +383,9 @@ static int expect_ptrne(const void *expr, int llen, const void *cmp) int ret = 0; llen += printf(" = <%p> ", expr); - if (expr == cmp) { + if (expr == cmp) ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } + result(llen, ret); return ret; } @@ -428,10 +407,8 @@ static int expect_ptrerr2(const void *expr, const void *expret, int experr1, int llen += printf(" != (<%p> %s) ", expret, errorname(experr1)); else llen += printf(" != (<%p> %s %s) ", expret, errorname(experr1), errorname(experr2)); - result(llen, FAIL); - } else { - result(llen, OK); } + result(llen, ret); return ret; } @@ -443,12 +420,9 @@ static int expect_strzr(const char *expr, int llen) int ret = 0; llen += printf(" = <%s> ", expr); - if (expr) { + if (expr) ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } + result(llen, ret); return ret; } @@ -461,12 +435,9 @@ static int expect_strnz(const char *expr, int llen) int ret = 0; llen += printf(" = <%s> ", expr); - if (!expr) { + if (!expr) ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } + result(llen, ret); return ret; } @@ -479,12 +450,9 @@ static int expect_streq(const char *expr, int llen, const char *cmp) int ret = 0; llen += printf(" = <%s> ", expr); - if (strcmp(expr, cmp) != 0) { + if (strcmp(expr, cmp) != 0) ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } + result(llen, ret); return ret; } @@ -497,12 +465,9 @@ static int expect_strne(const char *expr, int llen, const char *cmp) int ret = 0; llen += printf(" = <%s> ", expr); - if (strcmp(expr, cmp) == 0) { + if (strcmp(expr, cmp) == 0) ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } + result(llen, ret); return ret; } @@ -893,7 +858,7 @@ static int expect_vfprintf(int llen, size_t c, const char *expected, const char memfile = fdopen(fd, "w+"); if (!memfile) { - result(llen, FAIL); + result(llen, 1); return 1; } @@ -903,7 +868,7 @@ static int expect_vfprintf(int llen, size_t c, const char *expected, const char if (w != c) { llen += printf(" written(%d) != %d", w, (int) c); - result(llen, FAIL); + result(llen, 1); return 1; } @@ -917,14 +882,14 @@ static int expect_vfprintf(int llen, size_t c, const char *expected, const char if (r != w) { llen += printf(" written(%d) != read(%d)", w, r); - result(llen, FAIL); + result(llen, 1); return 1; } llen += printf(" \"%s\" = \"%s\"", expected, buf); ret = strncmp(expected, buf, c); - result(llen, ret ? FAIL : OK); + result(llen, ret); return ret; } @@ -987,7 +952,7 @@ static int run_protection(int min, int max) #if defined(_NOLIBC_STACKPROTECTOR) if (!__stack_chk_guard) { llen += printf("__stack_chk_guard not initialized"); - result(llen, FAIL); + result(llen, 1); return 1; } #endif @@ -998,7 +963,7 @@ static int run_protection(int min, int max) switch (pid) { case -1: llen += printf("fork()"); - result(llen, FAIL); + result(llen, 1); return 1; case 0: @@ -1014,10 +979,10 @@ static int run_protection(int min, int max) if (pid == -1 || !WIFSIGNALED(status) || WTERMSIG(status) != SIGABRT) { llen += printf("waitpid()"); - result(llen, FAIL); + result(llen, 1); return 1; } - result(llen, OK); + result(llen, 0); return 0; } } -- 2.41.0