From owner-svn-src-all@freebsd.org Sun Nov 8 06:37:52 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0D57AA29720; Sun, 8 Nov 2015 06:37:52 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AE7EF1825; Sun, 8 Nov 2015 06:37:51 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tA86boko049661; Sun, 8 Nov 2015 06:37:50 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tA86bo8V049654; Sun, 8 Nov 2015 06:37:50 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201511080637.tA86bo8V049654@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Garrett Cooper Date: Sun, 8 Nov 2015 06:37:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290537 - in head: lib/libc/tests/stdio tools/regression/lib/libc/stdio X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Nov 2015 06:37:52 -0000 Author: ngie Date: Sun Nov 8 06:37:50 2015 New Revision: 290537 URL: https://svnweb.freebsd.org/changeset/base/290537 Log: Integrate tools/regression/lib/libc/stdio into the FreeBSD test suite as lib/libc/tests/stdio - Fix some whitespace - Convert the testcases to ATF - Convert "/dev/null" to _PATH_DEVNULL MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Added: head/lib/libc/tests/stdio/fdopen_test.c - copied, changed from r290536, head/tools/regression/lib/libc/stdio/test-fdopen.c head/lib/libc/tests/stdio/fopen_test.c - copied, changed from r290536, head/tools/regression/lib/libc/stdio/test-fopen.c head/lib/libc/tests/stdio/freopen_test.c - copied, changed from r290536, head/tools/regression/lib/libc/stdio/test-freopen.c head/lib/libc/tests/stdio/getdelim_test.c - copied, changed from r290536, head/tools/regression/lib/libc/stdio/test-getdelim.c head/lib/libc/tests/stdio/mkostemp_test.c - copied, changed from r290536, head/tools/regression/lib/libc/stdio/test-mkostemp.c head/lib/libc/tests/stdio/open_memstream_test.c - copied, changed from r290536, head/tools/regression/lib/libc/stdio/test-open_memstream.c head/lib/libc/tests/stdio/open_wmemstream_test.c - copied, changed from r290536, head/tools/regression/lib/libc/stdio/test-open_wmemstream.c head/lib/libc/tests/stdio/perror_test.c - copied, changed from r290536, head/tools/regression/lib/libc/stdio/test-perror.c head/lib/libc/tests/stdio/print_positional_test.c - copied unchanged from r290536, head/tools/regression/lib/libc/stdio/test-print-positional.c head/lib/libc/tests/stdio/printbasic_test.c - copied, changed from r290536, head/tools/regression/lib/libc/stdio/test-printbasic.c head/lib/libc/tests/stdio/printfloat_test.c - copied, changed from r290536, head/tools/regression/lib/libc/stdio/test-printfloat.c head/lib/libc/tests/stdio/scanfloat_test.c - copied, changed from r290536, head/tools/regression/lib/libc/stdio/test-scanfloat.c Deleted: head/tools/regression/lib/libc/stdio/ Modified: head/lib/libc/tests/stdio/Makefile head/lib/libc/tests/stdio/fmemopen2_test.c Modified: head/lib/libc/tests/stdio/Makefile ============================================================================== --- head/lib/libc/tests/stdio/Makefile Sun Nov 8 04:15:52 2015 (r290536) +++ head/lib/libc/tests/stdio/Makefile Sun Nov 8 06:37:50 2015 (r290537) @@ -1,6 +1,20 @@ # $FreeBSD$ -ATF_TESTS_C= fmemopen2_test +ATF_TESTS_C+= fdopen_test +ATF_TESTS_C+= fmemopen2_test +ATF_TESTS_C+= fopen2_test +ATF_TESTS_C+= freopen_test +ATF_TESTS_C+= getdelim_test +ATF_TESTS_C+= mkostemp_test +ATF_TESTS_C+= open_memstream_test +ATF_TESTS_C+= open_wmemstream_test +ATF_TESTS_C+= perror_test +ATF_TESTS_C+= print_positional_test +ATF_TESTS_C+= printbasic_test +ATF_TESTS_C+= printfloat_test +ATF_TESTS_C+= scanfloat_test + +SRCS.fopen2_test= fopen_test.c NETBSD_ATF_TESTS_C= clearerr_test NETBSD_ATF_TESTS_C+= fflush_test Copied and modified: head/lib/libc/tests/stdio/fdopen_test.c (from r290536, head/tools/regression/lib/libc/stdio/test-fdopen.c) ============================================================================== --- head/tools/regression/lib/libc/stdio/test-fdopen.c Sun Nov 8 04:15:52 2015 (r290536, copy source) +++ head/lib/libc/tests/stdio/fdopen_test.c Sun Nov 8 06:37:50 2015 (r290537) @@ -27,13 +27,15 @@ #include __FBSDID("$FreeBSD$"); -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include -static int testnum = 1; +#include static void runtest(const char *fname, int intmode, const char *strmode, bool success) @@ -42,64 +44,182 @@ runtest(const char *fname, int intmode, int fd; fd = open(fname, intmode); - if (fd == -1) { - printf("not ok %d - open(\"%s\", %#x) failed\n", - testnum++, fname, intmode); - return; - } + ATF_REQUIRE_MSG(fd != -1, + "open(\"%s\", %#x) failed; errno=%d", fname, intmode, errno); + fp = fdopen(fd, strmode); if (fp == NULL) { close(fd); - if (success) - printf("not ok %d - " - "fdopen(open(\"%s\", %#x), \"%s\") failed\n", - testnum++, fname, intmode, strmode); - else - printf("ok %d - " - "fdopen(open(\"%s\", %#x), \"%s\") failed\n", - testnum++, fname, intmode, strmode); + ATF_REQUIRE_MSG(success == false, + "fdopen(open(\"%s\", %#x), \"%s\") succeeded unexpectedly", + fname, intmode, strmode); return; } - if (success) - printf("ok %d - " - "fdopen(open(\"%s\", %#x), \"%s\") succeeded\n", - testnum++, fname, intmode, strmode); - else - printf("not ok %d - " - "fdopen(open(\"%s\", %#x), \"%s\") succeeded\n", - testnum++, fname, intmode, strmode); + ATF_REQUIRE_MSG(success == true, + "fdopen(open(\"%s\", %#x), \"%s\") failed; errno=%d", + fname, intmode, strmode, errno); fclose(fp); } -/* - * Test program for fdopen(). - */ -int -main(int argc, char *argv[]) +ATF_TC_WITHOUT_HEAD(null__O_RDONLY__r_test); +ATF_TC_BODY(null__O_RDONLY__r_test, tc) +{ + + runtest(_PATH_DEVNULL, O_RDONLY, "r", true); +} + +ATF_TC_WITHOUT_HEAD(null__O_WRONLY__r_test); +ATF_TC_BODY(null__O_WRONLY__r_test, tc) +{ + + runtest(_PATH_DEVNULL, O_WRONLY, "r", false); +} + +ATF_TC_WITHOUT_HEAD(null__O_RDWR__r_test); +ATF_TC_BODY(null__O_RDWR__r_test, tc) +{ + + runtest(_PATH_DEVNULL, O_RDWR, "r", true); +} + +ATF_TC_WITHOUT_HEAD(null__O_RDONLY__w_test); +ATF_TC_BODY(null__O_RDONLY__w_test, tc) +{ + + runtest(_PATH_DEVNULL, O_RDONLY, "w", false); +} + +ATF_TC_WITHOUT_HEAD(null__O_WRONLY__w_test); +ATF_TC_BODY(null__O_WRONLY__w_test, tc) +{ + + runtest(_PATH_DEVNULL, O_WRONLY, "w", true); +} + +ATF_TC_WITHOUT_HEAD(null__O_RDWR__w_test); +ATF_TC_BODY(null__O_RDWR__w_test, tc) +{ + + runtest(_PATH_DEVNULL, O_RDWR, "w", true); +} + +ATF_TC_WITHOUT_HEAD(null__O_RDONLY__a_test); +ATF_TC_BODY(null__O_RDONLY__a_test, tc) +{ + + runtest(_PATH_DEVNULL, O_RDONLY, "a", false); +} + +ATF_TC_WITHOUT_HEAD(null__O_WRONLY__a_test); +ATF_TC_BODY(null__O_WRONLY__a_test, tc) +{ + + runtest(_PATH_DEVNULL, O_WRONLY, "a", true); +} + +ATF_TC_WITHOUT_HEAD(null__O_RDWR__test); +ATF_TC_BODY(null__O_RDWR__test, tc) +{ + + runtest(_PATH_DEVNULL, O_RDWR, "a", true); +} + +ATF_TC_WITHOUT_HEAD(null__O_RDONLY__r_append); +ATF_TC_BODY(null__O_RDONLY__r_append, tc) +{ + + runtest(_PATH_DEVNULL, O_RDONLY, "r+", false); +} + +ATF_TC_WITHOUT_HEAD(null__O_WRONLY__r_append); +ATF_TC_BODY(null__O_WRONLY__r_append, tc) +{ + + runtest(_PATH_DEVNULL, O_WRONLY, "r+", false); +} + +ATF_TC_WITHOUT_HEAD(null__O_RDWR__r_append); +ATF_TC_BODY(null__O_RDWR__r_append, tc) +{ + + runtest(_PATH_DEVNULL, O_RDWR, "r+", true); +} + +ATF_TC_WITHOUT_HEAD(null__O_RDONLY__w_append); +ATF_TC_BODY(null__O_RDONLY__w_append, tc) +{ + + runtest(_PATH_DEVNULL, O_RDONLY, "w+", false); +} + +ATF_TC_WITHOUT_HEAD(null__O_WRONLY__w_append); +ATF_TC_BODY(null__O_WRONLY__w_append, tc) +{ + + runtest(_PATH_DEVNULL, O_WRONLY, "w+", false); +} + +ATF_TC_WITHOUT_HEAD(null__O_RDWR__w_append); +ATF_TC_BODY(null__O_RDWR__w_append, tc) +{ + + runtest(_PATH_DEVNULL, O_RDWR, "w+", true); +} + +ATF_TC_WITHOUT_HEAD(sh__O_EXEC__r); +ATF_TC_BODY(sh__O_EXEC__r, tc) { - printf("1..19\n"); - runtest("/dev/null", O_RDONLY, "r", true); - runtest("/dev/null", O_WRONLY, "r", false); - runtest("/dev/null", O_RDWR, "r", true); - runtest("/dev/null", O_RDONLY, "w", false); - runtest("/dev/null", O_WRONLY, "w", true); - runtest("/dev/null", O_RDWR, "w", true); - runtest("/dev/null", O_RDONLY, "a", false); - runtest("/dev/null", O_WRONLY, "a", true); - runtest("/dev/null", O_RDWR, "a", true); - runtest("/dev/null", O_RDONLY, "r+", false); - runtest("/dev/null", O_WRONLY, "r+", false); - runtest("/dev/null", O_RDWR, "r+", true); - runtest("/dev/null", O_RDONLY, "w+", false); - runtest("/dev/null", O_WRONLY, "w+", false); - runtest("/dev/null", O_RDWR, "w+", true); + runtest("/bin/sh", O_EXEC, "r", false); +} + +ATF_TC_WITHOUT_HEAD(sh__O_EXEC__w); +ATF_TC_BODY(sh__O_EXEC__w, tc) +{ + runtest("/bin/sh", O_EXEC, "w", false); +} + +ATF_TC_WITHOUT_HEAD(sh__O_EXEC__r_append); +ATF_TC_BODY(sh__O_EXEC__r_append, tc) +{ + runtest("/bin/sh", O_EXEC, "r+", false); +} + +ATF_TC_WITHOUT_HEAD(sh__O_EXEC__w_append); +ATF_TC_BODY(sh__O_EXEC__w_append, tc) +{ + runtest("/bin/sh", O_EXEC, "w+", false); +} - return 0; +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, null__O_RDONLY__r_test); + ATF_TP_ADD_TC(tp, null__O_WRONLY__r_test); + ATF_TP_ADD_TC(tp, null__O_RDWR__r_test); + ATF_TP_ADD_TC(tp, null__O_RDONLY__w_test); + ATF_TP_ADD_TC(tp, null__O_WRONLY__w_test); + ATF_TP_ADD_TC(tp, null__O_RDWR__w_test); + ATF_TP_ADD_TC(tp, null__O_RDONLY__a_test); + ATF_TP_ADD_TC(tp, null__O_WRONLY__a_test); + ATF_TP_ADD_TC(tp, null__O_RDWR__test); + ATF_TP_ADD_TC(tp, null__O_RDONLY__r_append); + ATF_TP_ADD_TC(tp, null__O_WRONLY__r_append); + ATF_TP_ADD_TC(tp, null__O_RDWR__r_append); + ATF_TP_ADD_TC(tp, null__O_RDONLY__w_append); + ATF_TP_ADD_TC(tp, null__O_WRONLY__w_append); + ATF_TP_ADD_TC(tp, null__O_RDWR__w_append); + ATF_TP_ADD_TC(tp, sh__O_EXEC__r); + ATF_TP_ADD_TC(tp, sh__O_EXEC__w); + ATF_TP_ADD_TC(tp, sh__O_EXEC__r_append); + ATF_TP_ADD_TC(tp, sh__O_EXEC__w_append); + + return (atf_no_error()); } -/* vim:ts=8:cin:sw=8 - * */ +/* + vim:ts=8:cin:sw=8 + */ Modified: head/lib/libc/tests/stdio/fmemopen2_test.c ============================================================================== --- head/lib/libc/tests/stdio/fmemopen2_test.c Sun Nov 8 04:15:52 2015 (r290536) +++ head/lib/libc/tests/stdio/fmemopen2_test.c Sun Nov 8 06:37:50 2015 (r290537) @@ -35,15 +35,13 @@ __FBSDID("$FreeBSD$"); #include #include #include + #include ATF_TC_WITHOUT_HEAD(test_preexisting); ATF_TC_BODY(test_preexisting, tc) { - /* - * Use a pre-existing buffer. - */ - + /* Use a pre-existing buffer. */ char buf[512]; char buf2[512]; char str[] = "Test writing some stuff"; @@ -74,7 +72,7 @@ ATF_TC_BODY(test_preexisting, tc) nofr = fread(buf2, 1, sizeof(buf2), fp); ATF_REQUIRE(nofr == sizeof(buf2)); - /* + /* * Since a write on a FILE * retrieved by fmemopen * will add a '\0' (if there's space), we can check * the strings for equality. @@ -106,10 +104,7 @@ ATF_TC_BODY(test_preexisting, tc) ATF_TC_WITHOUT_HEAD(test_autoalloc); ATF_TC_BODY(test_autoalloc, tc) { - /* - * Let fmemopen allocate the buffer. - */ - + /* Let fmemopen allocate the buffer. */ char str[] = "A quick test"; FILE *fp; long pos; @@ -130,9 +125,7 @@ ATF_TC_BODY(test_autoalloc, tc) pos = ftell(fp); ATF_REQUIRE(pos == 512); - /* - * Try to write past the end, we should get a short object count (0) - */ + /* Try to write past the end, we should get a short object count (0) */ nofw = fwrite("a", 1, 1, fp); ATF_REQUIRE(nofw == 0); @@ -173,10 +166,7 @@ ATF_TC_BODY(test_data_length, tc) nofw = fwrite(str, 1, sizeof(str), fp); ATF_REQUIRE(nofw == sizeof(str)); - /* - * Now seek to the end and check that ftell - * gives us sizeof(str). - */ + /* Now seek to the end and check that ftell gives us sizeof(str). */ rc = fseek(fp, 0, SEEK_END); ATF_REQUIRE(rc == 0); pos = ftell(fp); @@ -264,9 +254,7 @@ ATF_TC_BODY(test_append_binary_pos, tc) ATF_REQUIRE(ftell(fp) == 0L); fclose(fp); - /* - * Make sure that a pre-allocated buffer behaves correctly. - */ + /* Make sure that a pre-allocated buffer behaves correctly. */ char buf[] = "Hello"; fp = fmemopen(buf, sizeof(buf), "ab+"); ATF_REQUIRE(ftell(fp) == strlen(buf)); @@ -276,9 +264,7 @@ ATF_TC_BODY(test_append_binary_pos, tc) ATF_TC_WITHOUT_HEAD(test_size_0); ATF_TC_BODY(test_size_0, tc) { - /* - * POSIX mandates that we return EINVAL if size is 0. - */ + /* POSIX mandates that we return EINVAL if size is 0. */ FILE *fp; Copied and modified: head/lib/libc/tests/stdio/fopen_test.c (from r290536, head/tools/regression/lib/libc/stdio/test-fopen.c) ============================================================================== --- head/tools/regression/lib/libc/stdio/test-fopen.c Sun Nov 8 04:15:52 2015 (r290536, copy source) +++ head/lib/libc/tests/stdio/fopen_test.c Sun Nov 8 06:37:50 2015 (r290537) @@ -27,9 +27,12 @@ #include __FBSDID("$FreeBSD$"); -#include -#include -#include +#include +#include +#include +#include + +#include /* * O_ACCMODE is currently defined incorrectly. This is what it should be. @@ -37,32 +40,21 @@ __FBSDID("$FreeBSD$"); */ #define CORRECT_O_ACCMODE (O_ACCMODE | O_EXEC) -static int testnum = 1; - static void runtest(const char *fname, const char *mode) { FILE *fp; - int fd, flags, wantedflags; + int exp_fget_ret, fget_ret, fd, flags, wantedflags; fp = fopen(fname, mode); - if (fp == NULL) { - printf("not ok %d - fopen(\"%s\", \"%s\") failed\n", - testnum++, fname, mode); - printf("not ok %d - FD_CLOEXEC # SKIP\n", - testnum++); - return; - } + ATF_REQUIRE_MSG(fp != NULL, + "fopen(\"%s\", \"%s\") failed", fname, mode); fd = fileno(fp); - if (fd < 0) - printf("not ok %d - fileno() failed\n", testnum++); - else - printf("ok %d - fopen(\"%s\", \"%s\") and fileno() succeeded\n", - testnum++, fname, mode); - if (fcntl(fd, F_GETFD) == (strchr(mode, 'e') != NULL ? FD_CLOEXEC : 0)) - printf("ok %d - FD_CLOEXEC flag correct\n", testnum++); - else - printf("not ok %d - FD_CLOEXEC flag incorrect\n", testnum++); + ATF_REQUIRE_MSG(fd >= 0, "fileno() failed for fopen"); + exp_fget_ret = strchr(mode, 'e') != NULL ? FD_CLOEXEC : 0; + ATF_REQUIRE_MSG((fget_ret = fcntl(fd, F_GETFD)) == exp_fget_ret, + "fcntl(.., F_GETFD) didn't FD_CLOEXEC as expected %d != %d", + exp_fget_ret, fget_ret); flags = fcntl(fd, F_GETFL); if (strchr(mode, '+')) wantedflags = O_RDWR | (*mode == 'a' ? O_APPEND : 0); @@ -74,40 +66,140 @@ runtest(const char *fname, const char *m wantedflags = O_WRONLY | O_APPEND; else wantedflags = -1; - if (wantedflags == -1) - printf("not ok %d - unrecognized mode\n", testnum++); - else if ((flags & (CORRECT_O_ACCMODE | O_APPEND)) == wantedflags) - printf("ok %d - correct access mode\n", testnum++); - else - printf("not ok %d - incorrect access mode\n", testnum++); fclose(fp); + if (wantedflags == -1) + atf_tc_fail("unrecognized mode: %s", mode); + else if ((flags & (CORRECT_O_ACCMODE | O_APPEND)) != wantedflags) + atf_tc_fail("incorrect access mode: %s", mode); } -/* - * Test program for fopen(). - */ -int -main(int argc, char *argv[]) +ATF_TC_WITHOUT_HEAD(fopen_r_test); +ATF_TC_BODY(fopen_r_test, tc) +{ + + runtest(_PATH_DEVNULL, "r"); +} + +ATF_TC_WITHOUT_HEAD(fopen_r_append_test); +ATF_TC_BODY(fopen_r_append_test, tc) +{ + + runtest(_PATH_DEVNULL, "r+"); +} + +ATF_TC_WITHOUT_HEAD(fopen_w_test); +ATF_TC_BODY(fopen_w_test, tc) +{ + + runtest(_PATH_DEVNULL, "w"); +} + +ATF_TC_WITHOUT_HEAD(fopen_w_append_test); +ATF_TC_BODY(fopen_w_append_test, tc) +{ + + runtest(_PATH_DEVNULL, "w+"); +} + +ATF_TC_WITHOUT_HEAD(fopen_a_test); +ATF_TC_BODY(fopen_a_test, tc) +{ + + runtest(_PATH_DEVNULL, "a"); +} + +ATF_TC_WITHOUT_HEAD(fopen_a_append_test); +ATF_TC_BODY(fopen_a_append_test, tc) +{ + + runtest(_PATH_DEVNULL, "a+"); +} + +ATF_TC_WITHOUT_HEAD(fopen_re_test); +ATF_TC_BODY(fopen_re_test, tc) +{ + + runtest(_PATH_DEVNULL, "re"); +} + +ATF_TC_WITHOUT_HEAD(fopen_r_append_e_test); +ATF_TC_BODY(fopen_r_append_e_test, tc) +{ + + runtest(_PATH_DEVNULL, "r+e"); +} + +ATF_TC_WITHOUT_HEAD(fopen_we_test); +ATF_TC_BODY(fopen_we_test, tc) +{ + + runtest(_PATH_DEVNULL, "we"); +} + +ATF_TC_WITHOUT_HEAD(fopen_w_append_e_test); +ATF_TC_BODY(fopen_w_append_e_test, tc) +{ + + runtest(_PATH_DEVNULL, "w+e"); +} + +ATF_TC_WITHOUT_HEAD(fopen_ae_test); +ATF_TC_BODY(fopen_ae_test, tc) +{ + + runtest(_PATH_DEVNULL, "ae"); +} + +ATF_TC_WITHOUT_HEAD(fopen_a_append_e_test); +ATF_TC_BODY(fopen_a_append_e_test, tc) +{ + + runtest(_PATH_DEVNULL, "a+e"); +} + +ATF_TC_WITHOUT_HEAD(fopen_re_append_test); +ATF_TC_BODY(fopen_re_append_test, tc) +{ + + runtest(_PATH_DEVNULL, "re+"); +} + +ATF_TC_WITHOUT_HEAD(fopen_we_append_test); +ATF_TC_BODY(fopen_we_append_test, tc) +{ + + runtest(_PATH_DEVNULL, "we+"); +} + +ATF_TC_WITHOUT_HEAD(fopen_ae_append_test); +ATF_TC_BODY(fopen_ae_append_test, tc) { - printf("1..45\n"); - runtest("/dev/null", "r"); - runtest("/dev/null", "r+"); - runtest("/dev/null", "w"); - runtest("/dev/null", "w+"); - runtest("/dev/null", "a"); - runtest("/dev/null", "a+"); - runtest("/dev/null", "re"); - runtest("/dev/null", "r+e"); - runtest("/dev/null", "we"); - runtest("/dev/null", "w+e"); - runtest("/dev/null", "ae"); - runtest("/dev/null", "a+e"); - runtest("/dev/null", "re+"); - runtest("/dev/null", "we+"); - runtest("/dev/null", "ae+"); - return 0; + runtest(_PATH_DEVNULL, "ae+"); } -/* vim:ts=8:cin:sw=8 - * */ +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, fopen_r_test); + ATF_TP_ADD_TC(tp, fopen_r_append_test); + ATF_TP_ADD_TC(tp, fopen_w_test); + ATF_TP_ADD_TC(tp, fopen_w_append_test); + ATF_TP_ADD_TC(tp, fopen_a_test); + ATF_TP_ADD_TC(tp, fopen_a_append_test); + ATF_TP_ADD_TC(tp, fopen_re_test); + ATF_TP_ADD_TC(tp, fopen_r_append_e_test); + ATF_TP_ADD_TC(tp, fopen_we_test); + ATF_TP_ADD_TC(tp, fopen_w_append_e_test); + ATF_TP_ADD_TC(tp, fopen_ae_test); + ATF_TP_ADD_TC(tp, fopen_a_append_e_test); + ATF_TP_ADD_TC(tp, fopen_re_append_test); + ATF_TP_ADD_TC(tp, fopen_we_append_test); + ATF_TP_ADD_TC(tp, fopen_ae_append_test); + + return (atf_no_error()); +} + +/* + vim:ts=8:cin:sw=8 + */ Copied and modified: head/lib/libc/tests/stdio/freopen_test.c (from r290536, head/tools/regression/lib/libc/stdio/test-freopen.c) ============================================================================== --- head/tools/regression/lib/libc/stdio/test-freopen.c Sun Nov 8 04:15:52 2015 (r290536, copy source) +++ head/lib/libc/tests/stdio/freopen_test.c Sun Nov 8 06:37:50 2015 (r290537) @@ -27,11 +27,13 @@ #include __FBSDID("$FreeBSD$"); -#include -#include -#include +#include +#include +#include +#include +#include -static int testnum = 1; +#include static void runtest(const char *fname1, const char *mode1, const char *fname2, @@ -42,68 +44,181 @@ runtest(const char *fname1, const char * fname2_print = fname2 != NULL ? fname2 : ""; fp1 = fopen(fname1, mode1); - if (fp1 == NULL) { - printf("not ok %d - fopen(\"%s\", \"%s\") failed\n", - testnum++, fname1, mode1); - return; - } + ATF_REQUIRE_MSG(fp1 != NULL, + "fopen(\"%s\", \"%s\") failed; errno=%d", fname1, mode1, errno); fp2 = freopen(fname2, mode2, fp1); if (fp2 == NULL) { fclose(fp1); - if (success) - printf("not ok %d - " - "freopen(\"%s\", \"%s\", fopen(\"%s\", \"%s\")) " - "failed\n", - testnum++, fname2_print, mode2, fname1, mode1); - else - printf("ok %d - " - "freopen(\"%s\", \"%s\", fopen(\"%s\", \"%s\")) " - "failed\n", - testnum++, fname2_print, mode2, fname1, mode1); + ATF_REQUIRE_MSG(success == false, + "freopen(\"%s\", \"%s\", fopen(\"%s\", \"%s\")) succeeded " + "unexpectedly", fname2_print, mode2, fname1, mode1); return; } - if (success) - printf("ok %d - " - "freopen(\"%s\", \"%s\", fopen(\"%s\", \"%s\")) " - "succeeded\n", - testnum++, fname2_print, mode2, fname1, mode1); - else - printf("not ok %d - " - "freopen(\"%s\", \"%s\", fopen(\"%s\", \"%s\")) " - "succeeded\n", - testnum++, fname2_print, mode2, fname1, mode1); + ATF_REQUIRE_MSG(success == true, + "freopen(\"%s\", \"%s\", fopen(\"%s\", \"%s\")) failed: %d", + fname2_print, mode2, fname1, mode1, errno); fclose(fp2); } -/* - * Test program for freopen(). - */ -int -main(int argc, char *argv[]) +ATF_TC_WITHOUT_HEAD(null__r__r__test); +ATF_TC_BODY(null__r__r__test, tc) +{ + + runtest(_PATH_DEVNULL, "r", NULL, "r", true); +} + +ATF_TC_WITHOUT_HEAD(null__w__r__test); +ATF_TC_BODY(null__w__r__test, tc) +{ + + runtest(_PATH_DEVNULL, "w", NULL, "r", false); +} + +ATF_TC_WITHOUT_HEAD(null__r_append__r__test); +ATF_TC_BODY(null__r_append__r__test, tc) +{ + + runtest(_PATH_DEVNULL, "r+", NULL, "r", true); +} + +ATF_TC_WITHOUT_HEAD(null__r__w__test); +ATF_TC_BODY(null__r__w__test, tc) +{ + + runtest(_PATH_DEVNULL, "r", NULL, "w", false); +} + +ATF_TC_WITHOUT_HEAD(null__w__w__test); +ATF_TC_BODY(null__w__w__test, tc) +{ + + runtest(_PATH_DEVNULL, "w", NULL, "w", true); +} + +ATF_TC_WITHOUT_HEAD(null__r_append__w__test); +ATF_TC_BODY(null__r_append__w__test, tc) +{ + + runtest(_PATH_DEVNULL, "r+", NULL, "w", true); +} + +ATF_TC_WITHOUT_HEAD(null__r__a__test); +ATF_TC_BODY(null__r__a__test, tc) +{ + + runtest(_PATH_DEVNULL, "r", NULL, "a", false); +} + +ATF_TC_WITHOUT_HEAD(null__w__a__test); +ATF_TC_BODY(null__w__a__test, tc) { - printf("1..19\n"); - runtest("/dev/null", "r", NULL, "r", true); - runtest("/dev/null", "w", NULL, "r", false); - runtest("/dev/null", "r+", NULL, "r", true); - runtest("/dev/null", "r", NULL, "w", false); - runtest("/dev/null", "w", NULL, "w", true); - runtest("/dev/null", "r+", NULL, "w", true); - runtest("/dev/null", "r", NULL, "a", false); - runtest("/dev/null", "w", NULL, "a", true); - runtest("/dev/null", "r+", NULL, "a", true); - runtest("/dev/null", "r", NULL, "r+", false); - runtest("/dev/null", "w", NULL, "r+", false); - runtest("/dev/null", "r+", NULL, "r+", true); - runtest("/dev/null", "r", NULL, "w+", false); - runtest("/dev/null", "w", NULL, "w+", false); - runtest("/dev/null", "r+", NULL, "w+", true); + + runtest(_PATH_DEVNULL, "w", NULL, "a", true); +} + +ATF_TC_WITHOUT_HEAD(null__r_append__a__test); +ATF_TC_BODY(null__r_append__a__test, tc) +{ + + runtest(_PATH_DEVNULL, "r+", NULL, "a", true); +} + +ATF_TC_WITHOUT_HEAD(null__r__r_append__test); +ATF_TC_BODY(null__r__r_append__test, tc) +{ + + runtest(_PATH_DEVNULL, "r", NULL, "r+", false); +} + +ATF_TC_WITHOUT_HEAD(null__w__r_append__test); +ATF_TC_BODY(null__w__r_append__test, tc) +{ + + runtest(_PATH_DEVNULL, "w", NULL, "r+", false); +} + +ATF_TC_WITHOUT_HEAD(null__r_append__r_append__test); +ATF_TC_BODY(null__r_append__r_append__test, tc) +{ + + runtest(_PATH_DEVNULL, "r+", NULL, "r+", true); +} + +ATF_TC_WITHOUT_HEAD(null__r__w_append__test); +ATF_TC_BODY(null__r__w_append__test, tc) +{ + + runtest(_PATH_DEVNULL, "r", NULL, "w+", false); +} + +ATF_TC_WITHOUT_HEAD(null__w__w_append__test); +ATF_TC_BODY(null__w__w_append__test, tc) +{ + + runtest(_PATH_DEVNULL, "w", NULL, "w+", false); +} + +ATF_TC_WITHOUT_HEAD(null__r_append__w_append__test); +ATF_TC_BODY(null__r_append__w_append__test, tc) +{ + + runtest(_PATH_DEVNULL, "r+", NULL, "w+", true); +} + +ATF_TC_WITHOUT_HEAD(sh__r__r__test); +ATF_TC_BODY(sh__r__r__test, tc) +{ + runtest("/bin/sh", "r", NULL, "r", true); +} + +ATF_TC_WITHOUT_HEAD(sh__sh__r__r__test); +ATF_TC_BODY(sh__sh__r__r__test, tc) +{ + runtest("/bin/sh", "r", "/bin/sh", "r", true); - runtest("/bin/sh", "r", "/dev/null", "r", true); - runtest("/bin/sh", "r", "/dev/null", "w", true); +} + +ATF_TC_WITHOUT_HEAD(sh__null__r__r__test); +ATF_TC_BODY(sh__null__r__r__test, tc) +{ + + runtest("/bin/sh", "r", _PATH_DEVNULL, "r", true); +} + +ATF_TC_WITHOUT_HEAD(sh__null__r__w__test); +ATF_TC_BODY(sh__null__r__w__test, tc) +{ + + runtest("/bin/sh", "r", _PATH_DEVNULL, "w", true); +} - return 0; +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, null__r__r__test); + ATF_TP_ADD_TC(tp, null__w__r__test); + ATF_TP_ADD_TC(tp, null__r_append__r__test); + ATF_TP_ADD_TC(tp, null__r__w__test); + ATF_TP_ADD_TC(tp, null__w__w__test); + ATF_TP_ADD_TC(tp, null__r_append__w__test); + ATF_TP_ADD_TC(tp, null__r__a__test); + ATF_TP_ADD_TC(tp, null__w__a__test); + ATF_TP_ADD_TC(tp, null__r_append__a__test); + ATF_TP_ADD_TC(tp, null__r__r_append__test); + ATF_TP_ADD_TC(tp, null__w__r_append__test); + ATF_TP_ADD_TC(tp, null__r_append__r_append__test); + ATF_TP_ADD_TC(tp, null__r__w_append__test); + ATF_TP_ADD_TC(tp, null__w__w_append__test); + ATF_TP_ADD_TC(tp, null__r_append__w_append__test); + ATF_TP_ADD_TC(tp, sh__r__r__test); + ATF_TP_ADD_TC(tp, sh__sh__r__r__test); + ATF_TP_ADD_TC(tp, sh__null__r__r__test); + ATF_TP_ADD_TC(tp, sh__null__r__w__test); + + return (atf_no_error()); } -/* vim:ts=8:cin:sw=8 - * */ +/* + vim:ts=8:cin:sw=8 + */ Copied and modified: head/lib/libc/tests/stdio/getdelim_test.c (from r290536, head/tools/regression/lib/libc/stdio/test-getdelim.c) ============================================================================== --- head/tools/regression/lib/libc/stdio/test-getdelim.c Sun Nov 8 04:15:52 2015 (r290536, copy source) +++ head/lib/libc/tests/stdio/getdelim_test.c Sun Nov 8 06:37:50 2015 (r290537) @@ -28,12 +28,13 @@ __FBSDID("$FreeBSD$"); #define _WITH_GETLINE -#include #include #include #include #include +#include + #define CHUNK_MAX 10 /* The assertions depend on this string. */ @@ -70,18 +71,16 @@ mkfilebuf(void) return (fropen(offp, _reader)); } -int -main(int argc, char *argv[]) +ATF_TC_WITHOUT_HEAD(getline_basic); +ATF_TC_BODY(getline_basic, tc) { FILE *fp; char *line; size_t linecap; - int i, n; + int i; srandom(0); - printf("1..6\n"); - /* * Test multiple times with different buffer sizes * and different _reader() return values. @@ -92,96 +91,147 @@ main(int argc, char *argv[]) linecap = i; line = malloc(i); /* First line: the full apothegm */ - assert(getline(&line, &linecap, fp) == sizeof(apothegm) - 1); - assert(memcmp(line, apothegm, sizeof(apothegm)) == 0); - assert(linecap >= sizeof(apothegm)); + ATF_REQUIRE(getline(&line, &linecap, fp) == sizeof(apothegm) - 1); + ATF_REQUIRE(memcmp(line, apothegm, sizeof(apothegm)) == 0); + ATF_REQUIRE(linecap >= sizeof(apothegm)); /* Second line: the NUL terminator following the newline */ - assert(getline(&line, &linecap, fp) == 1); - assert(line[0] == '\0' && line[1] == '\0'); + ATF_REQUIRE(getline(&line, &linecap, fp) == 1); + ATF_REQUIRE(line[0] == '\0' && line[1] == '\0'); /* Third line: EOF */ line[0] = 'X'; - assert(getline(&line, &linecap, fp) == -1); - assert(line[0] == '\0'); + ATF_REQUIRE(getline(&line, &linecap, fp) == -1); + ATF_REQUIRE(line[0] == '\0'); free(line); line = NULL; - assert(feof(fp)); - assert(!ferror(fp)); + ATF_REQUIRE(feof(fp)); + ATF_REQUIRE(!ferror(fp)); fclose(fp); } - assert(errno == 0); - printf("ok 1 - getline basic\n"); + ATF_REQUIRE(errno == 0); +} + +ATF_TC_WITHOUT_HEAD(stream_error); +ATF_TC_BODY(stream_error, tc) +{ + FILE *fp; + char *line; + size_t linecap; /* Make sure read errors are handled properly. */ + line = NULL; linecap = 0; errno = 0; - assert(getline(&line, &linecap, stdout) == -1); - assert(errno == EBADF); + ATF_REQUIRE(getline(&line, &linecap, stdout) == -1); + ATF_REQUIRE(errno == EBADF); errno = 0; - assert(getdelim(&line, &linecap, 'X', stdout) == -1); - assert(errno == EBADF); - assert(ferror(stdout)); - printf("ok 2 - stream error\n"); + ATF_REQUIRE(getdelim(&line, &linecap, 'X', stdout) == -1); + ATF_REQUIRE(errno == EBADF); + ATF_REQUIRE(ferror(stdout)); +} + +ATF_TC_WITHOUT_HEAD(invalid_params); +ATF_TC_BODY(invalid_params, tc) +{ + FILE *fp; + char *line; + size_t linecap; /* Make sure NULL linep or linecapp pointers are handled. */ fp = mkfilebuf(); - assert(getline(NULL, &linecap, fp) == -1); - assert(errno == EINVAL); - assert(getline(&line, NULL, fp) == -1); - assert(errno == EINVAL); - assert(ferror(fp)); + ATF_REQUIRE(getline(NULL, &linecap, fp) == -1); + ATF_REQUIRE(errno == EINVAL); + ATF_REQUIRE(getline(&line, NULL, fp) == -1); + ATF_REQUIRE(errno == EINVAL); + ATF_REQUIRE(ferror(fp)); fclose(fp); - printf("ok 3 - invalid params\n"); +} + +ATF_TC_WITHOUT_HEAD(eof); +ATF_TC_BODY(eof, tc) +{ + FILE *fp; + char *line; + size_t linecap; /* Make sure getline() allocates memory as needed if fp is at EOF. */ errno = 0; fp = mkfilebuf(); while (!feof(fp)) /* advance to EOF; can't fseek this stream */ getc(fp); - free(line); line = NULL; linecap = 0; - assert(getline(&line, &linecap, fp) == -1); - assert(line[0] == '\0'); - assert(linecap > 0); - assert(errno == 0); - assert(feof(fp)); - assert(!ferror(fp)); + printf("getline\n"); + ATF_REQUIRE(getline(&line, &linecap, fp) == -1); + ATF_REQUIRE(line[0] == '\0'); + ATF_REQUIRE(linecap > 0); + ATF_REQUIRE(errno == 0); + printf("feof\n"); + ATF_REQUIRE(feof(fp)); + ATF_REQUIRE(!ferror(fp)); fclose(fp); - printf("ok 4 - eof\n"); +} + +ATF_TC_WITHOUT_HEAD(nul); *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***