Skip to content

Commit 7889013

Browse files
committed
test: Handle 32-bit double/64-bit long double configurations
Use 32-bit appropriate values where possible, otherwise skip tests that assume doubles are 64-bits. Signed-off-by: Keith Packard <[email protected]>
1 parent 53ec062 commit 7889013

File tree

10 files changed

+67
-9
lines changed

10 files changed

+67
-9
lines changed

test/libc-testsuite/snprintf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ int test_snprintf(void)
178178
TEST_S(b, "123", "incorrect output");
179179
TEST(i, b[5], 'x', "buffer overrun");
180180

181+
#if __SIZEOF_DOUBLE__ == 8
181182
#if defined(TINY_STDIO) || (!defined(NO_FLOATING_POINT) && (!defined(_WANT_IO_LONG_DOUBLE) || defined(_LDBL_EQ_DBL)))
182183
/* Perform ascii arithmetic to test printing tiny doubles */
183184
TEST(i, snprintf(b, sizeof b, "%.1022f", 0x1p-1021), 1024, "%d != %d");
@@ -193,6 +194,7 @@ int test_snprintf(void)
193194
// for (j=2; b[j]=='0'; j++);
194195
// TEST(i, j, 1024, "%d != %d");
195196
#endif
197+
#endif
196198

197199

198200
#ifndef DISABLE_SLOW_TESTS
@@ -209,7 +211,7 @@ int test_snprintf(void)
209211

210212
(void) fp_tests;
211213
(void) k;
212-
#if !defined(NO_FLOATING_POINT) && defined(_IO_FLOAT_EXACT)
214+
#if !defined(NO_FLOATING_POINT) && defined(_IO_FLOAT_EXACT) && __SIZEOF_DOUBLE__ == 8
213215
for (j=0; fp_tests[j].fmt; j++) {
214216
TEST(i, snprintf(b, sizeof b, fp_tests[j].fmt, fp_tests[j].f), (int) strlen(b), "%d != %d");
215217
TEST_S(b, fp_tests[j].expect, "bad floating point conversion");

test/libc-testsuite/sscanf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ TEST(t, d, (double)x, "%g != %g") )
4444
#pragma GCC diagnostic ignored "-Wliteral-range"
4545
#pragma GCC diagnostic ignored "-Wformat-extra-args"
4646

47+
#if defined(__PICOLIBC__) && !defined(TINY_STDIO) && __SIZEOF_DOUBLE__ != 8
48+
#define NO_FLOATING_POINT
49+
#endif
50+
4751
int test_sscanf(void)
4852
{
4953
int i;

test/libc-testsuite/strtod.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ int test_strtod(void)
5959
TEST(d2, strtod(buf, 0), d, "round trip fail %a != %a (%a)");
6060
}
6161

62+
#if defined(__PICOLIBC__) && !defined(TINY_STDIO) && __SIZEOF_DOUBLE__ != 8
63+
/* skip strtod tests for legacy stdio on systems with atypical doubles */
64+
#else
6265
TEST(d, strtod("0x1p4", 0), 16.0, "hex float %a != %a");
6366
TEST(d, strtod("0x1.1p4", 0), 17.0, "hex float %a != %a");
67+
#endif
6468

6569
return err;
6670
}

