Module Name: src Committed By: pgoyette Date: Fri Dec 31 04:08:33 UTC 2010
Modified Files: src/distrib/sets/lists/tests: mi src/tests/lib/libc: Makefile Added Files: src/tests/lib/libc: t_convfp.c t_gdtoa.c t_randomid.c Log Message: Migrate a few miscellaneous tests from the old regress to atf To generate a diff of this commit: cvs rdiff -u -r1.197 -r1.198 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.12 -r1.13 src/tests/lib/libc/Makefile cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/t_convfp.c \ src/tests/lib/libc/t_gdtoa.c src/tests/lib/libc/t_randomid.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.197 src/distrib/sets/lists/tests/mi:1.198 --- src/distrib/sets/lists/tests/mi:1.197 Tue Dec 28 16:57:00 2010 +++ src/distrib/sets/lists/tests/mi Fri Dec 31 04:08:32 2010 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.197 2010/12/28 16:57:00 pgoyette Exp $ +# $NetBSD: mi,v 1.198 2010/12/31 04:08:32 pgoyette Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -367,6 +367,9 @@ ./usr/libdata/debug/usr/tests/lib/libc/string/t_string.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/string/t_stresep.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/string/t_swab.debug tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libc/t_convfp.debug tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libc/t_gdtoa.debug tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libc/t_randomid.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libdes tests-lib-debug ./usr/libdata/debug/usr/tests/lib/libdes/t_des.debug tests-lib-debug debug,atf,crypto ./usr/libdata/debug/usr/tests/lib/semaphore tests-lib-debug @@ -1626,6 +1629,9 @@ ./usr/tests/lib/libc/string/t_string tests-lib-tests atf ./usr/tests/lib/libc/string/t_stresep tests-lib-tests atf ./usr/tests/lib/libc/string/t_swab tests-lib-tests atf +./usr/tests/lib/libc/t_convfp tests-lib-tests atf +./usr/tests/lib/libc/t_gdtoa tests-lib-tests atf +./usr/tests/lib/libc/t_randomid tests-lib-tests atf ./usr/tests/lib/libdes tests-lib-tests ./usr/tests/lib/libdes/Atffile tests-lib-tests atf,crypto ./usr/tests/lib/libdes/t_des tests-lib-tests atf,crypto Index: src/tests/lib/libc/Makefile diff -u src/tests/lib/libc/Makefile:1.12 src/tests/lib/libc/Makefile:1.13 --- src/tests/lib/libc/Makefile:1.12 Mon Dec 27 19:35:30 2010 +++ src/tests/lib/libc/Makefile Fri Dec 31 04:08:33 2010 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.12 2010/12/27 19:35:30 pgoyette Exp $ +# $NetBSD: Makefile,v 1.13 2010/12/31 04:08:33 pgoyette Exp $ .include <bsd.own.mk> .include <bsd.sys.mk> @@ -9,6 +9,14 @@ TESTS_SUBDIRS+= ssp .endif +.if (${MACHINE_ARCH} != "vax" && ${MACHINE_ARCH} != "m68000") +SUBDIR+= ieeefp +.endif + TESTSDIR= ${TESTSBASE}/lib/libc +TESTS_C+= t_convfp +TESTS_C+= t_gdtoa +TESTS_C+= t_randomid + .include <bsd.test.mk> Added files: Index: src/tests/lib/libc/t_convfp.c diff -u /dev/null src/tests/lib/libc/t_convfp.c:1.1 --- /dev/null Fri Dec 31 04:08:33 2010 +++ src/tests/lib/libc/t_convfp.c Fri Dec 31 04:08:33 2010 @@ -0,0 +1,147 @@ +/* $NetBSD: t_convfp.c,v 1.1 2010/12/31 04:08:33 pgoyette Exp $ */ + +/*- + * Copyright (c) 2003 The NetBSD Foundation, Inc. + * All rights reserved. + * + * 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 <atf-c.h> + +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> + +/* + * This value is representable as an unsigned int, but not as an int. + * According to ISO C it must survive the convsion back from a double + * to an unsigned int (everything > -1 and < UINT_MAX+1 has to) + */ +#define UINT_TESTVALUE (INT_MAX+42U) + +/* The same for unsigned long */ +#define ULONG_TESTVALUE (LONG_MAX+42UL) + +static void test1(); +static void test2(); +static void test3(); + +ATF_TC(test1); + +ATF_TC_HEAD(test1, tc) +{ + + atf_tc_set_md_var(tc, "descr", "test conversions to unsigned int/long"); +} + +ATF_TC_BODY(test1, tc) +{ + unsigned int ui; + unsigned long ul; + long double dt; + double d; + + /* unsigned int test */ + d = UINT_TESTVALUE; + ui = (unsigned int)d; + + if (ui != UINT_TESTVALUE) + atf_tc_fail("FAILED: unsigned int %u (0x%x) != %u (0x%x)\n", + ui, ui, UINT_TESTVALUE, UINT_TESTVALUE); + + /* unsigned long vs. {long} double test */ + if (sizeof(d) > sizeof(ul)) { + d = ULONG_TESTVALUE; + ul = (unsigned long)d; + printf("testing double vs. long\n"); + } else if (sizeof(dt) > sizeof(ul)) { + dt = ULONG_TESTVALUE; + ul = (unsigned long)dt; + printf("testing long double vs. long\n"); + } else + atf_tc_skip("no suitable {long} double type found, skipping " + "\"unsigned long\" test\n" + "sizeof(long) = %d, sizeof(double) = %d, " + "sizeof(long double) = %d\n", + sizeof(ul), sizeof(d), sizeof(dt)); + + if (ul != ULONG_TESTVALUE) { + atf_tc_fail("unsigned long %lu (0x%lx) != %lu (0x%lx)\n", + ul, ul, ULONG_TESTVALUE, ULONG_TESTVALUE); + exit(1); + } +} + +ATF_TC(test2); + +ATF_TC_HEAD(test2, tc) +{ + + atf_tc_set_md_var(tc, "descr", "test double to unsigned long cast"); +} + +ATF_TC_BODY(test2, tc) +{ + double nv; + unsigned long uv; + + nv = 5.6; + uv = (unsigned long)nv; + + ATF_REQUIRE_EQ_MSG(uv, 5, + "%.3f casted to unsigned long is %lu\n", nv, uv); +} + +ATF_TC(test3); + +ATF_TC_HEAD(test3, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "test double/long double casts to unsigned long"); +} + +ATF_TC_BODY(test3, tc) +{ + double dv = 1.9; + long double ldv = dv; + unsigned long l1 = dv; + unsigned long l2 = ldv; + + ATF_REQUIRE_EQ_MSG(l1, 1, + "double 1.9 casted to unsigned long should be 1, but is %lu\n", l1); + + ATF_REQUIRE_EQ_MSG(l2, 1, + "long double 1.9 casted to unsigned long should be 1, but is %lu\n", + l2); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, test1); + ATF_TP_ADD_TC(tp, test2); + ATF_TP_ADD_TC(tp, test3); + + return atf_no_error(); +} Index: src/tests/lib/libc/t_gdtoa.c diff -u /dev/null src/tests/lib/libc/t_gdtoa.c:1.1 --- /dev/null Fri Dec 31 04:08:33 2010 +++ src/tests/lib/libc/t_gdtoa.c Fri Dec 31 04:08:33 2010 @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * 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 <sys/cdefs.h> +__RCSID("$NetBSD: t_gdtoa.c,v 1.1 2010/12/31 04:08:33 pgoyette Exp $"); + +#include <atf-c.h> + +#include <stdio.h> + +/* reported by Maksymilian Arciemowicz */ + +ATF_TC(long_format); + +ATF_TC_HEAD(long_format, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Test printf with %1.262159f format"); +} + +ATF_TC_BODY(long_format, tc) +{ + char *buf; + (void)asprintf(&buf, "%1.262159f", 1.1); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, long_format); + + return atf_no_error(); +} Index: src/tests/lib/libc/t_randomid.c diff -u /dev/null src/tests/lib/libc/t_randomid.c:1.1 --- /dev/null Fri Dec 31 04:08:33 2010 +++ src/tests/lib/libc/t_randomid.c Fri Dec 31 04:08:33 2010 @@ -0,0 +1,93 @@ +/* $NetBSD: t_randomid.c,v 1.1 2010/12/31 04:08:33 pgoyette Exp $ */ + +/*- + * Copyright (c) 2010 The NetBSD Foundation, Inc. + * All rights reserved. + * + * 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 <atf-c.h> + +#include <sys/types.h> + +#include <assert.h> +#include <inttypes.h> +#include <randomid.h> +#include <stdio.h> +#include <string.h> + +#define PERIOD 30000 + +uint64_t last[65536]; + +ATF_TC(randomid); + +ATF_TC_HEAD(randomid, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Check randomid(3)"); +} + +ATF_TC_BODY(randomid, tc) +{ + static randomid_t ctx = NULL; + uint64_t lowest, n, diff; + uint16_t id; + + memset(last, 0, sizeof(last)); + ctx = randomid_new(16, (long)3600); + + lowest = UINT64_MAX; + + for (n = 0; n < 1000000; n++) { + id = randomid(ctx); + + if (last[id] > 0) { + diff = n - last[id]; + + if (diff <= lowest) { + if (lowest != UINT64_MAX) + printf("id %5d: last call at %9lld, " + "current call %9lld (diff %5lld)" + ", lowest %lld\n", + id, last[id], n, diff, lowest); + + ATF_REQUIRE_MSG(diff >= PERIOD, + "diff (%"PRIu64") less than minimum " + "period (%d)", diff, PERIOD); + + lowest = diff; + } + } + + last[id] = n; + } +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, randomid); + + return atf_no_error(); +}