Author: ngie
Date: Sat Dec  5 04:17:40 2015
New Revision: 291840
URL: https://svnweb.freebsd.org/changeset/base/291840

Log:
  MFC r290537,r290540,r290560,r290856,r290871,r291839:
  
  r290537:
  
  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
  
  Sponsored by: EMC / Isilon Storage Division
  
  r290540:
  
  printfloat_test and scanfloat_test need symbols from msun; these are 
automatically
  provided on amd64, but not i386. Add libm to DPADD/LDADD to unbreak the i386
  tinderbox
  
  Pointyhat to: ngie
  Sponsored by: EMC / Isilon Storage Division
  
  r290560:
  
  Convert print_positional_test over to ATF
  
  Somehow missed in r290537
  
  Sponsored by: EMC / Isilon Storage Division
  
  r290856 (by bapt):
  
  also skip the definition of ':fopen_regular' to avoid the build to fail due to
  unused variables defined by ATF macros
  
  r290871:
  
  Disable -Wformat with scanfloat_test when compiling with gcc to avoid a
  "use of assignment suppression and length modifier together in scanf format"
  warning on line 90 (it's intentional)
  
  Sponsored by: EMC / Isilon Storage Division
  
  r291839:
  
  Initialize errno to 0 in the nul testcase before testing it
  
  For some odd reason stable/10 requires this, otherwise it always fails
  the errno == 0 check on line 196.
  
  Sponsored by: EMC / Isilon Storage Division

Added:
  stable/10/lib/libc/tests/stdio/fdopen_test.c
     - copied unchanged from r290537, head/lib/libc/tests/stdio/fdopen_test.c
  stable/10/lib/libc/tests/stdio/fopen_test.c
     - copied unchanged from r290537, head/lib/libc/tests/stdio/fopen_test.c
  stable/10/lib/libc/tests/stdio/freopen_test.c
     - copied unchanged from r290537, head/lib/libc/tests/stdio/freopen_test.c
  stable/10/lib/libc/tests/stdio/getdelim_test.c
     - copied, changed from r290537, head/lib/libc/tests/stdio/getdelim_test.c
  stable/10/lib/libc/tests/stdio/mkostemp_test.c
     - copied unchanged from r290537, head/lib/libc/tests/stdio/mkostemp_test.c
  stable/10/lib/libc/tests/stdio/open_memstream_test.c
     - copied unchanged from r290537, 
head/lib/libc/tests/stdio/open_memstream_test.c
  stable/10/lib/libc/tests/stdio/open_wmemstream_test.c
     - copied unchanged from r290537, 
head/lib/libc/tests/stdio/open_wmemstream_test.c
  stable/10/lib/libc/tests/stdio/perror_test.c
     - copied unchanged from r290537, head/lib/libc/tests/stdio/perror_test.c
  stable/10/lib/libc/tests/stdio/print_positional_test.c
     - copied, changed from r290537, 
head/lib/libc/tests/stdio/print_positional_test.c
  stable/10/lib/libc/tests/stdio/printbasic_test.c
     - copied unchanged from r290537, 
head/lib/libc/tests/stdio/printbasic_test.c
  stable/10/lib/libc/tests/stdio/printfloat_test.c
     - copied unchanged from r290537, 
head/lib/libc/tests/stdio/printfloat_test.c
  stable/10/lib/libc/tests/stdio/scanfloat_test.c
     - copied unchanged from r290537, head/lib/libc/tests/stdio/scanfloat_test.c
Modified:
  stable/10/lib/libc/tests/stdio/Makefile
  stable/10/lib/libc/tests/stdio/fmemopen2_test.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/tests/stdio/Makefile
==============================================================================
--- stable/10/lib/libc/tests/stdio/Makefile     Sat Dec  5 04:10:15 2015        
(r291839)
+++ stable/10/lib/libc/tests/stdio/Makefile     Sat Dec  5 04:17:40 2015        
(r291840)
@@ -1,8 +1,24 @@
 # $FreeBSD$
 
+.include <bsd.own.mk>
+
 TESTSDIR=      ${TESTSBASE}/lib/libc/stdio
 
-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
@@ -14,6 +30,18 @@ NETBSD_ATF_TESTS_C+= popen_test
 NETBSD_ATF_TESTS_C+=   printf_test
 NETBSD_ATF_TESTS_C+=   scanf_test
 
+DPADD.printfloat_test+=        ${LIBM}
+LDADD.printfloat_test+=        -lm
+
+DPADD.scanfloat_test+= ${LIBM}
+LDADD.scanfloat_test+= -lm
+
+.if ${COMPILER_TYPE} == "gcc"
+# 90: use of assignment suppression and length modifier together in scanf 
format
+PROG_OVERRIDE_VARS+=   NO_WFORMAT
+NO_WFORMAT.scanfloat_test=
+.endif
+
 .include "../Makefile.netbsd-tests"
 
 .include <bsd.test.mk>

Copied: stable/10/lib/libc/tests/stdio/fdopen_test.c (from r290537, 
head/lib/libc/tests/stdio/fdopen_test.c)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/lib/libc/tests/stdio/fdopen_test.c        Sat Dec  5 04:17:40 
2015        (r291840, copy of r290537, head/lib/libc/tests/stdio/fdopen_test.c)
@@ -0,0 +1,225 @@
+/*-
+ * Copyright (c) 2014 Jilles Tjoelker
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <errno.h>
+#include <fcntl.h>
+#include <paths.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+static void
+runtest(const char *fname, int intmode, const char *strmode, bool success)
+{
+       FILE *fp;
+       int fd;
+
+       fd = open(fname, intmode);
+       ATF_REQUIRE_MSG(fd != -1,
+           "open(\"%s\", %#x) failed; errno=%d", fname, intmode, errno);
+
+       fp = fdopen(fd, strmode);
+       if (fp == NULL) {
+               close(fd);
+               ATF_REQUIRE_MSG(success == false,
+                   "fdopen(open(\"%s\", %#x), \"%s\") succeeded unexpectedly",
+                   fname, intmode, strmode);
+               return;
+       }
+       ATF_REQUIRE_MSG(success == true,
+           "fdopen(open(\"%s\", %#x), \"%s\") failed; errno=%d",
+           fname, intmode, strmode, errno);
+       fclose(fp);
+}
+
+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)
+{
+
+       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);
+}
+
+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
+ */

Modified: stable/10/lib/libc/tests/stdio/fmemopen2_test.c
==============================================================================
--- stable/10/lib/libc/tests/stdio/fmemopen2_test.c     Sat Dec  5 04:10:15 
2015        (r291839)
+++ stable/10/lib/libc/tests/stdio/fmemopen2_test.c     Sat Dec  5 04:17:40 
2015        (r291840)
@@ -35,15 +35,13 @@ __FBSDID("$FreeBSD$");
 #include <stdio.h>
 #include <string.h>
 #include <strings.h>
+
 #include <atf-c.h>
 
 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.
@@ -105,10 +103,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;
@@ -129,9 +124,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);
 
