Convert TEST_f_b tests from code to data.

This commit is contained in:
Joseph Myers 2013-05-15 12:04:07 +00:00
parent cbe8c4d333
commit 7abeee129e
2 changed files with 135 additions and 67 deletions

View File

@ -1,5 +1,23 @@
2013-05-15 Joseph Myers <joseph@codesourcery.com> 2013-05-15 Joseph Myers <joseph@codesourcery.com>
* math/libm-test.inc (struct test_f_i_data): Add comment.
(RUN_TEST_LOOP_f_b): New macro.
(RUN_TEST_LOOP_f_b_tg): Likewise.
(finite_test_data): New variable.
(finite_test): Run tests with RUN_TEST_LOOP_f_b.
(isfinite_test_data): New variable.
(isfinite_test): Run tests with RUN_TEST_LOOP_f_b_tg.
(isinf_test_data): New variable.
(isinf_test): Run tests with RUN_TEST_LOOP_f_b_tg.
(isnan_test_data): New variable.
(isnan_test): Run tests with RUN_TEST_LOOP_f_b_tg.
(isnormal_test_data): New variable.
(isnormal_test): Run tests with RUN_TEST_LOOP_f_b_tg.
(issignaling_test_data): New variable.
(issignaling_test): Run tests with RUN_TEST_LOOP_f_b_tg.
(signbit_test_data): New variable.
(signbit_test): Run tests with RUN_TEST_LOOP_f_b_tg.
* math/libm-test.inc (acos_test_data): Use ERRNO_EDOM together * math/libm-test.inc (acos_test_data): Use ERRNO_EDOM together
with INVALID_EXCEPTION. with INVALID_EXCEPTION.
(acosh_test_data): Likewise. (acosh_test_data): Likewise.

View File

