1 /* $NetBSD: t_fenv.c,v 1.3 2015/12/22 14:20:59 christos Exp $ */
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.3 2015/12/22 14:20:59 christos Exp $");
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
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 " \
62 #ifndef FPU_EXC_PREREQ
63 #define FPU_EXC_PREREQ() /* nothing */
65 #ifndef FPU_RND_PREREQ
66 #define FPU_RND_PREREQ() /* nothing */
72 ATF_TC_HEAD(fegetround, tc)
74 atf_tc_set_md_var(tc, "descr",
75 "verify the fegetround() function agrees with the legacy "
79 ATF_TC_BODY(fegetround, tc)
84 ATF_CHECK(fegetround() == FE_TOWARDZERO);
86 ATF_CHECK(fegetround() == FE_DOWNWARD);
88 ATF_CHECK(fegetround() == FE_TONEAREST);
90 ATF_CHECK(fegetround() == FE_UPWARD);
95 ATF_TC_HEAD(fesetround, tc)
97 atf_tc_set_md_var(tc, "descr",
98 "verify the fesetround() function agrees with the legacy "
102 ATF_TC_BODY(fesetround, tc)
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);
118 ATF_TC_HEAD(fegetexcept, tc)
120 atf_tc_set_md_var(tc, "descr",
121 "verify the fegetexcept() function agrees with the legacy "
125 ATF_TC_BODY(fegetexcept, tc)
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));
137 ATF_CHECK(fegetexcept() == FE_INVALID);
140 ATF_CHECK(fegetexcept() == FE_DIVBYZERO);
143 ATF_CHECK(fegetexcept() == FE_OVERFLOW);
146 ATF_CHECK(fegetexcept() == FE_UNDERFLOW);
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 "
161 ATF_TC_BODY(feenableexcept, tc)
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);
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 */
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");
216 ATF_TP_ADD_TC(tp, t_nofenv);
217 return atf_no_error();