@@ -172,10 +165,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);
@@ -263,9 +253,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));
@@ -275,9 +263,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: stable/10/lib/libc/tests/stdio/fopen_test.c (from r290537, 
head/lib/libc/tests/stdio/fopen_test.c)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/lib/libc/tests/stdio/fopen_test.c Sat Dec  5 04:17:40 2015        
(r291840, copy of r290537, head/lib/libc/tests/stdio/fopen_test.c)
@@ -0,0 +1,205 @@
+/*-
+ * Copyright (c) 2013 Jilles Tjoelker
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <fcntl.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+/*
+ * O_ACCMODE is currently defined incorrectly. This is what it should be.
+ * Various code depends on the incorrect value.
+ */
+#define CORRECT_O_ACCMODE (O_ACCMODE | O_EXEC)
+
+static void
+runtest(const char *fname, const char *mode)
+{
+       FILE *fp;
+       int exp_fget_ret, fget_ret, fd, flags, wantedflags;
+
+       fp = fopen(fname, mode);
+       ATF_REQUIRE_MSG(fp != NULL,
+           "fopen(\"%s\", \"%s\") failed", fname, mode);
+       fd = fileno(fp);
+       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);
+       else if (*mode == 'r')
+               wantedflags = O_RDONLY;
+       else if (*mode == 'w')
+               wantedflags = O_WRONLY;
+       else if (*mode == 'a')
+               wantedflags = O_WRONLY | O_APPEND;
+       else
+               wantedflags = -1;
+       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);
+}
+
+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)
+{
+
+       runtest(_PATH_DEVNULL, "ae+");
+}
+
+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: stable/10/lib/libc/tests/stdio/freopen_test.c (from r290537, 
head/lib/libc/tests/stdio/freopen_test.c)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/lib/libc/tests/stdio/freopen_test.c       Sat Dec  5 04:17:40 
2015        (r291840, copy of r290537, head/lib/libc/tests/stdio/freopen_test.c)
@@ -0,0 +1,224 @@
+/*-
+ * Copyright (c) 2014 Jilles Tjoelker
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <errno.h>
+#include <paths.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+static void
+runtest(const char *fname1, const char *mode1, const char *fname2,
+    const char *mode2, bool success)
+{
+       FILE *fp1, *fp2;
+       const char *fname2_print;
+
+       fname2_print = fname2 != NULL ? fname2 : "<NULL>";
+       fp1 = fopen(fname1, mode1);
+       ATF_REQUIRE_MSG(fp1 != NULL,
+           "fopen(\"%s\", \"%s\") failed; errno=%d", fname1, mode1, errno);
+       fp2 = freopen(fname2, mode2, fp1);
+       if (fp2 == NULL) {
+               fclose(fp1);
+               ATF_REQUIRE_MSG(success == false,
+                   "freopen(\"%s\", \"%s\", fopen(\"%s\", \"%s\")) succeeded "
+                   "unexpectedly", fname2_print, mode2, fname1, mode1);
+               return;
+       }
+       ATF_REQUIRE_MSG(success == true,
+           "freopen(\"%s\", \"%s\", fopen(\"%s\", \"%s\")) failed: %d",
+           fname2_print, mode2, fname1, mode1, errno);
+       fclose(fp2);
+}
+
+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)
+{
+
+       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);
+}
+
+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);
+}
+
+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
+ */

