From 7e38ec308c1519f5c53e0f3ec4ae43d0b6558bef Mon Sep 17 00:00:00 2001 From: maya Date: Mon, 22 Aug 2016 08:49:33 +0000 Subject: [PATCH] add failing test for PR lib/51427 ilogb(INFINITY)=-INT_MAX, it should be INT_MAX while here, test raised exceptions, other values. XXX some platforms don't have exceptions --- distrib/sets/lists/debug/mi | 3 +- distrib/sets/lists/tests/mi | 3 +- tests/lib/libm/Makefile | 3 +- tests/lib/libm/t_ilogb.c | 109 ++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 tests/lib/libm/t_ilogb.c diff --git a/distrib/sets/lists/debug/mi b/distrib/sets/lists/debug/mi index 85ed3daf14ee..ad52baa527df 100644 --- a/distrib/sets/lists/debug/mi +++ b/distrib/sets/lists/debug/mi @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.164 2016/08/20 11:34:49 christos Exp $ +# $NetBSD: mi,v 1.165 2016/08/22 08:49:33 maya Exp $ ./etc/mtree/set.debug comp-sys-root ./usr/lib comp-sys-usr compatdir ./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib,compatfile @@ -2105,6 +2105,7 @@ ./usr/libdata/debug/usr/tests/lib/libm/t_floor.debug tests-obsolete obsolete,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_fmod.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_hypot.debug tests-lib-debug debug,atf,compattestfile +./usr/libdata/debug/usr/tests/lib/libm/t_ilogb.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_infinity.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_ldexp.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_libm.debug tests-obsolete obsolete,compattestfile diff --git a/distrib/sets/lists/tests/mi b/distrib/sets/lists/tests/mi index bbfb5cdd4114..1fb6a897d98a 100644 --- a/distrib/sets/lists/tests/mi +++ b/distrib/sets/lists/tests/mi @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.683 2016/08/19 10:22:42 christos Exp $ +# $NetBSD: mi,v 1.684 2016/08/22 08:49:33 maya Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -2912,6 +2912,7 @@ ./usr/tests/lib/libm/t_floor tests-obsolete obsolete ./usr/tests/lib/libm/t_fmod tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_hypot tests-lib-tests compattestfile,atf +./usr/tests/lib/libm/t_ilogb tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_infinity tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_ldexp tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_libm tests-obsolete obsolete diff --git a/tests/lib/libm/Makefile b/tests/lib/libm/Makefile index 77a39af2600e..e31b7c21a0d3 100644 --- a/tests/lib/libm/Makefile +++ b/tests/lib/libm/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.37 2016/01/24 20:26:47 gson Exp $ +# $NetBSD: Makefile,v 1.38 2016/08/22 08:49:33 maya Exp $ .include @@ -23,6 +23,7 @@ TESTS_C+= t_exp TESTS_C+= t_fenv TESTS_C+= t_fmod TESTS_C+= t_hypot +TESTS_C+= t_ilogb TESTS_C+= t_infinity TESTS_C+= t_ldexp TESTS_C+= t_log diff --git a/tests/lib/libm/t_ilogb.c b/tests/lib/libm/t_ilogb.c new file mode 100644 index 000000000000..97e63e254587 --- /dev/null +++ b/tests/lib/libm/t_ilogb.c @@ -0,0 +1,109 @@ +/* $NetBSD: t_ilogb.c,v 1.1 2016/08/22 08:49:33 maya Exp $ */ + +/*- + * Copyright (c) 2016 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Maya Rashish. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#define ATF_CHECK_RAISED_INVALID do { \ + int r; \ + r = feclearexcept(FE_ALL_EXCEPT); \ + ATF_CHECK(r == FE_INVALID); \ + } while (0) + +#define ATF_CHECK_RAISED_NOTHING do { \ + int r; \ + r = feclearexcept(FE_ALL_EXCEPT); \ + ATF_CHECK(r == 0); \ + } while (0) + +ATF_TC(ilogb); +ATF_TC_HEAD(ilogb, tc) +{ + atf_tc_set_md_var(tc, "descr","Check ilogb family"); +} + +ATF_TC_BODY(ilogb, tc) +{ + atf_tc_expect_fail("PR lib/51427"); + + ATF_CHECK(ilogbf(0) == FP_ILOGB0); + ATF_CHECK_RAISED_INVALID; + ATF_CHECK(ilogb(0) == FP_ILOGB0); + ATF_CHECK_RAISED_INVALID; + ATF_CHECK(ilogbl(0) == FP_ILOGB0); + ATF_CHECK_RAISED_INVALID; + + ATF_CHECK(ilogbf(-0) == FP_ILOGB0); + ATF_CHECK_RAISED_INVALID; + ATF_CHECK(ilogb(-0) == FP_ILOGB0); + ATF_CHECK_RAISED_INVALID; + ATF_CHECK(ilogbl(-0) == FP_ILOGB0); + ATF_CHECK_RAISED_INVALID; + + ATF_CHECK(ilogbf(INFINITY) == INT_MAX); + ATF_CHECK_RAISED_INVALID; + ATF_CHECK(ilogb(INFINITY) == INT_MAX); + ATF_CHECK_RAISED_INVALID; + ATF_CHECK(ilogbl(INFINITY) == INT_MAX); + ATF_CHECK_RAISED_INVALID; + + ATF_CHECK(ilogbf(-INFINITY) == INT_MAX); + ATF_CHECK_RAISED_INVALID; + ATF_CHECK(ilogb(-INFINITY) == INT_MAX); + ATF_CHECK_RAISED_INVALID; + ATF_CHECK(ilogbl(-INFINITY) == INT_MAX); + ATF_CHECK_RAISED_INVALID; + + ATF_CHECK(ilogbf(2^20) == 20); + ATF_CHECK_RAISED_NOTHING; + ATF_CHECK(ilogb(2^20) == 20); + ATF_CHECK_RAISED_NOTHING; + ATF_CHECK(ilogbl(2^20) == 20); + ATF_CHECK_RAISED_NOTHING; + +#ifndef __vax__ + ATF_CHECK(ilogbf(NAN) == FP_ILOGBNAN); + ATF_CHECK_RAISED_INVALID; + ATF_CHECK(ilogb(NAN) == FP_ILOGBNAN); + ATF_CHECK_RAISED_INVALID; + ATF_CHECK(ilogbl(NAN) == FP_ILOGBNAN); + ATF_CHECK_RAISED_INVALID; +#endif +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, ilogb); + + return atf_no_error(); +}