Module Name: src Committed By: pgoyette Date: Tue Dec 28 12:46:16 UTC 2010
Modified Files: src/distrib/sets/lists/tests: mi src/tests/lib/libc/gen: Makefile Added Files: src/tests/lib/libc/gen: t_dir.c t_fmtcheck.c t_humanize_number.c t_rbstress.c t_vis.c Log Message: Migrate the remaining libc/gen tests to atf To generate a diff of this commit: cvs rdiff -u -r1.195 -r1.196 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/gen/Makefile cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/gen/t_dir.c \ src/tests/lib/libc/gen/t_fmtcheck.c \ src/tests/lib/libc/gen/t_humanize_number.c \ src/tests/lib/libc/gen/t_rbstress.c src/tests/lib/libc/gen/t_vis.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.195 src/distrib/sets/lists/tests/mi:1.196 --- src/distrib/sets/lists/tests/mi:1.195 Tue Dec 28 09:15:24 2010 +++ src/distrib/sets/lists/tests/mi Tue Dec 28 12:46:15 2010 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.195 2010/12/28 09:15:24 he Exp $ +# $NetBSD: mi,v 1.196 2010/12/28 12:46:15 pgoyette Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -319,9 +319,14 @@ ./usr/libdata/debug/usr/tests/lib/libc tests-lib-debug ./usr/libdata/debug/usr/tests/lib/libc/gen tests-lib-debug ./usr/libdata/debug/usr/tests/lib/libc/gen/t_basedirname.debug tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libc/gen/t_dir.debug tests-lib-debug debug,atf +./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_syslog_pthread.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_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 +./usr/libdata/debug/usr/tests/lib/libc/gen/t_vis.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/hash tests-lib-debug ./usr/libdata/debug/usr/tests/lib/libc/hash/t_sha2.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/setjmp tests-lib-debug @@ -1565,9 +1570,14 @@ ./usr/tests/lib/libc/gen tests-lib-tests ./usr/tests/lib/libc/gen/Atffile tests-lib-tests atf ./usr/tests/lib/libc/gen/t_basedirname tests-lib-tests atf +./usr/tests/lib/libc/gen/t_dir tests-lib-tests atf +./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_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 +./usr/tests/lib/libc/gen/t_vis tests-lib-tests atf ./usr/tests/lib/libc/hash tests-lib-tests ./usr/tests/lib/libc/hash/Atffile tests-lib-tests atf ./usr/tests/lib/libc/hash/t_sha2 tests-lib-tests atf Index: src/tests/lib/libc/gen/Makefile diff -u src/tests/lib/libc/gen/Makefile:1.6 src/tests/lib/libc/gen/Makefile:1.7 --- src/tests/lib/libc/gen/Makefile:1.6 Sat Dec 25 01:25:37 2010 +++ src/tests/lib/libc/gen/Makefile Tue Dec 28 12:46:15 2010 @@ -1,12 +1,17 @@ -# $NetBSD: Makefile,v 1.6 2010/12/25 01:25:37 pgoyette Exp $ +# $NetBSD: Makefile,v 1.7 2010/12/28 12:46:15 pgoyette Exp $ .include <bsd.own.mk> TESTSDIR= ${TESTSBASE}/lib/libc/gen +TESTS_C+= t_basedirname +TESTS_C+= t_dir +TESTS_C+= t_fmtcheck TESTS_C+= t_glob_star +TESTS_C+= t_humanize_number +TESTS_C+= t_rbstress TESTS_C+= t_syslog_pthread -TESTS_C+= t_basedirname +TESTS_C+= t_vis .if !make(obj) && !make(cleandir) HAVE_SIGINFO != if (echo "\#include <signal.h>" && echo "SA_SIGINFO") | ${CC} -E -I${DESTDIR}/usr/include - | grep -sq 0x0040; then echo yes; else echo no; fi Added files: Index: src/tests/lib/libc/gen/t_dir.c diff -u /dev/null src/tests/lib/libc/gen/t_dir.c:1.1 --- /dev/null Tue Dec 28 12:46:16 2010 +++ src/tests/lib/libc/gen/t_dir.c Tue Dec 28 12:46:15 2010 @@ -0,0 +1,163 @@ +/* $NetBSD: t_dir.c,v 1.1 2010/12/28 12:46:15 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 <atf-c.h> + +#include <assert.h> +#include <dirent.h> +#include <err.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <sys/stat.h> + +ATF_TC(seekdir); + +ATF_TC_HEAD(seekdir, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Check telldir(3) and seekdir(3) for correct behavior (PR/24324)"); +} + +ATF_TC_BODY(seekdir, tc) +{ + DIR *dp; + char *wasname; + struct dirent *entry; + long here; + + mkdir("t", 0755); + creat("t/a", 0600); + creat("t/b", 0600); + creat("t/c", 0600); + + dp = opendir("t"); + if ( dp == NULL) + atf_tc_fail("Could not open temp directory."); + + /* skip two for . and .. */ + entry = readdir(dp); + entry = readdir(dp); + + /* get first entry */ + entry = readdir(dp); + here = telldir(dp); + + /* get second entry */ + entry = readdir(dp); + wasname = strdup(entry->d_name); + + /* get third entry */ + entry = readdir(dp); + + /* try to return to the position after the first entry */ + seekdir(dp, here); + entry = readdir(dp); + + if (strcmp(entry->d_name, wasname) != 0) + atf_tc_fail("1st seekdir found wrong name"); + + /* try again, and throw in a telldir() for good measure */ + seekdir(dp, here); + here = telldir(dp); + entry = readdir(dp); + + if (strcmp(entry->d_name, wasname) != 0) + atf_tc_fail("2nd seekdir found wrong name"); + + /* One more time, to make sure that telldir() doesn't affect result */ + seekdir(dp, here); + entry = readdir(dp); + + if (strcmp(entry->d_name, wasname) != 0) + atf_tc_fail("3rd seekdir found wrong name"); + + closedir(dp); +} + +ATF_TC(telldir_leak); + +ATF_TC_HEAD(telldir_leak, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Check telldir(3) for memory leakage (PR/24324)"); +} + +ATF_TC_BODY(telldir_leak, tc) +{ + DIR *dp; + long loc; + char *memused; + int i; + int oktouse = 4096; + + dp = opendir("."); + if (dp == NULL) + atf_tc_fail("Could not open current directory"); + + loc = telldir(dp); + memused = sbrk(0); + closedir(dp); + + for (i=0; i<1000; i++) { + dp = opendir("."); + if (dp == NULL) + atf_tc_fail("Could not open current directory"); + + loc = telldir(dp); + closedir(dp); + + if ((char *)(sbrk(0)) - memused > oktouse) { + (void)printf("Used %td extra bytes for %d telldir " + "calls", ((char *)(sbrk(0)) - memused), i); + oktouse = (char *)(sbrk(0)) - memused; + } + } + if (oktouse > 4096) { + atf_tc_fail("Failure: leaked %td bytes", oktouse); + } else { + (void)printf("OK: used %td bytes\n", (char *)(sbrk(0))-memused); + } +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, seekdir); + ATF_TP_ADD_TC(tp, telldir_leak); + + return atf_no_error(); +} Index: src/tests/lib/libc/gen/t_fmtcheck.c diff -u /dev/null src/tests/lib/libc/gen/t_fmtcheck.c:1.1 --- /dev/null Tue Dec 28 12:46:16 2010 +++ src/tests/lib/libc/gen/t_fmtcheck.c Tue Dec 28 12:46:15 2010 @@ -0,0 +1,116 @@ +/* $NetBSD: t_fmtcheck.c,v 1.1 2010/12/28 12:46:15 pgoyette Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code was contributed to The NetBSD Foundation by Allen Briggs. + * + * 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 <stdio.h> +#include <stdlib.h> + +const char *fmtcheck(const char *f1, const char *f2) + __attribute__((__format_arg__(2))); + +#include <err.h> + +struct test_fmt { + const char *fmt1; + const char *fmt2; + int correct; +} test_fmts[] = { + { "%d", "%d", 1 }, + { "%2d", "%2.2d", 1 }, + { "%x", "%d", 1 }, + { "%u", "%d", 1 }, + { "%03d", "%d", 1 }, + { "%-2d", "%d", 1 }, + { "%d", "%-12.1d", 1 }, + { "%d", "%-01.3d", 1 }, + { "%X", "%-01.3d", 1 }, + { "%D", "%ld", 1 }, + { "%s", "%s", 1 }, + { "%s", "This is a %s test", 1 }, + { "Hi, there. This is a %s test", "%s", 1 }, + { "%d", "%s", 2 }, + { "%e", "%s", 2 }, + { "%r", "%d", 2 }, + { "%*.2d", "%*d", 1 }, + { "%2.*d", "%*d", 2 }, + { "%*d", "%*d", 1 }, + { "%-3", "%d", 2 }, + { "%d %s", "%d", 2 }, + { "%*.*.*d", "%*.*.*d", 2 }, + { "%d", "%d %s", 1 }, + { "%40s", "%20s", 1 }, + { "%x %x %x", "%o %u %d", 1 }, + { "%o %u %d", "%x %x %X", 1 }, + { "%#o %u %#-d", "%x %#x %X", 1 }, + { "%qd", "%llx", 1 }, + { "%%", "%llx", 1 }, + { "%p %30s %#llx %-10.*e", "This number %lu%% and string %s has %qd numbers and %.*g floats", 1 }, +}; + +ATF_TC(tc_fmtcheck); + +ATF_TC_HEAD(tc_fmtcheck, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Test fmtcheck(3)"); +} + +ATF_TC_BODY(tc_fmtcheck, tc) +{ + unsigned int i, r; + const char *f, *cf, *f1, *f2; + + r = 0; + for (i = 0 ; i < __arraycount(test_fmts); i++) { + f1 = test_fmts[i].fmt1; + f2 = test_fmts[i].fmt2; + f = fmtcheck(f1, f2); + if (test_fmts[i].correct == 1) { + cf = f1; + } else { + cf = f2; + } + if (f != cf) { + r++; + atf_tc_fail_nonfatal("Test %d: (%s) vs. (%s) failed " + "(should have returned %s)", i, f1, f2, + (test_fmts[i].correct == 1) ? "1st" : "2nd"); + } + } +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, tc_fmtcheck); + + return atf_no_error(); +} Index: src/tests/lib/libc/gen/t_humanize_number.c diff -u /dev/null src/tests/lib/libc/gen/t_humanize_number.c:1.1 --- /dev/null Tue Dec 28 12:46:16 2010 +++ src/tests/lib/libc/gen/t_humanize_number.c Tue Dec 28 12:46:15 2010 @@ -0,0 +1,257 @@ +/* $NetBSD: t_humanize_number.c,v 1.1 2010/12/28 12:46:15 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 <atf-c.h> + +#include <err.h> +#include <inttypes.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <util.h> + +const struct hnopts { + size_t ho_len; + int64_t ho_num; + const char *ho_suffix; + int ho_scale; + int ho_flags; + int ho_retval; /* expected return value */ + const char *ho_retstr; /* expected string in buffer */ +} hnopts[] = { + /* + * Rev. 1.6 produces "10.0". + */ + { 5, 10737418236ULL * 1024, "", + HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL, 3, "10T" }, + + { 5, 10450000, "", + HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL, 3, "10M" }, + { 5, 10500000, "", /* just for reference */ + HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL, 3, "10M" }, + + /* + * Trailing space. Rev. 1.7 produces "1 ". + */ + { 5, 1, "", 0, HN_NOSPACE, 1, "1" }, + + { 5, 1, "", 0, 0, 2, "1 " }, /* just for reference */ + { 5, 1, "", 0, HN_B, 3, "1 B" }, /* and more ... */ + { 5, 1, "", 0, HN_DECIMAL, 2, "1 " }, + { 5, 1, "", 0, HN_NOSPACE | HN_B, 2, "1B" }, + { 5, 1, "", 0, HN_B | HN_DECIMAL, 3, "1 B" }, + { 5, 1, "", 0, HN_NOSPACE | HN_B | HN_DECIMAL, 2, "1B" }, + + /* + * Space and HN_B. Rev. 1.7 produces "1B". + */ + { 5, 1, "", HN_AUTOSCALE, HN_B, 3, "1 B" }, + { 5, 1000, "", /* just for reference */ + HN_AUTOSCALE, HN_B, 3, "1 K" }, + + /* + * Truncated output. Rev. 1.7 produces "1.0 K". + */ + { 6, 1000, "A", HN_AUTOSCALE, HN_DECIMAL, -1, "" }, + + /* + * Failure case reported by Greg Troxel <g...@netbsd.org>. + * Rev. 1.11 incorrectly returns 5 with filling the buffer + * with "1000". + */ + { 5, 1048258238, "", + HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL, 4, "1.0G" }, + /* Similar case it prints 1000 where it shouldn't */ + { 5, 1023488, "", + HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL, 4, "1.0M" }, + { 5, 1023999, "", + HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL, 4, "1.0M" }, +}; + +struct hnflags { + int hf_flags; + const char *hf_name; +}; + +const struct hnflags scale_flags[] = { + { HN_GETSCALE, "HN_GETSCALE" }, + { HN_AUTOSCALE, "HN_AUTOSCALE" }, +}; +const struct hnflags normal_flags[] = { + { HN_DECIMAL, "HN_DECIMAL" }, + { HN_NOSPACE, "HN_NOSPACE" }, + { HN_B, "HN_B" }, + { HN_DIVISOR_1000, "HN_DIVISOR_1000" }, +}; + +const char * + formatflags(char *, size_t, const struct hnflags *, size_t, int); +void newline(void); +void w_printf(const char *, ...); +int main(int, char *[]); + +const char * +formatflags(char *buf, size_t buflen, const struct hnflags *hfs, + size_t hfslen, int flags) +{ + const struct hnflags *hf; + char *p = buf; + ssize_t len = buflen; + unsigned int i, found; + int n; + + if (flags == 0) { + snprintf(buf, buflen, "0"); + return (buf); + } + for (i = found = 0; i < hfslen && flags & ~found; i++) { + hf = &hfs[i]; + if (flags & hf->hf_flags) { + found |= hf->hf_flags; + n = snprintf(p, len, "|%s", hf->hf_name); + if (n >= len) { + p = buf; + len = buflen; + /* Print `flags' as number */ + goto bad; + } + p += n; + len -= n; + } + } + flags &= ~found; + if (flags) +bad: + snprintf(p, len, "|0x%x", flags); + return (*buf == '|' ? buf + 1 : buf); +} + +static int col, bol = 1; +void +newline(void) +{ + + fprintf(stderr, "\n"); + col = 0; + bol = 1; +} + +void +w_printf(const char *fmt, ...) +{ + char buf[80]; + va_list ap; + int n; + + va_start(ap, fmt); + if (col >= 0) { + n = vsnprintf(buf, sizeof(buf), fmt, ap); + if (n >= (int)sizeof(buf)) { + col = -1; + goto overflow; + } else if (n == 0) + goto out; + + if (!bol) { + if (col + n > 75) + fprintf(stderr, "\n "), col = 4; + else + fprintf(stderr, " "), col++; + } + fprintf(stderr, "%s", buf); + col += n; + bol = 0; + } else { +overflow: + vfprintf(stderr, fmt, ap); + } +out: + va_end(ap); +} + +ATF_TC(humanize); + +ATF_TC_HEAD(humanize, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Test humanize_number(3)"); +} + +ATF_TC_BODY(humanize, tc) +{ + char fbuf[128]; + const struct hnopts *ho; + char *buf = NULL; + size_t buflen = 0; + unsigned int i; + int rv = 0; + + for (i = 0; i < __arraycount(hnopts); i++) { + ho = &hnopts[i]; + if (buflen < ho->ho_len) { + buflen = ho->ho_len; + buf = realloc(buf, buflen); + if (buf == NULL) + atf_tc_fail("realloc(..., %d) failed", buflen); + } + + rv = humanize_number(buf, ho->ho_len, ho->ho_num, + ho->ho_suffix, ho->ho_scale, ho->ho_flags); + + if (rv == ho->ho_retval && + (rv == -1 || strcmp(buf, ho->ho_retstr) == 0)) + continue; + + w_printf("humanize_number(\"%s\", %d, %" PRId64 ",", + ho->ho_retstr, ho->ho_len, ho->ho_num); + w_printf("\"%s\",", ho->ho_suffix); + w_printf("%s,", formatflags(fbuf, sizeof(fbuf), scale_flags, + sizeof(scale_flags) / sizeof(scale_flags[0]), + ho->ho_scale)); + w_printf("%s)", formatflags(fbuf, sizeof(fbuf), normal_flags, + sizeof(normal_flags) / sizeof(normal_flags[0]), + ho->ho_flags)); + w_printf("= %d,", ho->ho_retval); + w_printf("but got"); + w_printf("%d/[%s]", rv, rv == -1 ? "" : buf); + newline(); + atf_tc_fail_nonfatal("Failed for table entry %d", i); + } +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, humanize); + + return atf_no_error(); +} Index: src/tests/lib/libc/gen/t_rbstress.c diff -u /dev/null src/tests/lib/libc/gen/t_rbstress.c:1.1 --- /dev/null Tue Dec 28 12:46:16 2010 +++ src/tests/lib/libc/gen/t_rbstress.c Tue Dec 28 12:46:15 2010 @@ -0,0 +1,127 @@ +/* $NetBSD: t_rbstress.c,v 1.1 2010/12/28 12:46:15 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 <atf-c.h> + +#include <sys/cdefs.h> +#include <sys/tree.h> +#include <stdlib.h> +#include <stdio.h> + +struct mist { + RB_ENTRY(mist) rbentry; + int key; +}; +RB_HEAD(head, mist) tt; + +static int +mistcmp(struct mist *a, struct mist *b) +{ +#if 0 + return (b->key - a->key); /* wrong, can overflow */ +#else + if (b->key > a->key) + return 1; + else if (b->key < a->key) + return (-1); + else + return 0; +#endif +} + +RB_PROTOTYPE(head, mist, rbentry, mistcmp) +RB_GENERATE(head, mist, rbentry, mistcmp) + +static struct mist * +addmist(int key) +{ + struct mist *m; + + m = malloc(sizeof(struct mist)); + m->key = key; + RB_INSERT(head, &tt, m); + return m; +} + +static int +findmist(struct mist *m) +{ + + return (!!RB_FIND(head, &tt, m)); +} + +#define N 1000 +static int +test(void) +{ + struct mist *m[N]; + int fail, i, j; + + RB_INIT(&tt); + fail = 0; + for (i = 0; i < N; i++) { + m[i] = addmist(random() << 1); /* use all 32 bits */ + for (j = 0; j <= i; j++) + if (!findmist(m[j])) + fail++; + } + return fail; +} + +ATF_TC(rbstress); +ATF_TC_HEAD(rbstress, tc) +{ + + atf_tc_set_md_var(tc, "descr", "rb-tree stress test"); +} + +ATF_TC_BODY(rbstress, tc) +{ + int i, fail, f; + + srandom(4711); + fail = 0; + for (i = 0; i < 10; i++) { + f = test(); + if (f) { + atf_tc_fail_nonfatal("loop %d: %d errors\n", i, f); + fail += f; + } + } +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, rbstress); + + return atf_no_error(); +} Index: src/tests/lib/libc/gen/t_vis.c diff -u /dev/null src/tests/lib/libc/gen/t_vis.c:1.1 --- /dev/null Tue Dec 28 12:46:16 2010 +++ src/tests/lib/libc/gen/t_vis.c Tue Dec 28 12:46:15 2010 @@ -0,0 +1,98 @@ +/* $NetBSD: t_vis.c,v 1.1 2010/12/28 12:46:15 pgoyette Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code was 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. + * + * 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 <string.h> +#include <stdlib.h> +#include <err.h> +#include <vis.h> + +static int styles[] = { + VIS_OCTAL, + VIS_CSTYLE, + VIS_SP, + VIS_TAB, + VIS_NL, + VIS_WHITE, + VIS_SAFE, +#if 0 /* Not reversible */ + VIS_NOSLASH, +#endif +#ifdef VIS_HTTPSTYLE + VIS_HTTPSTYLE +#endif +}; + +#define SIZE 256 + +ATF_TC(vis); + +ATF_TC_HEAD(vis, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Test strvis(3)"); +} + +ATF_TC_BODY(vis, tc) +{ + char *srcbuf, *dstbuf, *visbuf; + unsigned int i, j; + + dstbuf = malloc(SIZE); + srcbuf = malloc(SIZE); + visbuf = malloc(SIZE * 4 + 1); + + for (i = 0; i < SIZE; i++) + srcbuf[i] = (char)i; + + for (i = 0; i < __arraycount(styles); i++) { + strsvisx(visbuf, srcbuf, SIZE, styles[i], ""); + /* + * XXX: The strunvisx api is busted; flags should be + * UNVIS_ flags, buf we follow FreeBSD's lead. This + * needs to be redone, by moving UNVIS_END into the + * VIS_ space, and bump the library/symbol. + */ + strunvisx(dstbuf, visbuf, styles[i] & VIS_HTTPSTYLE); + for (j = 0; j < SIZE; j++) + if (dstbuf[j] != (char)j) + atf_tc_fail_nonfatal("Failed for style %x, " + "char %d [%d]", styles[i], j, dstbuf[j]); + } +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, vis); + + return atf_no_error(); +}