Copied and modified: stable/10/lib/libc/tests/stdio/getdelim_test.c (from 
r290537, head/lib/libc/tests/stdio/getdelim_test.c)
==============================================================================
--- head/lib/libc/tests/stdio/getdelim_test.c   Sun Nov  8 06:37:50 2015        
(r290537, copy source)
+++ stable/10/lib/libc/tests/stdio/getdelim_test.c      Sat Dec  5 04:17:40 
2015        (r291840)
@@ -166,6 +166,7 @@ ATF_TC_BODY(eof, tc)
        ATF_REQUIRE(linecap > 0);
        ATF_REQUIRE(errno == 0);
        printf("feof\n");
+       errno = 0;
        ATF_REQUIRE(feof(fp));
        ATF_REQUIRE(!ferror(fp));
        fclose(fp);
@@ -178,6 +179,7 @@ ATF_TC_BODY(nul, tc)
        char *line;
        size_t linecap, n;
 
+       errno = 0;
        line = NULL;
        linecap = 0;
        /* Make sure a NUL delimiter works. */

Copied: stable/10/lib/libc/tests/stdio/mkostemp_test.c (from r290537, 
head/lib/libc/tests/stdio/mkostemp_test.c)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/lib/libc/tests/stdio/mkostemp_test.c      Sat Dec  5 04:17:40 
2015        (r291840, copy of r290537, 
head/lib/libc/tests/stdio/mkostemp_test.c)
@@ -0,0 +1,185 @@
+/*-
+ * Copyright (c) 2013 Jilles Tjoelker
+ * 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.
+ */
+
+/*
+ * Test program for mkostemp().
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+static const char template[] = "mkostemp.XXXXXXXX";
+static int testnum;
+
+#define MISCFLAGS (O_APPEND | O_DIRECT | O_SHLOCK | O_EXLOCK | O_SYNC)
+
+static void
+test_one(int oflags)
+{
+       char tmpf[sizeof(template)];
+       struct stat st1, st2;
+       int fd;
+
+       memcpy(tmpf, template, sizeof(tmpf));
+       fd = mkostemp(tmpf, oflags);
+       if (fd < 0) {
+               printf("not ok %d - oflags=%#x "
+                   "mkostemp() reported failure: %s\n",
+                   testnum++, oflags, strerror(errno));
+               return;
+       }
+       if (memcmp(tmpf, template, sizeof(tmpf) - 8 - 1) != 0) {
+               printf("not ok %d - oflags=%#x "
+                   "returned pathname does not match template: %s\n",
+                   testnum++, oflags, tmpf);
+               return;
+       }
+       do {
+               if (fcntl(fd, F_GETFD) !=
+                   (oflags & O_CLOEXEC ? FD_CLOEXEC : 0)) {
+                       printf("not ok %d - oflags=%#x "
+                           "close-on-exec flag incorrect\n",
+                           testnum++, oflags);
+                       break;
+               }
+               if ((fcntl(fd, F_GETFL) & MISCFLAGS) != (oflags & MISCFLAGS)) {
+                       printf("not ok %d - oflags=%#x "
+                           "open flags incorrect\n",
+                           testnum++, oflags);
+                       break;
+               }
+               if (stat(tmpf, &st1) == -1) {
+                       printf("not ok %d - oflags=%#x "
+                           "cannot stat returned pathname %s: %s\n",
+                           testnum++, oflags, tmpf, strerror(errno));
+                       break;
+               }
+               if (fstat(fd, &st2) == -1) {
+                       printf("not ok %d - oflags=%#x "
+                           "cannot fstat returned fd %d: %s\n",
+                           testnum++, oflags, fd, strerror(errno));
+                       break;
+               }
+               if (!S_ISREG(st1.st_mode) || (st1.st_mode & 0777) != 0600 ||
+                   st1.st_nlink != 1 || st1.st_size != 0) {
+                       printf("not ok %d - oflags=%#x "
+                           "named file attributes incorrect\n",
+                           testnum++, oflags);
+                       break;
+               }
+               if (!S_ISREG(st2.st_mode) || (st2.st_mode & 0777) != 0600 ||
+                   st2.st_nlink != 1 || st2.st_size != 0) {
+                       printf("not ok %d - oflags=%#x "
+                           "opened file attributes incorrect\n",
+                           testnum++, oflags);
+                       break;
+               }
+               if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) {
+                       printf("not ok %d - oflags=%#x "
+                           "named and opened file do not match\n",
+                           testnum++, oflags);
+                       break;
+               }
+               (void)unlink(tmpf);
+               if (fstat(fd, &st2) == -1)
+                       printf("not ok %d - oflags=%#x "
+                           "cannot fstat returned fd %d again: %s\n",
+                           testnum++, oflags, fd, strerror(errno));
+               else if (st2.st_nlink != 0)
+                       printf("not ok %d - oflags=%#x "
+                           "st_nlink is not 0 after unlink\n",
+                           testnum++, oflags);
+               else
+                       printf("ok %d - oflags=%#x\n", testnum++, oflags);
+               (void)close(fd);
+               return;
+       } while (0);
+       (void)close(fd);
+       (void)unlink(tmpf);
+}
+
+ATF_TC_WITHOUT_HEAD(zero);
+ATF_TC_BODY(zero, tc)
+{
+
+       test_one(0);
+}
+
+ATF_TC_WITHOUT_HEAD(O_CLOEXEC);
+ATF_TC_BODY(O_CLOEXEC, tc)
+{
+
+       test_one(O_CLOEXEC);
+}
+
+ATF_TC_WITHOUT_HEAD(O_APPEND);
+ATF_TC_BODY(O_APPEND, tc)
+{
+
+       test_one(O_APPEND);
+}
+
+ATF_TC_WITHOUT_HEAD(O_APPEND__O_CLOEXEC);
+ATF_TC_BODY(O_APPEND__O_CLOEXEC, tc)
+{
+
+       test_one(O_APPEND|O_CLOEXEC);
+}
+
+ATF_TC_WITHOUT_HEAD(bad_flags);
+ATF_TC_BODY(bad_flags, tc)
+{
+
+       char tmpf[sizeof(template)];
+
+       memcpy(tmpf, template, sizeof(tmpf));
+       ATF_REQUIRE_MSG(mkostemp(tmpf, O_CREAT) == -1,
+               "mkostemp(O_CREAT) succeeded unexpectedly");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, zero);
+       ATF_TP_ADD_TC(tp, O_CLOEXEC);
+       ATF_TP_ADD_TC(tp, O_APPEND);
+       ATF_TP_ADD_TC(tp, O_APPEND__O_CLOEXEC);
+       ATF_TP_ADD_TC(tp, bad_flags);
+

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "[email protected]"

Reply via email to