Date: Sun, 16 Nov 2014 07:55:29 +0000 (UTC) From: Garrett Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r274581 - in head: lib/libc/tests/gen tools/regression/lib/libc/gen Message-ID: <201411160755.sAG7tTKR033873@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ngie Date: Sun Nov 16 07:55:28 2014 New Revision: 274581 URL: https://svnweb.freebsd.org/changeset/base/274581 Log: Convert tools/regression/lib/libc/gen/test-arc4random into an ATF testcase and rename as lib/libc/gen/arc4random_test Sponsored by: EMC / Isilon Storage Division Added: head/lib/libc/tests/gen/arc4random_test.c - copied, changed from r274390, head/tools/regression/lib/libc/gen/test-arc4random.c Deleted: head/tools/regression/lib/libc/gen/test-arc4random.c Modified: head/lib/libc/tests/gen/Makefile Modified: head/lib/libc/tests/gen/Makefile ============================================================================== --- head/lib/libc/tests/gen/Makefile Sun Nov 16 07:03:19 2014 (r274580) +++ head/lib/libc/tests/gen/Makefile Sun Nov 16 07:55:28 2014 (r274581) @@ -4,6 +4,8 @@ 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) Copied and modified: head/lib/libc/tests/gen/arc4random_test.c (from r274390, head/tools/regression/lib/libc/gen/test-arc4random.c) ============================================================================== --- head/tools/regression/lib/libc/gen/test-arc4random.c Tue Nov 11 18:15:05 2014 (r274390, copy source) +++ head/lib/libc/tests/gen/arc4random_test.c Sun Nov 16 07:55:28 2014 (r274581) @@ -27,13 +27,14 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <sys/mman.h> #include <sys/types.h> +#include <sys/mman.h> #include <sys/wait.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <atf-c.h> /* * BUFSIZE is the number of bytes of rc4 output to compare. The probability @@ -45,7 +46,9 @@ __FBSDID("$FreeBSD$"); * 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[]) { +ATF_TC_WITHOUT_HEAD(test_arc4random); +ATF_TC_BODY(test_arc4random, tc) +{ struct shared_page { char parentbuf[BUFSIZE]; char childbuf[BUFSIZE]; @@ -65,10 +68,7 @@ int main(int argc, char *argv[]) { arc4random_buf(&c, 1); pid = fork(); - if (pid < 0) { - printf("fail 1 - fork\n"); - exit(1); - } + ATF_REQUIRE(0 <= pid); if (pid == 0) { /* child */ arc4random_buf(page->childbuf, BUFSIZE); @@ -79,11 +79,14 @@ int main(int argc, char *argv[]) { 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); - } + 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); - printf("ok 1 - sequences are different\n"); - exit(0); + return (atf_no_error()); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201411160755.sAG7tTKR033873>