Convert lib/msun/trig_test from TAP to ATF format

Only expose :accuracy and :reduction if !i386, similar to before,
but more holistically to avoid future -Wunused issue with the unused
functions.

MFC after:	1 month
This commit is contained in:
Enji Cooper 2017-07-25 03:55:44 +00:00
parent fd5e9c331e
commit 4580a78efd
2 changed files with 73 additions and 69 deletions

View File

@ -68,7 +68,7 @@ TAP_TESTS_C+= nan_test
TAP_TESTS_C+= nearbyint_test TAP_TESTS_C+= nearbyint_test
TAP_TESTS_C+= next_test TAP_TESTS_C+= next_test
TAP_TESTS_C+= rem_test TAP_TESTS_C+= rem_test
TAP_TESTS_C+= trig_test ATF_TESTS_C+= trig_test
.if !empty(PROG) && !empty(TAP_TESTS_C:M${PROG}) .if !empty(PROG) && !empty(TAP_TESTS_C:M${PROG})
CFLAGS+= -O0 CFLAGS+= -O0

View File

@ -44,6 +44,8 @@ __FBSDID("$FreeBSD$");
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <atf-c.h>
#include "test-utils.h" #include "test-utils.h"
#pragma STDC FENV_ACCESS ON #pragma STDC FENV_ACCESS ON
@ -63,9 +65,9 @@ __FBSDID("$FreeBSD$");
*/ */
#define test(func, x, result, exceptmask, excepts) do { \ #define test(func, x, result, exceptmask, excepts) do { \
volatile long double _d = x; \ volatile long double _d = x; \
assert(feclearexcept(FE_ALL_EXCEPT) == 0); \ ATF_CHECK(feclearexcept(FE_ALL_EXCEPT) == 0); \
assert(fpequal((func)(_d), (result))); \ ATF_CHECK(fpequal((func)(_d), (result))); \
assert(((void)(func), fetestexcept(exceptmask) == (excepts))); \ ATF_CHECK(((void)(func), fetestexcept(exceptmask) == (excepts))); \
} while (0) } while (0)
#define testall(prefix, x, result, exceptmask, excepts) do { \ #define testall(prefix, x, result, exceptmask, excepts) do { \
@ -79,11 +81,14 @@ __FBSDID("$FreeBSD$");
test(prefix##f, x, (float)result, exceptmask, excepts); \ test(prefix##f, x, (float)result, exceptmask, excepts); \
} while (0) } while (0)
/* ATF_TC(special);
* Test special cases in sin(), cos(), and tan(). ATF_TC_HEAD(special, tc)
*/ {
static void
run_special_tests(void) atf_tc_set_md_var(tc, "descr",
"test special cases in sin(), cos(), and tan()");
}
ATF_TC_BODY(special, tc)
{ {
/* Values at 0 should be exact. */ /* Values at 0 should be exact. */
@ -108,11 +113,15 @@ run_special_tests(void)
testall(cos, NAN, NAN, ALL_STD_EXCEPT, 0); testall(cos, NAN, NAN, ALL_STD_EXCEPT, 0);
} }
/* #ifndef __i386__
* Tests to ensure argument reduction for large arguments is accurate. ATF_TC(reduction);
*/ ATF_TC_HEAD(reduction, tc)
static void {
run_reduction_tests(void)
atf_tc_set_md_var(tc, "descr",
"tests to ensure argument reduction for large arguments is accurate");
}
ATF_TC_BODY(reduction, tc)
{ {
/* floats very close to odd multiples of pi */ /* floats very close to odd multiples of pi */
static const float f_pi_odd[] = { static const float f_pi_odd[] = {
@ -156,67 +165,70 @@ run_reduction_tests(void)
unsigned i; unsigned i;
for (i = 0; i < nitems(f_pi_odd); i++) { for (i = 0; i < nitems(f_pi_odd); i++) {
assert(fabs(sinf(f_pi_odd[i])) < FLT_EPSILON); ATF_CHECK(fabs(sinf(f_pi_odd[i])) < FLT_EPSILON);
assert(cosf(f_pi_odd[i]) == -1.0); ATF_CHECK(cosf(f_pi_odd[i]) == -1.0);
assert(fabs(tan(f_pi_odd[i])) < FLT_EPSILON); ATF_CHECK(fabs(tan(f_pi_odd[i])) < FLT_EPSILON);
assert(fabs(sinf(-f_pi_odd[i])) < FLT_EPSILON); ATF_CHECK(fabs(sinf(-f_pi_odd[i])) < FLT_EPSILON);
assert(cosf(-f_pi_odd[i]) == -1.0); ATF_CHECK(cosf(-f_pi_odd[i]) == -1.0);
assert(fabs(tanf(-f_pi_odd[i])) < FLT_EPSILON); ATF_CHECK(fabs(tanf(-f_pi_odd[i])) < FLT_EPSILON);
assert(fabs(sinf(f_pi_odd[i] * 2)) < FLT_EPSILON); ATF_CHECK(fabs(sinf(f_pi_odd[i] * 2)) < FLT_EPSILON);
assert(cosf(f_pi_odd[i] * 2) == 1.0); ATF_CHECK(cosf(f_pi_odd[i] * 2) == 1.0);
assert(fabs(tanf(f_pi_odd[i] * 2)) < FLT_EPSILON); ATF_CHECK(fabs(tanf(f_pi_odd[i] * 2)) < FLT_EPSILON);
assert(fabs(sinf(-f_pi_odd[i] * 2)) < FLT_EPSILON); ATF_CHECK(fabs(sinf(-f_pi_odd[i] * 2)) < FLT_EPSILON);
assert(cosf(-f_pi_odd[i] * 2) == 1.0); ATF_CHECK(cosf(-f_pi_odd[i] * 2) == 1.0);
assert(fabs(tanf(-f_pi_odd[i] * 2)) < FLT_EPSILON); ATF_CHECK(fabs(tanf(-f_pi_odd[i] * 2)) < FLT_EPSILON);
} }
for (i = 0; i < nitems(d_pi_odd); i++) { for (i = 0; i < nitems(d_pi_odd); i++) {
assert(fabs(sin(d_pi_odd[i])) < 2 * DBL_EPSILON); ATF_CHECK(fabs(sin(d_pi_odd[i])) < 2 * DBL_EPSILON);
assert(cos(d_pi_odd[i]) == -1.0); ATF_CHECK(cos(d_pi_odd[i]) == -1.0);
assert(fabs(tan(d_pi_odd[i])) < 2 * DBL_EPSILON); ATF_CHECK(fabs(tan(d_pi_odd[i])) < 2 * DBL_EPSILON);
assert(fabs(sin(-d_pi_odd[i])) < 2 * DBL_EPSILON); ATF_CHECK(fabs(sin(-d_pi_odd[i])) < 2 * DBL_EPSILON);
assert(cos(-d_pi_odd[i]) == -1.0); ATF_CHECK(cos(-d_pi_odd[i]) == -1.0);
assert(fabs(tan(-d_pi_odd[i])) < 2 * DBL_EPSILON); ATF_CHECK(fabs(tan(-d_pi_odd[i])) < 2 * DBL_EPSILON);
assert(fabs(sin(d_pi_odd[i] * 2)) < 2 * DBL_EPSILON); ATF_CHECK(fabs(sin(d_pi_odd[i] * 2)) < 2 * DBL_EPSILON);
assert(cos(d_pi_odd[i] * 2) == 1.0); ATF_CHECK(cos(d_pi_odd[i] * 2) == 1.0);
assert(fabs(tan(d_pi_odd[i] * 2)) < 2 * DBL_EPSILON); ATF_CHECK(fabs(tan(d_pi_odd[i] * 2)) < 2 * DBL_EPSILON);
assert(fabs(sin(-d_pi_odd[i] * 2)) < 2 * DBL_EPSILON); ATF_CHECK(fabs(sin(-d_pi_odd[i] * 2)) < 2 * DBL_EPSILON);
assert(cos(-d_pi_odd[i] * 2) == 1.0); ATF_CHECK(cos(-d_pi_odd[i] * 2) == 1.0);
assert(fabs(tan(-d_pi_odd[i] * 2)) < 2 * DBL_EPSILON); ATF_CHECK(fabs(tan(-d_pi_odd[i] * 2)) < 2 * DBL_EPSILON);
} }
#if LDBL_MANT_DIG > 53 #if LDBL_MANT_DIG > 53
for (i = 0; i < nitems(ld_pi_odd); i++) { for (i = 0; i < nitems(ld_pi_odd); i++) {
assert(fabsl(sinl(ld_pi_odd[i])) < LDBL_EPSILON); ATF_CHECK(fabsl(sinl(ld_pi_odd[i])) < LDBL_EPSILON);
assert(cosl(ld_pi_odd[i]) == -1.0); ATF_CHECK(cosl(ld_pi_odd[i]) == -1.0);
assert(fabsl(tanl(ld_pi_odd[i])) < LDBL_EPSILON); ATF_CHECK(fabsl(tanl(ld_pi_odd[i])) < LDBL_EPSILON);
assert(fabsl(sinl(-ld_pi_odd[i])) < LDBL_EPSILON); ATF_CHECK(fabsl(sinl(-ld_pi_odd[i])) < LDBL_EPSILON);
assert(cosl(-ld_pi_odd[i]) == -1.0); ATF_CHECK(cosl(-ld_pi_odd[i]) == -1.0);
assert(fabsl(tanl(-ld_pi_odd[i])) < LDBL_EPSILON); ATF_CHECK(fabsl(tanl(-ld_pi_odd[i])) < LDBL_EPSILON);
assert(fabsl(sinl(ld_pi_odd[i] * 2)) < LDBL_EPSILON); ATF_CHECK(fabsl(sinl(ld_pi_odd[i] * 2)) < LDBL_EPSILON);
assert(cosl(ld_pi_odd[i] * 2) == 1.0); ATF_CHECK(cosl(ld_pi_odd[i] * 2) == 1.0);
assert(fabsl(tanl(ld_pi_odd[i] * 2)) < LDBL_EPSILON); ATF_CHECK(fabsl(tanl(ld_pi_odd[i] * 2)) < LDBL_EPSILON);
assert(fabsl(sinl(-ld_pi_odd[i] * 2)) < LDBL_EPSILON); ATF_CHECK(fabsl(sinl(-ld_pi_odd[i] * 2)) < LDBL_EPSILON);
assert(cosl(-ld_pi_odd[i] * 2) == 1.0); ATF_CHECK(cosl(-ld_pi_odd[i] * 2) == 1.0);
assert(fabsl(tanl(-ld_pi_odd[i] * 2)) < LDBL_EPSILON); ATF_CHECK(fabsl(tanl(-ld_pi_odd[i] * 2)) < LDBL_EPSILON);
} }
#endif #endif
} }
/* ATF_TC(accuracy);
* Tests the accuracy of these functions over the primary range. ATF_TC_HEAD(accuracy, tc)
*/ {
static void
run_accuracy_tests(void) atf_tc_set_md_var(tc, "descr",
"tests the accuracy of these functions over the primary range");
}
ATF_TC_BODY(accuracy, tc)
{ {
/* For small args, sin(x) = tan(x) = x, and cos(x) = 1. */ /* For small args, sin(x) = tan(x) = x, and cos(x) = 1. */
@ -256,25 +268,17 @@ run_accuracy_tests(void)
* - tests for large numbers that get reduced to hi+lo with lo!=0 * - tests for large numbers that get reduced to hi+lo with lo!=0
*/ */
} }
#endif
int ATF_TP_ADD_TCS(tp)
main(void)
{ {
printf("1..3\n"); ATF_TP_ADD_TC(tp, special);
run_special_tests();
printf("ok 1 - trig\n");
#ifndef __i386__ #ifndef __i386__
run_reduction_tests(); ATF_TP_ADD_TC(tp, accuracy);
ATF_TP_ADD_TC(tp, reduction);
#endif #endif
printf("ok 2 - trig\n");
#ifndef __i386__ return (atf_no_error());
run_accuracy_tests();
#endif
printf("ok 3 - trig\n");
return (0);
} }