Index: head/contrib/netbsd-tests/lib/libc/c063/t_faccessat.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/c063/t_faccessat.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/c063/t_faccessat.c (revision 311925) @@ -1,191 +1,189 @@ -/* $NetBSD: t_faccessat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */ +/* $NetBSD: t_faccessat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Emmanuel Dreyfus. * * 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 -__RCSID("$NetBSD: t_faccessat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $"); +__RCSID("$NetBSD: t_faccessat.c,v 1.3 2017/01/10 15:13:56 christos Exp $"); +#include +#include #include #include #include #include #include #include #include #include -#include -#ifdef __FreeBSD__ -#include -#endif #define DIR "dir" #define FILE "dir/faccessat" #define BASEFILE "faccessat" #define LINK "dir/symlink" #define BASELINK "symlink" #define FILEERR "dir/faccessaterr" ATF_TC(faccessat_fd); ATF_TC_HEAD(faccessat_fd, tc) { atf_tc_set_md_var(tc, "descr", "See that faccessat works with fd"); } ATF_TC_BODY(faccessat_fd, tc) { int dfd; int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(faccessat(dfd, BASEFILE, F_OK, 0) == 0); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(faccessat_fdcwd); ATF_TC_HEAD(faccessat_fdcwd, tc) { atf_tc_set_md_var(tc, "descr", "See that faccessat works with fd as AT_FDCWD"); } ATF_TC_BODY(faccessat_fdcwd, tc) { int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(chdir(DIR) == 0); ATF_REQUIRE(faccessat(AT_FDCWD, BASEFILE, F_OK, 0) == 0); } ATF_TC(faccessat_fdcwderr); ATF_TC_HEAD(faccessat_fdcwderr, tc) { atf_tc_set_md_var(tc, "descr", "See that faccessat fails with fd as AT_FDCWD and bad path"); } ATF_TC_BODY(faccessat_fdcwderr, tc) { ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE(faccessat(AT_FDCWD, FILEERR, F_OK, 0) == -1); } ATF_TC(faccessat_fderr1); ATF_TC_HEAD(faccessat_fderr1, tc) { atf_tc_set_md_var(tc, "descr", "See that faccessat fail with bad path"); } ATF_TC_BODY(faccessat_fderr1, tc) { int dfd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(faccessat(dfd, FILEERR, F_OK, 0) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(faccessat_fderr2); ATF_TC_HEAD(faccessat_fderr2, tc) { atf_tc_set_md_var(tc, "descr", "See that faccessat fails with bad fdat"); } ATF_TC_BODY(faccessat_fderr2, tc) { int dfd; int fd; char cwd[MAXPATHLEN]; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1); ATF_REQUIRE(faccessat(dfd, BASEFILE, F_OK, 0) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(faccessat_fderr3); ATF_TC_HEAD(faccessat_fderr3, tc) { atf_tc_set_md_var(tc, "descr", "See that faccessat fails with fd as -1"); } ATF_TC_BODY(faccessat_fderr3, tc) { int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(faccessat(-1, FILE, F_OK, 0) == -1); } ATF_TC(faccessat_fdlink); ATF_TC_HEAD(faccessat_fdlink, tc) { atf_tc_set_md_var(tc, "descr", "See that faccessat works on symlink"); } ATF_TC_BODY(faccessat_fdlink, tc) { int dfd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE(symlink(FILE, LINK) == 0); /* NB: FILE does not exists */ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(faccessat(dfd, BASELINK, F_OK, 0) == -1); ATF_REQUIRE(errno == ENOENT); #ifdef __FreeBSD__ atf_tc_expect_fail("Depends on non-standard behavior not mentioned in POSIX.1-2008"); #endif ATF_REQUIRE(faccessat(dfd, BASELINK, F_OK, AT_SYMLINK_NOFOLLOW) == 0); ATF_REQUIRE(close(dfd) == 0); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, faccessat_fd); ATF_TP_ADD_TC(tp, faccessat_fdcwd); ATF_TP_ADD_TC(tp, faccessat_fdcwderr); ATF_TP_ADD_TC(tp, faccessat_fderr1); ATF_TP_ADD_TC(tp, faccessat_fderr2); ATF_TP_ADD_TC(tp, faccessat_fderr3); ATF_TP_ADD_TC(tp, faccessat_fdlink); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/c063/t_fchmodat.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/c063/t_fchmodat.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/c063/t_fchmodat.c (revision 311925) @@ -1,200 +1,198 @@ -/* $NetBSD: t_fchmodat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */ +/* $NetBSD: t_fchmodat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Emmanuel Dreyfus. * * 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 -__RCSID("$NetBSD: t_fchmodat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $"); +__RCSID("$NetBSD: t_fchmodat.c,v 1.3 2017/01/10 15:13:56 christos Exp $"); +#include +#include #include #include #include #include #include #include #include #include -#include -#ifdef __FreeBSD__ -#include -#endif #define DIR "dir" #define FILE "dir/fchmodat" #define BASEFILE "fchmodat" #define LINK "dir/symlink" #define BASELINK "symlink" #define FILEERR "dir/fchmodaterr" ATF_TC(fchmodat_fd); ATF_TC_HEAD(fchmodat_fd, tc) { atf_tc_set_md_var(tc, "descr", "See that fchmodat works with fd"); } ATF_TC_BODY(fchmodat_fd, tc) { int dfd; int fd; struct stat st; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(fchmodat(dfd, BASEFILE, 0600, 0) == 0); ATF_REQUIRE(close(dfd) == 0); ATF_REQUIRE(stat(FILE, &st) == 0); ATF_REQUIRE(st.st_mode = 0600); } ATF_TC(fchmodat_fdcwd); ATF_TC_HEAD(fchmodat_fdcwd, tc) { atf_tc_set_md_var(tc, "descr", "See that fchmodat works with fd as AT_FDCWD"); } ATF_TC_BODY(fchmodat_fdcwd, tc) { int fd; struct stat st; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(chdir(DIR) == 0); ATF_REQUIRE(fchmodat(AT_FDCWD, BASEFILE, 0600, 0) == 0); ATF_REQUIRE(stat(BASEFILE, &st) == 0); ATF_REQUIRE(st.st_mode = 0600); } ATF_TC(fchmodat_fdcwderr); ATF_TC_HEAD(fchmodat_fdcwderr, tc) { atf_tc_set_md_var(tc, "descr", "See that fchmodat fails with fd as AT_FDCWD and bad path"); } ATF_TC_BODY(fchmodat_fdcwderr, tc) { ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE(fchmodat(AT_FDCWD, FILEERR, 0600, 0) == -1); } ATF_TC(fchmodat_fderr1); ATF_TC_HEAD(fchmodat_fderr1, tc) { atf_tc_set_md_var(tc, "descr", "See that fchmodat fail with bad path"); } ATF_TC_BODY(fchmodat_fderr1, tc) { int dfd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(fchmodat(dfd, FILEERR, 0600, 0) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(fchmodat_fderr2); ATF_TC_HEAD(fchmodat_fderr2, tc) { atf_tc_set_md_var(tc, "descr", "See that fchmodat fails with bad fdat"); } ATF_TC_BODY(fchmodat_fderr2, tc) { int dfd; int fd; char cwd[MAXPATHLEN]; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1); ATF_REQUIRE(fchmodat(dfd, BASEFILE, 0600, 0) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(fchmodat_fderr3); ATF_TC_HEAD(fchmodat_fderr3, tc) { atf_tc_set_md_var(tc, "descr", "See that fchmodat fails with fd as -1"); } ATF_TC_BODY(fchmodat_fderr3, tc) { int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(fchmodat(-1, FILE, 0600, 0) == -1); } ATF_TC(fchmodat_fdlink); ATF_TC_HEAD(fchmodat_fdlink, tc) { atf_tc_set_md_var(tc, "descr", "See that fchmodat works on symlink"); } ATF_TC_BODY(fchmodat_fdlink, tc) { int dfdlink; struct stat st; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE(symlink(FILE, LINK) == 0); ATF_REQUIRE((dfdlink = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(fchmodat(dfdlink, BASELINK, 0600, 0) == -1); ATF_REQUIRE(errno = ENOENT); ATF_REQUIRE(fchmodat(dfdlink, BASELINK, 0600, AT_SYMLINK_NOFOLLOW) == 0); ATF_REQUIRE(close(dfdlink) == 0); ATF_REQUIRE(lstat(LINK, &st) == 0); ATF_REQUIRE(st.st_mode = 0600); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, fchmodat_fd); ATF_TP_ADD_TC(tp, fchmodat_fdcwd); ATF_TP_ADD_TC(tp, fchmodat_fdcwderr); ATF_TP_ADD_TC(tp, fchmodat_fderr1); ATF_TP_ADD_TC(tp, fchmodat_fderr2); ATF_TP_ADD_TC(tp, fchmodat_fderr3); ATF_TP_ADD_TC(tp, fchmodat_fdlink); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/c063/t_fchownat.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/c063/t_fchownat.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/c063/t_fchownat.c (revision 311925) @@ -1,250 +1,248 @@ -/* $NetBSD: t_fchownat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $ */ +/* $NetBSD: t_fchownat.c,v 1.4 2017/01/10 15:13:56 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Emmanuel Dreyfus. * * 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 -__RCSID("$NetBSD: t_fchownat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $"); +__RCSID("$NetBSD: t_fchownat.c,v 1.4 2017/01/10 15:13:56 christos Exp $"); +#include +#include #include #include #include #include #include #include #include #include #include -#include -#ifdef __FreeBSD__ -#include -#endif #define DIR "dir" #define FILE "dir/fchownat" #define BASEFILE "fchownat" #define LINK "dir/symlink" #define BASELINK "symlink" #define FILEERR "dir/fchownaterr" #define USER "nobody" static int getuser(uid_t *, gid_t *); static int getuser(uid_t *uid, gid_t *gid) { struct passwd *pw; if ((pw = getpwnam(USER)) == NULL) return -1; *uid = pw->pw_uid; *gid = pw->pw_gid; return 0; } ATF_TC(fchownat_fd); ATF_TC_HEAD(fchownat_fd, tc) { atf_tc_set_md_var(tc, "descr", "See that fchownat works with fd"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(fchownat_fd, tc) { int dfd; int fd; uid_t uid; gid_t gid; struct stat st; ATF_REQUIRE(getuser(&uid, &gid) == 0); ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(fchownat(dfd, BASEFILE, uid, gid, 0) == 0); ATF_REQUIRE(close(dfd) == 0); ATF_REQUIRE(stat(FILE, &st) == 0); ATF_REQUIRE(st.st_uid == uid); ATF_REQUIRE(st.st_gid == gid); } ATF_TC(fchownat_fdcwd); ATF_TC_HEAD(fchownat_fdcwd, tc) { atf_tc_set_md_var(tc, "descr", "See that fchownat works with fd as AT_FDCWD"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(fchownat_fdcwd, tc) { int fd; uid_t uid; gid_t gid; struct stat st; ATF_REQUIRE(getuser(&uid, &gid) == 0); ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(chdir(DIR) == 0); ATF_REQUIRE(fchownat(AT_FDCWD, BASEFILE, uid, gid, 0) == 0); ATF_REQUIRE(stat(BASEFILE, &st) == 0); ATF_REQUIRE(st.st_uid == uid); ATF_REQUIRE(st.st_gid == gid); } ATF_TC(fchownat_fdcwderr); ATF_TC_HEAD(fchownat_fdcwderr, tc) { atf_tc_set_md_var(tc, "descr", "See that fchownat fails with fd as AT_FDCWD and bad path"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(fchownat_fdcwderr, tc) { uid_t uid; gid_t gid; ATF_REQUIRE(getuser(&uid, &gid) == 0); ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE(fchownat(AT_FDCWD, FILEERR, uid, gid, 0) == -1); } ATF_TC(fchownat_fderr1); ATF_TC_HEAD(fchownat_fderr1, tc) { atf_tc_set_md_var(tc, "descr", "See that fchownat fail with bad path"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(fchownat_fderr1, tc) { int dfd; uid_t uid; gid_t gid; ATF_REQUIRE(getuser(&uid, &gid) == 0); ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(fchownat(dfd, FILEERR, uid, gid, 0) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(fchownat_fderr2); ATF_TC_HEAD(fchownat_fderr2, tc) { atf_tc_set_md_var(tc, "descr", "See that fchownat fails with bad fdat"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(fchownat_fderr2, tc) { int dfd; int fd; char cwd[MAXPATHLEN]; uid_t uid; gid_t gid; ATF_REQUIRE(getuser(&uid, &gid) == 0); ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1); ATF_REQUIRE(fchownat(dfd, BASEFILE, uid, gid, 0) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(fchownat_fderr3); ATF_TC_HEAD(fchownat_fderr3, tc) { atf_tc_set_md_var(tc, "descr", "See that fchownat fails with fd as -1"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(fchownat_fderr3, tc) { int fd; uid_t uid; gid_t gid; ATF_REQUIRE(getuser(&uid, &gid) == 0); ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(fchownat(-1, FILE, uid, gid, 0) == -1); } ATF_TC(fchownat_fdlink); ATF_TC_HEAD(fchownat_fdlink, tc) { atf_tc_set_md_var(tc, "descr", "See that fchownat works on symlink"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(fchownat_fdlink, tc) { int dfd; uid_t uid; gid_t gid; struct stat st; ATF_REQUIRE(getuser(&uid, &gid) == 0); ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE(symlink(FILE, LINK) == 0); /* Target does not exists */ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(fchownat(dfd, BASELINK, uid, gid, 0) == -1); ATF_REQUIRE(errno == ENOENT); ATF_REQUIRE(fchownat(dfd, BASELINK, uid, gid, AT_SYMLINK_NOFOLLOW) == 0); ATF_REQUIRE(close(dfd) == 0); ATF_REQUIRE(lstat(LINK, &st) == 0); ATF_REQUIRE(st.st_uid == uid); ATF_REQUIRE(st.st_gid == gid); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, fchownat_fd); ATF_TP_ADD_TC(tp, fchownat_fdcwd); ATF_TP_ADD_TC(tp, fchownat_fdcwderr); ATF_TP_ADD_TC(tp, fchownat_fderr1); ATF_TP_ADD_TC(tp, fchownat_fderr2); ATF_TP_ADD_TC(tp, fchownat_fderr3); ATF_TP_ADD_TC(tp, fchownat_fdlink); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/c063/t_fexecve.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/c063/t_fexecve.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/c063/t_fexecve.c (revision 311925) @@ -1,97 +1,95 @@ -/* $NetBSD: t_fexecve.c,v 1.2 2013/03/17 04:35:59 jmmv Exp $ */ +/* $NetBSD: t_fexecve.c,v 1.3 2017/01/10 15:15:09 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Emmanuel Dreyfus. * * 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 -__RCSID("$NetBSD: t_fexecve.c,v 1.2 2013/03/17 04:35:59 jmmv Exp $"); +__RCSID("$NetBSD: t_fexecve.c,v 1.3 2017/01/10 15:15:09 christos Exp $"); #include #include #include #include #include #include #include #include #include #include #include #include ATF_TC(fexecve); ATF_TC_HEAD(fexecve, tc) { atf_tc_set_md_var(tc, "descr", "See that fexecve works"); } ATF_TC_BODY(fexecve, tc) { int status; pid_t pid; const char *const argv[] = { "touch", "test", NULL }; const char *const envp[] = { NULL }; ATF_REQUIRE((pid = fork()) != -1); if (pid == 0) { int fd; if ((fd = open("/usr/bin/touch", O_RDONLY, 0)) == -1) err(EXIT_FAILURE, "open /usr/bin/touch"); if (fexecve(fd, __UNCONST(argv), __UNCONST(envp)) == -1) { int error; if (errno == ENOSYS) error = 76; else error = EXIT_FAILURE; -#ifdef __FreeBSD__ (void)close(fd); -#endif err(error, "fexecve"); } } ATF_REQUIRE(waitpid(pid, &status, 0) != -1); if (!WIFEXITED(status)) atf_tc_fail("child process did not exit cleanly"); if (WEXITSTATUS(status) == 76) atf_tc_expect_fail("fexecve not implemented"); else ATF_REQUIRE(WEXITSTATUS(status) == EXIT_SUCCESS); ATF_REQUIRE(access("test", F_OK) == 0); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, fexecve); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/c063/t_fstatat.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/c063/t_fstatat.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/c063/t_fstatat.c (revision 311925) @@ -1,199 +1,197 @@ -/* $NetBSD: t_fstatat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */ +/* $NetBSD: t_fstatat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Emmanuel Dreyfus. * * 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 -__RCSID("$NetBSD: t_fstatat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $"); +__RCSID("$NetBSD: t_fstatat.c,v 1.3 2017/01/10 15:13:56 christos Exp $"); +#include +#include #include #include #include #include #include #include #include #include -#include -#ifdef __FreeBSD__ -#include -#endif #define DIR "dir" #define FILE "dir/fstatat" #define BASEFILE "fstatat" #define LINK "dir/symlink" #define BASELINK "symlink" #define FILEERR "dir/symlink" ATF_TC(fstatat_fd); ATF_TC_HEAD(fstatat_fd, tc) { atf_tc_set_md_var(tc, "descr", "See that fstatat works with fd"); } ATF_TC_BODY(fstatat_fd, tc) { int dfd; int fd; struct stat st1, st2; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(fstatat(dfd, BASEFILE, &st1, 0) == 0); ATF_REQUIRE(close(dfd) == 0); ATF_REQUIRE(stat(FILE, &st2) == 0); ATF_REQUIRE(memcmp(&st1, &st2, sizeof(st1)) == 0); } ATF_TC(fstatat_fdcwd); ATF_TC_HEAD(fstatat_fdcwd, tc) { atf_tc_set_md_var(tc, "descr", "See that fstatat works with fd as AT_FDCWD"); } ATF_TC_BODY(fstatat_fdcwd, tc) { int fd; struct stat st; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(chdir(DIR) == 0); ATF_REQUIRE(fstatat(AT_FDCWD, BASEFILE, &st, 0) == 0); } ATF_TC(fstatat_fdcwderr); ATF_TC_HEAD(fstatat_fdcwderr, tc) { atf_tc_set_md_var(tc, "descr", "See that fstatat fails with fd as AT_FDCWD and bad path"); } ATF_TC_BODY(fstatat_fdcwderr, tc) { struct stat st; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE(fstatat(AT_FDCWD, FILEERR, &st, 0) == -1); } ATF_TC(fstatat_fderr1); ATF_TC_HEAD(fstatat_fderr1, tc) { atf_tc_set_md_var(tc, "descr", "See that fstatat fail with bad path"); } ATF_TC_BODY(fstatat_fderr1, tc) { int dfd; struct stat st; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(fstatat(dfd, FILEERR, &st, 0) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(fstatat_fderr2); ATF_TC_HEAD(fstatat_fderr2, tc) { atf_tc_set_md_var(tc, "descr", "See that fstatat fails with bad fdat"); } ATF_TC_BODY(fstatat_fderr2, tc) { int dfd; int fd; char cwd[MAXPATHLEN]; struct stat st; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1); ATF_REQUIRE(fstatat(dfd, BASEFILE, &st, 0) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(fstatat_fderr3); ATF_TC_HEAD(fstatat_fderr3, tc) { atf_tc_set_md_var(tc, "descr", "See that fstatat fails with fd as -1"); } ATF_TC_BODY(fstatat_fderr3, tc) { int fd; struct stat st; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(fstatat(-1, FILE, &st, 0) == -1); } ATF_TC(fstatat_fdlink); ATF_TC_HEAD(fstatat_fdlink, tc) { atf_tc_set_md_var(tc, "descr", "See that fstatat works on symlink"); } ATF_TC_BODY(fstatat_fdlink, tc) { int dfd; struct stat st; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE(symlink(FILE, LINK) == 0); /* target does not exists */ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(fstatat(dfd, BASELINK, &st, 0) == -1); ATF_REQUIRE(errno == ENOENT); ATF_REQUIRE(fstatat(dfd, BASELINK, &st, AT_SYMLINK_NOFOLLOW) == 0); ATF_REQUIRE(close(dfd) == 0); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, fstatat_fd); ATF_TP_ADD_TC(tp, fstatat_fdcwd); ATF_TP_ADD_TC(tp, fstatat_fdcwderr); ATF_TP_ADD_TC(tp, fstatat_fderr1); ATF_TP_ADD_TC(tp, fstatat_fderr2); ATF_TP_ADD_TC(tp, fstatat_fderr3); ATF_TP_ADD_TC(tp, fstatat_fdlink); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/c063/t_mkfifoat.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/c063/t_mkfifoat.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/c063/t_mkfifoat.c (revision 311925) @@ -1,127 +1,125 @@ -/* $NetBSD: t_mkfifoat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */ +/* $NetBSD: t_mkfifoat.c,v 1.3 2017/01/10 15:15:09 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Emmanuel Dreyfus. * * 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 -__RCSID("$NetBSD: t_mkfifoat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $"); +__RCSID("$NetBSD: t_mkfifoat.c,v 1.3 2017/01/10 15:15:09 christos Exp $"); #include #include #include #include #include #include #include #include #include #include #define DIR "dir" #define FIFO "dir/openat" #define BASEFIFO "openat" #define FIFOERR "dir/openaterr" ATF_TC(mkfifoat_fd); ATF_TC_HEAD(mkfifoat_fd, tc) { atf_tc_set_md_var(tc, "descr", "See that mkfifoat works with fd"); } ATF_TC_BODY(mkfifoat_fd, tc) { int dfd; int fd; mode_t mode = 0600; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE((fd = mkfifoat(dfd, BASEFIFO, mode)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(access(FIFO, F_OK) == 0); -#ifdef __FreeBSD__ (void)close(dfd); -#endif } ATF_TC(mkfifoat_fdcwd); ATF_TC_HEAD(mkfifoat_fdcwd, tc) { atf_tc_set_md_var(tc, "descr", "See that mkfifoat works with fd as AT_FDCWD"); } ATF_TC_BODY(mkfifoat_fdcwd, tc) { int fd; mode_t mode = 0600; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = mkfifoat(AT_FDCWD, FIFO, mode)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(access(FIFO, F_OK) == 0); } ATF_TC(mkfifoat_fdcwderr); ATF_TC_HEAD(mkfifoat_fdcwderr, tc) { atf_tc_set_md_var(tc, "descr", "See that mkfifoat fails with fd as AT_FDCWD and bad path"); } ATF_TC_BODY(mkfifoat_fdcwderr, tc) { int fd; mode_t mode = 0600; ATF_REQUIRE((fd = mkfifoat(AT_FDCWD, FIFOERR, mode)) == -1); } ATF_TC(mkfifoat_fderr); ATF_TC_HEAD(mkfifoat_fderr, tc) { atf_tc_set_md_var(tc, "descr", "See that mkfifoat fails with fd as -1"); } ATF_TC_BODY(mkfifoat_fderr, tc) { int fd; mode_t mode = 0600; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FIFO, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((fd = mkfifoat(-1, FIFO, mode)) == -1); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, mkfifoat_fd); ATF_TP_ADD_TC(tp, mkfifoat_fdcwd); ATF_TP_ADD_TC(tp, mkfifoat_fdcwderr); ATF_TP_ADD_TC(tp, mkfifoat_fderr); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/c063/t_mknodat.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/c063/t_mknodat.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/c063/t_mknodat.c (revision 311925) @@ -1,153 +1,151 @@ -/* $NetBSD: t_mknodat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $ */ +/* $NetBSD: t_mknodat.c,v 1.4 2017/01/10 15:15:09 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Emmanuel Dreyfus. * * 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 -__RCSID("$NetBSD: t_mknodat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $"); +__RCSID("$NetBSD: t_mknodat.c,v 1.4 2017/01/10 15:15:09 christos Exp $"); #include #include #include #include #include #include #include #include #include #include #define DIR "dir" #define FILE "dir/openat" #define BASEFILE "openat" #define FILEERR "dir/openaterr" static dev_t get_devnull(void); static dev_t get_devnull(void) { struct stat st; if (stat(_PATH_DEVNULL, &st) != 0) return NODEV; return st.st_rdev; } ATF_TC(mknodat_fd); ATF_TC_HEAD(mknodat_fd, tc) { atf_tc_set_md_var(tc, "descr", "See that mknodat works with fd"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(mknodat_fd, tc) { int dfd; int fd; dev_t dev; mode_t mode = S_IFCHR|0600; ATF_REQUIRE((dev = get_devnull()) != NODEV); ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE((fd = mknodat(dfd, BASEFILE, mode, dev)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(access(FILE, F_OK) == 0); -#ifdef __FreeBSD__ (void)close(dfd); -#endif } ATF_TC(mknodat_fdcwd); ATF_TC_HEAD(mknodat_fdcwd, tc) { atf_tc_set_md_var(tc, "descr", "See that mknodat works with fd as AT_FDCWD"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(mknodat_fdcwd, tc) { int fd; dev_t dev; mode_t mode = S_IFCHR|0600; ATF_REQUIRE((dev = get_devnull()) != NODEV); ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = mknodat(AT_FDCWD, FILE, mode, dev)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(access(FILE, F_OK) == 0); } ATF_TC(mknodat_fdcwderr); ATF_TC_HEAD(mknodat_fdcwderr, tc) { atf_tc_set_md_var(tc, "descr", "See that mknodat fails with fd as AT_FDCWD and bad path"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(mknodat_fdcwderr, tc) { int fd; dev_t dev; mode_t mode = S_IFCHR|0600; ATF_REQUIRE((dev = get_devnull()) != NODEV); ATF_REQUIRE((fd = mknodat(AT_FDCWD, FILEERR, mode, dev)) == -1); } ATF_TC(mknodat_fderr); ATF_TC_HEAD(mknodat_fderr, tc) { atf_tc_set_md_var(tc, "descr", "See that mknodat fails with fd as -1"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(mknodat_fderr, tc) { int fd; dev_t dev; mode_t mode = S_IFCHR|0600; ATF_REQUIRE((dev = get_devnull()) != NODEV); ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((fd = mknodat(-1, FILE, mode, dev)) == -1); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, mknodat_fd); ATF_TP_ADD_TC(tp, mknodat_fdcwd); ATF_TP_ADD_TC(tp, mknodat_fdcwderr); ATF_TP_ADD_TC(tp, mknodat_fderr); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/c063/t_o_search.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/c063/t_o_search.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/c063/t_o_search.c (revision 311925) @@ -1,278 +1,281 @@ -/* $NetBSD: t_o_search.c,v 1.4 2013/03/17 04:46:06 jmmv Exp $ */ +/* $NetBSD: t_o_search.c,v 1.5 2017/01/10 22:25:01 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Emmanuel Dreyfus. * * 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 -__RCSID("$NetBSD: t_o_search.c,v 1.4 2013/03/17 04:46:06 jmmv Exp $"); +__RCSID("$NetBSD: t_o_search.c,v 1.5 2017/01/10 22:25:01 christos Exp $"); #include + +#include +#include + #include #include #include #include #include #include #include #include -#include /* * dholland 20130112: disable tests that require O_SEARCH semantics * until a decision is reached about the semantics of O_SEARCH and a * non-broken implementation is available. */ #if (O_MASK & O_SEARCH) != 0 #define USE_O_SEARCH #endif #define DIR "dir" #define FILE "dir/o_search" #define BASEFILE "o_search" ATF_TC(o_search_perm1); ATF_TC_HEAD(o_search_perm1, tc) { atf_tc_set_md_var(tc, "descr", "See that openat enforces search permission"); atf_tc_set_md_var(tc, "require.user", "unprivileged"); } ATF_TC_BODY(o_search_perm1, tc) { int dfd; int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(fchmod(dfd, 644) == 0); ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) == -1); ATF_REQUIRE(errno == EACCES); ATF_REQUIRE(close(dfd) == 0); } #ifdef USE_O_SEARCH ATF_TC(o_search_root_flag1); ATF_TC_HEAD(o_search_root_flag1, tc) { atf_tc_set_md_var(tc, "descr", "See that root openat honours O_SEARCH"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(o_search_root_flag1, tc) { int dfd; int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1); ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(fchmod(dfd, 644) == 0); ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(fchmod(dfd, 444) == 0); ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(o_search_unpriv_flag1); ATF_TC_HEAD(o_search_unpriv_flag1, tc) { atf_tc_set_md_var(tc, "descr", "See that openat honours O_SEARCH"); atf_tc_set_md_var(tc, "require.user", "unprivileged"); } ATF_TC_BODY(o_search_unpriv_flag1, tc) { int dfd; int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1); ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(fchmod(dfd, 644) == 0); ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(fchmod(dfd, 444) == 0); ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1); ATF_REQUIRE(close(dfd) == 0); } #endif /* USE_O_SEARCH */ ATF_TC(o_search_perm2); ATF_TC_HEAD(o_search_perm2, tc) { atf_tc_set_md_var(tc, "descr", "See that faccessat enforces search permission"); atf_tc_set_md_var(tc, "require.user", "unprivileged"); } ATF_TC_BODY(o_search_perm2, tc) { int dfd; int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0); ATF_REQUIRE(fchmod(dfd, 644) == 0); ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == -1); ATF_REQUIRE(errno == EACCES); ATF_REQUIRE(close(dfd) == 0); } #ifdef USE_O_SEARCH ATF_TC(o_search_root_flag2); ATF_TC_HEAD(o_search_root_flag2, tc) { atf_tc_set_md_var(tc, "descr", "See that root fstatat honours O_SEARCH"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(o_search_root_flag2, tc) { int dfd; int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1); ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0); ATF_REQUIRE(fchmod(dfd, 644) == 0); ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0); ATF_REQUIRE(fchmod(dfd, 444) == 0); ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(o_search_unpriv_flag2); ATF_TC_HEAD(o_search_unpriv_flag2, tc) { atf_tc_set_md_var(tc, "descr", "See that fstatat honours O_SEARCH"); atf_tc_set_md_var(tc, "require.user", "unprivileged"); } ATF_TC_BODY(o_search_unpriv_flag2, tc) { int dfd; int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1); ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0); ATF_REQUIRE(fchmod(dfd, 644) == 0); ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0); ATF_REQUIRE(fchmod(dfd, 444) == 0); ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0); ATF_REQUIRE(close(dfd) == 0); } #endif /* USE_O_SEARCH */ ATF_TC(o_search_notdir); ATF_TC_HEAD(o_search_notdir, tc) { atf_tc_set_md_var(tc, "descr", "See that openat fails with non dir fd"); } ATF_TC_BODY(o_search_notdir, tc) { int dfd; int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((dfd = open(FILE, O_CREAT|O_RDWR|O_SEARCH, 0644)) != -1); ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) == -1); ATF_REQUIRE(errno == ENOTDIR); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, o_search_perm1); #ifdef USE_O_SEARCH ATF_TP_ADD_TC(tp, o_search_root_flag1); ATF_TP_ADD_TC(tp, o_search_unpriv_flag1); #endif ATF_TP_ADD_TC(tp, o_search_perm2); #ifdef USE_O_SEARCH ATF_TP_ADD_TC(tp, o_search_root_flag2); ATF_TP_ADD_TC(tp, o_search_unpriv_flag2); #endif ATF_TP_ADD_TC(tp, o_search_notdir); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/c063/t_openat.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/c063/t_openat.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/c063/t_openat.c (revision 311925) @@ -1,168 +1,166 @@ -/* $NetBSD: t_openat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */ +/* $NetBSD: t_openat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Emmanuel Dreyfus. * * 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 -__RCSID("$NetBSD: t_openat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $"); +__RCSID("$NetBSD: t_openat.c,v 1.3 2017/01/10 15:13:56 christos Exp $"); +#include +#include #include #include #include #include #include #include #include #include -#include -#ifdef __FreeBSD__ -#include -#endif #define DIR "dir" #define FILE "dir/openat" #define BASEFILE "openat" #define FILEERR "dir/openaterr" ATF_TC(openat_fd); ATF_TC_HEAD(openat_fd, tc) { atf_tc_set_md_var(tc, "descr", "See that openat works with fd"); } ATF_TC_BODY(openat_fd, tc) { int dfd; int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDONLY, 0)) != -1); ATF_REQUIRE(close(dfd) == 0); ATF_REQUIRE(close(fd) == 0); } ATF_TC(openat_fdcwd); ATF_TC_HEAD(openat_fdcwd, tc) { atf_tc_set_md_var(tc, "descr", "See that openat works with fd as AT_FDCWD"); } ATF_TC_BODY(openat_fdcwd, tc) { int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(chdir(DIR) == 0); ATF_REQUIRE((fd = openat(AT_FDCWD, BASEFILE, O_RDONLY, 0)) != -1); ATF_REQUIRE(close(fd) == 0); } ATF_TC(openat_fdcwderr); ATF_TC_HEAD(openat_fdcwderr, tc) { atf_tc_set_md_var(tc, "descr", "See that openat fails with fd as AT_FDCWD and bad path"); } ATF_TC_BODY(openat_fdcwderr, tc) { int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = openat(AT_FDCWD, FILEERR, O_RDONLY, 0)) == -1); } ATF_TC(openat_fderr1); ATF_TC_HEAD(openat_fderr1, tc) { atf_tc_set_md_var(tc, "descr", "See that openat fail with bad path"); } ATF_TC_BODY(openat_fderr1, tc) { int dfd; int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE((fd = openat(dfd, FILEERR, O_RDONLY, 0)) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(openat_fderr2); ATF_TC_HEAD(openat_fderr2, tc) { atf_tc_set_md_var(tc, "descr", "See that openat fails with bad fdat"); } ATF_TC_BODY(openat_fderr2, tc) { int dfd; int fd; char cwd[MAXPATHLEN]; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1); ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDONLY, 0)) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(openat_fderr3); ATF_TC_HEAD(openat_fderr3, tc) { atf_tc_set_md_var(tc, "descr", "See that openat fails with fd as -1"); } ATF_TC_BODY(openat_fderr3, tc) { int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((fd = openat(-1, FILE, O_RDONLY, 0)) == -1); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, openat_fd); ATF_TP_ADD_TC(tp, openat_fdcwd); ATF_TP_ADD_TC(tp, openat_fdcwderr); ATF_TP_ADD_TC(tp, openat_fderr1); ATF_TP_ADD_TC(tp, openat_fderr2); ATF_TP_ADD_TC(tp, openat_fderr3); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c (revision 311925) @@ -1,160 +1,158 @@ -/* $NetBSD: t_readlinkat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $ */ +/* $NetBSD: t_readlinkat.c,v 1.4 2017/01/10 15:13:56 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Emmanuel Dreyfus. * * 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 -__RCSID("$NetBSD: t_readlinkat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $"); +__RCSID("$NetBSD: t_readlinkat.c,v 1.4 2017/01/10 15:13:56 christos Exp $"); +#include +#include #include #include #include #include #include #include #include #include -#include -#ifdef __FreeBSD__ -#include -#endif #define DIR "dir" #define FILE "dir/readlinkat" #define BASEFILE "readlinkat" #define LINK "dir/symlink" #define BASELINK "symlink" #define FILEERR "dir/readlinkaterr" ATF_TC(readlinkat_fd); ATF_TC_HEAD(readlinkat_fd, tc) { atf_tc_set_md_var(tc, "descr", "See that readlinkat works with fd"); } ATF_TC_BODY(readlinkat_fd, tc) { int dfd; int fd; ssize_t len; char buf[MAXPATHLEN]; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(symlink(FILE, LINK) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); len = readlinkat(dfd, BASELINK, buf, sizeof(buf)-1); ATF_REQUIRE(len != -1); buf[len] = 0; ATF_REQUIRE(close(dfd) == 0); ATF_REQUIRE(strcmp(buf, FILE) == 0); } ATF_TC(readlinkat_fdcwd); ATF_TC_HEAD(readlinkat_fdcwd, tc) { atf_tc_set_md_var(tc, "descr", "See that readlinkat works with fd as AT_FDCWD"); } ATF_TC_BODY(readlinkat_fdcwd, tc) { int fd; ssize_t len; char buf[MAXPATHLEN]; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(symlink(FILE, LINK) == 0); len = readlinkat(AT_FDCWD, LINK, buf, sizeof(buf)-1); ATF_REQUIRE(len != -1); buf[len] = 0; ATF_REQUIRE(strcmp(buf, FILE) == 0); } ATF_TC(readlinkat_fdcwderr); ATF_TC_HEAD(readlinkat_fdcwderr, tc) { atf_tc_set_md_var(tc, "descr", "See that readlinkat fails with fd as AT_FDCWD and bad path"); } ATF_TC_BODY(readlinkat_fdcwderr, tc) { char buf[MAXPATHLEN]; ATF_REQUIRE(readlinkat(AT_FDCWD, LINK, buf, sizeof(buf)) == -1); } ATF_TC(readlinkat_fderr1); ATF_TC_HEAD(readlinkat_fderr1, tc) { atf_tc_set_md_var(tc, "descr", "See that readlinkat fail with bad path"); } ATF_TC_BODY(readlinkat_fderr1, tc) { int dfd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(readlinkat(dfd, FILEERR, F_OK, 0) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(readlinkat_fderr2); ATF_TC_HEAD(readlinkat_fderr2, tc) { atf_tc_set_md_var(tc, "descr", "See that readlinkat fails with fd as -1"); } ATF_TC_BODY(readlinkat_fderr2, tc) { int fd; char buf[MAXPATHLEN]; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(symlink(FILE, LINK) == 0); ATF_REQUIRE(readlinkat(-1, LINK, buf, sizeof(buf)) == -1); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, readlinkat_fd); ATF_TP_ADD_TC(tp, readlinkat_fdcwd); ATF_TP_ADD_TC(tp, readlinkat_fdcwderr); ATF_TP_ADD_TC(tp, readlinkat_fderr1); ATF_TP_ADD_TC(tp, readlinkat_fderr2); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c (revision 311925) @@ -1,179 +1,177 @@ -/* $NetBSD: t_unlinkat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */ +/* $NetBSD: t_unlinkat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Emmanuel Dreyfus. * * 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 -__RCSID("$NetBSD: t_unlinkat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $"); +__RCSID("$NetBSD: t_unlinkat.c,v 1.3 2017/01/10 15:13:56 christos Exp $"); +#include +#include #include #include #include #include #include #include #include #include -#include -#ifdef __FreeBSD__ -#include -#endif #define DIR "dir" #define FILE "dir/unlinkat" #define BASEFILE "unlinkat" #define FILEERR "dir/unlinkaterr" ATF_TC(unlinkat_fd); ATF_TC_HEAD(unlinkat_fd, tc) { atf_tc_set_md_var(tc, "descr", "See that unlinkat works with fd"); } ATF_TC_BODY(unlinkat_fd, tc) { int dfd; int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(unlinkat(dfd, BASEFILE, 0) == 0); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(unlinkat_fdcwd); ATF_TC_HEAD(unlinkat_fdcwd, tc) { atf_tc_set_md_var(tc, "descr", "See that unlinkat works with fd as AT_FDCWD"); } ATF_TC_BODY(unlinkat_fdcwd, tc) { int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(chdir(DIR) == 0); ATF_REQUIRE(unlinkat(AT_FDCWD, BASEFILE, 0) == 0); } ATF_TC(unlinkat_fdcwderr); ATF_TC_HEAD(unlinkat_fdcwderr, tc) { atf_tc_set_md_var(tc, "descr", "See that unlinkat fails with fd as AT_FDCWD and bad path"); } ATF_TC_BODY(unlinkat_fdcwderr, tc) { ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE(unlinkat(AT_FDCWD, FILEERR, 0) == -1); } ATF_TC(unlinkat_fderr1); ATF_TC_HEAD(unlinkat_fderr1, tc) { atf_tc_set_md_var(tc, "descr", "See that unlinkat fail with bad path"); } ATF_TC_BODY(unlinkat_fderr1, tc) { int dfd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(unlinkat(dfd, FILEERR, 0) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(unlinkat_fderr2); ATF_TC_HEAD(unlinkat_fderr2, tc) { atf_tc_set_md_var(tc, "descr", "See that unlinkat fails with bad fdat"); } ATF_TC_BODY(unlinkat_fderr2, tc) { int dfd; int fd; char cwd[MAXPATHLEN]; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1); ATF_REQUIRE(unlinkat(dfd, BASEFILE, 0) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(unlinkat_fderr3); ATF_TC_HEAD(unlinkat_fderr3, tc) { atf_tc_set_md_var(tc, "descr", "See that unlinkat fails with fd as -1"); } ATF_TC_BODY(unlinkat_fderr3, tc) { int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlinkat(-1, FILE, 0) == -1); } ATF_TC(unlinkat_dir); ATF_TC_HEAD(unlinkat_dir, tc) { atf_tc_set_md_var(tc, "descr", "See that unlinkat can remove directories"); } ATF_TC_BODY(unlinkat_dir, tc) { ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE(unlinkat(AT_FDCWD, DIR, 0) == -1); ATF_REQUIRE(errno == EPERM); ATF_REQUIRE(unlinkat(AT_FDCWD, DIR, AT_REMOVEDIR) == 0); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, unlinkat_fd); ATF_TP_ADD_TC(tp, unlinkat_fdcwd); ATF_TP_ADD_TC(tp, unlinkat_fdcwderr); ATF_TP_ADD_TC(tp, unlinkat_fderr1); ATF_TP_ADD_TC(tp, unlinkat_fderr2); ATF_TP_ADD_TC(tp, unlinkat_fderr3); ATF_TP_ADD_TC(tp, unlinkat_dir); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/c063/t_utimensat.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/c063/t_utimensat.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/c063/t_utimensat.c (revision 311925) @@ -1,215 +1,213 @@ -/* $NetBSD: t_utimensat.c,v 1.5 2013/03/17 04:46:06 jmmv Exp $ */ +/* $NetBSD: t_utimensat.c,v 1.6 2017/01/10 15:13:56 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Emmanuel Dreyfus. * * 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 -__RCSID("$NetBSD: t_utimensat.c,v 1.5 2013/03/17 04:46:06 jmmv Exp $"); +__RCSID("$NetBSD: t_utimensat.c,v 1.6 2017/01/10 15:13:56 christos Exp $"); +#include +#include +#include #include #include #include #include #include #include #include #include -#include -#ifdef __FreeBSD__ -#include -#endif -#include #define DIR "dir" #define FILE "dir/utimensat" #define BASEFILE "utimensat" #define LINK "dir/symlink" #define BASELINK "symlink" #define FILEERR "dir/symlink" const struct timespec tptr[] = { { 0x12345678, 987654321 }, { 0x15263748, 123456789 }, }; ATF_TC(utimensat_fd); ATF_TC_HEAD(utimensat_fd, tc) { atf_tc_set_md_var(tc, "descr", "See that utimensat works with fd"); } ATF_TC_BODY(utimensat_fd, tc) { int dfd; int fd; struct stat st; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(utimensat(dfd, BASEFILE, tptr, 0) == 0); ATF_REQUIRE(close(dfd) == 0); ATF_REQUIRE(stat(FILE, &st) == 0); ATF_REQUIRE(st.st_atimespec.tv_sec == tptr[0].tv_sec); ATF_REQUIRE(st.st_atimespec.tv_nsec == tptr[0].tv_nsec); ATF_REQUIRE(st.st_mtimespec.tv_sec == tptr[1].tv_sec); ATF_REQUIRE(st.st_mtimespec.tv_nsec == tptr[1].tv_nsec); } ATF_TC(utimensat_fdcwd); ATF_TC_HEAD(utimensat_fdcwd, tc) { atf_tc_set_md_var(tc, "descr", "See that utimensat works with fd as AT_FDCWD"); } ATF_TC_BODY(utimensat_fdcwd, tc) { int fd; struct stat st; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(chdir(DIR) == 0); ATF_REQUIRE(utimensat(AT_FDCWD, BASEFILE, tptr, 0) == 0); ATF_REQUIRE(stat(BASEFILE, &st) == 0); ATF_REQUIRE(st.st_atimespec.tv_sec == tptr[0].tv_sec); ATF_REQUIRE(st.st_atimespec.tv_nsec == tptr[0].tv_nsec); ATF_REQUIRE(st.st_mtimespec.tv_sec == tptr[1].tv_sec); ATF_REQUIRE(st.st_mtimespec.tv_nsec == tptr[1].tv_nsec); } ATF_TC(utimensat_fdcwderr); ATF_TC_HEAD(utimensat_fdcwderr, tc) { atf_tc_set_md_var(tc, "descr", "See that utimensat fails with fd as AT_FDCWD and bad path"); } ATF_TC_BODY(utimensat_fdcwderr, tc) { ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE(utimensat(AT_FDCWD, FILEERR, tptr, 0) == -1); } ATF_TC(utimensat_fderr1); ATF_TC_HEAD(utimensat_fderr1, tc) { atf_tc_set_md_var(tc, "descr", "See that utimensat fail with bad path"); } ATF_TC_BODY(utimensat_fderr1, tc) { int dfd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(utimensat(dfd, FILEERR, tptr, 0) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(utimensat_fderr2); ATF_TC_HEAD(utimensat_fderr2, tc) { atf_tc_set_md_var(tc, "descr", "See that utimensat fails with bad fdat"); } ATF_TC_BODY(utimensat_fderr2, tc) { int dfd; int fd; char cwd[MAXPATHLEN]; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1); ATF_REQUIRE(utimensat(dfd, BASEFILE, tptr, 0) == -1); ATF_REQUIRE(close(dfd) == 0); } ATF_TC(utimensat_fderr3); ATF_TC_HEAD(utimensat_fderr3, tc) { atf_tc_set_md_var(tc, "descr", "See that utimensat fails with fd as -1"); } ATF_TC_BODY(utimensat_fderr3, tc) { int fd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(utimensat(-1, FILE, tptr, 0) == -1); } ATF_TC(utimensat_fdlink); ATF_TC_HEAD(utimensat_fdlink, tc) { atf_tc_set_md_var(tc, "descr", "See that utimensat works on symlink"); } ATF_TC_BODY(utimensat_fdlink, tc) { int dfd; struct stat st; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE(symlink(FILE, LINK) == 0); /* NB: FILE does not exists */ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(utimensat(dfd, BASELINK, tptr, 0) == -1); ATF_REQUIRE(errno = ENOENT); ATF_REQUIRE(utimensat(dfd, BASELINK, tptr, AT_SYMLINK_NOFOLLOW) == 0); ATF_REQUIRE(close(dfd) == 0); ATF_REQUIRE(lstat(LINK, &st) == 0); ATF_REQUIRE(st.st_atimespec.tv_sec == tptr[0].tv_sec); ATF_REQUIRE(st.st_atimespec.tv_nsec == tptr[0].tv_nsec); ATF_REQUIRE(st.st_mtimespec.tv_sec == tptr[1].tv_sec); ATF_REQUIRE(st.st_mtimespec.tv_nsec == tptr[1].tv_nsec); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, utimensat_fd); ATF_TP_ADD_TC(tp, utimensat_fdcwd); ATF_TP_ADD_TC(tp, utimensat_fdcwderr); ATF_TP_ADD_TC(tp, utimensat_fderr1); ATF_TP_ADD_TC(tp, utimensat_fderr2); ATF_TP_ADD_TC(tp, utimensat_fderr3); ATF_TP_ADD_TC(tp, utimensat_fdlink); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c (revision 311925) @@ -1,392 +1,392 @@ -/* $NetBSD: t_fileactions.c,v 1.5 2012/04/09 19:42:07 martin Exp $ */ +/* $NetBSD: t_fileactions.c,v 1.6 2017/01/10 22:36:29 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Charles Zhang and * Martin Husemann . * * 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. */ -#ifdef __FreeBSD__ -#include -#endif #include + +#include +#include + #include #include #include #include #include #include #include -#include ATF_TC(t_spawn_openmode); ATF_TC_HEAD(t_spawn_openmode, tc) { atf_tc_set_md_var(tc, "descr", "Test the proper handling of 'mode' for 'open' fileactions"); atf_tc_set_md_var(tc, "require.progs", "/bin/cat"); } static off_t filesize(const char * restrict fname) { struct stat st; int err; err = stat(fname, &st); ATF_REQUIRE(err == 0); return st.st_size; } #define TESTFILE "./the_input_data" #define CHECKFILE "./the_output_data" #define TESTCONTENT "marry has a little lamb" static void make_testfile(const char *restrict file) { FILE *f; size_t written; f = fopen(file, "w"); ATF_REQUIRE(f != NULL); written = fwrite(TESTCONTENT, 1, strlen(TESTCONTENT), f); fclose(f); ATF_REQUIRE(written == strlen(TESTCONTENT)); } static void empty_outfile(const char *restrict filename) { FILE *f; f = fopen(filename, "w"); ATF_REQUIRE(f != NULL); fclose(f); } ATF_TC_BODY(t_spawn_openmode, tc) { int status, err; pid_t pid; size_t insize, outsize; char * const args[2] = { __UNCONST("cat"), NULL }; posix_spawn_file_actions_t fa; /* * try a "cat < testfile > checkfile" */ make_testfile(TESTFILE); unlink(CHECKFILE); posix_spawn_file_actions_init(&fa); posix_spawn_file_actions_addopen(&fa, fileno(stdin), TESTFILE, O_RDONLY, 0); posix_spawn_file_actions_addopen(&fa, fileno(stdout), CHECKFILE, O_WRONLY|O_CREAT, 0600); err = posix_spawn(&pid, "/bin/cat", &fa, NULL, args, NULL); posix_spawn_file_actions_destroy(&fa); ATF_REQUIRE(err == 0); /* ok, wait for the child to finish */ waitpid(pid, &status, 0); ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS); /* now check that input and output have the same size */ insize = filesize(TESTFILE); outsize = filesize(CHECKFILE); ATF_REQUIRE(insize == strlen(TESTCONTENT)); ATF_REQUIRE(insize == outsize); /* * try a "cat < testfile >> checkfile" */ make_testfile(TESTFILE); make_testfile(CHECKFILE); posix_spawn_file_actions_init(&fa); posix_spawn_file_actions_addopen(&fa, fileno(stdin), TESTFILE, O_RDONLY, 0); posix_spawn_file_actions_addopen(&fa, fileno(stdout), CHECKFILE, O_WRONLY|O_APPEND, 0); err = posix_spawn(&pid, "/bin/cat", &fa, NULL, args, NULL); posix_spawn_file_actions_destroy(&fa); ATF_REQUIRE(err == 0); /* ok, wait for the child to finish */ waitpid(pid, &status, 0); ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS); /* now check that output is twice as long as input */ insize = filesize(TESTFILE); outsize = filesize(CHECKFILE); ATF_REQUIRE(insize == strlen(TESTCONTENT)); ATF_REQUIRE(insize*2 == outsize); /* * try a "cat < testfile > checkfile" with input and output swapped */ make_testfile(TESTFILE); empty_outfile(CHECKFILE); posix_spawn_file_actions_init(&fa); posix_spawn_file_actions_addopen(&fa, fileno(stdout), TESTFILE, O_RDONLY, 0); posix_spawn_file_actions_addopen(&fa, fileno(stdin), CHECKFILE, O_WRONLY, 0); err = posix_spawn(&pid, "/bin/cat", &fa, NULL, args, NULL); posix_spawn_file_actions_destroy(&fa); ATF_REQUIRE(err == 0); /* ok, wait for the child to finish */ waitpid(pid, &status, 0); ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_FAILURE); /* now check that input and output are still the same size */ insize = filesize(TESTFILE); outsize = filesize(CHECKFILE); ATF_REQUIRE(insize == strlen(TESTCONTENT)); ATF_REQUIRE(outsize == 0); } ATF_TC(t_spawn_reopen); ATF_TC_HEAD(t_spawn_reopen, tc) { atf_tc_set_md_var(tc, "descr", "an open filehandle can be replaced by a 'open' fileaction"); atf_tc_set_md_var(tc, "require.progs", "/bin/cat"); } ATF_TC_BODY(t_spawn_reopen, tc) { int status, err; pid_t pid; char * const args[2] = { __UNCONST("cat"), NULL }; posix_spawn_file_actions_t fa; /* * make sure stdin is open in the parent */ freopen("/dev/zero", "r", stdin); /* * now request an open for this fd again in the child */ posix_spawn_file_actions_init(&fa); posix_spawn_file_actions_addopen(&fa, fileno(stdin), "/dev/null", O_RDONLY, 0); err = posix_spawn(&pid, "/bin/cat", &fa, NULL, args, NULL); posix_spawn_file_actions_destroy(&fa); ATF_REQUIRE(err == 0); waitpid(pid, &status, 0); ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS); } ATF_TC(t_spawn_open_nonexistent); ATF_TC_HEAD(t_spawn_open_nonexistent, tc) { atf_tc_set_md_var(tc, "descr", "posix_spawn fails when a file to open does not exist"); atf_tc_set_md_var(tc, "require.progs", "/bin/cat"); } ATF_TC_BODY(t_spawn_open_nonexistent, tc) { int err, status; pid_t pid; char * const args[2] = { __UNCONST("cat"), NULL }; posix_spawn_file_actions_t fa; posix_spawn_file_actions_init(&fa); posix_spawn_file_actions_addopen(&fa, STDIN_FILENO, "./non/ex/ist/ent", O_RDONLY, 0); err = posix_spawn(&pid, "/bin/cat", &fa, NULL, args, NULL); if (err == 0) { /* * The child has been created - it should fail and * return exit code 127 */ waitpid(pid, &status, 0); ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 127); } else { /* * The error has been noticed early enough, no child has * been run */ ATF_REQUIRE(err == ENOENT); } posix_spawn_file_actions_destroy(&fa); } #ifdef __NetBSD__ ATF_TC(t_spawn_open_nonexistent_diag); ATF_TC_HEAD(t_spawn_open_nonexistent_diag, tc) { atf_tc_set_md_var(tc, "descr", "posix_spawn fails when a file to open does not exist " "and delivers proper diagnostic"); atf_tc_set_md_var(tc, "require.progs", "/bin/cat"); } ATF_TC_BODY(t_spawn_open_nonexistent_diag, tc) { int err; pid_t pid; char * const args[2] = { __UNCONST("cat"), NULL }; posix_spawnattr_t attr; posix_spawn_file_actions_t fa; posix_spawnattr_init(&attr); /* * POSIX_SPAWN_RETURNERROR is a NetBSD specific flag that * will cause a "proper" return value from posix_spawn(2) * instead of a (potential) success there and a 127 exit * status from the child process (c.f. the non-diag variant * of this test). */ posix_spawnattr_setflags(&attr, POSIX_SPAWN_RETURNERROR); posix_spawn_file_actions_init(&fa); posix_spawn_file_actions_addopen(&fa, STDIN_FILENO, "./non/ex/ist/ent", O_RDONLY, 0); err = posix_spawn(&pid, "/bin/cat", &fa, &attr, args, NULL); ATF_REQUIRE(err == ENOENT); posix_spawn_file_actions_destroy(&fa); posix_spawnattr_destroy(&attr); } #endif ATF_TC(t_spawn_fileactions); ATF_TC_HEAD(t_spawn_fileactions, tc) { atf_tc_set_md_var(tc, "descr", "Tests various complex fileactions"); } ATF_TC_BODY(t_spawn_fileactions, tc) { int fd1, fd2, fd3, status, err; pid_t pid; char * const args[2] = { __UNCONST("h_fileactions"), NULL }; char helper[FILENAME_MAX]; posix_spawn_file_actions_t fa; posix_spawn_file_actions_init(&fa); closefrom(fileno(stderr)+1); fd1 = open("/dev/null", O_RDONLY); ATF_REQUIRE(fd1 == 3); fd2 = open("/dev/null", O_WRONLY, O_CLOEXEC); ATF_REQUIRE(fd2 == 4); fd3 = open("/dev/null", O_WRONLY); ATF_REQUIRE(fd3 == 5); posix_spawn_file_actions_addclose(&fa, fd1); posix_spawn_file_actions_addopen(&fa, 6, "/dev/null", O_RDWR, 0); posix_spawn_file_actions_adddup2(&fa, 1, 7); snprintf(helper, sizeof helper, "%s/h_fileactions", atf_tc_get_config_var(tc, "srcdir")); err = posix_spawn(&pid, helper, &fa, NULL, args, NULL); posix_spawn_file_actions_destroy(&fa); ATF_REQUIRE(err == 0); waitpid(pid, &status, 0); ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS); } ATF_TC(t_spawn_empty_fileactions); ATF_TC_HEAD(t_spawn_empty_fileactions, tc) { atf_tc_set_md_var(tc, "descr", "posix_spawn with empty fileactions (PR kern/46038)"); atf_tc_set_md_var(tc, "require.progs", "/bin/cat"); } ATF_TC_BODY(t_spawn_empty_fileactions, tc) { int status, err; pid_t pid; char * const args[2] = { __UNCONST("cat"), NULL }; posix_spawn_file_actions_t fa; size_t insize, outsize; /* * try a "cat < testfile > checkfile", but set up stdin/stdout * already in the parent and pass empty file actions to the child. */ make_testfile(TESTFILE); unlink(CHECKFILE); freopen(TESTFILE, "r", stdin); freopen(CHECKFILE, "w", stdout); posix_spawn_file_actions_init(&fa); err = posix_spawn(&pid, "/bin/cat", &fa, NULL, args, NULL); posix_spawn_file_actions_destroy(&fa); ATF_REQUIRE(err == 0); /* ok, wait for the child to finish */ waitpid(pid, &status, 0); ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS); /* now check that input and output have the same size */ insize = filesize(TESTFILE); outsize = filesize(CHECKFILE); ATF_REQUIRE(insize == strlen(TESTCONTENT)); ATF_REQUIRE(insize == outsize); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, t_spawn_fileactions); ATF_TP_ADD_TC(tp, t_spawn_open_nonexistent); #ifdef __NetBSD__ ATF_TP_ADD_TC(tp, t_spawn_open_nonexistent_diag); #endif ATF_TP_ADD_TC(tp, t_spawn_reopen); ATF_TP_ADD_TC(tp, t_spawn_openmode); ATF_TP_ADD_TC(tp, t_spawn_empty_fileactions); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/gen/t_assert.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_assert.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/gen/t_assert.c (revision 311925) @@ -1,155 +1,148 @@ -/* $NetBSD: t_assert.c,v 1.2 2011/06/14 05:28:00 jruoho Exp $ */ +/* $NetBSD: t_assert.c,v 1.3 2017/01/10 15:17:57 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * 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 -__RCSID("$NetBSD: t_assert.c,v 1.2 2011/06/14 05:28:00 jruoho Exp $"); +__RCSID("$NetBSD: t_assert.c,v 1.3 2017/01/10 15:17:57 christos Exp $"); +#include +#include +#include #include #include #include #include #include #include #include -#ifdef __FreeBSD__ -#include -#include -#include - static void disable_corefile(void) { struct rlimit limits; limits.rlim_cur = 0; limits.rlim_max = 0; ATF_REQUIRE(setrlimit(RLIMIT_CORE, &limits) == 0); } -#endif static void handler(int); static void handler(int signo) { /* Nothing. */ } ATF_TC(assert_false); ATF_TC_HEAD(assert_false, tc) { atf_tc_set_md_var(tc, "descr", "Test that assert(3) works, #1"); } ATF_TC_BODY(assert_false, tc) { struct sigaction sa; pid_t pid; int sta; pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { -#ifdef __FreeBSD__ disable_corefile(); -#endif (void)closefrom(0); (void)memset(&sa, 0, sizeof(struct sigaction)); sa.sa_flags = 0; sa.sa_handler = handler; (void)sigemptyset(&sa.sa_mask); (void)sigaction(SIGABRT, &sa, 0); assert(1 == 1); _exit(EXIT_SUCCESS); } (void)wait(&sta); if (WIFSIGNALED(sta) != 0 || WIFEXITED(sta) == 0) atf_tc_fail("assert(3) fired haphazardly"); } ATF_TC(assert_true); ATF_TC_HEAD(assert_true, tc) { atf_tc_set_md_var(tc, "descr", "Test that assert(3) works, #2"); } ATF_TC_BODY(assert_true, tc) { struct sigaction sa; pid_t pid; int sta; pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { -#ifdef __FreeBSD__ disable_corefile(); -#endif (void)closefrom(0); (void)memset(&sa, 0, sizeof(struct sigaction)); sa.sa_flags = 0; sa.sa_handler = handler; (void)sigemptyset(&sa.sa_mask); (void)sigaction(SIGABRT, &sa, 0); assert(1 == 2); _exit(EXIT_SUCCESS); } (void)wait(&sta); if (WIFSIGNALED(sta) == 0 || WTERMSIG(sta) != SIGABRT) atf_tc_fail("assert(3) did not fire"); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, assert_false); ATF_TP_ADD_TC(tp, assert_true); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/gen/t_dir.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_dir.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/gen/t_dir.c (revision 311925) @@ -1,201 +1,187 @@ -/* $NetBSD: t_dir.c,v 1.6 2013/10/19 17:45:00 christos Exp $ */ +/* $NetBSD: t_dir.c,v 1.8 2017/01/11 07:26:17 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. * 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 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 - +#include #include +#include #include #include +#include #include #include #include #include #include -#include -#ifdef __FreeBSD__ -#include -#endif ATF_TC(seekdir_basic); ATF_TC_HEAD(seekdir_basic, tc) { atf_tc_set_md_var(tc, "descr", "Check telldir(3) and seekdir(3) " "for correct behavior (PR lib/24324)"); } ATF_TC_BODY(seekdir_basic, tc) { DIR *dp; char *wasname; struct dirent *entry; long here; -#ifdef __FreeBSD__ #define CREAT(x, m) do { \ int _creat_fd; \ ATF_REQUIRE_MSG((_creat_fd = creat((x), (m))) != -1, \ "creat(%s, %x) failed: %s", (x), (m), \ strerror(errno)); \ (void)close(_creat_fd); \ } while(0); ATF_REQUIRE_MSG(mkdir("t", 0755) == 0, "mkdir failed: %s", strerror(errno)); CREAT("t/a", 0600); CREAT("t/b", 0600); CREAT("t/c", 0600); -#else - mkdir("t", 0755); - creat("t/a", 0600); - creat("t/b", 0600); - creat("t/c", 0600); -#endif 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); -#ifdef __FreeBSD__ ATF_REQUIRE_MSG(here != -1, "telldir failed: %s", strerror(errno)); -#endif /* get second entry */ entry = readdir(dp); #ifdef __FreeBSD__ ATF_REQUIRE_MSG(entry != NULL, "readdir failed: %s", strerror(errno)); #endif wasname = strdup(entry->d_name); if (wasname == NULL) atf_tc_fail("cannot allocate memory"); /* get third entry */ entry = readdir(dp); /* try to return to the position after the first entry */ seekdir(dp, here); entry = readdir(dp); if (entry == NULL) atf_tc_fail("entry 1 not found"); 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 (entry == NULL) atf_tc_fail("entry 2 not found"); 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 (entry == NULL) atf_tc_fail("entry 3 not found"); if (strcmp(entry->d_name, wasname) != 0) atf_tc_fail("3rd seekdir found wrong name"); closedir(dp); -#ifdef __FreeBSD__ free(wasname); -#endif } /* There is no sbrk on AArch64 and RISC-V */ #if !defined(__aarch64__) && !defined(__riscv__) ATF_TC(telldir_leak); ATF_TC_HEAD(telldir_leak, tc) { atf_tc_set_md_var(tc, "descr", "Check telldir(3) for memory leakage (PR lib/24324)"); } ATF_TC_BODY(telldir_leak, tc) { DIR *dp; char *memused; int i; int oktouse = 4096; dp = opendir("."); if (dp == NULL) atf_tc_fail("Could not open current directory"); (void)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"); (void)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 %d bytes", oktouse); } else { (void)printf("OK: used %td bytes\n", (char *)(sbrk(0))-memused); } } #endif ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, seekdir_basic); #if !defined(__aarch64__) && !defined(__riscv__) ATF_TP_ADD_TC(tp, telldir_leak); #endif return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/gen/t_ftok.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_ftok.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/gen/t_ftok.c (revision 311925) @@ -1,110 +1,108 @@ -/* $NetBSD: t_ftok.c,v 1.1 2011/11/08 05:47:00 jruoho Exp $ */ +/* $NetBSD: t_ftok.c,v 1.2 2017/01/10 15:19:52 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * 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 -__RCSID("$NetBSD: t_ftok.c,v 1.1 2011/11/08 05:47:00 jruoho Exp $"); +__RCSID("$NetBSD: t_ftok.c,v 1.2 2017/01/10 15:19:52 christos Exp $"); #include #include #include #include #include static const char *path = "ftok"; static const char *hlnk = "hlnk"; static const char *slnk = "slnk"; static const int key = 123456789; ATF_TC(ftok_err); ATF_TC_HEAD(ftok_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from ftok(3)"); } ATF_TC_BODY(ftok_err, tc) { ATF_REQUIRE(ftok("/a/b/c/d/e/f/g/h/i", key) == -1); } ATF_TC_WITH_CLEANUP(ftok_link); ATF_TC_HEAD(ftok_link, tc) { atf_tc_set_md_var(tc, "descr", "Test that links return the same key"); } ATF_TC_BODY(ftok_link, tc) { key_t k1, k2, k3; int fd; fd = open(path, O_RDONLY | O_CREAT); ATF_REQUIRE(fd >= 0); -#ifdef __FreeBSD__ (void)close(fd); -#endif ATF_REQUIRE(link(path, hlnk) == 0); ATF_REQUIRE(symlink(path, slnk) == 0); k1 = ftok(path, key); k2 = ftok(hlnk, key); k3 = ftok(slnk, key); ATF_REQUIRE(k1 != -1); ATF_REQUIRE(k2 != -1); ATF_REQUIRE(k3 != -1); if (k1 != k2) atf_tc_fail("ftok(3) gave different key for a hard link"); if (k1 != k3) atf_tc_fail("ftok(3) gave different key for a symbolic link"); ATF_REQUIRE(unlink(path) == 0); ATF_REQUIRE(unlink(hlnk) == 0); ATF_REQUIRE(unlink(slnk) == 0); } ATF_TC_CLEANUP(ftok_link, tc) { (void)unlink(path); (void)unlink(hlnk); (void)unlink(slnk); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, ftok_err); ATF_TP_ADD_TC(tp, ftok_link); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/gen/t_humanize_number.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_humanize_number.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/gen/t_humanize_number.c (revision 311925) @@ -1,321 +1,319 @@ -/* $NetBSD: t_humanize_number.c,v 1.8 2012/03/18 07:14:08 jruoho Exp $ */ +/* $NetBSD: t_humanize_number.c,v 1.9 2017/01/10 15:20:44 christos Exp $ */ /*- * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc. * 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 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 #include #include #include #include #include #include #ifdef __FreeBSD__ #include #else #include #endif 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". */ #ifndef __FreeBSD__ { 6, 1000, "A", HN_AUTOSCALE, HN_DECIMAL, -1, "" }, /* * Failure case reported by Greg Troxel . * 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" }, #endif { 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 *, ...) __printflike(1, 2); 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_number_basic); ATF_TC_HEAD(humanize_number_basic, tc) { atf_tc_set_md_var(tc, "descr", "Test humanize_number(3)"); } ATF_TC_BODY(humanize_number_basic, 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(..., %zu) 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\", %zu, %" 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); } -#ifdef __FreeBSD__ free(buf); -#endif } ATF_TC(humanize_number_big); ATF_TC_HEAD(humanize_number_big, tc) { atf_tc_set_md_var(tc, "descr", "Test humanize " "big numbers (PR lib/44097)"); } ATF_TC_BODY(humanize_number_big, tc) { char buf[1024]; int rv; /* * Seems to work. */ (void)memset(buf, 0, sizeof(buf)); rv = humanize_number(buf, 10, 10000, "", HN_AUTOSCALE, HN_NOSPACE); ATF_REQUIRE(rv != -1); ATF_CHECK_STREQ(buf, "10000"); /* * A bogus value with large number. */ (void)memset(buf, 0, sizeof(buf)); rv = humanize_number(buf, 10, INT64_MAX, "", HN_AUTOSCALE, HN_NOSPACE); ATF_REQUIRE(rv != -1); ATF_REQUIRE(strcmp(buf, "0") != 0); /* * Large buffer with HN_AUTOSCALE. Entirely bogus. */ (void)memset(buf, 0, sizeof(buf)); rv = humanize_number(buf, sizeof(buf), 10000, "", HN_AUTOSCALE, HN_NOSPACE); ATF_REQUIRE(rv != -1); ATF_REQUIRE(strcmp(buf, "0%d%s%d%s%s%s") != 0); /* * Tight buffer. * * The man page says that len must be at least 4. * 3 works, but anything less that will not. This * is because baselen starts with 2 for positive * numbers. */ (void)memset(buf, 0, sizeof(buf)); rv = humanize_number(buf, 3, 1, "", HN_AUTOSCALE, HN_NOSPACE); ATF_REQUIRE(rv != -1); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, humanize_number_basic); ATF_TP_ADD_TC(tp, humanize_number_big); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/gen/t_sleep.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_sleep.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/gen/t_sleep.c (revision 311925) @@ -1,351 +1,351 @@ -/* $NetBSD: t_sleep.c,v 1.9 2016/08/11 21:34:11 kre Exp $ */ +/* $NetBSD: t_sleep.c,v 1.11 2017/01/10 15:43:59 maya Exp $ */ /*- * Copyright (c) 2006 Frank Kardel * 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 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. */ +#ifdef __FreeBSD__ +#include +#endif +#include +#include +#include +#include /* for TIMESPEC_TO_TIMEVAL on FreeBSD */ + #include #include +#include #include #include #include #include #include #include -#include -#include -#include - #include "isqemu.h" #define BILLION 1000000000LL /* nano-seconds per second */ #define MILLION 1000000LL /* nano-seconds per milli-second */ #define ALARM 6 /* SIGALRM after this many seconds */ #define MAXSLEEP 22 /* Maximum delay in seconds */ #define KEVNT_TIMEOUT 10300 /* measured in milli-seconds */ #define FUZZ (40 * MILLION) /* scheduling fuzz accepted - 40 ms */ - -#ifdef __FreeBSD__ -#include -#include -#endif /* * Timer notes * * Most tests use FUZZ as their initial delay value, but 'sleep' * starts at 1sec (since it cannot handle sub-second intervals). * Subsequent passes double the previous interval, up to MAXSLEEP. * * The current values result in 5 passes for the 'sleep' test (at 1, * 2, 4, 8, and 16 seconds) and 10 passes for the other tests (at * 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24, and 20.48 * seconds). * * The ALARM is only set if the current pass's delay is longer, and * only if the ALARM has not already been triggered. * * The 'kevent' test needs the ALARM to be set on a different pass * from when the KEVNT_TIMEOUT fires. So set ALARM to fire on the * penultimate pass, and the KEVNT_TIMEOUT on the final pass. We * set KEVNT_TIMEOUT just barely long enough to put it into the * last test pass, and set MAXSLEEP a couple seconds longer than * necessary, in order to avoid a QEMU bug which nearly doubles * some timers. */ static volatile int sig; int sleeptest(int (*)(struct timespec *, struct timespec *), bool, bool); int do_nanosleep(struct timespec *, struct timespec *); int do_select(struct timespec *, struct timespec *); #ifdef __NetBSD__ int do_poll(struct timespec *, struct timespec *); #endif int do_sleep(struct timespec *, struct timespec *); int do_kevent(struct timespec *, struct timespec *); void sigalrm(int); void sigalrm(int s) { sig++; } int do_nanosleep(struct timespec *delay, struct timespec *remain) { int ret; if (nanosleep(delay, remain) == -1) ret = (errno == EINTR ? 0 : errno); else ret = 0; return ret; } int do_select(struct timespec *delay, struct timespec *remain) { int ret; struct timeval tv; TIMESPEC_TO_TIMEVAL(&tv, delay); if (select(0, NULL, NULL, NULL, &tv) == -1) ret = (errno == EINTR ? 0 : errno); else ret = 0; return ret; } #ifdef __NetBSD__ int do_poll(struct timespec *delay, struct timespec *remain) { int ret; struct timeval tv; TIMESPEC_TO_TIMEVAL(&tv, delay); if (pollts(NULL, 0, delay, NULL) == -1) ret = (errno == EINTR ? 0 : errno); else ret = 0; return ret; } #endif int do_sleep(struct timespec *delay, struct timespec *remain) { struct timeval tv; TIMESPEC_TO_TIMEVAL(&tv, delay); remain->tv_sec = sleep(delay->tv_sec); remain->tv_nsec = 0; return 0; } int do_kevent(struct timespec *delay, struct timespec *remain) { struct kevent ktimer; struct kevent kresult; int rtc, kq, kerrno; int tmo; ATF_REQUIRE_MSG((kq = kqueue()) != -1, "kqueue: %s", strerror(errno)); tmo = KEVNT_TIMEOUT; /* * If we expect the KEVNT_TIMEOUT to fire, and we're running * under QEMU, make sure the delay is long enough to account * for the effects of PR kern/43997 ! */ if (isQEMU() && tmo/1000 < delay->tv_sec && tmo/500 > delay->tv_sec) delay->tv_sec = MAXSLEEP; EV_SET(&ktimer, 1, EVFILT_TIMER, EV_ADD, 0, tmo, 0); rtc = kevent(kq, &ktimer, 1, &kresult, 1, delay); kerrno = errno; (void)close(kq); if (rtc == -1) { ATF_REQUIRE_MSG(kerrno == EINTR, "kevent: %s", strerror(kerrno)); return 0; } if (delay->tv_sec * BILLION + delay->tv_nsec > tmo * MILLION) ATF_REQUIRE_MSG(rtc > 0, "kevent: KEVNT_TIMEOUT did not cause EVFILT_TIMER event"); return 0; } ATF_TC(nanosleep); ATF_TC_HEAD(nanosleep, tc) { atf_tc_set_md_var(tc, "descr", "Test nanosleep(2) timing"); atf_tc_set_md_var(tc, "timeout", "65"); } ATF_TC_BODY(nanosleep, tc) { sleeptest(do_nanosleep, true, false); } ATF_TC(select); ATF_TC_HEAD(select, tc) { atf_tc_set_md_var(tc, "descr", "Test select(2) timing"); atf_tc_set_md_var(tc, "timeout", "65"); } ATF_TC_BODY(select, tc) { sleeptest(do_select, true, true); } #ifdef __NetBSD__ ATF_TC(poll); ATF_TC_HEAD(poll, tc) { atf_tc_set_md_var(tc, "descr", "Test poll(2) timing"); atf_tc_set_md_var(tc, "timeout", "65"); } ATF_TC_BODY(poll, tc) { sleeptest(do_poll, true, true); } #endif ATF_TC(sleep); ATF_TC_HEAD(sleep, tc) { atf_tc_set_md_var(tc, "descr", "Test sleep(3) timing"); atf_tc_set_md_var(tc, "timeout", "65"); } ATF_TC_BODY(sleep, tc) { sleeptest(do_sleep, false, false); } ATF_TC(kevent); ATF_TC_HEAD(kevent, tc) { atf_tc_set_md_var(tc, "descr", "Test kevent(2) timing"); atf_tc_set_md_var(tc, "timeout", "65"); } ATF_TC_BODY(kevent, tc) { sleeptest(do_kevent, true, true); } int sleeptest(int (*test)(struct timespec *, struct timespec *), bool subsec, bool sim_remain) { struct timespec tsa, tsb, tslp, tremain; int64_t delta1, delta2, delta3, round; sig = 0; signal(SIGALRM, sigalrm); if (subsec) { round = 1; delta3 = FUZZ; } else { round = 1000000000; delta3 = round; } tslp.tv_sec = delta3 / 1000000000; tslp.tv_nsec = delta3 % 1000000000; while (tslp.tv_sec <= MAXSLEEP) { /* * disturb sleep by signal on purpose */ if (tslp.tv_sec > ALARM && sig == 0) alarm(ALARM); clock_gettime(CLOCK_REALTIME, &tsa); (*test)(&tslp, &tremain); clock_gettime(CLOCK_REALTIME, &tsb); if (sim_remain) { timespecsub(&tsb, &tsa, &tremain); timespecsub(&tslp, &tremain, &tremain); } delta1 = (int64_t)tsb.tv_sec - (int64_t)tsa.tv_sec; delta1 *= BILLION; delta1 += (int64_t)tsb.tv_nsec - (int64_t)tsa.tv_nsec; delta2 = (int64_t)tremain.tv_sec * BILLION; delta2 += (int64_t)tremain.tv_nsec; delta3 = (int64_t)tslp.tv_sec * BILLION; delta3 += (int64_t)tslp.tv_nsec - delta1 - delta2; delta3 /= round; delta3 *= round; if (delta3 > FUZZ || delta3 < -FUZZ) { if (!sim_remain) atf_tc_expect_fail("Long reschedule latency " "due to PR kern/43997"); atf_tc_fail("Reschedule latency %"PRId64" exceeds " "allowable fuzz %lld", delta3, FUZZ); } delta3 = (int64_t)tslp.tv_sec * 2 * BILLION; delta3 += (int64_t)tslp.tv_nsec * 2; delta3 /= round; delta3 *= round; if (delta3 < FUZZ) break; tslp.tv_sec = delta3 / BILLION; tslp.tv_nsec = delta3 % BILLION; } ATF_REQUIRE_MSG(sig == 1, "Alarm did not fire!"); atf_tc_pass(); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, nanosleep); ATF_TP_ADD_TC(tp, select); #ifdef __NetBSD__ ATF_TP_ADD_TC(tp, poll); #endif ATF_TP_ADD_TC(tp, sleep); ATF_TP_ADD_TC(tp, kevent); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/gen/t_time.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_time.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/gen/t_time.c (revision 311925) @@ -1,118 +1,116 @@ -/* $NetBSD: t_time.c,v 1.3 2014/10/31 12:22:38 justin Exp $ */ +/* $NetBSD: t_time.c,v 1.4 2017/01/10 15:32:46 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * 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 -__RCSID("$NetBSD: t_time.c,v 1.3 2014/10/31 12:22:38 justin Exp $"); +__RCSID("$NetBSD: t_time.c,v 1.4 2017/01/10 15:32:46 christos Exp $"); -#ifdef __FreeBSD__ -#include -#endif #include #include #include #include #include #include #include +#include #include ATF_TC(time_copy); ATF_TC_HEAD(time_copy, tc) { atf_tc_set_md_var(tc, "descr", "Test the return values of time(3)"); } ATF_TC_BODY(time_copy, tc) { time_t t1, t2 = 0; t1 = time(&t2); if (t1 != t2) atf_tc_fail("incorrect return values from time(3)"); } ATF_TC(time_mono); ATF_TC_HEAD(time_mono, tc) { atf_tc_set_md_var(tc, "descr", "Test monotonicity of time(3)"); } ATF_TC_BODY(time_mono, tc) { const size_t maxiter = 10; time_t t1, t2; size_t i; for (i = 0; i < maxiter; i++) { t1 = time(NULL); (void)sleep(1); t2 = time(NULL); (void)fprintf(stderr, "%"PRId64" vs. %"PRId64"\n", (int64_t)t1, (int64_t)t2); if (t1 >= t2) atf_tc_fail("time(3) is not monotonic"); } } ATF_TC(time_timeofday); ATF_TC_HEAD(time_timeofday, tc) { atf_tc_set_md_var(tc, "descr", "Test time(3) vs. gettimeofday(2)"); } ATF_TC_BODY(time_timeofday, tc) { struct timeval tv = { 0, 0 }; time_t t1, t2; t1 = time(NULL); ATF_REQUIRE(gettimeofday(&tv, NULL) == 0); t2 = time(NULL); (void)fprintf(stderr, "%"PRId64" vs. %"PRId64"\n", (int64_t)t1, (int64_t)tv.tv_sec); if (t1 > tv.tv_sec || t2 < tv.tv_sec) atf_tc_fail("time(3) and gettimeofday(2) differ"); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, time_copy); ATF_TP_ADD_TC(tp, time_mono); ATF_TP_ADD_TC(tp, time_timeofday); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/gen/t_ttyname.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_ttyname.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/gen/t_ttyname.c (revision 311925) @@ -1,191 +1,189 @@ -/* $NetBSD: t_ttyname.c,v 1.3 2011/05/01 18:14:01 jruoho Exp $ */ +/* $NetBSD: t_ttyname.c,v 1.4 2017/01/10 15:33:40 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * 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 -__RCSID("$NetBSD: t_ttyname.c,v 1.3 2011/05/01 18:14:01 jruoho Exp $"); +__RCSID("$NetBSD: t_ttyname.c,v 1.4 2017/01/10 15:33:40 christos Exp $"); #include #include #include #include #include #include static long ttymax = 0; ATF_TC(ttyname_err); ATF_TC_HEAD(ttyname_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors in ttyname(3)"); } ATF_TC_BODY(ttyname_err, tc) { int fd; fd = open("XXX", O_RDONLY); if (fd < 0) { errno = 0; ATF_REQUIRE(isatty(fd) != -1); ATF_REQUIRE(errno == EBADF); errno = 0; ATF_REQUIRE(ttyname(fd) == NULL); ATF_REQUIRE(errno == EBADF); } fd = open("/etc/passwd", O_RDONLY); if (fd >= 0) { errno = 0; ATF_REQUIRE(isatty(fd) != -1); ATF_REQUIRE(errno == ENOTTY); errno = 0; ATF_REQUIRE(ttyname(fd) == NULL); ATF_REQUIRE(errno == ENOTTY); -#ifdef __FreeBSD__ (void)close(fd); -#endif } } ATF_TC(ttyname_r_err); ATF_TC_HEAD(ttyname_r_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors in ttyname_r(3)"); } ATF_TC_BODY(ttyname_r_err, tc) { char sbuf[0]; char *buf; int fd; int rv; buf = malloc(ttymax + 1); if (buf == NULL) return; (void)memset(buf, '\0', ttymax + 1); if (isatty(STDIN_FILENO) != 0) { rv = ttyname_r(STDIN_FILENO, sbuf, sizeof(sbuf)); ATF_REQUIRE(rv == ERANGE); } rv = ttyname_r(-1, buf, ttymax); ATF_REQUIRE(rv == EBADF); fd = open("/etc/passwd", O_RDONLY); if (fd >= 0) { rv = ttyname_r(fd, buf, ttymax); ATF_REQUIRE(rv == ENOTTY); ATF_REQUIRE(close(fd) == 0); } free(buf); } ATF_TC(ttyname_r_stdin); ATF_TC_HEAD(ttyname_r_stdin, tc) { atf_tc_set_md_var(tc, "descr", "Test ttyname_r(3) with stdin(3)"); } ATF_TC_BODY(ttyname_r_stdin, tc) { const char *str; char *buf; int rv; if (isatty(STDIN_FILENO) == 0) return; buf = malloc(ttymax + 1); if (buf == NULL) return; (void)memset(buf, '\0', ttymax + 1); str = ttyname(STDIN_FILENO); rv = ttyname_r(STDIN_FILENO, buf, ttymax); ATF_REQUIRE(rv == 0); ATF_REQUIRE(str != NULL); if (strcmp(str, buf) != 0) atf_tc_fail("ttyname(3) and ttyname_r(3) conflict"); free(buf); } ATF_TC(ttyname_stdin); ATF_TC_HEAD(ttyname_stdin, tc) { atf_tc_set_md_var(tc, "descr", "Test ttyname(3) with stdin(3)"); } ATF_TC_BODY(ttyname_stdin, tc) { if (isatty(STDIN_FILENO) != 0) ATF_REQUIRE(ttyname(STDIN_FILENO) != NULL); (void)close(STDIN_FILENO); ATF_REQUIRE(isatty(STDIN_FILENO) != 1); ATF_REQUIRE(ttyname(STDIN_FILENO) == NULL); } ATF_TP_ADD_TCS(tp) { ttymax = sysconf(_SC_TTY_NAME_MAX); ATF_REQUIRE(ttymax >= 0); ATF_TP_ADD_TC(tp, ttyname_err); ATF_TP_ADD_TC(tp, ttyname_r_err); ATF_TP_ADD_TC(tp, ttyname_r_stdin); ATF_TP_ADD_TC(tp, ttyname_stdin); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/gen/t_vis.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_vis.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/gen/t_vis.c (revision 311925) @@ -1,198 +1,190 @@ -/* $NetBSD: t_vis.c,v 1.8 2015/05/23 14:02:11 christos Exp $ */ +/* $NetBSD: t_vis.c,v 1.9 2017/01/10 15:16:57 christos 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 #include #include #include #include #include static int styles[] = { VIS_OCTAL, VIS_CSTYLE, VIS_SP, VIS_TAB, VIS_NL, VIS_WHITE, VIS_SAFE, #if 0 /* Not reversible */ VIS_NOSLASH, #endif VIS_HTTP1808, VIS_MIMESTYLE, #if 0 /* Not supported by vis(3) */ VIS_HTTP1866, #endif }; #define SIZE 256 ATF_TC(strvis_basic); ATF_TC_HEAD(strvis_basic, tc) { atf_tc_set_md_var(tc, "descr", "Test strvis(3)"); } ATF_TC_BODY(strvis_basic, tc) { char *srcbuf, *dstbuf, *visbuf; unsigned int i, j; ATF_REQUIRE((dstbuf = malloc(SIZE)) != NULL); ATF_REQUIRE((srcbuf = malloc(SIZE)) != NULL); ATF_REQUIRE((visbuf = malloc(SIZE * 4 + 1)) != NULL); for (i = 0; i < SIZE; i++) srcbuf[i] = (char)i; for (i = 0; i < __arraycount(styles); i++) { ATF_REQUIRE(strsvisx(visbuf, srcbuf, SIZE, styles[i], "") > 0); memset(dstbuf, 0, SIZE); ATF_REQUIRE(strunvisx(dstbuf, visbuf, styles[i] & (VIS_HTTP1808|VIS_MIMESTYLE)) > 0); 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]); } free(dstbuf); free(srcbuf); free(visbuf); } ATF_TC(strvis_null); ATF_TC_HEAD(strvis_null, tc) { atf_tc_set_md_var(tc, "descr", "Test strvis(3) NULL"); } ATF_TC_BODY(strvis_null, tc) { char dst[] = "fail"; strvis(dst, NULL, VIS_SAFE); ATF_REQUIRE(dst[0] == '\0' && dst[1] == 'a'); } ATF_TC(strvis_empty); ATF_TC_HEAD(strvis_empty, tc) { atf_tc_set_md_var(tc, "descr", "Test strvis(3) empty"); } ATF_TC_BODY(strvis_empty, tc) { char dst[] = "fail"; strvis(dst, "", VIS_SAFE); ATF_REQUIRE(dst[0] == '\0' && dst[1] == 'a'); } ATF_TC(strunvis_hex); ATF_TC_HEAD(strunvis_hex, tc) { atf_tc_set_md_var(tc, "descr", "Test strunvis(3) \\xXX"); } ATF_TC_BODY(strunvis_hex, tc) { static const struct { const char *e; const char *d; int error; } ed[] = { { "\\xff", "\xff", 1 }, { "\\x1", "\x1", 1 }, { "\\x1\\x02", "\x1\x2", 2 }, { "\\x1x", "\x1x", 2 }, { "\\xx", "", -1 }, }; char uv[10]; for (size_t i = 0; i < __arraycount(ed); i++) { ATF_REQUIRE(strunvis(uv, ed[i].e) == ed[i].error); if (ed[i].error > 0) ATF_REQUIRE(memcmp(ed[i].d, uv, ed[i].error) == 0); } } -/* Begin FreeBSD: ^/stable/10 doesn't have VIS_NOLOCALE */ #ifdef VIS_NOLOCALE -/* End FreeBSD */ ATF_TC(strvis_locale); ATF_TC_HEAD(strvis_locale, tc) { atf_tc_set_md_var(tc, "descr", "Test strvis(3) with locale"); } ATF_TC_BODY(strvis_locale, tc) { char s[256], cd[sizeof(s) * 4 + 1], jd[sizeof(cd)], *ol; int jr, cr; for (size_t i = 0; i < sizeof(s) - 1; i++) s[i] = i + 1; s[sizeof(s) - 1] = '\0'; ol = setlocale(LC_CTYPE, "ja_JP.UTF-8"); ATF_REQUIRE(ol != NULL); jr = strvisx(jd, s, sizeof(s), VIS_WHITE | VIS_NOLOCALE); ATF_REQUIRE(jr != -1); ol = strdup(ol); ATF_REQUIRE(ol != NULL); ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL); cr = strvisx(cd, s, sizeof(s), VIS_WHITE); ATF_REQUIRE(jr == cr); ATF_REQUIRE(memcmp(jd, cd, jr) == 0); setlocale(LC_CTYPE, ol); free(ol); } -/* Begin FreeBSD: ^/stable/10 doesn't have VIS_NOLOCALE */ #endif /* VIS_NOLOCALE */ -/* End FreeBSD */ ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, strvis_basic); ATF_TP_ADD_TC(tp, strvis_null); ATF_TP_ADD_TC(tp, strvis_empty); ATF_TP_ADD_TC(tp, strunvis_hex); -/* Begin FreeBSD: ^/stable/10 doesn't have VIS_NOLOCALE */ #ifdef VIS_NOLOCALE -/* End FreeBSD */ ATF_TP_ADD_TC(tp, strvis_locale); -/* Begin FreeBSD: ^/stable/10 doesn't have VIS_NOLOCALE */ #endif /* VIS_NOLOCALE */ -/* End FreeBSD */ return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/string/t_strchr.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/string/t_strchr.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/string/t_strchr.c (revision 311925) @@ -1,302 +1,294 @@ -/* $NetBSD: t_strchr.c,v 1.1 2011/07/07 08:59:33 jruoho Exp $ */ +/* $NetBSD: t_strchr.c,v 1.2 2017/01/10 15:34:49 christos Exp $ */ /* * Written by J.T. Conklin * Public domain. */ #include #include #include #include #include #include static char *slow_strchr(char *, int); static void verify_strchr(char *, int, unsigned int, unsigned int); char * (*volatile strchr_fn)(const char *, int); static char * slow_strchr(char *buf, int ch) { unsigned char c = 1; ch &= 0xff; for (; c != 0; buf++) { c = *buf; if (c == ch) return buf; } return 0; } static void verify_strchr(char *buf, int ch, unsigned int t, unsigned int a) { const char *off, *ok_off; off = strchr_fn(buf, ch); ok_off = slow_strchr(buf, ch); if (off == ok_off) return; fprintf(stderr, "test_strchr(\"%s\", %#x) gave %zd not %zd (test %d, " "alignment %d)\n", buf, ch, off ? off - buf : -1, ok_off ? ok_off - buf : -1, t, a); atf_tc_fail("Check stderr for details"); } ATF_TC(strchr_basic); ATF_TC_HEAD(strchr_basic, tc) { atf_tc_set_md_var(tc, "descr", "Test strchr(3) results"); } ATF_TC_BODY(strchr_basic, tc) { -#ifdef __FreeBSD__ void *dl_handle; -#endif - unsigned int t, a; char *off; char buf[32]; + unsigned int t, a; const char *tab[] = { "", "a", "aa", "abc", "abcd", "abcde", "abcdef", "abcdefg", "abcdefgh", "/", "//", "/a", "/a/", "/ab", "/ab/", "/abc", "/abc/", "/abcd", "/abcd/", "/abcde", "/abcde/", "/abcdef", "/abcdef/", "/abcdefg", "/abcdefg/", "/abcdefgh", "/abcdefgh/", "a/", "a//", "a/a", "a/a/", "a/ab", "a/ab/", "a/abc", "a/abc/", "a/abcd", "a/abcd/", "a/abcde", "a/abcde/", "a/abcdef", "a/abcdef/", "a/abcdefg", "a/abcdefg/", "a/abcdefgh", "a/abcdefgh/", "ab/", "ab//", "ab/a", "ab/a/", "ab/ab", "ab/ab/", "ab/abc", "ab/abc/", "ab/abcd", "ab/abcd/", "ab/abcde", "ab/abcde/", "ab/abcdef", "ab/abcdef/", "ab/abcdefg", "ab/abcdefg/", "ab/abcdefgh", "ab/abcdefgh/", "abc/", "abc//", "abc/a", "abc/a/", "abc/ab", "abc/ab/", "abc/abc", "abc/abc/", "abc/abcd", "abc/abcd/", "abc/abcde", "abc/abcde/", "abc/abcdef", "abc/abcdef/", "abc/abcdefg", "abc/abcdefg/", "abc/abcdefgh", "abc/abcdefgh/", "abcd/", "abcd//", "abcd/a", "abcd/a/", "abcd/ab", "abcd/ab/", "abcd/abc", "abcd/abc/", "abcd/abcd", "abcd/abcd/", "abcd/abcde", "abcd/abcde/", "abcd/abcdef", "abcd/abcdef/", "abcd/abcdefg", "abcd/abcdefg/", "abcd/abcdefgh", "abcd/abcdefgh/", "abcde/", "abcde//", "abcde/a", "abcde/a/", "abcde/ab", "abcde/ab/", "abcde/abc", "abcde/abc/", "abcde/abcd", "abcde/abcd/", "abcde/abcde", "abcde/abcde/", "abcde/abcdef", "abcde/abcdef/", "abcde/abcdefg", "abcde/abcdefg/", "abcde/abcdefgh", "abcde/abcdefgh/", "abcdef/", "abcdef//", "abcdef/a", "abcdef/a/", "abcdef/ab", "abcdef/ab/", "abcdef/abc", "abcdef/abc/", "abcdef/abcd", "abcdef/abcd/", "abcdef/abcde", "abcdef/abcde/", "abcdef/abcdef", "abcdef/abcdef/", "abcdef/abcdefg", "abcdef/abcdefg/", "abcdef/abcdefgh", "abcdef/abcdefgh/", "abcdefg/", "abcdefg//", "abcdefg/a", "abcdefg/a/", "abcdefg/ab", "abcdefg/ab/", "abcdefg/abc", "abcdefg/abc/", "abcdefg/abcd", "abcdefg/abcd/", "abcdefg/abcde", "abcdefg/abcde/", "abcdefg/abcdef", "abcdefg/abcdef/", "abcdefg/abcdefg", "abcdefg/abcdefg/", "abcdefg/abcdefgh", "abcdefg/abcdefgh/", "abcdefgh/", "abcdefgh//", "abcdefgh/a", "abcdefgh/a/", "abcdefgh/ab", "abcdefgh/ab/", "abcdefgh/abc", "abcdefgh/abc/", "abcdefgh/abcd", "abcdefgh/abcd/", "abcdefgh/abcde", "abcdefgh/abcde/", "abcdefgh/abcdef", "abcdefgh/abcdef/", "abcdefgh/abcdefg", "abcdefgh/abcdefg/", "abcdefgh/abcdefgh", "abcdefgh/abcdefgh/", }; -#ifdef __FreeBSD__ dl_handle = dlopen(NULL, RTLD_LAZY); strchr_fn = dlsym(dl_handle, "test_strlen"); -#else - strchr_fn = dlsym(dlopen(0, RTLD_LAZY), "test_strchr"); -#endif if (!strchr_fn) strchr_fn = strchr; for (a = 3; a < 3 + sizeof(long); ++a) { /* Put char and a \0 before the buffer */ buf[a-1] = '/'; buf[a-2] = '0'; buf[a-3] = 0xff; for (t = 0; t < (sizeof(tab) / sizeof(tab[0])); ++t) { int len = strlen(tab[t]) + 1; memcpy(&buf[a], tab[t], len); /* Put the char we are looking for after the \0 */ buf[a + len] = '/'; /* Check search for NUL at end of string */ verify_strchr(buf + a, 0, t, a); /* Then for the '/' in the strings */ verify_strchr(buf + a, '/', t, a); /* check zero extension of char arg */ verify_strchr(buf + a, 0xffffff00 | '/', t, a); /* Replace all the '/' with 0xff */ while ((off = slow_strchr(buf + a, '/')) != NULL) *off = 0xff; buf[a + len] = 0xff; /* Check we can search for 0xff as well as '/' */ verify_strchr(buf + a, 0xff, t, a); } } -#ifdef __FreeBSD__ (void)dlclose(dl_handle); -#endif } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, strchr_basic); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/string/t_strerror.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/string/t_strerror.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/string/t_strerror.c (revision 311925) @@ -1,139 +1,136 @@ -/* $NetBSD: t_strerror.c,v 1.3 2011/05/10 06:55:27 jruoho Exp $ */ +/* $NetBSD: t_strerror.c,v 1.4 2017/01/10 20:35:49 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * 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 -__RCSID("$NetBSD: t_strerror.c,v 1.3 2011/05/10 06:55:27 jruoho Exp $"); +__RCSID("$NetBSD: t_strerror.c,v 1.4 2017/01/10 20:35:49 christos Exp $"); #include #include +#include /* Needed for sys_nerr on FreeBSD */ #include #include #include - -#ifdef __FreeBSD__ -#include -#endif ATF_TC(strerror_basic); ATF_TC_HEAD(strerror_basic, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of strerror(3)"); } ATF_TC_BODY(strerror_basic, tc) { int i; for (i = 1; i < sys_nerr; i++) ATF_REQUIRE(strstr(strerror(i), "Unknown error:") == NULL); for (; i < sys_nerr + 10; i++) ATF_REQUIRE(strstr(strerror(i), "Unknown error:") != NULL); } ATF_TC(strerror_err); ATF_TC_HEAD(strerror_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from strerror(3)"); } ATF_TC_BODY(strerror_err, tc) { errno = 0; ATF_REQUIRE(strstr(strerror(INT_MAX), "Unknown error:") != NULL); ATF_REQUIRE(errno == EINVAL); errno = 0; ATF_REQUIRE(strstr(strerror(INT_MIN), "Unknown error:") != NULL); ATF_REQUIRE(errno == EINVAL); } ATF_TC(strerror_r_basic); ATF_TC_HEAD(strerror_r_basic, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of strerror_r(3)"); } ATF_TC_BODY(strerror_r_basic, tc) { char buf[512]; int i; for (i = 1; i < sys_nerr; i++) { ATF_REQUIRE(strerror_r(i, buf, sizeof(buf)) == 0); ATF_REQUIRE(strstr(buf, "Unknown error:") == NULL); } for (; i < sys_nerr + 10; i++) { ATF_REQUIRE(strerror_r(i, buf, sizeof(buf)) == EINVAL); ATF_REQUIRE(strstr(buf, "Unknown error:") != NULL); } } ATF_TC(strerror_r_err); ATF_TC_HEAD(strerror_r_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from strerror_r(3)"); } ATF_TC_BODY(strerror_r_err, tc) { char buf[512]; int rv; rv = strerror_r(EPERM, buf, 1); ATF_REQUIRE(rv == ERANGE); rv = strerror_r(INT_MAX, buf, sizeof(buf)); ATF_REQUIRE(rv == EINVAL); ATF_REQUIRE(strstr(buf, "Unknown error:") != NULL); rv = strerror_r(INT_MIN, buf, sizeof(buf)); ATF_REQUIRE(rv == EINVAL); ATF_REQUIRE(strstr(buf, "Unknown error:") != NULL); } ATF_TP_ADD_TCS(tp) { (void)setlocale(LC_ALL, "C"); ATF_TP_ADD_TC(tp, strerror_basic); ATF_TP_ADD_TC(tp, strerror_err); ATF_TP_ADD_TC(tp, strerror_r_basic); ATF_TP_ADD_TC(tp, strerror_r_err); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_access.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_access.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/sys/t_access.c (revision 311925) @@ -1,219 +1,216 @@ -/* $NetBSD: t_access.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $ */ +/* $NetBSD: t_access.c,v 1.2 2017/01/10 22:36:29 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * 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 -__RCSID("$NetBSD: t_access.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $"); +__RCSID("$NetBSD: t_access.c,v 1.2 2017/01/10 22:36:29 christos Exp $"); +#include + +#include + #include #include #include #include #include #include - -#include - -#ifdef __FreeBSD__ -#include -#include -#endif static const char path[] = "access"; static const int mode[4] = { R_OK, W_OK, X_OK, F_OK }; ATF_TC_WITH_CLEANUP(access_access); ATF_TC_HEAD(access_access, tc) { atf_tc_set_md_var(tc, "descr", "Test access(2) for EACCES"); atf_tc_set_md_var(tc, "require.user", "unprivileged"); } ATF_TC_BODY(access_access, tc) { const int perm[3] = { 0200, 0400, 0000 }; size_t i; int fd; fd = open(path, O_RDONLY | O_CREAT); if (fd < 0) return; for (i = 0; i < __arraycount(mode) - 1; i++) { ATF_REQUIRE(fchmod(fd, perm[i]) == 0); errno = 0; ATF_REQUIRE(access(path, mode[i]) != 0); ATF_REQUIRE(errno == EACCES); } ATF_REQUIRE(close(fd) == 0); } ATF_TC_CLEANUP(access_access, tc) { (void)unlink(path); } ATF_TC(access_fault); ATF_TC_HEAD(access_fault, tc) { atf_tc_set_md_var(tc, "descr", "Test access(2) for EFAULT"); } ATF_TC_BODY(access_fault, tc) { size_t i; for (i = 0; i < __arraycount(mode); i++) { errno = 0; ATF_REQUIRE(access(NULL, mode[i]) != 0); ATF_REQUIRE(errno == EFAULT); errno = 0; ATF_REQUIRE(access((char *)-1, mode[i]) != 0); ATF_REQUIRE(errno == EFAULT); } } ATF_TC(access_inval); ATF_TC_HEAD(access_inval, tc) { atf_tc_set_md_var(tc, "descr", "Test access(2) for EINVAL"); } ATF_TC_BODY(access_inval, tc) { #if defined(__FreeBSD__) && __FreeBSD_version < 1100033 atf_tc_expect_fail("arguments to access aren't validated; see " "bug # 181155 for more details"); #endif errno = 0; ATF_REQUIRE(access("/usr", -1) != 0); ATF_REQUIRE(errno == EINVAL); } ATF_TC(access_notdir); ATF_TC_HEAD(access_notdir, tc) { atf_tc_set_md_var(tc, "descr", "Test access(2) for ENOTDIR"); } ATF_TC_BODY(access_notdir, tc) { size_t i; for (i = 0; i < __arraycount(mode); i++) { errno = 0; /* * IEEE Std 1003.1-2008 about ENOTDIR: * * "A component of the path prefix is not a directory, * or the path argument contains at least one non- * character and ends with one or more trailing * characters and the last pathname component names an * existing file that is neither a directory nor a symbolic * link to a directory." */ ATF_REQUIRE(access("/etc/passwd//", mode[i]) != 0); ATF_REQUIRE(errno == ENOTDIR); } } ATF_TC(access_notexist); ATF_TC_HEAD(access_notexist, tc) { atf_tc_set_md_var(tc, "descr", "Test access(2) for ENOENT"); } ATF_TC_BODY(access_notexist, tc) { size_t i; for (i = 0; i < __arraycount(mode); i++) { errno = 0; ATF_REQUIRE(access("", mode[i]) != 0); ATF_REQUIRE(errno == ENOENT); } } ATF_TC(access_toolong); ATF_TC_HEAD(access_toolong, tc) { atf_tc_set_md_var(tc, "descr", "Test access(2) for ENAMETOOLONG"); } ATF_TC_BODY(access_toolong, tc) { char *buf; size_t i; buf = malloc(PATH_MAX); if (buf == NULL) return; for (i = 0; i < PATH_MAX; i++) buf[i] = 'x'; for (i = 0; i < __arraycount(mode); i++) { errno = 0; ATF_REQUIRE(access(buf, mode[i]) != 0); ATF_REQUIRE(errno == ENAMETOOLONG); } free(buf); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, access_access); ATF_TP_ADD_TC(tp, access_fault); ATF_TP_ADD_TC(tp, access_inval); ATF_TP_ADD_TC(tp, access_notdir); ATF_TP_ADD_TC(tp, access_notexist); ATF_TP_ADD_TC(tp, access_toolong); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_chroot.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_chroot.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/sys/t_chroot.c (revision 311925) @@ -1,321 +1,318 @@ -/* $NetBSD: t_chroot.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $ */ +/* $NetBSD: t_chroot.c,v 1.2 2017/01/10 22:36:29 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * 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 -__RCSID("$NetBSD: t_chroot.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $"); +__RCSID("$NetBSD: t_chroot.c,v 1.2 2017/01/10 22:36:29 christos Exp $"); #include +#include #include #include #include #include #include #include #include #include - -#ifdef __FreeBSD__ -#include -#endif ATF_TC(chroot_basic); ATF_TC_HEAD(chroot_basic, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of chroot(2)"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(chroot_basic, tc) { char buf[PATH_MAX]; int fd, sta; pid_t pid; (void)memset(buf, '\0', sizeof(buf)); (void)getcwd(buf, sizeof(buf)); (void)strlcat(buf, "/dir", sizeof(buf)); ATF_REQUIRE(mkdir(buf, 0500) == 0); ATF_REQUIRE(chdir(buf) == 0); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { if (chroot(buf) != 0) _exit(EXIT_FAILURE); errno = 0; if (chroot("/root") != -1) _exit(EXIT_FAILURE); if (errno != ENOENT) _exit(EXIT_FAILURE); fd = open("file", O_RDONLY | O_CREAT, 0600); if (fd < 0) _exit(EXIT_FAILURE); if (close(fd) != 0) _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); } (void)wait(&sta); if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) atf_tc_fail("chroot(2) failed"); (void)chdir("/"); (void)strlcat(buf, "/file", sizeof(buf)); fd = open(buf, O_RDONLY); if (fd < 0) atf_tc_fail("chroot(2) did not change the root directory"); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlink(buf) == 0); } ATF_TC(chroot_err); ATF_TC_HEAD(chroot_err, tc) { atf_tc_set_md_var(tc, "descr", "Test error conditions of chroot(2)"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(chroot_err, tc) { char buf[PATH_MAX + 1]; (void)memset(buf, 'x', sizeof(buf)); errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, chroot(buf) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, chroot((void *)-1) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, chroot("/a/b/c/d/e/f/g/h/i/j") == -1); } ATF_TC(chroot_perm); ATF_TC_HEAD(chroot_perm, tc) { atf_tc_set_md_var(tc, "descr", "Test permissions with chroot(2)"); atf_tc_set_md_var(tc, "require.user", "unprivileged"); } ATF_TC_BODY(chroot_perm, tc) { static char buf[LINE_MAX]; pid_t pid; int sta; (void)memset(buf, '\0', sizeof(buf)); ATF_REQUIRE(getcwd(buf, sizeof(buf)) != NULL); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { errno = 0; if (chroot(buf) != -1) _exit(EXIT_FAILURE); if (errno != EPERM) _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); } (void)wait(&sta); if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) atf_tc_fail("chroot(2) succeeded as unprivileged user"); } #ifdef __NetBSD__ ATF_TC(fchroot_basic); ATF_TC_HEAD(fchroot_basic, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of fchroot(2)"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(fchroot_basic, tc) { char buf[PATH_MAX]; int fd, sta; pid_t pid; (void)memset(buf, '\0', sizeof(buf)); (void)getcwd(buf, sizeof(buf)); (void)strlcat(buf, "/dir", sizeof(buf)); ATF_REQUIRE(mkdir(buf, 0500) == 0); ATF_REQUIRE(chdir(buf) == 0); fd = open(buf, O_RDONLY); ATF_REQUIRE(fd >= 0); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { if (fchroot(fd) != 0) _exit(EXIT_FAILURE); if (close(fd) != 0) _exit(EXIT_FAILURE); fd = open("file", O_RDONLY | O_CREAT, 0600); if (fd < 0) _exit(EXIT_FAILURE); if (close(fd) != 0) _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); } (void)wait(&sta); if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) atf_tc_fail("fchroot(2) failed"); (void)chdir("/"); (void)strlcat(buf, "/file", sizeof(buf)); fd = open(buf, O_RDONLY); if (fd < 0) atf_tc_fail("fchroot(2) did not change the root directory"); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlink(buf) == 0); } ATF_TC(fchroot_err); ATF_TC_HEAD(fchroot_err, tc) { atf_tc_set_md_var(tc, "descr", "Test error conditions of fchroot(2)"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(fchroot_err, tc) { int fd; fd = open("/etc/passwd", O_RDONLY); ATF_REQUIRE(fd >= 0); errno = 0; ATF_REQUIRE_ERRNO(EBADF, fchroot(-1) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOTDIR, fchroot(fd) == -1); ATF_REQUIRE(close(fd) == 0); } ATF_TC(fchroot_perm); ATF_TC_HEAD(fchroot_perm, tc) { atf_tc_set_md_var(tc, "descr", "Test permissions with fchroot(2)"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(fchroot_perm, tc) { static char buf[LINE_MAX]; struct passwd *pw; int fd, sta; pid_t pid; (void)memset(buf, '\0', sizeof(buf)); ATF_REQUIRE(getcwd(buf, sizeof(buf)) != NULL); pw = getpwnam("nobody"); fd = open(buf, O_RDONLY); ATF_REQUIRE(fd >= 0); ATF_REQUIRE(pw != NULL); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { (void)setuid(pw->pw_uid); errno = 0; if (fchroot(fd) != -1) _exit(EXIT_FAILURE); if (errno != EPERM) _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); } (void)wait(&sta); if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) atf_tc_fail("fchroot(2) succeeded as unprivileged user"); } #endif ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, chroot_basic); ATF_TP_ADD_TC(tp, chroot_err); ATF_TP_ADD_TC(tp, chroot_perm); #ifdef __NetBSD__ ATF_TP_ADD_TC(tp, fchroot_basic); ATF_TP_ADD_TC(tp, fchroot_err); ATF_TP_ADD_TC(tp, fchroot_perm); #endif return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_mincore.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_mincore.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/sys/t_mincore.c (revision 311925) @@ -1,351 +1,348 @@ -/* $NetBSD: t_mincore.c,v 1.8 2012/06/08 07:18:58 martin Exp $ */ +/* $NetBSD: t_mincore.c,v 1.9 2017/01/10 22:36:29 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * 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. */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, * NASA Ames Research Center. * * 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 -__RCSID("$NetBSD: t_mincore.c,v 1.8 2012/06/08 07:18:58 martin Exp $"); +__RCSID("$NetBSD: t_mincore.c,v 1.9 2017/01/10 22:36:29 christos Exp $"); #include +#include #include #include #include #include #include #include #include #include #include #include - -#ifdef __FreeBSD__ -#include -#endif static long page = 0; static const char path[] = "mincore"; static size_t check_residency(void *, size_t); static size_t check_residency(void *addr, size_t npgs) { size_t i, resident; char *vec; vec = malloc(npgs); ATF_REQUIRE(vec != NULL); ATF_REQUIRE(mincore(addr, npgs * page, vec) == 0); for (i = resident = 0; i < npgs; i++) { if (vec[i] != 0) resident++; #if 0 (void)fprintf(stderr, "page 0x%p is %sresident\n", (char *)addr + (i * page), vec[i] ? "" : "not "); #endif } free(vec); return resident; } ATF_TC(mincore_err); ATF_TC_HEAD(mincore_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from mincore(2)"); } ATF_TC_BODY(mincore_err, tc) { char *map, *vec; map = mmap(NULL, page, PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); vec = malloc(page); ATF_REQUIRE(vec != NULL); ATF_REQUIRE(map != MAP_FAILED); #ifdef __NetBSD__ errno = 0; ATF_REQUIRE_ERRNO(EINVAL, mincore(map, 0, vec) == -1); #endif errno = 0; ATF_REQUIRE_ERRNO(ENOMEM, mincore(0, page, vec) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, mincore(map, page, (void *)-1) == -1); free(vec); ATF_REQUIRE(munmap(map, page) == 0); } ATF_TC_WITH_CLEANUP(mincore_resid); ATF_TC_HEAD(mincore_resid, tc) { atf_tc_set_md_var(tc, "descr", "Test page residency with mincore(2)"); #ifdef __FreeBSD__ atf_tc_set_md_var(tc, "require.user", "root"); #endif } ATF_TC_BODY(mincore_resid, tc) { void *addr, *addr2, *addr3, *buf; size_t npgs = 0, resident; struct stat st; int fd, rv; struct rlimit rlim; ATF_REQUIRE(getrlimit(RLIMIT_MEMLOCK, &rlim) == 0); #ifdef __FreeBSD__ /* * Bump the mlock limit to unlimited so the rest of the testcase * passes instead of failing on the mlock call. */ rlim.rlim_max = RLIM_INFINITY; #endif rlim.rlim_cur = rlim.rlim_max; ATF_REQUIRE(setrlimit(RLIMIT_MEMLOCK, &rlim) == 0); (void)memset(&st, 0, sizeof(struct stat)); fd = open(path, O_RDWR | O_CREAT, 0700); buf = malloc(page * 5); ATF_REQUIRE(fd >= 0); ATF_REQUIRE(buf != NULL); rv = write(fd, buf, page * 5); ATF_REQUIRE(rv >= 0); ATF_REQUIRE(fd >= 0); ATF_REQUIRE(fstat(fd, &st) == 0); addr = mmap(NULL, (size_t)st.st_size, PROT_READ, MAP_FILE | MAP_SHARED, fd, (off_t) 0); ATF_REQUIRE(addr != MAP_FAILED); (void)close(fd); npgs = st.st_size / page; if (st.st_size % page != 0) npgs++; (void)check_residency(addr, npgs); rv = mlock(addr, npgs * page); if (rv == -1 && errno == EAGAIN) atf_tc_skip("hit process resource limits"); ATF_REQUIRE(munmap(addr, st.st_size) == 0); npgs = 128; #ifdef __FreeBSD__ addr = mmap(NULL, npgs * page, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, (off_t)0); #else addr = mmap(NULL, npgs * page, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_WIRED, -1, (off_t)0); #endif if (addr == MAP_FAILED) atf_tc_skip("could not mmap wired anonymous test area, system " "might be low on memory"); #ifdef __FreeBSD__ if (mlock(addr, npgs * page) == -1 && errno != ENOMEM) atf_tc_skip("could not wire anonymous test area, system might " "be low on memory"); #endif ATF_REQUIRE(check_residency(addr, npgs) == npgs); ATF_REQUIRE(munmap(addr, npgs * page) == 0); npgs = 128; addr = mmap(NULL, npgs * page, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, (off_t)0); ATF_REQUIRE(addr != MAP_FAILED); /* * Check that the in-core pages match the locked pages. */ ATF_REQUIRE(check_residency(addr, npgs) == 0); errno = 0; if (mlockall(MCL_CURRENT|MCL_FUTURE) != 0 && errno != ENOMEM) atf_tc_fail("mlockall(2) failed"); if (errno == ENOMEM) atf_tc_skip("mlockall() exceeded process resource limits"); resident = check_residency(addr, npgs); if (resident < npgs) atf_tc_fail("mlockall(MCL_FUTURE) succeeded, still only " "%zu pages of the newly mapped %zu pages are resident", resident, npgs); addr2 = mmap(NULL, npgs * page, PROT_READ, MAP_ANON, -1, (off_t)0); addr3 = mmap(NULL, npgs * page, PROT_NONE, MAP_ANON, -1, (off_t)0); if (addr2 == MAP_FAILED || addr3 == MAP_FAILED) atf_tc_skip("could not mmap more anonymous test pages with " "mlockall(MCL_FUTURE) in effect, system " "might be low on memory"); ATF_REQUIRE(check_residency(addr2, npgs) == npgs); ATF_REQUIRE(check_residency(addr3, npgs) == 0); ATF_REQUIRE(mprotect(addr3, npgs * page, PROT_READ) == 0); ATF_REQUIRE(check_residency(addr, npgs) == npgs); ATF_REQUIRE(check_residency(addr2, npgs) == npgs); (void)munlockall(); ATF_REQUIRE(madvise(addr2, npgs * page, MADV_FREE) == 0); #ifdef __NetBSD__ ATF_REQUIRE(check_residency(addr2, npgs) == 0); #endif (void)memset(addr, 0, npgs * page); ATF_REQUIRE(madvise(addr, npgs * page, MADV_FREE) == 0); #ifdef __NetBSD__ ATF_REQUIRE(check_residency(addr, npgs) == 0); #endif (void)munmap(addr, npgs * page); (void)munmap(addr2, npgs * page); (void)munmap(addr3, npgs * page); (void)unlink(path); #ifdef __FreeBSD__ free(buf); #endif } ATF_TC_CLEANUP(mincore_resid, tc) { (void)unlink(path); } ATF_TC(mincore_shmseg); ATF_TC_HEAD(mincore_shmseg, tc) { atf_tc_set_md_var(tc, "descr", "residency of shared memory"); } ATF_TC_BODY(mincore_shmseg, tc) { size_t npgs = 128; void *addr = NULL; int shmid; shmid = shmget(IPC_PRIVATE, npgs * page, IPC_CREAT | S_IRUSR | S_IWUSR); ATF_REQUIRE(shmid != -1); addr = shmat(shmid, NULL, 0); ATF_REQUIRE(addr != NULL); ATF_REQUIRE(check_residency(addr, npgs) == 0); (void)memset(addr, 0xff, npgs * page); ATF_REQUIRE(check_residency(addr, npgs) == npgs); ATF_REQUIRE(madvise(addr, npgs * page, MADV_FREE) == 0); /* * NOTE! Even though we have MADV_FREE'd the range, * there is another reference (the kernel's) to the * object which owns the pages. In this case, the * kernel does not simply free the pages, as haphazardly * freeing pages when there are still references to * an object can cause data corruption (say, the other * referencer doesn't expect the pages to be freed, * and is surprised by the subsequent ZFOD). * * Because of this, we simply report the number of * pages still resident, for information only. */ npgs = check_residency(addr, npgs); (void)fprintf(stderr, "%zu pages still resident\n", npgs); ATF_REQUIRE(shmdt(addr) == 0); ATF_REQUIRE(shmctl(shmid, IPC_RMID, NULL) == 0); } ATF_TP_ADD_TCS(tp) { page = sysconf(_SC_PAGESIZE); ATF_REQUIRE(page >= 0); ATF_TP_ADD_TC(tp, mincore_err); ATF_TP_ADD_TC(tp, mincore_resid); ATF_TP_ADD_TC(tp, mincore_shmseg); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_mmap.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_mmap.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/sys/t_mmap.c (revision 311925) @@ -1,605 +1,605 @@ -/* $NetBSD: t_mmap.c,v 1.9 2015/02/28 13:57:08 martin Exp $ */ +/* $NetBSD: t_mmap.c,v 1.10 2017/01/10 22:36:29 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * 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. */ /*- * Copyright (c)2004 YAMAMOTO Takashi, * 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 -__RCSID("$NetBSD: t_mmap.c,v 1.9 2015/02/28 13:57:08 martin Exp $"); +__RCSID("$NetBSD: t_mmap.c,v 1.10 2017/01/10 22:36:29 christos Exp $"); #include #include +#include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef __NetBSD__ #include #endif #ifdef __FreeBSD__ #include -#include #include #endif static long page = 0; static char path[] = "mmap"; static void map_check(void *, int); static void map_sighandler(int); static void testloan(void *, void *, char, int); #define BUFSIZE (32 * 1024) /* enough size to trigger sosend_loan */ static void map_check(void *map, int flag) { if (flag != 0) { ATF_REQUIRE(map == MAP_FAILED); return; } ATF_REQUIRE(map != MAP_FAILED); ATF_REQUIRE(munmap(map, page) == 0); } void testloan(void *vp, void *vp2, char pat, int docheck) { char buf[BUFSIZE]; char backup[BUFSIZE]; ssize_t nwritten; ssize_t nread; int fds[2]; int val; val = BUFSIZE; if (docheck != 0) (void)memcpy(backup, vp, BUFSIZE); if (socketpair(AF_LOCAL, SOCK_STREAM, PF_UNSPEC, fds) != 0) atf_tc_fail("socketpair() failed"); val = BUFSIZE; if (setsockopt(fds[1], SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)) != 0) atf_tc_fail("setsockopt() failed, SO_RCVBUF"); val = BUFSIZE; if (setsockopt(fds[0], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)) != 0) atf_tc_fail("setsockopt() failed, SO_SNDBUF"); if (fcntl(fds[0], F_SETFL, O_NONBLOCK) != 0) atf_tc_fail("fcntl() failed"); nwritten = write(fds[0], (char *)vp + page, BUFSIZE - page); if (nwritten == -1) atf_tc_fail("write() failed"); /* Break loan. */ (void)memset(vp2, pat, BUFSIZE); nread = read(fds[1], buf + page, BUFSIZE - page); if (nread == -1) atf_tc_fail("read() failed"); if (nread != nwritten) atf_tc_fail("too short read"); if (docheck != 0 && memcmp(backup, buf + page, nread) != 0) atf_tc_fail("data mismatch"); ATF_REQUIRE(close(fds[0]) == 0); ATF_REQUIRE(close(fds[1]) == 0); } static void map_sighandler(int signo) { _exit(signo); } #ifdef __NetBSD__ ATF_TC(mmap_block); ATF_TC_HEAD(mmap_block, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) with a block device"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(mmap_block, tc) { static const int mib[] = { CTL_HW, HW_DISKNAMES }; static const unsigned int miblen = __arraycount(mib); char *map, *dk, *drives, dev[PATH_MAX]; size_t len; int fd = -1; atf_tc_skip("The test case causes a panic (PR kern/38889, kern/46592)"); ATF_REQUIRE(sysctl(mib, miblen, NULL, &len, NULL, 0) == 0); drives = malloc(len); ATF_REQUIRE(drives != NULL); ATF_REQUIRE(sysctl(mib, miblen, drives, &len, NULL, 0) == 0); for (dk = strtok(drives, " "); dk != NULL; dk = strtok(NULL, " ")) { sprintf(dev, _PATH_DEV "%s%c", dk, 'a'+RAW_PART); fprintf(stderr, "trying: %s\n", dev); if ((fd = open(dev, O_RDONLY)) >= 0) { (void)fprintf(stderr, "using %s\n", dev); break; } } free(drives); if (fd < 0) atf_tc_skip("failed to find suitable block device"); map = mmap(NULL, 4096, PROT_READ, MAP_FILE, fd, 0); ATF_REQUIRE(map != MAP_FAILED); (void)fprintf(stderr, "first byte %x\n", *map); ATF_REQUIRE(close(fd) == 0); (void)fprintf(stderr, "first byte %x\n", *map); ATF_REQUIRE(munmap(map, 4096) == 0); } #endif ATF_TC(mmap_err); ATF_TC_HEAD(mmap_err, tc) { atf_tc_set_md_var(tc, "descr", "Test error conditions of mmap(2)"); } ATF_TC_BODY(mmap_err, tc) { size_t addr = SIZE_MAX; void *map; errno = 0; map = mmap(NULL, 3, PROT_READ, MAP_FILE|MAP_PRIVATE, -1, 0); ATF_REQUIRE(map == MAP_FAILED); ATF_REQUIRE(errno == EBADF); errno = 0; map = mmap(&addr, page, PROT_READ, MAP_FIXED|MAP_PRIVATE, -1, 0); ATF_REQUIRE(map == MAP_FAILED); ATF_REQUIRE(errno == EINVAL); errno = 0; map = mmap(NULL, page, PROT_READ, MAP_ANON|MAP_PRIVATE, INT_MAX, 0); ATF_REQUIRE(map == MAP_FAILED); ATF_REQUIRE(errno == EINVAL); } ATF_TC_WITH_CLEANUP(mmap_loan); ATF_TC_HEAD(mmap_loan, tc) { atf_tc_set_md_var(tc, "descr", "Test uvm page loanout with mmap(2)"); } ATF_TC_BODY(mmap_loan, tc) { char buf[BUFSIZE]; char *vp, *vp2; int fd; fd = open(path, O_RDWR | O_CREAT, 0600); ATF_REQUIRE(fd >= 0); (void)memset(buf, 'x', sizeof(buf)); (void)write(fd, buf, sizeof(buf)); vp = mmap(NULL, BUFSIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, fd, 0); ATF_REQUIRE(vp != MAP_FAILED); vp2 = vp; testloan(vp, vp2, 'A', 0); testloan(vp, vp2, 'B', 1); ATF_REQUIRE(munmap(vp, BUFSIZE) == 0); vp = mmap(NULL, BUFSIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0); vp2 = mmap(NULL, BUFSIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0); ATF_REQUIRE(vp != MAP_FAILED); ATF_REQUIRE(vp2 != MAP_FAILED); testloan(vp, vp2, 'E', 1); ATF_REQUIRE(munmap(vp, BUFSIZE) == 0); ATF_REQUIRE(munmap(vp2, BUFSIZE) == 0); } ATF_TC_CLEANUP(mmap_loan, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(mmap_prot_1); ATF_TC_HEAD(mmap_prot_1, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) protections, #1"); } ATF_TC_BODY(mmap_prot_1, tc) { void *map; int fd; /* * Open a file write-only and try to * map it read-only. This should fail. */ fd = open(path, O_WRONLY | O_CREAT, 0700); if (fd < 0) return; ATF_REQUIRE(write(fd, "XXX", 3) == 3); map = mmap(NULL, 3, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); map_check(map, 1); map = mmap(NULL, 3, PROT_WRITE, MAP_FILE|MAP_PRIVATE, fd, 0); map_check(map, 0); ATF_REQUIRE(close(fd) == 0); } ATF_TC_CLEANUP(mmap_prot_1, tc) { (void)unlink(path); } ATF_TC(mmap_prot_2); ATF_TC_HEAD(mmap_prot_2, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) protections, #2"); } ATF_TC_BODY(mmap_prot_2, tc) { char buf[2]; void *map; pid_t pid; int sta; /* * Make a PROT_NONE mapping and try to access it. * If we catch a SIGSEGV, all works as expected. */ map = mmap(NULL, page, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0); ATF_REQUIRE(map != MAP_FAILED); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR); ATF_REQUIRE(strlcpy(buf, map, sizeof(buf)) != 0); } (void)wait(&sta); ATF_REQUIRE(WIFEXITED(sta) != 0); ATF_REQUIRE(WEXITSTATUS(sta) == SIGSEGV); ATF_REQUIRE(munmap(map, page) == 0); } ATF_TC_WITH_CLEANUP(mmap_prot_3); ATF_TC_HEAD(mmap_prot_3, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) protections, #3"); } ATF_TC_BODY(mmap_prot_3, tc) { char buf[2]; int fd, sta; void *map; pid_t pid; /* * Open a file, change the permissions * to read-only, and try to map it as * PROT_NONE. This should succeed, but * the access should generate SIGSEGV. */ fd = open(path, O_RDWR | O_CREAT, 0700); if (fd < 0) #ifdef __FreeBSD__ atf_tc_skip("opening %s failed; skipping testcase: %s", path, strerror(errno)); #else return; #endif ATF_REQUIRE(write(fd, "XXX", 3) == 3); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(chmod(path, 0444) == 0); fd = open(path, O_RDONLY); ATF_REQUIRE(fd != -1); map = mmap(NULL, 3, PROT_NONE, MAP_FILE | MAP_SHARED, fd, 0); ATF_REQUIRE(map != MAP_FAILED); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR); ATF_REQUIRE(strlcpy(buf, map, sizeof(buf)) != 0); } (void)wait(&sta); ATF_REQUIRE(WIFEXITED(sta) != 0); ATF_REQUIRE(WEXITSTATUS(sta) == SIGSEGV); ATF_REQUIRE(munmap(map, 3) == 0); #ifdef __FreeBSD__ (void)close(fd); #endif } ATF_TC_CLEANUP(mmap_prot_3, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(mmap_truncate); ATF_TC_HEAD(mmap_truncate, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) and ftruncate(2)"); } ATF_TC_BODY(mmap_truncate, tc) { char *map; long i; int fd; fd = open(path, O_RDWR | O_CREAT, 0700); if (fd < 0) return; /* * See that ftruncate(2) works * while the file is mapped. */ ATF_REQUIRE(ftruncate(fd, page) == 0); map = mmap(NULL, page, PROT_READ | PROT_WRITE, MAP_FILE|MAP_PRIVATE, fd, 0); ATF_REQUIRE(map != MAP_FAILED); for (i = 0; i < page; i++) map[i] = 'x'; ATF_REQUIRE(ftruncate(fd, 0) == 0); ATF_REQUIRE(ftruncate(fd, page / 8) == 0); ATF_REQUIRE(ftruncate(fd, page / 4) == 0); ATF_REQUIRE(ftruncate(fd, page / 2) == 0); ATF_REQUIRE(ftruncate(fd, page / 12) == 0); ATF_REQUIRE(ftruncate(fd, page / 64) == 0); #ifdef __FreeBSD__ (void)munmap(map, page); #endif ATF_REQUIRE(close(fd) == 0); } ATF_TC_CLEANUP(mmap_truncate, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(mmap_truncate_signal); ATF_TC_HEAD(mmap_truncate_signal, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) ftruncate(2) causing signal"); } ATF_TC_BODY(mmap_truncate_signal, tc) { char *map; long i; int fd, sta; pid_t pid; #ifdef __FreeBSD__ atf_tc_expect_fail("testcase fails with SIGSEGV on FreeBSD; bug # 211924"); #endif fd = open(path, O_RDWR | O_CREAT, 0700); if (fd < 0) return; ATF_REQUIRE(write(fd, "foo\n", 5) == 5); map = mmap(NULL, page, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); ATF_REQUIRE(map != MAP_FAILED); sta = 0; for (i = 0; i < 5; i++) sta += map[i]; ATF_REQUIRE(sta == 334); ATF_REQUIRE(ftruncate(fd, 0) == 0); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { ATF_REQUIRE(signal(SIGBUS, map_sighandler) != SIG_ERR); ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR); sta = 0; for (i = 0; i < page; i++) sta += map[i]; /* child never will get this far, but the compiler will not know, so better use the values calculated to prevent the access to be optimized out */ ATF_REQUIRE(i == 0); ATF_REQUIRE(sta == 0); #ifdef __FreeBSD__ (void)munmap(map, page); (void)close(fd); #endif return; } (void)wait(&sta); ATF_REQUIRE(WIFEXITED(sta) != 0); if (WEXITSTATUS(sta) == SIGSEGV) atf_tc_fail("child process got SIGSEGV instead of SIGBUS"); ATF_REQUIRE(WEXITSTATUS(sta) == SIGBUS); ATF_REQUIRE(munmap(map, page) == 0); ATF_REQUIRE(close(fd) == 0); } ATF_TC_CLEANUP(mmap_truncate_signal, tc) { (void)unlink(path); } ATF_TC(mmap_va0); ATF_TC_HEAD(mmap_va0, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) and vm.user_va0_disable"); } ATF_TC_BODY(mmap_va0, tc) { int flags = MAP_ANON | MAP_FIXED | MAP_PRIVATE; size_t len = sizeof(int); void *map; int val; /* * Make an anonymous fixed mapping at zero address. If the address * is restricted as noted in security(7), the syscall should fail. */ #ifdef __FreeBSD__ if (sysctlbyname("security.bsd.map_at_zero", &val, &len, NULL, 0) != 0) atf_tc_fail("failed to read security.bsd.map_at_zero"); val = !val; /* 1 == enable map at zero */ #endif #ifdef __NetBSD__ if (sysctlbyname("vm.user_va0_disable", &val, &len, NULL, 0) != 0) atf_tc_fail("failed to read vm.user_va0_disable"); #endif map = mmap(NULL, page, PROT_EXEC, flags, -1, 0); map_check(map, val); map = mmap(NULL, page, PROT_READ, flags, -1, 0); map_check(map, val); map = mmap(NULL, page, PROT_WRITE, flags, -1, 0); map_check(map, val); map = mmap(NULL, page, PROT_READ|PROT_WRITE, flags, -1, 0); map_check(map, val); map = mmap(NULL, page, PROT_EXEC|PROT_READ|PROT_WRITE, flags, -1, 0); map_check(map, val); } ATF_TP_ADD_TCS(tp) { page = sysconf(_SC_PAGESIZE); ATF_REQUIRE(page >= 0); #ifdef __NetBSD__ ATF_TP_ADD_TC(tp, mmap_block); #endif ATF_TP_ADD_TC(tp, mmap_err); ATF_TP_ADD_TC(tp, mmap_loan); ATF_TP_ADD_TC(tp, mmap_prot_1); ATF_TP_ADD_TC(tp, mmap_prot_2); ATF_TP_ADD_TC(tp, mmap_prot_3); ATF_TP_ADD_TC(tp, mmap_truncate); ATF_TP_ADD_TC(tp, mmap_truncate_signal); ATF_TP_ADD_TC(tp, mmap_va0); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_wait.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_wait.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/sys/t_wait.c (revision 311925) @@ -1,265 +1,323 @@ -/* $NetBSD: t_wait.c,v 1.4 2016/04/27 21:14:24 christos Exp $ */ +/* $NetBSD: t_wait.c,v 1.7 2016/11/06 15:04:14 kamil Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software 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 -__RCSID("$NetBSD: t_wait.c,v 1.4 2016/04/27 21:14:24 christos Exp $"); +__RCSID("$NetBSD: t_wait.c,v 1.7 2016/11/06 15:04:14 kamil Exp $"); #include #include #include #include #include #include #include #include #include #include #ifdef __FreeBSD__ #define wrusage __wrusage #endif ATF_TC(wait6_invalid); ATF_TC_HEAD(wait6_invalid, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait6(2) returns EINVAL with 0 options"); } ATF_TC_BODY(wait6_invalid, tc) { siginfo_t si; struct wrusage wru; int st; ATF_REQUIRE(wait6(P_ALL, 0, &st, 0, &wru, &si) == -1 && errno == EINVAL); } -ATF_TC(wait6_noproc); -ATF_TC_HEAD(wait6_noproc, tc) -{ - atf_tc_set_md_var(tc, "descr", - "Test that wait6(2) returns ECHILD with for no processes"); -} - -ATF_TC_BODY(wait6_noproc, tc) -{ - siginfo_t si; - struct wrusage wru; - int st; - ATF_REQUIRE(wait6(P_ALL, 0, &st, WEXITED, &wru, &si) == -1 - && errno == ECHILD); -} - ATF_TC(wait6_exited); ATF_TC_HEAD(wait6_exited, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait6(2) handled exiting process and code"); } ATF_TC_BODY(wait6_exited, tc) { siginfo_t si; struct wrusage wru; int st; pid_t pid; switch (pid = fork()) { case -1: - ATF_REQUIRE(pid > 0); + ATF_REQUIRE(pid > 0); case 0: exit(0x5a5a5a5a); /*NOTREACHED*/ default: - ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); + ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); ATF_REQUIRE(WIFEXITED(st) && WEXITSTATUS(st) == 0x5a); ATF_REQUIRE(si.si_status = 0x5a5a5a5a); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_EXITED); #ifdef __NetBSD__ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, (uintmax_t)si.si_utime); #endif break; } } ATF_TC(wait6_terminated); ATF_TC_HEAD(wait6_terminated, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait6(2) handled terminated process and code"); } ATF_TC_BODY(wait6_terminated, tc) { siginfo_t si; struct wrusage wru; int st; pid_t pid; switch (pid = fork()) { case 0: sleep(100); /*FALLTHROUGH*/ case -1: - ATF_REQUIRE(pid > 0); + ATF_REQUIRE(pid > 0); default: ATF_REQUIRE(kill(pid, SIGTERM) == 0); - ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); + ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGTERM); ATF_REQUIRE(si.si_status == SIGTERM); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_KILLED); #ifdef __NetBSD__ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, (uintmax_t)si.si_utime); #endif break; } } ATF_TC(wait6_coredumped); ATF_TC_HEAD(wait6_coredumped, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait6(2) handled coredumped process and code"); } ATF_TC_BODY(wait6_coredumped, tc) { siginfo_t si; struct wrusage wru; int st; pid_t pid; static const struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY }; switch (pid = fork()) { case 0: ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0); *(char *)8 = 0; /*FALLTHROUGH*/ case -1: - ATF_REQUIRE(pid > 0); + ATF_REQUIRE(pid > 0); default: - ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); + ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGSEGV && WCOREDUMP(st)); ATF_REQUIRE(si.si_status == SIGSEGV); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_DUMPED); #ifdef __NetBSD__ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, (uintmax_t)si.si_utime); #endif break; } } ATF_TC(wait6_stop_and_go); ATF_TC_HEAD(wait6_stop_and_go, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait6(2) handled stopped/continued process and code"); } ATF_TC_BODY(wait6_stop_and_go, tc) { siginfo_t si; struct wrusage wru; int st; pid_t pid; static const struct rlimit rl = { 0, 0 }; ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0); switch (pid = fork()) { case 0: sleep(100); /*FALLTHROUGH*/ case -1: - ATF_REQUIRE(pid > 0); + ATF_REQUIRE(pid > 0); default: ATF_REQUIRE(kill(pid, SIGSTOP) == 0); - ATF_REQUIRE(wait6(P_PID, pid, &st, WSTOPPED, &wru, &si) == pid); + ATF_REQUIRE(wait6(P_PID, pid, &st, WSTOPPED, &wru, &si) == pid); + ATF_REQUIRE(!WIFEXITED(st)); + ATF_REQUIRE(!WIFSIGNALED(st)); ATF_REQUIRE(WIFSTOPPED(st) && WSTOPSIG(st) == SIGSTOP); + ATF_REQUIRE(!WIFCONTINUED(st)); ATF_REQUIRE(si.si_status == SIGSTOP); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_STOPPED); #ifdef __NetBSD__ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, (uintmax_t)si.si_utime); #endif ATF_REQUIRE(kill(pid, SIGCONT) == 0); - ATF_REQUIRE(wait6(P_PID, pid, &st, WCONTINUED, &wru, &si) == pid); + ATF_REQUIRE(wait6(P_PID, pid, &st, WCONTINUED, &wru, &si) == pid); + ATF_REQUIRE(!WIFEXITED(st)); + ATF_REQUIRE(!WIFSIGNALED(st)); ATF_REQUIRE(WIFCONTINUED(st)); + ATF_REQUIRE(!WIFSTOPPED(st)); ATF_REQUIRE(si.si_status == SIGCONT); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_CONTINUED); #ifdef __NetBSD__ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, (uintmax_t)si.si_utime); #endif ATF_REQUIRE(kill(pid, SIGQUIT) == 0); - ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); + ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); + ATF_REQUIRE(!WIFEXITED(st)); ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGQUIT); + ATF_REQUIRE(!WIFSTOPPED(st)); + ATF_REQUIRE(!WIFCONTINUED(st)); ATF_REQUIRE(si.si_status == SIGQUIT); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_KILLED); #ifdef __NetBSD__ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, (uintmax_t)si.si_utime); #endif break; } } +ATF_TC(wait6_stopgo_loop); +ATF_TC_HEAD(wait6_stopgo_loop, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test that wait6(2) handled stopped/continued process loop"); +} + +ATF_TC_BODY(wait6_stopgo_loop, tc) +{ + siginfo_t si; + struct wrusage wru; + int st; + pid_t pid; + static const struct rlimit rl = { 0, 0 }; + size_t N = 100; + + ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0); + switch (pid = fork()) { + case 0: + sleep(100); + /*FALLTHROUGH*/ + case -1: + ATF_REQUIRE(pid > 0); + } + + printf("Before loop of SIGSTOP/SIGCONT sequence %zu times\n", N); + while (N --> 0) { + ATF_REQUIRE(kill(pid, SIGSTOP) == 0); + ATF_REQUIRE(wait6(P_PID, pid, &st, WSTOPPED, &wru, &si) == pid); + ATF_REQUIRE(!WIFEXITED(st)); + ATF_REQUIRE(!WIFSIGNALED(st)); + ATF_REQUIRE(WIFSTOPPED(st) && WSTOPSIG(st) == SIGSTOP); + ATF_REQUIRE(!WIFCONTINUED(st)); + ATF_REQUIRE(si.si_status == SIGSTOP); + ATF_REQUIRE(si.si_pid == pid); + ATF_REQUIRE(si.si_uid == getuid()); + ATF_REQUIRE(si.si_code == CLD_STOPPED); + + ATF_REQUIRE(kill(pid, SIGCONT) == 0); + ATF_REQUIRE(wait6(P_PID, pid, &st, WCONTINUED, &wru, &si) == pid); + ATF_REQUIRE(!WIFEXITED(st)); + ATF_REQUIRE(!WIFSIGNALED(st)); + ATF_REQUIRE(WIFCONTINUED(st)); + ATF_REQUIRE(!WIFSTOPPED(st)); + ATF_REQUIRE(si.si_status == SIGCONT); + ATF_REQUIRE(si.si_pid == pid); + ATF_REQUIRE(si.si_uid == getuid()); + ATF_REQUIRE(si.si_code == CLD_CONTINUED); + } + ATF_REQUIRE(kill(pid, SIGQUIT) == 0); + ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); + ATF_REQUIRE(!WIFEXITED(st)); + ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGQUIT); + ATF_REQUIRE(!WIFSTOPPED(st)); + ATF_REQUIRE(!WIFCONTINUED(st)); + ATF_REQUIRE(si.si_status == SIGQUIT); + ATF_REQUIRE(si.si_pid == pid); + ATF_REQUIRE(si.si_uid == getuid()); + ATF_REQUIRE(si.si_code == CLD_KILLED); +#ifdef __NetBSD__ + printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, + (uintmax_t)si.si_utime); +#endif +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, wait6_invalid); - ATF_TP_ADD_TC(tp, wait6_noproc); ATF_TP_ADD_TC(tp, wait6_exited); ATF_TP_ADD_TC(tp, wait6_terminated); ATF_TP_ADD_TC(tp, wait6_coredumped); ATF_TP_ADD_TC(tp, wait6_stop_and_go); + ATF_TP_ADD_TC(tp, wait6_stopgo_loop); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/t_cdb.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/t_cdb.c (revision 311924) +++ head/contrib/netbsd-tests/lib/libc/t_cdb.c (revision 311925) @@ -1,158 +1,161 @@ -/* $NetBSD: t_cdb.c,v 1.1 2012/09/27 00:38:57 joerg Exp $ */ +/* $NetBSD: t_cdb.c,v 1.2 2017/01/10 22:24:29 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Joerg Sonnenberger. * * 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 COPYRIGHT HOLDERS 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 * COPYRIGHT HOLDERS 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 -__RCSID("$NetBSD: t_cdb.c,v 1.1 2012/09/27 00:38:57 joerg Exp $"); +__RCSID("$NetBSD: t_cdb.c,v 1.2 2017/01/10 22:24:29 christos Exp $"); #include + +#include + #include #include #include #include #include #include #include #define MAXKEYS 16384 static const char database_name[] = "test.cdb"; uint32_t keys[MAXKEYS]; static int cmp_keys(const void *a_, const void *b_) { uint32_t a = *(const uint32_t *)a_; uint32_t b = *(const uint32_t *)b_; return a > b ? 1 : (a < b ? 1 : 0); } static void init_keys(size_t len) { uint32_t sorted_keys[MAXKEYS]; size_t i; assert(len <= MAXKEYS); if (len == 0) return; do { for (i = 0; i < len; ++i) sorted_keys[i] = keys[i] = arc4random(); qsort(sorted_keys, len, sizeof(*sorted_keys), cmp_keys); for (i = 1; i < len; ++i) { if (sorted_keys[i - 1] == sorted_keys[i]) break; } } while (i != len); } static void write_database(size_t len) { struct cdbw *db; int fd; size_t i; uint32_t buf[2]; ATF_REQUIRE((db = cdbw_open()) != NULL); ATF_REQUIRE((fd = creat(database_name, S_IRUSR|S_IWUSR)) != -1); for (i = 0; i < len; ++i) { buf[0] = i; buf[1] = keys[i]; ATF_REQUIRE(cdbw_put(db, &keys[i], sizeof(keys[i]), buf, sizeof(buf)) == 0); } ATF_REQUIRE(cdbw_output(db, fd, "test database", arc4random) == 0); cdbw_close(db); ATF_REQUIRE(close(fd) == 0); } static void check_database(size_t len) { struct cdbr *db; size_t i, data_len; const void *data; uint32_t buf[2]; ATF_REQUIRE((db = cdbr_open(database_name, CDBR_DEFAULT)) != NULL); ATF_REQUIRE_EQ(cdbr_entries(db), len); for (i = 0; i < len; ++i) { ATF_REQUIRE(cdbr_find(db, &keys[i], sizeof(keys[i]), &data, &data_len) != -1); ATF_REQUIRE_EQ(data_len, sizeof(buf)); memcpy(buf, data, sizeof(buf)); ATF_REQUIRE_EQ(buf[0], i); ATF_REQUIRE_EQ(buf[1], keys[i]); } cdbr_close(db); } ATF_TC_WITH_CLEANUP(cdb); ATF_TC_HEAD(cdb, tc) { atf_tc_set_md_var(tc, "descr", "Test cdb(5) reading and writing"); } ATF_TC_BODY(cdb, tc) { size_t i, sizes[] = { 0, 16, 64, 1024, 2048 }; for (i = 0; i < __arraycount(sizes); ++i) { init_keys(sizes[i]); write_database(sizes[i]); check_database(sizes[i]); unlink(database_name); } } ATF_TC_CLEANUP(cdb, tc) { unlink(database_name); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, cdb); return atf_no_error(); } Index: head/contrib/netbsd-tests =================================================================== --- head/contrib/netbsd-tests (revision 311924) +++ head/contrib/netbsd-tests (revision 311925) Property changes on: head/contrib/netbsd-tests ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /vendor/NetBSD/tests/dist:r311922