test/long_double.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ typedef const struct {
190190
#undef TEST_IO_LONG_DOUBLE
191191
#endif
192192

193+
#if defined(__PICOLIBC__) && !defined(TINY_STDIO) && __LDBL_MANT_DIG__ != 64
194+
#undef TEST_IO_LONG_DOUBLE
195+
#endif
196+
193197
#ifdef TEST_IO_LONG_DOUBLE
194198
static long double vals[] = {
195199
1.0L,

test/math_errhandling.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ e_to_str(int e)
219219
#define BIGODD 0x1.123456789abcdef2p+63l
220220
#define BIGEVEN 0x1.123456789abcdef0p+63l
221221
#else
222-
#define BIGODD 0x1.123456789abcdp+52
223-
#define BIGEVEN 0x1.123456789abccp+52
222+
#define BIGODD 0x1.123456789abcdp+52l
223+
#define BIGEVEN 0x1.123456789abccp+52l
224224
#endif
225225
#define SMALL __LDBL_DENORM_MIN__
226226
#define FLOAT_T long double
@@ -266,10 +266,17 @@ e_to_str(int e)
266266
#endif
267267
#define DOUBLE_EXCEPTION_TEST EXCEPTION_TEST
268268

269+
#if __SIZEOF_DOUBLE__ == 4
270+
#define BIG 3e38
271+
#define BIGODD 0x1.123456p+23
272+
#define BIGEVEN 0x1.123454p+23
273+
#define SMALL 1e-45
274+
#else
269275
#define BIG 1.7e308
270276
#define BIGODD 0x1.123456789abcdp+52
271277
#define BIGEVEN 0x1.123456789abccp+52
272278
#define SMALL 5e-324
279+
#endif
273280
#define FLOAT_T double
274281
#define MIN_VAL __DBL_DENORM_MIN__
275282
#define MAX_VAL __DBL_MAX__

test/printf_scanf.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,11 @@ main(void)
351351
#define float_type double
352352
#define scanf_format "%lf"
353353
#if defined(TINY_STDIO) && !defined(_IO_FLOAT_EXACT)
354-
#define ERROR_MAX 1e-14
354+
# if __SIZEOF_DOUBLE__ == 4
355+
# define ERROR_MAX 1e-6
356+
# else
357+
# define ERROR_MAX 1e-14
358+
# endif
355359
#else
356360
#if (!defined(TINY_STDIO) && defined(_WANT_IO_LONG_DOUBLE))
357361
/* __ldtoa is really broken */

test/test-efcvt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ const struct test fcvt_tests[] = {
105105

106106
const struct test fcvt_extra_tests[] = {
107107
#ifdef TINY_STDIO
108+
#if __SIZEOF_DOUBLE__ == 4
109+
{ 0x1.fffffep127, 9, 39, 0, "340282350000000000000000000000000000000000000000" },
110+
#else
108111
{ 0x1.fffffffffffffp1023, 17, 309, 0, "17976931348623157"
109112
"0000000000000000000000000000000000000000"
110113
"0000000000000000000000000000000000000000"
@@ -116,6 +119,7 @@ const struct test fcvt_extra_tests[] = {
116119
"000000000000"
117120
"00000000000000000"},
118121
{ 0x1.fffffep127, 9, 39, 0, "340282346638528860000000000000000000000000000000" },
122+
#endif
119123
#else
120124
{ 0x1.fffffffffffffp1023, 17, 309, 0, "17976931348623157"
121125
"0814527423731704356798070567525844996598"

test/test-fma.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ static int roundings[] = {
6060
#endif
6161
};
6262

63+
static int rounding_map[] = {
64+
#ifdef FE_TONEAREST
65+
0,
66+
#endif
67+
#ifdef FE_UPWARD
68+
1,
69+
#endif
70+
#ifdef FE_DOWNWARD
71+
2,
72+
#endif
73+
#ifdef FE_TOWARDZERO
74+
3,
75+
#endif
76+
};
77+
6378
static const char *rounding_names[] = {
6479
#ifdef FE_TONEAREST
6580
"FE_TONEAREST",
@@ -163,7 +178,7 @@ test_fmaf(void)
163178
float y = fmaf_vec[t].y;
164179
float z = fmaf_vec[t].z;
165180
volatile float r = fmaf(x, y, z);
166-
float s = fmaf_vec[t].r[ro];
181+
float s = fmaf_vec[t].r[rounding_map[ro]];
167182
if (!equalf(r, s)) {
168183
strfromf(xs, sizeof(xs), "%a", x);
169184
strfromf(ys, sizeof(xs), "%a", y);
@@ -227,7 +242,7 @@ test_fma(void)
227242
double y = fma_vec[t].y;
228243
double z = fma_vec[t].z;
229244
volatile double r = fma(x, y, z);
230-
double s = fma_vec[t].r[ro];
245+
double s = fma_vec[t].r[rounding_map[ro]];
231246
if (!equal(r, s)) {
232247
printf("%u: round %s %a * %a + %a -> got %a want %a\n",
233248
t, rounding_names[ro],
@@ -288,7 +303,7 @@ test_fmal(void)
288303
long double y = fmal_vec[t].y;
289304
long double z = fmal_vec[t].z;
290305
long double r = fmal(x, y, z);
291-
long double s = fmal_vec[t].r[ro];
306+
long double s = fmal_vec[t].r[rounding_map[ro]];
292307
if (!equall(r, s)) {
293308
printf("%u: round %s %La * %La + %La -> got %La want %La\n",
294309
t, rounding_names[ro],

test/test-strtod.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ static const struct {
5858
{ "0x1.000002p0@", 0x1.000002p0, 0x1.000002p0f, 0x1.000002p0l },
5959
{ "0x1.000003p0@", 0x1.000003p0, 0x1.000004p0f, 0x1.000003p0l },
6060
{ "0x1.000001p0@", 0x1.000001p0, 0x1.000000p0f, 0x1.000001p0l },
61-
{ "0x1.000001000000001p0@", 0x1.000001p0, 0x1.000002p0f, 0x1.000001000000001p0l },
61+
{ "0x1.000001000000001p0@", 0x1.000001000000001p0, 0x1.000002p0f, 0x1.000001000000001p0l },
62+
#if __SIZEOF_DOUBLE__ == 8
6263
/* Check round-to-even for doubles */
6364
{ "0x100000000000008p0@", 0x1p56, 0x1p56f, 0x1.00000000000008p56l },
6465
{ "0x100000000000008.p0@", 0x1p56, 0x1p56f, 0x1.00000000000008p56l },
@@ -67,16 +68,19 @@ static const struct {
6768
{ "0x10000000000000801p0@", 0x1.0000000000001p64, 0x1p64f, 0x1.0000000000000801p64l },
6869
{ "0x10000000000000800.0000000000001p0@", 0x1.0000000000001p64, 0x1p64f, 0x1.00000000000008p64l },
6970
{ "0x10000000000001800p0@", 0x1.0000000000002p64, 0x1p64f, 0x1.00000000000018p64l },
71+
#endif
7072
/* Check max values for floats */
7173
{ "0x1.fffffep126@", 0x1.fffffep126, 0x1.fffffep126f, 0x1.fffffep126l },
7274
{ "0x1.ffffffp126@", 0x1.ffffffp126, 0x1.000000p127f, 0x1.ffffffp126l },
7375
{ "0x1.fffffep127@", 0x1.fffffep127, 0x1.fffffep127f, 0x1.fffffep127l },
7476
{ "0x1.ffffffp127@", 0x1.ffffffp127, (float) INFINITY, 0x1.ffffffp127l }, /* rounds up to INFINITY for float */
77+
#if __SIZEOF_DOUBLE__ == 8
7578
/* Check max values for doubles */
7679
{ "0x1.fffffffffffffp1022@", 0x1.fffffffffffffp1022, (float) INFINITY, 0x1.fffffffffffffp1022l },
7780
{ "0x1.fffffffffffff8p1022@", 0x1.0000000000000p1023, (float) INFINITY, 0x1.fffffffffffff8p1022l }, /* rounds up for double */
7881
{ "0x1.fffffffffffffp1023@", 0x1.fffffffffffffp1023, (float) INFINITY, 0x1.fffffffffffffp1023l },
79-
#ifdef _TEST_LONG_DOUBLE
82+
#endif
83+
#if defined(_TEST_LONG_DOUBLE) && __SIZEOF_LONG_DOUBLE__ > 8
8084
#if __LDBL_MANT_DIG__ > __DBL_MANT_DIG__
8185
{ "0x1.fffffffffffff8p1023@", (double) INFINITY, (float) INFINITY, 0x1.fffffffffffff8p1023l }, /* rounds up to INFINITY for double */
8286
#else

test/testcases.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
# define BINARY_FORMAT
2727
# endif
2828
# ifdef _HAS_IO_DOUBLE
29+
# if __SIZEOF_DOUBLE__ == 4
30+
# define LOW_FLOAT
31+
# endif
2932
# elif defined(_HAS_IO_FLOAT)
3033
# define LOW_FLOAT
3134
# else
@@ -42,6 +45,9 @@
4245
# define NO_CASE_HEX
4346
# endif
4447
#else
48+
# if __SIZEOF_DOUBLE__ == 4
49+
# define LOW_FLOAT
50+
# endif
4551
# ifdef NO_FLOATING_POINT
4652
# define NO_FLOAT
4753
# endif
@@ -685,7 +691,11 @@
685691
result |= test(__LINE__, "INF", "%A", (double) INFINITY);
686692
result |= test(__LINE__, "-INF", "%A", (double) -INFINITY);
687693
#ifdef LOW_FLOAT
694+
#ifdef NORMALIZED_A
695+
result |= test(__LINE__, "0x1p-149", "%a", 0x1p-149);
696+
#else
688697
result |= test(__LINE__, "0x0.000002p-126", "%a", 0x1p-149);
698+
#endif
689699
#else
690700
#ifdef NORMALIZED_A
691701
/* newlib legacy stdio normalizes %a format */

0 commit comments

Comments
 (0)