Skip to content

Commit ab7e39a

Browse files
committed
test: Cope with GDB simulator limitations
When running the simulator, rounding modes and exceptions aren't handled. In addition, it "emulates" fma with a*b+c. Signed-off-by: Keith Packard <[email protected]>
1 parent ae1aaf1 commit ab7e39a

File tree

6 files changed

+61
-7
lines changed

6 files changed

+61
-7
lines changed

newlib/libm/test/test.c

+6
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ test_mfok (float value,
425425
/* RX doesn't support nan or inf at all */
426426
if (isnan(shouldbe) || isinf(shouldbe))
427427
mag = 32;
428+
#endif
429+
#ifdef __sh__
430+
/* SuperH has a different canonical representation for nans */
431+
if (!!isnan(shouldbe) == !!isnan(value) &&
432+
!!__issignalingf(shouldbe) == !!__issignalingf(value))
433+
mag = 32;
428434
#endif
429435
a.value = shouldbe;
430436
b.value = value;

test/fenv.c

+10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
#define HAVE_HW_DOUBLE
4545
#endif
4646

47+
#ifdef __sh__
48+
#if !(defined(__SH4__) || defined(__SH4_SINGLE__) || defined(__SH4_SINGLE_ONLY__))
49+
#define GDB_SIMULATOR
50+
#endif
51+
#endif
52+
4753
#ifdef HAVE_HW_DOUBLE
4854
typedef double test_t;
4955
#define test_sqrt(x) sqrt(x)
@@ -206,6 +212,10 @@ int main(void)
206212
int ret;
207213
unsigned i;
208214

215+
#ifdef GDB_SIMULATOR
216+
printf("GDB simulator doesn't support fenv. Skipping\n");
217+
return 77;
218+
#endif
209219
(void) report;
210220
(void) e_to_str;
211221
if (math_errhandling & MATH_ERREXCEPT) {

test/math_errhandling.c

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
#define ALWAYS_INLINE __inline
5050
#endif
5151

52+
#ifdef __sh__
53+
#if !(defined(__SH4__) || defined(__SH4_SINGLE__) || defined(__SH4_SINGLE_ONLY__))
54+
#define GDB_SIMULATOR
55+
#endif
56+
#endif
57+
5258
static ALWAYS_INLINE float
5359
opt_barrier_float (float x)
5460
{

test/math_errhandling_tests.c

+19-7
Original file line numberDiff line numberDiff line change
@@ -1527,8 +1527,13 @@ makemathname(is_equal)(FLOAT_T a, FLOAT_T b)
15271527
{
15281528
if (isinf(a) && isinf(b))
15291529
return (a > 0) == (b > 0);
1530-
if (makemathname(isnan)(a) && makemathname(isnan)(b))
1530+
if (makemathname(isnan)(a) && makemathname(isnan)(b)) {
1531+
#ifdef GDB_SIMULATOR
1532+
return 1;
1533+
#else
15311534
return issignaling(a) == issignaling(b);
1535+
#endif
1536+
}
15321537
return a == b;
15331538
}
15341539

@@ -1652,6 +1657,12 @@ static bool makemathname(check_except)(void)
16521657
return result;
16531658
}
16541659

1660+
#ifdef GDB_SIMULATOR
1661+
#define record_exception_error() printf("\tignoring exception error on GDB simulator\n")
1662+
#else
1663+
#define record_exception_error() result++
1664+
#endif
1665+
16551666
static int
16561667
makemathname(run_tests)(void) {
16571668
int result = 0;
@@ -1661,8 +1672,9 @@ makemathname(run_tests)(void) {
16611672
int t;
16621673
int printed;
16631674

1664-
if (!makemathname(check_except)())
1665-
result++;
1675+
if (!makemathname(check_except)()) {
1676+
record_exception_error();
1677+
}
16661678

16671679
for (t = 0; makemathname(tests)[t].func; t++) {
16681680
printed = 0;
@@ -1695,7 +1707,7 @@ makemathname(run_tests)(void) {
16951707
PRINT;
16961708
printf("\texceptions supported. %s returns %s instead of %s\n",
16971709
makemathname(tests)[t].name, e_to_str(except), e_to_str(makemathname(tests)[t].except));
1698-
++result;
1710+
record_exception_error();
16991711
}
17001712
} else {
17011713
if (except) {
@@ -1706,7 +1718,7 @@ makemathname(run_tests)(void) {
17061718
{
17071719
PRINT;
17081720
printf("\texceptions not supported. %s returns %s\n", makemathname(tests)[t].name, e_to_str(except));
1709-
++result;
1721+
record_exception_error();
17101722
}
17111723
}
17121724
}
@@ -1755,13 +1767,13 @@ makemathname(run_tests)(void) {
17551767
IPRINT;
17561768
printf("\texceptions supported. %s returns %s instead of %s\n",
17571769
makemathname(itests)[t].name, e_to_str(except), e_to_str(makemathname(itests)[t].except));
1758-
++result;
1770+
record_exception_error();
17591771
}
17601772
} else {
17611773
if (except) {
17621774
IPRINT;
17631775
printf("\texceptions not supported. %s returns %s\n", makemathname(itests)[t].name, e_to_str(except));
1764-
++result;
1776+
record_exception_error();
17651777
}
17661778
}
17671779
if (math_errhandling & MATH_ERRNO) {

test/rounding-mode.c

+10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
#include <fenv.h>
3939
#include "rounding-mode.h"
4040

41+
#ifdef __sh__
42+
#if !(defined(__SH4__) || defined(__SH4_SINGLE__) || defined(__SH4_SINGLE_ONLY__))
43+
#define GDB_SIMULATOR
44+
#endif
45+
#endif
46+
4147
#ifndef PICOLIBC_DOUBLE_NOROUND
4248
static double
4349
do_round_int(double value, int mode)
@@ -229,6 +235,10 @@ int main(void)
229235
unsigned i;
230236
int ret = 0;
231237

238+
#ifdef GDB_SIMULATOR
239+
printf("GDB simulator doesn't support rounding modes. Skipping\n");
240+
return 77;
241+
#endif
232242
for (i = 0; i < NUM_VALUE; i++) {
233243
#ifdef FE_TONEAREST
234244
ret += check(FE_TONEAREST, "FE_TONEAREST", my_values[i]);

test/test-fma.c

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
#include <stdbool.h>
4242
#include <fenv.h>
4343

44+
#ifdef __sh__
45+
#if !(defined(__SH4__) || defined(__SH4_SINGLE__) || defined(__SH4_SINGLE_ONLY__))
46+
#define GDB_SIMULATOR
47+
#endif
48+
#endif
49+
4450
#if FLT_MANT_DIG == 24
4551

4652
static int roundings[] = {
@@ -336,6 +342,10 @@ main(void)
336342
printf("ARC soft float bug, skipping FMA tests\n");
337343
return 77;
338344
}
345+
#endif
346+
#ifdef GDB_SIMULATOR
347+
printf("GDB simulator doesn't support FMA. Skipping\n");
348+
return 77;
339349
#endif
340350
(void) rounding_names;
341351
(void) roundings;

0 commit comments

Comments
 (0)