Skip to content

Commit

Permalink
selftests/nolibc: avoid warnings during intptr tests
Browse files Browse the repository at this point in the history
Recent fix ceb528f ("selftests/nolibc: avoid gaps in test numbers")
had the annoying side effect of always returning skipped tests, which
are normally supposed to happen only when certain features are missing
to run the test (missing kernel options, toolchain not supporting
stack-protector etc). As such there are now always warnings. Let's
modify the test to not use the condition and instead use a ternary
expression to check the result.

Fixes: ceb528f ("selftests/nolibc: avoid gaps in test numbers")
Cc: Thomas WeiÃ<9F>schuh <[email protected]>
Signed-off-by: Willy Tarreau <[email protected]>
  • Loading branch information
wtarreau committed Aug 23, 2023
1 parent 202a0bd commit ca28345
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions tools/testing/selftests/nolibc/nolibc-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,18 +976,13 @@ int run_stdlib(int min, int max)
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;
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_TEST(limit_intptr_min); EXPECT_EQ(1, INTPTR_MIN, sizeof(long) == 8 ? (intptr_t) 0x8000000000000000LL : (intptr_t) 0x80000000); break;
CASE_TEST(limit_intptr_max); EXPECT_EQ(1, INTPTR_MAX, sizeof(long) == 8 ? (intptr_t) 0x7fffffffffffffffLL : (intptr_t) 0x7fffffff); break;
CASE_TEST(limit_uintptr_max); EXPECT_EQ(1, UINTPTR_MAX, sizeof(long) == 8 ? (uintptr_t) 0xffffffffffffffffULL : (uintptr_t) 0xffffffffU); break;
CASE_TEST(limit_ptrdiff_min); EXPECT_EQ(1, PTRDIFF_MIN, sizeof(long) == 8 ? (ptrdiff_t) 0x8000000000000000LL : (ptrdiff_t) 0x80000000); break;
CASE_TEST(limit_ptrdiff_max); EXPECT_EQ(1, PTRDIFF_MAX, sizeof(long) == 8 ? (ptrdiff_t) 0x7fffffffffffffffLL : (ptrdiff_t) 0x7fffffff); break;
CASE_TEST(limit_size_max); EXPECT_EQ(1, SIZE_MAX, sizeof(long) == 8 ? (size_t) 0xffffffffffffffffULL : (size_t) 0xffffffffU); break;

case __LINE__:
return ret; /* must be last */
/* note: do not set any defaults so as to permit holes above */
Expand Down

0 comments on commit ca28345

Please sign in to comment.