Remove building with NOCRYPTO option
[minix.git] / tests / lib / libm / t_fenv.c
blob08d5c729c788b07b4532996bbc424477843960c4
1 /* $NetBSD: t_fenv.c,v 1.2 2014/12/29 19:51:53 martin Exp $ */
3 /*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Martin Husemann.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_fenv.c,v 1.2 2014/12/29 19:51:53 martin Exp $");
34 #include <atf-c.h>
36 #ifdef HAVE_FENV_H
38 #include <ieeefp.h>
39 #include <stdlib.h>
40 #include <fenv.h>
43 #if __arm__ && !__SOFTFP__
45 * Some NEON fpus do not implement IEEE exception handling,
46 * skip these tests if running on them and compiled for
47 * hard float.
49 #define FPU_EXC_PREREQ() \
50 if (0 == fpsetmask(fpsetmask(FP_X_INV))) \
51 atf_tc_skip("FPU does not implement exception handling");
54 * Same as above: some don't allow configuring the rounding mode.
56 #define FPU_RND_PREREQ() \
57 if (0 == fpsetround(fpsetround(FP_RZ))) \
58 atf_tc_skip("FPU does not implement configurable " \
59 "rounding modes");
60 #endif
62 #ifndef FPU_EXC_PREREQ
63 #define FPU_EXC_PREREQ() /* nothing */
64 #endif
65 #ifndef FPU_RND_PREREQ
66 #define FPU_RND_PREREQ() /* nothing */
67 #endif
70 ATF_TC(fegetround);
72 ATF_TC_HEAD(fegetround, tc)
74 atf_tc_set_md_var(tc, "descr",
75 "verify the fegetround() function agrees with the legacy "
76 "fpsetround");
79 ATF_TC_BODY(fegetround, tc)
81 FPU_RND_PREREQ();
83 fpsetround(FP_RZ);
84 ATF_CHECK(fegetround() == FE_TOWARDZERO);
85 fpsetround(FP_RM);
86 ATF_CHECK(fegetround() == FE_DOWNWARD);
87 fpsetround(FP_RN);
88 ATF_CHECK(fegetround() == FE_TONEAREST);
89 fpsetround(FP_RP);
90 ATF_CHECK(fegetround() == FE_UPWARD);
93 ATF_TC(fesetround);
95 ATF_TC_HEAD(fesetround, tc)
97 atf_tc_set_md_var(tc, "descr",
98 "verify the fesetround() function agrees with the legacy "
99 "fpgetround");
102 ATF_TC_BODY(fesetround, tc)
104 FPU_RND_PREREQ();
106 fesetround(FE_TOWARDZERO);
107 ATF_CHECK(fpgetround() == FP_RZ);
108 fesetround(FE_DOWNWARD);
109 ATF_CHECK(fpgetround() == FP_RM);
110 fesetround(FE_TONEAREST);
111 ATF_CHECK(fpgetround() == FP_RN);
112 fesetround(FE_UPWARD);
113 ATF_CHECK(fpgetround() == FP_RP);
116 ATF_TC(fegetexcept);
118 ATF_TC_HEAD(fegetexcept, tc)
120 atf_tc_set_md_var(tc, "descr",
121 "verify the fegetexcept() function agrees with the legacy "
122 "fpsetmask()");
125 ATF_TC_BODY(fegetexcept, tc)
127 FPU_EXC_PREREQ();
129 fpsetmask(0);
130 ATF_CHECK(fegetexcept() == 0);
132 fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
133 ATF_CHECK(fegetexcept() == (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW
134 |FE_UNDERFLOW|FE_INEXACT));
136 fpsetmask(FP_X_INV);
137 ATF_CHECK(fegetexcept() == FE_INVALID);
139 fpsetmask(FP_X_DZ);
140 ATF_CHECK(fegetexcept() == FE_DIVBYZERO);
142 fpsetmask(FP_X_OFL);
143 ATF_CHECK(fegetexcept() == FE_OVERFLOW);
145 fpsetmask(FP_X_UFL);
146 ATF_CHECK(fegetexcept() == FE_UNDERFLOW);
148 fpsetmask(FP_X_IMP);
149 ATF_CHECK(fegetexcept() == FE_INEXACT);
152 ATF_TC(feenableexcept);
154 ATF_TC_HEAD(feenableexcept, tc)
156 atf_tc_set_md_var(tc, "descr",
157 "verify the feenableexcept() function agrees with the legacy "
158 "fpgetmask()");
161 ATF_TC_BODY(feenableexcept, tc)
163 FPU_EXC_PREREQ();
165 fedisableexcept(FE_ALL_EXCEPT);
166 ATF_CHECK(fpgetmask() == 0);
168 feenableexcept(FE_UNDERFLOW);
169 ATF_CHECK(fpgetmask() == FP_X_UFL);
171 fedisableexcept(FE_ALL_EXCEPT);
172 feenableexcept(FE_OVERFLOW);
173 ATF_CHECK(fpgetmask() == FP_X_OFL);
175 fedisableexcept(FE_ALL_EXCEPT);
176 feenableexcept(FE_DIVBYZERO);
177 ATF_CHECK(fpgetmask() == FP_X_DZ);
179 fedisableexcept(FE_ALL_EXCEPT);
180 feenableexcept(FE_INEXACT);
181 ATF_CHECK(fpgetmask() == FP_X_IMP);
183 fedisableexcept(FE_ALL_EXCEPT);
184 feenableexcept(FE_INVALID);
185 ATF_CHECK(fpgetmask() == FP_X_INV);
188 ATF_TP_ADD_TCS(tp)
190 ATF_TP_ADD_TC(tp, fegetround);
191 ATF_TP_ADD_TC(tp, fesetround);
192 ATF_TP_ADD_TC(tp, fegetexcept);
193 ATF_TP_ADD_TC(tp, feenableexcept);
195 return atf_no_error();
198 #else /* no fenv.h support */
200 ATF_TC(t_nofenv);
202 ATF_TC_HEAD(t_nofenv, tc)
204 atf_tc_set_md_var(tc, "descr",
205 "dummy test case - no fenv.h support");
209 ATF_TC_BODY(t_nofenv, tc)
211 atf_tc_skip("no fenv.h support on this architecture");
214 ATF_TP_ADD_TCS(tp)
216 ATF_TP_ADD_TC(tp, t_nofenv);
217 return atf_no_error();
220 #endif