Index: vendor/NetBSD/tests/dist/lib/libc/gen/t_dir.c =================================================================== --- vendor/NetBSD/tests/dist/lib/libc/gen/t_dir.c (revision 311964) +++ vendor/NetBSD/tests/dist/lib/libc/gen/t_dir.c (revision 311965) @@ -1,178 +1,188 @@ -/* $NetBSD: t_dir.c,v 1.8 2017/01/11 07:26:17 christos Exp $ */ +/* $NetBSD: t_dir.c,v 1.10 2017/01/11 18:15:02 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include ATF_TC(seekdir_basic); ATF_TC_HEAD(seekdir_basic, tc) { atf_tc_set_md_var(tc, "descr", "Check telldir(3) and seekdir(3) " "for correct behavior (PR lib/24324)"); } ATF_TC_BODY(seekdir_basic, tc) { DIR *dp; char *wasname; struct dirent *entry; long here; #define CREAT(x, m) do { \ int _creat_fd; \ - ATF_REQUIRE_MSG((_creat_fd = creat((x), (m)) != -1), \ + ATF_REQUIRE_MSG((_creat_fd = creat((x), (m))) != -1, \ "creat(%s, %x) failed: %s", (x), (m), \ strerror(errno)); \ (void)close(_creat_fd); \ } while(0); ATF_REQUIRE_MSG(mkdir("t", 0755) == 0, "mkdir failed: %s", strerror(errno)); CREAT("t/a", 0600); CREAT("t/b", 0600); CREAT("t/c", 0600); dp = opendir("t"); if ( dp == NULL) atf_tc_fail("Could not open temp directory."); /* skip two for . and .. */ entry = readdir(dp); + ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s", + ".", strerror(errno)); + entry = readdir(dp); + ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s", + "..", strerror(errno)); /* get first entry */ entry = readdir(dp); + ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s", + "first", strerror(errno)); + here = telldir(dp); - ATF_REQUIRE_MSG(here != -1, - "telldir failed: %s", strerror(errno)); + ATF_REQUIRE_MSG(here != -1, "telldir failed: %s", strerror(errno)); /* get second entry */ entry = readdir(dp); + ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s", + "second", strerror(errno)); + wasname = strdup(entry->d_name); if (wasname == NULL) atf_tc_fail("cannot allocate memory"); /* get third entry */ entry = readdir(dp); + ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s", + "third", strerror(errno)); /* try to return to the position after the first entry */ seekdir(dp, here); entry = readdir(dp); - - if (entry == NULL) - atf_tc_fail("entry 1 not found"); + ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s", + "first[1]", strerror(errno)); if (strcmp(entry->d_name, wasname) != 0) atf_tc_fail("1st seekdir found wrong name"); /* try again, and throw in a telldir() for good measure */ seekdir(dp, here); here = telldir(dp); entry = readdir(dp); - - if (entry == NULL) - atf_tc_fail("entry 2 not found"); + ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s", + "second[1]", strerror(errno)); if (strcmp(entry->d_name, wasname) != 0) atf_tc_fail("2nd seekdir found wrong name"); /* One more time, to make sure that telldir() doesn't affect result */ seekdir(dp, here); entry = readdir(dp); + ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s", + "third[1]", strerror(errno)); - if (entry == NULL) - atf_tc_fail("entry 3 not found"); if (strcmp(entry->d_name, wasname) != 0) atf_tc_fail("3rd seekdir found wrong name"); closedir(dp); free(wasname); } ATF_TC(telldir_leak); ATF_TC_HEAD(telldir_leak, tc) { atf_tc_set_md_var(tc, "descr", "Check telldir(3) for memory leakage (PR lib/24324)"); } ATF_TC_BODY(telldir_leak, tc) { DIR *dp; char *memused; int i; int oktouse = 4096; dp = opendir("."); if (dp == NULL) atf_tc_fail("Could not open current directory"); (void)telldir(dp); memused = sbrk(0); closedir(dp); for (i = 0; i < 1000; i++) { dp = opendir("."); if (dp == NULL) atf_tc_fail("Could not open current directory"); (void)telldir(dp); closedir(dp); if ((char *)sbrk(0) - memused > oktouse) { (void)printf("Used %td extra bytes for %d telldir " "calls", ((char *)sbrk(0) - memused), i); oktouse = (char *)sbrk(0) - memused; } } if (oktouse > 4096) { atf_tc_fail("Failure: leaked %d bytes", oktouse); } else { (void)printf("OK: used %td bytes\n", (char *)(sbrk(0))-memused); } } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, seekdir_basic); ATF_TP_ADD_TC(tp, telldir_leak); return atf_no_error(); } Index: vendor/NetBSD/tests/dist/lib/libc/string/t_memcpy.c =================================================================== --- vendor/NetBSD/tests/dist/lib/libc/string/t_memcpy.c (revision 311964) +++ vendor/NetBSD/tests/dist/lib/libc/string/t_memcpy.c (revision 311965) @@ -1,150 +1,151 @@ -/* $NetBSD: t_memcpy.c,v 1.5 2013/03/17 02:23:31 christos Exp $ */ +/* $NetBSD: t_memcpy.c,v 1.6 2017/01/11 18:05:54 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]; const char goodResult[] = "7b405d24bc03195474c70ddae9e1f8fb"; 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; srandom(0L); 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_REQUIRE_EQ_MSG(strcmp(result, goodResult), 0, "%s != %s", + result, goodResult); } 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: vendor/NetBSD/tests/dist/lib/libc/string/t_memmem.c =================================================================== --- vendor/NetBSD/tests/dist/lib/libc/string/t_memmem.c (revision 311964) +++ vendor/NetBSD/tests/dist/lib/libc/string/t_memmem.c (revision 311965) @@ -1,100 +1,103 @@ -/* $NetBSD: t_memmem.c,v 1.2 2011/07/07 08:27:36 jruoho Exp $ */ +/* $NetBSD: t_memmem.c,v 1.3 2017/01/11 18:07:37 christos Exp $ */ /*- * Copyright (c) 2005 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Perry E. Metzger of Metzger, Dowdeswell & Co. LLC. * * 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 char p0[] = ""; int lp0 = 0; char p1[] = "0123"; int lp1 = 4; char p2[] = "456"; int lp2 = 3; char p3[] = "789"; int lp3 = 3; char p4[] = "abc"; int lp4 = 3; char p5[] = "0"; int lp5 = 1; char p6[] = "9"; int lp6 = 1; char p7[] = "654"; int lp7 = 3; +char p8[] = "89abc"; +int lp8 = 5; char b0[] = ""; int lb0 = 0; char b1[] = "0"; int lb1 = 1; char b2[] = "0123456789"; int lb2 = 10; #define expect(b) \ if (!(b)) { \ fprintf(stderr, "failed on line %d\n", __LINE__); \ atf_tc_fail("Check stderr for test id/line"); \ } ATF_TC(memmem_basic); ATF_TC_HEAD(memmem_basic, tc) { atf_tc_set_md_var(tc, "descr", "Test memmem results"); } ATF_TC_BODY(memmem_basic, tc) { expect(memmem(b2, lb2, p0, lp0) == b2); expect(memmem(b0, lb0, p0, lp0) == b0); expect(memmem(b0, lb0, p1, lp1) == NULL); expect(memmem(b1, lb1, p1, lp1) == NULL); expect(memmem(b2, lb2, p1, lp1) == b2); expect(memmem(b2, lb2, p2, lp2) == (b2 + 4)); expect(memmem(b2, lb2, p3, lp3) == (b2 + 7)); expect(memmem(b2, lb2, p5, lp5) == b2); expect(memmem(b2, lb2, p6, lp6) == (b2 + 9)); expect(memmem(b2, lb2, p4, lp4) == NULL); expect(memmem(b2, lb2, p7, lp7) == NULL); + expect(memmem(b2, lb2, p8, lp8) == NULL); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, memmem_basic); return atf_no_error(); }