All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhangjin Wu <falcon@tinylab.org>
To: thomas@t-8ch.de, w@1wt.eu
Cc: arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	"Thomas Weißschuh" <linux@weissschuh.net>
Subject: [PATCH v3 04/14] selftests/nolibc: fix up int_fast16/32_t test cases for musl
Date: Fri, 30 Jun 2023 22:46:07 +0800	[thread overview]
Message-ID: <8b47bb0d7ff4c24d99e8e3c9e03f747664d3465a.1688134400.git.falcon@tinylab.org> (raw)
In-Reply-To: <cover.1688134399.git.falcon@tinylab.org>

musl limits the fast signed int in 32bit, but glibc and nolibc don't, to
let such test cases work on musl, let's provide the type based
SINT_MAX_OF_TYPE(type) and SINT_MIN_OF_TYPE(type).

Suggested-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/lkml/bc635c4f-67fe-4e86-bfdf-bcb4879b928d@t-8ch.de/
Reviewed-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index d9644244fc95..290b43c7dc72 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -41,6 +41,10 @@
 #endif
 #endif
 
+/* for the type of int_fast16_t and int_fast32_t, musl differs from glibc and nolibc */
+#define SINT_MAX_OF_TYPE(type) (((type)1 << (sizeof(type) * 8 - 2)) - (type)1 + ((type)1 << (sizeof(type) * 8 - 2)))
+#define SINT_MIN_OF_TYPE(type) (-SINT_MAX_OF_TYPE(type) - 1)
+
 /* will be used by nolibc by getenv() */
 char **environ;
 
@@ -818,11 +822,11 @@ int run_stdlib(int min, int max)
 		CASE_TEST(limit_int_fast8_max);     EXPECT_EQ(1, INT_FAST8_MAX,    (int_fast8_t)     0x7f); break;
 		CASE_TEST(limit_int_fast8_min);     EXPECT_EQ(1, INT_FAST8_MIN,    (int_fast8_t)     0x80); break;
 		CASE_TEST(limit_uint_fast8_max);    EXPECT_EQ(1, UINT_FAST8_MAX,   (uint_fast8_t)    0xff); break;
-		CASE_TEST(limit_int_fast16_min);    EXPECT_EQ(1, INT_FAST16_MIN,   (int_fast16_t)    INTPTR_MIN); break;
-		CASE_TEST(limit_int_fast16_max);    EXPECT_EQ(1, INT_FAST16_MAX,   (int_fast16_t)    INTPTR_MAX); break;
+		CASE_TEST(limit_int_fast16_min);    EXPECT_EQ(1, INT_FAST16_MIN,   (int_fast16_t)    SINT_MIN_OF_TYPE(int_fast16_t)); break;
+		CASE_TEST(limit_int_fast16_max);    EXPECT_EQ(1, INT_FAST16_MAX,   (int_fast16_t)    SINT_MAX_OF_TYPE(int_fast16_t)); break;
 		CASE_TEST(limit_uint_fast16_max);   EXPECT_EQ(1, UINT_FAST16_MAX,  (uint_fast16_t)   UINTPTR_MAX); break;
-		CASE_TEST(limit_int_fast32_min);    EXPECT_EQ(1, INT_FAST32_MIN,   (int_fast32_t)    INTPTR_MIN); break;
-		CASE_TEST(limit_int_fast32_max);    EXPECT_EQ(1, INT_FAST32_MAX,   (int_fast32_t)    INTPTR_MAX); break;
+		CASE_TEST(limit_int_fast32_min);    EXPECT_EQ(1, INT_FAST32_MIN,   (int_fast32_t)    SINT_MIN_OF_TYPE(int_fast32_t)); break;
+		CASE_TEST(limit_int_fast32_max);    EXPECT_EQ(1, INT_FAST32_MAX,   (int_fast32_t)    SINT_MAX_OF_TYPE(int_fast32_t)); break;
 		CASE_TEST(limit_uint_fast32_max);   EXPECT_EQ(1, UINT_FAST32_MAX,  (uint_fast32_t)   UINTPTR_MAX); break;
 		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;
-- 
2.25.1



  parent reply	other threads:[~2023-06-30 14:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-30 14:41 [PATCH v3 00/14] selftests/nolibc: allow run with minimal kernel config Zhangjin Wu
2023-06-30 14:42 ` [PATCH v3 01/14] selftests/nolibc: stat_fault: silence NULL argument warning with glibc Zhangjin Wu
2023-06-30 14:43 ` [PATCH v3 02/14] selftests/nolibc: gettid: restore for glibc and musl Zhangjin Wu
2023-06-30 14:44 ` [PATCH v3 03/14] selftests/nolibc: add _LARGEFILE64_SOURCE for musl Zhangjin Wu
2023-06-30 15:23   ` Arnd Bergmann
2023-06-30 18:01     ` Zhangjin Wu
2023-06-30 18:45       ` Arnd Bergmann
2023-06-30 14:46 ` Zhangjin Wu [this message]
2023-06-30 14:47 ` [PATCH v3 05/14] selftests/nolibc: fix up kernel parameters support Zhangjin Wu
2023-06-30 14:48 ` [PATCH v3 06/14] selftests/nolibc: stat_timestamps: remove procfs dependency Zhangjin Wu
2023-06-30 14:50 ` [PATCH v3 07/14] selftests/nolibc: chroot_exe: " Zhangjin Wu
2023-06-30 14:52 ` [PATCH v3 08/14] selftests/nolibc: link_cross: use /proc/self/cmdline Zhangjin Wu
2023-06-30 14:54 ` [PATCH v3 09/14] tools/nolibc: add rmdir() support Zhangjin Wu
2023-06-30 14:55 ` [PATCH v3 10/14] selftests/nolibc: add a new rmdir() test case Zhangjin Wu
2023-06-30 14:56 ` [PATCH v3 11/14] selftests/nolibc: fix up failures when CONFIG_PROC_FS=n Zhangjin Wu
2023-06-30 14:58 ` [PATCH v3 12/14] selftests/nolibc: prepare /tmp for tmpfs or ramfs Zhangjin Wu
2023-06-30 14:59 ` [PATCH v3 13/14] selftests/nolibc: add chmod_tmpdir test Zhangjin Wu
2023-06-30 15:00 ` [PATCH v3 14/14] selftests/nolibc: vfprintf: remove MEMFD_CREATE dependency Zhangjin Wu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8b47bb0d7ff4c24d99e8e3c9e03f747664d3465a.1688134400.git.falcon@tinylab.org \
    --to=falcon@tinylab.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=thomas@t-8ch.de \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.