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 274625) +++ head/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c (revision 274626) @@ -1,392 +1,392 @@ /* $NetBSD: t_fileactions.c,v 1.5 2012/04/09 19:42:07 martin 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. */ -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #endif #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); } -#if defined(__NetBSD__) +#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); -#if defined(__NetBSD__) +#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_getcwd.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_getcwd.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/gen/t_getcwd.c (revision 274626) @@ -1,153 +1,153 @@ /* $NetBSD: t_getcwd.c,v 1.3 2011/07/27 05:04:11 jruoho 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_getcwd.c,v 1.3 2011/07/27 05:04:11 jruoho Exp $"); #include #include #include #include #include #include #include #include ATF_TC(getcwd_err); ATF_TC_HEAD(getcwd_err, tc) { atf_tc_set_md_var(tc, "descr", "Test error conditions in getcwd(3)"); } ATF_TC_BODY(getcwd_err, tc) { char buf[MAXPATHLEN]; errno = 0; ATF_REQUIRE(getcwd(buf, 0) == NULL); ATF_REQUIRE(errno == EINVAL); -#if defined(__NetBSD__) +#ifdef __NetBSD__ errno = 0; ATF_REQUIRE(getcwd((void *)-1, sizeof(buf)) == NULL); ATF_REQUIRE(errno == EFAULT); #endif } ATF_TC(getcwd_fts); ATF_TC_HEAD(getcwd_fts, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of getcwd(3)"); } ATF_TC_BODY(getcwd_fts, tc) { const char *str = NULL; char buf[MAXPATHLEN]; char *argv[2]; FTSENT *ftse; FTS *fts; int ops; short depth; /* * Do not traverse too deep; cf. PR bin/45180. */ depth = 2; argv[1] = NULL; argv[0] = __UNCONST("/"); /* * Test that getcwd(3) works with basic * system directories. Note that having * no FTS_NOCHDIR specified should ensure * that the current directory is visited. */ ops = FTS_PHYSICAL | FTS_NOSTAT; fts = fts_open(argv, ops, NULL); if (fts == NULL) { str = "failed to initialize fts(3)"; goto out; } while ((ftse = fts_read(fts)) != NULL) { if (ftse->fts_level < 1) continue; if (ftse->fts_level > depth) { (void)fts_set(fts, ftse, FTS_SKIP); continue; } switch(ftse->fts_info) { case FTS_DP: (void)memset(buf, 0, sizeof(buf)); if (getcwd(buf, sizeof(buf)) == NULL) { str = "getcwd(3) failed"; goto out; } if (strstr(ftse->fts_path, buf) == NULL) { str = "getcwd(3) returned incorrect path"; goto out; } break; default: break; } } out: if (fts != NULL) (void)fts_close(fts); if (str != NULL) atf_tc_fail("%s", str); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, getcwd_err); ATF_TP_ADD_TC(tp, getcwd_fts); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/gen/t_glob.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_glob.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/gen/t_glob.c (revision 274626) @@ -1,287 +1,287 @@ /* $NetBSD: t_glob.c,v 1.3 2013/01/02 11:28:48 martin Exp $ */ /*- * Copyright (c) 2010 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 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_glob.c,v 1.3 2013/01/02 11:28:48 martin Exp $"); #include #include #include #include #include #include #include #include #include -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include "h_macros.h" #define __gl_stat_t struct stat #define _S_IFDIR S_IFDIR #else #include "../../../h_macros.h" #endif #ifdef DEBUG #define DPRINTF(a) printf a #else #define DPRINTF(a) #endif struct gl_file { const char *name; int dir; }; static struct gl_file a[] = { { "1", 0 }, { "b", 1 }, { "3", 0 }, { "4", 0 }, }; static struct gl_file b[] = { { "x", 0 }, { "y", 0 }, { "z", 0 }, { "w", 0 }, }; struct gl_dir { const char *name; /* directory name */ const struct gl_file *dir; size_t len, pos; }; static struct gl_dir d[] = { { "a", a, __arraycount(a), 0 }, { "a/b", b, __arraycount(b), 0 }, }; static const char *glob_star[] = { "a/1", "a/3", "a/4", "a/b", "a/b/w", "a/b/x", "a/b/y", "a/b/z", }; static const char *glob_star_not[] = { "a/1", "a/3", "a/4", "a/b", }; static void trim(char *buf, size_t len, const char *name) { char *path = buf, *epath = buf + len; while (path < epath && (*path++ = *name++) != '\0') continue; path--; while (path > buf && *--path == '/') *path = '\0'; } static void * gl_opendir(const char *dir) { size_t i; char buf[MAXPATHLEN]; trim(buf, sizeof(buf), dir); for (i = 0; i < __arraycount(d); i++) if (strcmp(buf, d[i].name) == 0) { DPRINTF(("opendir %s %zu\n", buf, i)); return &d[i]; } errno = ENOENT; return NULL; } static struct dirent * gl_readdir(void *v) { static struct dirent dir; struct gl_dir *dd = v; if (dd->pos < dd->len) { const struct gl_file *f = &dd->dir[dd->pos++]; strcpy(dir.d_name, f->name); dir.d_namlen = strlen(f->name); dir.d_ino = dd->pos; dir.d_type = f->dir ? DT_DIR : DT_REG; DPRINTF(("readdir %s %d\n", dir.d_name, dir.d_type)); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ dir.d_reclen = -1; /* Does not have _DIRENT_RECLEN */ #else dir.d_reclen = _DIRENT_RECLEN(&dir, dir.d_namlen); #endif return &dir; } return NULL; } static int gl_stat(const char *name , __gl_stat_t *st) { char buf[MAXPATHLEN]; trim(buf, sizeof(buf), name); memset(st, 0, sizeof(*st)); if (strcmp(buf, "a") == 0 || strcmp(buf, "a/b") == 0) { st->st_mode |= _S_IFDIR; return 0; } if (buf[0] == 'a' && buf[1] == '/') { struct gl_file *f; size_t offs, count; if (buf[2] == 'b' && buf[3] == '/') { offs = 4; count = __arraycount(b); f = b; } else { offs = 2; count = __arraycount(a); f = a; } for (size_t i = 0; i < count; i++) if (strcmp(f[i].name, buf + offs) == 0) return 0; } DPRINTF(("stat %s %d\n", buf, st->st_mode)); errno = ENOENT; return -1; } static int gl_lstat(const char *name , __gl_stat_t *st) { return gl_stat(name, st); } static void gl_closedir(void *v) { struct gl_dir *dd = v; dd->pos = 0; DPRINTF(("closedir %p\n", dd)); } static void run(const char *p, int flags, const char **res, size_t len) { glob_t gl; size_t i; memset(&gl, 0, sizeof(gl)); gl.gl_opendir = gl_opendir; gl.gl_readdir = gl_readdir; gl.gl_closedir = gl_closedir; gl.gl_stat = gl_stat; gl.gl_lstat = gl_lstat; RZ(glob(p, GLOB_ALTDIRFUNC | flags, NULL, &gl)); for (i = 0; i < gl.gl_pathc; i++) DPRINTF(("%s\n", gl.gl_pathv[i])); ATF_CHECK(len == gl.gl_pathc); for (i = 0; i < gl.gl_pathc; i++) ATF_CHECK_STREQ(gl.gl_pathv[i], res[i]); globfree(&gl); } -#if !defined(__FreeBSD__) +#ifndef __FreeBSD__ ATF_TC(glob_star); ATF_TC_HEAD(glob_star, tc) { atf_tc_set_md_var(tc, "descr", "Test glob(3) ** with GLOB_STAR"); } ATF_TC_BODY(glob_star, tc) { run("a/**", GLOB_STAR, glob_star, __arraycount(glob_star)); } #endif ATF_TC(glob_star_not); ATF_TC_HEAD(glob_star_not, tc) { atf_tc_set_md_var(tc, "descr", "Test glob(3) ** without GLOB_STAR"); } ATF_TC_BODY(glob_star_not, tc) { run("a/**", 0, glob_star_not, __arraycount(glob_star_not)); } #if 0 ATF_TC(glob_nocheck); ATF_TC_HEAD(glob_nocheck, tc) { atf_tc_set_md_var(tc, "descr", "Test glob(3) pattern with backslash and GLOB_NOCHECK"); } ATF_TC_BODY(glob_nocheck, tc) { static const char pattern[] = { 'f', 'o', 'o', '\\', ';', 'b', 'a', 'r', '\0' }; static const char *glob_nocheck[] = { pattern }; run(pattern, GLOB_NOCHECK, glob_nocheck, __arraycount(glob_nocheck)); } #endif ATF_TP_ADD_TCS(tp) { -#if !defined(__FreeBSD__) +#ifndef __FreeBSD__ ATF_TP_ADD_TC(tp, glob_star); #endif ATF_TP_ADD_TC(tp, glob_star_not); /* * Remove this test for now - the GLOB_NOCHECK return value has been * re-defined to return a modified pattern in revision 1.33 of glob.c * * ATF_TP_ADD_TC(tp, glob_nocheck); */ 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 274625) +++ head/contrib/netbsd-tests/lib/libc/gen/t_humanize_number.c (revision 274626) @@ -1,318 +1,318 @@ /* $NetBSD: t_humanize_number.c,v 1.8 2012/03/18 07:14:08 jruoho 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 -#if defined(__FreeBSD__) +#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". */ -#if !defined(__FreeBSD__) +#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); } } 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_nice.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_nice.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/gen/t_nice.c (revision 274626) @@ -1,221 +1,221 @@ /* $NetBSD: t_nice.c,v 1.8 2012/03/18 07:00:51 jruoho 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_nice.c,v 1.8 2012/03/18 07:00:51 jruoho Exp $"); #include #include #include #include #include #include #include #include static void *threadfunc(void *); static void * threadfunc(void *arg) { int pri, val; val = *(int *)arg; errno = 0; pri = getpriority(PRIO_PROCESS, 0); ATF_REQUIRE(errno == 0); if (pri != val) atf_tc_fail("nice(3) value was not propagated to threads"); return NULL; } ATF_TC(nice_err); ATF_TC_HEAD(nice_err, tc) { atf_tc_set_md_var(tc, "descr", "Test nice(3) for invalid parameters (PR lib/42587)"); atf_tc_set_md_var(tc, "require.user", "unprivileged"); } ATF_TC_BODY(nice_err, tc) { int i; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ atf_tc_expect_fail("nice(incr) with incr < 0 fails with unprivileged " "users and sets errno == EPERM; see PR # 189821 for more details"); #endif /* * The call should fail with EPERM if the * supplied parameter is negative and the * caller does not have privileges. */ for (i = -20; i < 0; i++) { errno = 0; ATF_REQUIRE_ERRNO(EPERM, nice(i) == -1); } } ATF_TC(nice_priority); ATF_TC_HEAD(nice_priority, tc) { atf_tc_set_md_var(tc, "descr", "Test nice(3) vs. getpriority(2)"); } ATF_TC_BODY(nice_priority, tc) { -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ int i, pri, pri2, nic; #else int i, pri, nic; #endif pid_t pid; int sta; for (i = 0; i <= 20; i++) { nic = nice(i); ATF_REQUIRE(nic != -1); errno = 0; pri = getpriority(PRIO_PROCESS, 0); ATF_REQUIRE(errno == 0); -#if defined(__NetBSD__) +#ifdef __NetBSD__ if (nic != pri) atf_tc_fail("nice(3) and getpriority(2) conflict"); #endif /* * Also verify that the nice(3) values * are inherited by child processes. */ pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { errno = 0; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ pri = getpriority(PRIO_PROCESS, 0); #else pri2 = getpriority(PRIO_PROCESS, 0); #endif ATF_REQUIRE(errno == 0); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ if (pri != pri2) #else if (nic != pri) #endif _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); } (void)wait(&sta); if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) atf_tc_fail("nice(3) value was not inherited"); } } ATF_TC(nice_root); ATF_TC_HEAD(nice_root, tc) { atf_tc_set_md_var(tc, "descr", "Test that nice(3) works"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(nice_root, tc) { int i; for (i = -20; i <= 20; i++) { ATF_REQUIRE(nice(i) != -1); } } ATF_TC(nice_thread); ATF_TC_HEAD(nice_thread, tc) { atf_tc_set_md_var(tc, "descr", "Test nice(3) with threads"); } ATF_TC_BODY(nice_thread, tc) { pthread_t tid[5]; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ int pri, rv, val; #else int rv, val; #endif size_t i; /* * Test that the scheduling priority is * propagated to all system scope threads. */ for (i = 0; i < __arraycount(tid); i++) { val = nice(i); ATF_REQUIRE(val != -1); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ pri = getpriority(PRIO_PROCESS, 0); rv = pthread_create(&tid[i], NULL, threadfunc, &pri); #else rv = pthread_create(&tid[i], NULL, threadfunc, &val); #endif ATF_REQUIRE(rv == 0); rv = pthread_join(tid[i], NULL); ATF_REQUIRE(rv == 0); } } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, nice_err); ATF_TP_ADD_TC(tp, nice_priority); ATF_TP_ADD_TC(tp, nice_root); ATF_TP_ADD_TC(tp, nice_thread); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/gen/t_raise.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_raise.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/gen/t_raise.c (revision 274626) @@ -1,194 +1,194 @@ /* $NetBSD: t_raise.c,v 1.5 2011/05/10 12:43:42 jruoho 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_raise.c,v 1.5 2011/05/10 12:43:42 jruoho Exp $"); #include #include #include #include #include static bool fail; static int count; static void handler_err(int); static void handler_ret(int); static void handler_stress(int); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ static int sig[] = { SIGALRM, SIGIO, SIGUSR1, SIGUSR2 }; #else static int sig[] = { SIGALRM, SIGIO, SIGUSR1, SIGUSR2, SIGPWR }; #endif static void handler_stress(int signo) { count++; } static void handler_err(int signo) { size_t i; for (i = 0; i < __arraycount(sig); i++) { if (sig[i] == signo) { fail = false; break; } } } static void handler_ret(int signo) { (void)sleep(1); fail = false; } ATF_TC(raise_err); ATF_TC_HEAD(raise_err, tc) { atf_tc_set_md_var(tc, "descr", "Test raise(3) for invalid parameters"); } ATF_TC_BODY(raise_err, tc) { int i = 0; while (i < 10) { ATF_REQUIRE(raise(10240 + i) == -1); i++; } } ATF_TC(raise_ret); ATF_TC_HEAD(raise_ret, tc) { atf_tc_set_md_var(tc, "descr", "Test return order of raise(3)"); } ATF_TC_BODY(raise_ret, tc) { struct sigaction sa; fail = true; sa.sa_flags = 0; sa.sa_handler = handler_ret; /* * Verify that raise(3) does not return * before the signal handler returns. */ ATF_REQUIRE(sigemptyset(&sa.sa_mask) == 0); ATF_REQUIRE(sigaction(SIGUSR1, &sa, 0) == 0); ATF_REQUIRE(raise(SIGUSR1) == 0); if (fail != false) atf_tc_fail("raise(3) returned before signal handler"); } ATF_TC(raise_sig); ATF_TC_HEAD(raise_sig, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of raise(3)"); } ATF_TC_BODY(raise_sig, tc) { struct timespec tv, tr; struct sigaction sa; size_t i; for (i = 0; i < __arraycount(sig); i++) { (void)memset(&sa, 0, sizeof(struct sigaction)); fail = true; tv.tv_sec = 0; tv.tv_nsec = 2; sa.sa_flags = 0; sa.sa_handler = handler_err; ATF_REQUIRE(sigemptyset(&sa.sa_mask) == 0); ATF_REQUIRE(sigaction(sig[i], &sa, 0) == 0); ATF_REQUIRE(raise(sig[i]) == 0); ATF_REQUIRE(nanosleep(&tv, &tr) == 0); if (fail != false) atf_tc_fail("raise(3) did not raise a signal"); } } ATF_TC(raise_stress); ATF_TC_HEAD(raise_stress, tc) { atf_tc_set_md_var(tc, "descr", "A basic stress test with raise(3)"); } ATF_TC_BODY(raise_stress, tc) { static const int maxiter = 1000 * 10; struct sigaction sa; int i; sa.sa_flags = 0; sa.sa_handler = handler_stress; ATF_REQUIRE(sigemptyset(&sa.sa_mask) == 0); ATF_REQUIRE(sigaction(SIGUSR1, &sa, 0) == 0); for (count = i = 0; i < maxiter; i++) (void)raise(SIGUSR1); if (count != maxiter) atf_tc_fail("not all signals were catched"); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, raise_err); ATF_TP_ADD_TC(tp, raise_ret); ATF_TP_ADD_TC(tp, raise_sig); ATF_TP_ADD_TC(tp, raise_stress); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/gen/t_setdomainname.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_setdomainname.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/gen/t_setdomainname.c (revision 274626) @@ -1,148 +1,148 @@ /* $NetBSD: t_setdomainname.c,v 1.2 2012/03/25 08:17:54 joerg 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_setdomainname.c,v 1.2 2012/03/25 08:17:54 joerg Exp $"); #include #include #include #include #include static char domain[MAXHOSTNAMELEN]; static const char domains[][MAXHOSTNAMELEN] = { "1234567890", "abcdefghijklmnopqrst", "!#\xa4%&/(..xasS812=!=!(I(!;X;;X.as.dasa=?;,..<>|**^\xa8", "--------------------------------------------------------------------" }; ATF_TC_WITH_CLEANUP(setdomainname_basic); ATF_TC_HEAD(setdomainname_basic, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of setdomainname(3)"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(setdomainname_basic, tc) { char name[MAXHOSTNAMELEN]; size_t i; for (i = 0; i < __arraycount(domains); i++) { (void)memset(name, 0, sizeof(name)); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ /* * Sanity checks to ensure that the wrong invariant isn't being * tested for per PR # 181127 */ ATF_REQUIRE_EQ(sizeof(domains[i]), MAXHOSTNAMELEN); ATF_REQUIRE_EQ(sizeof(name), MAXHOSTNAMELEN); ATF_REQUIRE(setdomainname(domains[i],sizeof(domains[i]) - 1) == 0); ATF_REQUIRE(getdomainname(name, sizeof(name) - 1) == 0); #else ATF_REQUIRE(setdomainname(domains[i],sizeof(domains[i])) == 0); ATF_REQUIRE(getdomainname(name, sizeof(name)) == 0); #endif ATF_REQUIRE(strcmp(domains[i], name) == 0); } (void)setdomainname(domain, sizeof(domain)); } ATF_TC_CLEANUP(setdomainname_basic, tc) { (void)setdomainname(domain, sizeof(domain)); } ATF_TC_WITH_CLEANUP(setdomainname_limit); ATF_TC_HEAD(setdomainname_limit, tc) { atf_tc_set_md_var(tc, "descr", "Too long domain name errors out?"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(setdomainname_limit, tc) { char name[MAXHOSTNAMELEN + 1]; (void)memset(name, 0, sizeof(name)); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ ATF_REQUIRE(setdomainname(name, MAXHOSTNAMELEN - 1 ) == 0); ATF_REQUIRE(setdomainname(name, MAXHOSTNAMELEN) == -1); #endif ATF_REQUIRE(setdomainname(name, sizeof(name)) == -1); } ATF_TC_CLEANUP(setdomainname_limit, tc) { (void)setdomainname(domain, sizeof(domain)); } ATF_TC_WITH_CLEANUP(setdomainname_perm); ATF_TC_HEAD(setdomainname_perm, tc) { atf_tc_set_md_var(tc, "descr", "Can normal user set the domain name?"); atf_tc_set_md_var(tc, "require.user", "unprivileged"); } ATF_TC_BODY(setdomainname_perm, tc) { errno = 0; ATF_REQUIRE_ERRNO(EPERM, setdomainname(domain, sizeof(domain)) == -1); } ATF_TC_CLEANUP(setdomainname_perm, tc) { (void)setdomainname(domain, sizeof(domain)); } ATF_TP_ADD_TCS(tp) { (void)memset(domain, 0, sizeof(domain)); ATF_REQUIRE(getdomainname(domain, sizeof(domain)) == 0); ATF_TP_ADD_TC(tp, setdomainname_basic); ATF_TP_ADD_TC(tp, setdomainname_limit); ATF_TP_ADD_TC(tp, setdomainname_perm); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/gen/t_siginfo.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_siginfo.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/gen/t_siginfo.c (revision 274626) @@ -1,505 +1,505 @@ /* $NetBSD: t_siginfo.c,v 1.24 2014/11/04 00:20:19 justin 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 -#if defined(__NetBSD__) +#ifdef __NetBSD__ #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_FENV #include #elif defined(_FLOAT_IEEE754) #include #endif #include "isqemu.h" /* for sigbus */ volatile char *addr; /* for sigchild */ pid_t child; int code; int status; /* for sigfpe */ sig_atomic_t fltdiv_signalled = 0; sig_atomic_t intdiv_signalled = 0; static void sig_debug(int signo, siginfo_t *info, ucontext_t *ctx) { unsigned int i; printf("%d %p %p\n", signo, info, ctx); if (info != NULL) { printf("si_signo=%d\n", info->si_signo); printf("si_errno=%d\n", info->si_errno); printf("si_code=%d\n", info->si_code); printf("si_value.sival_int=%d\n", info->si_value.sival_int); } if (ctx != NULL) { printf("uc_flags 0x%x\n", ctx->uc_flags); printf("uc_link %p\n", ctx->uc_link); for (i = 0; i < __arraycount(ctx->uc_sigmask.__bits); i++) printf("uc_sigmask[%d] 0x%x\n", i, ctx->uc_sigmask.__bits[i]); printf("uc_stack %p %lu 0x%x\n", ctx->uc_stack.ss_sp, (unsigned long)ctx->uc_stack.ss_size, ctx->uc_stack.ss_flags); -#if defined(__NetBSD__) +#ifdef __NetBSD__ for (i = 0; i < __arraycount(ctx->uc_mcontext.__gregs); i++) printf("uc_mcontext.greg[%d] 0x%lx\n", i, (long)ctx->uc_mcontext.__gregs[i]); #endif } } static void sigalrm_action(int signo, siginfo_t *info, void *ptr) { sig_debug(signo, info, (ucontext_t *)ptr); ATF_REQUIRE_EQ(info->si_signo, SIGALRM); ATF_REQUIRE_EQ(info->si_code, SI_TIMER); ATF_REQUIRE_EQ(info->si_value.sival_int, ITIMER_REAL); atf_tc_pass(); /* NOTREACHED */ } ATF_TC(sigalarm); ATF_TC_HEAD(sigalarm, tc) { atf_tc_set_md_var(tc, "descr", "Checks that signal trampoline correctly calls SIGALRM handler"); } ATF_TC_BODY(sigalarm, tc) { struct sigaction sa; sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = sigalrm_action; sigemptyset(&sa.sa_mask); sigaction(SIGALRM, &sa, NULL); for (;;) { alarm(1); sleep(1); } atf_tc_fail("SIGALRM handler wasn't called"); } static void sigchild_action(int signo, siginfo_t *info, void *ptr) { if (info != NULL) { printf("info=%p\n", info); printf("ptr=%p\n", ptr); printf("si_signo=%d\n", info->si_signo); printf("si_errno=%d\n", info->si_errno); printf("si_code=%d\n", info->si_code); printf("si_uid=%d\n", info->si_uid); printf("si_pid=%d\n", info->si_pid); printf("si_status=%d\n", info->si_status); -#if defined(__NetBSD__) +#ifdef __NetBSD__ printf("si_utime=%lu\n", (unsigned long int)info->si_utime); printf("si_stime=%lu\n", (unsigned long int)info->si_stime); #endif } ATF_REQUIRE_EQ(info->si_code, code); ATF_REQUIRE_EQ(info->si_signo, SIGCHLD); ATF_REQUIRE_EQ(info->si_uid, getuid()); ATF_REQUIRE_EQ(info->si_pid, child); if (WIFEXITED(info->si_status)) ATF_REQUIRE_EQ(WEXITSTATUS(info->si_status), status); else if (WIFSTOPPED(info->si_status)) ATF_REQUIRE_EQ(WSTOPSIG(info->si_status), status); else if (WIFSIGNALED(info->si_status)) ATF_REQUIRE_EQ(WTERMSIG(info->si_status), status); } static void setchildhandler(void (*action)(int, siginfo_t *, void *)) { struct sigaction sa; sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = action; sigemptyset(&sa.sa_mask); sigaction(SIGCHLD, &sa, NULL); } static void sigchild_setup(void) { sigset_t set; struct rlimit rlim; (void)getrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max; (void)setrlimit(RLIMIT_CORE, &rlim); setchildhandler(sigchild_action); sigemptyset(&set); sigaddset(&set, SIGCHLD); sigprocmask(SIG_BLOCK, &set, NULL); } ATF_TC(sigchild_normal); ATF_TC_HEAD(sigchild_normal, tc) { atf_tc_set_md_var(tc, "descr", "Checks that signal trampoline correctly calls SIGCHLD handler " "when child exits normally"); } ATF_TC_BODY(sigchild_normal, tc) { sigset_t set; sigchild_setup(); status = 25; code = CLD_EXITED; switch ((child = fork())) { case 0: sleep(1); exit(status); case -1: atf_tc_fail("fork failed"); default: sigemptyset(&set); sigsuspend(&set); } } ATF_TC(sigchild_dump); ATF_TC_HEAD(sigchild_dump, tc) { atf_tc_set_md_var(tc, "descr", "Checks that signal trampoline correctly calls SIGCHLD handler " "when child segfaults"); } ATF_TC_BODY(sigchild_dump, tc) { sigset_t set; sigchild_setup(); status = SIGSEGV; code = CLD_DUMPED; switch ((child = fork())) { case 0: sleep(1); *(volatile long *)0 = 0; atf_tc_fail("Child did not segfault"); /* NOTREACHED */ case -1: atf_tc_fail("fork failed"); default: sigemptyset(&set); sigsuspend(&set); } } ATF_TC(sigchild_kill); ATF_TC_HEAD(sigchild_kill, tc) { atf_tc_set_md_var(tc, "descr", "Checks that signal trampoline correctly calls SIGCHLD handler " "when child is killed"); } ATF_TC_BODY(sigchild_kill, tc) { sigset_t set; sigchild_setup(); status = SIGPIPE; code = CLD_KILLED; switch ((child = fork())) { case 0: sigemptyset(&set); sigsuspend(&set); break; case -1: atf_tc_fail("fork failed"); default: kill(child, SIGPIPE); sigemptyset(&set); sigsuspend(&set); } } static sigjmp_buf sigfpe_flt_env; static void sigfpe_flt_action(int signo, siginfo_t *info, void *ptr) { sig_debug(signo, info, (ucontext_t *)ptr); if (fltdiv_signalled++ != 0) atf_tc_fail("FPE handler called more than once"); ATF_REQUIRE_EQ(info->si_signo, SIGFPE); ATF_REQUIRE_EQ(info->si_code, FPE_FLTDIV); ATF_REQUIRE_EQ(info->si_errno, 0); siglongjmp(sigfpe_flt_env, 1); } ATF_TC(sigfpe_flt); ATF_TC_HEAD(sigfpe_flt, tc) { atf_tc_set_md_var(tc, "descr", "Checks that signal trampoline correctly calls SIGFPE handler " "for floating div-by-zero"); } ATF_TC_BODY(sigfpe_flt, tc) { struct sigaction sa; double d = strtod("0", NULL); if (isQEMU()) atf_tc_skip("Test does not run correctly under QEMU"); #if defined(__powerpc__) atf_tc_skip("Test not valid on powerpc"); #endif if (sigsetjmp(sigfpe_flt_env, 0) == 0) { sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = sigfpe_flt_action; sigemptyset(&sa.sa_mask); sigaction(SIGFPE, &sa, NULL); #ifdef HAVE_FENV feenableexcept(FE_ALL_EXCEPT); #elif defined(_FLOAT_IEEE754) fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP); #endif printf("%g\n", 1 / d); } if (fltdiv_signalled == 0) atf_tc_fail("FPE signal handler was not invoked"); } static sigjmp_buf sigfpe_int_env; static void sigfpe_int_action(int signo, siginfo_t *info, void *ptr) { sig_debug(signo, info, (ucontext_t *)ptr); if (intdiv_signalled++ != 0) atf_tc_fail("INTDIV handler called more than once"); ATF_REQUIRE_EQ(info->si_signo, SIGFPE); ATF_REQUIRE_EQ(info->si_code, FPE_INTDIV); atf_tc_expect_pass(); ATF_REQUIRE_EQ(info->si_errno, 0); siglongjmp(sigfpe_int_env, 1); } ATF_TC(sigfpe_int); ATF_TC_HEAD(sigfpe_int, tc) { atf_tc_set_md_var(tc, "descr", "Checks that signal trampoline correctly calls SIGFPE handler " "for integer div-by-zero (PR port-i386/43655)"); } ATF_TC_BODY(sigfpe_int, tc) { struct sigaction sa; long l = strtol("0", NULL, 10); #if defined(__powerpc__) atf_tc_skip("Test not valid on powerpc"); #endif if (sigsetjmp(sigfpe_int_env, 0) == 0) { sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = sigfpe_int_action; sigemptyset(&sa.sa_mask); sigaction(SIGFPE, &sa, NULL); #ifdef HAVE_FENV feenableexcept(FE_ALL_EXCEPT); #elif defined(_FLOAT_IEEE754) fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP); #endif printf("%ld\n", 1 / l); } if (intdiv_signalled == 0) atf_tc_fail("FPE signal handler was not invoked"); } static void sigsegv_action(int signo, siginfo_t *info, void *ptr) { sig_debug(signo, info, (ucontext_t *)ptr); ATF_REQUIRE_EQ(info->si_signo, SIGSEGV); ATF_REQUIRE_EQ(info->si_errno, 0); ATF_REQUIRE_EQ(info->si_code, SEGV_MAPERR); ATF_REQUIRE_EQ(info->si_addr, (void *)0); atf_tc_pass(); /* NOTREACHED */ } ATF_TC(sigsegv); ATF_TC_HEAD(sigsegv, tc) { atf_tc_set_md_var(tc, "descr", "Checks that signal trampoline correctly calls SIGSEGV handler"); } ATF_TC_BODY(sigsegv, tc) { struct sigaction sa; sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = sigsegv_action; sigemptyset(&sa.sa_mask); sigaction(SIGSEGV, &sa, NULL); *(volatile long *)0 = 0; atf_tc_fail("Test did not fault as expected"); } static void sigbus_action(int signo, siginfo_t *info, void *ptr) { printf("si_addr = %p\n", info->si_addr); sig_debug(signo, info, (ucontext_t *)ptr); ATF_REQUIRE_EQ(info->si_signo, SIGBUS); ATF_REQUIRE_EQ(info->si_errno, 0); ATF_REQUIRE_EQ(info->si_code, BUS_ADRALN); #if defined(__i386__) || defined(__x86_64__) atf_tc_expect_fail("x86 architecture does not correctly " "report the address where the unaligned access occured"); #endif ATF_REQUIRE_EQ(info->si_addr, (volatile void *)addr); atf_tc_pass(); /* NOTREACHED */ } ATF_TC(sigbus_adraln); ATF_TC_HEAD(sigbus_adraln, tc) { atf_tc_set_md_var(tc, "descr", "Checks that signal trampoline correctly calls SIGBUS handler " "for invalid address alignment"); } ATF_TC_BODY(sigbus_adraln, tc) { struct sigaction sa; #if defined(__alpha__) int rv, val; size_t len = sizeof(val); rv = sysctlbyname("machdep.unaligned_sigbus", &val, &len, NULL, 0); ATF_REQUIRE(rv == 0); if (val == 0) atf_tc_skip("SIGBUS signal not enabled for unaligned accesses"); #endif sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = sigbus_action; sigemptyset(&sa.sa_mask); sigaction(SIGBUS, &sa, NULL); /* Enable alignment checks for x86. 0x40000 is PSL_AC. */ #if defined(__i386__) __asm__("pushf; orl $0x40000, (%esp); popf"); #elif defined(__amd64__) __asm__("pushf; orl $0x40000, (%rsp); popf"); #endif addr = calloc(2, sizeof(int)); ATF_REQUIRE(addr != NULL); if (isQEMU()) atf_tc_expect_fail("QEMU fails to trap unaligned accesses"); /* Force an unaligned access */ addr++; printf("now trying to access unaligned address %p\n", addr); ATF_REQUIRE_EQ(*(volatile int *)addr, 0); atf_tc_fail("Test did not fault as expected"); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, sigalarm); ATF_TP_ADD_TC(tp, sigchild_normal); ATF_TP_ADD_TC(tp, sigchild_dump); ATF_TP_ADD_TC(tp, sigchild_kill); ATF_TP_ADD_TC(tp, sigfpe_flt); ATF_TP_ADD_TC(tp, sigfpe_int); ATF_TP_ADD_TC(tp, sigsegv); ATF_TP_ADD_TC(tp, sigbus_adraln); 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 274625) +++ head/contrib/netbsd-tests/lib/libc/gen/t_time.c (revision 274626) @@ -1,117 +1,117 @@ /* $NetBSD: t_time.c,v 1.2 2011/11/11 05:03:38 jruoho 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.2 2011/11/11 05:03:38 jruoho Exp $"); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #endif #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 t; t = time(NULL); ATF_REQUIRE(gettimeofday(&tv, NULL) == 0); (void)fprintf(stderr, "%"PRId64" vs. %"PRId64"\n", (int64_t)t, (int64_t)tv.tv_sec); if (t != 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 274625) +++ head/contrib/netbsd-tests/lib/libc/gen/t_ttyname.c (revision 274626) @@ -1,191 +1,191 @@ /* $NetBSD: t_ttyname.c,v 1.3 2011/05/01 18:14:01 jruoho 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 $"); #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); } } 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); } -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ atf_tc_expect_fail("FreeBSD returns ENOTTY instead of EBADF; see bin/191936"); #endif 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/locale/t_mbrtowc.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/locale/t_mbrtowc.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/locale/t_mbrtowc.c (revision 274626) @@ -1,277 +1,277 @@ /* $NetBSD: t_mbrtowc.c,v 1.1 2011/07/15 07:35:21 jruoho Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by YAMAMOTO Takashi * * 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)2003 Citrus Project, * 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 __COPYRIGHT("@(#) Copyright (c) 2011\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_mbrtowc.c,v 1.1 2011/07/15 07:35:21 jruoho Exp $"); #include #include #include #include #include #include #include #include #define SIZE 256 static struct test { const char *locale; const char *data; const wchar_t wchars[64]; const wchar_t widths[64]; size_t length; } tests[] = { { "C", "ABCD01234_\\", { 0x41, 0x42, 0x43, 0x44, 0x30, 0x31, 0x32, 0x33, 0x34, 0x5F, 0x5C }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 11 }, { "en_US.UTF-8", "[\001\177][\302\200\337\277][\340\240\200\357\277\277][\360\220\200" "\200\367\277\277\277][\370\210\200\200\200\373\277\277\277\277][\374" "\204\200\200\200\200\375\277\277\277\277\277]", { 0x5b, 0x01, 0x7f, 0x5d, 0x5b, 0x80, 0x7ff, 0x5d, 0x5b, 0x800, 0xffff, 0x5d, 0x5b, 0x10000, 0x1fffff, 0x5d, 0x5b, 0x200000, 0x3ffffff, 0x5d, 0x5b, 0x4000000, 0x7fffffff, 0x5d }, { 1, 1, 1, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 4, 4, 1, 1, 5, 5, 1, 1, 6, 6, 1 }, 24 }, { "ja_JP.ISO2022-JP2", "\033$BF|K\1348l\033(BA\033$B$\"\033(BB\033$B$$\033(B", { 0x4200467c, 0x42004b5c, 0x4200386c, 0x41, 0x42002422, 0x42, 0x42002424 }, { 5, 2, 2, 4, 5, 4, 5 }, 7 }, { "ja_JP.SJIS", "\223\372\226{\214\352A\202\240B\202\242", { 0x93fa, 0x967b, 0x8cea, 0x41, 0x82a0, 0x42, 0x82a2 }, { 2, 2, 2, 1, 2, 1, 2 }, 7 }, { "ja_JP.eucJP", "\306\374\313\334\270\354A\244\242B\244\244", { 0xc6fc, 0xcbdc, 0xb8ec, 0x41, 0xa4a2, 0x42, 0xa4a4 }, { 2, 2, 2, 1, 2, 1, 2 }, 7 }, { NULL, NULL, { }, { }, 0 } }; static void h_ctype2(const struct test *t, bool use_mbstate) { mbstate_t *stp; mbstate_t st; char buf[SIZE]; char *str; size_t n; ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); -#if defined(__NetBSD__) +#ifdef __NetBSD__ ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL); #else if (setlocale(LC_CTYPE, t->locale) == NULL) { fprintf(stderr, "Locale %s not found.\n", t->locale); return; } #endif (void)strvis(buf, t->data, VIS_WHITE | VIS_OCTAL); (void)printf("Checking string: \"%s\"\n", buf); ATF_REQUIRE((str = setlocale(LC_ALL, NULL)) != NULL); (void)printf("Using locale: %s\n", str); (void)printf("Using mbstate: %s\n", use_mbstate ? "yes" : "no"); (void)memset(&st, 0, sizeof(st)); // mbrtowc(0, 0, 0, &st); /* XXX for ISO2022-JP */ stp = use_mbstate ? &st : 0; for (n = 9; n > 0; n--) { const char *src = t->data; wchar_t dst; size_t nchar = 0; int width = 0; ATF_REQUIRE(mbsinit(stp) != 0); for (;;) { size_t rv = mbrtowc(&dst, src, n, stp); if (rv == 0) break; if (rv == (size_t)-2) { src += n; width += n; continue; } if (rv == (size_t)-1) { ATF_REQUIRE_EQ(errno, EILSEQ); atf_tc_fail("Invalid sequence"); /* NOTREACHED */ } width += rv; src += rv; if (dst != t->wchars[nchar] || width != t->widths[nchar]) { (void)printf("At position %zd:\n", nchar); (void)printf(" expected: 0x%04X (%u)\n", t->wchars[nchar], t->widths[nchar]); (void)printf(" got : 0x%04X (%u)\n", dst, width); atf_tc_fail("Test failed"); } nchar++; width = 0; } ATF_REQUIRE_EQ_MSG(dst, 0, "Incorrect terminating character: " "0x%04X (expected: 0x00)", dst); ATF_REQUIRE_EQ_MSG(nchar, t->length, "Incorrect length: " "%zd (expected: %zd)", nchar, t->length); } { wchar_t wbuf[SIZE]; size_t rv; char const *src = t->data; int i; (void)memset(wbuf, 0xFF, sizeof(wbuf)); rv = mbsrtowcs(wbuf, &src, SIZE, stp); ATF_REQUIRE_EQ_MSG(rv, t->length, "Incorrect length: %zd " "(expected: %zd)", rv, t->length); ATF_REQUIRE_EQ(src, NULL); for (i = 0; wbuf[i] != 0; ++i) { if (wbuf[i] == t->wchars[i]) continue; (void)printf("At position %d:\n", i); (void)printf(" expected: 0x%04X\n", t->wchars[i]); (void)printf(" got : 0x%04X\n", wbuf[i]); atf_tc_fail("Test failed"); } ATF_REQUIRE_EQ_MSG((size_t)i, t->length, "Incorrect length: " "%d (expected: %zd)", i, t->length); } (void)printf("Ok.\n"); } ATF_TC(mbrtowc_internal); ATF_TC_HEAD(mbrtowc_internal, tc) { atf_tc_set_md_var(tc, "descr", "Checks mbrtowc(3) and mbsrtowcs(3) (using internal " "state) with different locales"); } ATF_TC_BODY(mbrtowc_internal, tc) { struct test *t; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ atf_tc_expect_fail("ja_* locale fails"); #endif for (t = &tests[0]; t->data != NULL; ++t) h_ctype2(t, false); } ATF_TC(mbrtowc_object); ATF_TC_HEAD(mbrtowc_object, tc) { atf_tc_set_md_var(tc, "descr", "Checks mbrtowc(3) and mbsrtowcs(3) (using state " "object) with different locales"); } ATF_TC_BODY(mbrtowc_object, tc) { struct test *t; for (t = &tests[0]; t->data != NULL; ++t) h_ctype2(t, true); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, mbrtowc_internal); ATF_TP_ADD_TC(tp, mbrtowc_object); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/locale/t_mbstowcs.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/locale/t_mbstowcs.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/locale/t_mbstowcs.c (revision 274626) @@ -1,209 +1,209 @@ /* $NetBSD: t_mbstowcs.c,v 1.1 2011/07/15 07:35:21 jruoho Exp $ */ /*- * Copyright (c) 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. */ /*- * Copyright (c)2003 Citrus Project, * 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 __COPYRIGHT("@(#) Copyright (c) 2011\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_mbstowcs.c,v 1.1 2011/07/15 07:35:21 jruoho Exp $"); #include #include #include #include #include #include #include #include #define REQUIRE_ERRNO(x, v) \ ATF_REQUIRE_MSG((x) != (v), "%s: %s", #x, strerror(errno)) #define SIZE 256 static struct test { const char *locale; const char *data; wchar_t wchars[64]; int widths[64]; int width; } tests[] = { { "en_US.UTF-8", "[\001\177][\302\200\337\277][\340\240\200\357\277\277][\360\220\200" "\200\367\277\277\277][\370\210\200\200\200\373\277\277\277\277][\374" "\204\200\200\200\200\375\277\277\277\277\277]", { 0x5B, 0x01, 0x7F, 0x5D, 0x5B, 0x80, 0x07FF, 0x5D, 0x5B, 0x0800, 0xFFFF, 0x5D, 0x5B, 0x10000, 0x1FFFFF, 0x5D, 0x5B, 0x200000, 0x3FFFFFF, 0x5D, 0x5B, 0x4000000, 0x7FFFFFFF, 0x5D, 0x0A }, { 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, -1 }, -1 }, { "ja_JP.ISO2022-JP", "\033$B#J#I#S$G$9!#\033(Baaaa\033$B$\"$$$&$($*\033(B", { 0x4200234A, 0x42002349, 0x42002353, 0x42002447, 0x42002439, 0x42002123, 0x61, 0x61, 0x61, 0x61, 0x42002422, 0x42002424, 0x42002426, 0x42002428, 0x4200242A, 0x0A }, { 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, -1 }, 26 }, { "ja_JP.SJIS", "\202r\202i\202h\202r\202\305\202\267\201Baaaa\202\240\202\242" "\202\244\202\246\202\250", { 0x8272, 0x8269, 0x8268, 0x8272, 0x82C5, 0x82B7, 0x8142, 0x61, 0x61, 0x61, 0x61, 0x82A0, 0x82A2, 0x82A4, 0x82A6, 0x82A8, 0x0A }, { 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, -1 }, 28 }, { "ja_JP.eucJP", "\243\305\243\325\243\303\244\307\244\271\241\243aaaa\244\242\244" "\244\244\246\244\250\244\252", { 0xA3C5, 0xA3D5, 0xA3C3, 0xA4C7, 0xA4B9, 0xA1A3, 0x61, 0x61, 0x61, 0x61, 0xA4A2, 0xA4A4, 0xA4A6, 0xA4A8, 0xA4AA, 0x0A }, { 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, -1 }, 26 }, { NULL, NULL, {}, {}, 0 } }; ATF_TC(mbstowcs_basic); ATF_TC_HEAD(mbstowcs_basic, tc) { atf_tc_set_md_var(tc, "descr", "Checks wide character functions with different locales"); } ATF_TC_BODY(mbstowcs_basic, tc) { struct test *t; for (t = &tests[0]; t->data != NULL; ++t) { wchar_t wbuf[SIZE]; char buf[SIZE]; char visbuf[SIZE]; char *str; int i; ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); -#if defined(__NetBSD__) +#ifdef __NetBSD__ ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL); #else if (setlocale(LC_CTYPE, t->locale) == NULL) { fprintf(stderr, "Locale %s not found.\n", t->locale); continue; } #endif (void)strvis(visbuf, t->data, VIS_WHITE | VIS_OCTAL); (void)printf("Checking string: \"%s\"\n", visbuf); ATF_REQUIRE((str = setlocale(LC_ALL, NULL)) != NULL); (void)printf("Using locale: %s\n", str); REQUIRE_ERRNO((ssize_t)mbstowcs(wbuf, t->data, SIZE-1), -1); REQUIRE_ERRNO((ssize_t)wcstombs(buf, wbuf, SIZE-1), -1); if (strcmp(buf, t->data) != 0) { (void)strvis(visbuf, buf, VIS_WHITE | VIS_OCTAL); (void)printf("Conversion to wcs and back failed: " "\"%s\"\n", visbuf); atf_tc_fail("Test failed"); } /* The output here is implementation-dependent. */ for (i = 0; wbuf[i] != 0; ++i) { if (wbuf[i] == t->wchars[i] && wcwidth(wbuf[i]) == t->widths[i]) continue; (void)printf("At position %d:\n", i); (void)printf(" expected: 0x%04X (%d)\n", t->wchars[i], t->widths[i]); (void)printf(" got : 0x%04X (%d)\n", wbuf[i], wcwidth(wbuf[i])); atf_tc_fail("Test failed"); } if (wcswidth(wbuf, SIZE-1) != t->width) { (void)printf("Incorrect wcswidth:\n"); (void)printf(" expected: %d\n", t->width); (void)printf(" got : %d\n", wcswidth(wbuf, SIZE-1)); atf_tc_fail("Test failed"); } (void)printf("Ok.\n"); } } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, mbstowcs_basic); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/locale/t_mbtowc.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/locale/t_mbtowc.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/locale/t_mbtowc.c (revision 274626) @@ -1,157 +1,157 @@ /* $NetBSD: t_mbtowc.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $ */ /*- * Copyright (c) 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. */ /*- * Copyright (c)2007 Citrus Project, * 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 __COPYRIGHT("@(#) Copyright (c) 2011\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_mbtowc.c,v 1.1 2011/04/09 17:45:25 pgoyette Exp $"); #include #include #include #include #include #include #include #include static void h_mbtowc(const char *locale, const char *illegal, const char *legal) { char buf[64]; size_t stateful, ret; char *str; ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); -#if defined(__NetBSD__) +#ifdef __NetBSD__ ATF_REQUIRE(setlocale(LC_CTYPE, locale) != NULL); #else if (setlocale(LC_CTYPE, locale) == NULL) { fprintf(stderr, "Locale %s not found.\n", locale); return; } #endif ATF_REQUIRE((str = setlocale(LC_ALL, NULL)) != NULL); (void)printf("Using locale: %s\n", str); stateful = wctomb(NULL, L'\0'); (void)printf("Locale is state-%sdependent\n", stateful ? "in" : ""); /* initialize internal state */ ret = mbtowc(NULL, NULL, 0); ATF_REQUIRE(stateful ? ret : !ret); (void)strvis(buf, illegal, VIS_WHITE | VIS_OCTAL); (void)printf("Checking illegal sequence: \"%s\"\n", buf); ret = mbtowc(NULL, illegal, strlen(illegal)); (void)printf("mbtowc() returned: %zd\n", ret); ATF_REQUIRE_EQ(ret, (size_t)-1); (void)printf("errno: %s\n", strerror(errno)); ATF_REQUIRE_EQ(errno, EILSEQ); /* if this is stateless encoding, this re-initialization is not required. */ if (stateful) { /* re-initialize internal state */ ret = mbtowc(NULL, NULL, 0); ATF_REQUIRE(stateful ? ret : !ret); } /* valid multibyte sequence case */ (void)strvis(buf, legal, VIS_WHITE | VIS_OCTAL); (void)printf("Checking legal sequence: \"%s\"\n", buf); errno = 0; ret = mbtowc(NULL, legal, strlen(legal)); (void)printf("mbtowc() returned: %zd\n", ret); ATF_REQUIRE(ret != (size_t)-1); (void)printf("errno: %s\n", strerror(errno)); ATF_REQUIRE_EQ(errno, 0); (void)printf("Ok.\n"); } ATF_TC(mbtowc); ATF_TC_HEAD(mbtowc, tc) { atf_tc_set_md_var(tc, "descr", "Checks mbtowc(3)"); } ATF_TC_BODY(mbtowc, tc) { h_mbtowc("en_US.UTF-8", "\240", "\302\240"); h_mbtowc("ja_JP.ISO2022-JP", "\033$B", "\033$B$\"\033(B"); h_mbtowc("ja_JP.SJIS", "\202", "\202\240"); h_mbtowc("ja_JP.eucJP", "\244", "\244\242"); -#if !defined(__FreeBSD__) +#ifndef __FreeBSD__ /* Moved last as it fails */ h_mbtowc("zh_CN.GB18030", "\241", "\241\241"); #endif h_mbtowc("zh_TW.Big5", "\241", "\241@"); h_mbtowc("zh_TW.eucTW", "\241", "\241\241"); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ atf_tc_expect_fail("zh_CN.GB18030"); h_mbtowc("zh_CN.GB18030", "\241", "\241\241"); #endif } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, mbtowc); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/locale/t_wcstod.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/locale/t_wcstod.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/locale/t_wcstod.c (revision 274626) @@ -1,460 +1,460 @@ /* $NetBSD: t_wcstod.c,v 1.3 2011/10/01 17:56:11 christos Exp $ */ /*- * Copyright (c) 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. */ /*- * Copyright (c)2005 Citrus Project, * 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 __COPYRIGHT("@(#) Copyright (c) 2011\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_wcstod.c,v 1.3 2011/10/01 17:56:11 christos Exp $"); #include #include #include #include #include #include -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #endif #define ALT_HUGE_VAL -1 #define ALT_MINUS_HUGE_VAL -2 #define ALT_NAN -3 #if !defined(__vax__) static struct test { const wchar_t *wcs; size_t len; double val; int err; } tests[] = { { L"IN", 0, 0, 0 }, { L"+IN", 0, 0, 0 }, { L"-IN", 0, 0, 0 }, { L"INX", 0, 0, 0 }, { L"+INX", 0, 0, 0 }, { L"-INX", 0, 0, 0 }, { L"INF", 3, ALT_HUGE_VAL, 0 }, { L"+INF", 4, ALT_HUGE_VAL, 0 }, { L"-INF", 4, ALT_MINUS_HUGE_VAL, 0 }, { L"INFX", 3, ALT_HUGE_VAL, 0 }, { L"+INFX", 4, ALT_HUGE_VAL, 0 }, { L"-INFX", 4, ALT_MINUS_HUGE_VAL, 0 }, { L" IN", 0, 0, 0 }, { L" +IN", 0, 0, 0 }, { L" -IN", 0, 0, 0 }, { L" INX", 0, 0, 0 }, { L" +INX", 0, 0, 0 }, { L" -INX", 0, 0, 0 }, { L"+ INF", 0, 0, 0 }, { L"- INF", 0, 0, 0 }, { L" INF", 8, ALT_HUGE_VAL, 0 }, { L" +INF", 9, ALT_HUGE_VAL, 0 }, { L" -INF", 9, ALT_MINUS_HUGE_VAL, 0 }, { L" INFX", 8, ALT_HUGE_VAL, 0 }, { L" +INFX", 9, ALT_HUGE_VAL, 0 }, { L" -INFX", 9, ALT_MINUS_HUGE_VAL, 0 }, { L" INFINIT", 8, ALT_HUGE_VAL, 0 }, { L" +INFINIT", 9, ALT_HUGE_VAL, 0 }, { L" -INFINIT", 9, ALT_MINUS_HUGE_VAL, 0 }, { L" INFINITY", 13, ALT_HUGE_VAL, 0 }, { L" +INFINITY", 14, ALT_HUGE_VAL, 0 }, { L" -INFINITY", 14, ALT_MINUS_HUGE_VAL, 0 }, { L" INFINITYX", 13, ALT_HUGE_VAL, 0 }, { L" +INFINITYX", 14, ALT_HUGE_VAL, 0 }, { L" -INFINITYX", 14, ALT_MINUS_HUGE_VAL, 0 }, /* NAN */ { L"NA", 0, 0, 0 }, { L"+NA", 0, 0, 0 }, { L"-NA", 0, 0, 0 }, { L"NAX", 0, 0, 0 }, { L"+NAX", 0, 0, 0 }, { L"-NAX", 0, 0, 0 }, { L"NAN", 3, ALT_NAN, 0 }, { L"+NAN", 4, ALT_NAN, 0 }, { L"-NAN", 4, ALT_NAN, 0 }, { L"NANX", 3, ALT_NAN, 0 }, { L"+NANX", 4, ALT_NAN, 0 }, { L"-NANX", 4, ALT_NAN, 0 }, { L" NA", 0, 0, 0 }, { L" +NA", 0, 0, 0 }, { L" -NA", 0, 0, 0 }, { L" NAX", 0, 0, 0 }, { L" +NAX", 0, 0, 0 }, { L" -NAX", 0, 0, 0 }, { L"+ NAN", 0, 0, 0 }, { L"- NAN", 0, 0, 0 }, { L" NAN", 8, ALT_NAN, 0 }, { L" +NAN", 9, ALT_NAN, 0 }, { L" -NAN", 9, ALT_NAN, 0 }, { L" NANX", 8, ALT_NAN, 0 }, { L" +NANX", 9, ALT_NAN, 0 }, { L" -NANX", 9, ALT_NAN, 0 }, { L"0", 1, 0, 0 }, { L"+0", 2, 0, 0 }, { L"-0", 2, 0, 0 }, { L" 0", 11, 0, 0 }, { L" +0", 12, 0, 0 }, { L" -0", 12, 0, 0 }, { L"+ 0", 0, 0, 0 }, { L"- 0", 0, 0, 0 }, { L".", 0, 0, 0 }, { L".0", 2, 0, 0 }, { L".00", 3, 0, 0 }, { L".000", 4, 0, 0 }, { L"0.", 2, 0, 0 }, { L"+0.", 3, 0, 0 }, { L"-0.", 3, 0, 0 }, { L" 0.", 12, 0, 0 }, { L" +0.", 13, 0, 0 }, { L" -0.", 13, 0, 0 }, { L"0.0", 3, 0, 0 }, { L"+0.0", 4, 0, 0 }, { L"-0.0", 4, 0, 0 }, { L" 0.0", 13, 0, 0 }, { L" +0.0", 14, 0, 0 }, { L" -0.0", 14, 0, 0 }, { L"000", 3, 0, 0 }, { L"+000", 4, 0, 0 }, { L"-000", 4, 0, 0 }, { L" 000", 13, 0, 0 }, { L" +000", 14, 0, 0 }, { L" -000", 14, 0, 0 }, { L"000.", 4, 0, 0 }, { L"+000.", 5, 0, 0 }, { L"-000.", 5, 0, 0 }, { L" 000.", 14, 0, 0 }, { L" +000.", 15, 0, 0 }, { L" -000.", 15, 0, 0 }, { L"000.0", 5, 0, 0 }, { L"+000.0", 6, 0, 0 }, { L"-000.0", 6, 0, 0 }, { L" 000.0", 15, 0, 0 }, { L" +000.0", 16, 0, 0 }, { L" -000.0", 16, 0, 0 }, { L"0.0.", 3, 0, 0 }, { L"+0.0.", 4, 0, 0 }, { L"-0.0.", 4, 0, 0 }, { L" 0.0.", 13, 0, 0 }, { L" +0.0.", 14, 0, 0 }, { L" -0.0.", 14, 0, 0 }, { L"0.0.0", 3, 0, 0 }, { L"+0.0.0", 4, 0, 0 }, { L"-0.0.0", 4, 0, 0 }, { L" 0.0.0", 13, 0, 0 }, { L" +0.0.0", 14, 0, 0 }, { L" -0.0.0", 14, 0, 0 }, /* XXX: FIXME */ #if defined(__linux__) { L"0X", 2, 0, 0 }, { L"+0X", 3, 0, 0 }, { L"-0X", 3, 0, 0 }, #else { L"0X", 1, 0, 0 }, { L"+0X", 2, 0, 0 }, { L"-0X", 2, 0, 0 }, #endif /* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */ #if !defined(__SunOS__) #if defined(__linux__) { L"0X.", 3, 0, 0 }, { L"+0X.", 4, 0, 0 }, { L"-0X.", 4, 0, 0 }, { L" 0X.", 13, 0, 0 }, { L" +0X.", 14, 0, 0 }, { L" -0X.", 14, 0, 0 }, #else { L"0X.", 1, 0, 0 }, { L"+0X.", 2, 0, 0 }, { L"-0X.", 2, 0, 0 }, { L" 0X.", 11, 0, 0 }, { L" +0X.", 12, 0, 0 }, { L" -0X.", 12, 0, 0 }, #endif /* XXX: FIXME */ #if defined(__NetBSD__) || defined(__linux__) || defined(__FreeBSD__) { L"0X.0", 4, 0, 0 }, { L"+0X.0", 5, 0, 0 }, { L"-0X.0", 5, 0, 0 }, { L" 0X.0", 14, 0, 0 }, { L" +0X.0", 15, 0, 0 }, { L" -0X.0", 15, 0, 0 }, { L"0X.0P", 4, 0, 0 }, { L"+0X.0P", 5, 0, 0 }, { L"-0X.0P", 5, 0, 0 }, { L" 0X.0P", 14, 0, 0 }, { L" +0X.0P", 15, 0, 0 }, { L" -0X.0P", 15, 0, 0 }, #else { L"0X.0", 1, 0, 0 }, { L"+0X.0", 2, 0, 0 }, { L"-0X.0", 2, 0, 0 }, { L" 0X.0", 11, 0, 0 }, { L" +0X.0", 12, 0, 0 }, { L" -0X.0", 12, 0, 0 }, { L"0X.0P", 1, 0, 0 }, { L"+0X.0P", 2, 0, 0 }, { L"-0X.0P", 2, 0, 0 }, { L" 0X.0P", 11, 0, 0 }, { L" +0X.0P", 12, 0, 0 }, { L" -0X.0P", 12, 0, 0 }, #endif { L"0X0", 3, 0, 0 }, { L"+0X0", 4, 0, 0 }, { L"-0X0", 4, 0, 0 }, { L" 0X0", 13, 0, 0 }, { L" +0X0", 14, 0, 0 }, { L" -0X0", 14, 0, 0 }, { L"00X0.0", 2, 0, 0 }, { L"+00X0.0", 3, 0, 0 }, { L"-00X0.0", 3, 0, 0 }, { L" 00X0.0", 12, 0, 0 }, { L" +00X0.0", 13, 0, 0 }, { L" -00X0.0", 13, 0, 0 }, { L"0X0P", 3, 0, 0 }, { L"+0X0P", 4, 0, 0 }, { L"-0X0P", 4, 0, 0 }, { L" 0X0P", 13, 0, 0 }, { L" +0X0P", 14, 0, 0 }, { L" -0X0P", 14, 0, 0 }, { L"0X0.", 4, 0, 0 }, { L"+0X0.", 5, 0, 0 }, { L"-0X0.", 5, 0, 0 }, { L" 0X0.", 14, 0, 0 }, { L" +0X0.", 15, 0, 0 }, { L" -0X0.", 15, 0, 0 }, { L"0X0.0", 5, 0, 0 }, { L"+0X0.0", 6, 0, 0 }, { L"-0X0.0", 6, 0, 0 }, { L" 0X0.0", 15, 0, 0 }, { L" +0X0.0", 16, 0, 0 }, { L" -0X0.0", 16, 0, 0 }, { L"0X0.P", 4, 0, 0 }, { L"+0X0.P", 5, 0, 0 }, { L"-0X0.P", 5, 0, 0 }, { L" 0X0.P", 14, 0, 0 }, { L" +0X0.P", 15, 0, 0 }, { L" -0X0.P", 15, 0, 0 }, { L"0X0.P", 4, 0, 0 }, { L"+0X0.P", 5, 0, 0 }, { L"-0X0.P", 5, 0, 0 }, { L" 0X0.P", 14, 0, 0 }, { L" +0X0.P", 15, 0, 0 }, { L" -0X0.P", 15, 0, 0 }, #endif { L"0.12345678", 10, 0.12345678, 0 }, { L"+0.12345678", 11, +0.12345678, 0 }, { L"-0.12345678", 11, -0.12345678, 0 }, { L" 0.12345678", 15, 0.12345678, 0 }, { L" +0.12345678", 16, +0.12345678, 0 }, { L" -0.12345678", 16, -0.12345678, 0 }, { L"0.12345E67", 10, 0.12345E67, 0 }, { L"+0.12345E67", 11, +0.12345E67, 0 }, { L"-0.12345E67", 11, -0.12345E67, 0 }, { L" 0.12345E67", 15, 0.12345E67, 0 }, { L" +0.12345E67", 16, +0.12345E67, 0 }, { L" -0.12345E67", 16, -0.12345E67, 0 }, { L"0.12345E+6", 10, 0.12345E+6, 0 }, { L"+0.12345E+6", 11, +0.12345E+6, 0 }, { L"-0.12345E+6", 11, -0.12345E+6, 0 }, { L" 0.12345E+6", 15, 0.12345E+6, 0 }, { L" +0.12345E+6", 16, +0.12345E+6, 0 }, { L" -0.12345E+6", 16, -0.12345E+6, 0 }, { L"0.98765E-4", 10, 0.98765E-4, 0 }, { L"+0.98765E-4", 11, +0.98765E-4, 0 }, { L"-0.98765E-4", 11, -0.98765E-4, 0 }, { L" 0.98765E-4", 15, 0.98765E-4, 0 }, { L" +0.98765E-4", 16, +0.98765E-4, 0 }, { L" -0.98765E-4", 16, -0.98765E-4, 0 }, { L"12345678E9", 10, 12345678E9, 0 }, { L"+12345678E9", 11, +12345678E9, 0 }, { L"-12345678E9", 11, -12345678E9, 0 }, { L" 12345678E9", 15, 12345678E9, 0 }, { L" +12345678E9", 16, +12345678E9, 0 }, { L" -12345678E9", 16, -12345678E9, 0 }, /* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */ #if !defined(__SunOS__) { L"0x1P+2", 6, 4, 0 }, { L"+0x1P+2", 7, +4, 0 }, { L"-0x1P+2", 7, -4, 0 }, { L" 0x1P+2", 11, 4, 0 }, { L" +0x1P+2", 12, +4, 0 }, { L" -0x1P+2", 12, -4, 0 }, { L"0x1.0P+2", 8, 4, 0 }, { L"+0x1.0P+2", 9, +4, 0 }, { L"-0x1.0P+2", 9, -4, 0 }, { L" 0x1.0P+2", 13, 4, 0 }, { L" +0x1.0P+2", 14, +4, 0 }, { L" -0x1.0P+2", 14, -4, 0 }, { L"0x1P-2", 6, 0.25, 0 }, { L"+0x1P-2", 7, +0.25, 0 }, { L"-0x1P-2", 7, -0.25, 0 }, { L" 0x1P-2", 11, 0.25, 0 }, { L" +0x1P-2", 12, +0.25, 0 }, { L" -0x1P-2", 12, -0.25, 0 }, { L"0x1.0P-2", 8, 0.25, 0 }, { L"+0x1.0P-2", 9, +0.25, 0 }, { L"-0x1.0P-2", 9, -0.25, 0 }, { L" 0x1.0P-2", 13, 0.25, 0 }, { L" +0x1.0P-2", 14, +0.25, 0 }, { L" -0x1.0P-2", 14, -0.25, 0 }, #endif { NULL, 0, 0, 0 } }; #endif /* !defined(__vax__) */ ATF_TC(wcstod); ATF_TC_HEAD(wcstod, tc) { atf_tc_set_md_var(tc, "descr", "Checks wcstod(3)"); } ATF_TC_BODY(wcstod, tc) { #if defined(__vax__) #else struct test *t; #endif #if !defined(__vax__) for (t = &tests[0]; t->wcs != NULL; ++t) { double d; size_t n; wchar_t *tail; char *buf; /* we do not supported %ls nor %S yet. */ n = wcstombs(NULL, t->wcs, 0); ATF_REQUIRE((buf = (void *)malloc(n + 1)) != NULL); (void)wcstombs(buf, t->wcs, n + 1); (void)printf("Checking wcstod(\"%s\", &tail):\n", buf); free(buf); errno = 0; d = wcstod(t->wcs, &tail); (void)printf("[errno]\n"); (void)printf(" got : %s\n", strerror(errno)); (void)printf(" expected: %s\n", strerror(t->err)); ATF_REQUIRE_EQ(errno, t->err); n = (size_t)(tail - t->wcs); (void)printf("[endptr - nptr]\n"); (void)printf(" got : %zd\n", n); (void)printf(" expected: %zd\n", t->len); ATF_REQUIRE_EQ(n, t->len); (void)printf("[result]\n"); (void)printf(" real: %F\n", d); if (t->val == ALT_HUGE_VAL) { (void)printf(" expected: %F\n", HUGE_VAL); ATF_REQUIRE(isinf(d)); ATF_REQUIRE_EQ(d, HUGE_VAL); } else if (t->val == ALT_MINUS_HUGE_VAL) { (void)printf(" expected: %F\n", -HUGE_VAL); ATF_REQUIRE(isinf(d)); ATF_REQUIRE_EQ(d, -HUGE_VAL); } else if (t->val == ALT_NAN) { (void)printf(" expected: %F\n", NAN); ATF_REQUIRE(isnan(d)); } else { (void)printf(" expected: %F\n", t->val); ATF_REQUIRE_EQ(d, t->val); } (void)printf("\n"); } #else /* !defined(__vax__) */ atf_tc_skip("Test is unavailable on vax."); #endif /* !defined(__vax__) */ } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, wcstod); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/locale/t_wctomb.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/locale/t_wctomb.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/locale/t_wctomb.c (revision 274626) @@ -1,212 +1,212 @@ /* $NetBSD: t_wctomb.c,v 1.3 2013/03/25 15:31:03 gson Exp $ */ /*- * Copyright (c) 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. */ /*- * Copyright (c)2004 Citrus Project, * 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 __COPYRIGHT("@(#) Copyright (c) 2011\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_wctomb.c,v 1.3 2013/03/25 15:31:03 gson Exp $"); #include #include #include #include #include #include #include #include #define TC_WCTOMB 0 #define TC_WCRTOMB 1 #define TC_WCRTOMB_ST 2 static struct test { const char *locale; const char *data; size_t wclen; size_t mblen[16]; } tests[] = { { "ja_JP.ISO2022-JP", "\x1b$B" /* JIS X 0208-1983 */ "\x46\x7c\x4b\x5c\x38\x6c" /* "nihongo" */ "\x1b(B" /* ISO 646 */ "ABC" "\x1b(I" /* JIS X 0201 katakana */ "\xb1\xb2\xb3" /* "aiu" */ "\x1b(B", /* ISO 646 */ 3 + 3 + 3, { 3+2, 2, 2, 3+1, 1, 1, 3+1, 1, 1, 3+1 } }, { "C", "ABC", 3, { 1, 1, 1, 1 } }, { NULL, NULL, 0, { } } }; static void h_wctomb(const struct test *t, char tc) { wchar_t wcs[16 + 2]; char buf[128]; char cs[MB_LEN_MAX]; const char *pcs; char *str; mbstate_t st; mbstate_t *stp = NULL; size_t sz, ret, i; ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); -#if defined(__NetBSD__) +#ifdef __NetBSD__ ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL); #else if (setlocale(LC_CTYPE, t->locale) == NULL) { fprintf(stderr, "Locale %s not found.\n", t->locale); return; } #endif (void)strvis(buf, t->data, VIS_WHITE | VIS_OCTAL); (void)printf("Checking sequence: \"%s\"\n", buf); ATF_REQUIRE((str = setlocale(LC_ALL, NULL)) != NULL); (void)printf("Using locale: %s\n", str); if (tc == TC_WCRTOMB_ST) { (void)memset(&st, 0, sizeof(st)); stp = &st; } wcs[t->wclen] = L'X'; /* poison */ pcs = t->data; sz = mbsrtowcs(wcs, &pcs, t->wclen + 2, NULL); ATF_REQUIRE_EQ_MSG(sz, t->wclen, "mbsrtowcs() returned: " "%zu, expected: %zu", sz, t->wclen); ATF_REQUIRE_EQ(wcs[t->wclen], 0); for (i = 0; i < t->wclen + 1; i++) { if (tc == TC_WCTOMB) ret = wctomb(cs, wcs[i]); else ret = wcrtomb(cs, wcs[i], stp); if (ret == t->mblen[i]) continue; (void)printf("At position %zd:\n", i); (void)printf(" expected: %zd\n", t->mblen[i]); (void)printf(" got : %zd\n", ret); atf_tc_fail("Test failed"); /* NOTREACHED */ } (void)printf("Ok.\n"); } ATF_TC(wctomb); ATF_TC_HEAD(wctomb, tc) { atf_tc_set_md_var(tc, "descr", "Checks wctomb(3)"); } ATF_TC_BODY(wctomb, tc) { struct test *t; (void)printf("Checking wctomb()\n"); for (t = &tests[0]; t->data != NULL; ++t) h_wctomb(t, TC_WCTOMB); } ATF_TC(wcrtomb_state); ATF_TC_HEAD(wcrtomb_state, tc) { atf_tc_set_md_var(tc, "descr", "Checks wcrtomb(3) (using state object)"); } ATF_TC_BODY(wcrtomb_state, tc) { struct test *t; (void)printf("Checking wcrtomb() (with state object)\n"); for (t = &tests[0]; t->data != NULL; ++t) h_wctomb(t, TC_WCRTOMB_ST); } ATF_TC(wcrtomb); ATF_TC_HEAD(wcrtomb, tc) { atf_tc_set_md_var(tc, "descr", "Checks wcrtomb(3) (using internal state)"); } ATF_TC_BODY(wcrtomb, tc) { struct test *t; (void)printf("Checking wcrtomb() (using internal state)\n"); for (t = &tests[0]; t->data != NULL; ++t) h_wctomb(t, TC_WCRTOMB); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, wctomb); ATF_TP_ADD_TC(tp, wcrtomb); ATF_TP_ADD_TC(tp, wcrtomb_state); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/net/t_ether_aton.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/net/t_ether_aton.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/net/t_ether_aton.c (revision 274626) @@ -1,137 +1,137 @@ /* $NetBSD: t_ether_aton.c,v 1.1 2011/11/01 22:36:53 pgoyette Exp $ */ /*- * Copyright (c) 2010 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the NetBSD * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * 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_ether_aton.c,v 1.1 2011/11/01 22:36:53 pgoyette Exp $"); #include #include #include #include #include #include #include -#if !defined(__NetBSD__) -#if defined(__linux__) +#ifndef __NetBSD__ +#ifdef __linux__ #include #endif #include #endif -#if defined(__NetBSD__) +#ifdef __NetBSD__ #define ETHER_ADDR_LEN 6 int ether_aton_r(u_char *dest, size_t len, const char *str); #endif static const struct { u_char res[ETHER_ADDR_LEN]; const char *str; int error; } tests[] = { { { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }, "01:23:45:67:89:ab", 0 }, -#if defined(__NetBSD__) +#ifdef __NetBSD__ { { 0x00, 0x01, 0x22, 0x03, 0x14, 0x05 }, "0:1:22-3:14:05", 0 }, { { 0x00, 0x01, 0x22, 0x03, 0x14, 0x05 }, "000122031405", 0 }, { { 0x0a, 0x0B, 0xcc, 0xdD, 0xEE, 0x0f }, "0a0BccdDEE0f", 0 }, #endif #define ZERO { 0, 0, 0, 0, 0, 0 } { ZERO, "0:1:2-3:04:05:06", ENAMETOOLONG }, { ZERO, "0:1:2-3:04:", ENOBUFS }, { ZERO, "0:1:2-3:04:x7", EINVAL }, { ZERO, "1:x-3:04:05:7", EINVAL }, { ZERO, NULL, 0 }, }; ATF_TC(tc_ether_aton); ATF_TC_HEAD(tc_ether_aton, tc) { atf_tc_set_md_var(tc, "descr", "Check that ether_aton(3) works"); } ATF_TC_BODY(tc_ether_aton, tc) { -#if defined(__NetBSD__) +#ifdef __NetBSD__ u_char dest[ETHER_ADDR_LEN]; #else struct ether_addr dest; #endif size_t t; -#if defined(__NetBSD__) +#ifdef __NetBSD__ int e, r; #else int e; struct ether_addr *r; #endif const char *s; for (t = 0; tests[t].str; t++) { s = tests[t].str; if ((e = tests[t].error) == 0) { -#if defined(__NetBSD__) +#ifdef __NetBSD__ if (ether_aton_r(dest, sizeof(dest), s) != e) atf_tc_fail("failed on `%s'", s); if (memcmp(dest, tests[t].res, sizeof(dest)) != 0) atf_tc_fail("unexpected result on `%s'", s); #else if (ether_aton_r(s, &dest) == NULL && e == 0) atf_tc_fail("failed on `%s'", s); if (memcmp(&dest, tests[t].res, sizeof(dest)) != 0) atf_tc_fail("unexpected result on `%s'", s); #endif } else { -#if defined(__NetBSD__) +#ifdef __NetBSD__ if ((r = ether_aton_r(dest, sizeof(dest), s)) != e) atf_tc_fail("unexpectedly succeeded on `%s' " "(%d != %d)", s, r, e); #else if ((r = ether_aton_r(s, &dest)) != NULL && e != 0) atf_tc_fail("unexpectedly succeeded on `%s' " "(%p != %d)", s, r, e); #endif } } } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, tc_ether_aton); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/regex/debug.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/regex/debug.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/regex/debug.c (revision 274626) @@ -1,278 +1,278 @@ /* $NetBSD: debug.c,v 1.2 2011/10/10 04:32:41 christos Exp $ */ /*- * Copyright (c) 1993 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 -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #include #endif /* Don't sort these! */ #include "utils.h" #include "regex2.h" #include "test_regex.h" static void s_print(struct re_guts *, FILE *); static char *regchar(int); /* * regprint - print a regexp for debugging */ void regprint(regex_t *r, FILE *d) { -#if defined(__NetBSD__) +#ifdef __NetBSD__ struct re_guts *g = r->re_g; int c; int last; int nincat[NC]; fprintf(d, "%ld states, %zu categories", (long)g->nstates, g->ncategories); fprintf(d, ", first %ld last %ld", (long)g->firststate, (long)g->laststate); if (g->iflags&USEBOL) fprintf(d, ", USEBOL"); if (g->iflags&USEEOL) fprintf(d, ", USEEOL"); if (g->iflags&BAD) fprintf(d, ", BAD"); if (g->nsub > 0) fprintf(d, ", nsub=%ld", (long)g->nsub); if (g->must != NULL) fprintf(d, ", must(%ld) `%*s'", (long)g->mlen, (int)g->mlen, g->must); if (g->backrefs) fprintf(d, ", backrefs"); if (g->nplus > 0) fprintf(d, ", nplus %ld", (long)g->nplus); fprintf(d, "\n"); s_print(g, d); for (size_t i = 0; i < g->ncategories; i++) { nincat[i] = 0; for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (g->categories[c] == i) nincat[i]++; } fprintf(d, "cc0#%d", nincat[0]); for (size_t i = 1; i < g->ncategories; i++) if (nincat[i] == 1) { for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (g->categories[c] == i) break; fprintf(d, ", %zu=%s", i, regchar(c)); } fprintf(d, "\n"); for (size_t i = 1; i < g->ncategories; i++) if (nincat[i] != 1) { fprintf(d, "cc%zu\t", i); last = -1; for (c = CHAR_MIN; c <= CHAR_MAX+1; c++) /* +1 does flush */ if (c <= CHAR_MAX && g->categories[c] == i) { if (last < 0) { fprintf(d, "%s", regchar(c)); last = c; } } else { if (last >= 0) { if (last != c-1) fprintf(d, "-%s", regchar(c-1)); last = -1; } } fprintf(d, "\n"); } #endif } /* * s_print - print the strip for debugging */ static void s_print(struct re_guts *g, FILE *d) { sop *s; cset *cs; int done = 0; sop opnd; int col = 0; ssize_t last; sopno offset = 2; # define GAP() { if (offset % 5 == 0) { \ if (col > 40) { \ fprintf(d, "\n\t"); \ col = 0; \ } else { \ fprintf(d, " "); \ col++; \ } \ } else \ col++; \ offset++; \ } if (OP(g->strip[0]) != OEND) fprintf(d, "missing initial OEND!\n"); for (s = &g->strip[1]; !done; s++) { opnd = OPND(*s); switch (OP(*s)) { case OEND: fprintf(d, "\n"); done = 1; break; case OCHAR: if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL) fprintf(d, "\\%c", (char)opnd); else fprintf(d, "%s", regchar((char)opnd)); break; case OBOL: fprintf(d, "^"); break; case OEOL: fprintf(d, "$"); break; case OBOW: fprintf(d, "\\{"); break; case OEOW: fprintf(d, "\\}"); break; case OANY: fprintf(d, "."); break; case OANYOF: fprintf(d, "[(%ld)", (long)opnd); -#if defined(__NetBSD__) +#ifdef __NetBSD__ cs = &g->sets[opnd]; last = -1; for (size_t i = 0; i < g->csetsize+1; i++) /* +1 flushes */ if (CHIN(cs, i) && i < g->csetsize) { if (last < 0) { fprintf(d, "%s", regchar(i)); last = i; } } else { if (last >= 0) { if (last != (ssize_t)i - 1) fprintf(d, "-%s", regchar(i - 1)); last = -1; } } #endif fprintf(d, "]"); break; case OBACK_: fprintf(d, "(\\<%ld>", (long)opnd); break; case O_BACK: fprintf(d, "<%ld>\\)", (long)opnd); break; case OPLUS_: fprintf(d, "(+"); if (OP(*(s+opnd)) != O_PLUS) fprintf(d, "<%ld>", (long)opnd); break; case O_PLUS: if (OP(*(s-opnd)) != OPLUS_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "+)"); break; case OQUEST_: fprintf(d, "(?"); if (OP(*(s+opnd)) != O_QUEST) fprintf(d, "<%ld>", (long)opnd); break; case O_QUEST: if (OP(*(s-opnd)) != OQUEST_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "?)"); break; case OLPAREN: fprintf(d, "((<%ld>", (long)opnd); break; case ORPAREN: fprintf(d, "<%ld>))", (long)opnd); break; case OCH_: fprintf(d, "<"); if (OP(*(s+opnd)) != OOR2) fprintf(d, "<%ld>", (long)opnd); break; case OOR1: if (OP(*(s-opnd)) != OOR1 && OP(*(s-opnd)) != OCH_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "|"); break; case OOR2: fprintf(d, "|"); if (OP(*(s+opnd)) != OOR2 && OP(*(s+opnd)) != O_CH) fprintf(d, "<%ld>", (long)opnd); break; case O_CH: if (OP(*(s-opnd)) != OOR1) fprintf(d, "<%ld>", (long)opnd); fprintf(d, ">"); break; default: -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ fprintf(d, "!%ld(%ld)!", OP(*s), opnd); #else fprintf(d, "!%d(%d)!", OP(*s), opnd); #endif break; } if (!done) GAP(); } } /* * regchar - make a character printable */ static char * /* -> representation */ regchar(int ch) { static char buf[10]; if (isprint(ch) || ch == ' ') sprintf(buf, "%c", ch); else sprintf(buf, "\\%o", ch); return(buf); } Index: head/contrib/netbsd-tests/lib/libc/regex/t_exhaust.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/regex/t_exhaust.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/regex/t_exhaust.c (revision 274626) @@ -1,224 +1,224 @@ /* $NetBSD: t_exhaust.c,v 1.7 2011/11/16 18:37:31 christos Exp $ */ /*- * Copyright (c) 2011 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the NetBSD * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * 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_exhaust.c,v 1.7 2011/11/16 18:37:31 christos Exp $"); #include #include #include #include #include #include -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #endif #ifndef REGEX_MAXSIZE #define REGEX_MAXSIZE 9999 #endif static char * mkstr(const char *str, size_t len) { size_t slen = strlen(str); char *p = malloc(slen * len + 1); ATF_REQUIRE(p != NULL); for (size_t i = 0; i < len; i++) strcpy(&p[i * slen], str); return p; } static char * concat(const char *d, const char *s) { size_t dlen = strlen(d); size_t slen = strlen(s); char *p = malloc(dlen + slen + 1); ATF_REQUIRE(p != NULL); strcpy(p, d); strcpy(p + dlen, s); return p; } static char * p0(size_t len) { char *d, *s1, *s2; s1 = mkstr("\\(", len); s2 = concat(s1, ")"); free(s1); d = concat("(", s2); free(s2); return d; } static char * p1(size_t len) { char *d, *s1, *s2, *s3; s1 = mkstr("\\(", 60); s2 = mkstr("(.*)", len); s3 = concat(s1, s2); free(s2); free(s1); s1 = concat(s3, ")"); free(s3); d = concat("(", s1); free(s1); return d; } static char * ps(const char *m, const char *s, size_t len) { char *d, *s1, *s2, *s3; s1 = mkstr(m, len); s2 = mkstr(s, len); s3 = concat(s1, s2); free(s2); free(s1); d = concat("(.?)", s3); free(s3); return d; } static char * p2(size_t len) { return ps("((.*){0,255}", ")", len); } static char * p3(size_t len) { return ps("(.\\{0,}", ")", len); } static char * p4(size_t len) { return ps("((.*){1,255}", ")", len); } static char * p5(size_t len) { return ps("(", "){1,100}", len); } static char * p6(size_t len) { char *d, *s1, *s2; s1 = mkstr("(?:(.*)|", len); s2 = concat(s1, "(.*)"); free(s1); s1 = mkstr(")", len); d = concat(s2, s1); free(s1); free(s2); return d; } static const struct { char *(*pattern)(size_t); int type; } tests[] = { { p0, REG_EXTENDED }, { p1, REG_EXTENDED }, { p2, REG_EXTENDED }, { p3, REG_EXTENDED }, { p4, REG_EXTENDED }, { p5, REG_EXTENDED }, { p6, REG_BASIC }, }; ATF_TC(regcomp_too_big); ATF_TC_HEAD(regcomp_too_big, tc) { atf_tc_set_md_var(tc, "descr", "Check that large patterns don't" " crash, but return a proper error code"); // libtre needs it. atf_tc_set_md_var(tc, "timeout", "600"); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ atf_tc_set_md_var(tc, "require.memory", "64M"); #else atf_tc_set_md_var(tc, "require.memory", "120M"); #endif } ATF_TC_BODY(regcomp_too_big, tc) { regex_t re; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ struct rlimit limit; #endif int e; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ limit.rlim_cur = limit.rlim_max = 64 * 1024 * 1024; ATF_REQUIRE(setrlimit(RLIMIT_VMEM, &limit) != -1); #endif for (size_t i = 0; i < __arraycount(tests); i++) { char *d = (*tests[i].pattern)(REGEX_MAXSIZE); e = regcomp(&re, d, tests[i].type); if (e) { char ebuf[1024]; (void)regerror(e, &re, ebuf, sizeof(ebuf)); ATF_REQUIRE_MSG(e == REG_ESPACE, "regcomp returned %d (%s) for pattern %zu [%s]", e, ebuf, i, d); free(d); continue; } free(d); (void)regexec(&re, "aaaaaaaaaaa", 0, NULL, 0); regfree(&re); } } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, regcomp_too_big); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/regex/t_regex_att.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/regex/t_regex_att.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/regex/t_regex_att.c (revision 274626) @@ -1,639 +1,639 @@ /* $NetBSD: t_regex_att.c,v 1.1 2012/08/24 20:24:40 jmmv Exp $ */ /*- * Copyright (c) 2011 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the NetBSD * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * 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_regex_att.c,v 1.1 2012/08/24 20:24:40 jmmv Exp $"); #include #include #include #include #include #include #include #include -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #endif static const char sep[] = "\r\n\t"; static const char delim[3] = "\\\\\0"; static void fail(const char *pattern, const char *input, size_t lineno) { fprintf(stderr, "skipping failed test at line %zu (pattern=%s, input=%s)\n", lineno, pattern, input); } static int bug(const char *pattern, const char *input, size_t lineno) { static const struct { const char *p; const char *i; } b[] = { #if defined(REGEX_SPENCER) /* * The default libc implementation by Henry Spencer */ { "a[-]?c", "ac" }, // basic.dat { "(a*)*", "a" }, // categorization.dat { "(aba|a*b)*", "ababa" }, // categorization.dat { "\\(a\\(b\\)*\\)*\\2", "abab" }, // categorization.dat { "(a*)*", "aaaaaa" }, // nullsubexpression.dat { "(a*)*", "aaaaaax" }, // nullsubexpression.dat { "(a*)+", "a" }, // nullsubexpression.dat { "(a*)+", "aaaaaa" }, // nullsubexpression.dat { "(a*)+", "aaaaaax" }, // nullsubexpression.dat { "([a]*)*", "a" }, // nullsubexpression.dat { "([a]*)*", "aaaaaa" }, // nullsubexpression.dat { "([a]*)*", "aaaaaax" }, // nullsubexpression.dat { "([a]*)+", "a" }, // nullsubexpression.dat { "([a]*)+", "aaaaaa" }, // nullsubexpression.dat { "([a]*)+", "aaaaaax" }, // nullsubexpression.dat { "([^b]*)*", "a" }, // nullsubexpression.dat { "([^b]*)*", "aaaaaa" }, // nullsubexpression.dat { "([^b]*)*", "aaaaaab" }, // nullsubexpression.dat { "([ab]*)*", "a" }, // nullsubexpression.dat { "([ab]*)*", "aaaaaa" }, // nullsubexpression.dat { "([ab]*)*", "ababab" }, // nullsubexpression.dat { "([ab]*)*", "bababa" }, // nullsubexpression.dat { "([ab]*)*", "b" }, // nullsubexpression.dat { "([ab]*)*", "bbbbbb" }, // nullsubexpression.dat { "([ab]*)*", "aaaabcde" }, // nullsubexpression.dat { "([^a]*)*", "b" }, // nullsubexpression.dat { "([^a]*)*", "bbbbbb" }, // nullsubexpression.dat { "([^ab]*)*", "ccccxx" }, // nullsubexpression.dat { "\\(a*\\)*\\(x\\)", "ax" }, // nullsubexpression.dat { "\\(a*\\)*\\(x\\)", "axa" }, // nullsubexpression.dat { "\\(a*\\)*\\(x\\)\\(\\1\\)", "x" }, // nullsubexpression.dat /* crash! */ { "\\(a*\\)*\\(x\\)\\(\\1\\)", "ax" }, // nullsubexpression.dat /* crash! */ { "\\(a*\\)*\\(x\\)\\(\\1\\)\\(x\\)", "axxa" }, // "" { "(a*)*(x)", "ax" }, // nullsubexpression.dat { "(a*)*(x)", "axa" }, // nullsubexpression.dat { "(a*)+(x)", "ax" }, // nullsubexpression.dat { "(a*)+(x)", "axa" }, // nullsubexpression.dat { "((a|ab)(c|bcd))(d*)", "abcd" }, // forcedassoc.dat { "((a|ab)(bcd|c))(d*)", "abcd" }, // forcedassoc.dat { "((ab|a)(c|bcd))(d*)", "abcd" }, // forcedassoc.dat { "((ab|a)(bcd|c))(d*)", "abcd" }, // forcedassoc.dat { "((a*)(b|abc))(c*)", "abc" }, // forcedassoc.dat { "((a*)(abc|b))(c*)", "abc" }, // forcedassoc.dat { "((..)|(.)){2}", "aaa" }, // repetition.dat { "((..)|(.)){3}", "aaa" }, // repetition.dat { "((..)|(.)){3}", "aaaa" }, // repetition.dat { "((..)|(.)){3}", "aaaaa" }, // repetition.dat { "X(.?){0,}Y", "X1234567Y" }, // repetition.dat { "X(.?){1,}Y", "X1234567Y" }, // repetition.dat { "X(.?){2,}Y", "X1234567Y" }, // repetition.dat { "X(.?){3,}Y", "X1234567Y" }, // repetition.dat { "X(.?){4,}Y", "X1234567Y" }, // repetition.dat { "X(.?){5,}Y", "X1234567Y" }, // repetition.dat { "X(.?){6,}Y", "X1234567Y" }, // repetition.dat { "X(.?){7,}Y", "X1234567Y" }, // repetition.dat { "X(.?){0,8}Y", "X1234567Y" }, // repetition.dat { "X(.?){1,8}Y", "X1234567Y" }, // repetition.dat { "X(.?){2,8}Y", "X1234567Y" }, // repetition.dat { "X(.?){3,8}Y", "X1234567Y" }, // repetition.dat { "X(.?){4,8}Y", "X1234567Y" }, // repetition.dat { "X(.?){5,8}Y", "X1234567Y" }, // repetition.dat { "X(.?){6,8}Y", "X1234567Y" }, // repetition.dat { "X(.?){7,8}Y", "X1234567Y" }, // repetition.dat { "(a|ab|c|bcd){0,}(d*)", "ababcd" }, // repetition.dat { "(a|ab|c|bcd){1,}(d*)", "ababcd" }, // repetition.dat { "(a|ab|c|bcd){2,}(d*)", "ababcd" }, // repetition.dat { "(a|ab|c|bcd){3,}(d*)", "ababcd" }, // repetition.dat { "(a|ab|c|bcd){1,10}(d*)", "ababcd" }, // repetition.dat { "(a|ab|c|bcd){2,10}(d*)", "ababcd" }, // repetition.dat { "(a|ab|c|bcd){3,10}(d*)", "ababcd" }, // repetition.dat { "(a|ab|c|bcd)*(d*)", "ababcd" }, // repetition.dat { "(a|ab|c|bcd)+(d*)", "ababcd" }, // repetition.dat { "(ab|a|c|bcd){0,}(d*)", "ababcd" }, // repetition.dat { "(ab|a|c|bcd){1,}(d*)", "ababcd" }, // repetition.dat { "(ab|a|c|bcd){2,}(d*)", "ababcd" }, // repetition.dat { "(ab|a|c|bcd){3,}(d*)", "ababcd" }, // repetition.dat { "(ab|a|c|bcd){1,10}(d*)", "ababcd" }, // repetition.dat { "(ab|a|c|bcd){2,10}(d*)", "ababcd" }, // repetition.dat { "(ab|a|c|bcd){3,10}(d*)", "ababcd" }, // repetition.dat { "(ab|a|c|bcd)*(d*)", "ababcd" }, // repetition.dat { "(ab|a|c|bcd)+(d*)", "ababcd" }, // repetition.dat #elif defined(REGEX_TRE) { "a[-]?c", "ac" }, // basic.dat { "a\\(b\\)*\\1", "a" }, // categorization.dat { "a\\(b\\)*\\1", "abab" }, // categorization.dat { "\\(a\\(b\\)*\\)*\\2", "abab" }, // categorization.dat { "\\(a*\\)*\\(x\\)\\(\\1\\)", "ax" }, // categorization.dat { "\\(a*\\)*\\(x\\)\\(\\1\\)\\(x\\)", "axxa" }, // "" { "((..)|(.))*", "aa" }, // repetition.dat { "((..)|(.))*", "aaa" }, // repetition.dat { "((..)|(.))*", "aaaaa" }, // repetition.dat { "X(.?){7,}Y", "X1234567Y" }, // repetition.dat #else { "", "" } #endif }; for (size_t i = 0; i < __arraycount(b); i++) { if (strcmp(pattern, b[i].p) == 0 && strcmp(input, b[i].i) == 0) { fail(pattern, input, lineno); return 1; } } return 0; } #ifdef REGEX_SPENCER #define HAVE_BRACES 1 #define HAVE_MINIMAL 0 #endif #ifndef HAVE_BRACES #define HAVE_BRACES 1 #endif #ifndef HAVE_MINIMAL #define HAVE_MINIMAL 1 #endif static int optional(const char *s) { static const struct{ const char *n; int v; } nv[]= { { "[[]] not supported", HAVE_BRACES }, { "no *? +? mimimal match ops", HAVE_MINIMAL }, }; for (size_t i = 0; i < __arraycount(nv); i++) if (strcmp(nv[i].n, s) == 0) { if (nv[i].v) return 0; fprintf(stderr, "skipping unsupported [%s] tests\n", s); return 1; } ATF_REQUIRE_MSG(0, "Unknown feature: %s", s); return 0; } static int unsupported(const char *s) { static const char *we[] = { #if defined(REGEX_SPENCER) "ASSOCIATIVITY=left", // have right associativity "SUBEXPRESSION=precedence", // have grouping subexpression "REPEAT_LONGEST=last", // have first repeat longest "BUG=alternation-order", // don't have it "BUG=first-match", // don't have it "BUG=nomatch-match", // don't have it "BUG=repeat-any", // don't have it "BUG=range-null", // don't have it "BUG=repeat-null-unknown", // don't have it "BUG=repeat-null", // don't have it "BUG=repeat-artifact", // don't have it "BUG=subexpression-first", // don't have it #elif defined(REGEX_TRE) "ASSOCIATIVITY=right", // have left associativity "SUBEXPRESSION=grouping", // have precedence subexpression "REPEAT_LONGEST=first", // have last repeat longest "LENGTH=first", // have last length "BUG=alternation-order", // don't have it "BUG=first-match", // don't have it "BUG=range-null", // don't have it "BUG=repeat-null", // don't have it "BUG=repeat-artifact", // don't have it "BUG=subexpression-first", // don't have it "BUG=repeat-short", // don't have it #endif }; if (s == NULL) return 0; while (*s == '#' || isspace((unsigned char)*s)) s++; for (size_t i = 0; i < __arraycount(we); i++) if (strcmp(we[i], s) == 0) return 1; return 0; } static void geterror(const char *s, int *comp, int *exec) { static const struct { const char *n; int v; int ce; } nv[] = { #define COMP 1 #define EXEC 2 { "OK", 0, COMP|EXEC }, #define _DO(a, b) { # a, REG_ ## a, b }, _DO(NOMATCH, EXEC) _DO(BADPAT, COMP) _DO(ECOLLATE, COMP) _DO(ECTYPE, COMP) _DO(EESCAPE, COMP) _DO(ESUBREG, COMP) _DO(EBRACK, COMP) _DO(EPAREN, COMP) _DO(EBRACE, COMP) _DO(BADBR, COMP) _DO(ERANGE, COMP) _DO(ESPACE, EXEC) _DO(BADRPT, COMP) _DO(EMPTY, COMP) _DO(ASSERT, COMP) _DO(INVARG, COMP) _DO(ENOSYS, COMP) #undef _DO }; *comp = 0; *exec = 0; for (size_t i = 0; i < __arraycount(nv); i++) if (strcmp(s, nv[i].n) == 0) { if (nv[i].ce & COMP) *comp = nv[i].v; if (nv[i].ce & EXEC) *exec = nv[i].v; return; } ATF_REQUIRE_MSG(0, "Unknown error %s", s); return; } static int getflags(char *s) { int flags = 0; for (;; s++) switch (*s) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': *s = '\0'; break; case '\0': return flags; case 'B': case 'E': case 'F': case 'L': break; case 'i': flags |= REG_ICASE; *s = '\0'; break; case '$': *s = '\0'; break; case 'n': *s = '\0'; break; default: ATF_REQUIRE_MSG(0, "Unknown char %c", *s); break; } } static size_t getmatches(const char *s) { size_t i; char *q; for (i = 0; (q = strchr(s, '(')) != NULL; i++, s = q + 1) continue; ATF_REQUIRE_MSG(i != 0, "No parentheses found"); return i; } static void checkcomment(const char *s, size_t lineno) { if (s && strstr(s, "BUG") != NULL) fprintf(stderr, "Expected %s at line %zu\n", s, lineno); } static void checkmatches(const char *matches, size_t nm, const regmatch_t *pm, size_t lineno) { if (nm == 0) return; char *res; size_t len = strlen(matches) + 1, off = 0; ATF_REQUIRE((res = strdup(matches)) != NULL); for (size_t i = 0; i < nm; i++) { int l; if (pm[i].rm_so == -1 && pm[i].rm_eo == -1) l = snprintf(res + off, len - off, "(?,?)"); else l = snprintf(res + off, len - off, "(%lld,%lld)", (long long)pm[i].rm_so, (long long)pm[i].rm_eo); ATF_REQUIRE_MSG((size_t) l < len - off, "String too long %s" " cur=%d, max=%zu", res, l, len - off); off += l; } -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ ATF_CHECK_STREQ_MSG(res, matches, " at line %zu", lineno); #else ATF_REQUIRE_STREQ_MSG(res, matches, " at line %zu", lineno); #endif free(res); } static void att_test(const struct atf_tc *tc, const char *data_name) { regex_t re; char *line, *lastpattern = NULL, data_path[MAXPATHLEN]; size_t len, lineno = 0; int skipping = 0; FILE *input_file; snprintf(data_path, sizeof(data_path), "%s/data/%s.dat", atf_tc_get_config_var(tc, "srcdir"), data_name); input_file = fopen(data_path, "r"); if (input_file == NULL) atf_tc_fail("Failed to open input file %s", data_path); for (; (line = fparseln(input_file, &len, &lineno, delim, 0)) != NULL; free(line)) { char *name, *pattern, *input, *matches, *comment; regmatch_t *pm; size_t nm; #ifdef DEBUG fprintf(stderr, "[%s]\n", line); #endif if ((name = strtok(line, sep)) == NULL) continue; /* * We check these early so that we skip the lines quickly * in order to do more strict testing on the other arguments * The same characters are also tested in the switch below */ if (*name == '}') { skipping = 0; continue; } if (skipping) continue; if (*name == ';' || *name == '#' || strcmp(name, "NOTE") == 0) continue; if (*name == ':') { /* Skip ":HA#???:" prefix */ while (*++name && *name != ':') continue; if (*name) name++; } ATF_REQUIRE_MSG((pattern = strtok(NULL, sep)) != NULL, "Missing pattern at line %zu", lineno); ATF_REQUIRE_MSG((input = strtok(NULL, sep)) != NULL, "Missing input at line %zu", lineno); if (strchr(name, '$')) { ATF_REQUIRE(strunvis(pattern, pattern) != -1); ATF_REQUIRE(strunvis(input, input) != -1); } if (strcmp(input, "NULL") == 0) *input = '\0'; if (strcmp(pattern, "SAME") == 0) { ATF_REQUIRE(lastpattern != NULL); pattern = lastpattern; } else { free(lastpattern); ATF_REQUIRE((lastpattern = strdup(pattern)) != NULL); } ATF_REQUIRE_MSG((matches = strtok(NULL, sep)) != NULL, "Missing matches at line %zu", lineno); comment = strtok(NULL, sep); switch (*name) { case '{': /* Begin optional implementation */ if (optional(comment)) { skipping++; continue; } name++; /* We have it, so ignore */ break; case '}': /* End optional implementation */ skipping = 0; continue; case '?': /* Optional */ case '|': /* Alternative */ if (unsupported(comment)) continue; name++; /* We have it, so ignore */ break; case '#': /* Comment */ case ';': /* Skip */ continue; default: break; } /* XXX: Our bug */ if (bug(pattern, input, lineno)) continue; int comp, exec; if (*matches != '(') { geterror(matches, &comp, &exec); pm = NULL; nm = 0; } else { comp = exec = 0; nm = getmatches(matches); ATF_REQUIRE((pm = calloc(nm, sizeof(*pm))) != NULL); } int iflags = getflags(name); for (; *name; name++) { int flags; switch (*name) { case 'B': flags = REG_BASIC; break; case 'E': flags = REG_EXTENDED; break; case 'L': flags = REG_NOSPEC; break; default: ATF_REQUIRE_MSG(0, "Bad name %c", *name); continue; } int c = regcomp(&re, pattern, flags | iflags); ATF_REQUIRE_MSG(c == comp, "regcomp returned %d for pattern %s at line %zu", c, pattern, lineno); if (c) continue; int e = regexec(&re, input, nm, pm, 0); ATF_REQUIRE_MSG(e == exec, "Expected error %d," " got %d at line %zu", exec, e, lineno); checkmatches(matches, nm, pm, lineno); checkcomment(comment, lineno); regfree(&re); } free(pm); } fclose(input_file); } ATF_TC(basic); ATF_TC_HEAD(basic, tc) { atf_tc_set_md_var(tc, "descr", "Tests basic functionality"); } ATF_TC_BODY(basic, tc) { att_test(tc, "basic"); } ATF_TC(categorization); ATF_TC_HEAD(categorization, tc) { atf_tc_set_md_var(tc, "descr", "Tests implementation categorization"); } ATF_TC_BODY(categorization, tc) { att_test(tc, "categorization"); } ATF_TC(nullsubexpr); ATF_TC_HEAD(nullsubexpr, tc) { atf_tc_set_md_var(tc, "descr", "Tests (...)*"); } ATF_TC_BODY(nullsubexpr, tc) { att_test(tc, "nullsubexpr"); } ATF_TC(leftassoc); ATF_TC_HEAD(leftassoc, tc) { atf_tc_set_md_var(tc, "descr", "Tests left-associative " "implementations"); } ATF_TC_BODY(leftassoc, tc) { #if SKIP_LEFTASSOC /* jmmv: I converted the original shell-based tests to C and they * disabled this test in a very unconventional way without giving * any explation. Mark as broken here, but I don't know why. */ atf_tc_expect_fail("Reason for breakage unknown"); #endif -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ atf_tc_expect_fail("The expected and matched groups are mismatched on FreeBSD"); #endif att_test(tc, "leftassoc"); } ATF_TC(rightassoc); ATF_TC_HEAD(rightassoc, tc) { atf_tc_set_md_var(tc, "descr", "Tests right-associative " "implementations"); } ATF_TC_BODY(rightassoc, tc) { #if SKIP_RIGHTASSOC /* jmmv: I converted the original shell-based tests to C and they * disabled this test in a very unconventional way without giving * any explation. Mark as broken here, but I don't know why. */ atf_tc_expect_fail("Reason for breakage unknown"); #endif att_test(tc, "rightassoc"); } ATF_TC(forcedassoc); ATF_TC_HEAD(forcedassoc, tc) { atf_tc_set_md_var(tc, "descr", "Tests subexpression grouping to " "force association"); } ATF_TC_BODY(forcedassoc, tc) { att_test(tc, "forcedassoc"); } ATF_TC(repetition); ATF_TC_HEAD(repetition, tc) { atf_tc_set_md_var(tc, "descr", "Tests implicit vs. explicit " "repetition"); } ATF_TC_BODY(repetition, tc) { att_test(tc, "repetition"); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, basic); ATF_TP_ADD_TC(tp, categorization); ATF_TP_ADD_TC(tp, nullsubexpr); ATF_TP_ADD_TC(tp, leftassoc); ATF_TP_ADD_TC(tp, rightassoc); ATF_TP_ADD_TC(tp, forcedassoc); ATF_TP_ADD_TC(tp, repetition); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/stdlib/h_atexit.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/stdlib/h_atexit.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/stdlib/h_atexit.c (revision 274626) @@ -1,212 +1,212 @@ /* $NetBSD: h_atexit.c,v 1.1 2011/01/12 19:44:08 pgoyette Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code was contributed to The NetBSD Foundation by Jason R. Thorpe. * * 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 __COPYRIGHT("@(#) Copyright (c) 2011\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: h_atexit.c,v 1.1 2011/01/12 19:44:08 pgoyette Exp $"); #include #include #include #include #include extern int __cxa_atexit(void (*func)(void *), void *, void *); extern void __cxa_finalize(void *); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ /* * On shared object unload, in __cxa_finalize, call and clear all installed * atexit and __cxa_atexit handlers that are either installed by unloaded * dso, or points to the functions provided by the dso. * * The reason of the change is to ensure that there is no lingering pointers * to the unloaded code after the dlclose(3). It is known reason for infinite * stream of the crash reports for many programs which use loadable modules * and fail to properly clean on module unload. Examples are apache, php, * perl etc. * * You pass the &dso_handle_1 and &dso_handle_2, which points inside the * main binary, to the registration function. The code from r211706, * correctly detects that they are for the main binary, and on the first * call to __cxa_finalize(), which also pass pointer to main binary, all * registered functions from the main binary are executed. */ static void *dso_handle_1 = (void *)1; static void *dso_handle_2 = (void *)2; static void *dso_handle_3 = (void *)3; #else static int dso_handle_1; static int dso_handle_2; static int dso_handle_3; #endif static int arg_1; static int arg_2; static int arg_3; static int exiting_state; #define ASSERT(expr) \ do { \ if ((expr) == 0) { \ write(STDERR_FILENO, __func__, strlen(__func__)); \ write(STDERR_FILENO, ": ", 2); \ write(STDERR_FILENO, __STRING(expr), \ strlen(__STRING(expr))); \ write(STDERR_FILENO, "\n", 1); \ my_abort(); \ } \ } while (/*CONSTCOND*/0) #define SUCCESS() \ do { \ write(STDOUT_FILENO, __func__, strlen(__func__)); \ write(STDOUT_FILENO, "\n", 1); \ } while (/*CONSTCOND*/0) static void my_abort(void) { kill(getpid(), SIGABRT); /* NOTREACHED */ } static void cxa_handler_5(void *arg) { static int cxa_handler_5_called; ASSERT(arg == (void *)&arg_1); ASSERT(cxa_handler_5_called == 0); ASSERT(exiting_state == 5); exiting_state--; cxa_handler_5_called = 1; SUCCESS(); } static void cxa_handler_4(void *arg) { static int cxa_handler_4_called; ASSERT(arg == (void *)&arg_1); ASSERT(cxa_handler_4_called == 0); ASSERT(exiting_state == 4); exiting_state--; cxa_handler_4_called = 1; SUCCESS(); } static void cxa_handler_3(void *arg) { static int cxa_handler_3_called; ASSERT(arg == (void *)&arg_2); ASSERT(cxa_handler_3_called == 0); ASSERT(exiting_state == 3); exiting_state--; cxa_handler_3_called = 1; SUCCESS(); } static void cxa_handler_2(void *arg) { static int cxa_handler_2_called; ASSERT(arg == (void *)&arg_3); ASSERT(cxa_handler_2_called == 0); ASSERT(exiting_state == 2); exiting_state--; cxa_handler_2_called = 1; SUCCESS(); } static void normal_handler_1(void) { static int normal_handler_1_called; ASSERT(normal_handler_1_called == 0); ASSERT(exiting_state == 1); exiting_state--; normal_handler_1_called = 1; SUCCESS(); } static void normal_handler_0(void) { static int normal_handler_0_called; ASSERT(normal_handler_0_called == 0); ASSERT(exiting_state == 0); normal_handler_0_called = 1; SUCCESS(); } int main(int argc, char *argv[]) { exiting_state = 5; ASSERT(0 == atexit(normal_handler_0)); ASSERT(0 == atexit(normal_handler_1)); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ ASSERT(0 == __cxa_atexit(cxa_handler_4, &arg_1, dso_handle_1)); ASSERT(0 == __cxa_atexit(cxa_handler_5, &arg_1, dso_handle_1)); ASSERT(0 == __cxa_atexit(cxa_handler_3, &arg_2, dso_handle_2)); ASSERT(0 == __cxa_atexit(cxa_handler_2, &arg_3, dso_handle_3)); __cxa_finalize(dso_handle_1); __cxa_finalize(dso_handle_2); #else ASSERT(0 == __cxa_atexit(cxa_handler_4, &arg_1, &dso_handle_1)); ASSERT(0 == __cxa_atexit(cxa_handler_5, &arg_1, &dso_handle_1)); ASSERT(0 == __cxa_atexit(cxa_handler_3, &arg_2, &dso_handle_2)); ASSERT(0 == __cxa_atexit(cxa_handler_2, &arg_3, &dso_handle_3)); __cxa_finalize(&dso_handle_1); __cxa_finalize(&dso_handle_2); #endif exit(0); } Index: head/contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c (revision 274626) @@ -1,130 +1,130 @@ /* $NetBSD: h_getopt.c,v 1.1 2011/01/01 23:56:49 pgoyette Exp $ */ /*- * Copyright (c) 2002 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 #include #include #include #include -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #endif #define WS "\t\n " #define debug 0 int main(int argc, char *argv[]) { size_t len, lineno = 0; char *line, *ptr, *optstring = NULL, *result = NULL; char buf[1024]; char *args[100]; char arg[100]; int nargs = -1; int c; while ((line = fparseln(stdin, &len, &lineno, NULL, 0)) != NULL) { if (strncmp(line, "load:", 5) == 0) { if (optstring) free(optstring); optstring = strtok(&line[6], WS); if (optstring == NULL) errx(1, "missing optstring at line %ld", (unsigned long)lineno); optstring = strdup(optstring); if (debug) fprintf(stderr, "optstring = %s\n", optstring); } else if (strncmp(line, "args:", 5) == 0) { for (; nargs >= 0; nargs--) { if (args[nargs] != NULL) free(args[nargs]); } args[nargs = 0] = strtok(&line[6], WS); if (args[nargs] == NULL) errx(1, "missing args at line %ld", (unsigned long)lineno); args[nargs] = strdup(args[nargs]); while ((args[++nargs] = strtok(NULL, WS)) != NULL) args[nargs] = strdup(args[nargs]); if (debug) { int i = 0; for (i = 0; i < nargs; i++) fprintf(stderr, "argv[%d] = %s\n", i, args[i]); } } else if (strncmp(line, "result:", 7) == 0) { buf[0] = '\0'; optind = optreset = 1; if (result) free(result); result = strtok(&line[8], WS); if (result == NULL) errx(1, "missing result at line %ld", (unsigned long)lineno); result = strdup(result); if (nargs == -1) errx(1, "result: without args:"); if (debug) fprintf(stderr, "result = %s\n", result); while ((c = getopt(nargs, args, optstring)) != -1) { if (c == ':') err(1, "`:' found as argument char"); if ((ptr = strchr(optstring, c)) == NULL) { snprintf(arg, sizeof(arg), "!%c,", c); strcat(buf, arg); continue; } if (ptr[1] != ':') snprintf(arg, sizeof(arg), "%c,", c); else snprintf(arg, sizeof(arg), "%c=%s,", c, optarg); strcat(buf, arg); } len = strlen(buf); if (len > 0) { buf[len - 1] = '|'; buf[len] = '\0'; } else { buf[0] = '|'; buf[1] = '\0'; } snprintf(arg, sizeof(arg), "%d", nargs - optind); strcat(buf, arg); if (strcmp(buf, result) != 0) errx(1, "`%s' != `%s'", buf, result); } free(line); } return 0; } Index: head/contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c (revision 274626) @@ -1,242 +1,242 @@ /* $NetBSD: h_getopt_long.c,v 1.1 2011/01/01 23:56:49 pgoyette Exp $ */ /*- * Copyright (c) 2007 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 #include #include #include #include #include #include -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #endif #define SKIPWS(p) while (isspace((int)(*p))) p++ #define WS "\t\n " int main(int argc, char *argv[]) { size_t len, lineno = 0; char *line, *eptr, *longopt, *ptr, *optstring = NULL, *result = NULL; char buf[1024]; char *args[128]; char arg[256]; int nargs = -1; int c; int nlongopts = 0; int maxnlongopts = 0; int *longopt_flags = NULL; struct option *longopts = NULL; while ((line = fparseln(stdin, &len, &lineno, NULL, 0)) != NULL) { if (strncmp(line, "optstring:", 10) == 0) { if (optstring) free(optstring); optstring = strtok(&line[11], WS); if (optstring == NULL) errx(1, "missing optstring at line %ld", (unsigned long)lineno); optstring = strdup(optstring); } else if (strncmp(line, "longopts:", 9) == 0) { if (longopts) { int i; for (i = 0; i < nlongopts; i++) if (longopts[i].name != NULL) free(__UNCONST(longopts[i].name)); free(longopts); } if (longopt_flags) free(longopt_flags); nlongopts = 0; ptr = strtok(&line[10], WS); if (ptr == NULL) errx(1, "missing longopts at line %ld", (unsigned long)lineno); maxnlongopts = strtoul(ptr, &eptr, 10); if (*eptr != '\0') warnx("garbage in longopts at line %ld", (unsigned long)lineno); maxnlongopts++; /* space for trailer */ longopts = (struct option *)calloc(sizeof(struct option), maxnlongopts); if (longopts == NULL) err(1, "calloc"); longopt_flags = (int *)calloc(sizeof(int), maxnlongopts); if (longopt_flags == NULL) err(1, "calloc"); } else if (strncmp(line, "longopt:", 8) == 0) { if (longopts == NULL) errx(1, "longopt: without longopts at line %ld", (unsigned long)lineno); if (nlongopts >= maxnlongopts) errx(1, "longopt: too many options at line %ld", (unsigned long)lineno); /* name */ ptr = &line[9]; SKIPWS(ptr); longopt = strsep(&ptr, ","); if (longopt == NULL) errx(1, "missing longopt at line %ld", (unsigned long)lineno); longopts[nlongopts].name = strdup(longopt); /* has_arg */ SKIPWS(ptr); longopt = strsep(&ptr, ","); if (*longopt != '\0') { if (strncmp(longopt, "0", 1) == 0 || strncmp(longopt, "no_argument", 2) == 0) longopts[nlongopts].has_arg = no_argument; else if (strncmp(longopt, "1", 1) == 0 || strncmp(longopt, "required_argument", 8) == 0) longopts[nlongopts].has_arg = required_argument; else if (strncmp(longopt, "2", 1) == 0 || strncmp(longopt, "optional_argument", 8) == 0) longopts[nlongopts].has_arg = optional_argument; else errx(1, "unknown has_arg %s at line %ld", longopt, (unsigned long)lineno); } /* flag */ SKIPWS(ptr); longopt = strsep(&ptr, ","); if (*longopt != '\0' && strncmp(longopt, "NULL", 4) != 0) longopts[nlongopts].flag = &longopt_flags[nlongopts]; /* val */ SKIPWS(ptr); longopt = strsep(&ptr, ","); if (*longopt == '\0') errx(1, "missing val at line %ld", (unsigned long)lineno); if (*longopt != '\'') { longopts[nlongopts].val = (int)strtoul(longopt, &eptr, 10); if (*eptr != '\0') errx(1, "invalid val at line %ld", (unsigned long)lineno); } else longopts[nlongopts].val = (int)longopt[1]; nlongopts++; } else if (strncmp(line, "args:", 5) == 0) { for (; nargs >= 0; nargs--) { if (args[nargs] != NULL) free(args[nargs]); } args[nargs = 0] = strtok(&line[6], WS); if (args[nargs] == NULL) errx(1, "Missing args"); args[nargs] = strdup(args[nargs]); while ((args[++nargs] = strtok(NULL, WS)) != NULL) args[nargs] = strdup(args[nargs]); } else if (strncmp(line, "result:", 7) == 0) { int li; buf[0] = '\0'; optind = optreset = 1; if (result) free(result); result = strtok(&line[8], WS); if (result == NULL) errx(1, "missing result at line %ld", (unsigned long)lineno); if (optstring == NULL) errx(1, "result: without optstring"); if (longopts == NULL || nlongopts == 0) errx(1, "result: without longopts"); result = strdup(result); if (nargs == -1) errx(1, "result: without args"); li = -2; while ((c = getopt_long(nargs, args, optstring, longopts, &li)) != -1) { if (c == ':') errx(1, "`:' found as argument char"); if (li == -2) { ptr = strchr(optstring, c); if (ptr == NULL) { snprintf(arg, sizeof(arg), "!%c,", c); strcat(buf, arg); continue; } if (ptr[1] != ':') snprintf(arg, sizeof(arg), "%c,", c); else snprintf(arg, sizeof(arg), "%c=%s,", c, optarg); } else { switch (longopts[li].has_arg) { case no_argument: snprintf(arg, sizeof(arg), "-%s,", longopts[li].name); break; case required_argument: snprintf(arg, sizeof(arg), "-%s=%s,", longopts[li].name, optarg); break; case optional_argument: snprintf(arg, sizeof(arg), "-%s%s%s,", longopts[li].name, (optarg)? "=" : "", (optarg)? optarg : ""); break; default: errx(1, "internal error"); } } strcat(buf, arg); li = -2; } len = strlen(buf); if (len > 0) { buf[len - 1] = '|'; buf[len] = '\0'; } else { buf[0] = '|'; buf[1] = '\0'; } snprintf(arg, sizeof(arg), "%d", nargs - optind); strcat(buf, arg); if (strcmp(buf, result) != 0) errx(1, "`%s' != `%s'", buf, result); } else errx(1, "unknown directive at line %ld", (unsigned long)lineno); free(line); } return 0; } Index: head/contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c (revision 274626) @@ -1,211 +1,211 @@ /* $NetBSD: t_getenv.c,v 1.2 2011/07/15 13:54:31 jruoho Exp $ */ /*- * Copyright (c) 2010 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 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_getenv.c,v 1.2 2011/07/15 13:54:31 jruoho Exp $"); #include #include #include #include #include -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #endif extern char **environ; ATF_TC(clearenv_basic); ATF_TC_HEAD(clearenv_basic, tc) { atf_tc_set_md_var(tc, "descr", "Test user clearing environment directly"); } ATF_TC_BODY(clearenv_basic, tc) { char name[1024], value[1024]; for (size_t i = 0; i < 1024; i++) { snprintf(name, sizeof(name), "crap%zu", i); snprintf(value, sizeof(value), "%zu", i); ATF_CHECK(setenv(name, value, 1) != -1); } *environ = NULL; for (size_t i = 0; i < 1; i++) { snprintf(name, sizeof(name), "crap%zu", i); snprintf(value, sizeof(value), "%zu", i); ATF_CHECK(setenv(name, value, 1) != -1); } ATF_CHECK_STREQ(getenv("crap0"), "0"); ATF_CHECK(getenv("crap1") == NULL); ATF_CHECK(getenv("crap2") == NULL); } ATF_TC(getenv_basic); ATF_TC_HEAD(getenv_basic, tc) { atf_tc_set_md_var(tc, "descr", "Test setenv(3), getenv(3)"); } ATF_TC_BODY(getenv_basic, tc) { ATF_CHECK(setenv("EVIL", "very=bad", 1) != -1); ATF_CHECK_STREQ(getenv("EVIL"), "very=bad"); ATF_CHECK(getenv("EVIL=very") == NULL); ATF_CHECK(unsetenv("EVIL") != -1); } ATF_TC(putenv_basic); ATF_TC_HEAD(putenv_basic, tc) { atf_tc_set_md_var(tc, "descr", "Test putenv(3), getenv(3), unsetenv(3)"); } ATF_TC_BODY(putenv_basic, tc) { char string[1024]; snprintf(string, sizeof(string), "crap=true"); ATF_CHECK(putenv(string) != -1); ATF_CHECK_STREQ(getenv("crap"), "true"); string[1] = 'l'; ATF_CHECK_STREQ(getenv("clap"), "true"); ATF_CHECK(getenv("crap") == NULL); string[1] = 'r'; ATF_CHECK(unsetenv("crap") != -1); ATF_CHECK(getenv("crap") == NULL); ATF_CHECK_ERRNO(EINVAL, putenv(NULL) == -1); ATF_CHECK_ERRNO(EINVAL, putenv(__UNCONST("val")) == -1); ATF_CHECK_ERRNO(EINVAL, putenv(__UNCONST("=val")) == -1); } ATF_TC(setenv_basic); ATF_TC_HEAD(setenv_basic, tc) { atf_tc_set_md_var(tc, "descr", "Test setenv(3), getenv(3), unsetenv(3)"); atf_tc_set_md_var(tc, "timeout", "300"); } ATF_TC_BODY(setenv_basic, tc) { const size_t numvars = 8192; size_t i, offset; char name[1024]; char value[1024]; offset = lrand48(); for (i = 0; i < numvars; i++) { (void)snprintf(name, sizeof(name), "var%zu", (i * 7 + offset) % numvars); (void)snprintf(value, sizeof(value), "value%ld", lrand48()); ATF_CHECK(setenv(name, value, 1) != -1); ATF_CHECK(setenv(name, "foo", 0) != -1); ATF_CHECK_STREQ(getenv(name), value); } offset = lrand48(); for (i = 0; i < numvars; i++) { (void)snprintf(name, sizeof(name), "var%zu", (i * 11 + offset) % numvars); ATF_CHECK(unsetenv(name) != -1); ATF_CHECK(getenv(name) == NULL); ATF_CHECK(unsetenv(name) != -1); } ATF_CHECK_ERRNO(EINVAL, setenv(NULL, "val", 1) == -1); ATF_CHECK_ERRNO(EINVAL, setenv("", "val", 1) == -1); ATF_CHECK_ERRNO(EINVAL, setenv("v=r", "val", 1) == -1); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ /* Both FreeBSD and OS/X does not validate the second argument to setenv(3) */ atf_tc_expect_signal(SIGSEGV, "FreeBSD does not validate the second " "argument to setenv(3); see bin/189805"); #endif ATF_CHECK_ERRNO(EINVAL, setenv("var", NULL, 1) == -1); ATF_CHECK(setenv("var", "=val", 1) == 0); ATF_CHECK_STREQ(getenv("var"), "=val"); } ATF_TC(setenv_mixed); ATF_TC_HEAD(setenv_mixed, tc) { atf_tc_set_md_var(tc, "descr", "Test mixing setenv(3), unsetenv(3) and putenv(3)"); } ATF_TC_BODY(setenv_mixed, tc) { char string[32]; (void)strcpy(string, "mixedcrap=putenv"); ATF_CHECK(setenv("mixedcrap", "setenv", 1) != -1); ATF_CHECK_STREQ(getenv("mixedcrap"), "setenv"); ATF_CHECK(putenv(string) != -1); ATF_CHECK_STREQ(getenv("mixedcrap"), "putenv"); ATF_CHECK(unsetenv("mixedcrap") != -1); ATF_CHECK(getenv("mixedcrap") == NULL); ATF_CHECK(putenv(string) != -1); ATF_CHECK_STREQ(getenv("mixedcrap"), "putenv"); ATF_CHECK(setenv("mixedcrap", "setenv", 1) != -1); ATF_CHECK_STREQ(getenv("mixedcrap"), "setenv"); ATF_CHECK(unsetenv("mixedcrap") != -1); ATF_CHECK(getenv("mixedcrap") == NULL); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, clearenv_basic); ATF_TP_ADD_TC(tp, getenv_basic); ATF_TP_ADD_TC(tp, putenv_basic); ATF_TP_ADD_TC(tp, setenv_basic); ATF_TP_ADD_TC(tp, setenv_mixed); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/stdlib/t_hsearch.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/stdlib/t_hsearch.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/stdlib/t_hsearch.c (revision 274626) @@ -1,407 +1,407 @@ /* $NetBSD: t_hsearch.c,v 1.4 2014/07/20 20:17:21 christos Exp $ */ /*- * Copyright (c) 2008 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. */ /* * Copyright (c) 2001 Christopher G. Demetriou * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed for the * NetBSD Project. See http://www.NetBSD.org/ for * information about NetBSD. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_hsearch.c,v 1.4 2014/07/20 20:17:21 christos Exp $"); #include #include #include #include #include #include #define REQUIRE_ERRNO(x) ATF_REQUIRE_MSG(x, "%s", strerror(errno)) -#if defined(__NetBSD__) +#ifdef __NetBSD__ ATF_TC(hsearch_basic); ATF_TC_HEAD(hsearch_basic, tc) { atf_tc_set_md_var(tc, "descr", "Checks basic insertions and searching"); } ATF_TC_BODY(hsearch_basic, tc) { ENTRY e, *ep; char ch[2]; int i; REQUIRE_ERRNO(hcreate(16) != 0); /* ch[1] should be constant from here on down. */ ch[1] = '\0'; /* Basic insertions. Check enough that there'll be collisions. */ for (i = 0; i < 26; i++) { ch[0] = 'a' + i; e.key = strdup(ch); /* ptr to provided key is kept! */ ATF_REQUIRE(e.key != NULL); e.data = (void *)(intptr_t)i; ep = hsearch(e, ENTER); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, ch); ATF_REQUIRE_EQ((intptr_t)ep->data, i); } /* e.key should be constant from here on down. */ e.key = ch; /* Basic lookups. */ for (i = 0; i < 26; i++) { ch[0] = 'a' + i; ep = hsearch(e, FIND); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, ch); ATF_REQUIRE_EQ((intptr_t)ep->data, i); } hdestroy1(free, NULL); } #endif ATF_TC(hsearch_duplicate); ATF_TC_HEAD(hsearch_duplicate, tc) { atf_tc_set_md_var(tc, "descr", "Checks that inserting duplicate " "doesn't overwrite existing data"); } ATF_TC_BODY(hsearch_duplicate, tc) { ENTRY e, *ep; REQUIRE_ERRNO(hcreate(16)); e.key = __UNCONST("a"); e.data = (void *)(intptr_t) 0; ep = hsearch(e, ENTER); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, "a"); ATF_REQUIRE_EQ((intptr_t)ep->data, 0); e.data = (void *)(intptr_t)12345; ep = hsearch(e, ENTER); ep = hsearch(e, FIND); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, "a"); ATF_REQUIRE_EQ((intptr_t)ep->data, 0); hdestroy(); } ATF_TC(hsearch_nonexistent); ATF_TC_HEAD(hsearch_nonexistent, tc) { atf_tc_set_md_var(tc, "descr", "Checks searching for non-existent entry"); } ATF_TC_BODY(hsearch_nonexistent, tc) { ENTRY e, *ep; REQUIRE_ERRNO(hcreate(16)); e.key = __UNCONST("A"); ep = hsearch(e, FIND); ATF_REQUIRE_EQ(ep, NULL); hdestroy(); } ATF_TC(hsearch_two); ATF_TC_HEAD(hsearch_two, tc) { atf_tc_set_md_var(tc, "descr", "Checks that searching doesn't overwrite previous search results"); } ATF_TC_BODY(hsearch_two, tc) { ENTRY e, *ep, *ep2; REQUIRE_ERRNO(hcreate(16)); e.key = __UNCONST("a"); e.data = (void*)(intptr_t)0; ep = hsearch(e, ENTER); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, "a"); ATF_REQUIRE_EQ((intptr_t)ep->data, 0); e.key = __UNCONST("b"); e.data = (void*)(intptr_t)1; ep = hsearch(e, ENTER); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, "b"); ATF_REQUIRE_EQ((intptr_t)ep->data, 1); e.key = __UNCONST("a"); ep = hsearch(e, FIND); e.key = __UNCONST("b"); ep2 = hsearch(e, FIND); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, "a"); ATF_REQUIRE_EQ((intptr_t)ep->data, 0); ATF_REQUIRE(ep2 != NULL); ATF_REQUIRE_STREQ(ep2->key, "b"); ATF_REQUIRE_EQ((intptr_t)ep2->data, 1); hdestroy(); } -#if defined(__NetBSD__) +#ifdef __NetBSD__ ATF_TC(hsearch_r_basic); ATF_TC_HEAD(hsearch_r_basic, tc) { atf_tc_set_md_var(tc, "descr", "Checks basic insertions and searching"); } ATF_TC_BODY(hsearch_r_basic, tc) { ENTRY e, *ep; char ch[2]; int i; struct hsearch_data t; REQUIRE_ERRNO(hcreate_r(16, &t) != 0); /* ch[1] should be constant from here on down. */ ch[1] = '\0'; /* Basic insertions. Check enough that there'll be collisions. */ for (i = 0; i < 26; i++) { ch[0] = 'a' + i; e.key = strdup(ch); /* ptr to provided key is kept! */ ATF_REQUIRE(e.key != NULL); e.data = (void *)(intptr_t)i; ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, ch); ATF_REQUIRE_EQ((intptr_t)ep->data, i); } /* e.key should be constant from here on down. */ e.key = ch; /* Basic lookups. */ for (i = 0; i < 26; i++) { ch[0] = 'a' + i; ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, ch); ATF_REQUIRE_EQ((intptr_t)ep->data, i); } hdestroy1_r(&t, free, NULL); } #endif ATF_TC(hsearch_r_duplicate); ATF_TC_HEAD(hsearch_r_duplicate, tc) { atf_tc_set_md_var(tc, "descr", "Checks that inserting duplicate " "doesn't overwrite existing data"); } ATF_TC_BODY(hsearch_r_duplicate, tc) { ENTRY e, *ep; struct hsearch_data t; REQUIRE_ERRNO(hcreate_r(16, &t)); e.key = __UNCONST("a"); e.data = (void *)(intptr_t) 0; ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, "a"); ATF_REQUIRE_EQ((intptr_t)ep->data, 0); e.data = (void *)(intptr_t)12345; ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1); ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, "a"); ATF_REQUIRE_EQ((intptr_t)ep->data, 0); hdestroy_r(&t); } ATF_TC(hsearch_r_nonexistent); ATF_TC_HEAD(hsearch_r_nonexistent, tc) { atf_tc_set_md_var(tc, "descr", "Checks searching for non-existent entry"); } ATF_TC_BODY(hsearch_r_nonexistent, tc) { ENTRY e, *ep; struct hsearch_data t; REQUIRE_ERRNO(hcreate_r(16, &t)); e.key = __UNCONST("A"); ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1); ATF_REQUIRE_EQ(ep, NULL); hdestroy_r(&t); } ATF_TC(hsearch_r_two); ATF_TC_HEAD(hsearch_r_two, tc) { atf_tc_set_md_var(tc, "descr", "Checks that searching doesn't overwrite previous search results"); } ATF_TC_BODY(hsearch_r_two, tc) { ENTRY e, *ep, *ep2; struct hsearch_data t; REQUIRE_ERRNO(hcreate_r(16, &t)); e.key = __UNCONST("a"); e.data = (void*)(intptr_t)0; ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, "a"); ATF_REQUIRE_EQ((intptr_t)ep->data, 0); e.key = __UNCONST("b"); e.data = (void*)(intptr_t)1; ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, "b"); ATF_REQUIRE_EQ((intptr_t)ep->data, 1); e.key = __UNCONST("a"); ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1); e.key = __UNCONST("b"); ATF_REQUIRE(hsearch_r(e, FIND, &ep2, &t) == 1); ATF_REQUIRE(ep != NULL); ATF_REQUIRE_STREQ(ep->key, "a"); ATF_REQUIRE_EQ((intptr_t)ep->data, 0); ATF_REQUIRE(ep2 != NULL); ATF_REQUIRE_STREQ(ep2->key, "b"); ATF_REQUIRE_EQ((intptr_t)ep2->data, 1); hdestroy_r(&t); } ATF_TP_ADD_TCS(tp) { -#if defined(__NetBSD__) +#ifdef __NetBSD__ ATF_TP_ADD_TC(tp, hsearch_basic); #endif ATF_TP_ADD_TC(tp, hsearch_duplicate); ATF_TP_ADD_TC(tp, hsearch_nonexistent); ATF_TP_ADD_TC(tp, hsearch_two); -#if defined(__NetBSD__) +#ifdef __NetBSD__ ATF_TP_ADD_TC(tp, hsearch_r_basic); #endif ATF_TP_ADD_TC(tp, hsearch_r_duplicate); ATF_TP_ADD_TC(tp, hsearch_r_nonexistent); ATF_TP_ADD_TC(tp, hsearch_r_two); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/string/t_memcpy.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/string/t_memcpy.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/string/t_memcpy.c (revision 274626) @@ -1,162 +1,162 @@ /* $NetBSD: t_memcpy.c,v 1.5 2013/03/17 02:23:31 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 #define ALIGNMENTS 16 #define LENGTHS 4 #define BLOCKTYPES 4 MD5_CTX mc[1]; typedef unsigned char testBlock_t[ALIGNMENTS * LENGTHS]; testBlock_t bss1, bss2; unsigned char *start[BLOCKTYPES] = { bss1, bss2 }; char result[100]; -#if defined(__NetBSD__) +#ifdef __NetBSD__ const char goodResult[] = "7b405d24bc03195474c70ddae9e1f8fb"; #else const char goodResult[] = "217b4fbe456916bf62a2f85df752e4ab"; #endif static void runTest(unsigned char *b1, unsigned char *b2) { int i, j, k, m; size_t n; for (i = 0; i < ALIGNMENTS; ++i) { for (j = 0; j < ALIGNMENTS; ++j) { k = sizeof(testBlock_t) - (i > j ? i : j); for (m = 0; m < k; ++m) { for (n = 0; n < sizeof(testBlock_t); ++n) { b1[n] = (unsigned char)random(); b2[n] = (unsigned char)random(); } memcpy(b1 + i, b2 + j, m); MD5Update(mc, b1, sizeof(testBlock_t)); MD5Update(mc, b2, sizeof(testBlock_t)); } } } } ATF_TC(memcpy_basic); ATF_TC_HEAD(memcpy_basic, tc) { atf_tc_set_md_var(tc, "descr", "Test memcpy results"); } ATF_TC_BODY(memcpy_basic, tc) { int i, j; testBlock_t auto1, auto2; start[2] = auto1; start[3] = auto2; -#if defined(__NetBSD__) +#ifdef __NetBSD__ srandom(0L); #else /* * random() shall produce by default a sequence of numbers that can be * duplicated by calling srandom() with 1 as the seed. */ srandom(1); #endif MD5Init(mc); for (i = 0; i < BLOCKTYPES; ++i) for (j = 0; j < BLOCKTYPES; ++j) if (i != j) runTest(start[i], start[j]); MD5End(mc, result); ATF_REQUIRE_EQ(strcmp(result, goodResult), 0); } ATF_TC(memccpy_simple); ATF_TC_HEAD(memccpy_simple, tc) { atf_tc_set_md_var(tc, "descr", "Test memccpy(3) results"); } ATF_TC_BODY(memccpy_simple, tc) { char buf[100]; char c = ' '; (void)memset(buf, c, sizeof(buf)); ATF_CHECK(memccpy(buf, "foo bar", c, sizeof(buf)) != NULL); ATF_CHECK(buf[4] == c); ATF_CHECK(memccpy(buf, "foo bar", '\0', sizeof(buf) - 1) != NULL); ATF_CHECK(buf[8] == c); ATF_CHECK(memccpy(buf, "foo bar", 'x', 7) == NULL); ATF_CHECK(strncmp(buf, "foo bar", 7) == 0); ATF_CHECK(memccpy(buf, "xxxxxxx", 'r', 7) == NULL); ATF_CHECK(strncmp(buf, "xxxxxxx", 7) == 0); } ATF_TC(memcpy_return); ATF_TC_HEAD(memcpy_return, tc) { atf_tc_set_md_var(tc, "descr", "Test memcpy(3) return value"); } ATF_TC_BODY(memcpy_return, tc) { char *b = (char *)0x1; char c[2]; ATF_REQUIRE_EQ(memcpy(b, b, 0), b); ATF_REQUIRE_EQ(memcpy(c, "ab", sizeof(c)), c); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, memcpy_basic); ATF_TP_ADD_TC(tp, memcpy_return); ATF_TP_ADD_TC(tp, memccpy_simple); 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 274625) +++ head/contrib/netbsd-tests/lib/libc/string/t_strerror.c (revision 274626) @@ -1,139 +1,139 @@ /* $NetBSD: t_strerror.c,v 1.3 2011/05/10 06:55:27 jruoho 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 $"); #include #include #include #include #include -#if defined(__FreeBSD__) +#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 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_access.c (revision 274626) @@ -1,214 +1,214 @@ /* $NetBSD: t_access.c,v 1.1 2011/07/07 06:57:53 jruoho 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 $"); #include #include #include #include #include #include #include -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #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) { 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_clock_gettime.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_clock_gettime.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_clock_gettime.c (revision 274626) @@ -1,220 +1,220 @@ /* $NetBSD: t_clock_gettime.c,v 1.1 2011/10/15 06:42:16 jruoho Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Frank Kardel. * * 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) 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. */ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_clock_gettime.c,v 1.1 2011/10/15 06:42:16 jruoho Exp $"); #include #include -#if defined(__NetBSD__) +#ifdef __NetBSD__ #include #endif #include #include #include #include #include #include #include -#if defined(__NetBSD__) +#ifdef __NetBSD__ #include "../../../h_macros.h" #else #include #include #include "h_macros.h" #endif #define MINPOSDIFF 15000000 /* 15 ms for now */ #define TIMEOUT 5 #define TC_HARDWARE "kern.timecounter.hardware" #define TC_CHOICE "kern.timecounter.choice" static void check_timecounter(void) { struct timespec tsa, tsb, tsl, res; long long mindiff = INTMAX_MAX; time_t endlimit; #define CL(x) \ do { \ if ((x) != -1) \ break; \ atf_tc_fail_nonfatal("%s: %s", #x, strerror(errno)); \ return; \ } while (0) CL(clock_gettime(CLOCK_REALTIME, &tsa)); tsl = tsa; CL(time(&endlimit)); endlimit += TIMEOUT + 1; while ((time_t)tsa.tv_sec < endlimit) { long long diff; CL(clock_gettime(CLOCK_REALTIME, &tsb)); diff = 1000000000LL * (tsb.tv_sec - tsa.tv_sec) + tsb.tv_nsec - tsa.tv_nsec; if (diff > 0 && mindiff > diff) mindiff = diff; if (diff < 0 || diff > MINPOSDIFF) { long long elapsed; (void)printf("%stime TSA: 0x%jx.%08jx, TSB: 0x%jx.%08jx, " "diff = %lld nsec, ", (diff < 0) ? "BAD " : "", (uintmax_t)tsa.tv_sec, (uintmax_t)tsa.tv_nsec, (uintmax_t)tsb.tv_sec, (uintmax_t)tsb.tv_nsec, diff); elapsed = 1000000000LL * (tsb.tv_sec - tsl.tv_sec) + tsb.tv_nsec - tsl.tv_nsec; (void)printf("%lld nsec\n", elapsed); tsl = tsb; ATF_CHECK(diff >= 0); if (diff < 0) return; } tsa.tv_sec = tsb.tv_sec; tsa.tv_nsec = tsb.tv_nsec; } if (clock_getres(CLOCK_REALTIME, &res) == 0) { long long r = res.tv_sec * 1000000000 + res.tv_nsec; (void)printf("Claimed resolution: %lld nsec (%f Hz) or " "better\n", r, 1.0 / r * 1e9); (void)printf("Observed minimum non zero delta: %lld " "nsec\n", mindiff); } #undef CL } ATF_TC(clock_gettime_real); ATF_TC_HEAD(clock_gettime_real, tc) { atf_tc_set_md_var(tc, "require.user", "root"); atf_tc_set_md_var(tc, "descr", "Checks the monotonicity of the CLOCK_REALTIME implementation"); atf_tc_set_md_var(tc, "timeout", "300"); } ATF_TC_BODY(clock_gettime_real, tc) { char name[128], cbuf[512], ctrbuf[10240]; size_t cbufsiz = sizeof(cbuf); size_t ctrbufsiz = sizeof(ctrbuf); const char *p; char *save; int quality, n; if (sysctlbyname(TC_HARDWARE, cbuf, &cbufsiz, NULL, 0) != 0) { (void)printf("\nChecking legacy time implementation " "for %d seconds\n", TIMEOUT); check_timecounter(); return; /* NOTREACHED */ } (void)printf("%s = %s\n", TC_HARDWARE, cbuf); REQUIRE_LIBC(save = strdup(cbuf), NULL); RL(sysctlbyname(TC_CHOICE, ctrbuf, &ctrbufsiz, NULL, 0)); (void)printf("%s = %s\n", TC_CHOICE, ctrbuf); for (p = ctrbuf, n = 0; sscanf(p, "%127[^(](q=%d, f=%*u Hz)%*[ ]%n", name, &quality, &n) == 2; p += n) { struct timespec ts; int ret; if (quality < 0) continue; (void)printf("\nChecking %s for %d seconds\n", name, TIMEOUT); CHECK_LIBC(ret = sysctlbyname(TC_HARDWARE, NULL, 0, name, strlen(name)), -1); if (ret == -1) continue; /* wait a bit to select new counter in clockinterrupt */ ts.tv_sec = 0; ts.tv_nsec = 100000000; (void)nanosleep(&ts, NULL); check_timecounter(); } RL(sysctlbyname(TC_HARDWARE, NULL, 0, save, strlen(save))); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, clock_gettime_real); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_getgroups.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_getgroups.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_getgroups.c (revision 274626) @@ -1,174 +1,174 @@ /* $NetBSD: t_getgroups.c,v 1.1 2011/07/07 06:57:53 jruoho 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_getgroups.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $"); #include #include #include #include #include #include #include ATF_TC(getgroups_err); ATF_TC_HEAD(getgroups_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors in getgroups(2)"); } ATF_TC_BODY(getgroups_err, tc) { gid_t gidset[NGROUPS_MAX]; errno = 0; ATF_REQUIRE(getgroups(10, (gid_t *)-1) == -1); ATF_REQUIRE(errno == EFAULT); errno = 0; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ atf_tc_expect_fail("Reported as kern/189941"); #endif ATF_REQUIRE(getgroups(-1, gidset) == -1); ATF_REQUIRE(errno == EINVAL); } ATF_TC(getgroups_getgid); ATF_TC_HEAD(getgroups_getgid, tc) { atf_tc_set_md_var(tc, "descr", "Test getgid(2) from getgroups(2)"); } ATF_TC_BODY(getgroups_getgid, tc) { gid_t gidset[NGROUPS_MAX]; gid_t gid = getgid(); int i, n; /* * Check that getgid(2) is found from * the GIDs returned by getgroups(2). */ n = getgroups(NGROUPS_MAX, gidset); for (i = 0; i < n; i++) { if (gidset[i] == gid) return; } atf_tc_fail("getgid(2) not found from getgroups(2)"); } ATF_TC(getgroups_setgid); ATF_TC_HEAD(getgroups_setgid, tc) { atf_tc_set_md_var(tc, "descr", "Test setgid(2) from getgroups(2)"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(getgroups_setgid, tc) { gid_t gidset[NGROUPS_MAX]; int i, n, rv, sta; pid_t pid; /* * Check that we can setgid(2) * to the returned group IDs. */ n = getgroups(NGROUPS_MAX, gidset); ATF_REQUIRE(n >= 0); for (i = 0; i < n; i++) { pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { rv = setgid(gidset[i]); if (rv != 0) _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); } (void)wait(&sta); if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) atf_tc_fail("getgroups(2) is inconsistent"); } } ATF_TC(getgroups_zero); ATF_TC_HEAD(getgroups_zero, tc) { atf_tc_set_md_var(tc, "descr", "Test getgroups(2) with zero param"); } ATF_TC_BODY(getgroups_zero, tc) { const gid_t val = 123456789; gid_t gidset[NGROUPS_MAX]; size_t i; /* * If the first parameter is zero, the number * of groups should be returned but the supplied * buffer should remain intact. */ for (i = 0; i < __arraycount(gidset); i++) gidset[i] = val; ATF_REQUIRE(getgroups(0, gidset) >= 0); for (i = 0; i < __arraycount(gidset); i++) { if (gidset[i] != val) atf_tc_fail("getgroups(2) modified the buffer"); } } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, getgroups_err); ATF_TP_ADD_TC(tp, getgroups_getgid); ATF_TP_ADD_TC(tp, getgroups_setgid); ATF_TP_ADD_TC(tp, getgroups_zero); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_getrusage.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_getrusage.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_getrusage.c (revision 274626) @@ -1,210 +1,210 @@ /* $NetBSD: t_getrusage.c,v 1.3 2014/09/03 19:24:12 matt 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_getrusage.c,v 1.3 2014/09/03 19:24:12 matt Exp $"); #include #include #include #include #include #include #include #include static void work(void); static void sighandler(int); static const size_t maxiter = 2000; static void -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ sighandler(int signo __unused) #else sighandler(int signo) #endif { /* Nothing. */ } static void work(void) { size_t n = UINT16_MAX * 10; while (n > 0) { #ifdef __or1k__ asm volatile("l.nop"); /* Do something. */ #else asm volatile("nop"); /* Do something. */ #endif n--; } } ATF_TC(getrusage_err); ATF_TC_HEAD(getrusage_err, tc) { atf_tc_set_md_var(tc, "descr", "Test error conditions"); } ATF_TC_BODY(getrusage_err, tc) { struct rusage ru; errno = 0; ATF_REQUIRE(getrusage(INT_MAX, &ru) != 0); ATF_REQUIRE(errno == EINVAL); errno = 0; ATF_REQUIRE(getrusage(RUSAGE_SELF, (void *)0) != 0); ATF_REQUIRE(errno == EFAULT); } ATF_TC(getrusage_sig); ATF_TC_HEAD(getrusage_sig, tc) { atf_tc_set_md_var(tc, "descr", "Test signal count with getrusage(2)"); } ATF_TC_BODY(getrusage_sig, tc) { struct rusage ru; const long n = 5; int i; /* * Test that signals are recorded. */ ATF_REQUIRE(signal(SIGUSR1, sighandler) != SIG_ERR); for (i = 0; i < n; i++) ATF_REQUIRE(raise(SIGUSR1) == 0); (void)memset(&ru, 0, sizeof(struct rusage)); ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0); if (n != ru.ru_nsignals) atf_tc_fail("getrusage(2) did not record signals"); } ATF_TC(getrusage_utime_back); ATF_TC_HEAD(getrusage_utime_back, tc) { atf_tc_set_md_var(tc, "descr", "Test bogus values from getrusage(2)"); } ATF_TC_BODY(getrusage_utime_back, tc) { struct rusage ru1, ru2; size_t i; /* * Test that two consecutive calls are sane. */ #ifdef __NetBSD__ atf_tc_expect_fail("PR kern/30115"); #endif for (i = 0; i < maxiter; i++) { (void)memset(&ru1, 0, sizeof(struct rusage)); (void)memset(&ru2, 0, sizeof(struct rusage)); work(); ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru1) == 0); work(); ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru2) == 0); if (timercmp(&ru2.ru_utime, &ru1.ru_utime, <) != 0) atf_tc_fail("user time went backwards"); } #ifdef __NetBSD__ atf_tc_fail("anticipated error did not occur"); #endif } ATF_TC(getrusage_utime_zero); ATF_TC_HEAD(getrusage_utime_zero, tc) { atf_tc_set_md_var(tc, "descr", "Test zero utime from getrusage(2)"); } ATF_TC_BODY(getrusage_utime_zero, tc) { struct rusage ru; size_t i; #ifdef __FreeBSD__ atf_tc_skip("this testcase passes/fails sporadically on FreeBSD/i386 " "@ r273153 (at least)"); #endif /* * Test that getrusage(2) does not return * zero user time for the calling process. * * See also (duplicate) PR port-amd64/41734. */ atf_tc_expect_fail("PR kern/30115"); for (i = 0; i < maxiter; i++) { work(); (void)memset(&ru, 0, sizeof(struct rusage)); ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0); if (ru.ru_utime.tv_sec == 0 && ru.ru_utime.tv_usec == 0) atf_tc_fail("zero user time from getrusage(2)"); } atf_tc_fail("anticipated error did not occur"); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, getrusage_err); ATF_TP_ADD_TC(tp, getrusage_sig); ATF_TP_ADD_TC(tp, getrusage_utime_back); ATF_TP_ADD_TC(tp, getrusage_utime_zero); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_kevent.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_kevent.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_kevent.c (revision 274626) @@ -1,206 +1,206 @@ /* $NetBSD: t_kevent.c,v 1.6 2012/11/29 09:13:44 martin Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundatiom * 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_kevent.c,v 1.6 2012/11/29 09:13:44 martin Exp $"); #include #include #include #include #include #include #include #include #include #include #include #ifdef __NetBSD__ #include #endif #include #include #include #include #ifdef __FreeBSD__ #define DRVCTLDEV "/nonexistent" #endif ATF_TC(kevent_zerotimer); ATF_TC_HEAD(kevent_zerotimer, tc) { atf_tc_set_md_var(tc, "descr", "Checks that kevent with a 0 timer " "does not crash the system (PR lib/45618)"); } ATF_TC_BODY(kevent_zerotimer, tc) { struct kevent ev; int kq; ATF_REQUIRE((kq = kqueue()) != -1); EV_SET(&ev, 1, EVFILT_TIMER, EV_ADD|EV_ENABLE, 0, 1, 0); ATF_REQUIRE(kevent(kq, &ev, 1, NULL, 0, NULL) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, &ev, 1, NULL) == 1); } ATF_TC(kqueue_desc_passing); ATF_TC_HEAD(kqueue_desc_passing, tc) { atf_tc_set_md_var(tc, "descr", "Checks that passing a kqueue to " "another process does not crash the kernel (PR 46463)"); } ATF_TC_BODY(kqueue_desc_passing, tc) { pid_t child; int s[2], storage, status, kq; struct cmsghdr *msg; struct iovec iov; struct msghdr m; struct kevent ev; ATF_REQUIRE((kq = kqueue()) != -1); // atf_tc_skip("crashes kernel (PR 46463)"); ATF_REQUIRE(socketpair(AF_LOCAL, SOCK_STREAM, 0, s) != -1); msg = malloc(CMSG_SPACE(sizeof(int))); m.msg_iov = &iov; m.msg_iovlen = 1; m.msg_name = NULL; m.msg_namelen = 0; m.msg_control = msg; m.msg_controllen = CMSG_SPACE(sizeof(int)); child = fork(); if (child == 0) { close(s[0]); iov.iov_base = &storage; iov.iov_len = sizeof(int); m.msg_iov = &iov; m.msg_iovlen = 1; if (recvmsg(s[1], &m, 0) == -1) err(1, "child: could not recvmsg"); #ifdef __FreeBSD__ bcopy(CMSG_DATA(msg), &kq, sizeof(kq)); printf("child (pid %d): received kq fd %d\n", getpid(), kq); _exit(0); #else kq = *(int *)CMSG_DATA(msg); printf("child (pid %d): received kq fd %d\n", getpid(), kq); exit(0); #endif } close(s[1]); iov.iov_base = &storage; iov.iov_len = sizeof(int); msg->cmsg_level = SOL_SOCKET; msg->cmsg_type = SCM_RIGHTS; msg->cmsg_len = CMSG_LEN(sizeof(int)); #ifdef __FreeBSD__ /* * What is should have been * bcopy(&s[0], CMSG_DATA(msg), sizeof(kq)); */ bcopy(&kq, CMSG_DATA(msg), sizeof(kq)); #else *(int *)CMSG_DATA(msg) = kq; #endif EV_SET(&ev, 1, EVFILT_TIMER, EV_ADD|EV_ENABLE, 0, 1, 0); ATF_CHECK(kevent(kq, &ev, 1, NULL, 0, NULL) != -1); printf("parent (pid %d): sending kq fd %d\n", getpid(), kq); if (sendmsg(s[0], &m, 0) == -1) { -#if defined(__NetBSD__) +#ifdef __NetBSD__ ATF_REQUIRE_EQ_MSG(errno, EBADF, "errno is %d", errno); atf_tc_skip("PR kern/46523"); #endif -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ ATF_REQUIRE_EQ_MSG(errno, EOPNOTSUPP, "errno is %d", errno); close(s[0]); #endif } close(kq); waitpid(child, &status, 0); ATF_CHECK(WIFEXITED(status) && WEXITSTATUS(status)==0); } ATF_TC(kqueue_unsupported_fd); ATF_TC_HEAD(kqueue_unsupported_fd, tc) { atf_tc_set_md_var(tc, "descr", "Checks that watching an fd whose" " type is not supported does not crash the kernel"); } ATF_TC_BODY(kqueue_unsupported_fd, tc) { /* mqueue and semaphore use fnullop_kqueue also */ int fd, kq; struct kevent ev; fd = open(DRVCTLDEV, O_RDONLY); if (fd == -1 && errno == ENOENT) atf_tc_skip("no " DRVCTLDEV " available for testing"); ATF_REQUIRE(fd != -1); ATF_REQUIRE((kq = kqueue()) != -1); EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK| NOTE_RENAME|NOTE_REVOKE, 0, 0); ATF_REQUIRE(kevent(kq, &ev, 1, NULL, 0, NULL) == -1); ATF_REQUIRE_ERRNO(EOPNOTSUPP, true); (void)close(fd); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, kevent_zerotimer); ATF_TP_ADD_TC(tp, kqueue_desc_passing); ATF_TP_ADD_TC(tp, kqueue_unsupported_fd); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_listen.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_listen.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_listen.c (revision 274626) @@ -1,138 +1,138 @@ /* $NetBSD: t_listen.c,v 1.4 2012/03/18 07:00:52 jruoho Exp $ */ /* * Copyright (c) 2007 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 -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #endif static const char *path = "listen"; ATF_TC_WITH_CLEANUP(listen_err); ATF_TC_HEAD(listen_err, tc) { atf_tc_set_md_var(tc, "descr", "Checks errors from listen(2) (PR standards/46150)"); } ATF_TC_BODY(listen_err, tc) { static const size_t siz = sizeof(struct sockaddr_in); struct sockaddr_in sina, sinb; int fda, fdb, fdc; (void)memset(&sina, 0, sizeof(struct sockaddr_in)); (void)memset(&sinb, 0, sizeof(struct sockaddr_in)); sina.sin_family = AF_INET; sina.sin_port = htons(31522); sina.sin_addr.s_addr = inet_addr("127.0.0.1"); sinb.sin_family = AF_INET; sinb.sin_port = htons(31522); sinb.sin_addr.s_addr = inet_addr("127.0.0.1"); fda = socket(AF_INET, SOCK_STREAM, 0); fdb = socket(AF_INET, SOCK_STREAM, 0); fdc = open("listen", O_RDWR | O_CREAT, 0600); ATF_REQUIRE(fda >= 0 && fdb >= 0 && fdc >= 0); ATF_REQUIRE_ERRNO(ENOTSOCK, listen(fdc, 1) == -1); (void)close(fdc); (void)unlink(path); ATF_REQUIRE(bind(fda, (struct sockaddr *)&sina, siz) == 0); ATF_REQUIRE(listen(fda, 1) == 0); /* * According to IEEE Std 1003.1-2008: if the socket is * already connected, the call should fail with EINVAL. */ ATF_REQUIRE(connect(fdb, (struct sockaddr *)&sinb, siz) == 0); ATF_REQUIRE_ERRNO(EINVAL, listen(fdb, 1) == -1); (void)close(fda); (void)close(fdb); ATF_REQUIRE_ERRNO(EBADF, connect(fdb, (struct sockaddr *)&sinb, siz) == -1); } ATF_TC_CLEANUP(listen_err, tc) { (void)unlink(path); } ATF_TC(listen_low_port); ATF_TC_HEAD(listen_low_port, tc) { atf_tc_set_md_var(tc, "descr", "Does low-port allocation work?"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(listen_low_port, tc) { int sd, val; sd = socket(AF_INET, SOCK_STREAM, 0); val = IP_PORTRANGE_LOW; if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val, sizeof(val)) == -1) atf_tc_fail("setsockopt failed: %s", strerror(errno)); if (listen(sd, 5) == -1) { int serrno = errno; atf_tc_fail("listen failed: %s%s", strerror(serrno), serrno != EACCES ? "" : " (see http://mail-index.netbsd.org/" "source-changes/2007/12/16/0011.html)"); } close(sd); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, listen_err); ATF_TP_ADD_TC(tp, listen_low_port); return 0; } Index: head/contrib/netbsd-tests/lib/libc/sys/t_msgrcv.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_msgrcv.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_msgrcv.c (revision 274626) @@ -1,346 +1,346 @@ /* $NetBSD: t_msgrcv.c,v 1.3 2013/07/24 11:44:10 skrll 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_msgrcv.c,v 1.3 2013/07/24 11:44:10 skrll Exp $"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #endif #define MSG_KEY 1234 #define MSG_MTYPE_1 0x41 #define MSG_MTYPE_2 0x42 #define MSG_MTYPE_3 0x43 #define MSG_LEN 3 struct msg { long mtype; char buf[MSG_LEN]; }; static void clean(void); static void clean(void) { int id; if ((id = msgget(MSG_KEY, 0)) != -1) (void)msgctl(id, IPC_RMID, 0); } ATF_TC_WITH_CLEANUP(msgrcv_basic); ATF_TC_HEAD(msgrcv_basic, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of msgrcv(2)"); } ATF_TC_BODY(msgrcv_basic, tc) { struct msg msg1 = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; struct msg msg2 = { MSG_MTYPE_1, { 'x', 'y', 'z' } }; int id; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); (void)msgsnd(id, &msg1, MSG_LEN, IPC_NOWAIT); (void)msgrcv(id, &msg2, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT); ATF_CHECK(msg1.buf[0] == msg2.buf[0]); ATF_CHECK(msg1.buf[1] == msg2.buf[1]); ATF_CHECK(msg1.buf[2] == msg2.buf[2]); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgrcv_basic, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgrcv_block); ATF_TC_HEAD(msgrcv_block, tc) { atf_tc_set_md_var(tc, "descr", "Test that msgrcv(2) blocks"); } ATF_TC_BODY(msgrcv_block, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; int id, sta; pid_t pid; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { if (msgrcv(id, &msg, MSG_LEN, MSG_MTYPE_1, 0) < 0) _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); } /* * Below msgsnd(2) should unblock the child, * and hence kill(2) should fail with ESRCH. */ (void)sleep(1); (void)msgsnd(id, &msg, MSG_LEN, IPC_NOWAIT); (void)sleep(1); (void)kill(pid, SIGKILL); (void)wait(&sta); if (WIFEXITED(sta) == 0 || WIFSIGNALED(sta) != 0) atf_tc_fail("msgrcv(2) did not block"); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgrcv_block, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgrcv_err); ATF_TC_HEAD(msgrcv_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from msgrcv(2)"); } ATF_TC_BODY(msgrcv_err, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; int id, r = 0; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); errno = 0; ATF_REQUIRE_ERRNO(ENOMSG, msgrcv(id, &msg, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT) == -1); ATF_REQUIRE(msgsnd(id, &msg, MSG_LEN, IPC_NOWAIT) == 0); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, msgrcv(id, (void *)-1, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgrcv(-1, &msg, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgrcv(-1, &msg, SSIZE_MAX, MSG_MTYPE_1, IPC_NOWAIT) == -1); ATF_REQUIRE(msgsnd(id, &msg, MSG_LEN, IPC_NOWAIT) == 0); errno = 0; ATF_REQUIRE_ERRNO(E2BIG, msgrcv(id, &r, MSG_LEN - 1, MSG_MTYPE_1, IPC_NOWAIT) == -1); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgrcv_err, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgrcv_mtype); ATF_TC_HEAD(msgrcv_mtype, tc) { atf_tc_set_md_var(tc, "descr", "Test message types with msgrcv(2)"); } ATF_TC_BODY(msgrcv_mtype, tc) { struct msg msg1 = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; struct msg msg2 = { MSG_MTYPE_3, { 'x', 'y', 'z' } }; int id; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); (void)msgsnd(id, &msg1, MSG_LEN, IPC_NOWAIT); (void)msgrcv(id, &msg2, MSG_LEN, MSG_MTYPE_2, IPC_NOWAIT); ATF_CHECK(msg1.buf[0] != msg2.buf[0]); /* Different mtype. */ ATF_CHECK(msg1.buf[1] != msg2.buf[1]); ATF_CHECK(msg1.buf[2] != msg2.buf[2]); (void)msgrcv(id, &msg2, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT); ATF_CHECK(msg1.buf[0] == msg2.buf[0]); /* Same mtype. */ ATF_CHECK(msg1.buf[1] == msg2.buf[1]); ATF_CHECK(msg1.buf[2] == msg2.buf[2]); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgrcv_mtype, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgrcv_nonblock); ATF_TC_HEAD(msgrcv_nonblock, tc) { atf_tc_set_md_var(tc, "descr", "Test msgrcv(2) with IPC_NOWAIT"); atf_tc_set_md_var(tc, "timeout", "10"); } ATF_TC_BODY(msgrcv_nonblock, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; const ssize_t n = 10; int id, sta; ssize_t i; pid_t pid; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); for (i = 0; i < n; i++) { ATF_REQUIRE(msgsnd(id, &msg, MSG_LEN, IPC_NOWAIT) == 0); } pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { while (i != 0) { if (msgrcv(id, &msg, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT) == -1) _exit(EXIT_FAILURE); i--; } _exit(EXIT_SUCCESS); } (void)sleep(2); (void)kill(pid, SIGKILL); (void)wait(&sta); if (WIFSIGNALED(sta) != 0 || WTERMSIG(sta) == SIGKILL) atf_tc_fail("msgrcv(2) blocked with IPC_NOWAIT"); if (WIFEXITED(sta) == 0 && WEXITSTATUS(sta) != EXIT_SUCCESS) atf_tc_fail("msgrcv(2) failed"); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgrcv_nonblock, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgrcv_truncate); ATF_TC_HEAD(msgrcv_truncate, tc) { atf_tc_set_md_var(tc, "descr", "Test msgrcv(2) with MSG_NOERROR"); } ATF_TC_BODY(msgrcv_truncate, tc) { #define MSG_SMALLLEN 2 struct msgsmall { long mtype; char buf[MSG_SMALLLEN]; }; struct msg msg1 = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; struct msgsmall msg2 = { MSG_MTYPE_1, { 'x', 'y' } }; int id; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); (void)msgsnd(id, &msg1, MSG_LEN, IPC_NOWAIT); (void)msgrcv(id, &msg2, MSG_SMALLLEN, MSG_MTYPE_1, IPC_NOWAIT | MSG_NOERROR); ATF_CHECK(msg1.buf[0] == msg2.buf[0]); ATF_CHECK(msg1.buf[1] == msg2.buf[1]); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgrcv_truncate, tc) { clean(); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, msgrcv_basic); ATF_TP_ADD_TC(tp, msgrcv_block); ATF_TP_ADD_TC(tp, msgrcv_err); ATF_TP_ADD_TC(tp, msgrcv_mtype); ATF_TP_ADD_TC(tp, msgrcv_nonblock); ATF_TP_ADD_TC(tp, msgrcv_truncate); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_msgsnd.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_msgsnd.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_msgsnd.c (revision 274626) @@ -1,342 +1,342 @@ /* $NetBSD: t_msgsnd.c,v 1.2 2011/11/05 08:47:54 jruoho 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_msgsnd.c,v 1.2 2011/11/05 08:47:54 jruoho Exp $"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #endif #define MSG_KEY 1234 #define MSG_MTYPE_1 0x41 #define MSG_MTYPE_2 0x42 #define MSG_MTYPE_3 0x43 struct msg { long mtype; char buf[3]; }; static void clean(void); static void clean(void) { int id; if ((id = msgget(MSG_KEY, 0)) != -1) (void)msgctl(id, IPC_RMID, 0); } ATF_TC_WITH_CLEANUP(msgsnd_block); ATF_TC_HEAD(msgsnd_block, tc) { atf_tc_set_md_var(tc, "descr", "Test that msgsnd(2) blocks"); atf_tc_set_md_var(tc, "timeout", "10"); } ATF_TC_BODY(msgsnd_block, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; int id, sta; pid_t pid; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { /* * Enqueue messages until some limit (e.g. the maximum * number of messages in the queue or the maximum number * of bytes in the queue) is reached. After this the call * should block when the IPC_NOWAIT is not set. */ for (;;) { if (msgsnd(id, &msg, sizeof(struct msg), 0) < 0) _exit(EXIT_FAILURE); } } (void)sleep(2); (void)kill(pid, SIGKILL); (void)wait(&sta); if (WIFEXITED(sta) != 0 || WIFSIGNALED(sta) == 0) atf_tc_fail("msgsnd(2) did not block"); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgsnd_block, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgsnd_count); ATF_TC_HEAD(msgsnd_count, tc) { atf_tc_set_md_var(tc, "descr", "Test that msgsnd(2) increments the amount of " "message in the queue, as given by msgctl(2)"); atf_tc_set_md_var(tc, "timeout", "10"); } ATF_TC_BODY(msgsnd_count, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; struct msqid_ds ds; size_t i = 0; int id, rv; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); for (;;) { errno = 0; rv = msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT); if (rv == 0) { i++; continue; } if (rv == -1 && errno == EAGAIN) break; atf_tc_fail("failed to enqueue a message"); } (void)memset(&ds, 0, sizeof(struct msqid_ds)); (void)msgctl(id, IPC_STAT, &ds); if (ds.msg_qnum != i) atf_tc_fail("incorrect message count"); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgsnd_count, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgsnd_err); ATF_TC_HEAD(msgsnd_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from msgsnd(2)"); } ATF_TC_BODY(msgsnd_err, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; int id; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, msgsnd(id, (void *)-1, sizeof(struct msg), IPC_NOWAIT) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgsnd(-1, &msg, sizeof(struct msg), IPC_NOWAIT) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgsnd(-1, &msg, SSIZE_MAX, IPC_NOWAIT) == -1); errno = 0; msg.mtype = 0; ATF_REQUIRE_ERRNO(EINVAL, msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT) == -1); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgsnd_err, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgsnd_nonblock); ATF_TC_HEAD(msgsnd_nonblock, tc) { atf_tc_set_md_var(tc, "descr", "Test msgsnd(2) with IPC_NOWAIT"); atf_tc_set_md_var(tc, "timeout", "10"); } ATF_TC_BODY(msgsnd_nonblock, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; int id, rv, sta; pid_t pid; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { for (;;) { errno = 0; rv = msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT); if (rv == -1 && errno == EAGAIN) _exit(EXIT_SUCCESS); } } (void)sleep(2); (void)kill(pid, SIGKILL); (void)wait(&sta); if (WIFEXITED(sta) == 0 || WIFSIGNALED(sta) != 0) atf_tc_fail("msgsnd(2) blocked with IPC_NOWAIT"); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgsnd_nonblock, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgsnd_perm); ATF_TC_HEAD(msgsnd_perm, tc) { atf_tc_set_md_var(tc, "descr", "Test permissions with msgsnd(2)"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(msgsnd_perm, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; struct passwd *pw; int id, sta; pid_t pid; uid_t uid; pw = getpwnam("nobody"); id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); ATF_REQUIRE(pw != NULL); uid = pw->pw_uid; ATF_REQUIRE(uid != 0); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { /* * Try to enqueue a message to the queue * created by root as RW for owner only. */ if (setuid(uid) != 0) _exit(EX_OSERR); id = msgget(MSG_KEY, 0); if (id == -1) _exit(EX_OSERR); errno = 0; if (msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT) == 0) _exit(EXIT_FAILURE); if (errno != EACCES) _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); } (void)wait(&sta); if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) { if (errno == EX_OSERR) atf_tc_fail("system call failed"); atf_tc_fail("UID %u enqueued message to root's queue", uid); } ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgsnd_perm, tc) { clean(); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, msgsnd_block); ATF_TP_ADD_TC(tp, msgsnd_count); ATF_TP_ADD_TC(tp, msgsnd_err); ATF_TP_ADD_TC(tp, msgsnd_nonblock); ATF_TP_ADD_TC(tp, msgsnd_perm); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_nanosleep.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_nanosleep.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_nanosleep.c (revision 274626) @@ -1,191 +1,191 @@ /* $NetBSD: t_nanosleep.c,v 1.3 2013/03/31 16:47:16 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_nanosleep.c,v 1.3 2013/03/31 16:47:16 christos Exp $"); #include #include #include #include #include #include #include #include #include #include #include static void -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ handler(int signo __unused) #else handler(int signo) #endif { /* Nothing. */ } ATF_TC(nanosleep_basic); ATF_TC_HEAD(nanosleep_basic, tc) { atf_tc_set_md_var(tc, "descr", "Test that nanosleep(2) works"); } ATF_TC_BODY(nanosleep_basic, tc) { static const size_t maxiter = 10; struct timespec ts1, ts2, tsn; size_t i; for (i = 1; i < maxiter; i++) { tsn.tv_sec = 0; tsn.tv_nsec = i; (void)memset(&ts1, 0, sizeof(struct timespec)); (void)memset(&ts2, 0, sizeof(struct timespec)); ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, &ts1) == 0); ATF_REQUIRE(nanosleep(&tsn, NULL) == 0); ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, &ts2) == 0); /* * Verify that we slept at least one nanosecond. */ if (timespeccmp(&ts2, &ts1, <=) != 0) { (void)fprintf(stderr, "sleep time:: sec %llu, nsec %lu\n\t\t" "ts1: sec %llu, nsec %lu\n\t\t" "ts2: sec %llu, nsec %lu\n", (unsigned long long)tsn.tv_sec, tsn.tv_nsec, (unsigned long long)ts1.tv_sec, ts1.tv_nsec, (unsigned long long)ts2.tv_sec, ts2.tv_nsec); atf_tc_fail_nonfatal("inaccuracies in sleep time " "(resolution = %lu nsec)", tsn.tv_nsec); } } } ATF_TC(nanosleep_err); ATF_TC_HEAD(nanosleep_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from nanosleep(2) (PR bin/14558)"); } ATF_TC_BODY(nanosleep_err, tc) { struct timespec ts; ts.tv_sec = 1; ts.tv_nsec = -1; errno = 0; ATF_REQUIRE_ERRNO(EINVAL, nanosleep(&ts, NULL) == -1); ts.tv_sec = 1; ts.tv_nsec = 1000000000; errno = 0; ATF_REQUIRE_ERRNO(EINVAL, nanosleep(&ts, NULL) == -1); ts.tv_sec = -1; ts.tv_nsec = 0; errno = 0; ATF_REQUIRE_ERRNO(0, nanosleep(&ts, NULL) == 0); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, nanosleep((void *)-1, NULL) == -1); } ATF_TC(nanosleep_sig); ATF_TC_HEAD(nanosleep_sig, tc) { atf_tc_set_md_var(tc, "descr", "Test signal for nanosleep(2)"); } ATF_TC_BODY(nanosleep_sig, tc) { struct timespec tsn, tsr; pid_t pid; int sta; /* * Test that a signal interrupts nanosleep(2). * * (In which case the return value should be -1 and the * second parameter should contain the unslept time.) */ pid = fork(); ATF_REQUIRE(pid >= 0); ATF_REQUIRE(signal(SIGINT, handler) == 0); if (pid == 0) { tsn.tv_sec = 10; tsn.tv_nsec = 0; tsr.tv_sec = 0; tsr.tv_nsec = 0; errno = 0; if (nanosleep(&tsn, &tsr) != -1) _exit(EXIT_FAILURE); if (errno != EINTR) _exit(EXIT_FAILURE); if (tsr.tv_sec == 0 && tsr.tv_nsec == 0) _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); } (void)sleep(1); (void)kill(pid, SIGINT); (void)wait(&sta); if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) atf_tc_fail("signal did not interrupt nanosleep(2)"); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, nanosleep_basic); ATF_TP_ADD_TC(tp, nanosleep_err); ATF_TP_ADD_TC(tp, nanosleep_sig); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_pipe2.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_pipe2.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_pipe2.c (revision 274626) @@ -1,210 +1,210 @@ /* $NetBSD: t_pipe2.c,v 1.8 2012/05/16 13:54:28 jruoho Exp $ */ /*- * Copyright (c) 2011 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the NetBSD * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * 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_pipe2.c,v 1.8 2012/05/16 13:54:28 jruoho Exp $"); #include #include #include #include #include #include static void run(int flags) { int fd[2], i; while ((i = open("/", O_RDONLY)) < 3) ATF_REQUIRE(i != -1); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ closefrom(3); #else ATF_REQUIRE(fcntl(3, F_CLOSEM) != -1); #endif ATF_REQUIRE(pipe2(fd, flags) == 0); ATF_REQUIRE(fd[0] == 3); ATF_REQUIRE(fd[1] == 4); if (flags & O_CLOEXEC) { ATF_REQUIRE((fcntl(fd[0], F_GETFD) & FD_CLOEXEC) != 0); ATF_REQUIRE((fcntl(fd[1], F_GETFD) & FD_CLOEXEC) != 0); } else { ATF_REQUIRE((fcntl(fd[0], F_GETFD) & FD_CLOEXEC) == 0); ATF_REQUIRE((fcntl(fd[1], F_GETFD) & FD_CLOEXEC) == 0); } if (flags & O_NONBLOCK) { ATF_REQUIRE((fcntl(fd[0], F_GETFL) & O_NONBLOCK) != 0); ATF_REQUIRE((fcntl(fd[1], F_GETFL) & O_NONBLOCK) != 0); } else { ATF_REQUIRE((fcntl(fd[0], F_GETFL) & O_NONBLOCK) == 0); ATF_REQUIRE((fcntl(fd[1], F_GETFL) & O_NONBLOCK) == 0); } -#if !defined(__FreeBSD__) +#ifndef __FreeBSD__ if (flags & O_NOSIGPIPE) { ATF_REQUIRE(fcntl(fd[0], F_GETNOSIGPIPE) != 0); ATF_REQUIRE(fcntl(fd[1], F_GETNOSIGPIPE) != 0); } else { ATF_REQUIRE(fcntl(fd[0], F_GETNOSIGPIPE) == 0); ATF_REQUIRE(fcntl(fd[1], F_GETNOSIGPIPE) == 0); } #endif ATF_REQUIRE(close(fd[0]) != -1); ATF_REQUIRE(close(fd[1]) != -1); } ATF_TC(pipe2_basic); ATF_TC_HEAD(pipe2_basic, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of pipe2(2)"); } ATF_TC_BODY(pipe2_basic, tc) { run(0); } ATF_TC(pipe2_consume); ATF_TC_HEAD(pipe2_consume, tc) { atf_tc_set_md_var(tc, "descr", "Test that consuming file descriptors " "with pipe2(2) does not crash the system (PR kern/46457)"); } ATF_TC_BODY(pipe2_consume, tc) { struct rlimit rl; int err, filedes[2]; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ int old; closefrom(4); #else err = fcntl(4, F_CLOSEM); ATF_REQUIRE(err == 0); #endif err = getrlimit(RLIMIT_NOFILE, &rl); ATF_REQUIRE(err == 0); /* * The heart of this test is to run against the number of open * file descriptor limit in the middle of a pipe2() call - i.e. * before the call only a single descriptor may be openend. */ -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ old = rl.rlim_cur; #endif rl.rlim_cur = 4; err = setrlimit(RLIMIT_NOFILE, &rl); ATF_REQUIRE(err == 0); err = pipe2(filedes, O_CLOEXEC); ATF_REQUIRE(err == -1); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ rl.rlim_cur = old; err = setrlimit(RLIMIT_NOFILE, &rl); #endif } ATF_TC(pipe2_nonblock); ATF_TC_HEAD(pipe2_nonblock, tc) { atf_tc_set_md_var(tc, "descr", "A non-blocking test of pipe2(2)"); } ATF_TC_BODY(pipe2_nonblock, tc) { run(O_NONBLOCK); } ATF_TC(pipe2_cloexec); ATF_TC_HEAD(pipe2_cloexec, tc) { atf_tc_set_md_var(tc, "descr", "A close-on-exec test of pipe2(2)"); } ATF_TC_BODY(pipe2_cloexec, tc) { run(O_CLOEXEC); } -#if defined(__NetBSD__) +#ifdef __NetBSD__ ATF_TC(pipe2_nosigpipe); ATF_TC_HEAD(pipe2_nosigpipe, tc) { atf_tc_set_md_var(tc, "descr", "A no sigpipe test of pipe2(2)"); } ATF_TC_BODY(pipe2_nosigpipe, tc) { run(O_NOSIGPIPE); } #endif ATF_TC(pipe2_einval); ATF_TC_HEAD(pipe2_einval, tc) { atf_tc_set_md_var(tc, "descr", "A error check of pipe2(2)"); } ATF_TC_BODY(pipe2_einval, tc) { int fd[2]; ATF_REQUIRE_ERRNO(EINVAL, pipe2(fd, O_ASYNC) == -1); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, pipe2_basic); ATF_TP_ADD_TC(tp, pipe2_consume); ATF_TP_ADD_TC(tp, pipe2_nonblock); ATF_TP_ADD_TC(tp, pipe2_cloexec); -#if defined(__NetBSD__) +#ifdef __NetBSD__ ATF_TP_ADD_TC(tp, pipe2_nosigpipe); #endif ATF_TP_ADD_TC(tp, pipe2_einval); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_poll.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_poll.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_poll.c (revision 274626) @@ -1,396 +1,396 @@ /* $NetBSD: t_poll.c,v 1.3 2012/03/18 07:00:52 jruoho Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Matthias Scheler. * * 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 static int desc; static void child1(void) { struct pollfd pfd; pfd.fd = desc; pfd.events = POLLIN | POLLHUP | POLLOUT; (void)poll(&pfd, 1, 2000); (void)printf("child1 exit\n"); } static void child2(void) { struct pollfd pfd; pfd.fd = desc; pfd.events = POLLIN | POLLHUP | POLLOUT; (void)sleep(1); (void)poll(&pfd, 1, INFTIM); (void)printf("child2 exit\n"); } static void child3(void) { struct pollfd pfd; (void)sleep(5); pfd.fd = desc; pfd.events = POLLIN | POLLHUP | POLLOUT; (void)poll(&pfd, 1, INFTIM); (void)printf("child3 exit\n"); } ATF_TC(poll_3way); ATF_TC_HEAD(poll_3way, tc) { atf_tc_set_md_var(tc, "timeout", "15"); atf_tc_set_md_var(tc, "descr", "Check for 3-way collision for descriptor. First child comes " "and polls on descriptor, second child comes and polls, first " "child times out and exits, third child comes and polls. When " "the wakeup event happens, the two remaining children should " "both be awaken. (kern/17517)"); } ATF_TC_BODY(poll_3way, tc) { int pf[2]; int status, i; pid_t pid; pipe(pf); desc = pf[0]; pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { (void)close(pf[1]); child1(); _exit(0); /* NOTREACHED */ } pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { (void)close(pf[1]); child2(); _exit(0); /* NOTREACHED */ } pid = fork(); ATF_REQUIRE( pid >= 0); if (pid == 0) { (void)close(pf[1]); child3(); _exit(0); /* NOTREACHED */ } (void)sleep(10); (void)printf("parent write\n"); ATF_REQUIRE(write(pf[1], "konec\n", 6) == 6); for(i = 0; i < 3; ++i) (void)wait(&status); (void)printf("parent terminated\n"); } ATF_TC(poll_basic); ATF_TC_HEAD(poll_basic, tc) { atf_tc_set_md_var(tc, "timeout", "10"); atf_tc_set_md_var(tc, "descr", "Basis functionality test for poll(2)"); } ATF_TC_BODY(poll_basic, tc) { int fds[2]; struct pollfd pfds[2]; int ret; ATF_REQUIRE_EQ(pipe(fds), 0); pfds[0].fd = fds[0]; pfds[0].events = POLLIN; pfds[1].fd = fds[1]; pfds[1].events = POLLOUT; /* * Check that we get a timeout waiting for data on the read end * of our pipe. */ pfds[0].revents = -1; pfds[1].revents = -1; ATF_REQUIRE_EQ_MSG(ret = poll(&pfds[0], 1, 1), 0, "got: %d", ret); ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents); ATF_REQUIRE_EQ_MSG(pfds[1].revents, -1, "got: %d", pfds[1].revents); /* Check that the write end of the pipe as reported as ready. */ pfds[0].revents = -1; pfds[1].revents = -1; ATF_REQUIRE_EQ_MSG(ret = poll(&pfds[1], 1, 1), 1, "got: %d", ret); ATF_REQUIRE_EQ_MSG(pfds[0].revents, -1, "got: %d", pfds[0].revents); ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",\ pfds[1].revents); /* Check that only the write end of the pipe as reported as ready. */ pfds[0].revents = -1; pfds[1].revents = -1; ATF_REQUIRE_EQ_MSG(ret = poll(pfds, 2, 1), 1, "got: %d", ret); ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents); ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d", pfds[1].revents); /* Write data to our pipe. */ ATF_REQUIRE_EQ(write(fds[1], "", 1), 1); /* Check that both ends of our pipe are reported as ready. */ pfds[0].revents = -1; pfds[1].revents = -1; ATF_REQUIRE_EQ_MSG(ret = poll(pfds, 2, 1), 2, "got: %d", ret); ATF_REQUIRE_EQ_MSG(pfds[0].revents, POLLIN, "got: %d", pfds[0].revents); ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d", pfds[1].revents); ATF_REQUIRE_EQ(close(fds[0]), 0); ATF_REQUIRE_EQ(close(fds[1]), 0); } ATF_TC(poll_err); ATF_TC_HEAD(poll_err, tc) { atf_tc_set_md_var(tc, "descr", "Check errors from poll(2)"); } ATF_TC_BODY(poll_err, tc) { struct pollfd pfd; int fd = 0; pfd.fd = fd; pfd.events = POLLIN; errno = 0; ATF_REQUIRE_ERRNO(EFAULT, poll((struct pollfd *)-1, 1, -1) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, poll(&pfd, 1, -2) == -1); } -#if !defined(__FreeBSD__) +#ifndef __FreeBSD__ ATF_TC(pollts_basic); ATF_TC_HEAD(pollts_basic, tc) { atf_tc_set_md_var(tc, "timeout", "10"); atf_tc_set_md_var(tc, "descr", "Basis functionality test for pollts(2)"); } ATF_TC_BODY(pollts_basic, tc) { int fds[2]; struct pollfd pfds[2]; struct timespec timeout; int ret; ATF_REQUIRE_EQ(pipe(fds), 0); pfds[0].fd = fds[0]; pfds[0].events = POLLIN; pfds[1].fd = fds[1]; pfds[1].events = POLLOUT; /* Use a timeout of 1 second. */ timeout.tv_sec = 1; timeout.tv_nsec = 0; /* * Check that we get a timeout waiting for data on the read end * of our pipe. */ pfds[0].revents = -1; pfds[1].revents = -1; ATF_REQUIRE_EQ_MSG(ret = pollts(&pfds[0], 1, &timeout, NULL), 0, "got: %d", ret); ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents); ATF_REQUIRE_EQ_MSG(pfds[1].revents, -1, "got: %d", pfds[1].revents); /* Check that the write end of the pipe as reported as ready. */ pfds[0].revents = -1; pfds[1].revents = -1; ATF_REQUIRE_EQ_MSG(ret = pollts(&pfds[1], 1, &timeout, NULL), 1, "got: %d", ret); ATF_REQUIRE_EQ_MSG(pfds[0].revents, -1, "got: %d", pfds[0].revents); ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",\ pfds[1].revents); /* Check that only the write end of the pipe as reported as ready. */ pfds[0].revents = -1; pfds[1].revents = -1; ATF_REQUIRE_EQ_MSG(ret = pollts(pfds, 2, &timeout, NULL), 1, "got: %d", ret); ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents); ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d", pfds[1].revents); /* Write data to our pipe. */ ATF_REQUIRE_EQ(write(fds[1], "", 1), 1); /* Check that both ends of our pipe are reported as ready. */ pfds[0].revents = -1; pfds[1].revents = -1; ATF_REQUIRE_EQ_MSG(ret = pollts(pfds, 2, &timeout, NULL), 2, "got: %d", ret); ATF_REQUIRE_EQ_MSG(pfds[0].revents, POLLIN, "got: %d", pfds[0].revents); ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d", pfds[1].revents); ATF_REQUIRE_EQ(close(fds[0]), 0); ATF_REQUIRE_EQ(close(fds[1]), 0); } ATF_TC(pollts_err); ATF_TC_HEAD(pollts_err, tc) { atf_tc_set_md_var(tc, "descr", "Check errors from pollts(2)"); } ATF_TC_BODY(pollts_err, tc) { struct timespec timeout; struct pollfd pfd; int fd = 0; pfd.fd = fd; pfd.events = POLLIN; timeout.tv_sec = 1; timeout.tv_nsec = 0; errno = 0; ATF_REQUIRE_ERRNO(EFAULT, pollts((void *)-1, 1, &timeout, NULL) == -1); timeout.tv_sec = -1; timeout.tv_nsec = -1; errno = 0; ATF_REQUIRE_ERRNO(EINVAL, pollts(&pfd, 1, &timeout, NULL) == -1); } ATF_TC(pollts_sigmask); ATF_TC_HEAD(pollts_sigmask, tc) { atf_tc_set_md_var(tc, "timeout", "10"); atf_tc_set_md_var(tc, "descr", "Check that pollts(2) restores the signal mask (PR kern/44986)"); } ATF_TC_BODY(pollts_sigmask, tc) { int fd; struct pollfd pfd; struct timespec timeout; sigset_t mask; int ret; fd = open(_PATH_DEVNULL, O_RDONLY); ATF_REQUIRE(fd >= 0); pfd.fd = fd; pfd.events = POLLIN; /* Use a timeout of 1 second. */ timeout.tv_sec = 1; timeout.tv_nsec = 0; /* Unblock all signals. */ ATF_REQUIRE_EQ(sigfillset(&mask), 0); ATF_REQUIRE_EQ(sigprocmask(SIG_UNBLOCK, &mask, NULL), 0); /* * Check that pollts(2) immediately returns. We block *all* * signals during pollts(2). */ ATF_REQUIRE_EQ_MSG(ret = pollts(&pfd, 1, &timeout, &mask), 1, "got: %d", ret); /* Check that signals are now longer blocked. */ ATF_REQUIRE_EQ(sigprocmask(SIG_SETMASK, NULL, &mask), 0); ATF_REQUIRE_EQ_MSG(sigismember(&mask, SIGUSR1), 0, "signal mask was changed."); ATF_REQUIRE_EQ(close(fd), 0); } #endif ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, poll_3way); ATF_TP_ADD_TC(tp, poll_basic); ATF_TP_ADD_TC(tp, poll_err); -#if !defined(__FreeBSD__) +#ifndef __FreeBSD__ ATF_TP_ADD_TC(tp, pollts_basic); ATF_TP_ADD_TC(tp, pollts_err); ATF_TP_ADD_TC(tp, pollts_sigmask); #endif return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_revoke.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_revoke.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_revoke.c (revision 274626) @@ -1,195 +1,195 @@ /* $NetBSD: t_revoke.c,v 1.1 2011/07/07 06:57:54 jruoho 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_revoke.c,v 1.1 2011/07/07 06:57:54 jruoho Exp $"); #include #include #include #include #include #include #include #include #include #include static const char path[] = "revoke"; ATF_TC_WITH_CLEANUP(revoke_basic); ATF_TC_HEAD(revoke_basic, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of revoke(2)"); } ATF_TC_BODY(revoke_basic, tc) { struct rlimit res; char tmp[10]; size_t i, n; int *buf; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ atf_tc_skip("revoke(2) is only implemented for devfs(5)."); #endif (void)memset(&res, 0, sizeof(struct rlimit)); (void)getrlimit(RLIMIT_NOFILE, &res); if ((n = res.rlim_cur / 10) == 0) n = 10; buf = calloc(n, sizeof(int)); ATF_REQUIRE(buf != NULL); buf[0] = open(path, O_RDWR | O_CREAT, 0600); ATF_REQUIRE(buf[0] >= 0); for (i = 1; i < n; i++) { buf[i] = open(path, O_RDWR); ATF_REQUIRE(buf[i] >= 0); } ATF_REQUIRE(revoke(path) == 0); for (i = 0; i < n; i++) { ATF_REQUIRE(read(buf[i], tmp, sizeof(tmp)) == -1); (void)close(buf[i]); } free(buf); (void)unlink(path); } ATF_TC_CLEANUP(revoke_basic, tc) { (void)unlink(path); } ATF_TC(revoke_err); ATF_TC_HEAD(revoke_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from revoke(2)"); atf_tc_set_md_var(tc, "require.user", "unprivileged"); } ATF_TC_BODY(revoke_err, tc) { char buf[1024 + 1]; /* XXX: From the manual page... */ (void)memset(buf, 'x', sizeof(buf)); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, revoke((char *)-1) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, revoke(buf) == -1); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ atf_tc_skip("revoke(2) is only implemented for devfs(5)."); #endif errno = 0; ATF_REQUIRE_ERRNO(EPERM, revoke("/etc/passwd") == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, revoke("/etc/xxx/yyy") == -1); } ATF_TC_WITH_CLEANUP(revoke_perm); ATF_TC_HEAD(revoke_perm, tc) { atf_tc_set_md_var(tc, "descr", "Test permissions revoke(2)"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(revoke_perm, tc) { struct passwd *pw; int fd, sta; pid_t pid; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ atf_tc_skip("revoke(2) is only implemented for devfs(5)."); #endif pw = getpwnam("nobody"); fd = open(path, O_RDWR | O_CREAT, 0600); ATF_REQUIRE(fd >= 0); ATF_REQUIRE(pw != NULL); ATF_REQUIRE(revoke(path) == 0); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { if (setuid(pw->pw_uid) != 0) _exit(EXIT_FAILURE); errno = 0; if (revoke(path) == 0) _exit(EXIT_FAILURE); if (errno != EACCES) _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("revoke(2) did not obey permissions"); ATF_REQUIRE(unlink(path) == 0); } ATF_TC_CLEANUP(revoke_perm, tc) { (void)unlink(path); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, revoke_basic); ATF_TP_ADD_TC(tp, revoke_err); ATF_TP_ADD_TC(tp, revoke_perm); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c (revision 274626) @@ -1,115 +1,115 @@ /* $NetBSD: t_sigqueue.c,v 1.4 2011/07/07 16:31:11 jruoho Exp $ */ /*- * Copyright (c) 2011 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_sigqueue.c,v 1.4 2011/07/07 16:31:11 jruoho Exp $"); #include #include #include #include #include #include static void handler(int, siginfo_t *, void *); #define VALUE (int)0xc001dad1 static int value; static void -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ handler(int signo __unused, siginfo_t *info __unused, void *data __unused) #else handler(int signo, siginfo_t *info, void *data) #endif { value = info->si_value.sival_int; kill(0, SIGINFO); } ATF_TC(sigqueue_basic); ATF_TC_HEAD(sigqueue_basic, tc) { atf_tc_set_md_var(tc, "descr", "Checks sigqueue(3) sigval delivery"); } ATF_TC_BODY(sigqueue_basic, tc) { struct sigaction sa; union sigval sv; sa.sa_sigaction = handler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_SIGINFO; if (sigaction(SIGUSR1, &sa, NULL) != 0) atf_tc_fail("sigaction failed"); sv.sival_int = VALUE; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ /* * From kern_sig.c: * Specification says sigqueue can only send signal to single process. */ if (sigqueue(getpid(), SIGUSR1, sv) != 0) #else if (sigqueue(0, SIGUSR1, sv) != 0) #endif atf_tc_fail("sigqueue failed"); sched_yield(); ATF_REQUIRE_EQ(sv.sival_int, value); } ATF_TC(sigqueue_err); ATF_TC_HEAD(sigqueue_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from sigqueue(3)"); } ATF_TC_BODY(sigqueue_err, tc) { union sigval sv; errno = 0; ATF_REQUIRE_ERRNO(EINVAL, sigqueue(getpid(), -1, sv) == -1); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, sigqueue_basic); ATF_TP_ADD_TC(tp, sigqueue_err); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_stat.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_stat.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_stat.c (revision 274626) @@ -1,421 +1,421 @@ /* $NetBSD: t_stat.c,v 1.4 2012/03/17 08:37:08 jruoho 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_stat.c,v 1.4 2012/03/17 08:37:08 jruoho Exp $"); #include #include #include #include #include #include #include #include #include #include #include #include -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #endif static const char *path = "stat"; ATF_TC_WITH_CLEANUP(stat_chflags); ATF_TC_HEAD(stat_chflags, tc) { atf_tc_set_md_var(tc, "descr", "Test chflags(2) with stat(2)"); } ATF_TC_BODY(stat_chflags, tc) { struct stat sa, sb; int fd; (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); fd = open(path, O_RDONLY | O_CREAT); ATF_REQUIRE(fd != -1); ATF_REQUIRE(stat(path, &sa) == 0); ATF_REQUIRE(chflags(path, UF_NODUMP) == 0); ATF_REQUIRE(stat(path, &sb) == 0); if (sa.st_flags == sb.st_flags) atf_tc_fail("stat(2) did not detect chflags(2)"); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlink(path) == 0); } ATF_TC_CLEANUP(stat_chflags, tc) { (void)unlink(path); } ATF_TC(stat_dir); ATF_TC_HEAD(stat_dir, tc) { atf_tc_set_md_var(tc, "descr", "Test stat(2) with directories"); } ATF_TC_BODY(stat_dir, tc) { const short depth = 2; struct stat sa, sb; char *argv[2]; FTSENT *ftse; FTS *fts; int ops; argv[1] = NULL; argv[0] = __UNCONST("/"); ops = FTS_NOCHDIR; ops |= FTS_PHYSICAL; fts = fts_open(argv, ops, NULL); ATF_REQUIRE(fts != NULL); while ((ftse = fts_read(fts)) != NULL) { if (ftse->fts_level < 1) continue; if (ftse->fts_level > depth) { (void)fts_set(fts, ftse, FTS_SKIP); continue; } switch(ftse->fts_info) { case FTS_DP: (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); ATF_REQUIRE(stat(ftse->fts_parent->fts_path,&sa) == 0); ATF_REQUIRE(chdir(ftse->fts_path) == 0); ATF_REQUIRE(stat(".", &sb) == 0); /* * The previous two stat(2) calls * should be for the same directory. */ if (sa.st_dev != sb.st_dev || sa.st_ino != sb.st_ino) atf_tc_fail("inconsistent stat(2)"); /* * Check that fts(3)'s stat(2) * call equals the manual one. */ if (sb.st_ino != ftse->fts_statp->st_ino) atf_tc_fail("stat(2) and fts(3) differ"); break; default: break; } } (void)fts_close(fts); } ATF_TC(stat_err); ATF_TC_HEAD(stat_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from the stat(2) family"); } ATF_TC_BODY(stat_err, tc) { char buf[NAME_MAX + 1]; struct stat st; (void)memset(buf, 'x', sizeof(buf)); errno = 0; ATF_REQUIRE_ERRNO(EBADF, fstat(-1, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, stat(buf, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, lstat(buf, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, stat((void *)-1, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, lstat((void *)-1, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, stat("/etc/passwd", (void *)-1) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, lstat("/etc/passwd", (void *)-1) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, stat("/a/b/c/d/e/f/g/h/i/j/k", &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, lstat("/a/b/c/d/e/f/g/h/i/j/k", &st) == -1); } ATF_TC_WITH_CLEANUP(stat_mtime); ATF_TC_HEAD(stat_mtime, tc) { atf_tc_set_md_var(tc, "descr", "Test modification times with stat(2)"); } ATF_TC_BODY(stat_mtime, tc) { struct stat sa, sb; int fd[3]; size_t i; for (i = 0; i < __arraycount(fd); i++) { (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); fd[i] = open(path, O_WRONLY | O_CREAT); ATF_REQUIRE(fd[i] != -1); ATF_REQUIRE(write(fd[i], "X", 1) == 1); ATF_REQUIRE(stat(path, &sa) == 0); (void)sleep(1); ATF_REQUIRE(write(fd[i], "X", 1) == 1); ATF_REQUIRE(stat(path, &sb) == 0); ATF_REQUIRE(close(fd[i]) == 0); ATF_REQUIRE(unlink(path) == 0); if (sa.st_mtime == sb.st_mtime) atf_tc_fail("mtimes did not change"); } } ATF_TC_CLEANUP(stat_mtime, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(stat_perm); ATF_TC_HEAD(stat_perm, tc) { atf_tc_set_md_var(tc, "descr", "Test permissions with stat(2)"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(stat_perm, tc) { struct stat sa, sb; gid_t gid; uid_t uid; int fd; (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); uid = getuid(); gid = getgid(); fd = open(path, O_RDONLY | O_CREAT); ATF_REQUIRE(fd != -1); ATF_REQUIRE(fstat(fd, &sa) == 0); ATF_REQUIRE(stat(path, &sb) == 0); if (gid != sa.st_gid || sa.st_gid != sb.st_gid) atf_tc_fail("invalid GID"); if (uid != sa.st_uid || sa.st_uid != sb.st_uid) atf_tc_fail("invalid UID"); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlink(path) == 0); } ATF_TC_CLEANUP(stat_perm, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(stat_size); ATF_TC_HEAD(stat_size, tc) { atf_tc_set_md_var(tc, "descr", "Test file sizes with stat(2)"); } ATF_TC_BODY(stat_size, tc) { struct stat sa, sb, sc; const size_t n = 10; size_t i; int fd; fd = open(path, O_WRONLY | O_CREAT); ATF_REQUIRE(fd >= 0); for (i = 0; i < n; i++) { (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); (void)memset(&sc, 0, sizeof(struct stat)); ATF_REQUIRE(fstat(fd, &sa) == 0); ATF_REQUIRE(write(fd, "X", 1) == 1); ATF_REQUIRE(fstat(fd, &sb) == 0); ATF_REQUIRE(stat(path, &sc) == 0); if (sa.st_size + 1 != sb.st_size) atf_tc_fail("invalid file size"); if (sb.st_size != sc.st_size) atf_tc_fail("stat(2) and fstat(2) mismatch"); } ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlink(path) == 0); } ATF_TC_CLEANUP(stat_size, tc) { (void)unlink(path); } ATF_TC(stat_socket); ATF_TC_HEAD(stat_socket, tc) { atf_tc_set_md_var(tc, "descr", "Test fstat(2) with " "a socket (PR kern/46077)"); } ATF_TC_BODY(stat_socket, tc) { struct sockaddr_in addr; struct stat st; uint32_t iaddr; int fd, flags; (void)memset(&st, 0, sizeof(struct stat)); (void)memset(&addr, 0, sizeof(struct sockaddr_in)); fd = socket(AF_INET, SOCK_STREAM, 0); ATF_REQUIRE(fd >= 0); flags = fcntl(fd, F_GETFL); ATF_REQUIRE(flags != -1); ATF_REQUIRE(fcntl(fd, F_SETFL, flags | O_NONBLOCK) != -1); ATF_REQUIRE(inet_pton(AF_INET, "127.0.0.1", &iaddr) == 1); addr.sin_port = htons(42); addr.sin_family = AF_INET; addr.sin_addr.s_addr = iaddr; errno = 0; ATF_REQUIRE_ERRNO(EINPROGRESS, connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) == -1); errno = 0; if (fstat(fd, &st) != 0 || errno != 0) atf_tc_fail("fstat(2) failed for a EINPROGRESS socket"); (void)close(fd); } ATF_TC_WITH_CLEANUP(stat_symlink); ATF_TC_HEAD(stat_symlink, tc) { atf_tc_set_md_var(tc, "descr", "Test symbolic links with stat(2)"); } ATF_TC_BODY(stat_symlink, tc) { const char *pathlink = "pathlink"; struct stat sa, sb; int fd; (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); fd = open(path, O_WRONLY | O_CREAT); ATF_REQUIRE(fd >= 0); ATF_REQUIRE(symlink(path, pathlink) == 0); ATF_REQUIRE(stat(pathlink, &sa) == 0); ATF_REQUIRE(lstat(pathlink, &sb) == 0); if (S_ISLNK(sa.st_mode) != 0) atf_tc_fail("stat(2) detected symbolic link"); if (S_ISLNK(sb.st_mode) == 0) atf_tc_fail("lstat(2) did not detect symbolic link"); if (sa.st_mode == sb.st_mode) atf_tc_fail("inconsistencies between stat(2) and lstat(2)"); ATF_REQUIRE(unlink(path) == 0); ATF_REQUIRE(unlink(pathlink) == 0); } ATF_TC_CLEANUP(stat_symlink, tc) { (void)unlink(path); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, stat_chflags); ATF_TP_ADD_TC(tp, stat_dir); ATF_TP_ADD_TC(tp, stat_err); ATF_TP_ADD_TC(tp, stat_mtime); ATF_TP_ADD_TC(tp, stat_perm); ATF_TP_ADD_TC(tp, stat_size); ATF_TP_ADD_TC(tp, stat_socket); ATF_TP_ADD_TC(tp, stat_symlink); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_timer_create.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_timer_create.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_timer_create.c (revision 274626) @@ -1,211 +1,211 @@ /* $NetBSD: t_timer_create.c,v 1.4 2012/03/18 07:00:52 jruoho 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 static timer_t t; static bool fail = true; static void -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ timer_signal_handler(int signo, siginfo_t *si, void *osi __unused) #else timer_signal_handler(int signo, siginfo_t *si, void *osi) #endif { timer_t *tp; tp = si->si_value.sival_ptr; if (*tp == t && signo == SIGALRM) fail = false; (void)fprintf(stderr, "%s: %s\n", __func__, strsignal(signo)); } static void timer_signal_create(clockid_t cid, bool expire) { struct itimerspec tim; struct sigaction act; struct sigevent evt; sigset_t set; t = 0; fail = true; (void)memset(&evt, 0, sizeof(struct sigevent)); (void)memset(&act, 0, sizeof(struct sigaction)); (void)memset(&tim, 0, sizeof(struct itimerspec)); /* * Set handler. */ act.sa_flags = SA_SIGINFO; act.sa_sigaction = timer_signal_handler; ATF_REQUIRE(sigemptyset(&set) == 0); ATF_REQUIRE(sigemptyset(&act.sa_mask) == 0); /* * Block SIGALRM while configuring the timer. */ ATF_REQUIRE(sigaction(SIGALRM, &act, NULL) == 0); ATF_REQUIRE(sigaddset(&set, SIGALRM) == 0); ATF_REQUIRE(sigprocmask(SIG_SETMASK, &set, NULL) == 0); /* * Create the timer (SIGEV_SIGNAL). */ evt.sigev_signo = SIGALRM; evt.sigev_value.sival_ptr = &t; evt.sigev_notify = SIGEV_SIGNAL; ATF_REQUIRE(timer_create(cid, &evt, &t) == 0); /* * Start the timer. After this, unblock the signal. */ tim.it_value.tv_sec = expire ? 5 : 1; tim.it_value.tv_nsec = 0; ATF_REQUIRE(timer_settime(t, 0, &tim, NULL) == 0); (void)sigprocmask(SIG_UNBLOCK, &set, NULL); (void)sleep(2); if (expire) { if (!fail) atf_tc_fail("timer fired too soon"); } else { if (fail) atf_tc_fail("timer failed to fire"); } ATF_REQUIRE(timer_delete(t) == 0); } ATF_TC(timer_create_err); ATF_TC_HEAD(timer_create_err, tc) { atf_tc_set_md_var(tc, "descr", "Check errors from timer_create(2) (PR lib/42434"); } ATF_TC_BODY(timer_create_err, tc) { struct sigevent ev; (void)memset(&ev, 0, sizeof(struct sigevent)); errno = 0; ev.sigev_signo = -1; ev.sigev_notify = SIGEV_SIGNAL; ATF_REQUIRE_ERRNO(EINVAL, timer_create(CLOCK_REALTIME, &ev, &t) == -1); errno = 0; ev.sigev_signo = SIGUSR1; ev.sigev_notify = SIGEV_THREAD + 100; ATF_REQUIRE_ERRNO(EINVAL, timer_create(CLOCK_REALTIME, &ev, &t) == -1); } ATF_TC(timer_create_real); ATF_TC_HEAD(timer_create_real, tc) { atf_tc_set_md_var(tc, "descr", "Checks timer_create(2) with CLOCK_REALTIME and sigevent(3), " "SIGEV_SIGNAL"); } ATF_TC_BODY(timer_create_real, tc) { timer_signal_create(CLOCK_REALTIME, false); } ATF_TC(timer_create_mono); ATF_TC_HEAD(timer_create_mono, tc) { atf_tc_set_md_var(tc, "descr", "Checks timer_create(2) with CLOCK_MONOTONIC and sigevent(3), " "SIGEV_SIGNAL"); } ATF_TC_BODY(timer_create_mono, tc) { timer_signal_create(CLOCK_MONOTONIC, false); } ATF_TC(timer_create_real_expire); ATF_TC_HEAD(timer_create_real_expire, tc) { atf_tc_set_md_var(tc, "descr", "Checks timer_create(2) with CLOCK_REALTIME and sigevent(3), " "SIGEV_SIGNAL, with expiration"); } ATF_TC_BODY(timer_create_real_expire, tc) { timer_signal_create(CLOCK_REALTIME, true); } ATF_TC(timer_create_mono_expire); ATF_TC_HEAD(timer_create_mono_expire, tc) { atf_tc_set_md_var(tc, "descr", "Checks timer_create(2) with CLOCK_MONOTONIC and sigevent(3), " "SIGEV_SIGNAL, with expiration"); } ATF_TC_BODY(timer_create_mono_expire, tc) { timer_signal_create(CLOCK_MONOTONIC, true); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, timer_create_err); ATF_TP_ADD_TC(tp, timer_create_real); ATF_TP_ADD_TC(tp, timer_create_mono); ATF_TP_ADD_TC(tp, timer_create_real_expire); ATF_TP_ADD_TC(tp, timer_create_mono_expire); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_unlink.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_unlink.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_unlink.c (revision 274626) @@ -1,162 +1,162 @@ /* $NetBSD: t_unlink.c,v 1.2 2014/04/21 18:05:17 martin 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_unlink.c,v 1.2 2014/04/21 18:05:17 martin Exp $"); #include #include #include #include #include #include #include static char path[] = "unlink"; ATF_TC_WITH_CLEANUP(unlink_basic); ATF_TC_HEAD(unlink_basic, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of unlink(2)"); } ATF_TC_BODY(unlink_basic, tc) { const size_t n = 512; size_t i; int fd; for (i = 0; i < n; i++) { fd = open(path, O_RDWR | O_CREAT, 0666); ATF_REQUIRE(fd != -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlink(path) == 0); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, open(path, O_RDONLY) == -1); } } ATF_TC_CLEANUP(unlink_basic, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(unlink_err); ATF_TC_HEAD(unlink_err, tc) { atf_tc_set_md_var(tc, "descr", "Test error conditions of unlink(2)"); } ATF_TC_BODY(unlink_err, tc) { char buf[PATH_MAX + 1]; (void)memset(buf, 'x', sizeof(buf)); errno = 0; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ ATF_REQUIRE_ERRNO(EISDIR, unlink("/") == -1); #else ATF_REQUIRE_ERRNO(EBUSY, unlink("/") == -1); #endif errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, unlink(buf) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, unlink("/a/b/c/d/e/f/g/h/i/j/k/l/m") == -1); } ATF_TC_CLEANUP(unlink_err, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(unlink_fifo); ATF_TC_HEAD(unlink_fifo, tc) { atf_tc_set_md_var(tc, "descr", "Test unlink(2) for a FIFO"); } ATF_TC_BODY(unlink_fifo, tc) { ATF_REQUIRE(mkfifo(path, 0666) == 0); ATF_REQUIRE(unlink(path) == 0); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, open(path, O_RDONLY) == -1); } ATF_TC_CLEANUP(unlink_fifo, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(unlink_perm); ATF_TC_HEAD(unlink_perm, tc) { atf_tc_set_md_var(tc, "descr", "Test permissions with unlink(2)"); atf_tc_set_md_var(tc, "require.user", "unprivileged"); } ATF_TC_BODY(unlink_perm, tc) { int rv; errno = 0; rv = unlink("/etc"); ATF_REQUIRE_MSG(rv == -1 && (errno == EACCES || errno == EPERM), "unlinking a directory did not fail with EPERM or EACCESS; " "unlink() returned %d, errno %d", rv, errno); errno = 0; ATF_REQUIRE_ERRNO(EACCES, unlink("/root/.profile") == -1); } ATF_TC_CLEANUP(unlink_perm, tc) { (void)unlink(path); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, unlink_basic); ATF_TP_ADD_TC(tp, unlink_err); ATF_TP_ADD_TC(tp, unlink_fifo); ATF_TP_ADD_TC(tp, unlink_perm); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/sys/t_write.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_write.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/sys/t_write.c (revision 274626) @@ -1,236 +1,236 @@ /* $NetBSD: t_write.c,v 1.2 2011/10/19 16:19:30 jruoho Exp $ */ /*- * Copyright (c) 2001, 2008 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 __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_write.c,v 1.2 2011/10/19 16:19:30 jruoho Exp $"); #include -#if defined(__NetBSD__) +#ifdef __NetBSD__ #include #endif #include #include #include #include #include #include #include #include -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ #include #endif static void sighandler(int); static bool fail = false; static const char *path = "write"; static void -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ sighandler(int signo __unused) #else sighandler(int signo) #endif { fail = false; } ATF_TC_WITH_CLEANUP(write_err); ATF_TC_HEAD(write_err, tc) { atf_tc_set_md_var(tc, "descr", "Checks errors from write(2)"); } ATF_TC_BODY(write_err, tc) { char rbuf[3] = { 'a', 'b', 'c' }; char wbuf[3] = { 'x', 'y', 'z' }; int fd; errno = 0; ATF_REQUIRE_ERRNO(EBADF, write(-1, wbuf, sizeof(wbuf)) == -1); fd = open(path, O_RDWR | O_CREAT); if (fd >= 0) { errno = 0; ATF_REQUIRE_ERRNO(0, write(fd, wbuf, 3) == 3); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, write(fd, wbuf, SIZE_MAX) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, write(fd, (void *)-1, 1) == -1); /* * Check that the above bogus write(2) * calls did not corrupt the file. */ ATF_REQUIRE(lseek(fd, 0, SEEK_SET) == 0); ATF_REQUIRE(read(fd, rbuf, 3) == 3); ATF_REQUIRE(memcmp(rbuf, wbuf, 3) == 0); (void)close(fd); (void)unlink(path); } } ATF_TC_CLEANUP(write_err, tc) { (void)unlink(path); } ATF_TC(write_pipe); ATF_TC_HEAD(write_pipe, tc) { atf_tc_set_md_var(tc, "descr", "Checks for EPIPE from write(2)"); } ATF_TC_BODY(write_pipe, tc) { int fds[2]; ATF_REQUIRE(pipe(fds) == 0); ATF_REQUIRE(signal(SIGPIPE, sighandler) == 0); ATF_REQUIRE(write(fds[1], "x", 1) != -1); ATF_REQUIRE(close(fds[0]) == 0); errno = 0; fail = true; if (write(fds[1], "x", 1) != -1 || errno != EPIPE) atf_tc_fail_nonfatal("expected EPIPE but write(2) succeeded"); ATF_REQUIRE(close(fds[1]) == 0); if (fail != false) atf_tc_fail_nonfatal("SIGPIPE was not raised"); } ATF_TC_WITH_CLEANUP(write_pos); ATF_TC_HEAD(write_pos, tc) { atf_tc_set_md_var(tc, "descr", "Checks that write(2) " "updates the file position"); } ATF_TC_BODY(write_pos, tc) { const size_t n = 123; size_t i; int fd; fd = open(path, O_RDWR | O_CREAT); ATF_REQUIRE(fd >= 0); for (i = 0; i < n; i++) { ATF_REQUIRE(write(fd, "x", 1) == 1); ATF_REQUIRE(lseek(fd, 0, SEEK_CUR) == (off_t)(i + 1)); } ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlink(path) == 0); } ATF_TC_CLEANUP(write_pos, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(write_ret); ATF_TC_HEAD(write_ret, tc) { atf_tc_set_md_var(tc, "descr", "Checks return values from write(2)"); } ATF_TC_BODY(write_ret, tc) { const size_t n = 99; char buf[123]; size_t i, j; int fd; fd = open(path, O_WRONLY | O_CREAT); ATF_REQUIRE(fd >= 0); (void)memset(buf, 'x', sizeof(buf)); for (i = j = 0; i < n; i++) j += write(fd, buf, sizeof(buf)); if (j != n * 123) atf_tc_fail("inconsistent return values from write(2)"); (void)close(fd); (void)unlink(path); } ATF_TC_CLEANUP(write_ret, tc) { (void)unlink(path); } ATF_TC(writev_iovmax); ATF_TC_HEAD(writev_iovmax, tc) { atf_tc_set_md_var(tc, "timeout", "10"); atf_tc_set_md_var(tc, "descr", "Checks that file descriptor is properly FILE_UNUSE()d " "when iovcnt is greater than IOV_MAX"); } ATF_TC_BODY(writev_iovmax, tc) { ssize_t retval; (void)printf("Calling writev(2, NULL, IOV_MAX + 1)...\n"); errno = 0; retval = writev(2, NULL, IOV_MAX + 1); ATF_REQUIRE_EQ_MSG(retval, -1, "got: %zd", retval); ATF_REQUIRE_EQ_MSG(errno, EINVAL, "got: %s", strerror(errno)); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, write_err); ATF_TP_ADD_TC(tp, write_pipe); ATF_TP_ADD_TC(tp, write_pos); ATF_TP_ADD_TC(tp, write_ret); ATF_TP_ADD_TC(tp, writev_iovmax); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/time/t_strptime.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/time/t_strptime.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/time/t_strptime.c (revision 274626) @@ -1,281 +1,281 @@ /* $NetBSD: t_strptime.c,v 1.1 2011/01/13 00:14:10 pgoyette Exp $ */ /*- * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by David Laight. * * 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 __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_strptime.c,v 1.1 2011/01/13 00:14:10 pgoyette Exp $"); #include #include static void h_pass(const char *buf, const char *fmt, int len, int tm_sec, int tm_min, int tm_hour, int tm_mday, int tm_mon, int tm_year, int tm_wday, int tm_yday) { struct tm tm = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, NULL }; const char *ret, *exp; exp = buf + len; ret = strptime(buf, fmt, &tm); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ ATF_CHECK_MSG(ret == exp, "strptime(\"%s\", \"%s\", tm): incorrect return code: " "expected: %p, got: %p", buf, fmt, exp, ret); #define H_REQUIRE_FIELD(field) \ ATF_CHECK_MSG(tm.field == field, \ "strptime(\"%s\", \"%s\", tm): incorrect %s: " \ "expected: %d, but got: %d", buf, fmt, \ ___STRING(field), field, tm.field) #else ATF_REQUIRE_MSG(ret == exp, "strptime(\"%s\", \"%s\", tm): incorrect return code: " "expected: %p, got: %p", buf, fmt, exp, ret); #define H_REQUIRE_FIELD(field) \ ATF_REQUIRE_MSG(tm.field == field, \ "strptime(\"%s\", \"%s\", tm): incorrect %s: " \ "expected: %d, but got: %d", buf, fmt, \ ___STRING(field), field, tm.field) #endif H_REQUIRE_FIELD(tm_sec); H_REQUIRE_FIELD(tm_min); H_REQUIRE_FIELD(tm_hour); H_REQUIRE_FIELD(tm_mday); H_REQUIRE_FIELD(tm_mon); H_REQUIRE_FIELD(tm_year); H_REQUIRE_FIELD(tm_wday); H_REQUIRE_FIELD(tm_yday); #undef H_REQUIRE_FIELD } static void h_fail(const char *buf, const char *fmt) { struct tm tm = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, NULL }; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ ATF_CHECK_MSG(strptime(buf, fmt, &tm) == NULL, "strptime(\"%s\", " "\"%s\", &tm) should fail, but it didn't", buf, fmt); #else ATF_REQUIRE_MSG(strptime(buf, fmt, &tm) == NULL, "strptime(\"%s\", " "\"%s\", &tm) should fail, but it didn't", buf, fmt); #endif } ATF_TC(common); ATF_TC_HEAD(common, tc) { atf_tc_set_md_var(tc, "descr", "Checks strptime(3): various checks"); } ATF_TC_BODY(common, tc) { -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ atf_tc_expect_fail("There are various issues with strptime on FreeBSD"); #endif h_pass("Tue Jan 20 23:27:46 1998", "%a %b %d %T %Y", 24, 46, 27, 23, 20, 0, 98, 2, -1); h_pass("Tue Jan 20 23:27:46 1998", "%a %b %d %H:%M:%S %Y", 24, 46, 27, 23, 20, 0, 98, 2, -1); h_pass("Tue Jan 20 23:27:46 1998", "%c", 24, 46, 27, 23, 20, 0, 98, 2, -1); h_pass("Fri Mar 4 20:05:34 2005", "%a %b %e %H:%M:%S %Y", 24, 34, 5, 20, 4, 2, 105, 5, -1); h_pass("5\t3 4 8pm:05:34 2005", "%w%n%m%t%d%n%k%p:%M:%S %Y", 21, 34, 5, 20, 4, 2, 105, 5, -1); h_pass("Fri Mar 4 20:05:34 2005", "%c", 24, 34, 5, 20, 4, 2, 105, 5, -1); h_pass("x20y", "x%Cy", 4, -1, -1, -1, -1, -1, 100, -1, -1); h_pass("x84y", "x%yy", 4, -1, -1, -1, -1, -1, 84, -1, -1); h_pass("x2084y", "x%C%yy", 6, -1, -1, -1, -1, -1, 184, -1, -1); h_pass("x8420y", "x%y%Cy", 6, -1, -1, -1, -1, -1, 184, -1, -1); h_pass("%20845", "%%%C%y5", 6, -1, -1, -1, -1, -1, 184, -1, -1); h_fail("%", "%E%"); h_pass("1980", "%Y", 4, -1, -1, -1, -1, -1, 80, -1, -1); h_pass("1980", "%EY", 4, -1, -1, -1, -1, -1, 80, -1, -1); h_pass("0", "%S", 1, 0, -1, -1, -1, -1, -1, -1, -1); h_pass("59", "%S", 2, 59, -1, -1, -1, -1, -1, -1, -1); h_pass("60", "%S", 2, 60, -1, -1, -1, -1, -1, -1, -1); h_pass("61", "%S", 2, 61, -1, -1, -1, -1, -1, -1, -1); h_fail("62", "%S"); } ATF_TC(day); ATF_TC_HEAD(day, tc) { atf_tc_set_md_var(tc, "descr", "Checks strptime(3): day names"); } ATF_TC_BODY(day, tc) { h_pass("Sun", "%a", 3, -1, -1, -1, -1, -1, -1, 0, -1); h_pass("Sunday", "%a", 6, -1, -1, -1, -1, -1, -1, 0, -1); h_pass("Mon", "%a", 3, -1, -1, -1, -1, -1, -1, 1, -1); h_pass("Monday", "%a", 6, -1, -1, -1, -1, -1, -1, 1, -1); h_pass("Tue", "%a", 3, -1, -1, -1, -1, -1, -1, 2, -1); h_pass("Tuesday", "%a", 7, -1, -1, -1, -1, -1, -1, 2, -1); h_pass("Wed", "%a", 3, -1, -1, -1, -1, -1, -1, 3, -1); h_pass("Wednesday", "%a", 9, -1, -1, -1, -1, -1, -1, 3, -1); h_pass("Thu", "%a", 3, -1, -1, -1, -1, -1, -1, 4, -1); h_pass("Thursday", "%a", 8, -1, -1, -1, -1, -1, -1, 4, -1); h_pass("Fri", "%a", 3, -1, -1, -1, -1, -1, -1, 5, -1); h_pass("Friday", "%a", 6, -1, -1, -1, -1, -1, -1, 5, -1); h_pass("Sat", "%a", 3, -1, -1, -1, -1, -1, -1, 6, -1); h_pass("Saturday", "%a", 8, -1, -1, -1, -1, -1, -1, 6, -1); h_pass("Saturn", "%a", 3, -1, -1, -1, -1, -1, -1, 6, -1); h_fail("Moon", "%a"); h_pass("Sun", "%A", 3, -1, -1, -1, -1, -1, -1, 0, -1); h_pass("Sunday", "%A", 6, -1, -1, -1, -1, -1, -1, 0, -1); h_pass("Mon", "%A", 3, -1, -1, -1, -1, -1, -1, 1, -1); h_pass("Monday", "%A", 6, -1, -1, -1, -1, -1, -1, 1, -1); h_pass("Tue", "%A", 3, -1, -1, -1, -1, -1, -1, 2, -1); h_pass("Tuesday", "%A", 7, -1, -1, -1, -1, -1, -1, 2, -1); h_pass("Wed", "%A", 3, -1, -1, -1, -1, -1, -1, 3, -1); h_pass("Wednesday", "%A", 9, -1, -1, -1, -1, -1, -1, 3, -1); h_pass("Thu", "%A", 3, -1, -1, -1, -1, -1, -1, 4, -1); h_pass("Thursday", "%A", 8, -1, -1, -1, -1, -1, -1, 4, -1); h_pass("Fri", "%A", 3, -1, -1, -1, -1, -1, -1, 5, -1); h_pass("Friday", "%A", 6, -1, -1, -1, -1, -1, -1, 5, -1); h_pass("Sat", "%A", 3, -1, -1, -1, -1, -1, -1, 6, -1); h_pass("Saturday", "%A", 8, -1, -1, -1, -1, -1, -1, 6, -1); h_pass("Saturn", "%A", 3, -1, -1, -1, -1, -1, -1, 6, -1); h_fail("Moon", "%A"); h_pass("mon", "%a", 3, -1, -1, -1, -1, -1, -1, 1, -1); h_pass("tueSDay", "%A", 7, -1, -1, -1, -1, -1, -1, 2, -1); h_pass("sunday", "%A", 6, -1, -1, -1, -1, -1, -1, 0, -1); -#if defined(__NetBSD__) +#ifdef __NetBSD__ h_fail("sunday", "%EA"); #else h_pass("Sunday", "%EA", 6, -1, -1, -1, -1, -1, -1, 0, -1); #endif h_pass("SaturDay", "%A", 8, -1, -1, -1, -1, -1, -1, 6, -1); -#if defined(__NetBSD__) +#ifdef __NetBSD__ h_fail("SaturDay", "%OA"); #else h_pass("SaturDay", "%OA", 8, -1, -1, -1, -1, -1, -1, 6, -1); #endif } ATF_TC(month); ATF_TC_HEAD(month, tc) { atf_tc_set_md_var(tc, "descr", "Checks strptime(3): month names"); } ATF_TC_BODY(month, tc) { h_pass("Jan", "%b", 3, -1, -1, -1, -1, 0, -1, -1, -1); h_pass("January", "%b", 7, -1, -1, -1, -1, 0, -1, -1, -1); h_pass("Feb", "%b", 3, -1, -1, -1, -1, 1, -1, -1, -1); h_pass("February", "%b", 8, -1, -1, -1, -1, 1, -1, -1, -1); h_pass("Mar", "%b", 3, -1, -1, -1, -1, 2, -1, -1, -1); h_pass("March", "%b", 5, -1, -1, -1, -1, 2, -1, -1, -1); h_pass("Apr", "%b", 3, -1, -1, -1, -1, 3, -1, -1, -1); h_pass("April", "%b", 5, -1, -1, -1, -1, 3, -1, -1, -1); h_pass("May", "%b", 3, -1, -1, -1, -1, 4, -1, -1, -1); h_pass("Jun", "%b", 3, -1, -1, -1, -1, 5, -1, -1, -1); h_pass("June", "%b", 4, -1, -1, -1, -1, 5, -1, -1, -1); h_pass("Jul", "%b", 3, -1, -1, -1, -1, 6, -1, -1, -1); h_pass("July", "%b", 4, -1, -1, -1, -1, 6, -1, -1, -1); h_pass("Aug", "%b", 3, -1, -1, -1, -1, 7, -1, -1, -1); h_pass("August", "%b", 6, -1, -1, -1, -1, 7, -1, -1, -1); h_pass("Sep", "%b", 3, -1, -1, -1, -1, 8, -1, -1, -1); h_pass("September", "%b", 9, -1, -1, -1, -1, 8, -1, -1, -1); h_pass("Oct", "%b", 3, -1, -1, -1, -1, 9, -1, -1, -1); h_pass("October", "%b", 7, -1, -1, -1, -1, 9, -1, -1, -1); h_pass("Nov", "%b", 3, -1, -1, -1, -1, 10, -1, -1, -1); h_pass("November", "%b", 8, -1, -1, -1, -1, 10, -1, -1, -1); h_pass("Dec", "%b", 3, -1, -1, -1, -1, 11, -1, -1, -1); h_pass("December", "%b", 8, -1, -1, -1, -1, 11, -1, -1, -1); h_pass("Mayor", "%b", 3, -1, -1, -1, -1, 4, -1, -1, -1); h_pass("Mars", "%b", 3, -1, -1, -1, -1, 2, -1, -1, -1); h_fail("Rover", "%b"); h_pass("Jan", "%B", 3, -1, -1, -1, -1, 0, -1, -1, -1); h_pass("January", "%B", 7, -1, -1, -1, -1, 0, -1, -1, -1); h_pass("Feb", "%B", 3, -1, -1, -1, -1, 1, -1, -1, -1); h_pass("February", "%B", 8, -1, -1, -1, -1, 1, -1, -1, -1); h_pass("Mar", "%B", 3, -1, -1, -1, -1, 2, -1, -1, -1); h_pass("March", "%B", 5, -1, -1, -1, -1, 2, -1, -1, -1); h_pass("Apr", "%B", 3, -1, -1, -1, -1, 3, -1, -1, -1); h_pass("April", "%B", 5, -1, -1, -1, -1, 3, -1, -1, -1); h_pass("May", "%B", 3, -1, -1, -1, -1, 4, -1, -1, -1); h_pass("Jun", "%B", 3, -1, -1, -1, -1, 5, -1, -1, -1); h_pass("June", "%B", 4, -1, -1, -1, -1, 5, -1, -1, -1); h_pass("Jul", "%B", 3, -1, -1, -1, -1, 6, -1, -1, -1); h_pass("July", "%B", 4, -1, -1, -1, -1, 6, -1, -1, -1); h_pass("Aug", "%B", 3, -1, -1, -1, -1, 7, -1, -1, -1); h_pass("August", "%B", 6, -1, -1, -1, -1, 7, -1, -1, -1); h_pass("Sep", "%B", 3, -1, -1, -1, -1, 8, -1, -1, -1); h_pass("September", "%B", 9, -1, -1, -1, -1, 8, -1, -1, -1); h_pass("Oct", "%B", 3, -1, -1, -1, -1, 9, -1, -1, -1); h_pass("October", "%B", 7, -1, -1, -1, -1, 9, -1, -1, -1); h_pass("Nov", "%B", 3, -1, -1, -1, -1, 10, -1, -1, -1); h_pass("November", "%B", 8, -1, -1, -1, -1, 10, -1, -1, -1); h_pass("Dec", "%B", 3, -1, -1, -1, -1, 11, -1, -1, -1); h_pass("December", "%B", 8, -1, -1, -1, -1, 11, -1, -1, -1); h_pass("Mayor", "%B", 3, -1, -1, -1, -1, 4, -1, -1, -1); h_pass("Mars", "%B", 3, -1, -1, -1, -1, 2, -1, -1, -1); h_fail("Rover", "%B"); h_pass("september", "%b", 9, -1, -1, -1, -1, 8, -1, -1, -1); h_pass("septembe", "%B", 3, -1, -1, -1, -1, 8, -1, -1, -1); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, common); ATF_TP_ADD_TC(tp, day); ATF_TP_ADD_TC(tp, month); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/tls/dso/h_tls_dlopen.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/tls/dso/h_tls_dlopen.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/tls/dso/h_tls_dlopen.c (revision 274626) @@ -1,62 +1,62 @@ /* $NetBSD: h_tls_dlopen.c,v 1.5 2013/10/21 19:14:16 joerg Exp $ */ /*- * Copyright (c) 2011 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: h_tls_dlopen.c,v 1.5 2013/10/21 19:14:16 joerg Exp $"); #include #include -#if defined(__NetBSD__) +#ifdef __NetBSD__ #include #endif #ifdef __HAVE_NO___THREAD #define __thread #endif extern __thread int var1; extern __thread int var2; extern __thread int *var3; __thread int var5 = 1; static __thread pid_t (*local_var)(void) = getpid; void testf_dso_helper(int x, int y); void testf_dso_helper(int x, int y) { var1 = x; var2 = y; var3 = &optind; ATF_CHECK_EQ(local_var, getpid); } Index: head/contrib/netbsd-tests/lib/libc/tls/t_tls_dlopen.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/tls/t_tls_dlopen.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/tls/t_tls_dlopen.c (revision 274626) @@ -1,115 +1,115 @@ /* $NetBSD: t_tls_dlopen.c,v 1.3 2012/01/17 20:34:57 joerg Exp $ */ /*- * Copyright (c) 2011 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_tls_dlopen.c,v 1.3 2012/01/17 20:34:57 joerg Exp $"); #include #include #include #include -#if defined(__NetBSD__) +#ifdef __NetBSD__ #include #endif #ifdef __HAVE_NO___THREAD #define __thread #endif ATF_TC(t_tls_dlopen); ATF_TC_HEAD(t_tls_dlopen, tc) { atf_tc_set_md_var(tc, "descr", "Test (un)initialized TLS variables and dlopen"); } void (*testf_helper)(int, int); __thread int var1 = 1; __thread int var2; __thread int *var3 = &optind; int var4_helper; __thread int *var4 = &var4_helper; static void * testf(void *dummy) { ATF_CHECK_EQ(var1, 1); ATF_CHECK_EQ(var2, 0); ATF_CHECK_EQ(var3, &optind); ATF_CHECK_EQ(var4, &var4_helper); testf_helper(2, 2); ATF_CHECK_EQ(var1, 2); ATF_CHECK_EQ(var2, 2); testf_helper(3, 3); ATF_CHECK_EQ(var1, 3); ATF_CHECK_EQ(var2, 3); ATF_CHECK_EQ(var3, &optind); return NULL; } ATF_TC_BODY(t_tls_dlopen, tc) { void *handle; pthread_t t; #ifdef __HAVE_NO___THREAD atf_tc_skip("no TLS support on this platform"); #endif handle = dlopen("h_tls_dlopen.so", RTLD_NOW | RTLD_LOCAL); ATF_REQUIRE(handle != NULL); testf_helper = dlsym(handle, "testf_dso_helper"); ATF_REQUIRE(testf_helper != NULL); testf(NULL); pthread_create(&t, 0, testf, 0); pthread_join(t, NULL); pthread_create(&t, 0, testf, 0); pthread_join(t, NULL); dlclose(handle); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, t_tls_dlopen); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/tls/t_tls_dynamic.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/tls/t_tls_dynamic.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/tls/t_tls_dynamic.c (revision 274626) @@ -1,107 +1,107 @@ /* $NetBSD: t_tls_dynamic.c,v 1.3 2012/01/17 20:34:57 joerg Exp $ */ /*- * Copyright (c) 2011 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_tls_dynamic.c,v 1.3 2012/01/17 20:34:57 joerg Exp $"); #include #include #include -#if defined(__NetBSD__) +#ifdef __NetBSD__ #include #endif #ifdef __HAVE_NO___THREAD #define __thread #endif ATF_TC(t_tls_dynamic); ATF_TC_HEAD(t_tls_dynamic, tc) { atf_tc_set_md_var(tc, "descr", "Test (un)initialized TLS variables in dynamic binaries"); } void testf_dso_helper(int, int); extern __thread int var1; extern __thread int var2; extern __thread pid_t (*dso_var1)(void); __thread int *var3 = &optind; int var4_helper; __thread int *var4 = &var4_helper; static void * testf(void *dummy) { ATF_CHECK_EQ(var1, 1); ATF_CHECK_EQ(var2, 0); testf_dso_helper(2, 2); ATF_CHECK_EQ(var1, 2); ATF_CHECK_EQ(var2, 2); testf_dso_helper(3, 3); ATF_CHECK_EQ(var1, 3); ATF_CHECK_EQ(var2, 3); ATF_CHECK_EQ(var3, &optind); ATF_CHECK_EQ(var4, &var4_helper); ATF_CHECK_EQ(dso_var1, getpid); return NULL; } ATF_TC_BODY(t_tls_dynamic, tc) { pthread_t t; #ifdef __HAVE_NO___THREAD atf_tc_skip("no TLS support on this platform"); #endif testf(NULL); pthread_create(&t, 0, testf, 0); pthread_join(t, NULL); pthread_create(&t, 0, testf, 0); pthread_join(t, NULL); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, t_tls_dynamic); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/tls/t_tls_static.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/tls/t_tls_static.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/tls/t_tls_static.c (revision 274626) @@ -1,95 +1,95 @@ /* $NetBSD: t_tls_static.c,v 1.2 2012/01/17 20:34:57 joerg Exp $ */ /*- * Copyright (c) 2011 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_tls_static.c,v 1.2 2012/01/17 20:34:57 joerg Exp $"); #include #include -#if defined(__NetBSD__) +#ifdef __NetBSD__ #include #endif #ifdef __HAVE_NO___THREAD #define __thread #endif ATF_TC(t_tls_static); ATF_TC_HEAD(t_tls_static, tc) { atf_tc_set_md_var(tc, "descr", "Test (un)initialized TLS variables in static binaries"); } void testf_helper(void); __thread int var1 = 1; __thread int var2; static void * testf(void *dummy) { ATF_CHECK_EQ(var1, 1); ATF_CHECK_EQ(var2, 0); testf_helper(); ATF_CHECK_EQ(var1, -1); ATF_CHECK_EQ(var2, -1); return NULL; } ATF_TC_BODY(t_tls_static, tc) { pthread_t t; #ifdef __HAVE_NO___THREAD atf_tc_skip("no TLS support on this platform"); #endif testf(NULL); pthread_create(&t, 0, testf, 0); pthread_join(t, NULL); pthread_create(&t, 0, testf, 0); pthread_join(t, NULL); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, t_tls_static); return atf_no_error(); } Index: head/contrib/netbsd-tests/lib/libc/tls/t_tls_static_helper.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/tls/t_tls_static_helper.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/tls/t_tls_static_helper.c (revision 274626) @@ -1,55 +1,55 @@ /* $NetBSD: t_tls_static_helper.c,v 1.2 2012/01/17 20:34:57 joerg Exp $ */ /*- * Copyright (c) 2011 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_tls_static_helper.c,v 1.2 2012/01/17 20:34:57 joerg Exp $"); -#if defined(__NetBSD__) +#ifdef __NetBSD__ #include #endif #ifdef __HAVE_NO___THREAD #define __thread #endif extern __thread int var1; extern __thread int var2; void testf_helper(void); void testf_helper(void) { var1 = -1; var2 = -1; } Index: head/contrib/netbsd-tests/lib/libc/tls_dso/h_tls_dynamic.c =================================================================== --- head/contrib/netbsd-tests/lib/libc/tls_dso/h_tls_dynamic.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libc/tls_dso/h_tls_dynamic.c (revision 274626) @@ -1,58 +1,58 @@ /* $NetBSD: h_tls_dynamic.c,v 1.5 2013/10/21 19:11:17 joerg Exp $ */ /*- * Copyright (c) 2011 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: h_tls_dynamic.c,v 1.5 2013/10/21 19:11:17 joerg Exp $"); #include -#if defined(__NetBSD__) +#ifdef __NetBSD__ #include #endif #ifdef __HAVE_NO___THREAD #define __thread #endif __thread int var1 = 1; __thread int var2; __thread pid_t (*dso_var1)(void) = getpid; void testf_dso_helper(int x, int y); void testf_dso_helper(int x, int y) { var1 = x; var2 = y; } Index: head/contrib/netbsd-tests/lib/libpthread/h_atexit.c =================================================================== --- head/contrib/netbsd-tests/lib/libpthread/h_atexit.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libpthread/h_atexit.c (revision 274626) @@ -1,203 +1,203 @@ /* $NetBSD: h_atexit.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ /* * Copyright (c) 2008 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. */ /* * Program to test atexit(3) and __cxa_atexit()/__cxa_finalize(). * * Written by Jason R. Thorpe, February 2003. * Public domain. */ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: h_atexit.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); #include #include #include #include #include extern int __cxa_atexit(void (*func)(void *), void *, void *); extern void __cxa_finalize(void *); #ifdef __FreeBSD__ /* * See comments in ../../lib/libc/stdlib/h_atexit.c about the deviation * between FreeBSD and NetBSD with this helper program */ static void *dso_handle_1 = (void *)1; static void *dso_handle_2 = (void *)2; static void *dso_handle_3 = (void *)3; #else static int dso_handle_1; static int dso_handle_2; static int dso_handle_3; #endif static int arg_1; static int arg_2; static int arg_3; static int exiting_state; #define ASSERT(expr) \ do { \ if ((expr) == 0) { \ write(STDERR_FILENO, __func__, strlen(__func__)); \ write(STDERR_FILENO, ": ", 2); \ write(STDERR_FILENO, __STRING(expr), \ strlen(__STRING(expr))); \ write(STDERR_FILENO, "\n", 1); \ my_abort(); \ } \ } while (/*CONSTCOND*/0) #define SUCCESS() \ do { \ write(STDOUT_FILENO, __func__, strlen(__func__)); \ write(STDOUT_FILENO, "\n", 1); \ } while (/*CONSTCOND*/0) static void my_abort(void) { kill(getpid(), SIGABRT); /* NOTREACHED */ } static void cxa_handler_5(void *arg) { static int cxa_handler_5_called; ASSERT(arg == (void *)&arg_1); ASSERT(cxa_handler_5_called == 0); ASSERT(exiting_state == 5); exiting_state--; cxa_handler_5_called = 1; SUCCESS(); } static void cxa_handler_4(void *arg) { static int cxa_handler_4_called; ASSERT(arg == (void *)&arg_1); ASSERT(cxa_handler_4_called == 0); ASSERT(exiting_state == 4); exiting_state--; cxa_handler_4_called = 1; SUCCESS(); } static void cxa_handler_3(void *arg) { static int cxa_handler_3_called; ASSERT(arg == (void *)&arg_2); ASSERT(cxa_handler_3_called == 0); ASSERT(exiting_state == 3); exiting_state--; cxa_handler_3_called = 1; SUCCESS(); } static void cxa_handler_2(void *arg) { static int cxa_handler_2_called; ASSERT(arg == (void *)&arg_3); ASSERT(cxa_handler_2_called == 0); ASSERT(exiting_state == 2); exiting_state--; cxa_handler_2_called = 1; SUCCESS(); } static void normal_handler_1(void) { static int normal_handler_1_called; ASSERT(normal_handler_1_called == 0); ASSERT(exiting_state == 1); exiting_state--; normal_handler_1_called = 1; SUCCESS(); } static void normal_handler_0(void) { static int normal_handler_0_called; ASSERT(normal_handler_0_called == 0); ASSERT(exiting_state == 0); normal_handler_0_called = 1; SUCCESS(); } int main(int argc, char *argv[]) { exiting_state = 5; -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ ASSERT(0 == atexit(normal_handler_0)); ASSERT(0 == atexit(normal_handler_1)); ASSERT(0 == __cxa_atexit(cxa_handler_4, &arg_1, dso_handle_1)); ASSERT(0 == __cxa_atexit(cxa_handler_5, &arg_1, dso_handle_1)); ASSERT(0 == __cxa_atexit(cxa_handler_3, &arg_2, dso_handle_2)); ASSERT(0 == __cxa_atexit(cxa_handler_2, &arg_3, dso_handle_3)); __cxa_finalize(dso_handle_1); __cxa_finalize(dso_handle_2); #else ASSERT(0 == __cxa_atexit(cxa_handler_4, &arg_1, &dso_handle_1)); ASSERT(0 == __cxa_atexit(cxa_handler_5, &arg_1, &dso_handle_1)); ASSERT(0 == __cxa_atexit(cxa_handler_3, &arg_2, &dso_handle_2)); ASSERT(0 == __cxa_atexit(cxa_handler_2, &arg_3, &dso_handle_3)); __cxa_finalize(&dso_handle_1); __cxa_finalize(&dso_handle_2); #endif exit(0); } Index: head/contrib/netbsd-tests/lib/libpthread/t_detach.c =================================================================== --- head/contrib/netbsd-tests/lib/libpthread/t_detach.c (revision 274625) +++ head/contrib/netbsd-tests/lib/libpthread/t_detach.c (revision 274626) @@ -1,95 +1,95 @@ /* $NetBSD: t_detach.c,v 1.1 2011/03/24 13:52:04 jruoho 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_detach.c,v 1.1 2011/03/24 13:52:04 jruoho Exp $"); #include #include #include #include "h_common.h" static void *func(void *); static void * func(void *arg) { return NULL; } ATF_TC(pthread_detach); ATF_TC_HEAD(pthread_detach, tc) { atf_tc_set_md_var(tc, "descr", "A test of pthread_detach(3)"); } ATF_TC_BODY(pthread_detach, tc) { const int state = PTHREAD_CREATE_JOINABLE; pthread_attr_t attr; pthread_t t; int rv; /* * Create a joinable thread. */ PTHREAD_REQUIRE(pthread_attr_init(&attr)); PTHREAD_REQUIRE(pthread_attr_setdetachstate(&attr, state)); PTHREAD_REQUIRE(pthread_create(&t, &attr, func, NULL)); /* * Detach the thread and try to * join it; EINVAL should follow. */ PTHREAD_REQUIRE(pthread_detach(t)); rv = pthread_join(t, NULL); ATF_REQUIRE(rv == EINVAL); -#if defined(__FreeBSD__) +#ifdef __FreeBSD__ atf_tc_expect_fail("PR # 191906: fails with EINVAL, not ESRCH"); #endif /* * As usual, ESRCH should follow if * we try to detach an invalid thread. */ rv = pthread_cancel(NULL); ATF_REQUIRE(rv == ESRCH); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, pthread_detach); return atf_no_error(); }