stdlib: merge some tests from gnulib

This makes the tests the same in both places. The changes in Gnulib
brought in by this patch also silence -Woverflow when using gcc 16.1.1
on i686.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
Collin Funk
2026-08-28 19:08:05 -07:00
parent 0e30e9ce27
commit 6a46a9b6ec
3 changed files with 63 additions and 18 deletions
+1
View File
@@ -113,6 +113,7 @@ gnulib:
stdlib/setenv.c stdlib/setenv.c
stdlib/strtoll.c stdlib/strtoll.c
stdlib/strtoul.c stdlib/strtoul.c
# Merged from gnulib 2026-08-27, (gnulib commit ec224ee81b)
stdlib/tst-stdc_rotate_left.c stdlib/tst-stdc_rotate_left.c
stdlib/tst-stdc_rotate_right.c stdlib/tst-stdc_rotate_right.c
# Merged from gnulib 2014-6-26, needs merge back # Merged from gnulib 2014-6-26, needs merge back
+31 -9
View File
@@ -15,8 +15,27 @@
License along with the GNU C Library; if not, see License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */ <https://www.gnu.org/licenses/>. */
#ifdef GNULIB_TEST_STDBIT
# include <config.h>
#endif
/* Specification. */
#include <stdbit.h> #include <stdbit.h>
#include <support/check.h>
#include <limits.h>
#ifdef GNULIB_TEST_STDBIT
# include "macros.h"
# define MAIN_STATIC
# define MAIN main
# define TEST_COMPARE(a, b) ASSERT ((a) == (b))
# define TEST_EXIT_STATUS test_exit_status
#else
# include <support/check.h>
# define MAIN_STATIC static
# define MAIN do_test
# define TEST_EXIT_STATUS 0
#endif
#define TEST_CASE(type, function, value, shift, expect) \ #define TEST_CASE(type, function, value, shift, expect) \
do \ do \
@@ -431,10 +450,11 @@ test_stdc_rotate_left_ui (void)
static void static void
test_stdc_rotate_left_ul (void) test_stdc_rotate_left_ul (void)
{ {
if (sizeof 0ul < sizeof 0ull) #if ULONG_MAX >> 31 == 1
TEST_CASES_32 (unsigned long int, stdc_rotate_left_ul); TEST_CASES_32 (unsigned long int, stdc_rotate_left_ul);
else #else
TEST_CASES_64 (unsigned long long int, stdc_rotate_left_ul); TEST_CASES_64 (unsigned long int, stdc_rotate_left_ul);
#endif
} }
static void static void
@@ -443,15 +463,17 @@ test_stdc_rotate_left_ull (void)
TEST_CASES_64 (unsigned long long int, stdc_rotate_left_ull); TEST_CASES_64 (unsigned long long int, stdc_rotate_left_ull);
} }
static int MAIN_STATIC int
do_test (void) MAIN (void)
{ {
test_stdc_rotate_left_uc (); test_stdc_rotate_left_uc ();
test_stdc_rotate_left_us (); test_stdc_rotate_left_us ();
test_stdc_rotate_left_ui (); test_stdc_rotate_left_ui ();
test_stdc_rotate_left_ul (); test_stdc_rotate_left_ul ();
test_stdc_rotate_left_ull (); test_stdc_rotate_left_ull ();
return 0; return TEST_EXIT_STATUS;
} }
#include <support/test-driver.c> #ifndef GNULIB_TEST_STDBIT
# include <support/test-driver.c>
#endif
+31 -9
View File
@@ -15,8 +15,27 @@
License along with the GNU C Library; if not, see License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */ <https://www.gnu.org/licenses/>. */
#ifdef GNULIB_TEST_STDBIT
# include <config.h>
#endif
/* Specification. */
#include <stdbit.h> #include <stdbit.h>
#include <support/check.h>
#include <limits.h>
#ifdef GNULIB_TEST_STDBIT
# include "macros.h"
# define MAIN_STATIC
# define MAIN main
# define TEST_COMPARE(a, b) ASSERT ((a) == (b))
# define TEST_EXIT_STATUS test_exit_status
#else
# include <support/check.h>
# define MAIN_STATIC static
# define MAIN do_test
# define TEST_EXIT_STATUS 0
#endif
#define TEST_CASE(type, function, value, shift, expect) \ #define TEST_CASE(type, function, value, shift, expect) \
do \ do \
@@ -431,10 +450,11 @@ test_stdc_rotate_right_ui (void)
static void static void
test_stdc_rotate_right_ul (void) test_stdc_rotate_right_ul (void)
{ {
if (sizeof 0ul < sizeof 0ull) #if ULONG_MAX >> 31 == 1
TEST_CASES_32 (unsigned long int, stdc_rotate_right_ul); TEST_CASES_32 (unsigned long int, stdc_rotate_right_ul);
else #else
TEST_CASES_64 (unsigned long long int, stdc_rotate_right_ul); TEST_CASES_64 (unsigned long int, stdc_rotate_right_ul);
#endif
} }
static void static void
@@ -443,15 +463,17 @@ test_stdc_rotate_right_ull (void)
TEST_CASES_64 (unsigned long long int, stdc_rotate_right_ull); TEST_CASES_64 (unsigned long long int, stdc_rotate_right_ull);
} }
static int MAIN_STATIC int
do_test (void) MAIN (void)
{ {
test_stdc_rotate_right_uc (); test_stdc_rotate_right_uc ();
test_stdc_rotate_right_us (); test_stdc_rotate_right_us ();
test_stdc_rotate_right_ui (); test_stdc_rotate_right_ui ();
test_stdc_rotate_right_ul (); test_stdc_rotate_right_ul ();
test_stdc_rotate_right_ull (); test_stdc_rotate_right_ull ();
return 0; return TEST_EXIT_STATUS;
} }
#include <support/test-driver.c> #ifndef GNULIB_TEST_STDBIT
# include <support/test-driver.c>
#endif