@ -983,6 +983,8 @@ struct test_c_c_data
__complex__ FLOAT max_ulp; __complex__ FLOAT max_ulp;
int exceptions; int exceptions;
}; };
/* Used for all of RUN_TEST_LOOP_f_i, RUN_TEST_LOOP_f_i_tg,
RUN_TEST_LOOP_f_b and RUN_TEST_LOOP_f_b_tg. */
struct test_f_i_data struct test_f_i_data
{ {
const char *test_name; const char *test_name;
@ -1238,10 +1240,24 @@ struct test_ff_i_data
MAX_ULP, EXCEPTIONS) \ MAX_ULP, EXCEPTIONS) \
check_bool (TEST_NAME, FUNC (FUNC_NAME) (ARG), EXPECTED, \ check_bool (TEST_NAME, FUNC (FUNC_NAME) (ARG), EXPECTED, \
MAX_ULP, EXCEPTIONS) MAX_ULP, EXCEPTIONS)
#define RUN_TEST_LOOP_f_b(FUNC_NAME, ARRAY, ROUNDING_MODE) \
IF_ROUND_INIT_ ## ROUNDING_MODE \
for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
RUN_TEST_f_b ((ARRAY)[i].test_name, FUNC_NAME, (ARRAY)[i].arg, \
(ARRAY)[i].expected, (ARRAY)[i].max_ulp, \
(ARRAY)[i].exceptions); \
ROUND_RESTORE_ ## ROUNDING_MODE
#define RUN_TEST_f_b_tg(TEST_NAME, FUNC_NAME, ARG, EXPECTED, \ #define RUN_TEST_f_b_tg(TEST_NAME, FUNC_NAME, ARG, EXPECTED, \
MAX_ULP, EXCEPTIONS) \ MAX_ULP, EXCEPTIONS) \
check_bool (TEST_NAME, FUNC_NAME (ARG), EXPECTED, \ check_bool (TEST_NAME, FUNC_NAME (ARG), EXPECTED, \
MAX_ULP, EXCEPTIONS) MAX_ULP, EXCEPTIONS)
#define RUN_TEST_LOOP_f_b_tg(FUNC_NAME, ARRAY, ROUNDING_MODE) \
IF_ROUND_INIT_ ## ROUNDING_MODE \
for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \
RUN_TEST_f_b_tg ((ARRAY)[i].test_name, FUNC_NAME, (ARRAY)[i].arg, \
(ARRAY)[i].expected, (ARRAY)[i].max_ulp, \
(ARRAY)[i].exceptions); \
ROUND_RESTORE_ ## ROUNDING_MODE
#define RUN_TEST_f_l(TEST_NAME, FUNC_NAME, ARG, EXPECTED, \ #define RUN_TEST_f_l(TEST_NAME, FUNC_NAME, ARG, EXPECTED, \
MAX_ULP, EXCEPTIONS) \ MAX_ULP, EXCEPTIONS) \
check_long (TEST_NAME, FUNC (FUNC_NAME) (ARG), EXPECTED, \ check_long (TEST_NAME, FUNC (FUNC_NAME) (ARG), EXPECTED, \
@ -8396,19 +8412,24 @@ fdim_test (void)
} }
static const struct test_f_i_data finite_test_data[] =
{
START_DATA (finite),
TEST_f_b (finite, 0, 1),
TEST_f_b (finite, minus_zero, 1),
TEST_f_b (finite, 10, 1),
TEST_f_b (finite, min_subnorm_value, 1),
TEST_f_b (finite, plus_infty, 0),
TEST_f_b (finite, minus_infty, 0),
TEST_f_b (finite, qnan_value, 0),
END_DATA (finite)
};
static void static void
finite_test (void) finite_test (void)
{ {
START (finite); START (finite);
RUN_TEST_LOOP_f_b (finite, finite_test_data, );
TEST_f_b (finite, 0, 1);
TEST_f_b (finite, minus_zero, 1);
TEST_f_b (finite, 10, 1);
TEST_f_b (finite, min_subnorm_value, 1);
TEST_f_b (finite, plus_infty, 0);
TEST_f_b (finite, minus_infty, 0);
TEST_f_b (finite, qnan_value, 0);
END (finite); END (finite);
} }
@ -9780,19 +9801,24 @@ ilogb_test (void)
END (ilogb); END (ilogb);
} }
static const struct test_f_i_data isfinite_test_data[] =
{
START_DATA (isfinite),
TEST_f_b (isfinite, 0, 1),
TEST_f_b (isfinite, minus_zero, 1),
TEST_f_b (isfinite, 10, 1),
TEST_f_b (isfinite, min_subnorm_value, 1),
TEST_f_b (isfinite, plus_infty, 0),
TEST_f_b (isfinite, minus_infty, 0),
TEST_f_b (isfinite, qnan_value, 0),
END_DATA (isfinite)
};
static void static void
isfinite_test (void) isfinite_test (void)
{ {
START (isfinite); START (isfinite);
RUN_TEST_LOOP_f_b_tg (isfinite, isfinite_test_data, );
TEST_f_b (isfinite, 0, 1);
TEST_f_b (isfinite, minus_zero, 1);
TEST_f_b (isfinite, 10, 1);
TEST_f_b (isfinite, min_subnorm_value, 1);
TEST_f_b (isfinite, plus_infty, 0);
TEST_f_b (isfinite, minus_infty, 0);
TEST_f_b (isfinite, qnan_value, 0);
END (isfinite); END (isfinite);
} }
@ -9856,19 +9882,24 @@ isgreaterequal_test (void)
END (isgreaterequal); END (isgreaterequal);
} }
static const struct test_f_i_data isinf_test_data[] =
{
START_DATA (isinf),
TEST_f_b (isinf, 0, 0),
TEST_f_b (isinf, minus_zero, 0),
TEST_f_b (isinf, 10, 0),
TEST_f_b (isinf, min_subnorm_value, 0),
TEST_f_b (isinf, plus_infty, 1),
TEST_f_b (isinf, minus_infty, 1),
TEST_f_b (isinf, qnan_value, 0),
END_DATA (isinf)
};
static void static void
isinf_test (void) isinf_test (void)
{ {
START (isinf); START (isinf);
RUN_TEST_LOOP_f_b_tg (isinf, isinf_test_data, );
TEST_f_b (isinf, 0, 0);
TEST_f_b (isinf, minus_zero, 0);
TEST_f_b (isinf, 10, 0);
TEST_f_b (isinf, min_subnorm_value, 0);
TEST_f_b (isinf, plus_infty, 1);
TEST_f_b (isinf, minus_infty, 1);
TEST_f_b (isinf, qnan_value, 0);
END (isinf); END (isinf);
} }
@ -9962,51 +9993,66 @@ islessgreater_test (void)
END (islessgreater); END (islessgreater);
} }
static const struct test_f_i_data isnan_test_data[] =
{
START_DATA (isnan),
TEST_f_b (isnan, 0, 0),
TEST_f_b (isnan, minus_zero, 0),
TEST_f_b (isnan, 10, 0),
TEST_f_b (isnan, min_subnorm_value, 0),
TEST_f_b (isnan, plus_infty, 0),
TEST_f_b (isnan, minus_infty, 0),
TEST_f_b (isnan, qnan_value, 1),
END_DATA (isnan)
};
static void static void
isnan_test (void) isnan_test (void)
{ {
START (isnan); START (isnan);
RUN_TEST_LOOP_f_b_tg (isnan, isnan_test_data, );
TEST_f_b (isnan, 0, 0);
TEST_f_b (isnan, minus_zero, 0);
TEST_f_b (isnan, 10, 0);
TEST_f_b (isnan, min_subnorm_value, 0);
TEST_f_b (isnan, plus_infty, 0);
TEST_f_b (isnan, minus_infty, 0);
TEST_f_b (isnan, qnan_value, 1);
END (isnan); END (isnan);
} }
static const struct test_f_i_data isnormal_test_data[] =
{
START_DATA (isnormal),
TEST_f_b (isnormal, 0, 0),
TEST_f_b (isnormal, minus_zero, 0),
TEST_f_b (isnormal, 10, 1),
TEST_f_b (isnormal, min_subnorm_value, 0),
TEST_f_b (isnormal, plus_infty, 0),
TEST_f_b (isnormal, minus_infty, 0),
TEST_f_b (isnormal, qnan_value, 0),
END_DATA (isnormal)
};
static void static void
isnormal_test (void) isnormal_test (void)
{ {
START (isnormal); START (isnormal);
RUN_TEST_LOOP_f_b_tg (isnormal, isnormal_test_data, );
TEST_f_b (isnormal, 0, 0);
TEST_f_b (isnormal, minus_zero, 0);
TEST_f_b (isnormal, 10, 1);
TEST_f_b (isnormal, min_subnorm_value, 0);
TEST_f_b (isnormal, plus_infty, 0);
TEST_f_b (isnormal, minus_infty, 0);
TEST_f_b (isnormal, qnan_value, 0);
END (isnormal); END (isnormal);
} }
static const struct test_f_i_data issignaling_test_data[] =
{
START_DATA (issignaling),
TEST_f_b (issignaling, 0, 0),
TEST_f_b (issignaling, minus_zero, 0),
TEST_f_b (issignaling, 10, 0),
TEST_f_b (issignaling, min_subnorm_value, 0),
TEST_f_b (issignaling, plus_infty, 0),
TEST_f_b (issignaling, minus_infty, 0),
TEST_f_b (issignaling, qnan_value, 0),
END_DATA (issignaling)
};
static void static void
issignaling_test (void) issignaling_test (void)
{ {
START (issignaling); START (issignaling);
RUN_TEST_LOOP_f_b_tg (issignaling, issignaling_test_data, );
TEST_f_b (issignaling, 0, 0);
TEST_f_b (issignaling, minus_zero, 0);
TEST_f_b (issignaling, 10, 0);
TEST_f_b (issignaling, min_subnorm_value, 0);
TEST_f_b (issignaling, plus_infty, 0);
TEST_f_b (issignaling, minus_infty, 0);
TEST_f_b (issignaling, qnan_value, 0);
END (issignaling); END (issignaling);
} }
@ -13448,23 +13494,27 @@ scalbln_test (void)
} }
static const struct test_f_i_data signbit_test_data[] =
{
START_DATA (signbit),
/* TODO: missing qNaN tests. */
TEST_f_b (signbit, 0, 0),
TEST_f_b (signbit, minus_zero, 1),
TEST_f_b (signbit, plus_infty, 0),
TEST_f_b (signbit, minus_infty, 1),
/* signbit (x) != 0 for x < 0. */
TEST_f_b (signbit, -1, 1),
/* signbit (x) == 0 for x >= 0. */
TEST_f_b (signbit, 1, 0),
END_DATA (signbit)
};
static void static void
signbit_test (void) signbit_test (void)
{ {
/* TODO: missing qNaN tests. */
START (signbit); START (signbit);
RUN_TEST_LOOP_f_b_tg (signbit, signbit_test_data, );
TEST_f_b (signbit, 0, 0);
TEST_f_b (signbit, minus_zero, 1);
TEST_f_b (signbit, plus_infty, 0);
TEST_f_b (signbit, minus_infty, 1);
/* signbit (x) != 0 for x < 0. */
TEST_f_b (signbit, -1, 1);
/* signbit (x) == 0 for x >= 0. */
TEST_f_b (signbit, 1, 0);
END (signbit); END (signbit);
} }