Index: head/lib/libc/tests/gen/Makefile =================================================================== --- head/lib/libc/tests/gen/Makefile (revision 274580) +++ head/lib/libc/tests/gen/Makefile (revision 274581) @@ -1,58 +1,60 @@ # $FreeBSD$ .include TESTSDIR= ${TESTSBASE}/lib/libc/gen +ATF_TESTS_C= arc4random_test + # TODO: t_closefrom, t_cpuset, t_fmtcheck, t_randomid, t_sleep # TODO: t_siginfo (fixes require further inspection) # TODO: t_sethostname_test (consistently screws up the hostname) NETBSD_ATF_TESTS_C= alarm_test NETBSD_ATF_TESTS_C+= assert_test NETBSD_ATF_TESTS_C+= basedirname_test NETBSD_ATF_TESTS_C+= dir_test NETBSD_ATF_TESTS_C+= floatunditf_test NETBSD_ATF_TESTS_C+= fnmatch_test NETBSD_ATF_TESTS_C+= fpclassify_test NETBSD_ATF_TESTS_C+= fpsetmask_test NETBSD_ATF_TESTS_C+= fpsetround_test NETBSD_ATF_TESTS_C+= ftok_test NETBSD_ATF_TESTS_C+= getcwd_test NETBSD_ATF_TESTS_C+= getgrent_test NETBSD_ATF_TESTS_C+= glob_test NETBSD_ATF_TESTS_C+= humanize_number_test NETBSD_ATF_TESTS_C+= isnan_test NETBSD_ATF_TESTS_C+= nice_test NETBSD_ATF_TESTS_C+= pause_test NETBSD_ATF_TESTS_C+= raise_test NETBSD_ATF_TESTS_C+= realpath_test NETBSD_ATF_TESTS_C+= setdomainname_test NETBSD_ATF_TESTS_C+= sethostname_test NETBSD_ATF_TESTS_C+= sleep_test NETBSD_ATF_TESTS_C+= syslog_test NETBSD_ATF_TESTS_C+= time_test NETBSD_ATF_TESTS_C+= ttyname_test NETBSD_ATF_TESTS_C+= vis_test .include "../Makefile.netbsd-tests" LDADD.humanize_number_test+= -lutil DPADD.humanize_number_test+= ${LIBUTIL} LDADD.fpclassify_test+= -lm DPADD.fpclassify_test+= ${LIBM} LDADD.fpsetround_test+= -lm DPADD.fpsetround_test+= ${LIBM} LDADD.siginfo_test+= -lm DPADD.siginfo_test+= ${LIBM} LDADD.nice_test+= -lpthread DPADD.nice_test+= ${LIBPTHREAD} LDADD.syslog_test+= -lpthread DPADD.syslog_test+= ${LIBPTHREAD} TESTS_SUBDIRS= execve TESTS_SUBDIRS+= posix_spawn .include Index: head/lib/libc/tests/gen/arc4random_test.c =================================================================== --- head/lib/libc/tests/gen/arc4random_test.c (nonexistent) +++ head/lib/libc/tests/gen/arc4random_test.c (revision 274581) @@ -0,0 +1,92 @@ +/*- + * Copyright (c) 2011 David Schultz + * 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 AUTHOR 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 AUTHOR 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * BUFSIZE is the number of bytes of rc4 output to compare. The probability + * that this test fails spuriously is 2**(-BUFSIZE * 8). + */ +#define BUFSIZE 8 + +/* + * Test whether arc4random_buf() returns the same sequence of bytes in both + * parent and child processes. (Hint: It shouldn't.) + */ +ATF_TC_WITHOUT_HEAD(test_arc4random); +ATF_TC_BODY(test_arc4random, tc) +{ + struct shared_page { + char parentbuf[BUFSIZE]; + char childbuf[BUFSIZE]; + } *page; + pid_t pid; + char c; + + printf("1..1\n"); + + page = mmap(NULL, sizeof(struct shared_page), PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0); + if (page == MAP_FAILED) { + printf("fail 1 - mmap\n"); + exit(1); + } + + arc4random_buf(&c, 1); + + pid = fork(); + ATF_REQUIRE(0 <= pid); + if (pid == 0) { + /* child */ + arc4random_buf(page->childbuf, BUFSIZE); + exit(0); + } else { + /* parent */ + int status; + arc4random_buf(page->parentbuf, BUFSIZE); + wait(&status); + } + ATF_CHECK_MSG(memcmp(page->parentbuf, page->childbuf, BUFSIZE) != 0, + "sequences are the same"); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, test_arc4random); + + return (atf_no_error()); +} Property changes on: head/lib/libc/tests/gen/arc4random_test.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/tools/regression/lib/libc/gen/test-arc4random.c =================================================================== --- head/tools/regression/lib/libc/gen/test-arc4random.c (revision 274580) +++ head/tools/regression/lib/libc/gen/test-arc4random.c (nonexistent) @@ -1,89 +0,0 @@ -/*- - * Copyright (c) 2011 David Schultz - * 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 AUTHOR 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 AUTHOR 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 -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include - -/* - * BUFSIZE is the number of bytes of rc4 output to compare. The probability - * that this test fails spuriously is 2**(-BUFSIZE * 8). - */ -#define BUFSIZE 8 - -/* - * Test whether arc4random_buf() returns the same sequence of bytes in both - * parent and child processes. (Hint: It shouldn't.) - */ -int main(int argc, char *argv[]) { - struct shared_page { - char parentbuf[BUFSIZE]; - char childbuf[BUFSIZE]; - } *page; - pid_t pid; - char c; - - printf("1..1\n"); - - page = mmap(NULL, sizeof(struct shared_page), PROT_READ | PROT_WRITE, - MAP_ANON | MAP_SHARED, -1, 0); - if (page == MAP_FAILED) { - printf("fail 1 - mmap\n"); - exit(1); - } - - arc4random_buf(&c, 1); - - pid = fork(); - if (pid < 0) { - printf("fail 1 - fork\n"); - exit(1); - } - if (pid == 0) { - /* child */ - arc4random_buf(page->childbuf, BUFSIZE); - exit(0); - } else { - /* parent */ - int status; - arc4random_buf(page->parentbuf, BUFSIZE); - wait(&status); - } - if (memcmp(page->parentbuf, page->childbuf, BUFSIZE) == 0) { - printf("fail 1 - sequences are the same\n"); - exit(1); - } - - printf("ok 1 - sequences are different\n"); - exit(0); -} Property changes on: head/tools/regression/lib/libc/gen/test-arc4random.c ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property