From patchwork Tue Jul 11 09:48:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13308379 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99B0AEB64DC for ; Tue, 11 Jul 2023 09:49:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232192AbjGKJtw (ORCPT ); Tue, 11 Jul 2023 05:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231558AbjGKJtj (ORCPT ); Tue, 11 Jul 2023 05:49:39 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA627CE; Tue, 11 Jul 2023 02:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1689068974; bh=I1822N+UF+jAkDVQCrbQ8SL5nFp5rcCn28BvKolp1T0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=K1wwGeeiZLUuLz5EfSTlgeD9okS63NQoo1Tkqi1sQK+cf4c8HB3Rt4GStYqZxNHco j0iRPgWFTRpuqwOKAjwQCrz2RGNChL5o4A0qx+etal8HxRobDGwTBLStTg55g3tWq6 3u+2jD06VpeTYxIVe0mXJqg3F5z8N96ZobUSwv5Q= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 11 Jul 2023 11:48:39 +0200 Subject: [PATCH 1/4] selftests/nolibc: make evaluation of test conditions MIME-Version: 1.0 Message-Id: <20230711-nolibc-sizeof-long-gaps-v1-1-dc78c3b85fc3@weissschuh.net> References: <20230711-nolibc-sizeof-long-gaps-v1-0-dc78c3b85fc3@weissschuh.net> In-Reply-To: <20230711-nolibc-sizeof-long-gaps-v1-0-dc78c3b85fc3@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zhangjin Wu , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1689068953; l=9411; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=I1822N+UF+jAkDVQCrbQ8SL5nFp5rcCn28BvKolp1T0=; b=36egk9Q28laXJBW735eeY0D8ibWEWySVagip/C12PtxgH5iGGQ3nuqnyRTaT/PRjT7fhCwjw7 3awFzQGKK7hDZr1s1igHthGfEgjUkmV0Ti+U2xaBfo3EGSuC2YTZ4Wn X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org If "cond" is a multi-token statement the behavior of the preprocessor will lead to the negation "!" to be only applied to the first token. Although currently no test uses such multi-token conditions but it can happen at any time. Put braces around "cond" to ensure the negation works as expected. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/nolibc/nolibc-test.c | 42 ++++++++++++++-------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index f357bd815abc..c252ea0c2f01 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -147,7 +147,7 @@ static int pad_spc(int llen, int cnt, const char *fmt, ...) */ #define EXPECT_ZR(cond, expr) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_zr(expr, llen); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_zr(expr, llen); } while (0) static int expect_zr(int expr, int llen) { @@ -160,7 +160,7 @@ static int expect_zr(int expr, int llen) #define EXPECT_NZ(cond, expr, val) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_nz(expr, llen; } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_nz(expr, llen; } while (0) static int expect_nz(int expr, int llen) { @@ -173,7 +173,7 @@ static int expect_nz(int expr, int llen) #define EXPECT_EQ(cond, expr, val) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_eq(expr, llen, val); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_eq(expr, llen, val); } while (0) static int expect_eq(uint64_t expr, int llen, uint64_t val) { @@ -186,7 +186,7 @@ static int expect_eq(uint64_t expr, int llen, uint64_t val) #define EXPECT_NE(cond, expr, val) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ne(expr, llen, val); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ne(expr, llen, val); } while (0) static int expect_ne(int expr, int llen, int val) { @@ -199,7 +199,7 @@ static int expect_ne(int expr, int llen, int val) #define EXPECT_GE(cond, expr, val) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ge(expr, llen, val); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ge(expr, llen, val); } while (0) static int expect_ge(int expr, int llen, int val) { @@ -212,7 +212,7 @@ static int expect_ge(int expr, int llen, int val) #define EXPECT_GT(cond, expr, val) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_gt(expr, llen, val); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_gt(expr, llen, val); } while (0) static int expect_gt(int expr, int llen, int val) { @@ -225,7 +225,7 @@ static int expect_gt(int expr, int llen, int val) #define EXPECT_LE(cond, expr, val) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_le(expr, llen, val); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_le(expr, llen, val); } while (0) static int expect_le(int expr, int llen, int val) { @@ -238,7 +238,7 @@ static int expect_le(int expr, int llen, int val) #define EXPECT_LT(cond, expr, val) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_lt(expr, llen, val); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_lt(expr, llen, val); } while (0) static int expect_lt(int expr, int llen, int val) { @@ -251,7 +251,7 @@ static int expect_lt(int expr, int llen, int val) #define EXPECT_SYSZR(cond, expr) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_syszr(expr, llen); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_syszr(expr, llen); } while (0) static int expect_syszr(int expr, int llen) { @@ -270,7 +270,7 @@ static int expect_syszr(int expr, int llen) #define EXPECT_SYSEQ(cond, expr, val) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_syseq(expr, llen, val); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_syseq(expr, llen, val); } while (0) static int expect_syseq(int expr, int llen, int val) { @@ -289,7 +289,7 @@ static int expect_syseq(int expr, int llen, int val) #define EXPECT_SYSNE(cond, expr, val) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_sysne(expr, llen, val); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_sysne(expr, llen, val); } while (0) static int expect_sysne(int expr, int llen, int val) { @@ -308,7 +308,7 @@ static int expect_sysne(int expr, int llen, int val) #define EXPECT_SYSER2(cond, expr, expret, experr1, experr2) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_syserr2(expr, expret, experr1, experr2, llen); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_syserr2(expr, expret, experr1, experr2, llen); } while (0) #define EXPECT_SYSER(cond, expr, expret, experr) \ EXPECT_SYSER2(cond, expr, expret, experr, 0) @@ -334,7 +334,7 @@ static int expect_syserr2(int expr, int expret, int experr1, int experr2, int ll #define EXPECT_PTRZR(cond, expr) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrzr(expr, llen); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrzr(expr, llen); } while (0) static int expect_ptrzr(const void *expr, int llen) { @@ -352,7 +352,7 @@ static int expect_ptrzr(const void *expr, int llen) #define EXPECT_PTRNZ(cond, expr) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrnz(expr, llen); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrnz(expr, llen); } while (0) static int expect_ptrnz(const void *expr, int llen) { @@ -369,7 +369,7 @@ static int expect_ptrnz(const void *expr, int llen) } #define EXPECT_PTREQ(cond, expr, cmp) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptreq(expr, llen, cmp); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptreq(expr, llen, cmp); } while (0) static int expect_ptreq(const void *expr, int llen, const void *cmp) { @@ -386,7 +386,7 @@ static int expect_ptreq(const void *expr, int llen, const void *cmp) } #define EXPECT_PTRNE(cond, expr, cmp) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrne(expr, llen, cmp); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrne(expr, llen, cmp); } while (0) static int expect_ptrne(const void *expr, int llen, const void *cmp) { @@ -403,7 +403,7 @@ static int expect_ptrne(const void *expr, int llen, const void *cmp) } #define EXPECT_PTRER2(cond, expr, expret, experr1, experr2) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrerr2(expr, expret, experr1, experr2, llen); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrerr2(expr, expret, experr1, experr2, llen); } while (0) #define EXPECT_PTRER(cond, expr, expret, experr) \ EXPECT_PTRER2(cond, expr, expret, experr, 0) @@ -428,7 +428,7 @@ static int expect_ptrerr2(const void *expr, const void *expret, int experr1, int } #define EXPECT_STRZR(cond, expr) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_strzr(expr, llen); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_strzr(expr, llen); } while (0) static int expect_strzr(const char *expr, int llen) { @@ -446,7 +446,7 @@ static int expect_strzr(const char *expr, int llen) #define EXPECT_STRNZ(cond, expr) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_strnz(expr, llen); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_strnz(expr, llen); } while (0) static int expect_strnz(const char *expr, int llen) { @@ -464,7 +464,7 @@ static int expect_strnz(const char *expr, int llen) #define EXPECT_STREQ(cond, expr, cmp) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_streq(expr, llen, cmp); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_streq(expr, llen, cmp); } while (0) static int expect_streq(const char *expr, int llen, const char *cmp) { @@ -482,7 +482,7 @@ static int expect_streq(const char *expr, int llen, const char *cmp) #define EXPECT_STRNE(cond, expr, cmp) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_strne(expr, llen, cmp); } while (0) + do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_strne(expr, llen, cmp); } while (0) static int expect_strne(const char *expr, int llen, const char *cmp) { From patchwork Tue Jul 11 09:48:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13308378 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3466EC001B0 for ; Tue, 11 Jul 2023 09:49:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232140AbjGKJtw (ORCPT ); Tue, 11 Jul 2023 05:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231653AbjGKJto (ORCPT ); Tue, 11 Jul 2023 05:49:44 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 788AE10A; Tue, 11 Jul 2023 02:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1689068974; bh=txFukGFwyweVshf0G5po0roPtMNzdkZKHFjAEnu9/v8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iJVfM8jhI7hf1IL/Hbtk6PTdCqgNpdT5w0yqGi2ujcL/IWdndcmRAx5JMXDvrZuSp YETS5twab4qxJqE2CMXiwwDjmZdVpVmulX6ypO7HkoCldobpmLAt2vIySkWI940UUN S57wVw1oJwticAFObWXMJWJBHnxsACo7kbdKvGhk= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 11 Jul 2023 11:48:40 +0200 Subject: [PATCH 2/4] selftests/nolibc: simplify status printing MIME-Version: 1.0 Message-Id: <20230711-nolibc-sizeof-long-gaps-v1-2-dc78c3b85fc3@weissschuh.net> References: <20230711-nolibc-sizeof-long-gaps-v1-0-dc78c3b85fc3@weissschuh.net> In-Reply-To: <20230711-nolibc-sizeof-long-gaps-v1-0-dc78c3b85fc3@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zhangjin Wu , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1689068953; l=16359; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=txFukGFwyweVshf0G5po0roPtMNzdkZKHFjAEnu9/v8=; b=ffZCKr1Wzpbq7cuSyuk0E+DlmtB/1JAot5oohiM7uH420wiOd8ZSh0H9ElBMBuojb18LA2CfG Z22zBOIehOdCySNi7x9dZdoMbspvXfFkjG6N1PwBmFrD5ZCti/bfuDg X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org pad_spc() is only ever used to print the status message of testcases. The line size is always constant, the return value is never used and the format string is never used as such. Remove all the unneeded logic and simplify the API and its users. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/nolibc/nolibc-test.c | 154 ++++++++++++++------------- 1 file changed, 81 insertions(+), 73 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index c252ea0c2f01..b7ed10512d67 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -127,17 +127,25 @@ static void putcharn(char c, size_t n) fputs(buf, stdout); } -static int pad_spc(int llen, int cnt, const char *fmt, ...) +enum RESULT { + OK, + FAIL, + SKIPPED, +}; + +static void result(int llen, enum RESULT r) { - va_list args; - int ret; + const char *msg; - putcharn(' ', cnt - llen); + if (r == OK) + msg = " [OK]"; + else if (r == SKIPPED) + msg = "[SKIPPED]"; + else + msg = "[FAIL]"; - va_start(args, fmt); - ret = vfprintf(stdout, fmt, args); - va_end(args); - return ret < 0 ? ret : ret + cnt - llen; + putcharn(' ', 64 - llen); + puts(msg); } /* The tests below are intended to be used by the macroes, which evaluate @@ -147,111 +155,111 @@ static int pad_spc(int llen, int cnt, const char *fmt, ...) */ #define EXPECT_ZR(cond, expr) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_zr(expr, llen); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_zr(expr, llen); } while (0) static int expect_zr(int expr, int llen) { int ret = !(expr == 0); llen += printf(" = %d ", expr); - pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n"); + result(llen, ret ? FAIL : OK); return ret; } #define EXPECT_NZ(cond, expr, val) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_nz(expr, llen; } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_nz(expr, llen; } while (0) static int expect_nz(int expr, int llen) { int ret = !(expr != 0); llen += printf(" = %d ", expr); - pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n"); + result(llen, ret ? FAIL : OK); return ret; } #define EXPECT_EQ(cond, expr, val) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_eq(expr, llen, val); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_eq(expr, llen, val); } while (0) static int expect_eq(uint64_t expr, int llen, uint64_t val) { int ret = !(expr == val); llen += printf(" = %lld ", (long long)expr); - pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n"); + result(llen, ret ? FAIL : OK); return ret; } #define EXPECT_NE(cond, expr, val) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ne(expr, llen, val); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ne(expr, llen, val); } while (0) static int expect_ne(int expr, int llen, int val) { int ret = !(expr != val); llen += printf(" = %d ", expr); - pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n"); + result(llen, ret ? FAIL : OK); return ret; } #define EXPECT_GE(cond, expr, val) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ge(expr, llen, val); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ge(expr, llen, val); } while (0) static int expect_ge(int expr, int llen, int val) { int ret = !(expr >= val); llen += printf(" = %d ", expr); - pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n"); + result(llen, ret ? FAIL : OK); return ret; } #define EXPECT_GT(cond, expr, val) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_gt(expr, llen, val); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_gt(expr, llen, val); } while (0) static int expect_gt(int expr, int llen, int val) { int ret = !(expr > val); llen += printf(" = %d ", expr); - pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n"); + result(llen, ret ? FAIL : OK); return ret; } #define EXPECT_LE(cond, expr, val) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_le(expr, llen, val); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_le(expr, llen, val); } while (0) static int expect_le(int expr, int llen, int val) { int ret = !(expr <= val); llen += printf(" = %d ", expr); - pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n"); + result(llen, ret ? FAIL : OK); return ret; } #define EXPECT_LT(cond, expr, val) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_lt(expr, llen, val); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_lt(expr, llen, val); } while (0) static int expect_lt(int expr, int llen, int val) { int ret = !(expr < val); llen += printf(" = %d ", expr); - pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n"); + result(llen, ret ? FAIL : OK); return ret; } #define EXPECT_SYSZR(cond, expr) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_syszr(expr, llen); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_syszr(expr, llen); } while (0) static int expect_syszr(int expr, int llen) { @@ -260,17 +268,17 @@ static int expect_syszr(int expr, int llen) if (expr) { ret = 1; llen += printf(" = %d %s ", expr, errorname(errno)); - llen += pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); } else { llen += printf(" = %d ", expr); - llen += pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); } return ret; } #define EXPECT_SYSEQ(cond, expr, val) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_syseq(expr, llen, val); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_syseq(expr, llen, val); } while (0) static int expect_syseq(int expr, int llen, int val) { @@ -279,17 +287,17 @@ static int expect_syseq(int expr, int llen, int val) if (expr != val) { ret = 1; llen += printf(" = %d %s ", expr, errorname(errno)); - llen += pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); } else { llen += printf(" = %d ", expr); - llen += pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); } return ret; } #define EXPECT_SYSNE(cond, expr, val) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_sysne(expr, llen, val); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_sysne(expr, llen, val); } while (0) static int expect_sysne(int expr, int llen, int val) { @@ -298,17 +306,17 @@ static int expect_sysne(int expr, int llen, int val) if (expr == val) { ret = 1; llen += printf(" = %d %s ", expr, errorname(errno)); - llen += pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); } else { llen += printf(" = %d ", expr); - llen += pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); } return ret; } #define EXPECT_SYSER2(cond, expr, expret, experr1, experr2) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_syserr2(expr, expret, experr1, experr2, llen); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_syserr2(expr, expret, experr1, experr2, llen); } while (0) #define EXPECT_SYSER(cond, expr, expret, experr) \ EXPECT_SYSER2(cond, expr, expret, experr, 0) @@ -325,16 +333,16 @@ 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)); - llen += pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); } else { - llen += pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); } return ret; } #define EXPECT_PTRZR(cond, expr) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrzr(expr, llen); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptrzr(expr, llen); } while (0) static int expect_ptrzr(const void *expr, int llen) { @@ -343,16 +351,16 @@ static int expect_ptrzr(const void *expr, int llen) llen += printf(" = <%p> ", expr); if (expr) { ret = 1; - llen += pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); } else { - llen += pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); } return ret; } #define EXPECT_PTRNZ(cond, expr) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrnz(expr, llen); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptrnz(expr, llen); } while (0) static int expect_ptrnz(const void *expr, int llen) { @@ -361,15 +369,15 @@ static int expect_ptrnz(const void *expr, int llen) llen += printf(" = <%p> ", expr); if (!expr) { ret = 1; - llen += pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); } else { - llen += pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); } return ret; } #define EXPECT_PTREQ(cond, expr, cmp) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptreq(expr, llen, cmp); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptreq(expr, llen, cmp); } while (0) static int expect_ptreq(const void *expr, int llen, const void *cmp) { @@ -378,15 +386,15 @@ static int expect_ptreq(const void *expr, int llen, const void *cmp) llen += printf(" = <%p> ", expr); if (expr != cmp) { ret = 1; - llen += pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); } else { - llen += pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); } return ret; } #define EXPECT_PTRNE(cond, expr, cmp) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrne(expr, llen, cmp); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptrne(expr, llen, cmp); } while (0) static int expect_ptrne(const void *expr, int llen, const void *cmp) { @@ -395,15 +403,15 @@ static int expect_ptrne(const void *expr, int llen, const void *cmp) llen += printf(" = <%p> ", expr); if (expr == cmp) { ret = 1; - llen += pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); } else { - llen += pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); } return ret; } #define EXPECT_PTRER2(cond, expr, expret, experr1, experr2) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrerr2(expr, expret, experr1, experr2, llen); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptrerr2(expr, expret, experr1, experr2, llen); } while (0) #define EXPECT_PTRER(cond, expr, expret, experr) \ EXPECT_PTRER2(cond, expr, expret, experr, 0) @@ -420,15 +428,15 @@ 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)); - llen += pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); } else { - llen += pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); } return ret; } #define EXPECT_STRZR(cond, expr) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_strzr(expr, llen); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_strzr(expr, llen); } while (0) static int expect_strzr(const char *expr, int llen) { @@ -437,16 +445,16 @@ static int expect_strzr(const char *expr, int llen) llen += printf(" = <%s> ", expr); if (expr) { ret = 1; - llen += pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); } else { - llen += pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); } return ret; } #define EXPECT_STRNZ(cond, expr) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_strnz(expr, llen); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_strnz(expr, llen); } while (0) static int expect_strnz(const char *expr, int llen) { @@ -455,16 +463,16 @@ static int expect_strnz(const char *expr, int llen) llen += printf(" = <%s> ", expr); if (!expr) { ret = 1; - llen += pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); } else { - llen += pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); } return ret; } #define EXPECT_STREQ(cond, expr, cmp) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_streq(expr, llen, cmp); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_streq(expr, llen, cmp); } while (0) static int expect_streq(const char *expr, int llen, const char *cmp) { @@ -473,16 +481,16 @@ static int expect_streq(const char *expr, int llen, const char *cmp) llen += printf(" = <%s> ", expr); if (strcmp(expr, cmp) != 0) { ret = 1; - llen += pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); } else { - llen += pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); } return ret; } #define EXPECT_STRNE(cond, expr, cmp) \ - do { if (!(cond)) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_strne(expr, llen, cmp); } while (0) + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_strne(expr, llen, cmp); } while (0) static int expect_strne(const char *expr, int llen, const char *cmp) { @@ -491,9 +499,9 @@ static int expect_strne(const char *expr, int llen, const char *cmp) llen += printf(" = <%s> ", expr); if (strcmp(expr, cmp) == 0) { ret = 1; - llen += pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); } else { - llen += pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); } return ret; } @@ -879,13 +887,13 @@ static int expect_vfprintf(int llen, size_t c, const char *expected, const char fd = open("/tmp", O_TMPFILE | O_EXCL | O_RDWR, 0600); if (fd == -1) { - pad_spc(llen, 64, "[SKIPPED]\n"); + result(llen, SKIPPED); return 0; } memfile = fdopen(fd, "w+"); if (!memfile) { - pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); return 1; } @@ -895,7 +903,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); - pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); return 1; } @@ -909,14 +917,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); - pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); return 1; } llen += printf(" \"%s\" = \"%s\"", expected, buf); ret = strncmp(expected, buf, c); - pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n"); + result(llen, ret ? FAIL : OK); return ret; } @@ -972,14 +980,14 @@ static int run_protection(int min, int max) #if !defined(_NOLIBC_STACKPROTECTOR) llen += printf("not supported"); - pad_spc(llen, 64, "[SKIPPED]\n"); + result(llen, SKIPPED); return 0; #endif #if defined(_NOLIBC_STACKPROTECTOR) if (!__stack_chk_guard) { llen += printf("__stack_chk_guard not initialized"); - pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); return 1; } #endif @@ -990,7 +998,7 @@ static int run_protection(int min, int max) switch (pid) { case -1: llen += printf("fork()"); - pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); return 1; case 0: @@ -1006,10 +1014,10 @@ static int run_protection(int min, int max) if (pid == -1 || !WIFSIGNALED(status) || WTERMSIG(status) != SIGABRT) { llen += printf("waitpid()"); - pad_spc(llen, 64, "[FAIL]\n"); + result(llen, FAIL); return 1; } - pad_spc(llen, 64, " [OK]\n"); + result(llen, OK); return 0; } } From patchwork Tue Jul 11 09:48:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13308375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BC40EB64DD for ; Tue, 11 Jul 2023 09:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231825AbjGKJtt (ORCPT ); Tue, 11 Jul 2023 05:49:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231553AbjGKJti (ORCPT ); Tue, 11 Jul 2023 05:49:38 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72294A8; Tue, 11 Jul 2023 02:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1689068974; bh=03IWGhZ8QhtZRHbntN3H9nx1jWn0im7jMDrqpZcDC9E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=enZLzOOfdJZURIRYExyX4nKPwq7ZrcP6Uu30k8Z8FBnN5DX90an+CEoQpTtgBZ59C Iep6Ze5HZeB6caPqlPsg3BMNkMgxLiIqkF9u0h5BKomFfMvd91AUwIv0EjoSrvJWme SwemeWFdHQs/HFFbzwJHtGxZIypoDgJlcYSexLZo= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 11 Jul 2023 11:48:41 +0200 Subject: [PATCH 3/4] selftests/nolibc: simplify status argument MIME-Version: 1.0 Message-Id: <20230711-nolibc-sizeof-long-gaps-v1-3-dc78c3b85fc3@weissschuh.net> References: <20230711-nolibc-sizeof-long-gaps-v1-0-dc78c3b85fc3@weissschuh.net> In-Reply-To: <20230711-nolibc-sizeof-long-gaps-v1-0-dc78c3b85fc3@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zhangjin Wu , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1689068953; l=8351; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=03IWGhZ8QhtZRHbntN3H9nx1jWn0im7jMDrqpZcDC9E=; b=GDj2A6NCENuF5duP+jAGRG273sGNnZpRTvbg/ryTcxFqm04Xf1W6x1W3XHtf6GRUuicM5bhWG a9hhDUb2lShA0D4j1P1LaZGu6iLgm3Gp4f/B6EF7zDxSoDNUi0UX71I X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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; } } From patchwork Tue Jul 11 09:48:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13308377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 628F6EB64DD for ; Tue, 11 Jul 2023 09:49:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231588AbjGKJtu (ORCPT ); Tue, 11 Jul 2023 05:49:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231754AbjGKJtk (ORCPT ); Tue, 11 Jul 2023 05:49:40 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6944FBE; Tue, 11 Jul 2023 02:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1689068974; bh=83SeGYY069UVxi94jP42yD5YlEmP07oKsxDCaS0DfLI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TNM11yR3/EprBB8Zbx+0ReDPGkWTXEKW/tR6mFLRKWeS0yDsvVYAvKCvNEj22jmXr QiruHvFuP7v+Ul65XonvTuwOJZUx2xPR5HXMQba2CRi1TDBarqS/7JYXYhXhiHjTia Yw9+hHwo52a1ZdtdUwY6lPhwCKBGcvweP2NSDX7g= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 11 Jul 2023 11:48:42 +0200 Subject: [PATCH 4/4] selftests/nolibc: avoid gaps in test numbers MIME-Version: 1.0 Message-Id: <20230711-nolibc-sizeof-long-gaps-v1-4-dc78c3b85fc3@weissschuh.net> References: <20230711-nolibc-sizeof-long-gaps-v1-0-dc78c3b85fc3@weissschuh.net> In-Reply-To: <20230711-nolibc-sizeof-long-gaps-v1-0-dc78c3b85fc3@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zhangjin Wu , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1689068953; l=4197; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=83SeGYY069UVxi94jP42yD5YlEmP07oKsxDCaS0DfLI=; b=8p8gHUPx37Id6K1WBhsyn1nlAsIFAof0sMQzd2/vZgcKJXeXQWUEwdPYT6QawzH40qigiipqz odYARoIC+dNAl6l63qU37l8GCLYsuDye8XNvqOWxRTy12Iuf6/MZ7pB X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org As the test numbers are based on line numbers gaps without testcases are to be avoided. Instead use the already existing test condition logic to implement conditional execution. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/nolibc/nolibc-test.c | 30 ++++++++++++---------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 754815c142f6..09660b362645 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -815,23 +815,19 @@ int run_stdlib(int min, int max) CASE_TEST(limit_int_fast64_min); EXPECT_EQ(1, INT_FAST64_MIN, (int_fast64_t) INT64_MIN); break; CASE_TEST(limit_int_fast64_max); EXPECT_EQ(1, INT_FAST64_MAX, (int_fast64_t) INT64_MAX); break; CASE_TEST(limit_uint_fast64_max); EXPECT_EQ(1, UINT_FAST64_MAX, (uint_fast64_t) UINT64_MAX); break; -#if __SIZEOF_LONG__ == 8 - CASE_TEST(limit_intptr_min); EXPECT_EQ(1, INTPTR_MIN, (intptr_t) 0x8000000000000000LL); break; - CASE_TEST(limit_intptr_max); EXPECT_EQ(1, INTPTR_MAX, (intptr_t) 0x7fffffffffffffffLL); break; - CASE_TEST(limit_uintptr_max); EXPECT_EQ(1, UINTPTR_MAX, (uintptr_t) 0xffffffffffffffffULL); break; - CASE_TEST(limit_ptrdiff_min); EXPECT_EQ(1, PTRDIFF_MIN, (ptrdiff_t) 0x8000000000000000LL); break; - CASE_TEST(limit_ptrdiff_max); EXPECT_EQ(1, PTRDIFF_MAX, (ptrdiff_t) 0x7fffffffffffffffLL); break; - CASE_TEST(limit_size_max); EXPECT_EQ(1, SIZE_MAX, (size_t) 0xffffffffffffffffULL); break; -#elif __SIZEOF_LONG__ == 4 - CASE_TEST(limit_intptr_min); EXPECT_EQ(1, INTPTR_MIN, (intptr_t) 0x80000000); break; - CASE_TEST(limit_intptr_max); EXPECT_EQ(1, INTPTR_MAX, (intptr_t) 0x7fffffff); break; - CASE_TEST(limit_uintptr_max); EXPECT_EQ(1, UINTPTR_MAX, (uintptr_t) 0xffffffffU); break; - CASE_TEST(limit_ptrdiff_min); EXPECT_EQ(1, PTRDIFF_MIN, (ptrdiff_t) 0x80000000); break; - CASE_TEST(limit_ptrdiff_max); EXPECT_EQ(1, PTRDIFF_MAX, (ptrdiff_t) 0x7fffffff); break; - CASE_TEST(limit_size_max); EXPECT_EQ(1, SIZE_MAX, (size_t) 0xffffffffU); break; -#else -# warning "__SIZEOF_LONG__ is undefined" -#endif /* __SIZEOF_LONG__ */ + CASE_TEST(sizeof_long_sane); EXPECT_EQ(1, sizeof(long) == 8 || sizeof(long) == 4, 1); break; + CASE_TEST(limit_intptr_min_64); EXPECT_EQ(sizeof(long) == 8, INTPTR_MIN, (intptr_t) 0x8000000000000000LL); break; + CASE_TEST(limit_intptr_max_64); EXPECT_EQ(sizeof(long) == 8, INTPTR_MAX, (intptr_t) 0x7fffffffffffffffLL); break; + CASE_TEST(limit_uintptr_max_64); EXPECT_EQ(sizeof(long) == 8, UINTPTR_MAX, (uintptr_t) 0xffffffffffffffffULL); break; + CASE_TEST(limit_ptrdiff_min_64); EXPECT_EQ(sizeof(long) == 8, PTRDIFF_MIN, (ptrdiff_t) 0x8000000000000000LL); break; + CASE_TEST(limit_ptrdiff_max_64); EXPECT_EQ(sizeof(long) == 8, PTRDIFF_MAX, (ptrdiff_t) 0x7fffffffffffffffLL); break; + CASE_TEST(limit_size_max_64); EXPECT_EQ(sizeof(long) == 8, SIZE_MAX, (size_t) 0xffffffffffffffffULL); break; + CASE_TEST(limit_intptr_min_32); EXPECT_EQ(sizeof(long) == 4, INTPTR_MIN, (intptr_t) 0x80000000); break; + CASE_TEST(limit_intptr_max_32); EXPECT_EQ(sizeof(long) == 4, INTPTR_MAX, (intptr_t) 0x7fffffff); break; + CASE_TEST(limit_uintptr_max_32); EXPECT_EQ(sizeof(long) == 4, UINTPTR_MAX, (uintptr_t) 0xffffffffU); break; + CASE_TEST(limit_ptrdiff_min_32); EXPECT_EQ(sizeof(long) == 4, PTRDIFF_MIN, (ptrdiff_t) 0x80000000); break; + CASE_TEST(limit_ptrdiff_max_32); EXPECT_EQ(sizeof(long) == 4, PTRDIFF_MAX, (ptrdiff_t) 0x7fffffff); break; + CASE_TEST(limit_size_max_32); EXPECT_EQ(sizeof(long) == 4, SIZE_MAX, (size_t) 0xffffffffU); break; case __LINE__: return ret; /* must be last */ /* note: do not set any defaults so as to permit holes above */