diff --git a/distrib/sets/lists/tests/mi b/distrib/sets/lists/tests/mi index 199752eb7c47..41c94ac24d8d 100644 --- a/distrib/sets/lists/tests/mi +++ b/distrib/sets/lists/tests/mi @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.196 2010/12/28 12:46:15 pgoyette Exp $ +# $NetBSD: mi,v 1.197 2010/12/28 16:57:00 pgoyette Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -323,6 +323,7 @@ ./usr/libdata/debug/usr/tests/lib/libc/gen/t_fmtcheck.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/gen/t_glob_star.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/gen/t_humanize_number.debug tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libc/gen/t_ldexp.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/gen/t_rbstress.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/gen/t_syslog_pthread.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/gen/t_siginfo.debug tests-lib-debug debug,atf @@ -1574,6 +1575,7 @@ ./usr/tests/lib/libc/gen/t_fmtcheck tests-lib-tests atf ./usr/tests/lib/libc/gen/t_glob_star tests-lib-tests atf ./usr/tests/lib/libc/gen/t_humanize_number tests-lib-tests atf +./usr/tests/lib/libc/gen/t_ldexp tests-lib-tests atf ./usr/tests/lib/libc/gen/t_rbstress tests-lib-tests atf ./usr/tests/lib/libc/gen/t_syslog_pthread tests-lib-tests atf ./usr/tests/lib/libc/gen/t_siginfo tests-lib-tests atf diff --git a/tests/lib/libc/gen/Makefile b/tests/lib/libc/gen/Makefile index ba7989b33302..e1a58581e95a 100644 --- a/tests/lib/libc/gen/Makefile +++ b/tests/lib/libc/gen/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.7 2010/12/28 12:46:15 pgoyette Exp $ +# $NetBSD: Makefile,v 1.8 2010/12/28 16:57:00 pgoyette Exp $ .include @@ -9,6 +9,7 @@ TESTS_C+= t_dir TESTS_C+= t_fmtcheck TESTS_C+= t_glob_star TESTS_C+= t_humanize_number +TESTS_C+= t_ldexp TESTS_C+= t_rbstress TESTS_C+= t_syslog_pthread TESTS_C+= t_vis diff --git a/tests/lib/libc/gen/t_ldexp.c b/tests/lib/libc/gen/t_ldexp.c new file mode 100644 index 000000000000..ff4776f55e68 --- /dev/null +++ b/tests/lib/libc/gen/t_ldexp.c @@ -0,0 +1,208 @@ +/* $NetBSD: t_ldexp.c,v 1.1 2010/12/28 16:57:00 pgoyette Exp $ */ + +/*- + * Copyright (c) 2010 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by + * + * 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 +#include +#include + +#define SKIP 9999 +#define FORMAT "%23.23lg" + +struct ldexp_test { + double x; + int exp1; + int exp2; + const char *result; +}; + +struct ldexp_test basics[] = { + { 1.0, 5, SKIP, " 32" }, + { 1.0, 1022, SKIP, "4.4942328371557897693233e+307" }, + { 1.0, 1023, -1, "4.4942328371557897693233e+307" }, + { 1.0, 1023, SKIP, "8.9884656743115795386465e+307" }, + { 1.0, 1022, 1, "8.9884656743115795386465e+307" }, + { 1.0, -1022, 2045, "8.9884656743115795386465e+307" }, + { 1.0, -5, SKIP, " 0.03125" }, + { 1.0, -1021, SKIP, "4.4501477170144027661805e-308" }, + { 1.0, -1022, 1, "4.4501477170144027661805e-308" }, + { 1.0, -1022, SKIP, "2.2250738585072013830902e-308" }, + { 1.0, -1021, -1, "2.2250738585072013830902e-308" }, + { 1.0, 1023, -2045, "2.2250738585072013830902e-308" }, + { 1.0, 1023, -1023, " 1" }, + { 1.0, -1022, 1022, " 1" }, + { 0, 0, 0, NULL } +}; + +struct ldexp_test zero[] = { + { 0.0, -1, SKIP, " 0" }, + { 0.0, 0, SKIP, " 0" }, + { 0.0, 1, SKIP, " 0" }, + { 0.0, 1024, SKIP, " 0" }, + { 0.0, 1025, SKIP, " 0" }, + { 0.0, -1023, SKIP, " 0" }, + { 0.0, -1024, SKIP, " 0" }, + { 0, 0, 0, NULL } +}; + +struct ldexp_test infinity[] = { + { 1.0, 1024, -1, " inf" }, + { 1.0, 1024, 0, " inf" }, + { 1.0, 1024, 1, " inf" }, + { -1.0, 1024, -1, " -inf" }, + { -1.0, 1024, 0, " -inf" }, + { -1.0, 1024, 1, " -inf" }, + { 0, 0, 0, NULL } +}; + +struct ldexp_test overflow[] = { + { 1.0, 1024, SKIP, " inf" }, + { 1.0, 1023, 1, " inf" }, + { 1.0, -1022, 2046, " inf" }, + { 1.0, 1025, SKIP, " inf" }, + { -1.0, 1024, SKIP, " -inf" }, + { -1.0, 1023, 1, " -inf" }, + { -1.0, -1022, 2046, " -inf" }, + { -1.0, 1025, SKIP, " -inf" }, + { 0, 0, 0, NULL } +}; + +struct ldexp_test denormal[] = { + { 1.0, -1023, SKIP, "1.1125369292536006915451e-308" }, + { 1.0, -1022, -1, "1.1125369292536006915451e-308" }, + { 1.0, 1023, -2046, "1.1125369292536006915451e-308" }, + { 1.0, -1024, SKIP, "5.5626846462680034577256e-309" }, + { 1.0, -1074, SKIP, "4.9406564584124654417657e-324" }, + { -1.0, -1023, SKIP, "-1.1125369292536006915451e-308" }, + { -1.0, -1022, -1, "-1.1125369292536006915451e-308" }, + { -1.0, 1023, -2046, "-1.1125369292536006915451e-308" }, + { -1.0, -1024, SKIP, "-5.5626846462680034577256e-309" }, + { -1.0, -1074, SKIP, "-4.9406564584124654417657e-324" }, + { 0, 0, 0, NULL } +}; + +struct ldexp_test underflow[] = { + { 1.0, -1075, SKIP, " 0" }, + { 1.0, -1074, -1, " 0" }, + { 1.0, 1023, -2098, " 0" }, + { 1.0, -1076, SKIP, " 0" }, + { -1.0, -1075, SKIP, " -0" }, + { -1.0, -1074, -1, " -0" }, + { -1.0, 1023, -2098, " -0" }, + { -1.0, -1076, SKIP, " -0" }, + { 0, 0, 0, NULL } +}; + +struct ldexp_test denormal_large_exp[] = { + { 1.0, -1028, 1024, " 0.0625" }, + { 1.0, -1028, 1025, " 0.125" }, + { 1.0, -1028, 1026, " 0.25" }, + { 1.0, -1028, 1027, " 0.5" }, + { 1.0, -1028, 1028, " 1" }, + { 1.0, -1028, 1029, " 2" }, + { 1.0, -1028, 1030, " 4" }, + { 1.0, -1028, 1040, " 4096" }, + { 1.0, -1028, 1050, " 4194304" }, + { 1.0, -1028, 1060, " 4294967296" }, + { 1.0, -1028, 1100, " 4722366482869645213696" }, + { 1.0, -1028, 1200, "5.9863107065073783529623e+51" }, + { 1.0, -1028, 1300, "7.5885503602567541832791e+81" }, + { 1.0, -1028, 1400, "9.6196304190416209014353e+111" }, + { 1.0, -1028, 1500, "1.2194330274671844653834e+142" }, + { 1.0, -1028, 1600, "1.5458150092069033378781e+172" }, + { 1.0, -1028, 1700, "1.9595533242629369747791e+202" }, + { 1.0, -1028, 1800, "2.4840289476811342962384e+232" }, + { 1.0, -1028, 1900, "3.1488807865122869393369e+262" }, + { 1.0, -1028, 2000, "3.9916806190694396233127e+292" }, + { 1.0, -1028, 2046, "2.808895523222368605827e+306" }, + { 1.0, -1028, 2047, "5.6177910464447372116541e+306" }, + { 1.0, -1028, 2048, "1.1235582092889474423308e+307" }, + { 1.0, -1028, 2049, "2.2471164185778948846616e+307" }, + { 1.0, -1028, 2050, "4.4942328371557897693233e+307" }, + { 1.0, -1028, 2051, "8.9884656743115795386465e+307" }, + { 0, 0, 0, NULL } +}; + +static void +run_test(struct ldexp_test *table) +{ + int i; + double v; + char outbuf[64]; + + for (i = 0; table->result != NULL; table++, i++) { + v = ldexp(table->x, table->exp1); + if (table->exp2 != SKIP) + v = ldexp(v, table->exp2); + snprintf(outbuf, sizeof(outbuf), FORMAT, v); + ATF_CHECK_STREQ_MSG(table->result, outbuf, + "Entry %d:\n\tExp: \"%s\"\n\tAct: \"%s\"", + i, table->result, outbuf); + } +} + +#define TEST(name) \ + ATF_TC(name); \ + ATF_TC_HEAD(name, tc) \ + { \ + \ + atf_tc_set_md_var(tc, "descr", \ + "Test ldexp(3) for " ___STRING(name)); \ + } \ + ATF_TC_BODY(name, tc) \ + { \ + \ + run_test(name); \ + } + +TEST(basics) +TEST(zero) +TEST(infinity) +TEST(overflow) +TEST(denormal) +TEST(underflow) +TEST(denormal_large_exp) + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, basics); + ATF_TP_ADD_TC(tp, zero); + ATF_TP_ADD_TC(tp, infinity); + ATF_TP_ADD_TC(tp, overflow); + ATF_TP_ADD_TC(tp, denormal); + ATF_TP_ADD_TC(tp, underflow); + ATF_TP_ADD_TC(tp, denormal_large_exp); + + return atf_no_error(); +}