diff options
Diffstat (limited to 'src/regress/lib/libc')
139 files changed, 9732 insertions, 0 deletions
diff --git a/src/regress/lib/libc/Makefile b/src/regress/lib/libc/Makefile new file mode 100644 index 0000000000..d05c583efc --- /dev/null +++ b/src/regress/lib/libc/Makefile | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.32 2010/08/23 22:34:37 millert Exp $ | ||
| 2 | |||
| 3 | SUBDIR+= _setjmp alloca atexit basename cxa-atexit db dirname fnmatch | ||
| 4 | SUBDIR+= fpclassify getaddrinfo getcap getopt_long glob hsearch longjmp | ||
| 5 | SUBDIR+= locale malloc netdb popen printf regex setjmp setjmp-signal | ||
| 6 | SUBDIR+= sigreturn sigsetjmp sprintf strerror strtod strtonum telldir time vis | ||
| 7 | SUBDIR+= orientation stdio_threading mkstemp env | ||
| 8 | |||
| 9 | .if (${MACHINE_ARCH} != "vax") | ||
| 10 | SUBDIR+= ieeefp | ||
| 11 | .endif | ||
| 12 | |||
| 13 | .if exists(arch/${MACHINE_ARCH}) | ||
| 14 | SUBDIR+= arch/${MACHINE_ARCH} | ||
| 15 | .endif | ||
| 16 | |||
| 17 | install: | ||
| 18 | |||
| 19 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/_setjmp/Makefile b/src/regress/lib/libc/_setjmp/Makefile new file mode 100644 index 0000000000..5d58242523 --- /dev/null +++ b/src/regress/lib/libc/_setjmp/Makefile | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2002/01/01 23:00:51 art Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.2 1995/04/20 22:38:44 cgd Exp $ | ||
| 3 | |||
| 4 | PROG= _setjmptest | ||
| 5 | SRCS= jmptest.c | ||
| 6 | |||
| 7 | CFLAGS+= -DTEST_U_SETJMP | ||
| 8 | |||
| 9 | .PATH: ${.CURDIR}/../setjmp | ||
| 10 | |||
| 11 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/alloca/Makefile b/src/regress/lib/libc/alloca/Makefile new file mode 100644 index 0000000000..f31417cda7 --- /dev/null +++ b/src/regress/lib/libc/alloca/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2003/02/12 06:49:04 mickey Exp $ | ||
| 2 | |||
| 3 | PROG= alloca | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/alloca/alloca.c b/src/regress/lib/libc/alloca/alloca.c new file mode 100644 index 0000000000..54fa90edae --- /dev/null +++ b/src/regress/lib/libc/alloca/alloca.c | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | /* $OpenBSD: alloca.c,v 1.7 2004/03/10 01:17:45 deraadt Exp $ */ | ||
| 2 | |||
| 3 | /* Written by Michael Shalayeff, 2003, Public Domain. */ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <string.h> | ||
| 8 | |||
| 9 | int | ||
| 10 | main(int argc, char *argv[]) | ||
| 11 | { | ||
| 12 | char *q, *p; | ||
| 13 | |||
| 14 | p = alloca(41); | ||
| 15 | strlcpy(p, "hellow world", 41); | ||
| 16 | |||
| 17 | q = alloca(53); | ||
| 18 | strlcpy(q, "hellow world", 53); | ||
| 19 | |||
| 20 | exit(strcmp(p, q)); | ||
| 21 | } | ||
diff --git a/src/regress/lib/libc/arch/alpha/Makefile b/src/regress/lib/libc/arch/alpha/Makefile new file mode 100644 index 0000000000..8c4dfb735c --- /dev/null +++ b/src/regress/lib/libc/arch/alpha/Makefile | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2002/02/23 01:25:11 art Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.1 1995/04/24 05:53:31 cgd Exp $ | ||
| 3 | |||
| 4 | # do nothing here; none of the tests here can be run automatically | ||
| 5 | SUBDIR= | ||
| 6 | |||
| 7 | install: | ||
| 8 | |||
| 9 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/Makefile b/src/regress/lib/libc/arch/alpha/divremtest/Makefile new file mode 100644 index 0000000000..1da3ac8494 --- /dev/null +++ b/src/regress/lib/libc/arch/alpha/divremtest/Makefile | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2001/01/29 02:05:39 niklas Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.1 1995/04/24 05:53:34 cgd Exp $ | ||
| 3 | |||
| 4 | PROG= divremtest | ||
| 5 | NOMAN= | ||
| 6 | |||
| 7 | CLEANFILES+= mkcases cases.c mktestcases testcases | ||
| 8 | |||
| 9 | divremtest.c: cases.c | ||
| 10 | |||
| 11 | cases.c: mkcases | ||
| 12 | /bin/rm -f cases.c | ||
| 13 | mkcases > cases.c | ||
| 14 | |||
| 15 | # a typical strategy to use this: | ||
| 16 | # compile a NetBSD divremtest binary, an OSF/1 divremtest binary, and an | ||
| 17 | # OSF/1 mktestcases binary. You then run mktestecases | divremtest -g | ||
| 18 | # on an OSF/1 machine, and pipe the output to an rsh to a NetBSD machine | ||
| 19 | # which then runs divremtest. You can test an infinite number of random | ||
| 20 | # values that way; I like to put a 'dd' in, so I can see how much I've done. | ||
| 21 | |||
| 22 | testcases: mktestcases divremtest | ||
| 23 | /bin/rm -f testcases | ||
| 24 | mktestcases | divremtest -g > testcases | ||
| 25 | |||
| 26 | regress: | ||
| 27 | @echo THIS TEST CANNOT BE RUN AUTOMATICALLY. | ||
| 28 | @false | ||
| 29 | |||
| 30 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c b/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c new file mode 100644 index 0000000000..3d9e8a6de2 --- /dev/null +++ b/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c | |||
| @@ -0,0 +1,184 @@ | |||
| 1 | /* $OpenBSD: divremtest.c,v 1.2 2001/01/29 02:05:39 niklas Exp $ */ | ||
| 2 | /* $NetBSD: divremtest.c,v 1.1 1995/04/24 05:53:35 cgd Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed by Christopher G. Demetriou | ||
| 19 | * for the NetBSD Project. | ||
| 20 | * 4. The name of the author may not be used to endorse or promote products | ||
| 21 | * derived from this software without specific prior written permission | ||
| 22 | * | ||
| 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 33 | */ | ||
| 34 | |||
| 35 | #include <stdio.h> | ||
| 36 | #include <unistd.h> | ||
| 37 | #include <signal.h> | ||
| 38 | |||
| 39 | void testfile(); | ||
| 40 | void usage(); | ||
| 41 | |||
| 42 | int generate; | ||
| 43 | |||
| 44 | int | ||
| 45 | main(argc, argv) | ||
| 46 | int argc; | ||
| 47 | char **argv; | ||
| 48 | { | ||
| 49 | int c; | ||
| 50 | |||
| 51 | signal(SIGFPE, SIG_IGN); | ||
| 52 | |||
| 53 | while ((c = getopt(argc, argv, "g")) != -1) | ||
| 54 | switch (c) { | ||
| 55 | case 'g': | ||
| 56 | generate = 1; | ||
| 57 | break; | ||
| 58 | |||
| 59 | default: | ||
| 60 | usage(); | ||
| 61 | break; | ||
| 62 | } | ||
| 63 | |||
| 64 | argc -= optind; | ||
| 65 | argv += optind; | ||
| 66 | |||
| 67 | if (argc == 0) | ||
| 68 | testfile(); | ||
| 69 | else | ||
| 70 | for (; argc != 0; argc--, argv++) { | ||
| 71 | if (freopen(argv[0], "r", stdin) == NULL) { | ||
| 72 | fprintf(stderr, | ||
| 73 | "divremtest: couldn't open %s\n", | ||
| 74 | argv[0]); | ||
| 75 | exit(1); | ||
| 76 | } | ||
| 77 | |||
| 78 | testfile(); | ||
| 79 | } | ||
| 80 | |||
| 81 | exit(0); | ||
| 82 | } | ||
| 83 | |||
| 84 | void | ||
| 85 | testfile() | ||
| 86 | { | ||
| 87 | union operand { | ||
| 88 | unsigned long input; | ||
| 89 | int op_int; | ||
| 90 | unsigned int op_u_int; | ||
| 91 | long op_long; | ||
| 92 | unsigned long op_u_long; | ||
| 93 | } op1, op2, divres, modres, divwant, modwant; | ||
| 94 | char opspec[6]; | ||
| 95 | int encoded, i; | ||
| 96 | |||
| 97 | while (scanf("%6c %lx %lx %lx %lx\n", opspec, &op1.input, | ||
| 98 | &op2.input, &divwant.input, &modwant.input) != EOF) { | ||
| 99 | |||
| 100 | encoded = 0; | ||
| 101 | |||
| 102 | for (i = 0; i < 6; i += 2) { | ||
| 103 | int posval; | ||
| 104 | |||
| 105 | switch (opspec[i]) { | ||
| 106 | case '.': | ||
| 107 | posval = 0; | ||
| 108 | break; | ||
| 109 | case '-': | ||
| 110 | posval = 1; | ||
| 111 | break; | ||
| 112 | default: | ||
| 113 | fprintf(stderr, | ||
| 114 | "unknown signedness spec %c\n", | ||
| 115 | opspec[i]); | ||
| 116 | exit(1); | ||
| 117 | } | ||
| 118 | encoded |= posval << ((5 - i) * 4); | ||
| 119 | } | ||
| 120 | |||
| 121 | for (i = 1; i < 6; i += 2) { | ||
| 122 | int posval; | ||
| 123 | |||
| 124 | switch (opspec[i]) { | ||
| 125 | case 'i': | ||
| 126 | posval = 0; | ||
| 127 | break; | ||
| 128 | case 'l': | ||
| 129 | posval = 1; | ||
| 130 | break; | ||
| 131 | default: | ||
| 132 | fprintf(stderr, "unknown length spec %c\n", | ||
| 133 | opspec[i]); | ||
| 134 | exit(1); | ||
| 135 | } | ||
| 136 | encoded |= posval << ((5 - i) * 4); | ||
| 137 | } | ||
| 138 | |||
| 139 | /* KILL ME!!! */ | ||
| 140 | switch (encoded) { | ||
| 141 | |||
| 142 | #define TRY_IT(a, b, c) \ | ||
| 143 | divres.a = op1.b / op2.c; \ | ||
| 144 | modres.a = op1.b % op2.c; \ | ||
| 145 | if (generate) { \ | ||
| 146 | printf("%6s 0x%016lx 0x%016lx 0x%016lx 0x%016lx\n", \ | ||
| 147 | opspec, op1.input, op2.input, \ | ||
| 148 | divres.a, modres.a); \ | ||
| 149 | } else { \ | ||
| 150 | if ((divres.a != divwant.a) || \ | ||
| 151 | (modres.a != modwant.a)) { \ | ||
| 152 | fprintf(stderr, "%6s 0x%016lx 0x%016lx\n", \ | ||
| 153 | opspec, op1.input, op2.input); \ | ||
| 154 | fprintf(stderr, "FAILED:\n"); \ | ||
| 155 | fprintf(stderr, \ | ||
| 156 | "div:\twanted 0x%16lx, got 0x%16lx\n", \ | ||
| 157 | divwant.a, divres.a); \ | ||
| 158 | fprintf(stderr, \ | ||
| 159 | "mod:\twanted 0x%16lx, got 0x%16lx\n", \ | ||
| 160 | modwant.a, modres.a); \ | ||
| 161 | \ | ||
| 162 | exit(1); \ | ||
| 163 | } \ | ||
| 164 | } | ||
| 165 | |||
| 166 | #include "cases.c" | ||
| 167 | |||
| 168 | #undef TRY_IT | ||
| 169 | |||
| 170 | default: | ||
| 171 | fprintf(stderr, | ||
| 172 | "INTERNAL ERROR: unknown encoding %x\n", encoded); | ||
| 173 | exit(1); | ||
| 174 | } | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | void | ||
| 179 | usage() | ||
| 180 | { | ||
| 181 | |||
| 182 | fprintf(stderr, "usage: divremtest [-v] [testfile ...]\n"); | ||
| 183 | exit(1); | ||
| 184 | } | ||
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/mkcases.c b/src/regress/lib/libc/arch/alpha/divremtest/mkcases.c new file mode 100644 index 0000000000..fcb4765b8c --- /dev/null +++ b/src/regress/lib/libc/arch/alpha/divremtest/mkcases.c | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | /* $OpenBSD: mkcases.c,v 1.2 2001/01/29 02:05:39 niklas Exp $ */ | ||
| 2 | /* $NetBSD: mkcases.c,v 1.1 1995/04/24 05:53:36 cgd Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed by Christopher G. Demetriou | ||
| 19 | * for the NetBSD Project. | ||
| 20 | * 4. The name of the author may not be used to endorse or promote products | ||
| 21 | * derived from this software without specific prior written permission | ||
| 22 | * | ||
| 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 33 | */ | ||
| 34 | |||
| 35 | char *tab[4] = { "u_int", "int", "u_long", "long" }; | ||
| 36 | |||
| 37 | int | ||
| 38 | main() | ||
| 39 | { | ||
| 40 | int i; | ||
| 41 | |||
| 42 | for (i = 0; i < 64; i++) { | ||
| 43 | printf( | ||
| 44 | " case 0x%d%d%d%d%d%d: /* %s <= %s op %s */\n", | ||
| 45 | (i >> 5) & 1, | ||
| 46 | (i >> 4) & 1, | ||
| 47 | (i >> 3) & 1, | ||
| 48 | (i >> 2) & 1, | ||
| 49 | (i >> 1) & 1, | ||
| 50 | (i >> 0) & 1, | ||
| 51 | tab[(i >> 4) & 0x3], | ||
| 52 | tab[(i >> 2) & 0x3], | ||
| 53 | tab[(i >> 0) & 0x3]); | ||
| 54 | printf( | ||
| 55 | " TRY_IT(op_%s, op_%s, op_%s);\n", | ||
| 56 | tab[(i >> 4) & 0x3], | ||
| 57 | tab[(i >> 2) & 0x3], | ||
| 58 | tab[(i >> 0) & 0x3]); | ||
| 59 | printf( | ||
| 60 | " break;\n\n"); | ||
| 61 | } | ||
| 62 | |||
| 63 | exit(0); | ||
| 64 | } | ||
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c b/src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c new file mode 100644 index 0000000000..3b01653f32 --- /dev/null +++ b/src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | /* $OpenBSD: mktestcases.c,v 1.2 2001/01/29 02:05:40 niklas Exp $ */ | ||
| 2 | /* $NetBSD: mktestcases.c,v 1.1 1995/04/24 05:53:37 cgd Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed by Christopher G. Demetriou | ||
| 19 | * for the NetBSD Project. | ||
| 20 | * 4. The name of the author may not be used to endorse or promote products | ||
| 21 | * derived from this software without specific prior written permission | ||
| 22 | * | ||
| 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 33 | */ | ||
| 34 | |||
| 35 | #include <stdio.h> | ||
| 36 | |||
| 37 | int | ||
| 38 | main() | ||
| 39 | { | ||
| 40 | int i, j; | ||
| 41 | unsigned long n1, n2; | ||
| 42 | |||
| 43 | srandom(time(NULL)); | ||
| 44 | |||
| 45 | for (i = 1; /* i < 10240 */ 1; i++) { | ||
| 46 | n1 = (unsigned) | ||
| 47 | (random() & ((random() & random()) | 0x80000000)); | ||
| 48 | n1 <<= 32; | ||
| 49 | n1 |= (unsigned)(random() & random() & random()); | ||
| 50 | |||
| 51 | n2 = (unsigned) | ||
| 52 | (random() & ((random() & random()) | 0x80000000)); | ||
| 53 | n2 <<= 32; | ||
| 54 | n2 |= (unsigned)(random() & random() & random()); | ||
| 55 | |||
| 56 | for (j = 0; j < 64; j++) { | ||
| 57 | char *tab[] = { ".i", ".l", "-i", "-l" }; | ||
| 58 | |||
| 59 | printf("%s%s%s 0x%lx 0x%lx 0 0\n", | ||
| 60 | tab[(j >> 4) & 0x3], | ||
| 61 | tab[(j >> 2) & 0x3], | ||
| 62 | tab[(j >> 0) & 0x3], | ||
| 63 | n1, n2); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | exit(0); | ||
| 68 | } | ||
diff --git a/src/regress/lib/libc/atexit/Makefile b/src/regress/lib/libc/atexit/Makefile new file mode 100644 index 0000000000..c14b3c7ac4 --- /dev/null +++ b/src/regress/lib/libc/atexit/Makefile | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2003/07/31 22:46:59 david Exp $ | ||
| 2 | |||
| 3 | NOMAN= | ||
| 4 | PROG=atexit_test | ||
| 5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
| 6 | CLEANFILES+= invalid.out valid.out | ||
| 7 | |||
| 8 | run-regress-atexit_test: ${PROG} | ||
| 9 | ./${PROG} -valid 2>${.OBJDIR}/valid.out | ||
| 10 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok | ||
| 11 | ./${PROG} -invalid-atexit 2>${.OBJDIR}/invalid.out | ||
| 12 | cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok | ||
| 13 | ./${PROG} -invalid-cleanup 2>${.OBJDIR}/invalid.out | ||
| 14 | cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok | ||
| 15 | |||
| 16 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/atexit/atexit_test.c b/src/regress/lib/libc/atexit/atexit_test.c new file mode 100644 index 0000000000..3dd0b62c3e --- /dev/null +++ b/src/regress/lib/libc/atexit/atexit_test.c | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | /* $OpenBSD: atexit_test.c,v 1.6 2007/09/03 14:42:44 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2002 Daniel Hartmeier | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * | ||
| 11 | * - Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * - Redistributions in binary form must reproduce the above | ||
| 14 | * copyright notice, this list of conditions and the following | ||
| 15 | * disclaimer in the documentation and/or other materials provided | ||
| 16 | * with the distribution. | ||
| 17 | * | ||
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| 28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | * | ||
| 31 | * Effort sponsored in part by the Defense Advanced Research Projects | ||
| 32 | * Agency (DARPA) and Air Force Research Laboratory, Air Force | ||
| 33 | * Materiel Command, USAF, under agreement number F30602-01-2-0537. | ||
| 34 | * | ||
| 35 | */ | ||
| 36 | |||
| 37 | #include <stdio.h> | ||
| 38 | #include <stdlib.h> | ||
| 39 | #include <string.h> | ||
| 40 | #include <signal.h> | ||
| 41 | #include "stdlib/atexit.h" | ||
| 42 | |||
| 43 | void handle_first(void); | ||
| 44 | void handle_middle(void); | ||
| 45 | void handle_last(void); | ||
| 46 | void handle_invalid(void); | ||
| 47 | void handle_cleanup(void); | ||
| 48 | void handle_signal(int); | ||
| 49 | |||
| 50 | static int counter; | ||
| 51 | |||
| 52 | int | ||
| 53 | main(int argc, char *argv[]) | ||
| 54 | { | ||
| 55 | int i; | ||
| 56 | |||
| 57 | if (argc != 2 || (strcmp(argv[1], "-valid") && | ||
| 58 | strcmp(argv[1], "-invalid-atexit") && | ||
| 59 | strcmp(argv[1], "-invalid-cleanup"))) { | ||
| 60 | fprintf(stderr, "%s -valid/-invalid-atexit/-invalid-cleanup\n", | ||
| 61 | argv[0]); | ||
| 62 | return (1); | ||
| 63 | } | ||
| 64 | fprintf(stderr, "main()\n"); | ||
| 65 | if (atexit(handle_last)) { | ||
| 66 | perror("atexit(handle_last) failed"); | ||
| 67 | return (1); | ||
| 68 | } | ||
| 69 | for (i = 0; i < 65535; ++i) { | ||
| 70 | if (atexit(handle_middle)) { | ||
| 71 | perror("atexit(handle_middle) failed"); | ||
| 72 | return (1); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | if (atexit(handle_first)) { | ||
| 76 | perror("atexit(handle_first) failed"); | ||
| 77 | return (1); | ||
| 78 | } | ||
| 79 | /* this is supposed to segfault */ | ||
| 80 | if (!strcmp(argv[1], "-invalid-atexit")) { | ||
| 81 | signal(SIGSEGV, handle_signal); | ||
| 82 | __atexit->fns[0].fn_ptr.std_func = handle_invalid; | ||
| 83 | } else if (!strcmp(argv[1], "-invalid-cleanup")) { | ||
| 84 | struct atexit *p = __atexit; | ||
| 85 | |||
| 86 | signal(SIGSEGV, handle_signal); | ||
| 87 | while (p != NULL && p->next != NULL) | ||
| 88 | p = p->next; | ||
| 89 | if (p == NULL) | ||
| 90 | fprintf(stderr, "p == NULL, no page found\n"); | ||
| 91 | p->fns[0].fn_ptr.std_func = handle_invalid; | ||
| 92 | } | ||
| 93 | __atexit_register_cleanup(handle_cleanup); | ||
| 94 | counter = 0; | ||
| 95 | fprintf(stderr, "main() returns\n"); | ||
| 96 | return (0); | ||
| 97 | } | ||
| 98 | |||
| 99 | void | ||
| 100 | handle_first(void) | ||
| 101 | { | ||
| 102 | fprintf(stderr, "handle_first() counter == %i\n", counter); | ||
| 103 | } | ||
| 104 | |||
| 105 | void | ||
| 106 | handle_middle(void) | ||
| 107 | { | ||
| 108 | counter++; | ||
| 109 | } | ||
| 110 | |||
| 111 | void | ||
| 112 | handle_last(void) | ||
| 113 | { | ||
| 114 | fprintf(stderr, "handle_last() counter == %i\n", counter); | ||
| 115 | } | ||
| 116 | |||
| 117 | void | ||
| 118 | handle_cleanup(void) | ||
| 119 | { | ||
| 120 | fprintf(stderr, "handle_cleanup()\n"); | ||
| 121 | } | ||
| 122 | |||
| 123 | void | ||
| 124 | handle_invalid(void) | ||
| 125 | { | ||
| 126 | fprintf(stderr, "handle_invalid() THIS SHOULD HAVE SEGFAULTED INSTEAD!\n"); | ||
| 127 | } | ||
| 128 | |||
| 129 | void | ||
| 130 | handle_signal(int sigraised) | ||
| 131 | { | ||
| 132 | switch (sigraised) { | ||
| 133 | case SIGSEGV: | ||
| 134 | fprintf(stderr, "SIGSEGV\n"); | ||
| 135 | exit(0); | ||
| 136 | default: | ||
| 137 | fprintf(stderr, "unexpected signal caught\n"); | ||
| 138 | exit(1); | ||
| 139 | } | ||
| 140 | } | ||
diff --git a/src/regress/lib/libc/atexit/invalid.ok b/src/regress/lib/libc/atexit/invalid.ok new file mode 100644 index 0000000000..98cbf8c1de --- /dev/null +++ b/src/regress/lib/libc/atexit/invalid.ok | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | main() | ||
| 2 | SIGSEGV | ||
| 3 | handle_first() counter == 0 | ||
| 4 | handle_last() counter == 65535 | ||
diff --git a/src/regress/lib/libc/atexit/valid.ok b/src/regress/lib/libc/atexit/valid.ok new file mode 100644 index 0000000000..6509e827a7 --- /dev/null +++ b/src/regress/lib/libc/atexit/valid.ok | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | main() | ||
| 2 | main() returns | ||
| 3 | handle_first() counter == 0 | ||
| 4 | handle_last() counter == 65535 | ||
| 5 | handle_cleanup() | ||
diff --git a/src/regress/lib/libc/basename/Makefile b/src/regress/lib/libc/basename/Makefile new file mode 100644 index 0000000000..958b06fd11 --- /dev/null +++ b/src/regress/lib/libc/basename/Makefile | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | PROG=basename_test | ||
| 2 | |||
| 3 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/basename/basename_test.c b/src/regress/lib/libc/basename/basename_test.c new file mode 100644 index 0000000000..34e138c726 --- /dev/null +++ b/src/regress/lib/libc/basename/basename_test.c | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2007 Bret S. Lambert <blambert@gsipt.net> | ||
| 3 | * | ||
| 4 | * Public domain. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <sys/param.h> | ||
| 8 | |||
| 9 | #include <libgen.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <string.h> | ||
| 12 | #include <limits.h> | ||
| 13 | #include <errno.h> | ||
| 14 | |||
| 15 | int | ||
| 16 | main(void) | ||
| 17 | { | ||
| 18 | char path[2 * MAXPATHLEN]; | ||
| 19 | const char *dir = "junk/"; | ||
| 20 | const char *fname = "file.name.ext"; | ||
| 21 | char *str; | ||
| 22 | int i; | ||
| 23 | |||
| 24 | /* Test normal functioning */ | ||
| 25 | strlcpy(path, "/", sizeof(path)); | ||
| 26 | strlcat(path, dir, sizeof(path)); | ||
| 27 | strlcat(path, fname, sizeof(path)); | ||
| 28 | str = basename(path); | ||
| 29 | if (strcmp(str, fname) != 0) | ||
| 30 | goto fail; | ||
| 31 | |||
| 32 | /* | ||
| 33 | * There are four states that require special handling: | ||
| 34 | * | ||
| 35 | * 1) path is NULL | ||
| 36 | * 2) path is the empty string | ||
| 37 | * 3) path is composed entirely of slashes | ||
| 38 | * 4) the resulting name is larger than MAXPATHLEN | ||
| 39 | * | ||
| 40 | * The first two cases require that a pointer | ||
| 41 | * to the string "." be returned. | ||
| 42 | * | ||
| 43 | * The third case requires that a pointer | ||
| 44 | * to the string "/" be returned. | ||
| 45 | * | ||
| 46 | * The final case requires that NULL be returned | ||
| 47 | * and errno * be set to ENAMETOOLONG. | ||
| 48 | */ | ||
| 49 | /* Case 1 */ | ||
| 50 | str = basename(NULL); | ||
| 51 | if (strcmp(str, ".") != 0) | ||
| 52 | goto fail; | ||
| 53 | |||
| 54 | /* Case 2 */ | ||
| 55 | strlcpy(path, "", sizeof(path)); | ||
| 56 | str = basename(path); | ||
| 57 | if (strcmp(str, ".") != 0) | ||
| 58 | goto fail; | ||
| 59 | |||
| 60 | /* Case 3 */ | ||
| 61 | for (i = 0; i < MAXPATHLEN - 1; i++) | ||
| 62 | strlcat(path, "/", sizeof(path)); /* path cleared above */ | ||
| 63 | str = basename(path); | ||
| 64 | if (strcmp(str, "/") != 0) | ||
| 65 | goto fail; | ||
| 66 | |||
| 67 | /* Case 4 */ | ||
| 68 | strlcpy(path, "/", sizeof(path)); | ||
| 69 | strlcat(path, dir, sizeof(path)); | ||
| 70 | for (i = 0; i <= MAXPATHLEN; i += sizeof(fname)) | ||
| 71 | strlcat(path, fname, sizeof(path)); | ||
| 72 | str = basename(path); | ||
| 73 | if (str != NULL || errno != ENAMETOOLONG) | ||
| 74 | goto fail; | ||
| 75 | |||
| 76 | return (0); | ||
| 77 | fail: | ||
| 78 | return (1); | ||
| 79 | } | ||
diff --git a/src/regress/lib/libc/cxa-atexit/Makefile b/src/regress/lib/libc/cxa-atexit/Makefile new file mode 100644 index 0000000000..5061ca04ac --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/Makefile | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2010/05/10 18:20:31 drahn Exp $ | ||
| 2 | |||
| 3 | .include <bsd.own.mk> | ||
| 4 | |||
| 5 | |||
| 6 | .if ${COMPILER_VERSION:L} == "gcc3" || ${COMPILER_VERSION:L} == "gcc4" | ||
| 7 | SUBDIR+= libgd1 libgd2 test1 | ||
| 8 | .endif | ||
| 9 | |||
| 10 | install: | ||
| 11 | |||
| 12 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd1/Makefile b/src/regress/lib/libc/cxa-atexit/libgd1/Makefile new file mode 100644 index 0000000000..958b726d28 --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/libgd1/Makefile | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2007/09/03 14:42:44 millert Exp $ | ||
| 2 | |||
| 3 | LIB=gd1 | ||
| 4 | SRCS= gd1.C | ||
| 5 | NOPROFILE=yes | ||
| 6 | |||
| 7 | regress: all | ||
| 8 | |||
| 9 | .include <bsd.lib.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd1/gd1.C b/src/regress/lib/libc/cxa-atexit/libgd1/gd1.C new file mode 100644 index 0000000000..b3ecd56d91 --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/libgd1/gd1.C | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | /* $OpenBSD: gd1.C,v 1.1 2007/09/03 14:42:44 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <stdio.h> | ||
| 20 | |||
| 21 | extern int check1; | ||
| 22 | |||
| 23 | struct global_destructor_test_obj1 { | ||
| 24 | inline ~global_destructor_test_obj1() { | ||
| 25 | check1 = 0; | ||
| 26 | } | ||
| 27 | }; | ||
| 28 | |||
| 29 | extern "C" void gd_test1() | ||
| 30 | { | ||
| 31 | static global_destructor_test_obj1 gdt; | ||
| 32 | } | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd1/shlib_version b/src/regress/lib/libc/cxa-atexit/libgd1/shlib_version new file mode 100644 index 0000000000..97c9f92d6b --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/libgd1/shlib_version | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | major=0 | ||
| 2 | minor=0 | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd2/Makefile b/src/regress/lib/libc/cxa-atexit/libgd2/Makefile new file mode 100644 index 0000000000..7ca21d8bd2 --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/libgd2/Makefile | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2007/09/03 14:42:44 millert Exp $ | ||
| 2 | |||
| 3 | LIB=gd2 | ||
| 4 | SRCS= gd2.C | ||
| 5 | NOPROFILE=yes | ||
| 6 | |||
| 7 | regress: all | ||
| 8 | |||
| 9 | .include <bsd.lib.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd2/gd2.C b/src/regress/lib/libc/cxa-atexit/libgd2/gd2.C new file mode 100644 index 0000000000..69e7ffb220 --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/libgd2/gd2.C | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | /* $OpenBSD: gd2.C,v 1.1 2007/09/03 14:42:44 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <stdio.h> | ||
| 20 | |||
| 21 | extern int check2; | ||
| 22 | |||
| 23 | struct global_destructor_test_obj2 { | ||
| 24 | inline ~global_destructor_test_obj2() { | ||
| 25 | check2 = 0; | ||
| 26 | } | ||
| 27 | }; | ||
| 28 | |||
| 29 | extern "C" void gd_test2() | ||
| 30 | { | ||
| 31 | static global_destructor_test_obj2 gdt; | ||
| 32 | } | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd2/shlib_version b/src/regress/lib/libc/cxa-atexit/libgd2/shlib_version new file mode 100644 index 0000000000..97c9f92d6b --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/libgd2/shlib_version | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | major=0 | ||
| 2 | minor=0 | ||
diff --git a/src/regress/lib/libc/cxa-atexit/test1/Makefile b/src/regress/lib/libc/cxa-atexit/test1/Makefile new file mode 100644 index 0000000000..533392d144 --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/test1/Makefile | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2007/09/03 14:42:44 millert Exp $ | ||
| 2 | |||
| 3 | .include <bsd.obj.mk> | ||
| 4 | |||
| 5 | GD1_DIR=${.CURDIR}/../libgd1 | ||
| 6 | GD1_OBJDIR!= if [ -d $(GD1_DIR)/${__objdir} ]; then \ | ||
| 7 | echo "$(GD1_DIR)/${__objdir}"; \ | ||
| 8 | else \ | ||
| 9 | echo "$(GD1_DIR)"; \ | ||
| 10 | fi | ||
| 11 | |||
| 12 | GD2_DIR=${.CURDIR}/../libgd2 | ||
| 13 | GD2_OBJDIR!= if [ -d $(GD2_DIR)/${__objdir} ]; then \ | ||
| 14 | echo "$(GD2_DIR)/${__objdir}"; \ | ||
| 15 | else \ | ||
| 16 | echo "$(GD2_DIR)"; \ | ||
| 17 | fi | ||
| 18 | |||
| 19 | PROG= test1 | ||
| 20 | |||
| 21 | SRCS= test1.C | ||
| 22 | |||
| 23 | CFLAGS+= -DLIBGD1="\"$(GD1_OBJDIR)/libgd1.so\"" | ||
| 24 | CFLAGS+= -DLIBGD2="\"$(GD2_OBJDIR)/libgd2.so\"" | ||
| 25 | LDFLAGS+= -Wl,-E | ||
| 26 | |||
| 27 | NOMAN= | ||
| 28 | |||
| 29 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/test1/test1.C b/src/regress/lib/libc/cxa-atexit/test1/test1.C new file mode 100644 index 0000000000..75fb967a90 --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/test1/test1.C | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | /* $OpenBSD: test1.C,v 1.1 2007/09/03 14:42:44 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <dlfcn.h> | ||
| 20 | #include <err.h> | ||
| 21 | #include <stdio.h> | ||
| 22 | |||
| 23 | int check1, check2; | ||
| 24 | |||
| 25 | int | ||
| 26 | main() | ||
| 27 | { | ||
| 28 | void *libgd1, *libgd2; | ||
| 29 | void (*gd_test)(); | ||
| 30 | int i; | ||
| 31 | |||
| 32 | for (i=0; i < 50; i++) { | ||
| 33 | check1 = check2 = 1; | ||
| 34 | |||
| 35 | libgd1 = dlopen(LIBGD1, RTLD_LAZY); | ||
| 36 | if (libgd1 == NULL) | ||
| 37 | errx(1, "dlopen(%s, RTLD_LAZY) FAILED\n", LIBGD1); | ||
| 38 | |||
| 39 | gd_test = (void (*)())dlsym(libgd1, "gd_test1"); | ||
| 40 | if (gd_test == NULL) | ||
| 41 | errx(1, "dlsym(libgd1, \"gd_test1\") FAILED\n"); | ||
| 42 | |||
| 43 | (*gd_test)(); | ||
| 44 | |||
| 45 | libgd2 = dlopen(LIBGD2, RTLD_LAZY); | ||
| 46 | if (libgd2 == NULL) | ||
| 47 | errx(1, "dlopen(%s, RTLD_LAZY) FAILED\n", LIBGD2); | ||
| 48 | |||
| 49 | gd_test = (void (*)())dlsym(libgd2, "gd_test2"); | ||
| 50 | if (gd_test == NULL) | ||
| 51 | errx(1, "dlsym(libgd2, \"gd_test2\") FAILED\n"); | ||
| 52 | |||
| 53 | (*gd_test)(); | ||
| 54 | |||
| 55 | dlclose(libgd1); | ||
| 56 | dlclose(libgd2); | ||
| 57 | |||
| 58 | if (check1 || check2) | ||
| 59 | errx(1, "global destructors not called\n"); | ||
| 60 | } | ||
| 61 | |||
| 62 | return (0); | ||
| 63 | } | ||
diff --git a/src/regress/lib/libc/db/Makefile b/src/regress/lib/libc/db/Makefile new file mode 100644 index 0000000000..7d2882594d --- /dev/null +++ b/src/regress/lib/libc/db/Makefile | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.10 2002/09/02 20:01:43 avsm Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.11 1995/12/12 01:54:15 cgd Exp $ | ||
| 3 | |||
| 4 | PROG= dbtest | ||
| 5 | |||
| 6 | # add -DSTATISTICS to CFLAGS to get usage statistics. Note that | ||
| 7 | # for this to work, libc must be compiled with -DSTATISTICS as well | ||
| 8 | CFLAGS+= -g -D__DBINTERFACE_PRIVATE -DDEBUG | ||
| 9 | CLEANFILES+= t1 t2 t3 log | ||
| 10 | |||
| 11 | DBTARGETS=1 2 3 4 5 6 7 8 9 10 11 12 13 20 | ||
| 12 | |||
| 13 | .for DT in ${DBTARGETS} | ||
| 14 | db-${DT}: ${PROG} | ||
| 15 | sh ${.CURDIR}/run.test ${DT} | ||
| 16 | REGRESS_TARGETS+=db-${DT} | ||
| 17 | .PHONY: db-${DT} | ||
| 18 | .endfor | ||
| 19 | |||
| 20 | REGRESS_SLOW_TARGETS+=db-3 db-12 db-20 | ||
| 21 | |||
| 22 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/db/README b/src/regress/lib/libc/db/README new file mode 100644 index 0000000000..23a1b77221 --- /dev/null +++ b/src/regress/lib/libc/db/README | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | # $OpenBSD: README,v 1.3 2001/01/29 02:05:40 niklas Exp $ | ||
| 2 | # $NetBSD: README,v 1.5 1996/05/03 21:54:19 cgd Exp $ | ||
| 3 | # @(#)README 8.8 (Berkeley) 7/31/94 | ||
| 4 | |||
| 5 | To run the tests, enter "make regress". | ||
| 6 | |||
| 7 | Fairly large files (the command files) are built in this directory during | ||
| 8 | the test runs, and even larger files (the database files) are created in | ||
| 9 | "/var/tmp". If the latter directory doesn't exist, set the environmental | ||
| 10 | variable TMPDIR to a directory where the files can be built. | ||
| 11 | |||
| 12 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||
| 13 | The script file consists of lines with an initial character which is | ||
| 14 | the command for that line, or an initial character indicating a key | ||
| 15 | or data entry for a previous command. | ||
| 16 | |||
| 17 | Legal command characters are as follows: | ||
| 18 | |||
| 19 | c: compare a record | ||
| 20 | + must be followed by [kK][dD]; the data value in the database | ||
| 21 | associated with the specified key is compared to the specified | ||
| 22 | data value. | ||
| 23 | e: echo a string | ||
| 24 | + writes out the rest of the line into the output file; if the | ||
| 25 | last character is not a carriage-return, a newline is appended. | ||
| 26 | f: set the flags for the next command | ||
| 27 | + no value zero's the flags | ||
| 28 | g: do a get command | ||
| 29 | + must be followed by [kK] | ||
| 30 | + writes out the retrieved data DBT. | ||
| 31 | o [r]: dump [reverse] | ||
| 32 | + dump the database out, if 'r' is set, in reverse order. | ||
| 33 | p: do a put command | ||
| 34 | + must be followed by [kK][dD] | ||
| 35 | r: do a del command | ||
| 36 | + must be followed by [kK] unless R_CURSOR flag set. | ||
| 37 | S: sync the database | ||
| 38 | s: do a seq command | ||
| 39 | + must be followed by [kK] if R_CURSOR flag set. | ||
| 40 | + writes out the retrieved data DBT. | ||
| 41 | |||
| 42 | Legal key/data characters are as follows: | ||
| 43 | |||
| 44 | D [file]: data file | ||
| 45 | + set the current data value to the contents of the file | ||
| 46 | d [data]: | ||
| 47 | + set the current key value to the contents of the line. | ||
| 48 | K [file]: key file | ||
| 49 | + set the current key value to the contents of the file | ||
| 50 | k [data]: | ||
| 51 | + set the current key value to the contents of the line. | ||
| 52 | |||
| 53 | Blank lines, lines with leading white space, and lines with leading | ||
| 54 | hash marks (#) are ignored. | ||
| 55 | |||
| 56 | Options to dbtest are as follows: | ||
| 57 | |||
| 58 | -d: Set the DB_LOCK flag. | ||
| 59 | -f: Use the file argument as the database file. | ||
| 60 | -i: Use the rest of the argument to set elements in the info | ||
| 61 | structure. If the type is btree, then "-i cachesize=10240" | ||
| 62 | will set BTREEINFO.cachesize to 10240. | ||
| 63 | -o: The rest of the argument is the output file instead of | ||
| 64 | using stdout. | ||
| 65 | -s: Don't delete the database file before opening it, i.e. | ||
| 66 | use the database file from a previous run. | ||
| 67 | |||
| 68 | Dbtest requires two arguments, the type of access "hash", "recno" | ||
| 69 | or "btree", and the script name or "-" to indicate stdin. | ||
diff --git a/src/regress/lib/libc/db/dbtest.c b/src/regress/lib/libc/db/dbtest.c new file mode 100644 index 0000000000..c28ec0db5e --- /dev/null +++ b/src/regress/lib/libc/db/dbtest.c | |||
| @@ -0,0 +1,733 @@ | |||
| 1 | /* $OpenBSD: dbtest.c,v 1.12 2009/10/27 23:59:32 deraadt Exp $ */ | ||
| 2 | /* $NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $ */ | ||
| 3 | |||
| 4 | /*- | ||
| 5 | * Copyright (c) 1992, 1993, 1994 | ||
| 6 | * The Regents of the University of California. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. Neither the name of the University nor the names of its contributors | ||
| 17 | * may be used to endorse or promote products derived from this software | ||
| 18 | * without specific prior written permission. | ||
| 19 | * | ||
| 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 30 | * SUCH DAMAGE. | ||
| 31 | */ | ||
| 32 | |||
| 33 | #include <sys/param.h> | ||
| 34 | #include <sys/stat.h> | ||
| 35 | |||
| 36 | #include <ctype.h> | ||
| 37 | #include <errno.h> | ||
| 38 | #include <fcntl.h> | ||
| 39 | #include <limits.h> | ||
| 40 | #include <stdio.h> | ||
| 41 | #include <stdlib.h> | ||
| 42 | #include <string.h> | ||
| 43 | #include <stdarg.h> | ||
| 44 | #include <unistd.h> | ||
| 45 | |||
| 46 | #include <db.h> | ||
| 47 | |||
| 48 | enum S { COMMAND, COMPARE, GET, PUT, REMOVE, SEQ, SEQFLAG, KEY, DATA }; | ||
| 49 | |||
| 50 | void compare(DBT *, DBT *); | ||
| 51 | DBTYPE dbtype(char *); | ||
| 52 | void dump(DB *, int); | ||
| 53 | void dberr(const char *, ...); | ||
| 54 | void get(DB *, DBT *); | ||
| 55 | void getdata(DB *, DBT *, DBT *); | ||
| 56 | void put(DB *, DBT *, DBT *); | ||
| 57 | void rem(DB *, DBT *); | ||
| 58 | char *sflags(int); | ||
| 59 | void synk(DB *); | ||
| 60 | void *rfile(char *, size_t *); | ||
| 61 | void seq(DB *, DBT *); | ||
| 62 | u_int setflags(char *); | ||
| 63 | void *setinfo(DBTYPE, char *); | ||
| 64 | void usage(void); | ||
| 65 | void *xmalloc(char *, size_t); | ||
| 66 | |||
| 67 | DBTYPE type; /* Database type. */ | ||
| 68 | void *infop; /* Iflags. */ | ||
| 69 | u_long lineno; /* Current line in test script. */ | ||
| 70 | u_int flags; /* Current DB flags. */ | ||
| 71 | int ofd = STDOUT_FILENO; /* Standard output fd. */ | ||
| 72 | |||
| 73 | DB *XXdbp; /* Global for gdb. */ | ||
| 74 | int XXlineno; /* Fast breakpoint for gdb. */ | ||
| 75 | |||
| 76 | int | ||
| 77 | main(int argc, char *argv[]) | ||
| 78 | { | ||
| 79 | extern int optind; | ||
| 80 | extern char *optarg; | ||
| 81 | enum S command, state; | ||
| 82 | DB *dbp; | ||
| 83 | DBT data, key, keydata; | ||
| 84 | size_t len; | ||
| 85 | int ch, oflags, sflag; | ||
| 86 | char *fname, *infoarg, *p, *t, buf[8 * 1024]; | ||
| 87 | |||
| 88 | infoarg = NULL; | ||
| 89 | fname = NULL; | ||
| 90 | oflags = O_CREAT | O_RDWR; | ||
| 91 | sflag = 0; | ||
| 92 | while ((ch = getopt(argc, argv, "f:i:lo:s")) != -1) | ||
| 93 | switch (ch) { | ||
| 94 | case 'f': | ||
| 95 | fname = optarg; | ||
| 96 | break; | ||
| 97 | case 'i': | ||
| 98 | infoarg = optarg; | ||
| 99 | break; | ||
| 100 | case 'l': | ||
| 101 | oflags |= DB_LOCK; | ||
| 102 | break; | ||
| 103 | case 'o': | ||
| 104 | if ((ofd = open(optarg, | ||
| 105 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) | ||
| 106 | dberr("%s: %s", optarg, strerror(errno)); | ||
| 107 | break; | ||
| 108 | case 's': | ||
| 109 | sflag = 1; | ||
| 110 | break; | ||
| 111 | case '?': | ||
| 112 | default: | ||
| 113 | usage(); | ||
| 114 | } | ||
| 115 | argc -= optind; | ||
| 116 | argv += optind; | ||
| 117 | |||
| 118 | if (argc != 2) | ||
| 119 | usage(); | ||
| 120 | |||
| 121 | /* Set the type. */ | ||
| 122 | type = dbtype(*argv++); | ||
| 123 | |||
| 124 | /* Open the descriptor file. */ | ||
| 125 | if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL) | ||
| 126 | dberr("%s: %s", *argv, strerror(errno)); | ||
| 127 | |||
| 128 | /* Set up the db structure as necessary. */ | ||
| 129 | if (infoarg == NULL) | ||
| 130 | infop = NULL; | ||
| 131 | else | ||
| 132 | for (p = strtok(infoarg, ",\t "); p != NULL; | ||
| 133 | p = strtok(0, ",\t ")) | ||
| 134 | if (*p != '\0') | ||
| 135 | infop = setinfo(type, p); | ||
| 136 | |||
| 137 | /* | ||
| 138 | * Open the DB. Delete any preexisting copy, you almost never | ||
| 139 | * want it around, and it often screws up tests. | ||
| 140 | */ | ||
| 141 | if (fname == NULL) { | ||
| 142 | p = getenv("TMPDIR"); | ||
| 143 | if (p == NULL) | ||
| 144 | p = "/var/tmp"; | ||
| 145 | (void)snprintf(buf, sizeof buf, "%s/__dbtest", p); | ||
| 146 | fname = buf; | ||
| 147 | (void)unlink(buf); | ||
| 148 | } else if (!sflag) | ||
| 149 | (void)unlink(fname); | ||
| 150 | |||
| 151 | if ((dbp = dbopen(fname, | ||
| 152 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) | ||
| 153 | dberr("dbopen: %s", strerror(errno)); | ||
| 154 | XXdbp = dbp; | ||
| 155 | |||
| 156 | state = COMMAND; | ||
| 157 | for (lineno = 1; | ||
| 158 | (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { | ||
| 159 | /* Delete the newline, displaying the key/data is easier. */ | ||
| 160 | if (ofd == STDOUT_FILENO && (t = strchr(p, '\n')) != NULL) | ||
| 161 | *t = '\0'; | ||
| 162 | if ((len = strlen(buf)) == 0 || isspace(*p) || *p == '#') | ||
| 163 | continue; | ||
| 164 | |||
| 165 | /* Convenient gdb break point. */ | ||
| 166 | if (XXlineno == lineno) | ||
| 167 | XXlineno = 1; | ||
| 168 | switch (*p) { | ||
| 169 | case 'c': /* compare */ | ||
| 170 | if (state != COMMAND) | ||
| 171 | dberr("line %lu: not expecting command", | ||
| 172 | lineno); | ||
| 173 | state = KEY; | ||
| 174 | command = COMPARE; | ||
| 175 | break; | ||
| 176 | case 'e': /* echo */ | ||
| 177 | if (state != COMMAND) | ||
| 178 | dberr("line %lu: not expecting command", | ||
| 179 | lineno); | ||
| 180 | /* Don't display the newline, if CR at EOL. */ | ||
| 181 | if (p[len - 2] == '\r') | ||
| 182 | --len; | ||
| 183 | if (write(ofd, p + 1, len - 1) != len - 1 || | ||
| 184 | write(ofd, "\n", 1) != 1) | ||
| 185 | dberr("write: %s", strerror(errno)); | ||
| 186 | break; | ||
| 187 | case 'g': /* get */ | ||
| 188 | if (state != COMMAND) | ||
| 189 | dberr("line %lu: not expecting command", | ||
| 190 | lineno); | ||
| 191 | state = KEY; | ||
| 192 | command = GET; | ||
| 193 | break; | ||
| 194 | case 'p': /* put */ | ||
| 195 | if (state != COMMAND) | ||
| 196 | dberr("line %lu: not expecting command", | ||
| 197 | lineno); | ||
| 198 | state = KEY; | ||
| 199 | command = PUT; | ||
| 200 | break; | ||
| 201 | case 'r': /* remove */ | ||
| 202 | if (state != COMMAND) | ||
| 203 | dberr("line %lu: not expecting command", | ||
| 204 | lineno); | ||
| 205 | if (flags == R_CURSOR) { | ||
| 206 | rem(dbp, &key); | ||
| 207 | state = COMMAND; | ||
| 208 | } else { | ||
| 209 | state = KEY; | ||
| 210 | command = REMOVE; | ||
| 211 | } | ||
| 212 | break; | ||
| 213 | case 'S': /* sync */ | ||
| 214 | if (state != COMMAND) | ||
| 215 | dberr("line %lu: not expecting command", | ||
| 216 | lineno); | ||
| 217 | synk(dbp); | ||
| 218 | state = COMMAND; | ||
| 219 | break; | ||
| 220 | case 's': /* seq */ | ||
| 221 | if (state != COMMAND) | ||
| 222 | dberr("line %lu: not expecting command", | ||
| 223 | lineno); | ||
| 224 | if (flags == R_CURSOR) { | ||
| 225 | state = KEY; | ||
| 226 | command = SEQ; | ||
| 227 | } else | ||
| 228 | seq(dbp, &key); | ||
| 229 | break; | ||
| 230 | case 'f': | ||
| 231 | flags = setflags(p + 1); | ||
| 232 | break; | ||
| 233 | case 'D': /* data file */ | ||
| 234 | if (state != DATA) | ||
| 235 | dberr("line %lu: not expecting data", lineno); | ||
| 236 | data.data = rfile(p + 1, &data.size); | ||
| 237 | goto ldata; | ||
| 238 | case 'd': /* data */ | ||
| 239 | if (state != DATA) | ||
| 240 | dberr("line %lu: not expecting data", lineno); | ||
| 241 | data.data = xmalloc(p + 1, len - 1); | ||
| 242 | data.size = len - 1; | ||
| 243 | ldata: switch (command) { | ||
| 244 | case COMPARE: | ||
| 245 | compare(&keydata, &data); | ||
| 246 | break; | ||
| 247 | case PUT: | ||
| 248 | put(dbp, &key, &data); | ||
| 249 | break; | ||
| 250 | default: | ||
| 251 | dberr("line %lu: command doesn't take data", | ||
| 252 | lineno); | ||
| 253 | } | ||
| 254 | if (type != DB_RECNO) | ||
| 255 | free(key.data); | ||
| 256 | free(data.data); | ||
| 257 | state = COMMAND; | ||
| 258 | break; | ||
| 259 | case 'K': /* key file */ | ||
| 260 | if (state != KEY) | ||
| 261 | dberr("line %lu: not expecting a key", lineno); | ||
| 262 | if (type == DB_RECNO) | ||
| 263 | dberr("line %lu: 'K' not available for recno", | ||
| 264 | lineno); | ||
| 265 | key.data = rfile(p + 1, &key.size); | ||
| 266 | goto lkey; | ||
| 267 | case 'k': /* key */ | ||
| 268 | if (state != KEY) | ||
| 269 | dberr("line %lu: not expecting a key", lineno); | ||
| 270 | if (type == DB_RECNO) { | ||
| 271 | static recno_t recno; | ||
| 272 | recno = atoi(p + 1); | ||
| 273 | key.data = &recno; | ||
| 274 | key.size = sizeof(recno); | ||
| 275 | } else { | ||
| 276 | key.data = xmalloc(p + 1, len - 1); | ||
| 277 | key.size = len - 1; | ||
| 278 | } | ||
| 279 | lkey: switch (command) { | ||
| 280 | case COMPARE: | ||
| 281 | getdata(dbp, &key, &keydata); | ||
| 282 | state = DATA; | ||
| 283 | break; | ||
| 284 | case GET: | ||
| 285 | get(dbp, &key); | ||
| 286 | if (type != DB_RECNO) | ||
| 287 | free(key.data); | ||
| 288 | state = COMMAND; | ||
| 289 | break; | ||
| 290 | case PUT: | ||
| 291 | state = DATA; | ||
| 292 | break; | ||
| 293 | case REMOVE: | ||
| 294 | rem(dbp, &key); | ||
| 295 | if ((type != DB_RECNO) && (flags != R_CURSOR)) | ||
| 296 | free(key.data); | ||
| 297 | state = COMMAND; | ||
| 298 | break; | ||
| 299 | case SEQ: | ||
| 300 | seq(dbp, &key); | ||
| 301 | if ((type != DB_RECNO) && (flags != R_CURSOR)) | ||
| 302 | free(key.data); | ||
| 303 | state = COMMAND; | ||
| 304 | break; | ||
| 305 | default: | ||
| 306 | dberr("line %lu: command doesn't take a key", | ||
| 307 | lineno); | ||
| 308 | } | ||
| 309 | break; | ||
| 310 | case 'o': | ||
| 311 | dump(dbp, p[1] == 'r'); | ||
| 312 | break; | ||
| 313 | default: | ||
| 314 | dberr("line %lu: %s: unknown command character", | ||
| 315 | lineno, p); | ||
| 316 | } | ||
| 317 | } | ||
| 318 | #ifdef STATISTICS | ||
| 319 | /* | ||
| 320 | * -l must be used (DB_LOCK must be set) for this to be | ||
| 321 | * used, otherwise a page will be locked and it will fail. | ||
| 322 | */ | ||
| 323 | if (type == DB_BTREE && oflags & DB_LOCK) | ||
| 324 | __bt_stat(dbp); | ||
| 325 | #endif | ||
| 326 | if (dbp->close(dbp)) | ||
| 327 | dberr("db->close: %s", strerror(errno)); | ||
| 328 | (void)close(ofd); | ||
| 329 | exit(0); | ||
| 330 | } | ||
| 331 | |||
| 332 | #define NOOVERWRITE "put failed, would overwrite key\n" | ||
| 333 | |||
| 334 | void | ||
| 335 | compare(db1, db2) | ||
| 336 | DBT *db1, *db2; | ||
| 337 | { | ||
| 338 | register size_t len; | ||
| 339 | register u_char *p1, *p2; | ||
| 340 | |||
| 341 | if (db1->size != db2->size) | ||
| 342 | printf("compare failed: key->data len %lu != data len %lu\n", | ||
| 343 | db1->size, db2->size); | ||
| 344 | |||
| 345 | len = MIN(db1->size, db2->size); | ||
| 346 | for (p1 = db1->data, p2 = db2->data; len--;) | ||
| 347 | if (*p1++ != *p2++) { | ||
| 348 | printf("compare failed at offset %d\n", | ||
| 349 | p1 - (u_char *)db1->data); | ||
| 350 | break; | ||
| 351 | } | ||
| 352 | } | ||
| 353 | |||
| 354 | void | ||
| 355 | get(dbp, kp) | ||
| 356 | DB *dbp; | ||
| 357 | DBT *kp; | ||
| 358 | { | ||
| 359 | DBT data; | ||
| 360 | |||
| 361 | switch (dbp->get(dbp, kp, &data, flags)) { | ||
| 362 | case 0: | ||
| 363 | (void)write(ofd, data.data, data.size); | ||
| 364 | if (ofd == STDOUT_FILENO) | ||
| 365 | (void)write(ofd, "\n", 1); | ||
| 366 | break; | ||
| 367 | case -1: | ||
| 368 | dberr("line %lu: get: %s", lineno, strerror(errno)); | ||
| 369 | /* NOTREACHED */ | ||
| 370 | case 1: | ||
| 371 | #define NOSUCHKEY "get failed, no such key\n" | ||
| 372 | if (ofd != STDOUT_FILENO) | ||
| 373 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
| 374 | else | ||
| 375 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
| 376 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
| 377 | #undef NOSUCHKEY | ||
| 378 | break; | ||
| 379 | } | ||
| 380 | } | ||
| 381 | |||
| 382 | void | ||
| 383 | getdata(dbp, kp, dp) | ||
| 384 | DB *dbp; | ||
| 385 | DBT *kp, *dp; | ||
| 386 | { | ||
| 387 | switch (dbp->get(dbp, kp, dp, flags)) { | ||
| 388 | case 0: | ||
| 389 | return; | ||
| 390 | case -1: | ||
| 391 | dberr("line %lu: getdata: %s", lineno, strerror(errno)); | ||
| 392 | /* NOTREACHED */ | ||
| 393 | case 1: | ||
| 394 | dberr("line %lu: getdata failed, no such key", lineno); | ||
| 395 | /* NOTREACHED */ | ||
| 396 | } | ||
| 397 | } | ||
| 398 | |||
| 399 | void | ||
| 400 | put(dbp, kp, dp) | ||
| 401 | DB *dbp; | ||
| 402 | DBT *kp, *dp; | ||
| 403 | { | ||
| 404 | switch (dbp->put(dbp, kp, dp, flags)) { | ||
| 405 | case 0: | ||
| 406 | break; | ||
| 407 | case -1: | ||
| 408 | dberr("line %lu: put: %s", lineno, strerror(errno)); | ||
| 409 | /* NOTREACHED */ | ||
| 410 | case 1: | ||
| 411 | (void)write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1); | ||
| 412 | break; | ||
| 413 | } | ||
| 414 | } | ||
| 415 | |||
| 416 | void | ||
| 417 | rem(dbp, kp) | ||
| 418 | DB *dbp; | ||
| 419 | DBT *kp; | ||
| 420 | { | ||
| 421 | switch (dbp->del(dbp, kp, flags)) { | ||
| 422 | case 0: | ||
| 423 | break; | ||
| 424 | case -1: | ||
| 425 | dberr("line %lu: rem: %s", lineno, strerror(errno)); | ||
| 426 | /* NOTREACHED */ | ||
| 427 | case 1: | ||
| 428 | #define NOSUCHKEY "rem failed, no such key\n" | ||
| 429 | if (ofd != STDOUT_FILENO) | ||
| 430 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
| 431 | else if (flags != R_CURSOR) | ||
| 432 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
| 433 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
| 434 | else | ||
| 435 | (void)fprintf(stderr, | ||
| 436 | "%d: rem of cursor failed\n", lineno); | ||
| 437 | #undef NOSUCHKEY | ||
| 438 | break; | ||
| 439 | } | ||
| 440 | } | ||
| 441 | |||
| 442 | void | ||
| 443 | synk(dbp) | ||
| 444 | DB *dbp; | ||
| 445 | { | ||
| 446 | switch (dbp->sync(dbp, flags)) { | ||
| 447 | case 0: | ||
| 448 | break; | ||
| 449 | case -1: | ||
| 450 | dberr("line %lu: synk: %s", lineno, strerror(errno)); | ||
| 451 | /* NOTREACHED */ | ||
| 452 | } | ||
| 453 | } | ||
| 454 | |||
| 455 | void | ||
| 456 | seq(dbp, kp) | ||
| 457 | DB *dbp; | ||
| 458 | DBT *kp; | ||
| 459 | { | ||
| 460 | DBT data; | ||
| 461 | |||
| 462 | switch (dbp->seq(dbp, kp, &data, flags)) { | ||
| 463 | case 0: | ||
| 464 | (void)write(ofd, data.data, data.size); | ||
| 465 | if (ofd == STDOUT_FILENO) | ||
| 466 | (void)write(ofd, "\n", 1); | ||
| 467 | break; | ||
| 468 | case -1: | ||
| 469 | dberr("line %lu: seq: %s", lineno, strerror(errno)); | ||
| 470 | /* NOTREACHED */ | ||
| 471 | case 1: | ||
| 472 | #define NOSUCHKEY "seq failed, no such key\n" | ||
| 473 | if (ofd != STDOUT_FILENO) | ||
| 474 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
| 475 | else if (flags == R_CURSOR) | ||
| 476 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
| 477 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
| 478 | else | ||
| 479 | (void)fprintf(stderr, | ||
| 480 | "%d: seq (%s) failed\n", lineno, sflags(flags)); | ||
| 481 | #undef NOSUCHKEY | ||
| 482 | break; | ||
| 483 | } | ||
| 484 | } | ||
| 485 | |||
| 486 | void | ||
| 487 | dump(dbp, rev) | ||
| 488 | DB *dbp; | ||
| 489 | int rev; | ||
| 490 | { | ||
| 491 | DBT key, data; | ||
| 492 | int flags, nflags; | ||
| 493 | |||
| 494 | if (rev) { | ||
| 495 | flags = R_LAST; | ||
| 496 | nflags = R_PREV; | ||
| 497 | } else { | ||
| 498 | flags = R_FIRST; | ||
| 499 | nflags = R_NEXT; | ||
| 500 | } | ||
| 501 | for (;; flags = nflags) | ||
| 502 | switch (dbp->seq(dbp, &key, &data, flags)) { | ||
| 503 | case 0: | ||
| 504 | (void)write(ofd, data.data, data.size); | ||
| 505 | if (ofd == STDOUT_FILENO) | ||
| 506 | (void)write(ofd, "\n", 1); | ||
| 507 | break; | ||
| 508 | case 1: | ||
| 509 | goto done; | ||
| 510 | case -1: | ||
| 511 | dberr("line %lu: (dump) seq: %s", | ||
| 512 | lineno, strerror(errno)); | ||
| 513 | /* NOTREACHED */ | ||
| 514 | } | ||
| 515 | done: return; | ||
| 516 | } | ||
| 517 | |||
| 518 | u_int | ||
| 519 | setflags(s) | ||
| 520 | char *s; | ||
| 521 | { | ||
| 522 | char *p; | ||
| 523 | |||
| 524 | for (; isspace(*s); ++s); | ||
| 525 | if (*s == '\n' || *s == '\0') | ||
| 526 | return (0); | ||
| 527 | if ((p = strchr(s, '\n')) != NULL) | ||
| 528 | *p = '\0'; | ||
| 529 | if (!strcmp(s, "R_CURSOR")) return (R_CURSOR); | ||
| 530 | if (!strcmp(s, "R_FIRST")) return (R_FIRST); | ||
| 531 | if (!strcmp(s, "R_IAFTER")) return (R_IAFTER); | ||
| 532 | if (!strcmp(s, "R_IBEFORE")) return (R_IBEFORE); | ||
| 533 | if (!strcmp(s, "R_LAST")) return (R_LAST); | ||
| 534 | if (!strcmp(s, "R_NEXT")) return (R_NEXT); | ||
| 535 | if (!strcmp(s, "R_NOOVERWRITE")) return (R_NOOVERWRITE); | ||
| 536 | if (!strcmp(s, "R_PREV")) return (R_PREV); | ||
| 537 | if (!strcmp(s, "R_SETCURSOR")) return (R_SETCURSOR); | ||
| 538 | |||
| 539 | dberr("line %lu: %s: unknown flag", lineno, s); | ||
| 540 | /* NOTREACHED */ | ||
| 541 | } | ||
| 542 | |||
| 543 | char * | ||
| 544 | sflags(flags) | ||
| 545 | int flags; | ||
| 546 | { | ||
| 547 | switch (flags) { | ||
| 548 | case R_CURSOR: return ("R_CURSOR"); | ||
| 549 | case R_FIRST: return ("R_FIRST"); | ||
| 550 | case R_IAFTER: return ("R_IAFTER"); | ||
| 551 | case R_IBEFORE: return ("R_IBEFORE"); | ||
| 552 | case R_LAST: return ("R_LAST"); | ||
| 553 | case R_NEXT: return ("R_NEXT"); | ||
| 554 | case R_NOOVERWRITE: return ("R_NOOVERWRITE"); | ||
| 555 | case R_PREV: return ("R_PREV"); | ||
| 556 | case R_SETCURSOR: return ("R_SETCURSOR"); | ||
| 557 | } | ||
| 558 | |||
| 559 | return ("UNKNOWN!"); | ||
| 560 | } | ||
| 561 | |||
| 562 | DBTYPE | ||
| 563 | dbtype(s) | ||
| 564 | char *s; | ||
| 565 | { | ||
| 566 | if (!strcmp(s, "btree")) | ||
| 567 | return (DB_BTREE); | ||
| 568 | if (!strcmp(s, "hash")) | ||
| 569 | return (DB_HASH); | ||
| 570 | if (!strcmp(s, "recno")) | ||
| 571 | return (DB_RECNO); | ||
| 572 | dberr("%s: unknown type (use btree, hash or recno)", s); | ||
| 573 | /* NOTREACHED */ | ||
| 574 | } | ||
| 575 | |||
| 576 | void * | ||
| 577 | setinfo(type, s) | ||
| 578 | DBTYPE type; | ||
| 579 | char *s; | ||
| 580 | { | ||
| 581 | static BTREEINFO ib; | ||
| 582 | static HASHINFO ih; | ||
| 583 | static RECNOINFO rh; | ||
| 584 | char *eq; | ||
| 585 | |||
| 586 | if ((eq = strchr(s, '=')) == NULL) | ||
| 587 | dberr("%s: illegal structure set statement", s); | ||
| 588 | *eq++ = '\0'; | ||
| 589 | if (!isdigit(*eq)) | ||
| 590 | dberr("%s: structure set statement must be a number", s); | ||
| 591 | |||
| 592 | switch (type) { | ||
| 593 | case DB_BTREE: | ||
| 594 | if (!strcmp("flags", s)) { | ||
| 595 | ib.flags = atoi(eq); | ||
| 596 | return (&ib); | ||
| 597 | } | ||
| 598 | if (!strcmp("cachesize", s)) { | ||
| 599 | ib.cachesize = atoi(eq); | ||
| 600 | return (&ib); | ||
| 601 | } | ||
| 602 | if (!strcmp("maxkeypage", s)) { | ||
| 603 | ib.maxkeypage = atoi(eq); | ||
| 604 | return (&ib); | ||
| 605 | } | ||
| 606 | if (!strcmp("minkeypage", s)) { | ||
| 607 | ib.minkeypage = atoi(eq); | ||
| 608 | return (&ib); | ||
| 609 | } | ||
| 610 | if (!strcmp("lorder", s)) { | ||
| 611 | ib.lorder = atoi(eq); | ||
| 612 | return (&ib); | ||
| 613 | } | ||
| 614 | if (!strcmp("psize", s)) { | ||
| 615 | ib.psize = atoi(eq); | ||
| 616 | return (&ib); | ||
| 617 | } | ||
| 618 | break; | ||
| 619 | case DB_HASH: | ||
| 620 | if (!strcmp("bsize", s)) { | ||
| 621 | ih.bsize = atoi(eq); | ||
| 622 | return (&ih); | ||
| 623 | } | ||
| 624 | if (!strcmp("ffactor", s)) { | ||
| 625 | ih.ffactor = atoi(eq); | ||
| 626 | return (&ih); | ||
| 627 | } | ||
| 628 | if (!strcmp("nelem", s)) { | ||
| 629 | ih.nelem = atoi(eq); | ||
| 630 | return (&ih); | ||
| 631 | } | ||
| 632 | if (!strcmp("cachesize", s)) { | ||
| 633 | ih.cachesize = atoi(eq); | ||
| 634 | return (&ih); | ||
| 635 | } | ||
| 636 | if (!strcmp("lorder", s)) { | ||
| 637 | ih.lorder = atoi(eq); | ||
| 638 | return (&ih); | ||
| 639 | } | ||
| 640 | break; | ||
| 641 | case DB_RECNO: | ||
| 642 | if (!strcmp("flags", s)) { | ||
| 643 | rh.flags = atoi(eq); | ||
| 644 | return (&rh); | ||
| 645 | } | ||
| 646 | if (!strcmp("cachesize", s)) { | ||
| 647 | rh.cachesize = atoi(eq); | ||
| 648 | return (&rh); | ||
| 649 | } | ||
| 650 | if (!strcmp("lorder", s)) { | ||
| 651 | rh.lorder = atoi(eq); | ||
| 652 | return (&rh); | ||
| 653 | } | ||
| 654 | if (!strcmp("reclen", s)) { | ||
| 655 | rh.reclen = atoi(eq); | ||
| 656 | return (&rh); | ||
| 657 | } | ||
| 658 | if (!strcmp("bval", s)) { | ||
| 659 | rh.bval = atoi(eq); | ||
| 660 | return (&rh); | ||
| 661 | } | ||
| 662 | if (!strcmp("psize", s)) { | ||
| 663 | rh.psize = atoi(eq); | ||
| 664 | return (&rh); | ||
| 665 | } | ||
| 666 | break; | ||
| 667 | } | ||
| 668 | dberr("%s: unknown structure value", s); | ||
| 669 | /* NOTREACHED */ | ||
| 670 | } | ||
| 671 | |||
| 672 | void * | ||
| 673 | rfile(name, lenp) | ||
| 674 | char *name; | ||
| 675 | size_t *lenp; | ||
| 676 | { | ||
| 677 | struct stat sb; | ||
| 678 | void *p; | ||
| 679 | int fd; | ||
| 680 | char *np; | ||
| 681 | |||
| 682 | for (; isspace(*name); ++name); | ||
| 683 | if ((np = strchr(name, '\n')) != NULL) | ||
| 684 | *np = '\0'; | ||
| 685 | if ((fd = open(name, O_RDONLY, 0)) < 0 || | ||
| 686 | fstat(fd, &sb)) | ||
| 687 | dberr("%s: %s\n", name, strerror(errno)); | ||
| 688 | #ifdef NOT_PORTABLE | ||
| 689 | if (sb.st_size > (off_t)SIZE_T_MAX) | ||
| 690 | dberr("%s: %s\n", name, strerror(E2BIG)); | ||
| 691 | #endif | ||
| 692 | if ((p = (void *)malloc((u_int)sb.st_size)) == NULL) | ||
| 693 | dberr("%s", strerror(errno)); | ||
| 694 | (void)read(fd, p, (int)sb.st_size); | ||
| 695 | *lenp = sb.st_size; | ||
| 696 | (void)close(fd); | ||
| 697 | return (p); | ||
| 698 | } | ||
| 699 | |||
| 700 | void * | ||
| 701 | xmalloc(text, len) | ||
| 702 | char *text; | ||
| 703 | size_t len; | ||
| 704 | { | ||
| 705 | void *p; | ||
| 706 | |||
| 707 | if ((p = (void *)malloc(len)) == NULL) | ||
| 708 | dberr("%s", strerror(errno)); | ||
| 709 | memmove(p, text, len); | ||
| 710 | return (p); | ||
| 711 | } | ||
| 712 | |||
| 713 | void | ||
| 714 | usage() | ||
| 715 | { | ||
| 716 | (void)fprintf(stderr, | ||
| 717 | "usage: dbtest [-l] [-f file] [-i info] [-o file] type script\n"); | ||
| 718 | exit(1); | ||
| 719 | } | ||
| 720 | |||
| 721 | void | ||
| 722 | dberr(const char *fmt, ...) | ||
| 723 | { | ||
| 724 | va_list ap; | ||
| 725 | |||
| 726 | va_start(ap, fmt); | ||
| 727 | (void)fprintf(stderr, "dbtest: "); | ||
| 728 | (void)vfprintf(stderr, fmt, ap); | ||
| 729 | va_end(ap); | ||
| 730 | (void)fprintf(stderr, "\n"); | ||
| 731 | exit(1); | ||
| 732 | /* NOTREACHED */ | ||
| 733 | } | ||
diff --git a/src/regress/lib/libc/db/run.test b/src/regress/lib/libc/db/run.test new file mode 100644 index 0000000000..0d6837e360 --- /dev/null +++ b/src/regress/lib/libc/db/run.test | |||
| @@ -0,0 +1,707 @@ | |||
| 1 | #!/bin/sh - | ||
| 2 | # | ||
| 3 | # $OpenBSD: run.test,v 1.3 2001/01/29 02:05:41 niklas Exp $ | ||
| 4 | # $NetBSD: run.test,v 1.8 1996/05/03 21:57:51 cgd Exp $ | ||
| 5 | # @(#)run.test 8.10 (Berkeley) 7/26/94 | ||
| 6 | # | ||
| 7 | |||
| 8 | # db regression tests | ||
| 9 | main() | ||
| 10 | { | ||
| 11 | |||
| 12 | PROG=./dbtest | ||
| 13 | TMP1=t1 | ||
| 14 | TMP2=t2 | ||
| 15 | TMP3=t3 | ||
| 16 | |||
| 17 | if [ -f /usr/share/dict/words ]; then | ||
| 18 | DICT=/usr/share/dict/words | ||
| 19 | elif [ -f /usr/dict/words ]; then | ||
| 20 | DICT=/usr/dict/words | ||
| 21 | else | ||
| 22 | echo 'run.test: no dictionary' | ||
| 23 | exit 1 | ||
| 24 | fi | ||
| 25 | |||
| 26 | if [ $# -eq 0 ]; then | ||
| 27 | for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do | ||
| 28 | test$t | ||
| 29 | done | ||
| 30 | else | ||
| 31 | while [ $# -gt 0 ] | ||
| 32 | do case "$1" in | ||
| 33 | test*) | ||
| 34 | $1;; | ||
| 35 | [0-9]*) | ||
| 36 | test$1;; | ||
| 37 | btree) | ||
| 38 | for t in 1 2 3 7 8 9 10 12 13; do | ||
| 39 | test$t | ||
| 40 | done;; | ||
| 41 | hash) | ||
| 42 | for t in 1 2 3 8 13 20; do | ||
| 43 | test$t | ||
| 44 | done;; | ||
| 45 | recno) | ||
| 46 | for t in 1 2 3 4 5 6 7 10 11; do | ||
| 47 | test$t | ||
| 48 | done;; | ||
| 49 | *) | ||
| 50 | echo "run.test: unknown test $1" | ||
| 51 | echo "usage: run.test test# | type" | ||
| 52 | exit 1 | ||
| 53 | esac | ||
| 54 | shift | ||
| 55 | done | ||
| 56 | fi | ||
| 57 | rm -f $TMP1 $TMP2 $TMP3 | ||
| 58 | exit 0 | ||
| 59 | } | ||
| 60 | |||
| 61 | # Take the first hundred entries in the dictionary, and make them | ||
| 62 | # be key/data pairs. | ||
| 63 | test1() | ||
| 64 | { | ||
| 65 | echo "Test 1: btree, hash: small key, small data pairs" | ||
| 66 | sed 200q $DICT > $TMP1 | ||
| 67 | for type in btree hash; do | ||
| 68 | rm -f $TMP2 $TMP3 | ||
| 69 | for i in `sed 200q $DICT`; do | ||
| 70 | echo p | ||
| 71 | echo k$i | ||
| 72 | echo d$i | ||
| 73 | echo g | ||
| 74 | echo k$i | ||
| 75 | done > $TMP2 | ||
| 76 | $PROG -o $TMP3 $type $TMP2 | ||
| 77 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 78 | else | ||
| 79 | echo "test1: type $type: failed" | ||
| 80 | exit 1 | ||
| 81 | fi | ||
| 82 | done | ||
| 83 | echo "Test 1: recno: small key, small data pairs" | ||
| 84 | rm -f $TMP2 $TMP3 | ||
| 85 | sed 200q $DICT | | ||
| 86 | awk '{ | ||
| 87 | ++i; | ||
| 88 | printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); | ||
| 89 | }' > $TMP2 | ||
| 90 | $PROG -o $TMP3 recno $TMP2 | ||
| 91 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 92 | else | ||
| 93 | echo "test1: type recno: failed" | ||
| 94 | exit 1 | ||
| 95 | fi | ||
| 96 | } | ||
| 97 | |||
| 98 | # Take the first 200 entries in the dictionary, and give them | ||
| 99 | # each a medium size data entry. | ||
| 100 | test2() | ||
| 101 | { | ||
| 102 | echo "Test 2: btree, hash: small key, medium data pairs" | ||
| 103 | mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
| 104 | echo $mdata | | ||
| 105 | awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1 | ||
| 106 | for type in hash btree; do | ||
| 107 | rm -f $TMP2 $TMP3 | ||
| 108 | for i in `sed 200q $DICT`; do | ||
| 109 | echo p | ||
| 110 | echo k$i | ||
| 111 | echo d$mdata | ||
| 112 | echo g | ||
| 113 | echo k$i | ||
| 114 | done > $TMP2 | ||
| 115 | $PROG -o $TMP3 $type $TMP2 | ||
| 116 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 117 | else | ||
| 118 | echo "test2: type $type: failed" | ||
| 119 | exit 1 | ||
| 120 | fi | ||
| 121 | done | ||
| 122 | echo "Test 2: recno: small key, medium data pairs" | ||
| 123 | rm -f $TMP2 $TMP3 | ||
| 124 | echo $mdata | | ||
| 125 | awk '{ for (i = 1; i < 201; ++i) | ||
| 126 | printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); | ||
| 127 | }' > $TMP2 | ||
| 128 | $PROG -o $TMP3 recno $TMP2 | ||
| 129 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 130 | else | ||
| 131 | echo "test2: type recno: failed" | ||
| 132 | exit 1 | ||
| 133 | fi | ||
| 134 | } | ||
| 135 | |||
| 136 | # Insert the programs in /bin with their paths as their keys. | ||
| 137 | test3() | ||
| 138 | { | ||
| 139 | echo "Test 3: hash: small key, big data pairs" | ||
| 140 | rm -f $TMP1 | ||
| 141 | (find /bin -type f -print | xargs cat) > $TMP1 | ||
| 142 | for type in hash; do | ||
| 143 | rm -f $TMP2 $TMP3 | ||
| 144 | for i in `find /bin -type f -print`; do | ||
| 145 | echo p | ||
| 146 | echo k$i | ||
| 147 | echo D$i | ||
| 148 | echo g | ||
| 149 | echo k$i | ||
| 150 | done > $TMP2 | ||
| 151 | $PROG -o $TMP3 $type $TMP2 | ||
| 152 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 153 | else | ||
| 154 | echo "test3: $type: failed" | ||
| 155 | exit 1 | ||
| 156 | fi | ||
| 157 | done | ||
| 158 | echo "Test 3: btree: small key, big data pairs" | ||
| 159 | for psize in 512 16384 65536; do | ||
| 160 | echo " page size $psize" | ||
| 161 | for type in btree; do | ||
| 162 | rm -f $TMP2 $TMP3 | ||
| 163 | for i in `find /bin -type f -print`; do | ||
| 164 | echo p | ||
| 165 | echo k$i | ||
| 166 | echo D$i | ||
| 167 | echo g | ||
| 168 | echo k$i | ||
| 169 | done > $TMP2 | ||
| 170 | $PROG -i psize=$psize -o $TMP3 $type $TMP2 | ||
| 171 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 172 | else | ||
| 173 | echo "test3: $type: page size $psize: failed" | ||
| 174 | exit 1 | ||
| 175 | fi | ||
| 176 | done | ||
| 177 | done | ||
| 178 | echo "Test 3: recno: big data pairs" | ||
| 179 | rm -f $TMP2 $TMP3 | ||
| 180 | find /bin -type f -print | | ||
| 181 | awk '{ | ||
| 182 | ++i; | ||
| 183 | printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i); | ||
| 184 | }' > $TMP2 | ||
| 185 | for psize in 512 16384 65536; do | ||
| 186 | echo " page size $psize" | ||
| 187 | $PROG -i psize=$psize -o $TMP3 recno $TMP2 | ||
| 188 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 189 | else | ||
| 190 | echo "test3: recno: page size $psize: failed" | ||
| 191 | exit 1 | ||
| 192 | fi | ||
| 193 | done | ||
| 194 | } | ||
| 195 | |||
| 196 | # Do random recno entries. | ||
| 197 | test4() | ||
| 198 | { | ||
| 199 | echo "Test 4: recno: random entries" | ||
| 200 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 201 | awk '{ | ||
| 202 | for (i = 37; i <= 37 + 88 * 17; i += 17) { | ||
| 203 | if (i % 41) | ||
| 204 | s = substr($0, 1, i % 41); | ||
| 205 | else | ||
| 206 | s = substr($0, 1); | ||
| 207 | printf("input key %d: %s\n", i, s); | ||
| 208 | } | ||
| 209 | for (i = 1; i <= 15; ++i) { | ||
| 210 | if (i % 41) | ||
| 211 | s = substr($0, 1, i % 41); | ||
| 212 | else | ||
| 213 | s = substr($0, 1); | ||
| 214 | printf("input key %d: %s\n", i, s); | ||
| 215 | } | ||
| 216 | for (i = 19234; i <= 19234 + 61 * 27; i += 27) { | ||
| 217 | if (i % 41) | ||
| 218 | s = substr($0, 1, i % 41); | ||
| 219 | else | ||
| 220 | s = substr($0, 1); | ||
| 221 | printf("input key %d: %s\n", i, s); | ||
| 222 | } | ||
| 223 | exit | ||
| 224 | }' > $TMP1 | ||
| 225 | rm -f $TMP2 $TMP3 | ||
| 226 | cat $TMP1 | | ||
| 227 | awk 'BEGIN { | ||
| 228 | i = 37; | ||
| 229 | incr = 17; | ||
| 230 | } | ||
| 231 | { | ||
| 232 | printf("p\nk%d\nd%s\n", i, $0); | ||
| 233 | if (i == 19234 + 61 * 27) | ||
| 234 | exit; | ||
| 235 | if (i == 37 + 88 * 17) { | ||
| 236 | i = 1; | ||
| 237 | incr = 1; | ||
| 238 | } else if (i == 15) { | ||
| 239 | i = 19234; | ||
| 240 | incr = 27; | ||
| 241 | } else | ||
| 242 | i += incr; | ||
| 243 | } | ||
| 244 | END { | ||
| 245 | for (i = 37; i <= 37 + 88 * 17; i += 17) | ||
| 246 | printf("g\nk%d\n", i); | ||
| 247 | for (i = 1; i <= 15; ++i) | ||
| 248 | printf("g\nk%d\n", i); | ||
| 249 | for (i = 19234; i <= 19234 + 61 * 27; i += 27) | ||
| 250 | printf("g\nk%d\n", i); | ||
| 251 | }' > $TMP2 | ||
| 252 | $PROG -o $TMP3 recno $TMP2 | ||
| 253 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 254 | else | ||
| 255 | echo "test4: type recno: failed" | ||
| 256 | exit 1 | ||
| 257 | fi | ||
| 258 | } | ||
| 259 | |||
| 260 | # Do reverse order recno entries. | ||
| 261 | test5() | ||
| 262 | { | ||
| 263 | echo "Test 5: recno: reverse order entries" | ||
| 264 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 265 | awk ' { | ||
| 266 | for (i = 1500; i; --i) { | ||
| 267 | if (i % 34) | ||
| 268 | s = substr($0, 1, i % 34); | ||
| 269 | else | ||
| 270 | s = substr($0, 1); | ||
| 271 | printf("input key %d: %s\n", i, s); | ||
| 272 | } | ||
| 273 | exit; | ||
| 274 | }' > $TMP1 | ||
| 275 | rm -f $TMP2 $TMP3 | ||
| 276 | cat $TMP1 | | ||
| 277 | awk 'BEGIN { | ||
| 278 | i = 1500; | ||
| 279 | } | ||
| 280 | { | ||
| 281 | printf("p\nk%d\nd%s\n", i, $0); | ||
| 282 | --i; | ||
| 283 | } | ||
| 284 | END { | ||
| 285 | for (i = 1500; i; --i) | ||
| 286 | printf("g\nk%d\n", i); | ||
| 287 | }' > $TMP2 | ||
| 288 | $PROG -o $TMP3 recno $TMP2 | ||
| 289 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 290 | else | ||
| 291 | echo "test5: type recno: failed" | ||
| 292 | exit 1 | ||
| 293 | fi | ||
| 294 | } | ||
| 295 | |||
| 296 | # Do alternating order recno entries. | ||
| 297 | test6() | ||
| 298 | { | ||
| 299 | echo "Test 6: recno: alternating order entries" | ||
| 300 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 301 | awk ' { | ||
| 302 | for (i = 1; i < 1200; i += 2) { | ||
| 303 | if (i % 34) | ||
| 304 | s = substr($0, 1, i % 34); | ||
| 305 | else | ||
| 306 | s = substr($0, 1); | ||
| 307 | printf("input key %d: %s\n", i, s); | ||
| 308 | } | ||
| 309 | for (i = 2; i < 1200; i += 2) { | ||
| 310 | if (i % 34) | ||
| 311 | s = substr($0, 1, i % 34); | ||
| 312 | else | ||
| 313 | s = substr($0, 1); | ||
| 314 | printf("input key %d: %s\n", i, s); | ||
| 315 | } | ||
| 316 | exit; | ||
| 317 | }' > $TMP1 | ||
| 318 | rm -f $TMP2 $TMP3 | ||
| 319 | cat $TMP1 | | ||
| 320 | awk 'BEGIN { | ||
| 321 | i = 1; | ||
| 322 | even = 0; | ||
| 323 | } | ||
| 324 | { | ||
| 325 | printf("p\nk%d\nd%s\n", i, $0); | ||
| 326 | i += 2; | ||
| 327 | if (i >= 1200) { | ||
| 328 | if (even == 1) | ||
| 329 | exit; | ||
| 330 | even = 1; | ||
| 331 | i = 2; | ||
| 332 | } | ||
| 333 | } | ||
| 334 | END { | ||
| 335 | for (i = 1; i < 1200; ++i) | ||
| 336 | printf("g\nk%d\n", i); | ||
| 337 | }' > $TMP2 | ||
| 338 | $PROG -o $TMP3 recno $TMP2 | ||
| 339 | sort -o $TMP1 $TMP1 | ||
| 340 | sort -o $TMP3 $TMP3 | ||
| 341 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 342 | else | ||
| 343 | echo "test6: type recno: failed" | ||
| 344 | exit 1 | ||
| 345 | fi | ||
| 346 | } | ||
| 347 | |||
| 348 | # Delete cursor record | ||
| 349 | test7() | ||
| 350 | { | ||
| 351 | echo "Test 7: btree, recno: delete cursor record" | ||
| 352 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 353 | awk '{ | ||
| 354 | for (i = 1; i <= 120; ++i) | ||
| 355 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
| 356 | printf("%05d: input key %d: %s\n", 120, 120, $0); | ||
| 357 | printf("seq failed, no such key\n"); | ||
| 358 | printf("%05d: input key %d: %s\n", 1, 1, $0); | ||
| 359 | printf("%05d: input key %d: %s\n", 2, 2, $0); | ||
| 360 | exit; | ||
| 361 | }' > $TMP1 | ||
| 362 | rm -f $TMP2 $TMP3 | ||
| 363 | |||
| 364 | for type in btree recno; do | ||
| 365 | cat $TMP1 | | ||
| 366 | awk '{ | ||
| 367 | if (i == 120) | ||
| 368 | exit; | ||
| 369 | printf("p\nk%d\nd%s\n", ++i, $0); | ||
| 370 | } | ||
| 371 | END { | ||
| 372 | printf("fR_NEXT\n"); | ||
| 373 | for (i = 1; i <= 120; ++i) | ||
| 374 | printf("s\n"); | ||
| 375 | printf("fR_CURSOR\ns\nk120\n"); | ||
| 376 | printf("r\n"); | ||
| 377 | printf("fR_NEXT\ns\n"); | ||
| 378 | printf("fR_CURSOR\ns\nk1\n"); | ||
| 379 | printf("r\n"); | ||
| 380 | printf("fR_FIRST\ns\n"); | ||
| 381 | }' > $TMP2 | ||
| 382 | $PROG -o $TMP3 recno $TMP2 | ||
| 383 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 384 | else | ||
| 385 | echo "test7: type $type: failed" | ||
| 386 | exit 1 | ||
| 387 | fi | ||
| 388 | done | ||
| 389 | } | ||
| 390 | |||
| 391 | # Make sure that overflow pages are reused. | ||
| 392 | test8() | ||
| 393 | { | ||
| 394 | echo "Test 8: btree, hash: repeated small key, big data pairs" | ||
| 395 | rm -f $TMP1 | ||
| 396 | echo "" | | ||
| 397 | awk 'BEGIN { | ||
| 398 | for (i = 1; i <= 10; ++i) { | ||
| 399 | printf("p\nkkey1\nD/bin/sh\n"); | ||
| 400 | printf("p\nkkey2\nD/bin/csh\n"); | ||
| 401 | if (i % 8 == 0) { | ||
| 402 | printf("c\nkkey2\nD/bin/csh\n"); | ||
| 403 | printf("c\nkkey1\nD/bin/sh\n"); | ||
| 404 | printf("e\t%d of 10 (comparison)\n", i); | ||
| 405 | } else | ||
| 406 | printf("e\t%d of 10 \n", i); | ||
| 407 | printf("r\nkkey1\nr\nkkey2\n"); | ||
| 408 | } | ||
| 409 | }' > $TMP1 | ||
| 410 | $PROG btree $TMP1 | ||
| 411 | # $PROG hash $TMP1 | ||
| 412 | # No explicit test for success. | ||
| 413 | } | ||
| 414 | |||
| 415 | # Test btree duplicate keys | ||
| 416 | test9() | ||
| 417 | { | ||
| 418 | echo "Test 9: btree: duplicate keys" | ||
| 419 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 420 | awk '{ | ||
| 421 | for (i = 1; i <= 543; ++i) | ||
| 422 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
| 423 | exit; | ||
| 424 | }' > $TMP1 | ||
| 425 | rm -f $TMP2 $TMP3 | ||
| 426 | |||
| 427 | for type in btree; do | ||
| 428 | cat $TMP1 | | ||
| 429 | awk '{ | ||
| 430 | if (i++ % 2) | ||
| 431 | printf("p\nkduplicatekey\nd%s\n", $0); | ||
| 432 | else | ||
| 433 | printf("p\nkunique%dkey\nd%s\n", i, $0); | ||
| 434 | } | ||
| 435 | END { | ||
| 436 | printf("o\n"); | ||
| 437 | }' > $TMP2 | ||
| 438 | $PROG -iflags=1 -o $TMP3 $type $TMP2 | ||
| 439 | sort -o $TMP3 $TMP3 | ||
| 440 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 441 | else | ||
| 442 | echo "test9: type $type: failed" | ||
| 443 | exit 1 | ||
| 444 | fi | ||
| 445 | done | ||
| 446 | } | ||
| 447 | |||
| 448 | # Test use of cursor flags without initialization | ||
| 449 | test10() | ||
| 450 | { | ||
| 451 | echo "Test 10: btree, recno: test cursor flag use" | ||
| 452 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 453 | awk '{ | ||
| 454 | for (i = 1; i <= 20; ++i) | ||
| 455 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
| 456 | exit; | ||
| 457 | }' > $TMP1 | ||
| 458 | rm -f $TMP2 $TMP3 | ||
| 459 | |||
| 460 | # Test that R_CURSOR doesn't succeed before cursor initialized | ||
| 461 | for type in btree recno; do | ||
| 462 | cat $TMP1 | | ||
| 463 | awk '{ | ||
| 464 | if (i == 10) | ||
| 465 | exit; | ||
| 466 | printf("p\nk%d\nd%s\n", ++i, $0); | ||
| 467 | } | ||
| 468 | END { | ||
| 469 | printf("fR_CURSOR\nr\n"); | ||
| 470 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); | ||
| 471 | }' > $TMP2 | ||
| 472 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 | ||
| 473 | if [ -s $TMP3 ] ; then | ||
| 474 | echo "Test 10: delete: R_CURSOR SHOULD HAVE FAILED" | ||
| 475 | exit 1 | ||
| 476 | fi | ||
| 477 | done | ||
| 478 | for type in btree recno; do | ||
| 479 | cat $TMP1 | | ||
| 480 | awk '{ | ||
| 481 | if (i == 10) | ||
| 482 | exit; | ||
| 483 | printf("p\nk%d\nd%s\n", ++i, $0); | ||
| 484 | } | ||
| 485 | END { | ||
| 486 | printf("fR_CURSOR\np\nk1\ndsome data\n"); | ||
| 487 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); | ||
| 488 | }' > $TMP2 | ||
| 489 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 | ||
| 490 | if [ -s $TMP3 ] ; then | ||
| 491 | echo "Test 10: put: R_CURSOR SHOULD HAVE FAILED" | ||
| 492 | exit 1 | ||
| 493 | fi | ||
| 494 | done | ||
| 495 | } | ||
| 496 | |||
| 497 | # Test insert in reverse order. | ||
| 498 | test11() | ||
| 499 | { | ||
| 500 | echo "Test 11: recno: reverse order insert" | ||
| 501 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 502 | awk '{ | ||
| 503 | for (i = 1; i <= 779; ++i) | ||
| 504 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
| 505 | exit; | ||
| 506 | }' > $TMP1 | ||
| 507 | rm -f $TMP2 $TMP3 | ||
| 508 | |||
| 509 | for type in recno; do | ||
| 510 | cat $TMP1 | | ||
| 511 | awk '{ | ||
| 512 | if (i == 0) { | ||
| 513 | i = 1; | ||
| 514 | printf("p\nk1\nd%s\n", $0); | ||
| 515 | printf("%s\n", "fR_IBEFORE"); | ||
| 516 | } else | ||
| 517 | printf("p\nk1\nd%s\n", $0); | ||
| 518 | } | ||
| 519 | END { | ||
| 520 | printf("or\n"); | ||
| 521 | }' > $TMP2 | ||
| 522 | $PROG -o $TMP3 $type $TMP2 | ||
| 523 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 524 | else | ||
| 525 | echo "test11: type $type: failed" | ||
| 526 | exit 1 | ||
| 527 | fi | ||
| 528 | done | ||
| 529 | } | ||
| 530 | |||
| 531 | # Take the first 20000 entries in the dictionary, reverse them, and give | ||
| 532 | # them each a small size data entry. Use a small page size to make sure | ||
| 533 | # the btree split code gets hammered. | ||
| 534 | test12() | ||
| 535 | { | ||
| 536 | echo "Test 12: btree: lots of keys, small page size" | ||
| 537 | mdata=abcdefghijklmnopqrstuvwxy | ||
| 538 | echo $mdata | | ||
| 539 | awk '{ for (i = 1; i < 20001; ++i) print $0 }' > $TMP1 | ||
| 540 | for type in btree; do | ||
| 541 | rm -f $TMP2 $TMP3 | ||
| 542 | for i in `sed 20000q $DICT | rev`; do | ||
| 543 | echo p | ||
| 544 | echo k$i | ||
| 545 | echo d$mdata | ||
| 546 | echo g | ||
| 547 | echo k$i | ||
| 548 | done > $TMP2 | ||
| 549 | $PROG -i psize=512 -o $TMP3 $type $TMP2 | ||
| 550 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 551 | else | ||
| 552 | echo "test12: type $type: failed" | ||
| 553 | exit 1 | ||
| 554 | fi | ||
| 555 | done | ||
| 556 | } | ||
| 557 | |||
| 558 | # Test different byte orders. | ||
| 559 | test13() | ||
| 560 | { | ||
| 561 | echo "Test 13: btree, hash: differing byte orders" | ||
| 562 | sed 50q $DICT > $TMP1 | ||
| 563 | for order in 1234 4321; do | ||
| 564 | for type in btree hash; do | ||
| 565 | rm -f byte.file $TMP2 $TMP3 | ||
| 566 | for i in `sed 50q $DICT`; do | ||
| 567 | echo p | ||
| 568 | echo k$i | ||
| 569 | echo d$i | ||
| 570 | echo g | ||
| 571 | echo k$i | ||
| 572 | done > $TMP2 | ||
| 573 | $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | ||
| 574 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 575 | else | ||
| 576 | echo "test13: $type/$order put failed" | ||
| 577 | exit 1 | ||
| 578 | fi | ||
| 579 | for i in `sed 50q $DICT`; do | ||
| 580 | echo g | ||
| 581 | echo k$i | ||
| 582 | done > $TMP2 | ||
| 583 | $PROG -s \ | ||
| 584 | -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | ||
| 585 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 586 | else | ||
| 587 | echo "test13: $type/$order get failed" | ||
| 588 | exit 1 | ||
| 589 | fi | ||
| 590 | done | ||
| 591 | done | ||
| 592 | rm -f byte.file | ||
| 593 | } | ||
| 594 | |||
| 595 | # Try a variety of bucketsizes and fill factors for hashing | ||
| 596 | test20() | ||
| 597 | { | ||
| 598 | echo\ | ||
| 599 | "Test 20: hash: bucketsize, fill factor; nelem 25000 cachesize 65536" | ||
| 600 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 601 | awk '{ | ||
| 602 | for (i = 1; i <= 10000; ++i) { | ||
| 603 | if (i % 34) | ||
| 604 | s = substr($0, 1, i % 34); | ||
| 605 | else | ||
| 606 | s = substr($0, 1); | ||
| 607 | printf("%s\n", s); | ||
| 608 | } | ||
| 609 | exit; | ||
| 610 | }' > $TMP1 | ||
| 611 | sed 10000q $DICT | | ||
| 612 | awk 'BEGIN { | ||
| 613 | ds="abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | ||
| 614 | } | ||
| 615 | { | ||
| 616 | if (++i % 34) | ||
| 617 | s = substr(ds, 1, i % 34); | ||
| 618 | else | ||
| 619 | s = substr(ds, 1); | ||
| 620 | printf("p\nk%s\nd%s\n", $0, s); | ||
| 621 | }' > $TMP2 | ||
| 622 | sed 10000q $DICT | | ||
| 623 | awk '{ | ||
| 624 | ++i; | ||
| 625 | printf("g\nk%s\n", $0); | ||
| 626 | }' >> $TMP2 | ||
| 627 | bsize=256 | ||
| 628 | for ffactor in 11 14 21; do | ||
| 629 | echo " bucketsize $bsize, fill factor $ffactor" | ||
| 630 | $PROG -o$TMP3 \ | ||
| 631 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
| 632 | hash $TMP2 | ||
| 633 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 634 | else | ||
| 635 | echo "test20: type hash:\ | ||
| 636 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
| 637 | exit 1 | ||
| 638 | fi | ||
| 639 | done | ||
| 640 | bsize=512 | ||
| 641 | for ffactor in 21 28 43; do | ||
| 642 | echo " bucketsize $bsize, fill factor $ffactor" | ||
| 643 | $PROG -o$TMP3 \ | ||
| 644 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
| 645 | hash $TMP2 | ||
| 646 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 647 | else | ||
| 648 | echo "test20: type hash:\ | ||
| 649 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
| 650 | exit 1 | ||
| 651 | fi | ||
| 652 | done | ||
| 653 | bsize=1024 | ||
| 654 | for ffactor in 43 57 85; do | ||
| 655 | echo " bucketsize $bsize, fill factor $ffactor" | ||
| 656 | $PROG -o$TMP3 \ | ||
| 657 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
| 658 | hash $TMP2 | ||
| 659 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 660 | else | ||
| 661 | echo "test20: type hash:\ | ||
| 662 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
| 663 | exit 1 | ||
| 664 | fi | ||
| 665 | done | ||
| 666 | bsize=2048 | ||
| 667 | for ffactor in 85 114 171; do | ||
| 668 | echo " bucketsize $bsize, fill factor $ffactor" | ||
| 669 | $PROG -o$TMP3 \ | ||
| 670 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
| 671 | hash $TMP2 | ||
| 672 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 673 | else | ||
| 674 | echo "test20: type hash:\ | ||
| 675 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
| 676 | exit 1 | ||
| 677 | fi | ||
| 678 | done | ||
| 679 | bsize=4096 | ||
| 680 | for ffactor in 171 228 341; do | ||
| 681 | echo " bucketsize $bsize, fill factor $ffactor" | ||
| 682 | $PROG -o$TMP3 \ | ||
| 683 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
| 684 | hash $TMP2 | ||
| 685 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 686 | else | ||
| 687 | echo "test20: type hash:\ | ||
| 688 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
| 689 | exit 1 | ||
| 690 | fi | ||
| 691 | done | ||
| 692 | bsize=8192 | ||
| 693 | for ffactor in 341 455 683; do | ||
| 694 | echo " bucketsize $bsize, fill factor $ffactor" | ||
| 695 | $PROG -o$TMP3 \ | ||
| 696 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
| 697 | hash $TMP2 | ||
| 698 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 699 | else | ||
| 700 | echo "test20: type hash:\ | ||
| 701 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
| 702 | exit 1 | ||
| 703 | fi | ||
| 704 | done | ||
| 705 | } | ||
| 706 | |||
| 707 | main $* | ||
diff --git a/src/regress/lib/libc/dirname/Makefile b/src/regress/lib/libc/dirname/Makefile new file mode 100644 index 0000000000..fc152df954 --- /dev/null +++ b/src/regress/lib/libc/dirname/Makefile | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | PROG=dirname_test | ||
| 2 | |||
| 3 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/dirname/dirname_test.c b/src/regress/lib/libc/dirname/dirname_test.c new file mode 100644 index 0000000000..add76980cf --- /dev/null +++ b/src/regress/lib/libc/dirname/dirname_test.c | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2007 Bret S. Lambert <blambert@gsipt.net> | ||
| 3 | * | ||
| 4 | * Public domain. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <sys/param.h> | ||
| 8 | |||
| 9 | #include <libgen.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <string.h> | ||
| 12 | #include <limits.h> | ||
| 13 | #include <errno.h> | ||
| 14 | |||
| 15 | int | ||
| 16 | main(void) | ||
| 17 | { | ||
| 18 | char path[2 * MAXPATHLEN]; | ||
| 19 | char dname[128]; | ||
| 20 | const char *dir = "junk"; | ||
| 21 | const char *fname = "/file.name.ext"; | ||
| 22 | char *str; | ||
| 23 | int i; | ||
| 24 | |||
| 25 | /* Test normal functioning */ | ||
| 26 | strlcpy(path, "/", sizeof(path)); | ||
| 27 | strlcpy(dname, "/", sizeof(dname)); | ||
| 28 | strlcat(path, dir, sizeof(path)); | ||
| 29 | strlcat(dname, dir, sizeof(dname)); | ||
| 30 | strlcat(path, fname, sizeof(path)); | ||
| 31 | str = dirname(path); | ||
| 32 | if (strcmp(str, dname) != 0) | ||
| 33 | errx(1, "0: dirname(%s) = %s != %s", path, str, dname); | ||
| 34 | |||
| 35 | /* | ||
| 36 | * There are four states that require special handling: | ||
| 37 | * | ||
| 38 | * 1) path is NULL | ||
| 39 | * 2) path is the empty string | ||
| 40 | * 3) path is composed entirely of slashes | ||
| 41 | * 4) the resulting name is larger than MAXPATHLEN | ||
| 42 | * | ||
| 43 | * The first two cases require that a pointer | ||
| 44 | * to the string "." be returned. | ||
| 45 | * | ||
| 46 | * The third case requires that a pointer | ||
| 47 | * to the string "/" be returned. | ||
| 48 | * | ||
| 49 | * The final case requires that NULL be returned | ||
| 50 | * and errno * be set to ENAMETOOLONG. | ||
| 51 | */ | ||
| 52 | /* Case 1 */ | ||
| 53 | str = dirname(NULL); | ||
| 54 | if (strcmp(str, ".") != 0) | ||
| 55 | errx(1, "1: dirname(NULL) = %s != .", str); | ||
| 56 | |||
| 57 | /* Case 2 */ | ||
| 58 | strlcpy(path, "", sizeof(path)); | ||
| 59 | str = dirname(path); | ||
| 60 | if (strcmp(str, ".") != 0) | ||
| 61 | errx(1, "2: dirname(%s) = %s != .", path, str); | ||
| 62 | |||
| 63 | /* Case 3 */ | ||
| 64 | for (i = 0; i < MAXPATHLEN - 1; i++) | ||
| 65 | strlcat(path, "/", sizeof(path)); /* path cleared above */ | ||
| 66 | str = dirname(path); | ||
| 67 | if (strcmp(str, "/") != 0) | ||
| 68 | errx(1, "3: dirname(%s) = %s != /", path, str); | ||
| 69 | |||
| 70 | /* Case 4 */ | ||
| 71 | strlcpy(path, "/", sizeof(path)); /* reset path */ | ||
| 72 | for (i = 0; i <= MAXPATHLEN; i += strlen(dir)) | ||
| 73 | strlcat(path, dir, sizeof(path)); | ||
| 74 | strlcat(path, fname, sizeof(path)); | ||
| 75 | str = dirname(path); | ||
| 76 | if (str != NULL) | ||
| 77 | errx(1, "4: dirname(%s) = %s != NULL", path, str); | ||
| 78 | if (errno != ENAMETOOLONG) | ||
| 79 | errx(1, "4: dirname(%s) sets errno to %d", path, errno); | ||
| 80 | |||
| 81 | return (0); | ||
| 82 | } | ||
diff --git a/src/regress/lib/libc/env/Makefile b/src/regress/lib/libc/env/Makefile new file mode 100644 index 0000000000..92e04369f4 --- /dev/null +++ b/src/regress/lib/libc/env/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2010/08/23 22:34:37 millert Exp $ | ||
| 2 | |||
| 3 | PROG= envtest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/env/envtest.c b/src/regress/lib/libc/env/envtest.c new file mode 100644 index 0000000000..33fc463404 --- /dev/null +++ b/src/regress/lib/libc/env/envtest.c | |||
| @@ -0,0 +1,125 @@ | |||
| 1 | /* $OpenBSD: envtest.c,v 1.1 2010/08/23 22:34:37 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <sys/types.h> | ||
| 20 | |||
| 21 | #include <stdio.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <unistd.h> | ||
| 25 | |||
| 26 | extern char **environ; | ||
| 27 | |||
| 28 | static int | ||
| 29 | count_instances(const char *name) | ||
| 30 | { | ||
| 31 | int count = 0; | ||
| 32 | size_t namelen; | ||
| 33 | char **ep; | ||
| 34 | |||
| 35 | namelen = strlen(name); | ||
| 36 | for (ep = environ; *ep != NULL; ep++) { | ||
| 37 | if (strncmp(name, *ep, namelen) == 0 && (*ep)[namelen] == '=') | ||
| 38 | count++; | ||
| 39 | } | ||
| 40 | |||
| 41 | return count; | ||
| 42 | } | ||
| 43 | |||
| 44 | static void | ||
| 45 | fake_env(void) | ||
| 46 | { | ||
| 47 | static char *fakenv[7]; | ||
| 48 | |||
| 49 | fakenv[0] = "HOME=/root"; | ||
| 50 | fakenv[1] = "USER=root"; | ||
| 51 | fakenv[2] = "LOGNAME=root"; | ||
| 52 | fakenv[3] = "SHELL=/bin/sh"; | ||
| 53 | fakenv[4] = "USER=root"; | ||
| 54 | fakenv[5] = NULL; | ||
| 55 | |||
| 56 | environ = fakenv; | ||
| 57 | } | ||
| 58 | |||
| 59 | int | ||
| 60 | main(int argc, char *argv[]) | ||
| 61 | { | ||
| 62 | char *buf; | ||
| 63 | int n, failures = 0; | ||
| 64 | size_t len, bufsize; | ||
| 65 | |||
| 66 | /* Enable malloc security options. */ | ||
| 67 | setenv("MALLOC_OPTIONS", "S", 0); | ||
| 68 | |||
| 69 | fake_env(); | ||
| 70 | n = count_instances("USER"); | ||
| 71 | if (n != 2) { | ||
| 72 | fprintf(stderr, "initial: %d instances of USER, expected %d\n", | ||
| 73 | n, 2); | ||
| 74 | failures++; | ||
| 75 | } | ||
| 76 | |||
| 77 | if (unsetenv("USER") != 0) { | ||
| 78 | fprintf(stderr, "unsetenv: failed to remove USER\n"); | ||
| 79 | failures++; | ||
| 80 | } | ||
| 81 | n = count_instances("USER"); | ||
| 82 | if (n != 0) { | ||
| 83 | fprintf(stderr, "unsetenv: %d instances of USER, expected %d\n", | ||
| 84 | n, 0); | ||
| 85 | failures++; | ||
| 86 | } | ||
| 87 | |||
| 88 | fake_env(); | ||
| 89 | if (setenv("USER", "nobody", 0) != 0) { | ||
| 90 | fprintf(stderr, "setenv: failed to set USER\n"); | ||
| 91 | failures++; | ||
| 92 | } | ||
| 93 | n = count_instances("USER"); | ||
| 94 | if (n != 2) { | ||
| 95 | fprintf(stderr, "setenv: %d instances of USER, expected %d\n", | ||
| 96 | n, 2); | ||
| 97 | failures++; | ||
| 98 | } | ||
| 99 | |||
| 100 | fake_env(); | ||
| 101 | if (setenv("USER", "nobody", 1) != 0) { | ||
| 102 | fprintf(stderr, "setenv: failed to set USER\n"); | ||
| 103 | failures++; | ||
| 104 | } | ||
| 105 | n = count_instances("USER"); | ||
| 106 | if (n != 1) { | ||
| 107 | fprintf(stderr, "setenv: %d instances of USER, expected %d\n", | ||
| 108 | n, 1); | ||
| 109 | failures++; | ||
| 110 | } | ||
| 111 | |||
| 112 | fake_env(); | ||
| 113 | if (putenv("USER=nobody") != 0) { | ||
| 114 | fprintf(stderr, "putenv: failed to set USER\n"); | ||
| 115 | failures++; | ||
| 116 | } | ||
| 117 | n = count_instances("USER"); | ||
| 118 | if (n != 1) { | ||
| 119 | fprintf(stderr, "putenv: %d instances of USER, expected %d\n", | ||
| 120 | n, 1); | ||
| 121 | failures++; | ||
| 122 | } | ||
| 123 | |||
| 124 | return failures; | ||
| 125 | } | ||
diff --git a/src/regress/lib/libc/fnmatch/Makefile b/src/regress/lib/libc/fnmatch/Makefile new file mode 100644 index 0000000000..b2f357105f --- /dev/null +++ b/src/regress/lib/libc/fnmatch/Makefile | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2008/10/01 23:04:58 millert Exp $ | ||
| 2 | |||
| 3 | PROG= fnm_test | ||
| 4 | |||
| 5 | run-regress-${PROG}: | ||
| 6 | ./${PROG} ${.CURDIR}/${PROG}.in | ||
| 7 | |||
| 8 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/fnmatch/fnm_test.c b/src/regress/lib/libc/fnmatch/fnm_test.c new file mode 100644 index 0000000000..e987010095 --- /dev/null +++ b/src/regress/lib/libc/fnmatch/fnm_test.c | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | /* $OpenBSD: fnm_test.c,v 1.1 2008/10/01 23:04:58 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Public domain, 2008, Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <err.h> | ||
| 8 | #include <fnmatch.h> | ||
| 9 | #include <stdio.h> | ||
| 10 | #include <stdlib.h> | ||
| 11 | |||
| 12 | int | ||
| 13 | main(int argc, char **argv) | ||
| 14 | { | ||
| 15 | FILE *fp = stdin; | ||
| 16 | char pattern[1024], string[1024]; | ||
| 17 | int errors = 0, flags, got, want; | ||
| 18 | |||
| 19 | if (argc > 1) { | ||
| 20 | if ((fp = fopen(argv[1], "r")) == NULL) | ||
| 21 | err(1, "%s", argv[1]); | ||
| 22 | } | ||
| 23 | |||
| 24 | /* | ||
| 25 | * Read in test file, which is formatted thusly: | ||
| 26 | * | ||
| 27 | * pattern string flags expected_result | ||
| 28 | * | ||
| 29 | */ | ||
| 30 | for (;;) { | ||
| 31 | got = fscanf(fp, "%s %s 0x%x %d\n", pattern, string, &flags, | ||
| 32 | &want); | ||
| 33 | if (got == EOF) | ||
| 34 | break; | ||
| 35 | if (got == 4) { | ||
| 36 | got = fnmatch(pattern, string, flags); | ||
| 37 | if (got != want) { | ||
| 38 | warnx("%s %s %d: want %d, got %d", pattern, | ||
| 39 | string, flags, want, got); | ||
| 40 | errors++; | ||
| 41 | } | ||
| 42 | } | ||
| 43 | } | ||
| 44 | exit(errors); | ||
| 45 | } | ||
diff --git a/src/regress/lib/libc/fnmatch/fnm_test.in b/src/regress/lib/libc/fnmatch/fnm_test.in new file mode 100644 index 0000000000..3c707f8a19 --- /dev/null +++ b/src/regress/lib/libc/fnmatch/fnm_test.in | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | /bin/[[:alpha:][:alnum:]]* /bin/ls 0x2 0 | ||
| 2 | /bin/[[:upper:]][[:alnum:]] /bin/ls 0x10 0 | ||
| 3 | /bin/[[:opper:][:alnum:]]* /bin/ls 0x0 1 | ||
| 4 | [[:alpha:][:alnum:]]*.c foo1.c 0x4 0 | ||
| 5 | [[:upper:]]* FOO 0x0 0 | ||
diff --git a/src/regress/lib/libc/fpclassify/Makefile b/src/regress/lib/libc/fpclassify/Makefile new file mode 100644 index 0000000000..96916d20e7 --- /dev/null +++ b/src/regress/lib/libc/fpclassify/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2008/09/07 20:36:10 martynas Exp $ | ||
| 2 | |||
| 3 | PROG= fpclassify | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/fpclassify/fpclassify.c b/src/regress/lib/libc/fpclassify/fpclassify.c new file mode 100644 index 0000000000..174c04d983 --- /dev/null +++ b/src/regress/lib/libc/fpclassify/fpclassify.c | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | /* $OpenBSD: fpclassify.c,v 1.1 2008/09/07 20:36:10 martynas Exp $ */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 25 | * SUCH DAMAGE. | ||
| 26 | * | ||
| 27 | * $FreeBSD: src/tools/regression/lib/libc/gen/test-fpclassify.c,v 1.3 2003/03/27 05:32:28 das Exp $ | ||
| 28 | */ | ||
| 29 | |||
| 30 | #include <assert.h> | ||
| 31 | #include <float.h> | ||
| 32 | #include <math.h> | ||
| 33 | #include <stdlib.h> | ||
| 34 | |||
| 35 | int | ||
| 36 | main(void) | ||
| 37 | { | ||
| 38 | |||
| 39 | assert(fpclassify((float)0) == FP_ZERO); | ||
| 40 | assert(fpclassify((float)-0.0) == FP_ZERO); | ||
| 41 | assert(fpclassify((float)1) == FP_NORMAL); | ||
| 42 | assert(fpclassify((float)1000) == FP_NORMAL); | ||
| 43 | #ifndef __alpha__ | ||
| 44 | assert(fpclassify(0x1.2p-150f) == FP_SUBNORMAL); | ||
| 45 | #endif /* !__alpha__ */ | ||
| 46 | assert(fpclassify(HUGE_VALF) == FP_INFINITE); | ||
| 47 | assert(fpclassify((float)HUGE_VAL) == FP_INFINITE); | ||
| 48 | assert(fpclassify((float)HUGE_VALL) == FP_INFINITE); | ||
| 49 | assert(fpclassify(NAN) == FP_NAN); | ||
| 50 | |||
| 51 | assert(fpclassify((double)0) == FP_ZERO); | ||
| 52 | assert(fpclassify((double)-0) == FP_ZERO); | ||
| 53 | assert(fpclassify((double)1) == FP_NORMAL); | ||
| 54 | assert(fpclassify((double)1000) == FP_NORMAL); | ||
| 55 | #ifndef __alpha__ | ||
| 56 | assert(fpclassify(0x1.2p-1075) == FP_SUBNORMAL); | ||
| 57 | #endif /* !__alpha__ */ | ||
| 58 | assert(fpclassify(HUGE_VAL) == FP_INFINITE); | ||
| 59 | assert(fpclassify((double)HUGE_VALF) == FP_INFINITE); | ||
| 60 | assert(fpclassify((double)HUGE_VALL) == FP_INFINITE); | ||
| 61 | assert(fpclassify((double)NAN) == FP_NAN); | ||
| 62 | |||
| 63 | assert(fpclassify((long double)0) == FP_ZERO); | ||
| 64 | assert(fpclassify((long double)-0.0) == FP_ZERO); | ||
| 65 | assert(fpclassify((long double)1) == FP_NORMAL); | ||
| 66 | assert(fpclassify((long double)1000) == FP_NORMAL); | ||
| 67 | #if (LDBL_MANT_DIG > DBL_MANT_DIG) | ||
| 68 | assert(fpclassify(0x1.2p-16383L) == FP_SUBNORMAL); | ||
| 69 | #endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) */ | ||
| 70 | assert(fpclassify(HUGE_VALL) == FP_INFINITE); | ||
| 71 | assert(fpclassify((long double)HUGE_VALF) == FP_INFINITE); | ||
| 72 | assert(fpclassify((long double)HUGE_VAL) == FP_INFINITE); | ||
| 73 | assert(fpclassify((long double)NAN) == FP_NAN); | ||
| 74 | |||
| 75 | return (0); | ||
| 76 | } | ||
diff --git a/src/regress/lib/libc/gcvt/Makefile b/src/regress/lib/libc/gcvt/Makefile new file mode 100644 index 0000000000..d8efaa9362 --- /dev/null +++ b/src/regress/lib/libc/gcvt/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2010/09/17 19:51:38 millert Exp $ | ||
| 2 | |||
| 3 | PROG= gcvt_test | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/gcvt/gcvt_test.c b/src/regress/lib/libc/gcvt/gcvt_test.c new file mode 100644 index 0000000000..164d600cd2 --- /dev/null +++ b/src/regress/lib/libc/gcvt/gcvt_test.c | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | /* $OpenBSD: gcvt_test.c,v 1.4 2010/09/18 20:29:15 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Public domain, 2010, Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <stdio.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include <string.h> | ||
| 10 | |||
| 11 | static struct test_vector { | ||
| 12 | double d; | ||
| 13 | int ndig; | ||
| 14 | char *expect; | ||
| 15 | } test_vectors[] = { | ||
| 16 | /* adapted from perl's Configure test */ | ||
| 17 | { 0.1, 8, "0.1" }, | ||
| 18 | { 0.01, 8, "0.01" }, | ||
| 19 | { 0.001, 8, "0.001" }, | ||
| 20 | { 0.0001, 8, "0.0001" }, | ||
| 21 | { 0.00009, 8, "9e-05" }, | ||
| 22 | { 1.0, 8, "1" }, | ||
| 23 | { 1.1, 8, "1.1" }, | ||
| 24 | { 1.01, 8, "1.01" }, | ||
| 25 | { 1.001, 8, "1.001" }, | ||
| 26 | { 1.0001, 8, "1.0001" }, | ||
| 27 | { 1.00001, 8, "1.00001" }, | ||
| 28 | { 1.000001, 8, "1.000001" }, | ||
| 29 | { 0.0, 8, "0" }, | ||
| 30 | { -1.0, 8, "-1" }, | ||
| 31 | { 100000.0, 8, "100000" }, | ||
| 32 | { -100000.0, 8, "-100000" }, | ||
| 33 | { 123.456, 8, "123.456" }, | ||
| 34 | { 1e34, 8, "1e+34" }, | ||
| 35 | /* adapted from emx */ | ||
| 36 | { 0.0, -1, "0" }, | ||
| 37 | { 0.0, 0, "0" }, | ||
| 38 | { 0.0, 1, "0" }, | ||
| 39 | { 0.0, 2, "0" }, | ||
| 40 | { 1.0, -1, "1" }, | ||
| 41 | { 1.0, 0, "1" }, | ||
| 42 | { 1.0, 2, "1" }, | ||
| 43 | { 1.0, 10, "1" }, | ||
| 44 | { 1.236, -1, "1.236" }, | ||
| 45 | { 1.236, 0, "1" }, | ||
| 46 | { 1.236, 1, "1" }, | ||
| 47 | { 1.236, 2, "1.2" }, | ||
| 48 | { 1.236, 3, "1.24" }, | ||
| 49 | { 1.236, 4, "1.236" }, | ||
| 50 | { 1.236, 5, "1.236" }, | ||
| 51 | { 1.236, 6, "1.236" }, | ||
| 52 | { 12.36, -1, "12.36" }, | ||
| 53 | { 12.36, 0, "1e+01" }, | ||
| 54 | { 12.36, 1, "1e+01" }, | ||
| 55 | { 12.36, 2, "12" }, | ||
| 56 | { 12.36, 3, "12.4" }, | ||
| 57 | { 12.36, 4, "12.36" }, | ||
| 58 | { 12.36, 5, "12.36" }, | ||
| 59 | { 12.36, 6, "12.36" }, | ||
| 60 | { 123.6, -1, "123.6" }, | ||
| 61 | { 123.6, 0, "1e+02" }, | ||
| 62 | { 123.6, 1, "1e+02" }, | ||
| 63 | { 123.6, 2, "1.2e+02" }, | ||
| 64 | { 123.6, 3, "124" }, | ||
| 65 | { 123.6, 4, "123.6" }, | ||
| 66 | { 123.6, 5, "123.6" }, | ||
| 67 | { 123.6, 6, "123.6" }, | ||
| 68 | { 1236.0, -1, "1236" }, | ||
| 69 | { 1236.0, 0, "1e+03" }, | ||
| 70 | { 1236.0, 1, "1e+03" }, | ||
| 71 | { 1236.0, 2, "1.2e+03" }, | ||
| 72 | { 1236.0, 3, "1.24e+03" }, | ||
| 73 | { 1236.0, 4, "1236" }, | ||
| 74 | { 1236.0, 5, "1236" }, | ||
| 75 | { 1236.0, 6, "1236" }, | ||
| 76 | { 1e100, 10, "1e+100" }, | ||
| 77 | { 1e100, 20, "1.0000000000000000159e+100" }, | ||
| 78 | { 0.01236, -1, "0.01236" }, | ||
| 79 | { 0.01236, 0, "0.01" }, | ||
| 80 | { 0.01236, 1, "0.01" }, | ||
| 81 | { 0.01236, 2, "0.012" }, | ||
| 82 | { 0.01236, 3, "0.0124" }, | ||
| 83 | { 0.01236, 4, "0.01236" }, | ||
| 84 | { 1e-100, 20, "1.00000000000000002e-100" }, | ||
| 85 | { 1e-100, -1, "1e-100" }, | ||
| 86 | { -1.2, 5, "-1.2" }, | ||
| 87 | { -0.03, 5, "-0.03" }, | ||
| 88 | { 0.1, 1, "0.1" }, | ||
| 89 | { 0.1, 0, "0.1" }, | ||
| 90 | { 0.099999, 10, "0.099999" }, | ||
| 91 | { 0.99999, 10, "0.99999" }, | ||
| 92 | }; | ||
| 93 | |||
| 94 | #define NTESTVEC (sizeof(test_vectors) / sizeof(test_vectors[0])) | ||
| 95 | |||
| 96 | static int | ||
| 97 | dotest(struct test_vector *tv) | ||
| 98 | { | ||
| 99 | char buf[256], *got; | ||
| 100 | |||
| 101 | got = gcvt(tv->d, tv->ndig, buf); | ||
| 102 | if (strcmp(tv->expect, got) != 0) { | ||
| 103 | fprintf(stderr, "%g @ %d: expected %s, got %s\n", | ||
| 104 | tv->d, tv->ndig, tv->expect, got); | ||
| 105 | return 1; | ||
| 106 | } | ||
| 107 | return 0; | ||
| 108 | } | ||
| 109 | |||
| 110 | int | ||
| 111 | main(int argc, char *argv[]) | ||
| 112 | { | ||
| 113 | int i, failures = 0; | ||
| 114 | |||
| 115 | for (i = 0; i < NTESTVEC; i++) { | ||
| 116 | failures += dotest(&test_vectors[i]); | ||
| 117 | } | ||
| 118 | |||
| 119 | return failures; | ||
| 120 | } | ||
diff --git a/src/regress/lib/libc/getaddrinfo/Makefile b/src/regress/lib/libc/getaddrinfo/Makefile new file mode 100644 index 0000000000..4d4978a6a2 --- /dev/null +++ b/src/regress/lib/libc/getaddrinfo/Makefile | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2002/09/02 20:01:43 avsm Exp $ | ||
| 2 | |||
| 3 | PROG= gaitest | ||
| 4 | SRCS= gaitest.c | ||
| 5 | NOMAN= # defined | ||
| 6 | CLEANFILES+= out | ||
| 7 | |||
| 8 | REGRESS_TARGETS=do-test | ||
| 9 | |||
| 10 | do-test: ${PROG} | ||
| 11 | sh ${.CURDIR}/testsuite.sh >out 2>&1 | ||
| 12 | @if diff -u out ${.CURDIR}/answer; then \ | ||
| 13 | echo SUCCESS; \ | ||
| 14 | else \ | ||
| 15 | echo FAIL; \ | ||
| 16 | exit 1; \ | ||
| 17 | fi | ||
| 18 | |||
| 19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getaddrinfo/answer b/src/regress/lib/libc/getaddrinfo/answer new file mode 100644 index 0000000000..778fc64baa --- /dev/null +++ b/src/regress/lib/libc/getaddrinfo/answer | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | == basic ones | ||
| 2 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv http | ||
| 3 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
| 4 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv http | ||
| 5 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
| 6 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv http | ||
| 7 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
| 8 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
| 9 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv tftp | ||
| 10 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 | ||
| 11 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv tftp | ||
| 12 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 | ||
| 13 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv tftp | ||
| 14 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 | ||
| 15 | ai2: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 | ||
| 16 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv echo | ||
| 17 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7 | ||
| 18 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7 | ||
| 19 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv echo | ||
| 20 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7 | ||
| 21 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7 | ||
| 22 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv echo | ||
| 23 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7 | ||
| 24 | ai2: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7 | ||
| 25 | ai3: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7 | ||
| 26 | ai4: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7 | ||
| 27 | |||
| 28 | == specific address family | ||
| 29 | arg: flags 0x2 family 2 socktype 0 protocol 0 addrlen 0 host localhost serv http | ||
| 30 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
| 31 | arg: flags 0x2 family 24 socktype 0 protocol 0 addrlen 0 host localhost serv http | ||
| 32 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
| 33 | |||
| 34 | == empty hostname | ||
| 35 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http | ||
| 36 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
| 37 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
| 38 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo | ||
| 39 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7 | ||
| 40 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7 | ||
| 41 | ai3: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7 | ||
| 42 | ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7 | ||
| 43 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp | ||
| 44 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 | ||
| 45 | ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 | ||
| 46 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80 | ||
| 47 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 80 | ||
| 48 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
| 49 | ai3: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 80 | ||
| 50 | ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
| 51 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http | ||
| 52 | ai1: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 80 | ||
| 53 | ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 80 | ||
| 54 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo | ||
| 55 | ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 7 | ||
| 56 | ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 7 | ||
| 57 | ai3: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 7 | ||
| 58 | ai4: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 7 | ||
| 59 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp | ||
| 60 | ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 69 | ||
| 61 | ai2: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 69 | ||
| 62 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80 | ||
| 63 | ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 80 | ||
| 64 | ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 80 | ||
| 65 | ai3: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 80 | ||
| 66 | ai4: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 80 | ||
| 67 | arg: flags 0x2 family 0 socktype 1 protocol 0 addrlen 0 host (empty) serv 80 | ||
| 68 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
| 69 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
| 70 | arg: flags 0x2 family 0 socktype 2 protocol 0 addrlen 0 host (empty) serv 80 | ||
| 71 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 80 | ||
| 72 | ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 80 | ||
| 73 | |||
| 74 | == empty servname | ||
| 75 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv (empty) | ||
| 76 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 | ||
| 77 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 | ||
| 78 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv (empty) | ||
| 79 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 | ||
| 80 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 | ||
| 81 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv (empty) | ||
| 82 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 | ||
| 83 | ai2: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 | ||
| 84 | ai3: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 | ||
| 85 | ai4: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 | ||
| 86 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv (empty) | ||
| 87 | name or service is not known | ||
| 88 | |||
| 89 | == sock_raw | ||
| 90 | arg: flags 0x2 family 0 socktype 3 protocol 0 addrlen 0 host localhost serv (empty) | ||
| 91 | ai1: flags 0x2 family 2 socktype 3 protocol 0 addrlen 16 host 127.0.0.1 serv 0 | ||
| 92 | ai2: flags 0x2 family 24 socktype 3 protocol 0 addrlen 28 host ::1 serv 0 | ||
| 93 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv (empty) | ||
| 94 | ai1: flags 0x2 family 2 socktype 3 protocol 59 addrlen 16 host 127.0.0.1 serv 0 | ||
| 95 | ai2: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 | ||
| 96 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv 80 | ||
| 97 | service not supported for ai_socktype | ||
| 98 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv www | ||
| 99 | service not supported for ai_socktype | ||
| 100 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host ::1 serv (empty) | ||
| 101 | ai1: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 | ||
| 102 | |||
| 103 | == unsupported family | ||
| 104 | arg: flags 0x2 family 99 socktype 0 protocol 0 addrlen 0 host localhost serv (empty) | ||
| 105 | ai_family not supported | ||
| 106 | |||
| 107 | == the following items are specified in jinmei scopeaddr format doc. | ||
| 108 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host fe80::1%lo0 serv http | ||
| 109 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host fe80::1%lo0 serv 80 | ||
| 110 | |||
diff --git a/src/regress/lib/libc/getaddrinfo/gaitest.c b/src/regress/lib/libc/getaddrinfo/gaitest.c new file mode 100644 index 0000000000..12a4498459 --- /dev/null +++ b/src/regress/lib/libc/getaddrinfo/gaitest.c | |||
| @@ -0,0 +1,195 @@ | |||
| 1 | /* $OpenBSD: gaitest.c,v 1.6 2009/06/09 18:15:08 phessler Exp $ */ | ||
| 2 | /* $NetBSD: gaitest.c,v 1.3 2002/07/05 15:47:43 itojun Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project. | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. Neither the name of the project nor the names of its contributors | ||
| 17 | * may be used to endorse or promote products derived from this software | ||
| 18 | * without specific prior written permission. | ||
| 19 | * | ||
| 20 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | ||
| 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | ||
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 30 | * SUCH DAMAGE. | ||
| 31 | */ | ||
| 32 | |||
| 33 | /* | ||
| 34 | * Please note: the order of the responses (and the regress test) | ||
| 35 | * is dependent on the "family" keywords in resolv.conf. | ||
| 36 | * | ||
| 37 | * This expects the default behaviour of "family inet4 inet6" | ||
| 38 | */ | ||
| 39 | |||
| 40 | #include <sys/types.h> | ||
| 41 | #include <sys/socket.h> | ||
| 42 | #include <netinet/in.h> | ||
| 43 | #include <arpa/inet.h> | ||
| 44 | #include <netdb.h> | ||
| 45 | #include <stdio.h> | ||
| 46 | #include <stdlib.h> | ||
| 47 | #include <string.h> | ||
| 48 | #include <unistd.h> | ||
| 49 | |||
| 50 | struct addrinfo ai; | ||
| 51 | |||
| 52 | char host[NI_MAXHOST]; | ||
| 53 | char serv[NI_MAXSERV]; | ||
| 54 | int vflag = 0; | ||
| 55 | |||
| 56 | static void usage(void); | ||
| 57 | static void print1(const char *, const struct addrinfo *, char *, char *); | ||
| 58 | int main(int, char *[]); | ||
| 59 | |||
| 60 | static void | ||
| 61 | usage() | ||
| 62 | { | ||
| 63 | fprintf(stderr, "usage: test [-f family] [-s socktype] [-p proto] [-DPRSv46] host serv\n"); | ||
| 64 | } | ||
| 65 | |||
| 66 | static void | ||
| 67 | print1(title, res, h, s) | ||
| 68 | const char *title; | ||
| 69 | const struct addrinfo *res; | ||
| 70 | char *h; | ||
| 71 | char *s; | ||
| 72 | { | ||
| 73 | char *start, *end; | ||
| 74 | int error; | ||
| 75 | const int niflag = NI_NUMERICHOST | NI_NUMERICSERV; | ||
| 76 | |||
| 77 | if (res->ai_addr) { | ||
| 78 | error = getnameinfo(res->ai_addr, res->ai_addr->sa_len, | ||
| 79 | host, sizeof(host), serv, sizeof(serv), | ||
| 80 | niflag); | ||
| 81 | h = host; | ||
| 82 | s = serv; | ||
| 83 | } else | ||
| 84 | error = 0; | ||
| 85 | |||
| 86 | if (vflag) { | ||
| 87 | start = "\t"; | ||
| 88 | end = "\n"; | ||
| 89 | } else { | ||
| 90 | start = " "; | ||
| 91 | end = ""; | ||
| 92 | } | ||
| 93 | printf("%s%s", title, end); | ||
| 94 | printf("%sflags 0x%x%s", start, res->ai_flags, end); | ||
| 95 | printf("%sfamily %d%s", start, res->ai_family, end); | ||
| 96 | printf("%ssocktype %d%s", start, res->ai_socktype, end); | ||
| 97 | printf("%sprotocol %d%s", start, res->ai_protocol, end); | ||
| 98 | printf("%saddrlen %d%s", start, res->ai_addrlen, end); | ||
| 99 | if (error) | ||
| 100 | printf("%serror %d%s", start, error, end); | ||
| 101 | else { | ||
| 102 | printf("%shost %s%s", start, h, end); | ||
| 103 | printf("%sserv %s%s", start, s, end); | ||
| 104 | } | ||
| 105 | #if 0 | ||
| 106 | if (res->ai_canonname) | ||
| 107 | printf("%scname \"%s\"%s", start, res->ai_canonname, end); | ||
| 108 | #endif | ||
| 109 | if (!vflag) | ||
| 110 | printf("\n"); | ||
| 111 | |||
| 112 | } | ||
| 113 | |||
| 114 | int | ||
| 115 | main(argc, argv) | ||
| 116 | int argc; | ||
| 117 | char *argv[]; | ||
| 118 | { | ||
| 119 | struct addrinfo *res; | ||
| 120 | int error, i; | ||
| 121 | char *p, *q; | ||
| 122 | extern int optind; | ||
| 123 | extern char *optarg; | ||
| 124 | int c; | ||
| 125 | char nbuf[10]; | ||
| 126 | |||
| 127 | memset(&ai, 0, sizeof(ai)); | ||
| 128 | ai.ai_family = PF_UNSPEC; | ||
| 129 | ai.ai_flags |= AI_CANONNAME; | ||
| 130 | while ((c = getopt(argc, argv, "Df:p:PRs:Sv46")) != -1) { | ||
| 131 | switch (c) { | ||
| 132 | case 'D': | ||
| 133 | ai.ai_socktype = SOCK_DGRAM; | ||
| 134 | break; | ||
| 135 | case 'f': | ||
| 136 | ai.ai_family = atoi(optarg); | ||
| 137 | break; | ||
| 138 | case 'p': | ||
| 139 | ai.ai_protocol = atoi(optarg); | ||
| 140 | break; | ||
| 141 | case 'P': | ||
| 142 | ai.ai_flags |= AI_PASSIVE; | ||
| 143 | break; | ||
| 144 | case 'R': | ||
| 145 | ai.ai_socktype = SOCK_RAW; | ||
| 146 | break; | ||
| 147 | case 's': | ||
| 148 | ai.ai_socktype = atoi(optarg); | ||
| 149 | break; | ||
| 150 | case 'S': | ||
| 151 | ai.ai_socktype = SOCK_STREAM; | ||
| 152 | break; | ||
| 153 | case 'v': | ||
| 154 | vflag++; | ||
| 155 | break; | ||
| 156 | case '4': | ||
| 157 | ai.ai_family = PF_INET; | ||
| 158 | break; | ||
| 159 | case '6': | ||
| 160 | ai.ai_family = PF_INET6; | ||
| 161 | break; | ||
| 162 | default: | ||
| 163 | usage(); | ||
| 164 | exit(1); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | argc -= optind; | ||
| 168 | argv += optind; | ||
| 169 | |||
| 170 | if (argc != 2){ | ||
| 171 | usage(); | ||
| 172 | exit(1); | ||
| 173 | } | ||
| 174 | |||
| 175 | p = *argv[0] ? argv[0] : NULL; | ||
| 176 | q = *argv[1] ? argv[1] : NULL; | ||
| 177 | |||
| 178 | print1("arg:", &ai, p ? p : "(empty)", q ? q : "(empty)"); | ||
| 179 | |||
| 180 | error = getaddrinfo(p, q, &ai, &res); | ||
| 181 | if (error) { | ||
| 182 | printf("%s\n", gai_strerror(error)); | ||
| 183 | exit(1); | ||
| 184 | } | ||
| 185 | |||
| 186 | i = 1; | ||
| 187 | do { | ||
| 188 | snprintf(nbuf, sizeof(nbuf), "ai%d:", i); | ||
| 189 | print1(nbuf, res, NULL, NULL); | ||
| 190 | |||
| 191 | i++; | ||
| 192 | } while ((res = res->ai_next) != NULL); | ||
| 193 | |||
| 194 | exit(0); | ||
| 195 | } | ||
diff --git a/src/regress/lib/libc/getaddrinfo/testsuite.sh b/src/regress/lib/libc/getaddrinfo/testsuite.sh new file mode 100644 index 0000000000..1e4e524054 --- /dev/null +++ b/src/regress/lib/libc/getaddrinfo/testsuite.sh | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | # $OpenBSD: testsuite.sh,v 1.1 2002/07/05 15:54:30 itojun Exp $ | ||
| 2 | # $NetBSD: testsuite.sh,v 1.3 2002/07/05 15:49:11 itojun Exp $ | ||
| 3 | |||
| 4 | # | ||
| 5 | # Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project. | ||
| 6 | # All rights reserved. | ||
| 7 | # | ||
| 8 | # Redistribution and use in source and binary forms, with or without | ||
| 9 | # modification, are permitted provided that the following conditions | ||
| 10 | # are met: | ||
| 11 | # 1. Redistributions of source code must retain the above copyright | ||
| 12 | # notice, this list of conditions and the following disclaimer. | ||
| 13 | # 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | # notice, this list of conditions and the following disclaimer in the | ||
| 15 | # documentation and/or other materials provided with the distribution. | ||
| 16 | # 3. Neither the name of the project nor the names of its contributors | ||
| 17 | # may be used to endorse or promote products derived from this software | ||
| 18 | # without specific prior written permission. | ||
| 19 | # | ||
| 20 | # THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | ||
| 21 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | ||
| 24 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 25 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 26 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 27 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 28 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 29 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 30 | # SUCH DAMAGE. | ||
| 31 | # | ||
| 32 | |||
| 33 | TEST=./gaitest | ||
| 34 | #TEST='./test -v' | ||
| 35 | #IF=`ifconfig -a | grep -v '^ ' | sed -e 's/:.*//' | head -1 | awk '{print $1}'` | ||
| 36 | |||
| 37 | echo '== basic ones' | ||
| 38 | $TEST ::1 http | ||
| 39 | $TEST 127.0.0.1 http | ||
| 40 | $TEST localhost http | ||
| 41 | $TEST ::1 tftp | ||
| 42 | $TEST 127.0.0.1 tftp | ||
| 43 | $TEST localhost tftp | ||
| 44 | $TEST ::1 echo | ||
| 45 | $TEST 127.0.0.1 echo | ||
| 46 | $TEST localhost echo | ||
| 47 | echo | ||
| 48 | |||
| 49 | echo '== specific address family' | ||
| 50 | $TEST -4 localhost http | ||
| 51 | $TEST -6 localhost http | ||
| 52 | echo | ||
| 53 | |||
| 54 | echo '== empty hostname' | ||
| 55 | $TEST '' http | ||
| 56 | $TEST '' echo | ||
| 57 | $TEST '' tftp | ||
| 58 | $TEST '' 80 | ||
| 59 | $TEST -P '' http | ||
| 60 | $TEST -P '' echo | ||
| 61 | $TEST -P '' tftp | ||
| 62 | $TEST -P '' 80 | ||
| 63 | $TEST -S '' 80 | ||
| 64 | $TEST -D '' 80 | ||
| 65 | echo | ||
| 66 | |||
| 67 | echo '== empty servname' | ||
| 68 | $TEST ::1 '' | ||
| 69 | $TEST 127.0.0.1 '' | ||
| 70 | $TEST localhost '' | ||
| 71 | $TEST '' '' | ||
| 72 | echo | ||
| 73 | |||
| 74 | echo '== sock_raw' | ||
| 75 | $TEST -R -p 0 localhost '' | ||
| 76 | $TEST -R -p 59 localhost '' | ||
| 77 | $TEST -R -p 59 localhost 80 | ||
| 78 | $TEST -R -p 59 localhost www | ||
| 79 | $TEST -R -p 59 ::1 '' | ||
| 80 | echo | ||
| 81 | |||
| 82 | echo '== unsupported family' | ||
| 83 | $TEST -f 99 localhost '' | ||
| 84 | echo | ||
| 85 | |||
| 86 | echo '== the following items are specified in jinmei scopeaddr format doc.' | ||
| 87 | $TEST fe80::1%lo0 http | ||
| 88 | #$TEST fe80::1%$IF http | ||
| 89 | echo | ||
diff --git a/src/regress/lib/libc/getcap/Makefile b/src/regress/lib/libc/getcap/Makefile new file mode 100644 index 0000000000..7b7ae394ff --- /dev/null +++ b/src/regress/lib/libc/getcap/Makefile | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2009/06/09 18:16:40 phessler Exp $ | ||
| 2 | |||
| 3 | PROG= getcaptest | ||
| 4 | |||
| 5 | REGRESS_TARGETS=shortcap | ||
| 6 | |||
| 7 | shortcap: getcaptest | ||
| 8 | ./getcaptest ${.CURDIR}/shortcap.in | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getcap/getcaptest.c b/src/regress/lib/libc/getcap/getcaptest.c new file mode 100644 index 0000000000..0f4464b6c5 --- /dev/null +++ b/src/regress/lib/libc/getcap/getcaptest.c | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | /* $OpenBSD: getcaptest.c,v 1.1 2006/03/10 05:28:57 ray Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Written by Raymond Lai <ray@cyth.net>. | ||
| 5 | * Public domain. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <stdio.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | |||
| 11 | int | ||
| 12 | main(int argc, char *argv[]) | ||
| 13 | { | ||
| 14 | char *buf, *db_array[2]; | ||
| 15 | |||
| 16 | if (argc != 2) | ||
| 17 | return (1); | ||
| 18 | |||
| 19 | db_array[0] = argv[1]; | ||
| 20 | db_array[1] = NULL; | ||
| 21 | |||
| 22 | while (cgetnext(&buf, db_array) > 0) | ||
| 23 | puts(buf); | ||
| 24 | |||
| 25 | return (0); | ||
| 26 | } | ||
diff --git a/src/regress/lib/libc/getcap/shortcap.in b/src/regress/lib/libc/getcap/shortcap.in new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/src/regress/lib/libc/getcap/shortcap.in | |||
| @@ -0,0 +1 @@ | |||
| 0 | |||
diff --git a/src/regress/lib/libc/getopt_long/Makefile b/src/regress/lib/libc/getopt_long/Makefile new file mode 100644 index 0000000000..13a187e190 --- /dev/null +++ b/src/regress/lib/libc/getopt_long/Makefile | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2002/12/08 19:25:08 millert Exp $ | ||
| 2 | |||
| 3 | NOMAN= | ||
| 4 | PROG=getopt_long_test | ||
| 5 | CLEANFILES+=test.out | ||
| 6 | |||
| 7 | # test getopt_long and getopt_long_only | ||
| 8 | run-regress-${PROG}: ${PROG} | ||
| 9 | @( test -n "$$POSIXLY_CORRECT" && unset POSIXLY_CORRECT; \ | ||
| 10 | test -n "$$LONG_ONLY" && unset LONG_ONLY; \ | ||
| 11 | ./${PROG} myfile --force -f infile -9 ; \ | ||
| 12 | ./${PROG} onefile twofile --best -Williterate -i foo.in threefile ; \ | ||
| 13 | ./${PROG} -1bfast - ; \ | ||
| 14 | ./${PROG} --fast --drinking=guiness -i foo.in somefile ; \ | ||
| 15 | export POSIXLY_CORRECT=1 ; \ | ||
| 16 | ./${PROG} myfile --force -f infile -9 ; \ | ||
| 17 | ./${PROG} onefile twofile --best -Williterate -i foo.in threefile ; \ | ||
| 18 | ./${PROG} -1bfast - ; \ | ||
| 19 | ./${PROG} --fast --drinking=guiness -i foo.in somefile ; \ | ||
| 20 | unset POSIXLY_CORRECT ; export LONG_ONLY=1 ; \ | ||
| 21 | ./${PROG} myfile -force -f infile -9 ; \ | ||
| 22 | ./${PROG} onefile twofile -best -Williterate -i foo.in threefile ; \ | ||
| 23 | ./${PROG} -1bfast - ; \ | ||
| 24 | ./${PROG} --fast -drinking=guiness -i foo.in somefile ; \ | ||
| 25 | export POSIXLY_CORRECT=1 ; \ | ||
| 26 | ./${PROG} myfile -force -f infile -9 ; \ | ||
| 27 | ./${PROG} onefile twofile -best -Williterate -i foo.in threefile ; \ | ||
| 28 | ./${PROG} -1bfast - ; \ | ||
| 29 | ./${PROG} --fast -drinking=guiness -i foo.in somefile ) >test.out 2>&1 | ||
| 30 | cmp -s ${.OBJDIR}/test.out ${.CURDIR}/test.ok | ||
| 31 | |||
| 32 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getopt_long/getopt_long_test.c b/src/regress/lib/libc/getopt_long/getopt_long_test.c new file mode 100644 index 0000000000..9f6f603702 --- /dev/null +++ b/src/regress/lib/libc/getopt_long/getopt_long_test.c | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | * | ||
| 16 | * Sponsored in part by the Defense Advanced Research Projects | ||
| 17 | * Agency (DARPA) and Air Force Research Laboratory, Air Force | ||
| 18 | * Materiel Command, USAF, under agreement number F39502-99-1-0512. | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdio.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include <getopt.h> | ||
| 24 | |||
| 25 | /* | ||
| 26 | * Simple getopt_long() and getopt_long_only() excerciser. | ||
| 27 | * ENVIRONMENT: | ||
| 28 | * LONG_ONLY : use getopt_long_only() (default is getopt_long()) | ||
| 29 | * POSIXLY_CORRECT : don't permute args | ||
| 30 | */ | ||
| 31 | |||
| 32 | int | ||
| 33 | main(int argc, char **argv) | ||
| 34 | { | ||
| 35 | int ch, idx, goggles; | ||
| 36 | int (*gl)(int, char * const *, const char *, const struct option *, int *); | ||
| 37 | struct option longopts[] = { | ||
| 38 | { "force", no_argument, 0, 0 }, | ||
| 39 | { "fast", no_argument, 0, '1' }, | ||
| 40 | { "best", no_argument, 0, '9' }, | ||
| 41 | { "input", required_argument, 0, 'i' }, | ||
| 42 | { "illiterate", no_argument, 0, 0 }, | ||
| 43 | { "drinking", required_argument, &goggles, 42 }, | ||
| 44 | { "help", no_argument, 0, 'h' }, | ||
| 45 | { 0, 0, 0, 0 }, | ||
| 46 | }; | ||
| 47 | |||
| 48 | if (getenv("LONG_ONLY")) { | ||
| 49 | gl = getopt_long_only; | ||
| 50 | printf("getopt_long_only"); | ||
| 51 | } else { | ||
| 52 | gl = getopt_long; | ||
| 53 | printf("getopt_long"); | ||
| 54 | } | ||
| 55 | if (getenv("POSIXLY_CORRECT")) | ||
| 56 | printf(" (POSIXLY_CORRECT)"); | ||
| 57 | printf(": "); | ||
| 58 | for (idx = 1; idx < argc; idx++) | ||
| 59 | printf("%s ", argv[idx]); | ||
| 60 | printf("\n"); | ||
| 61 | |||
| 62 | goggles = 0; | ||
| 63 | for (;;) { | ||
| 64 | idx = -1; | ||
| 65 | ch = gl(argc, argv, "19bf:i:hW;-", longopts, &idx); | ||
| 66 | if (ch == -1) | ||
| 67 | break; | ||
| 68 | switch (ch) { | ||
| 69 | case 0: | ||
| 70 | case '1': | ||
| 71 | case '9': | ||
| 72 | case 'h': | ||
| 73 | case 'b': | ||
| 74 | case '-': | ||
| 75 | if (idx != -1) { | ||
| 76 | if (goggles == 42) | ||
| 77 | printf("option %s, arg %s\n", | ||
| 78 | longopts[idx].name, optarg); | ||
| 79 | else | ||
| 80 | printf("option %s\n", | ||
| 81 | longopts[idx].name); | ||
| 82 | } else | ||
| 83 | printf("option %c\n", ch); | ||
| 84 | break; | ||
| 85 | case 'f': | ||
| 86 | case 'i': | ||
| 87 | if (idx != -1) | ||
| 88 | printf("option %s, arg %s\n", | ||
| 89 | longopts[idx].name, optarg); | ||
| 90 | else | ||
| 91 | printf("option %c, arg %s\n", ch, optarg); | ||
| 92 | break; | ||
| 93 | |||
| 94 | case '?': | ||
| 95 | break; | ||
| 96 | |||
| 97 | default: | ||
| 98 | printf("unexpected return value: %c\n", ch); | ||
| 99 | break; | ||
| 100 | } | ||
| 101 | } | ||
| 102 | argc -= optind; | ||
| 103 | argv += optind; | ||
| 104 | |||
| 105 | if (argc > 0) { | ||
| 106 | printf("remaining ARGV: "); | ||
| 107 | while (argc--) | ||
| 108 | printf("%s ", *argv++); | ||
| 109 | printf("\n"); | ||
| 110 | } | ||
| 111 | printf("\n"); | ||
| 112 | |||
| 113 | exit (0); | ||
| 114 | } | ||
diff --git a/src/regress/lib/libc/getopt_long/test.ok b/src/regress/lib/libc/getopt_long/test.ok new file mode 100644 index 0000000000..9782087f40 --- /dev/null +++ b/src/regress/lib/libc/getopt_long/test.ok | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | getopt_long: myfile --force -f infile -9 | ||
| 2 | option force | ||
| 3 | option f, arg infile | ||
| 4 | option 9 | ||
| 5 | remaining ARGV: myfile | ||
| 6 | |||
| 7 | getopt_long: onefile twofile --best -Williterate -i foo.in threefile | ||
| 8 | option best | ||
| 9 | option illiterate | ||
| 10 | option i, arg foo.in | ||
| 11 | remaining ARGV: onefile twofile threefile | ||
| 12 | |||
| 13 | getopt_long: -1bfast - | ||
| 14 | option 1 | ||
| 15 | option b | ||
| 16 | option f, arg ast | ||
| 17 | option - | ||
| 18 | |||
| 19 | getopt_long: --fast --drinking=guiness -i foo.in somefile | ||
| 20 | option fast | ||
| 21 | option drinking, arg guiness | ||
| 22 | option i, arg foo.in | ||
| 23 | remaining ARGV: somefile | ||
| 24 | |||
| 25 | getopt_long (POSIXLY_CORRECT): myfile --force -f infile -9 | ||
| 26 | remaining ARGV: myfile --force -f infile -9 | ||
| 27 | |||
| 28 | getopt_long (POSIXLY_CORRECT): onefile twofile --best -Williterate -i foo.in threefile | ||
| 29 | remaining ARGV: onefile twofile --best -Williterate -i foo.in threefile | ||
| 30 | |||
| 31 | getopt_long (POSIXLY_CORRECT): -1bfast - | ||
| 32 | option 1 | ||
| 33 | option b | ||
| 34 | option f, arg ast | ||
| 35 | option - | ||
| 36 | |||
| 37 | getopt_long (POSIXLY_CORRECT): --fast --drinking=guiness -i foo.in somefile | ||
| 38 | option fast | ||
| 39 | option drinking, arg guiness | ||
| 40 | option i, arg foo.in | ||
| 41 | remaining ARGV: somefile | ||
| 42 | |||
| 43 | getopt_long_only: myfile -force -f infile -9 | ||
| 44 | option force | ||
| 45 | option f, arg infile | ||
| 46 | option 9 | ||
| 47 | remaining ARGV: myfile | ||
| 48 | |||
| 49 | getopt_long_only: onefile twofile -best -Williterate -i foo.in threefile | ||
| 50 | option best | ||
| 51 | option illiterate | ||
| 52 | option i, arg foo.in | ||
| 53 | remaining ARGV: onefile twofile threefile | ||
| 54 | |||
| 55 | getopt_long_only: -1bfast - | ||
| 56 | option 1 | ||
| 57 | option b | ||
| 58 | option fast | ||
| 59 | option - | ||
| 60 | |||
| 61 | getopt_long_only: --fast -drinking=guiness -i foo.in somefile | ||
| 62 | option fast | ||
| 63 | option drinking, arg guiness | ||
| 64 | option i, arg foo.in | ||
| 65 | remaining ARGV: somefile | ||
| 66 | |||
| 67 | getopt_long_only (POSIXLY_CORRECT): myfile -force -f infile -9 | ||
| 68 | remaining ARGV: myfile -force -f infile -9 | ||
| 69 | |||
| 70 | getopt_long_only (POSIXLY_CORRECT): onefile twofile -best -Williterate -i foo.in threefile | ||
| 71 | remaining ARGV: onefile twofile -best -Williterate -i foo.in threefile | ||
| 72 | |||
| 73 | getopt_long_only (POSIXLY_CORRECT): -1bfast - | ||
| 74 | option 1 | ||
| 75 | option b | ||
| 76 | option fast | ||
| 77 | option - | ||
| 78 | |||
| 79 | getopt_long_only (POSIXLY_CORRECT): --fast -drinking=guiness -i foo.in somefile | ||
| 80 | option fast | ||
| 81 | option drinking, arg guiness | ||
| 82 | option i, arg foo.in | ||
| 83 | remaining ARGV: somefile | ||
| 84 | |||
diff --git a/src/regress/lib/libc/glob/Makefile b/src/regress/lib/libc/glob/Makefile new file mode 100644 index 0000000000..ef209a3e18 --- /dev/null +++ b/src/regress/lib/libc/glob/Makefile | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2010/09/24 13:32:55 djm Exp $ | ||
| 2 | |||
| 3 | PROG= globtest | ||
| 4 | |||
| 5 | run-regress-${PROG}: | ||
| 6 | mkdir -p `sed 's@/[^/]*$$@@' ${.CURDIR}/files | sort -u` | ||
| 7 | touch `cat ${.CURDIR}/files` | ||
| 8 | chmod 0755 `grep '/r[^/]*$$' ${.CURDIR}/files` | ||
| 9 | chmod 0444 `grep '/s[^/]*$$' ${.CURDIR}/files` | ||
| 10 | chmod 0711 `grep '/t[^/]*$$' ${.CURDIR}/files` | ||
| 11 | ./${PROG} ${.CURDIR}/${PROG}.in | ||
| 12 | |||
| 13 | clean: | ||
| 14 | rm -rf fake ${PROG} ${OBJS} *.core | ||
| 15 | |||
| 16 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/glob/files b/src/regress/lib/libc/glob/files new file mode 100644 index 0000000000..c5e92aacd5 --- /dev/null +++ b/src/regress/lib/libc/glob/files | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | fake/bin/[ | ||
| 2 | fake/bin/cat | ||
| 3 | fake/bin/chgrp | ||
| 4 | fake/bin/chio | ||
| 5 | fake/bin/chmod | ||
| 6 | fake/bin/cksum | ||
| 7 | fake/bin/cp | ||
| 8 | fake/bin/cpio | ||
| 9 | fake/bin/csh | ||
| 10 | fake/bin/date | ||
| 11 | fake/bin/dd | ||
| 12 | fake/bin/df | ||
| 13 | fake/bin/domainname | ||
| 14 | fake/bin/echo | ||
| 15 | fake/bin/ed | ||
| 16 | fake/bin/eject | ||
| 17 | fake/bin/expr | ||
| 18 | fake/bin/hostname | ||
| 19 | fake/bin/kill | ||
| 20 | fake/bin/ksh | ||
| 21 | fake/bin/ln | ||
| 22 | fake/bin/ls | ||
| 23 | fake/bin/md5 | ||
| 24 | fake/bin/mkdir | ||
| 25 | fake/bin/mt | ||
| 26 | fake/bin/mv | ||
| 27 | fake/bin/pax | ||
| 28 | fake/bin/ps | ||
| 29 | fake/bin/pwd | ||
| 30 | fake/bin/rcp | ||
| 31 | fake/bin/rksh | ||
| 32 | fake/bin/rm | ||
| 33 | fake/bin/rmail | ||
| 34 | fake/bin/rmd160 | ||
| 35 | fake/bin/rmdir | ||
| 36 | fake/bin/sh | ||
| 37 | fake/bin/sha1 | ||
| 38 | fake/bin/sha256 | ||
| 39 | fake/bin/sha384 | ||
| 40 | fake/bin/sha512 | ||
| 41 | fake/bin/sleep | ||
| 42 | fake/bin/stty | ||
| 43 | fake/bin/sum | ||
| 44 | fake/bin/sync | ||
| 45 | fake/bin/systrace | ||
| 46 | fake/bin/tar | ||
| 47 | fake/bin/test | ||
diff --git a/src/regress/lib/libc/glob/globtest.c b/src/regress/lib/libc/glob/globtest.c new file mode 100644 index 0000000000..e47a728da8 --- /dev/null +++ b/src/regress/lib/libc/glob/globtest.c | |||
| @@ -0,0 +1,144 @@ | |||
| 1 | /* $OpenBSD: globtest.c,v 1.2 2010/09/24 13:32:55 djm Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Public domain, 2008, Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <err.h> | ||
| 8 | #include <glob.h> | ||
| 9 | #include <stdio.h> | ||
| 10 | #include <stdlib.h> | ||
| 11 | #include <string.h> | ||
| 12 | |||
| 13 | #define MAX_RESULTS 256 | ||
| 14 | |||
| 15 | struct gl_entry { | ||
| 16 | int flags; | ||
| 17 | int nresults; | ||
| 18 | char pattern[1024]; | ||
| 19 | char *results[MAX_RESULTS]; | ||
| 20 | long modes[MAX_RESULTS]; | ||
| 21 | }; | ||
| 22 | |||
| 23 | int test_glob(struct gl_entry *); | ||
| 24 | |||
| 25 | int | ||
| 26 | main(int argc, char **argv) | ||
| 27 | { | ||
| 28 | FILE *fp = stdin; | ||
| 29 | char *buf, *cp, *want, *got, *last; | ||
| 30 | const char *errstr; | ||
| 31 | int errors = 0, i, lineno, mode; | ||
| 32 | struct gl_entry entry; | ||
| 33 | size_t len; | ||
| 34 | |||
| 35 | if (argc > 1) { | ||
| 36 | if ((fp = fopen(argv[1], "r")) == NULL) | ||
| 37 | err(1, "%s", argv[1]); | ||
| 38 | } | ||
| 39 | |||
| 40 | /* | ||
| 41 | * Read in test file, which is formatted thusly: | ||
| 42 | * | ||
| 43 | * [pattern] <flags> | ||
| 44 | * result1 [mode] | ||
| 45 | * result2 [mode] | ||
| 46 | * result3 [mode] | ||
| 47 | * ... | ||
| 48 | * | ||
| 49 | */ | ||
| 50 | lineno = 0; | ||
| 51 | memset(&entry, 0, sizeof(entry)); | ||
| 52 | while ((buf = fgetln(fp, &len)) != NULL) { | ||
| 53 | lineno++; | ||
| 54 | if (buf[len - 1] != '\n') | ||
| 55 | errx(1, "missing newline at EOF"); | ||
| 56 | buf[--len] = '\0'; | ||
| 57 | if (len == 0) | ||
| 58 | continue; /* blank line */ | ||
| 59 | |||
| 60 | if (buf[0] == '[') { | ||
| 61 | /* check previous pattern */ | ||
| 62 | if (entry.pattern[0]) | ||
| 63 | errors += test_glob(&entry); | ||
| 64 | |||
| 65 | /* start new entry */ | ||
| 66 | if ((cp = strrchr(buf + 1, ']')) == NULL) | ||
| 67 | errx(1, "invalid entry on line %d", lineno); | ||
| 68 | len = cp - buf - 1; | ||
| 69 | if (len >= sizeof(entry.pattern)) | ||
| 70 | errx(1, "pattern too big on line %d", lineno); | ||
| 71 | memcpy(entry.pattern, buf + 1, len); | ||
| 72 | entry.pattern[len] = '\0'; | ||
| 73 | |||
| 74 | buf = cp + 2; | ||
| 75 | if (*buf++ != '<') | ||
| 76 | errx(1, "invalid entry on line %d", lineno); | ||
| 77 | if ((cp = strchr(buf, '>')) == NULL) | ||
| 78 | errx(1, "invalid entry on line %d", lineno); | ||
| 79 | entry.flags = (int)strtol(buf, &cp, 0); | ||
| 80 | if (*cp != '>' || entry.flags < 0 || entry.flags > 0x4000) | ||
| 81 | errx(1, "invalid flags: %s", buf); | ||
| 82 | entry.nresults = 0; | ||
| 83 | continue; | ||
| 84 | } | ||
| 85 | if (!entry.pattern[0]) | ||
| 86 | errx(1, "missing entry on line %d", lineno); | ||
| 87 | |||
| 88 | if (entry.nresults + 1 > MAX_RESULTS) { | ||
| 89 | errx(1, "too many results for %s, max %d", | ||
| 90 | entry.pattern, MAX_RESULTS); | ||
| 91 | } | ||
| 92 | if ((cp = strchr(buf, ' ')) != NULL) { | ||
| 93 | *cp++ = '\0'; | ||
| 94 | mode = strtol(cp, NULL, 8); | ||
| 95 | } else | ||
| 96 | mode = -1; | ||
| 97 | entry.modes[entry.nresults] = mode; | ||
| 98 | entry.results[entry.nresults++] = strdup(buf); | ||
| 99 | } | ||
| 100 | if (entry.pattern[0]) | ||
| 101 | errors += test_glob(&entry); /* test last pattern */ | ||
| 102 | exit(errors); | ||
| 103 | } | ||
| 104 | |||
| 105 | int test_glob(struct gl_entry *entry) | ||
| 106 | { | ||
| 107 | glob_t gl; | ||
| 108 | int i; | ||
| 109 | |||
| 110 | if (glob(entry->pattern, entry->flags, NULL, &gl) != 0) | ||
| 111 | errx(1, "glob failed: %s", entry->pattern); | ||
| 112 | |||
| 113 | if (gl.gl_matchc != entry->nresults) | ||
| 114 | goto mismatch; | ||
| 115 | |||
| 116 | for (i = 0; i < gl.gl_matchc; i++) { | ||
| 117 | if (strcmp(gl.gl_pathv[i], entry->results[i]) != 0) | ||
| 118 | goto mismatch; | ||
| 119 | if ((entry->flags & GLOB_KEEPSTAT) != 0) { | ||
| 120 | if (entry->modes[i] == -1 || | ||
| 121 | gl.gl_statv[i] == NULL || | ||
| 122 | entry->modes[i] != gl.gl_statv[i]->st_mode) | ||
| 123 | goto badmode; | ||
| 124 | } | ||
| 125 | free(entry->results[i]); | ||
| 126 | } | ||
| 127 | return (0); | ||
| 128 | badmode: | ||
| 129 | warnx("mismatch mode for pattern %s, flags 0x%x, file \"%s\" " | ||
| 130 | "(found %07o, expected %07o)", entry->pattern, entry->flags, | ||
| 131 | gl.gl_pathv[i], gl.gl_statv[i] ? gl.gl_statv[i]->st_mode : 0, | ||
| 132 | entry->modes[i]); | ||
| 133 | goto cleanup; | ||
| 134 | mismatch: | ||
| 135 | warnx("mismatch for pattern %s, flags 0x%x " | ||
| 136 | "(found \"%s\", expected \"%s\")", entry->pattern, entry->flags, | ||
| 137 | gl.gl_pathv[i], entry->results[i]); | ||
| 138 | cleanup: | ||
| 139 | while (i < gl.gl_matchc) { | ||
| 140 | free(entry->results[i++]); | ||
| 141 | } | ||
| 142 | return (0); | ||
| 143 | return (1); | ||
| 144 | } | ||
diff --git a/src/regress/lib/libc/glob/globtest.in b/src/regress/lib/libc/glob/globtest.in new file mode 100644 index 0000000000..2ae3b4dfb2 --- /dev/null +++ b/src/regress/lib/libc/glob/globtest.in | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | [fake/bin/[[:alpha:]]*] <0x0> | ||
| 2 | fake/bin/cat | ||
| 3 | fake/bin/chgrp | ||
| 4 | fake/bin/chio | ||
| 5 | fake/bin/chmod | ||
| 6 | fake/bin/cksum | ||
| 7 | fake/bin/cp | ||
| 8 | fake/bin/cpio | ||
| 9 | fake/bin/csh | ||
| 10 | fake/bin/date | ||
| 11 | fake/bin/dd | ||
| 12 | fake/bin/df | ||
| 13 | fake/bin/domainname | ||
| 14 | fake/bin/echo | ||
| 15 | fake/bin/ed | ||
| 16 | fake/bin/eject | ||
| 17 | fake/bin/expr | ||
| 18 | fake/bin/hostname | ||
| 19 | fake/bin/kill | ||
| 20 | fake/bin/ksh | ||
| 21 | fake/bin/ln | ||
| 22 | fake/bin/ls | ||
| 23 | fake/bin/md5 | ||
| 24 | fake/bin/mkdir | ||
| 25 | fake/bin/mt | ||
| 26 | fake/bin/mv | ||
| 27 | fake/bin/pax | ||
| 28 | fake/bin/ps | ||
| 29 | fake/bin/pwd | ||
| 30 | fake/bin/rcp | ||
| 31 | fake/bin/rksh | ||
| 32 | fake/bin/rm | ||
| 33 | fake/bin/rmail | ||
| 34 | fake/bin/rmd160 | ||
| 35 | fake/bin/rmdir | ||
| 36 | fake/bin/sh | ||
| 37 | fake/bin/sha1 | ||
| 38 | fake/bin/sha256 | ||
| 39 | fake/bin/sha384 | ||
| 40 | fake/bin/sha512 | ||
| 41 | fake/bin/sleep | ||
| 42 | fake/bin/stty | ||
| 43 | fake/bin/sum | ||
| 44 | fake/bin/sync | ||
| 45 | fake/bin/systrace | ||
| 46 | fake/bin/tar | ||
| 47 | fake/bin/test | ||
| 48 | |||
| 49 | [fake/bin/[[:alpha:]]*] <0x4000> | ||
| 50 | fake/bin/cat 0100644 | ||
| 51 | fake/bin/chgrp 0100644 | ||
| 52 | fake/bin/chio 0100644 | ||
| 53 | fake/bin/chmod 0100644 | ||
| 54 | fake/bin/cksum 0100644 | ||
| 55 | fake/bin/cp 0100644 | ||
| 56 | fake/bin/cpio 0100644 | ||
| 57 | fake/bin/csh 0100644 | ||
| 58 | fake/bin/date 0100644 | ||
| 59 | fake/bin/dd 0100644 | ||
| 60 | fake/bin/df 0100644 | ||
| 61 | fake/bin/domainname 0100644 | ||
| 62 | fake/bin/echo 0100644 | ||
| 63 | fake/bin/ed 0100644 | ||
| 64 | fake/bin/eject 0100644 | ||
| 65 | fake/bin/expr 0100644 | ||
| 66 | fake/bin/hostname 0100644 | ||
| 67 | fake/bin/kill 0100644 | ||
| 68 | fake/bin/ksh 0100644 | ||
| 69 | fake/bin/ln 0100644 | ||
| 70 | fake/bin/ls 0100644 | ||
| 71 | fake/bin/md5 0100644 | ||
| 72 | fake/bin/mkdir 0100644 | ||
| 73 | fake/bin/mt 0100644 | ||
| 74 | fake/bin/mv 0100644 | ||
| 75 | fake/bin/pax 0100644 | ||
| 76 | fake/bin/ps 0100644 | ||
| 77 | fake/bin/pwd 0100644 | ||
| 78 | fake/bin/rcp 0100755 | ||
| 79 | fake/bin/rksh 0100755 | ||
| 80 | fake/bin/rm 0100755 | ||
| 81 | fake/bin/rmail 0100755 | ||
| 82 | fake/bin/rmd160 0100755 | ||
| 83 | fake/bin/rmdir 0100755 | ||
| 84 | fake/bin/sh 0100444 | ||
| 85 | fake/bin/sha1 0100444 | ||
| 86 | fake/bin/sha256 0100444 | ||
| 87 | fake/bin/sha384 0100444 | ||
| 88 | fake/bin/sha512 0100444 | ||
| 89 | fake/bin/sleep 0100444 | ||
| 90 | fake/bin/stty 0100444 | ||
| 91 | fake/bin/sum 0100444 | ||
| 92 | fake/bin/sync 0100444 | ||
| 93 | fake/bin/systrace 0100444 | ||
| 94 | fake/bin/tar 0100711 | ||
| 95 | fake/bin/test 0100711 | ||
| 96 | |||
| 97 | [fake/bin/rm{,dir,ail}] <0x80> | ||
| 98 | fake/bin/rm | ||
| 99 | fake/bin/rmdir | ||
| 100 | fake/bin/rmail | ||
| 101 | |||
| 102 | [fake/bin/sha[[:digit:]]] <0x0> | ||
| 103 | fake/bin/sha1 | ||
| 104 | |||
| 105 | [fake/bin/sha[[:digit:]]*] <0x0> | ||
| 106 | fake/bin/sha1 | ||
| 107 | fake/bin/sha256 | ||
| 108 | fake/bin/sha384 | ||
| 109 | fake/bin/sha512 | ||
| 110 | |||
| 111 | [fake/bin/ca[a-z]] <0x0> | ||
| 112 | fake/bin/cat | ||
| 113 | |||
| 114 | [fake/b[a-z]*] <0x4000> | ||
| 115 | fake/bin 0040755 | ||
| 116 | |||
diff --git a/src/regress/lib/libc/hsearch/Makefile b/src/regress/lib/libc/hsearch/Makefile new file mode 100644 index 0000000000..cddc8ac0c4 --- /dev/null +++ b/src/regress/lib/libc/hsearch/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2004/06/24 04:33:07 millert Exp $ | ||
| 2 | |||
| 3 | PROG= hsearchtest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/hsearch/hsearchtest.c b/src/regress/lib/libc/hsearch/hsearchtest.c new file mode 100644 index 0000000000..8659ef7e77 --- /dev/null +++ b/src/regress/lib/libc/hsearch/hsearchtest.c | |||
| @@ -0,0 +1,122 @@ | |||
| 1 | /* $OpenBSD: hsearchtest.c,v 1.2 2009/10/27 23:59:32 deraadt Exp $ */ | ||
| 2 | /* $NetBSD: hsearchtest.c,v 1.5 2003/07/26 19:38:46 salo Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (c) 2001 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed for the | ||
| 19 | * NetBSD Project. See http://www.NetBSD.org/ for | ||
| 20 | * information about NetBSD. | ||
| 21 | * 4. The name of the author may not be used to endorse or promote products | ||
| 22 | * derived from this software without specific prior written permission. | ||
| 23 | * | ||
| 24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 34 | * | ||
| 35 | * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> | ||
| 36 | */ | ||
| 37 | |||
| 38 | /* | ||
| 39 | * Test program for hsearch() et al. | ||
| 40 | */ | ||
| 41 | |||
| 42 | #include <search.h> | ||
| 43 | #include <stdlib.h> | ||
| 44 | #include <stdio.h> | ||
| 45 | #include <string.h> | ||
| 46 | |||
| 47 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LINE__, #e)) | ||
| 48 | |||
| 49 | static void | ||
| 50 | testfail(const char *file, unsigned long line, const char *expression) | ||
| 51 | { | ||
| 52 | |||
| 53 | fprintf(stderr, "TEST FAILED: %s: file %s, line %ld\n", | ||
| 54 | expression, file, line); | ||
| 55 | exit(1); | ||
| 56 | } | ||
| 57 | |||
| 58 | int | ||
| 59 | main(int argc, char *argv[]) | ||
| 60 | { | ||
| 61 | ENTRY e, *ep, *ep2; | ||
| 62 | int created_ok; | ||
| 63 | char ch[2]; | ||
| 64 | int i; | ||
| 65 | |||
| 66 | created_ok = hcreate(16); | ||
| 67 | TEST(created_ok); | ||
| 68 | |||
| 69 | /* ch[1] should be constant from here on down. */ | ||
| 70 | ch[1] = '\0'; | ||
| 71 | |||
| 72 | /* Basic insertions. Check enough that there'll be collisions. */ | ||
| 73 | for (i = 0; i < 26; i++) { | ||
| 74 | ch[0] = 'a' + i; | ||
| 75 | e.key = strdup(ch); /* ptr to provided key is kept! */ | ||
| 76 | TEST(e.key != NULL); | ||
| 77 | e.data = (void *)(long)i; | ||
| 78 | ep = hsearch(e, ENTER); | ||
| 79 | TEST(ep != NULL); | ||
| 80 | TEST(strcmp(ep->key, ch) == 0); | ||
| 81 | TEST((long)ep->data == i); | ||
| 82 | } | ||
| 83 | |||
| 84 | /* e.key should be constant from here on down. */ | ||
| 85 | e.key = ch; | ||
| 86 | |||
| 87 | /* Basic lookups. */ | ||
| 88 | for (i = 0; i < 26; i++) { | ||
| 89 | ch[0] = 'a' + i; | ||
| 90 | ep = hsearch(e, FIND); | ||
| 91 | TEST(ep != NULL); | ||
| 92 | TEST(strcmp(ep->key, ch) == 0); | ||
| 93 | TEST((long)ep->data == i); | ||
| 94 | } | ||
| 95 | |||
| 96 | /* Check duplicate entry. Should _not_ overwrite existing data. */ | ||
| 97 | ch[0] = 'a'; | ||
| 98 | e.data = (void *)(long)12345; | ||
| 99 | ep = hsearch(e, FIND); | ||
| 100 | TEST(ep != NULL); | ||
| 101 | TEST(strcmp(ep->key, ch) == 0); | ||
| 102 | TEST((long)ep->data == 0); | ||
| 103 | |||
| 104 | /* Check for something that's not there. */ | ||
| 105 | ch[0] = 'A'; | ||
| 106 | ep = hsearch(e, FIND); | ||
| 107 | TEST(ep == NULL); | ||
| 108 | |||
| 109 | /* Check two at once. */ | ||
| 110 | ch[0] = 'a'; | ||
| 111 | ep = hsearch(e, FIND); | ||
| 112 | ch[0] = 'b'; | ||
| 113 | ep2 = hsearch(e, FIND); | ||
| 114 | TEST(ep != NULL); | ||
| 115 | TEST(strcmp(ep->key, "a") == 0 && (long)ep->data == 0); | ||
| 116 | TEST(ep2 != NULL); | ||
| 117 | TEST(strcmp(ep2->key, "b") == 0 && (long)ep2->data == 1); | ||
| 118 | |||
| 119 | hdestroy(); | ||
| 120 | |||
| 121 | exit(0); | ||
| 122 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/Makefile b/src/regress/lib/libc/ieeefp/Makefile new file mode 100644 index 0000000000..89ff51a2e7 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/Makefile | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.6 2004/01/15 18:53:23 miod Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.5 1996/04/09 16:54:18 phil Exp $ | ||
| 3 | |||
| 4 | SUBDIR+= except inf infinity round | ||
| 5 | |||
| 6 | install: | ||
| 7 | |||
| 8 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/except/Makefile b/src/regress/lib/libc/ieeefp/except/Makefile new file mode 100644 index 0000000000..205331548f --- /dev/null +++ b/src/regress/lib/libc/ieeefp/except/Makefile | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2004/07/22 19:29:42 kettenis Exp $ | ||
| 2 | |||
| 3 | PROG=except | ||
| 4 | |||
| 5 | REGRESS_TARGETS+= fltdiv fltinv fltovf fltund | ||
| 6 | |||
| 7 | fltdiv: ${PROG} | ||
| 8 | ./${PROG} fltdiv | ||
| 9 | |||
| 10 | fltinv: ${PROG} | ||
| 11 | ./${PROG} fltinv | ||
| 12 | |||
| 13 | fltovf: ${PROG} | ||
| 14 | ./${PROG} fltovf | ||
| 15 | |||
| 16 | fltund: ${PROG} | ||
| 17 | ./${PROG} fltund | ||
| 18 | |||
| 19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/except/except.c b/src/regress/lib/libc/ieeefp/except/except.c new file mode 100644 index 0000000000..cc3dcf8e44 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/except/except.c | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | /* $OpenBSD: except.c,v 1.12 2010/05/08 19:16:33 naddy Exp $ */ | ||
| 2 | |||
| 3 | #include <sys/types.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <signal.h> | ||
| 9 | #include <assert.h> | ||
| 10 | #include <ieeefp.h> | ||
| 11 | #include <float.h> | ||
| 12 | #include <err.h> | ||
| 13 | |||
| 14 | volatile sig_atomic_t signal_status; | ||
| 15 | |||
| 16 | volatile const double one = 1.0; | ||
| 17 | volatile const double zero = 0.0; | ||
| 18 | volatile const double huge = DBL_MAX; | ||
| 19 | volatile const double tiny = DBL_MIN; | ||
| 20 | |||
| 21 | void | ||
| 22 | sigfpe(int sig, siginfo_t *si, void *v) | ||
| 23 | { | ||
| 24 | char buf[132]; | ||
| 25 | |||
| 26 | if (si) { | ||
| 27 | snprintf(buf, sizeof(buf), "sigfpe: addr=%p, code=%d\n", | ||
| 28 | si->si_addr, si->si_code); | ||
| 29 | write(1, buf, strlen(buf)); | ||
| 30 | } | ||
| 31 | _exit(signal_status); | ||
| 32 | } | ||
| 33 | |||
| 34 | |||
| 35 | int | ||
| 36 | main(int argc, char *argv[]) | ||
| 37 | { | ||
| 38 | struct sigaction sa; | ||
| 39 | volatile double x; | ||
| 40 | |||
| 41 | if (argc != 2) { | ||
| 42 | fprintf(stderr, "usage: %s condition\n", argv[0]); | ||
| 43 | exit(1); | ||
| 44 | } | ||
| 45 | |||
| 46 | /* | ||
| 47 | * check to make sure that all exceptions are masked and | ||
| 48 | * that the accumulated exception status is clear. | ||
| 49 | */ | ||
| 50 | assert(fpgetmask() == 0); | ||
| 51 | assert(fpgetsticky() == 0); | ||
| 52 | |||
| 53 | memset(&sa, 0, sizeof(sa)); | ||
| 54 | sa.sa_sigaction = sigfpe; | ||
| 55 | sa.sa_flags = SA_SIGINFO; | ||
| 56 | sigaction(SIGFPE, &sa, NULL); | ||
| 57 | signal_status = 1; | ||
| 58 | |||
| 59 | if (strcmp(argv[1], "fltdiv") == 0) { | ||
| 60 | /* trip divide by zero */ | ||
| 61 | x = one / zero; | ||
| 62 | assert(fpgetsticky() & FP_X_DZ); | ||
| 63 | fpsetsticky(0); | ||
| 64 | |||
| 65 | /* and now unmask to get a signal */ | ||
| 66 | signal_status = 0; | ||
| 67 | fpsetmask(FP_X_DZ); | ||
| 68 | x = one / zero; | ||
| 69 | } else if (strcmp(argv[1], "fltinv") == 0) { | ||
| 70 | /* trip invalid operation */ | ||
| 71 | x = zero / zero; | ||
| 72 | assert(fpgetsticky() & FP_X_INV); | ||
| 73 | fpsetsticky(0); | ||
| 74 | |||
| 75 | /* and now unmask to get a signal */ | ||
| 76 | signal_status = 0; | ||
| 77 | fpsetmask(FP_X_INV); | ||
| 78 | x = zero / zero; | ||
| 79 | } else if (strcmp(argv[1], "fltovf") == 0) { | ||
| 80 | /* trip overflow */ | ||
| 81 | x = huge * huge; | ||
| 82 | assert(fpgetsticky() & FP_X_OFL); | ||
| 83 | fpsetsticky(0); | ||
| 84 | |||
| 85 | /* and now unmask to get a signal */ | ||
| 86 | signal_status = 0; | ||
| 87 | fpsetmask(FP_X_OFL); | ||
| 88 | x = huge * huge; | ||
| 89 | } else if (strcmp(argv[1], "fltund") == 0) { | ||
| 90 | /* trip underflow */ | ||
| 91 | x = tiny * tiny; | ||
| 92 | assert(fpgetsticky() & FP_X_UFL); | ||
| 93 | fpsetsticky(0); | ||
| 94 | |||
| 95 | /* and now unmask to get a signal */ | ||
| 96 | signal_status = 0; | ||
| 97 | fpsetmask(FP_X_UFL); | ||
| 98 | x = tiny * tiny; | ||
| 99 | } else { | ||
| 100 | errx(1, "unrecognized condition %s", argv[1]); | ||
| 101 | } | ||
| 102 | |||
| 103 | /* | ||
| 104 | * attempt to trigger the exception on machines where | ||
| 105 | * floating-point exceptions are deferred. | ||
| 106 | */ | ||
| 107 | x = one * one; | ||
| 108 | |||
| 109 | errx(1, "signal wasn't caught"); | ||
| 110 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/inf/Makefile b/src/regress/lib/libc/ieeefp/inf/Makefile new file mode 100644 index 0000000000..b9a50e0ce6 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/inf/Makefile | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2002/02/16 17:22:16 pvalchev Exp $ | ||
| 2 | |||
| 3 | PROG= inf | ||
| 4 | SRCS= inf.c | ||
| 5 | |||
| 6 | LDADD+= -lm | ||
| 7 | DPADD+= ${LIBM} | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/inf/inf.c b/src/regress/lib/libc/ieeefp/inf/inf.c new file mode 100644 index 0000000000..a1956145a6 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/inf/inf.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | /* $OpenBSD: inf.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Peter Valchev <pvalchev@openbsd.org> Public Domain, 2002. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <math.h> | ||
| 8 | |||
| 9 | int | ||
| 10 | main(int argc, char *argv[]) | ||
| 11 | { | ||
| 12 | if (isinf(HUGE_VAL)) | ||
| 13 | return 0; | ||
| 14 | |||
| 15 | return 1; | ||
| 16 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/infinity/Makefile b/src/regress/lib/libc/ieeefp/infinity/Makefile new file mode 100644 index 0000000000..ac102d8a63 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/infinity/Makefile | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2004/01/16 19:34:37 miod Exp $ | ||
| 2 | |||
| 3 | PROG= infinity | ||
| 4 | |||
| 5 | DPADD+= ${LIBM} | ||
| 6 | LDADD+= -lm | ||
| 7 | |||
| 8 | REGRESS_TARGETS+= add mult neg pumpkin | ||
| 9 | |||
| 10 | add: ${PROG} | ||
| 11 | ./${PROG} -a | ||
| 12 | |||
| 13 | mult: ${PROG} | ||
| 14 | ./${PROG} -m | ||
| 15 | |||
| 16 | neg: ${PROG} | ||
| 17 | ./${PROG} -n | ||
| 18 | |||
| 19 | pumpkin: ${PROG} | ||
| 20 | ./${PROG} -p | ||
| 21 | |||
| 22 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/infinity/infinity.c b/src/regress/lib/libc/ieeefp/infinity/infinity.c new file mode 100644 index 0000000000..3b1b71ec90 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/infinity/infinity.c | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | /* $OpenBSD: infinity.c,v 1.2 2004/01/16 19:34:37 miod Exp $ */ | ||
| 2 | /* | ||
| 3 | * Written by Miodrag Vallat, 2004 - Public Domain | ||
| 4 | * Inspired from Perl's t/op/arith test #134 | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <math.h> | ||
| 8 | #include <signal.h> | ||
| 9 | #include <unistd.h> | ||
| 10 | |||
| 11 | void | ||
| 12 | sigfpe(int signum) | ||
| 13 | { | ||
| 14 | /* looks like we don't handle fp overflow correctly... */ | ||
| 15 | _exit(1); | ||
| 16 | } | ||
| 17 | |||
| 18 | int | ||
| 19 | main(int argc, char *argv[]) | ||
| 20 | { | ||
| 21 | int opt; | ||
| 22 | double d, two; | ||
| 23 | int i; | ||
| 24 | char method = 'a'; | ||
| 25 | |||
| 26 | while ((opt = getopt(argc, argv, "amnp")) != -1) | ||
| 27 | method = (char)opt; | ||
| 28 | |||
| 29 | signal(SIGFPE, sigfpe); | ||
| 30 | |||
| 31 | switch (method) { | ||
| 32 | case 'a': | ||
| 33 | /* try to produce +Inf through addition */ | ||
| 34 | d = 1.0; | ||
| 35 | for (i = 2000; i != 0; i--) { | ||
| 36 | d = d + d; | ||
| 37 | } | ||
| 38 | /* result should be _positive_ infinity */ | ||
| 39 | if (!isinf(d) || copysign(1.0, d) < 0.0) | ||
| 40 | return (1); | ||
| 41 | break; | ||
| 42 | case 'm': | ||
| 43 | /* try to produce +Inf through multiplication */ | ||
| 44 | d = 1.0; | ||
| 45 | two = 2.0; | ||
| 46 | for (i = 2000; i != 0; i--) { | ||
| 47 | d = d * two; | ||
| 48 | } | ||
| 49 | /* result should be _positive_ infinity */ | ||
| 50 | if (!isinf(d) || copysign(1.0, d) < 0.0) | ||
| 51 | return (1); | ||
| 52 | break; | ||
| 53 | case 'n': | ||
| 54 | /* try to produce -Inf through subtraction */ | ||
| 55 | d = -1.0; | ||
| 56 | for (i = 2000; i != 0; i--) { | ||
| 57 | d = d + d; | ||
| 58 | } | ||
| 59 | /* result should be _negative_ infinity */ | ||
| 60 | if (!isinf(d) || copysign(1.0, d) > 0.0) | ||
| 61 | return (1); | ||
| 62 | break; | ||
| 63 | case 'p': | ||
| 64 | /* try to produce -Inf through multiplication */ | ||
| 65 | d = -1.0; | ||
| 66 | two = 2.0; | ||
| 67 | for (i = 2000; i != 0; i--) { | ||
| 68 | d = d * two; | ||
| 69 | } | ||
| 70 | /* result should be _negative_ infinity */ | ||
| 71 | if (!isinf(d) || copysign(1.0, d) > 0.0) | ||
| 72 | return (1); | ||
| 73 | break; | ||
| 74 | } | ||
| 75 | |||
| 76 | return (0); | ||
| 77 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/round/Makefile b/src/regress/lib/libc/ieeefp/round/Makefile new file mode 100644 index 0000000000..9ea6dd8c39 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/round/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2002/02/18 11:25:34 art Exp $ | ||
| 2 | |||
| 3 | PROG= round | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/round/round.c b/src/regress/lib/libc/ieeefp/round/round.c new file mode 100644 index 0000000000..807941ea56 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/round/round.c | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | /* $OpenBSD: round.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $ */ | ||
| 2 | /* $NetBSD: round.c,v 1.1 1995/04/26 00:27:28 jtc Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Written by J.T. Conklin, Apr 18, 1995 | ||
| 6 | * Public domain. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <assert.h> | ||
| 10 | #include <stdlib.h> | ||
| 11 | #include <ieeefp.h> | ||
| 12 | #include <float.h> | ||
| 13 | |||
| 14 | int | ||
| 15 | main(int argc, char *argv[]) | ||
| 16 | { | ||
| 17 | /* | ||
| 18 | * This test would be better if it actually performed some | ||
| 19 | * calculations to verify the selected rounding mode. But | ||
| 20 | * this is probably acceptable since the fp{get,set}round | ||
| 21 | * functions usually just get or set the processors fpu | ||
| 22 | * control word. | ||
| 23 | */ | ||
| 24 | |||
| 25 | assert(fpgetround() == FP_RN); | ||
| 26 | assert(FLT_ROUNDS == 1); | ||
| 27 | |||
| 28 | assert(fpsetround(FP_RP) == FP_RN); | ||
| 29 | assert(fpgetround() == FP_RP); | ||
| 30 | assert(FLT_ROUNDS == 2); | ||
| 31 | |||
| 32 | assert(fpsetround(FP_RM) == FP_RP); | ||
| 33 | assert(fpgetround() == FP_RM); | ||
| 34 | assert(FLT_ROUNDS == 3); | ||
| 35 | |||
| 36 | assert(fpsetround(FP_RZ) == FP_RM); | ||
| 37 | assert(fpgetround() == FP_RZ); | ||
| 38 | assert(FLT_ROUNDS == 0); | ||
| 39 | |||
| 40 | assert(fpsetround(FP_RN) == FP_RZ); | ||
| 41 | assert(fpgetround() == FP_RN); | ||
| 42 | assert(FLT_ROUNDS == 1); | ||
| 43 | |||
| 44 | exit(0); | ||
| 45 | } | ||
diff --git a/src/regress/lib/libc/locale/Makefile b/src/regress/lib/libc/locale/Makefile new file mode 100644 index 0000000000..c182172ba2 --- /dev/null +++ b/src/regress/lib/libc/locale/Makefile | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2005/08/11 21:57:02 espie Exp $ | ||
| 2 | |||
| 3 | SUBDIR+= check_isw | ||
| 4 | |||
| 5 | install: | ||
| 6 | |||
| 7 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/locale/check_isw/Makefile b/src/regress/lib/libc/locale/check_isw/Makefile new file mode 100644 index 0000000000..0885968fd1 --- /dev/null +++ b/src/regress/lib/libc/locale/check_isw/Makefile | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2005/08/11 21:57:02 espie Exp $ | ||
| 2 | |||
| 3 | NOMAN= | ||
| 4 | PROG=check_isw | ||
| 5 | |||
| 6 | run-regress-check_isw: ${PROG} | ||
| 7 | ./${PROG} >/dev/null | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/locale/check_isw/check_isw.c b/src/regress/lib/libc/locale/check_isw/check_isw.c new file mode 100644 index 0000000000..9386267f61 --- /dev/null +++ b/src/regress/lib/libc/locale/check_isw/check_isw.c | |||
| @@ -0,0 +1,147 @@ | |||
| 1 | /* $OpenBSD: check_isw.c,v 1.1 2005/08/11 21:57:02 espie Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2005 Marc Espie <espie@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | /* This checks consistency of the isw* functions with the default <ctype> | ||
| 19 | * functions. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <stdio.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | #include <ctype.h> | ||
| 25 | #include <wchar.h> | ||
| 26 | #include <wctype.h> | ||
| 27 | |||
| 28 | int bad = 0; | ||
| 29 | |||
| 30 | void | ||
| 31 | check_bool(int v1, int v2, char msg) | ||
| 32 | { | ||
| 33 | if (!v1 != !v2) { | ||
| 34 | printf("%c", msg); | ||
| 35 | bad++; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | void | ||
| 40 | check_value(int v1, int v2, char msg) | ||
| 41 | { | ||
| 42 | if (v1 != v2) { | ||
| 43 | printf("%c", msg); | ||
| 44 | bad++; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | void | ||
| 49 | test1() | ||
| 50 | { | ||
| 51 | int i; | ||
| 52 | |||
| 53 | for (i = 0; i < 256; i++) { | ||
| 54 | printf(" %02x: ", i); | ||
| 55 | check_bool(isalnum(i), iswalnum(i), '1'); | ||
| 56 | check_bool(isalpha(i), iswalpha(i), '2'); | ||
| 57 | check_bool(isblank(i), iswblank(i), '3'); | ||
| 58 | check_bool(iscntrl(i), iswcntrl(i), '4'); | ||
| 59 | check_bool(isdigit(i), iswdigit(i), '5'); | ||
| 60 | check_bool(isgraph(i), iswgraph(i), '6'); | ||
| 61 | check_bool(islower(i), iswlower(i), '6'); | ||
| 62 | check_bool(isprint(i), iswprint(i), '7'); | ||
| 63 | check_bool(ispunct(i), iswpunct(i), '8'); | ||
| 64 | check_bool(isspace(i), iswspace(i), '9'); | ||
| 65 | check_bool(isupper(i), iswupper(i), 'a'); | ||
| 66 | check_bool(isxdigit(i), iswxdigit(i), 'b'); | ||
| 67 | check_value(tolower(i), towlower(i), 'c'); | ||
| 68 | check_value(toupper(i), towupper(i), 'd'); | ||
| 69 | if (i % 8 == 7) | ||
| 70 | printf("\n"); | ||
| 71 | } | ||
| 72 | printf("%\n"); | ||
| 73 | } | ||
| 74 | |||
| 75 | void | ||
| 76 | test2() | ||
| 77 | { | ||
| 78 | unsigned char *s; | ||
| 79 | unsigned char *buf; | ||
| 80 | int i, j; | ||
| 81 | size_t n; | ||
| 82 | wchar_t c, d; | ||
| 83 | mbstate_t state; | ||
| 84 | |||
| 85 | s = malloc(256); | ||
| 86 | if (!s) { | ||
| 87 | bad++; | ||
| 88 | return; | ||
| 89 | } | ||
| 90 | buf = malloc(MB_CUR_MAX); | ||
| 91 | if (!buf) { | ||
| 92 | bad++; | ||
| 93 | free(s); | ||
| 94 | return; | ||
| 95 | } | ||
| 96 | for (i = 0; i < 256; i++) | ||
| 97 | s[i] = i+1; | ||
| 98 | |||
| 99 | j = 0; | ||
| 100 | mbrtowc(NULL, NULL, 1, &state); | ||
| 101 | printf(" %02x: ", 0); | ||
| 102 | |||
| 103 | while ((n = mbrtowc(&c, s+j, 256-j, &state)) == 1) { | ||
| 104 | printf(" %02x: ", s[j]); | ||
| 105 | check_bool(isalnum(s[j]), iswalnum(c), '1'); | ||
| 106 | check_bool(isalpha(s[j]), iswalpha(c), '2'); | ||
| 107 | check_bool(isblank(s[j]), iswblank(c), '3'); | ||
| 108 | check_bool(iscntrl(s[j]), iswcntrl(c), '4'); | ||
| 109 | check_bool(isdigit(s[j]), iswdigit(c), '5'); | ||
| 110 | check_bool(isgraph(s[j]), iswgraph(c), '6'); | ||
| 111 | check_bool(islower(s[j]), iswlower(c), '6'); | ||
| 112 | check_bool(isprint(s[j]), iswprint(c), '7'); | ||
| 113 | check_bool(ispunct(s[j]), iswpunct(c), '8'); | ||
| 114 | check_bool(isspace(s[j]), iswspace(c), '9'); | ||
| 115 | check_bool(isupper(s[j]), iswupper(c), 'a'); | ||
| 116 | check_bool(isxdigit(s[j]), iswxdigit(c), 'b'); | ||
| 117 | d = towlower(c); | ||
| 118 | if (wctomb(buf, d) == 1) { | ||
| 119 | check_value(tolower(s[j]), buf[0], 'c'); | ||
| 120 | } else { | ||
| 121 | bad++; | ||
| 122 | } | ||
| 123 | d = towupper(c); | ||
| 124 | if (wctomb(buf, d) == 1) { | ||
| 125 | check_value(toupper(s[j]), buf[0], 'c'); | ||
| 126 | } else { | ||
| 127 | bad++; | ||
| 128 | } | ||
| 129 | if (s[j] % 8 == 7) | ||
| 130 | printf("\n"); | ||
| 131 | j++; | ||
| 132 | } | ||
| 133 | if (n != 0 || j != 255) { | ||
| 134 | bad++; | ||
| 135 | } | ||
| 136 | free(s); | ||
| 137 | free(buf); | ||
| 138 | } | ||
| 139 | |||
| 140 | |||
| 141 | int | ||
| 142 | main() | ||
| 143 | { | ||
| 144 | test1(); | ||
| 145 | test2(); | ||
| 146 | return bad !=0; | ||
| 147 | } | ||
diff --git a/src/regress/lib/libc/longjmp/Makefile b/src/regress/lib/libc/longjmp/Makefile new file mode 100644 index 0000000000..825e0f86d9 --- /dev/null +++ b/src/regress/lib/libc/longjmp/Makefile | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2002/09/02 20:01:43 avsm Exp $ | ||
| 2 | PROG= longjmp | ||
| 3 | |||
| 4 | do-longjmp: ${PROG} | ||
| 5 | ./longjmp | ||
| 6 | |||
| 7 | do-_longjmp: ${PROG} | ||
| 8 | ./longjmp -_ | ||
| 9 | |||
| 10 | REGRESS_TARGETS=do-longjmp do-_longjmp | ||
| 11 | .PHONY: ${REGRESS_TARGETS} | ||
| 12 | |||
| 13 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/longjmp/longjmp.c b/src/regress/lib/libc/longjmp/longjmp.c new file mode 100644 index 0000000000..7dea5bd97c --- /dev/null +++ b/src/regress/lib/libc/longjmp/longjmp.c | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | /* $OpenBSD: longjmp.c,v 1.4 2002/02/18 11:27:45 art Exp $ */ | ||
| 2 | /* | ||
| 3 | * Artur Grabowski <art@openbsd.org>, 2002 Public Domain. | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <stdio.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | #include <unistd.h> | ||
| 9 | #include <setjmp.h> | ||
| 10 | #include <err.h> | ||
| 11 | #include <sys/types.h> | ||
| 12 | #include <sys/time.h> | ||
| 13 | #include <sys/resource.h> | ||
| 14 | |||
| 15 | |||
| 16 | jmp_buf buf; | ||
| 17 | |||
| 18 | /* | ||
| 19 | * When longjmp is passed the incorrect arg (0), it should translate it into | ||
| 20 | * something better. | ||
| 21 | * | ||
| 22 | * The rlimit is here in case we start spinning. | ||
| 23 | */ | ||
| 24 | int | ||
| 25 | main(int argc, char **argv) | ||
| 26 | { | ||
| 27 | struct rlimit rl; | ||
| 28 | volatile int i, expect; | ||
| 29 | int (*sj)(jmp_buf); | ||
| 30 | void (*lj)(jmp_buf, int); | ||
| 31 | int ch; | ||
| 32 | extern char *__progname; | ||
| 33 | |||
| 34 | sj = setjmp; | ||
| 35 | lj = longjmp; | ||
| 36 | |||
| 37 | while ((ch = getopt(argc, argv, "_")) != -1) { | ||
| 38 | switch (ch) { | ||
| 39 | case '_': | ||
| 40 | sj = _setjmp; | ||
| 41 | lj = _longjmp; | ||
| 42 | break; | ||
| 43 | default: | ||
| 44 | fprintf(stderr, "Usage: %s [-_]\n", __progname); | ||
| 45 | exit(1); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | rl.rlim_cur = 2; | ||
| 50 | rl.rlim_max = 2; | ||
| 51 | if (setrlimit(RLIMIT_CPU, &rl) < 0) | ||
| 52 | err(1, "setrlimit"); | ||
| 53 | |||
| 54 | expect = 0; | ||
| 55 | i = (*sj)(buf); | ||
| 56 | if (i == 0 && expect != 0) | ||
| 57 | errx(1, "setjmp returns 0 on longjmp(.., 0)"); | ||
| 58 | if (expect == 0) { | ||
| 59 | expect = -1; | ||
| 60 | (*lj)(buf, 0); | ||
| 61 | } | ||
| 62 | |||
| 63 | expect = 0; | ||
| 64 | i = (*sj)(buf); | ||
| 65 | if (i != expect) | ||
| 66 | errx(1, "bad return from setjmp %d/%d", expect, i); | ||
| 67 | if (expect < 1000) | ||
| 68 | (*lj)(buf, expect += 2); | ||
| 69 | |||
| 70 | return 0; | ||
| 71 | } | ||
diff --git a/src/regress/lib/libc/malloc/Makefile b/src/regress/lib/libc/malloc/Makefile new file mode 100644 index 0000000000..7c919d1bc2 --- /dev/null +++ b/src/regress/lib/libc/malloc/Makefile | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2006/04/18 19:04:39 otto Exp $ | ||
| 2 | |||
| 3 | SUBDIR+= malloc0test malloc_errno malloc_ulimit1 malloc_ulimit2 | ||
| 4 | |||
| 5 | install: | ||
| 6 | |||
| 7 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc0test/Makefile b/src/regress/lib/libc/malloc/malloc0test/Makefile new file mode 100644 index 0000000000..8ed8163a79 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc0test/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2003/07/15 10:09:37 otto Exp $ | ||
| 2 | |||
| 3 | PROG= malloc0test | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc0test/malloc0test.c b/src/regress/lib/libc/malloc/malloc0test/malloc0test.c new file mode 100644 index 0000000000..06ff0996ee --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc0test/malloc0test.c | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | /* $OpenBSD: malloc0test.c,v 1.5 2008/04/13 00:22:17 djm Exp $ */ | ||
| 2 | /* | ||
| 3 | * Public domain. 2001, Theo de Raadt | ||
| 4 | */ | ||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/signal.h> | ||
| 7 | #include <stdio.h> | ||
| 8 | #include <unistd.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include <setjmp.h> | ||
| 11 | #include <limits.h> | ||
| 12 | #include <errno.h> | ||
| 13 | |||
| 14 | volatile sig_atomic_t got; | ||
| 15 | jmp_buf jmp; | ||
| 16 | |||
| 17 | static void | ||
| 18 | catch(int signo) | ||
| 19 | { | ||
| 20 | got++; | ||
| 21 | longjmp(jmp, 1); | ||
| 22 | } | ||
| 23 | |||
| 24 | static int | ||
| 25 | test(char *p, int size) | ||
| 26 | { | ||
| 27 | signal(SIGSEGV, catch); | ||
| 28 | got = 0; | ||
| 29 | if (setjmp(jmp) == 0) | ||
| 30 | *p = 0; | ||
| 31 | if (setjmp(jmp) == 0) | ||
| 32 | *(p+size-1) = 0; | ||
| 33 | return (got); | ||
| 34 | } | ||
| 35 | |||
| 36 | char *prot_table[] = { | ||
| 37 | "unprotected", | ||
| 38 | "fuckup", | ||
| 39 | "protected" | ||
| 40 | }; | ||
| 41 | |||
| 42 | #define SIZE 10 | ||
| 43 | |||
| 44 | /* | ||
| 45 | * Do random memory allocations. | ||
| 46 | * | ||
| 47 | * For each one, ensure that it is at least 16 bytes in size (that | ||
| 48 | * being what our current malloc returns for the minsize of an | ||
| 49 | * object, alignment wise); | ||
| 50 | * | ||
| 51 | * For zero-byte allocations, check that they are still aligned. | ||
| 52 | * | ||
| 53 | * For each object, ensure that they are correctly protected or not | ||
| 54 | * protected. | ||
| 55 | * | ||
| 56 | * Does not regress test malloc + free combinations ... it should. | ||
| 57 | */ | ||
| 58 | int | ||
| 59 | main(int argc, char *argv[]) | ||
| 60 | { | ||
| 61 | caddr_t blob; | ||
| 62 | int size, tsize; | ||
| 63 | int prot; | ||
| 64 | int rval = 0, fuckup = 0; | ||
| 65 | long limit = 200000, count; | ||
| 66 | int ch, silent = 0; | ||
| 67 | char *ep; | ||
| 68 | extern char *__progname; | ||
| 69 | |||
| 70 | while ((ch = getopt(argc, argv, "sn:")) != -1) { | ||
| 71 | switch (ch) { | ||
| 72 | case 's': | ||
| 73 | silent = 1; | ||
| 74 | break; | ||
| 75 | case 'n': | ||
| 76 | errno = 0; | ||
| 77 | limit = strtol(optarg, &ep, 10); | ||
| 78 | if (optarg[0] == '\0' || *ep != '\0' || | ||
| 79 | (errno == ERANGE && | ||
| 80 | (limit == LONG_MAX || limit == LONG_MIN))) | ||
| 81 | goto usage; | ||
| 82 | break; | ||
| 83 | default: | ||
| 84 | usage: | ||
| 85 | fprintf(stderr, "Usage: %s [-s][-n <count>]\n", | ||
| 86 | __progname); | ||
| 87 | exit(1); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | if (limit == 0) | ||
| 92 | limit = LONG_MAX; | ||
| 93 | |||
| 94 | for (count = 0; count < limit; count++) { | ||
| 95 | size = arc4random_uniform(SIZE); | ||
| 96 | blob = malloc(size); | ||
| 97 | if (blob == NULL) { | ||
| 98 | fprintf(stderr, "success: out of memory\n"); | ||
| 99 | exit(rval); | ||
| 100 | } | ||
| 101 | |||
| 102 | tsize = size == 0 ? 16 : size; | ||
| 103 | fuckup = 0; | ||
| 104 | prot = test(blob, tsize); | ||
| 105 | |||
| 106 | if (size == 0 && prot < 2) | ||
| 107 | fuckup = 1; | ||
| 108 | |||
| 109 | if (fuckup) { | ||
| 110 | printf("%8p %6d %20s %10s\n", blob, size, | ||
| 111 | prot_table[prot], fuckup ? "fuckup" : ""); | ||
| 112 | rval = 1; | ||
| 113 | } | ||
| 114 | |||
| 115 | if (!silent && count % 100000 == 0 && count != 0) | ||
| 116 | fprintf(stderr, "count = %ld\n", count); | ||
| 117 | } | ||
| 118 | |||
| 119 | return rval; | ||
| 120 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errno/Makefile b/src/regress/lib/libc/malloc/malloc_errno/Makefile new file mode 100644 index 0000000000..73ebe37491 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_errno/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2003/07/15 10:06:31 otto Exp $ | ||
| 2 | |||
| 3 | PROG= malloc_errno | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c b/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c new file mode 100644 index 0000000000..896ea3c900 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | /* $OpenBSD: malloc_errno.c,v 1.4 2003/12/25 18:49:57 miod Exp $ */ | ||
| 2 | /* | ||
| 3 | * Public domain. 2003, Otto Moerbeek | ||
| 4 | */ | ||
| 5 | #include <err.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <stdio.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | |||
| 10 | static void | ||
| 11 | testerrno(size_t sz) | ||
| 12 | { | ||
| 13 | void *p; | ||
| 14 | |||
| 15 | errno = -1; | ||
| 16 | p = malloc(sz); | ||
| 17 | |||
| 18 | if (p == NULL && errno != ENOMEM) | ||
| 19 | errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno); | ||
| 20 | |||
| 21 | /* if alloc succeeded, test if errno did not change */ | ||
| 22 | if (p != NULL && errno != -1) | ||
| 23 | errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno); | ||
| 24 | |||
| 25 | free(p); | ||
| 26 | } | ||
| 27 | |||
| 28 | /* | ||
| 29 | * Provide some (silly) arguments to malloc(), and check if ERRNO is set | ||
| 30 | * correctly. | ||
| 31 | */ | ||
| 32 | int | ||
| 33 | main(int argc, char *argv[]) | ||
| 34 | { | ||
| 35 | size_t i; | ||
| 36 | |||
| 37 | testerrno(1); | ||
| 38 | testerrno(100000); | ||
| 39 | testerrno(-1); | ||
| 40 | testerrno(-1000); | ||
| 41 | testerrno(-10000); | ||
| 42 | testerrno(-10000000); | ||
| 43 | for (i = 0; i < 0x10; i++) | ||
| 44 | testerrno(i * 0x10000000); | ||
| 45 | return 0; | ||
| 46 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile b/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile new file mode 100644 index 0000000000..46ced27a98 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2006/04/18 19:03:30 otto Exp $ | ||
| 2 | |||
| 3 | PROG= malloc_ulimit1 | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c b/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c new file mode 100644 index 0000000000..99e805e8e1 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | /* $OpenBSD: malloc_ulimit1.c,v 1.2 2006/05/16 05:47:13 otto Exp $ */ | ||
| 2 | |||
| 3 | /* Public Domain, 2006, Otto Moerbeek <otto@drijf.net> */ | ||
| 4 | |||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/time.h> | ||
| 7 | #include <sys/resource.h> | ||
| 8 | #include <err.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | |||
| 12 | /* | ||
| 13 | * This code tries to trigger the case present in -current as of April | ||
| 14 | * 2006) where the allocation of the region itself succeeds, but the | ||
| 15 | * page dir entry pages fails. | ||
| 16 | * This in turn trips a "hole in directories" error. | ||
| 17 | * Having a large (512M) ulimit -m helps a lot in triggering the | ||
| 18 | * problem. Note that you may need to run this test multiple times to | ||
| 19 | * see the error. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #define STARTI 1300 | ||
| 23 | #define FACTOR 1024 | ||
| 24 | |||
| 25 | main() | ||
| 26 | { | ||
| 27 | struct rlimit lim; | ||
| 28 | size_t sz; | ||
| 29 | int i; | ||
| 30 | void *p; | ||
| 31 | |||
| 32 | if (getrlimit(RLIMIT_DATA, &lim) == -1) | ||
| 33 | err(1, "getrlimit"); | ||
| 34 | |||
| 35 | sz = lim.rlim_cur / FACTOR; | ||
| 36 | |||
| 37 | for (i = STARTI; i >= 0; i--) { | ||
| 38 | size_t len = (sz-i) * FACTOR; | ||
| 39 | p = malloc(len); | ||
| 40 | free(p); | ||
| 41 | free(malloc(4096)); | ||
| 42 | } | ||
| 43 | return (0); | ||
| 44 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile b/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile new file mode 100644 index 0000000000..bc83666415 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2006/04/18 19:04:03 otto Exp $ | ||
| 2 | |||
| 3 | PROG= malloc_ulimit2 | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c b/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c new file mode 100644 index 0000000000..ca8e8f438a --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | /* $OpenBSD: malloc_ulimit2.c,v 1.2 2006/05/16 05:47:13 otto Exp $ */ | ||
| 2 | |||
| 3 | /* Public Domain, 2006, Otto Moerbeek <otto@drijf.net> */ | ||
| 4 | |||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/time.h> | ||
| 7 | #include <sys/resource.h> | ||
| 8 | #include <err.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | |||
| 12 | #define FACTOR 1024 | ||
| 13 | |||
| 14 | main() | ||
| 15 | { | ||
| 16 | struct rlimit lim; | ||
| 17 | size_t sz; | ||
| 18 | int i; | ||
| 19 | void *p; | ||
| 20 | |||
| 21 | if (getrlimit(RLIMIT_DATA, &lim) == -1) | ||
| 22 | err(1, "getrlimit"); | ||
| 23 | |||
| 24 | sz = lim.rlim_cur / FACTOR; | ||
| 25 | |||
| 26 | for (i = 0; ; i++) { | ||
| 27 | size_t len = (sz-i) * FACTOR; | ||
| 28 | p = malloc(len); | ||
| 29 | if (p != NULL) { | ||
| 30 | free(p); | ||
| 31 | break; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | i += 10; | ||
| 35 | for (; i >= 0; i--) { | ||
| 36 | size_t len = (sz-i) * FACTOR; | ||
| 37 | p = malloc(len); | ||
| 38 | free(p); | ||
| 39 | free(malloc(4096)); | ||
| 40 | } | ||
| 41 | return (0); | ||
| 42 | } | ||
diff --git a/src/regress/lib/libc/mkstemp/Makefile b/src/regress/lib/libc/mkstemp/Makefile new file mode 100644 index 0000000000..dc7eb281a9 --- /dev/null +++ b/src/regress/lib/libc/mkstemp/Makefile | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2010/02/11 07:35:38 guenther Exp $ | ||
| 2 | |||
| 3 | PROG=mkstemp_test | ||
| 4 | CLEANFILES+= ; rm -rf output | ||
| 5 | |||
| 6 | O = output | ||
| 7 | |||
| 8 | # The ktrace/kdump/perl combo verifies that all open() calls that | ||
| 9 | # were passed O_CREAT were also passed O_EXCL | ||
| 10 | run-regress-${PROG}: ${PROG} | ||
| 11 | mkdir -p $O && cd $O && ktrace ../${PROG} | ||
| 12 | cd $O && kdump | perl -mFcntl -nl \ | ||
| 13 | -e '/ open\([^,]*,([^,]+)/ or next;' \ | ||
| 14 | -e '$$f = oct($$1);' \ | ||
| 15 | -e 'if ($$f & O_CREAT && !($$f & O_EXCL)) {' \ | ||
| 16 | -e ' print "FAIL"; exit 1' \ | ||
| 17 | -e '}' | ||
| 18 | |||
| 19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/mkstemp/mkstemp_test.c b/src/regress/lib/libc/mkstemp/mkstemp_test.c new file mode 100644 index 0000000000..fd133d8368 --- /dev/null +++ b/src/regress/lib/libc/mkstemp/mkstemp_test.c | |||
| @@ -0,0 +1,156 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2010 Philip Guenther <guenther@openbsd.org> | ||
| 3 | * | ||
| 4 | * Public domain. | ||
| 5 | * | ||
| 6 | * Verify that mkstemp() and mkstemps() doesn't overrun or underrun | ||
| 7 | * the template buffer and that it can generate names that don't | ||
| 8 | * contain any X's | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <sys/param.h> | ||
| 12 | |||
| 13 | #include <err.h> | ||
| 14 | #include <stdio.h> | ||
| 15 | #include <stdlib.h> | ||
| 16 | #include <string.h> | ||
| 17 | #include <sys/mman.h> | ||
| 18 | #include <sys/stat.h> | ||
| 19 | #include <unistd.h> | ||
| 20 | |||
| 21 | #define MAX_TEMPLATE_LEN 10 | ||
| 22 | #define MAX_TRIES 100 | ||
| 23 | |||
| 24 | #define SUFFIX ".suff" | ||
| 25 | #define SLEN (sizeof SUFFIX - 1) | ||
| 26 | |||
| 27 | long pg; | ||
| 28 | |||
| 29 | /* | ||
| 30 | * verify that a path generated by mkstemp() or mkstemp() looks like a | ||
| 31 | * reasonable expansion of the template and matches the fd. Returns true | ||
| 32 | * if all the X's were replaced with non-X's | ||
| 33 | */ | ||
| 34 | int | ||
| 35 | check(int fd, char const *path, char const *prefix, size_t plen, | ||
| 36 | char const *suffix, size_t slen, int tlen) | ||
| 37 | { | ||
| 38 | struct stat sb, fsb; | ||
| 39 | char const *p; | ||
| 40 | |||
| 41 | if (fd < 0) | ||
| 42 | err(1, "mkstemp"); | ||
| 43 | if (stat(path, &sb)) | ||
| 44 | err(1, "stat(%s)", path); | ||
| 45 | if (fstat(fd, &fsb)) | ||
| 46 | err(1, "fstat(%d==%s)", fd, path); | ||
| 47 | if (sb.st_dev != fsb.st_dev || sb.st_ino != fsb.st_ino) | ||
| 48 | errx(1, "stat mismatch"); | ||
| 49 | close(fd); | ||
| 50 | if (memcmp(path, prefix, plen) != 0) | ||
| 51 | errx(1, "prefix changed! %s vs %s", prefix, path); | ||
| 52 | if (memcmp(path + plen + tlen, suffix, slen + 1) != 0) | ||
| 53 | errx(1, "suffix changed! %s vs %s", suffix, path); | ||
| 54 | for (p = path + plen; p < path + plen + tlen; p++) | ||
| 55 | if (*p == '\0') | ||
| 56 | errx(1, "unexpected truncation"); | ||
| 57 | else if (*p == 'X') | ||
| 58 | return 0; | ||
| 59 | return 1; | ||
| 60 | } | ||
| 61 | |||
| 62 | |||
| 63 | void | ||
| 64 | try_mkstemp(char *p, char const *prefix, int len) | ||
| 65 | { | ||
| 66 | char *q; | ||
| 67 | size_t plen = strlen(prefix); | ||
| 68 | int tries, fd; | ||
| 69 | |||
| 70 | for (tries = 0; tries < MAX_TRIES; tries++) { | ||
| 71 | memcpy(p, prefix, plen); | ||
| 72 | memset(p + plen, 'X', len); | ||
| 73 | p[plen + len] = '\0'; | ||
| 74 | fd = mkstemp(p); | ||
| 75 | if (check(fd, p, prefix, plen, "", 0, len)) | ||
| 76 | return; | ||
| 77 | } | ||
| 78 | errx(1, "exceeded MAX_TRIES"); | ||
| 79 | } | ||
| 80 | |||
| 81 | void | ||
| 82 | try_mkstemps(char *p, char const *prefix, int len, char const *suffix) | ||
| 83 | { | ||
| 84 | char *q; | ||
| 85 | size_t plen = strlen(prefix); | ||
| 86 | size_t slen = strlen(suffix); | ||
| 87 | int tries, fd; | ||
| 88 | |||
| 89 | for (tries = 0; tries < MAX_TRIES; tries++) { | ||
| 90 | memcpy(p, prefix, plen); | ||
| 91 | memset(p + plen, 'X', len); | ||
| 92 | memcpy(p + plen + len, suffix, slen + 1); | ||
| 93 | fd = mkstemps(p, slen); | ||
| 94 | if (check(fd, p, prefix, plen, suffix, slen, len)) | ||
| 95 | return; | ||
| 96 | } | ||
| 97 | errx(1, "exceeded MAX_TRIES"); | ||
| 98 | } | ||
| 99 | |||
| 100 | int | ||
| 101 | main(void) | ||
| 102 | { | ||
| 103 | struct stat sb, fsb; | ||
| 104 | char cwd[MAXPATHLEN + 1]; | ||
| 105 | char *p; | ||
| 106 | size_t clen; | ||
| 107 | int i; | ||
| 108 | |||
| 109 | pg = sysconf(_SC_PAGESIZE); | ||
| 110 | if (getcwd(cwd, sizeof cwd - 1) == NULL) | ||
| 111 | err(1, "getcwd"); | ||
| 112 | clen = strlen(cwd); | ||
| 113 | cwd[clen++] = '/'; | ||
| 114 | cwd[clen] = '\0'; | ||
| 115 | p = mmap(NULL, pg * 3, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); | ||
| 116 | if (p == NULL) | ||
| 117 | err(1, "mmap"); | ||
| 118 | if (mprotect(p, pg, PROT_NONE) || mprotect(p + pg * 2, pg, PROT_NONE)) | ||
| 119 | err(1, "mprotect"); | ||
| 120 | p += pg; | ||
| 121 | |||
| 122 | i = MAX_TEMPLATE_LEN + 1; | ||
| 123 | while (i-- > 1) { | ||
| 124 | /* try first at the start of a page, no prefix */ | ||
| 125 | try_mkstemp(p, "", i); | ||
| 126 | /* now at the end of the page, no prefix */ | ||
| 127 | try_mkstemp(p + pg - i - 1, "", i); | ||
| 128 | /* start of the page, prefixed with the cwd */ | ||
| 129 | try_mkstemp(p, cwd, i); | ||
| 130 | /* how about at the end of the page, prefixed with cwd? */ | ||
| 131 | try_mkstemp(p + pg - clen - i - 1, cwd, i); | ||
| 132 | |||
| 133 | /* again, with mkstemps() and an empty suffix */ | ||
| 134 | /* try first at the start of a page, no prefix */ | ||
| 135 | try_mkstemps(p, "", i, ""); | ||
| 136 | /* now at the end of the page, no prefix */ | ||
| 137 | try_mkstemps(p + pg - i - 1, "", i, ""); | ||
| 138 | /* start of the page, prefixed with the cwd */ | ||
| 139 | try_mkstemps(p, cwd, i, ""); | ||
| 140 | /* how about at the end of the page, prefixed with cwd? */ | ||
| 141 | try_mkstemps(p + pg - clen - i - 1, cwd, i, ""); | ||
| 142 | |||
| 143 | /* mkstemps() and a non-empty suffix */ | ||
| 144 | /* try first at the start of a page, no prefix */ | ||
| 145 | try_mkstemps(p, "", i, SUFFIX); | ||
| 146 | /* now at the end of the page, no prefix */ | ||
| 147 | try_mkstemps(p + pg - i - SLEN - 1, "", i, SUFFIX); | ||
| 148 | /* start of the page, prefixed with the cwd */ | ||
| 149 | try_mkstemps(p, cwd, i, SUFFIX); | ||
| 150 | /* how about at the end of the page, prefixed with cwd? */ | ||
| 151 | try_mkstemps(p + pg - clen - i - SLEN - 1, cwd, i, SUFFIX); | ||
| 152 | |||
| 153 | } | ||
| 154 | |||
| 155 | return 0; | ||
| 156 | } | ||
diff --git a/src/regress/lib/libc/netdb/Makefile b/src/regress/lib/libc/netdb/Makefile new file mode 100644 index 0000000000..8254607227 --- /dev/null +++ b/src/regress/lib/libc/netdb/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2004/10/25 15:10:36 otto Exp $ | ||
| 2 | |||
| 3 | PROG= netdb | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/netdb/netdb.c b/src/regress/lib/libc/netdb/netdb.c new file mode 100644 index 0000000000..0082c1bd1b --- /dev/null +++ b/src/regress/lib/libc/netdb/netdb.c | |||
| @@ -0,0 +1,182 @@ | |||
| 1 | /* $OpenBSD: netdb.c,v 1.1 2004/10/25 15:10:36 otto Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Public domain, 2004, Otto Moerbeek <otto@drijf.net> | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <err.h> | ||
| 8 | #include <netdb.h> | ||
| 9 | #include <stdarg.h> | ||
| 10 | |||
| 11 | int ret = 0; | ||
| 12 | |||
| 13 | void | ||
| 14 | checkp(int n, struct protoent *p, int proto, const char *name, ...) | ||
| 15 | { | ||
| 16 | va_list va; | ||
| 17 | char *a; | ||
| 18 | int i; | ||
| 19 | |||
| 20 | if (p == NULL) { | ||
| 21 | warnx("%d proto struct is NULL", n); | ||
| 22 | ret = 1; | ||
| 23 | return; | ||
| 24 | } | ||
| 25 | if (p->p_proto != proto) { | ||
| 26 | warnx("%d proto num mismatch %d %d", n, p->p_proto, proto); | ||
| 27 | ret = 1; | ||
| 28 | } | ||
| 29 | if (strcmp(p->p_name, name) != 0) { | ||
| 30 | warnx("%d proto name mismatch %s %s", n, p->p_name, name); | ||
| 31 | ret = 1; | ||
| 32 | } | ||
| 33 | va_start(va, name); | ||
| 34 | a = va_arg(va, char *); | ||
| 35 | i = 0; | ||
| 36 | while (a != NULL) { | ||
| 37 | if (strcmp(p->p_aliases[i], a) != 0) { | ||
| 38 | warnx("%d proto alias mismatch %s %s", n, | ||
| 39 | p->p_aliases[i], a); | ||
| 40 | ret = 1; | ||
| 41 | } | ||
| 42 | i++; | ||
| 43 | a = va_arg(va, char *); | ||
| 44 | } | ||
| 45 | if (p->p_aliases[i] != NULL) { | ||
| 46 | warnx("%d proto alias list does not end with NULL", n); | ||
| 47 | ret = 1; | ||
| 48 | } | ||
| 49 | va_end(va); | ||
| 50 | } | ||
| 51 | |||
| 52 | |||
| 53 | void | ||
| 54 | checks(int n, struct servent *s, int port, const char *proto, | ||
| 55 | const char *name, ...) | ||
| 56 | { | ||
| 57 | va_list va; | ||
| 58 | char *a; | ||
| 59 | int i; | ||
| 60 | |||
| 61 | if (s == NULL) { | ||
| 62 | warnx("%d serv struct is NULL", n); | ||
| 63 | ret = 1; | ||
| 64 | return; | ||
| 65 | } | ||
| 66 | if (s->s_port != ntohs(port)) { | ||
| 67 | warnx("%d port num mismatch %d %d", n, s->s_port, port); | ||
| 68 | ret = 1; | ||
| 69 | } | ||
| 70 | if (strcmp(s->s_name, name) != 0) { | ||
| 71 | warnx("%d serv name mismatch %s %s", n, s->s_name, name); | ||
| 72 | ret = 1; | ||
| 73 | } | ||
| 74 | if (strcmp(s->s_proto, proto) != 0) { | ||
| 75 | warnx("%d serv proto mismatch %s %s", n, s->s_proto, proto); | ||
| 76 | ret = 1; | ||
| 77 | } | ||
| 78 | va_start(va, name); | ||
| 79 | a = va_arg(va, char *); | ||
| 80 | i = 0; | ||
| 81 | while (a != NULL) { | ||
| 82 | if (strcmp(s->s_aliases[i], a) != 0) { | ||
| 83 | warnx("%d serv alias mismatch %s %s", n, | ||
| 84 | s->s_aliases[i], a); | ||
| 85 | ret = 1; | ||
| 86 | } | ||
| 87 | i++; | ||
| 88 | a = va_arg(va, char *); | ||
| 89 | } | ||
| 90 | if (s->s_aliases[i] != NULL) { | ||
| 91 | warnx("%d serv alias list does not end with NULL", n); | ||
| 92 | ret = 1; | ||
| 93 | } | ||
| 94 | va_end(va); | ||
| 95 | } | ||
| 96 | |||
| 97 | int | ||
| 98 | main() | ||
| 99 | { | ||
| 100 | struct protoent *p; | ||
| 101 | struct protoent protoent; | ||
| 102 | struct protoent_data protoent_data; | ||
| 103 | struct servent *s; | ||
| 104 | struct servent servent; | ||
| 105 | struct servent_data servent_data; | ||
| 106 | int r; | ||
| 107 | |||
| 108 | p = getprotobynumber(35); | ||
| 109 | checkp(1, p, 35, "idpr", "IDPR", (char *)NULL); | ||
| 110 | |||
| 111 | p = getprotobyname("igp"); | ||
| 112 | checkp(2, p, 9, "igp", "IGP", (char *) NULL); | ||
| 113 | |||
| 114 | p = getprotobyname("RDP"); | ||
| 115 | checkp(3, p, 27, "rdp", "RDP", (char *) NULL); | ||
| 116 | |||
| 117 | p = getprotobyname("vrrp"); | ||
| 118 | checkp(4, p, 112, "carp", "CARP", "vrrp", (char *) NULL); | ||
| 119 | |||
| 120 | p = getprotobyname("nonexistent"); | ||
| 121 | if (p != NULL) | ||
| 122 | err(1, "nonexistent proto found"); | ||
| 123 | |||
| 124 | memset(&protoent_data, 0, sizeof(protoent_data)); | ||
| 125 | r = getprotobynumber_r(35, &protoent, &protoent_data); | ||
| 126 | if (r != 0) | ||
| 127 | err(1, "proto not found"); | ||
| 128 | |||
| 129 | checkp(5, &protoent, 35, "idpr", "IDPR", (char *)NULL); | ||
| 130 | |||
| 131 | r = getprotobyname_r("vrrp", &protoent, &protoent_data); | ||
| 132 | if (r != 0) | ||
| 133 | err(1, "proto not found"); | ||
| 134 | checkp(6, &protoent, 112, "carp", "CARP", "vrrp", (char *) NULL); | ||
| 135 | |||
| 136 | r = getprotobyname_r("nonexistent", &protoent, &protoent_data); | ||
| 137 | if (r != -1) | ||
| 138 | err(1, "nonexistent proto found"); | ||
| 139 | |||
| 140 | r = getprotobyname_r("", &protoent, &protoent_data); | ||
| 141 | if (r != -1) | ||
| 142 | err(1, "nonexistent proto found"); | ||
| 143 | |||
| 144 | |||
| 145 | r = getprotobynumber_r(256, &protoent, &protoent_data); | ||
| 146 | if (r != -1) | ||
| 147 | err(1, "nonexistent proto found"); | ||
| 148 | |||
| 149 | s = getservbyname("zip", NULL); | ||
| 150 | checks(7, s, 6, "ddp", "zip", (char *)NULL); | ||
| 151 | |||
| 152 | s = getservbyname("nicname", "tcp"); | ||
| 153 | checks(8, s, 43, "tcp", "whois", "nicname", (char *)NULL); | ||
| 154 | |||
| 155 | s = getservbyport(htons(42), "tcp"); | ||
| 156 | checks(9, s, 42, "tcp", "nameserver", "name", (char *)NULL); | ||
| 157 | |||
| 158 | memset(&servent_data, 0, sizeof(servent_data)); | ||
| 159 | r = getservbyname_r("zip", "ddp", &servent, &servent_data); | ||
| 160 | if (r != 0) | ||
| 161 | err(1, "servent not found"); | ||
| 162 | checks(10, &servent, 6, "ddp", "zip", (char *)NULL); | ||
| 163 | |||
| 164 | r = getservbyport_r(htons(520), NULL, &servent, &servent_data); | ||
| 165 | if (r != 0) | ||
| 166 | err(1, "servent not found"); | ||
| 167 | checks(11, &servent, 520, "udp", "route", "router", "routed", (char *)NULL); | ||
| 168 | |||
| 169 | r = getservbyname_r("nonexistent", NULL, &servent, &servent_data); | ||
| 170 | if (r != -1) | ||
| 171 | err(1, "nonexiststent servent found"); | ||
| 172 | |||
| 173 | r = getservbyport_r(htons(50000), NULL, &servent, &servent_data); | ||
| 174 | if (r != -1) | ||
| 175 | err(1, "nonexistent servent found"); | ||
| 176 | |||
| 177 | r = getservbyport_r(htons(520), "tcp", &servent, &servent_data); | ||
| 178 | if (r != -1) | ||
| 179 | err(1, "nonexistent servent found"); | ||
| 180 | |||
| 181 | return ret; | ||
| 182 | } | ||
diff --git a/src/regress/lib/libc/orientation/Makefile b/src/regress/lib/libc/orientation/Makefile new file mode 100644 index 0000000000..5c73702abe --- /dev/null +++ b/src/regress/lib/libc/orientation/Makefile | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2010/06/29 16:20:28 guenther Exp $ | ||
| 2 | |||
| 3 | NOMAN= | ||
| 4 | PROG=orientation_test | ||
| 5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
| 6 | |||
| 7 | run-regress-${PROG}: ${PROG} | ||
| 8 | ./${PROG} | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/orientation/orientation_test.c b/src/regress/lib/libc/orientation/orientation_test.c new file mode 100644 index 0000000000..4af6a3407b --- /dev/null +++ b/src/regress/lib/libc/orientation/orientation_test.c | |||
| @@ -0,0 +1,252 @@ | |||
| 1 | /* $OpenBSD: orientation_test.c,v 1.1 2009/11/21 09:56:10 guenther Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2009 Philip Guenther | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * | ||
| 11 | * - Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * - Redistributions in binary form must reproduce the above | ||
| 14 | * copyright notice, this list of conditions and the following | ||
| 15 | * disclaimer in the documentation and/or other materials provided | ||
| 16 | * with the distribution. | ||
| 17 | * | ||
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| 28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | |||
| 32 | /* | ||
| 33 | * Test whether the various stdio functions set the stream orientation | ||
| 34 | * ("width") as they should | ||
| 35 | */ | ||
| 36 | |||
| 37 | #include <sys/types.h> | ||
| 38 | #include <err.h> | ||
| 39 | #include <stddef.h> | ||
| 40 | #include <stdio.h> | ||
| 41 | #include <stdlib.h> | ||
| 42 | #include <string.h> | ||
| 43 | #include <unistd.h> | ||
| 44 | #include <wchar.h> | ||
| 45 | |||
| 46 | char filename[] = "/tmp/fwide.XXXXXXXXXX"; | ||
| 47 | |||
| 48 | FILE *dup_stdout = NULL; | ||
| 49 | int failures = 0; | ||
| 50 | |||
| 51 | void | ||
| 52 | fail(int line, int r, char const *expect, char const *test) | ||
| 53 | { | ||
| 54 | failures++; | ||
| 55 | fprintf(dup_stdout, | ||
| 56 | "FAIL: %d: fwide returned %d, expected %s 0 after %s\n", | ||
| 57 | line, r, expect, test); | ||
| 58 | } | ||
| 59 | |||
| 60 | FILE * | ||
| 61 | setup(int line) | ||
| 62 | { | ||
| 63 | FILE *f; | ||
| 64 | int r; | ||
| 65 | |||
| 66 | if ((f = fopen(filename, "r+")) == NULL) | ||
| 67 | err(2, "fopen"); | ||
| 68 | if ((r = fwide(f, 0)) != 0) | ||
| 69 | fail(line, r, "==", "fopen"); | ||
| 70 | return (f); | ||
| 71 | } | ||
| 72 | |||
| 73 | FILE * | ||
| 74 | setup_std(FILE *std, int line) | ||
| 75 | { | ||
| 76 | int r; | ||
| 77 | |||
| 78 | if (freopen(filename, "r+", std) == NULL) | ||
| 79 | err(2, "freopen"); | ||
| 80 | if ((r = fwide(std, 0)) != 0) | ||
| 81 | fail(line, r, "==", "freopen"); | ||
| 82 | return (std); | ||
| 83 | } | ||
| 84 | |||
| 85 | #define TEST_(x, op) \ | ||
| 86 | do { \ | ||
| 87 | f = setup(__LINE__); \ | ||
| 88 | x; \ | ||
| 89 | if (!((r = fwide(f, 0)) op 0)) \ | ||
| 90 | fail(__LINE__, r, #op, #x); \ | ||
| 91 | fclose(f); \ | ||
| 92 | } while (0) | ||
| 93 | |||
| 94 | #define TEST_STD_(std, x, op) \ | ||
| 95 | do { \ | ||
| 96 | f = setup_std(std, __LINE__); \ | ||
| 97 | x; \ | ||
| 98 | if (!((r = fwide(f, 0)) op 0)) \ | ||
| 99 | fail(__LINE__, r, #op, #x); \ | ||
| 100 | } while (0) | ||
| 101 | |||
| 102 | #define TEST_UNCHANGED(x) TEST_(x, ==) | ||
| 103 | #define TEST_NARROW(x) TEST_(x, <) | ||
| 104 | #define TEST_WIDE(x) TEST_(x, >) | ||
| 105 | #define TEST_UNCHANGED_STD(std, x) TEST_STD_(std, x, ==) | ||
| 106 | #define TEST_NARROW_STD(std, x) TEST_STD_(std, x, <) | ||
| 107 | #define TEST_WIDE_STD(std, x) TEST_STD_(std, x, >) | ||
| 108 | |||
| 109 | int | ||
| 110 | main(int argc, char *argv[]) | ||
| 111 | { | ||
| 112 | char buffer[BUFSIZ]; | ||
| 113 | wchar_t wbuffer[BUFSIZ]; | ||
| 114 | FILE *f; | ||
| 115 | off_t off; | ||
| 116 | fpos_t pos; | ||
| 117 | size_t size; | ||
| 118 | int fd, r; | ||
| 119 | char c; | ||
| 120 | wchar_t wc; | ||
| 121 | |||
| 122 | if ((fd = dup(1)) == -1) | ||
| 123 | err(2, "dup"); | ||
| 124 | if ((dup_stdout = fdopen(fd, "w")) == NULL) | ||
| 125 | err(2, "fdopen"); | ||
| 126 | if ((fd = mkstemp(filename)) == -1) | ||
| 127 | err(2, "mkstemp"); | ||
| 128 | if (write(fd, "0123456789\n\n", 12) != 12 || close(fd)) | ||
| 129 | err(2, "write + close"); | ||
| 130 | |||
| 131 | /* status */ | ||
| 132 | TEST_UNCHANGED(fwide(f, 0)); | ||
| 133 | TEST_NARROW(fwide(f, -1)); | ||
| 134 | TEST_WIDE(fwide(f, 1)); | ||
| 135 | TEST_UNCHANGED(feof(f)); | ||
| 136 | TEST_UNCHANGED(ferror(f)); | ||
| 137 | TEST_UNCHANGED(fileno(f)); | ||
| 138 | TEST_UNCHANGED(clearerr(f)); | ||
| 139 | |||
| 140 | /* flush and purge */ | ||
| 141 | TEST_UNCHANGED(fflush(f)); | ||
| 142 | TEST_UNCHANGED(fpurge(f)); | ||
| 143 | |||
| 144 | /* positioning */ | ||
| 145 | TEST_UNCHANGED(fgetpos(f, &pos)); | ||
| 146 | TEST_UNCHANGED(fgetpos(f, &pos); fsetpos(f, &pos)); | ||
| 147 | TEST_UNCHANGED(ftell(f)); | ||
| 148 | TEST_UNCHANGED(ftello(f)); | ||
| 149 | TEST_UNCHANGED(fseek(f, 1, SEEK_CUR)); | ||
| 150 | TEST_UNCHANGED(fseek(f, 1, SEEK_SET)); | ||
| 151 | TEST_UNCHANGED(fseek(f, 1, SEEK_END)); | ||
| 152 | TEST_UNCHANGED(fseeko(f, 1, SEEK_CUR)); | ||
| 153 | TEST_UNCHANGED(fseeko(f, 1, SEEK_SET)); | ||
| 154 | TEST_UNCHANGED(fseeko(f, 1, SEEK_END)); | ||
| 155 | TEST_UNCHANGED(rewind(f)); | ||
| 156 | |||
| 157 | /* buffering */ | ||
| 158 | TEST_UNCHANGED(setbuf(f, NULL)); | ||
| 159 | TEST_UNCHANGED(setbuf(f, buffer)); | ||
| 160 | TEST_UNCHANGED(setvbuf(f, buffer, _IONBF, BUFSIZ)); | ||
| 161 | TEST_UNCHANGED(setvbuf(f, buffer, _IOLBF, BUFSIZ)); | ||
| 162 | TEST_UNCHANGED(setvbuf(f, buffer, _IOFBF, BUFSIZ)); | ||
| 163 | TEST_UNCHANGED(setvbuf(f, NULL, _IONBF, 0)); | ||
| 164 | TEST_UNCHANGED(setvbuf(f, NULL, _IOLBF, 0)); | ||
| 165 | TEST_UNCHANGED(setvbuf(f, NULL, _IOFBF, 0)); | ||
| 166 | TEST_UNCHANGED(setbuffer(f, NULL, 0)); | ||
| 167 | TEST_UNCHANGED(setbuffer(f, buffer, BUFSIZ)); | ||
| 168 | TEST_UNCHANGED(setlinebuf(f)); | ||
| 169 | |||
| 170 | /* locking */ | ||
| 171 | TEST_UNCHANGED(flockfile(f);funlockfile(f)); | ||
| 172 | TEST_UNCHANGED(ftrylockfile(f);funlockfile(f)); | ||
| 173 | |||
| 174 | /* input */ | ||
| 175 | TEST_NARROW(getc(f)); | ||
| 176 | TEST_NARROW(getc_unlocked(f)); | ||
| 177 | TEST_NARROW(fgetc(f)); | ||
| 178 | TEST_NARROW(c = fgetc(f); ungetc(c, f)); | ||
| 179 | TEST_NARROW(fgets(buffer, BUFSIZ, f)); | ||
| 180 | TEST_NARROW(fscanf(f, "%s\n", buffer)); | ||
| 181 | TEST_NARROW(fgetln(f, &size)); | ||
| 182 | |||
| 183 | /* output */ | ||
| 184 | TEST_NARROW(putc('c', f)); | ||
| 185 | TEST_NARROW(putc_unlocked('c', f)); | ||
| 186 | TEST_NARROW(fputc('c', f)); | ||
| 187 | TEST_NARROW(fputs("foo", f)); | ||
| 188 | TEST_NARROW(fprintf(f, "%s\n", "foo")); | ||
| 189 | |||
| 190 | /* input from stdin */ | ||
| 191 | TEST_NARROW_STD(stdin, getchar()); | ||
| 192 | TEST_NARROW_STD(stdin, getchar_unlocked()); | ||
| 193 | TEST_NARROW_STD(stdin, gets(buffer)); | ||
| 194 | TEST_NARROW_STD(stdin, scanf("%s\n", buffer)); | ||
| 195 | |||
| 196 | /* output to stdout */ | ||
| 197 | TEST_NARROW_STD(stdout, putchar('c')); | ||
| 198 | TEST_NARROW_STD(stdout, putchar_unlocked('c')); | ||
| 199 | TEST_NARROW_STD(stdout, puts("foo")); | ||
| 200 | TEST_NARROW_STD(stdout, printf("foo")); | ||
| 201 | |||
| 202 | /* word-size ops */ | ||
| 203 | /* | ||
| 204 | * fread and fwrite are specified as being implemented in | ||
| 205 | * terms of fgetc() and fputc() and therefore must set the | ||
| 206 | * stream orientation to narrow. | ||
| 207 | */ | ||
| 208 | TEST_NARROW(fread(buffer, 4, BUFSIZ / 4, f)); | ||
| 209 | TEST_NARROW(fwrite(buffer, 4, BUFSIZ / 4, f)); | ||
| 210 | |||
| 211 | /* | ||
| 212 | * getw() and putw() aren't specified anywhere but logically | ||
| 213 | * should behave the same as fread/fwrite. Not all OSes agree: | ||
| 214 | * Solaris 10 has them not changing the orientation. | ||
| 215 | */ | ||
| 216 | TEST_NARROW(getw(f)); | ||
| 217 | TEST_NARROW(putw(1234, f)); | ||
| 218 | |||
| 219 | |||
| 220 | /* WIDE CHAR TIME! */ | ||
| 221 | /* the four functions prefixed with "//X" are unimplemented */ | ||
| 222 | |||
| 223 | /* input */ | ||
| 224 | TEST_WIDE(getwc(f)); | ||
| 225 | TEST_WIDE(fgetwc(f)); | ||
| 226 | TEST_WIDE(wc = fgetwc(f); ungetwc(wc, f)); | ||
| 227 | TEST_WIDE(fgetws(wbuffer, BUFSIZ, f)); | ||
| 228 | //X TEST_WIDE(fwscanf(f, L"%s\n", wbuffer)); | ||
| 229 | |||
| 230 | /* output */ | ||
| 231 | TEST_WIDE(putwc(L'c', f)); | ||
| 232 | TEST_WIDE(fputwc(L'c', f)); | ||
| 233 | TEST_WIDE(fputws(L"foo", f)); | ||
| 234 | //X TEST_WIDE(fwprintf(f, L"%s\n", L"foo")); | ||
| 235 | |||
| 236 | /* input from stdin */ | ||
| 237 | TEST_WIDE_STD(stdin, getwchar()); | ||
| 238 | //X TEST_WIDE_STD(stdin, wscanf(L"%s\n", wbuffer)); | ||
| 239 | |||
| 240 | /* output to stdout */ | ||
| 241 | TEST_WIDE_STD(stdout, putwchar(L'c')); | ||
| 242 | //X TEST_WIDE_STD(stdout, wprintf(L"foo")); | ||
| 243 | |||
| 244 | |||
| 245 | TEST_UNCHANGED_STD(stderr, perror("foo")); | ||
| 246 | |||
| 247 | remove(filename); | ||
| 248 | if (failures) | ||
| 249 | exit(1); | ||
| 250 | exit(0); | ||
| 251 | } | ||
| 252 | |||
diff --git a/src/regress/lib/libc/popen/Makefile b/src/regress/lib/libc/popen/Makefile new file mode 100644 index 0000000000..25b8668a7a --- /dev/null +++ b/src/regress/lib/libc/popen/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2002/02/16 01:55:09 art Exp $ | ||
| 2 | |||
| 3 | PROG=popen | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/popen/popen.c b/src/regress/lib/libc/popen/popen.c new file mode 100644 index 0000000000..916cb71b03 --- /dev/null +++ b/src/regress/lib/libc/popen/popen.c | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | /* $NetBSD: popen.c,v 1.1 1999/09/30 09:23:23 tron Exp $ */ | ||
| 2 | |||
| 3 | /*- | ||
| 4 | * Copyright (c) 1999 The NetBSD Foundation, Inc. | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * This code is derived from software contributed to The NetBSD Foundation | ||
| 8 | * by Matthias Scheler. | ||
| 9 | * | ||
| 10 | * Redistribution and use in source and binary forms, with or without | ||
| 11 | * modification, are permitted provided that the following conditions | ||
| 12 | * are met: | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in the | ||
| 17 | * documentation and/or other materials provided with the distribution. | ||
| 18 | * | ||
| 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include <sys/param.h> | ||
| 33 | |||
| 34 | #include <err.h> | ||
| 35 | #include <errno.h> | ||
| 36 | #include <paths.h> | ||
| 37 | #include <stdio.h> | ||
| 38 | #include <stdlib.h> | ||
| 39 | #include <time.h> | ||
| 40 | #include <unistd.h> | ||
| 41 | |||
| 42 | #define _PATH_CAT "/bin/cat" | ||
| 43 | #define BUFSIZE (640*1024) | ||
| 44 | /* 640KB ought to be enough for everyone. */ | ||
| 45 | #define DATAFILE "popen.data" | ||
| 46 | |||
| 47 | int | ||
| 48 | main(int argc, char **argv) | ||
| 49 | { | ||
| 50 | char *buffer, command[MAXPATHLEN]; | ||
| 51 | int index, in; | ||
| 52 | FILE *pipe; | ||
| 53 | |||
| 54 | if ((buffer = malloc(BUFSIZE*sizeof(char))) == NULL) | ||
| 55 | err(1, NULL); | ||
| 56 | |||
| 57 | for (index=0; index<BUFSIZE; index++) | ||
| 58 | buffer[index]=arc4random(); | ||
| 59 | |||
| 60 | (void)snprintf(command, sizeof(command), "%s >%s", | ||
| 61 | _PATH_CAT, DATAFILE); | ||
| 62 | if ((pipe = popen(command, "w")) == NULL) | ||
| 63 | err(1, "popen write"); | ||
| 64 | |||
| 65 | if (fwrite(buffer, sizeof(char), BUFSIZE, pipe) != BUFSIZE) | ||
| 66 | err(1, "write"); | ||
| 67 | |||
| 68 | if (pclose(pipe) == -1) | ||
| 69 | err(1, "pclose"); | ||
| 70 | |||
| 71 | (void)snprintf(command, sizeof(command), "%s %s", | ||
| 72 | _PATH_CAT, DATAFILE); | ||
| 73 | if ((pipe = popen(command, "r")) == NULL) | ||
| 74 | err(1, "popen read"); | ||
| 75 | |||
| 76 | index = 0; | ||
| 77 | while ((in = fgetc(pipe)) != EOF) | ||
| 78 | if (index == BUFSIZE) { | ||
| 79 | errno = EFBIG; | ||
| 80 | err(1, "read"); | ||
| 81 | } | ||
| 82 | else | ||
| 83 | if ((char)in != buffer[index++]) { | ||
| 84 | errno = EINVAL; | ||
| 85 | err(1, "read"); | ||
| 86 | } | ||
| 87 | |||
| 88 | if (index < BUFSIZE) { | ||
| 89 | errno = EIO; | ||
| 90 | err(1, "read"); | ||
| 91 | } | ||
| 92 | |||
| 93 | if (pclose(pipe) == -1) | ||
| 94 | err(1, "pclose"); | ||
| 95 | |||
| 96 | (void)unlink(DATAFILE); | ||
| 97 | return 0; | ||
| 98 | } | ||
diff --git a/src/regress/lib/libc/printf/Makefile b/src/regress/lib/libc/printf/Makefile new file mode 100644 index 0000000000..c2e2732d6e --- /dev/null +++ b/src/regress/lib/libc/printf/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2008/09/07 20:36:10 martynas Exp $ | ||
| 2 | |||
| 3 | PROG= fp | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/printf/fp.c b/src/regress/lib/libc/printf/fp.c new file mode 100644 index 0000000000..6ed52fdb49 --- /dev/null +++ b/src/regress/lib/libc/printf/fp.c | |||
| @@ -0,0 +1,217 @@ | |||
| 1 | /* $OpenBSD: fp.c,v 1.1 2008/09/07 20:36:10 martynas Exp $ */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2002, 2005 David Schultz <das@FreeBSD.org> | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 25 | * SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | |||
| 28 | /* | ||
| 29 | * Test for printf() floating point formats. | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include <assert.h> | ||
| 33 | #include <err.h> | ||
| 34 | #include <float.h> | ||
| 35 | #include <math.h> | ||
| 36 | #include <stdio.h> | ||
| 37 | #include <stdarg.h> | ||
| 38 | #include <stdint.h> | ||
| 39 | #include <stdlib.h> | ||
| 40 | #include <string.h> | ||
| 41 | |||
| 42 | #define testfmt(result, fmt, ...) \ | ||
| 43 | _testfmt((result), __LINE__, #__VA_ARGS__, fmt, __VA_ARGS__) | ||
| 44 | void _testfmt(const char *, int, const char *, const char *, ...); | ||
| 45 | void smash_stack(void); | ||
| 46 | |||
| 47 | int | ||
| 48 | main(int argc, char *argv[]) | ||
| 49 | { | ||
| 50 | /* | ||
| 51 | * Basic tests of decimal output functionality. | ||
| 52 | */ | ||
| 53 | testfmt(" 1.000000E+00", "%13E", 1.0); | ||
| 54 | testfmt(" 1.000000", "%13f", 1.0); | ||
| 55 | testfmt(" 1", "%13G", 1.0); | ||
| 56 | testfmt(" 1.000000E+00", "%13LE", 1.0L); | ||
| 57 | testfmt(" 1.000000", "%13Lf", 1.0L); | ||
| 58 | testfmt(" 1", "%13LG", 1.0L); | ||
| 59 | |||
| 60 | testfmt("2.718282", "%.*f", -2, 2.7182818); | ||
| 61 | |||
| 62 | testfmt("1.234568e+06", "%e", 1234567.8); | ||
| 63 | testfmt("1234567.800000", "%f", 1234567.8); | ||
| 64 | testfmt("1.23457E+06", "%G", 1234567.8); | ||
| 65 | testfmt("1.234568e+06", "%Le", 1234567.8L); | ||
| 66 | testfmt("1234567.800000", "%Lf", 1234567.8L); | ||
| 67 | testfmt("1.23457E+06", "%LG", 1234567.8L); | ||
| 68 | |||
| 69 | #if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) | ||
| 70 | testfmt("123456789.864210", "%Lf", 123456789.8642097531L); | ||
| 71 | testfmt("-1.23457E+08", "%LG", -123456789.8642097531L); | ||
| 72 | testfmt("123456789.8642097531", "%.10Lf", 123456789.8642097531L); | ||
| 73 | testfmt(" 3.141592653589793238e-4000", "%L27.18Le", | ||
| 74 | 3.14159265358979323846e-4000L); | ||
| 75 | #endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) */ | ||
| 76 | |||
| 77 | /* | ||
| 78 | * Infinities and NaNs | ||
| 79 | */ | ||
| 80 | #ifdef NAN | ||
| 81 | testfmt("nan", "%e", NAN); | ||
| 82 | testfmt("NAN", "%F", NAN); | ||
| 83 | testfmt("nan", "%g", NAN); | ||
| 84 | testfmt("NAN", "%LE", (long double)NAN); | ||
| 85 | testfmt(" nan", "%05e", NAN); | ||
| 86 | #endif /* NAN */ | ||
| 87 | |||
| 88 | testfmt("INF", "%E", HUGE_VAL); | ||
| 89 | testfmt("-inf", "%f", -HUGE_VAL); | ||
| 90 | testfmt("+inf", "%+g", HUGE_VAL); | ||
| 91 | testfmt(" inf", "%4.2Le", HUGE_VALL); | ||
| 92 | testfmt("-inf", "%Lf", -HUGE_VALL); | ||
| 93 | testfmt(" inf", "%05e", HUGE_VAL); | ||
| 94 | testfmt(" -inf", "%05e", -HUGE_VAL); | ||
| 95 | |||
| 96 | /* | ||
| 97 | * Padding | ||
| 98 | */ | ||
| 99 | testfmt("0.000000e+00", "%e", 0.0); | ||
| 100 | testfmt("0.000000", "%F", (double)0.0); | ||
| 101 | testfmt("0", "%G", 0.0); | ||
| 102 | testfmt(" 0", "%3.0Lg", 0.0L); | ||
| 103 | testfmt(" 0", "%5.0f", 0.001); | ||
| 104 | |||
| 105 | /* | ||
| 106 | * Precision specifiers | ||
| 107 | */ | ||
| 108 | testfmt("1.0123e+00", "%.4e", 1.0123456789); | ||
| 109 | testfmt("1.0123", "%.4f", 1.0123456789); | ||
| 110 | testfmt("1.012", "%.4g", 1.0123456789); | ||
| 111 | testfmt("1.2346e-02", "%.4e", 0.0123456789); | ||
| 112 | testfmt("0.0123", "%.4f", 0.0123456789); | ||
| 113 | testfmt("0.01235", "%.4g", 0.0123456789); | ||
| 114 | |||
| 115 | /* | ||
| 116 | * Signed conversions | ||
| 117 | */ | ||
| 118 | testfmt("+2.500000e-01", "%+e", 0.25); | ||
| 119 | testfmt("+0.000000", "%+F", 0.0); | ||
| 120 | testfmt("-1", "%+g", -1.0); | ||
| 121 | |||
| 122 | testfmt("-1.000000e+00", "% e", -1.0); | ||
| 123 | testfmt("+1.000000", "% +f", 1.0); | ||
| 124 | testfmt(" 1", "% g", 1.0); | ||
| 125 | testfmt(" 0", "% g", 0.0); | ||
| 126 | |||
| 127 | /* | ||
| 128 | * ``Alternate form'' | ||
| 129 | */ | ||
| 130 | testfmt("1.250e+00", "%#.3e", 1.25); | ||
| 131 | testfmt("123.000000", "%#f", 123.0); | ||
| 132 | testfmt(" 12345.", "%#7.5g", 12345.0); | ||
| 133 | testfmt(" 1.00000", "%#8g", 1.0); | ||
| 134 | testfmt("0.0", "%#.2g", 0.0); | ||
| 135 | |||
| 136 | /* | ||
| 137 | * Padding and decimal point placement | ||
| 138 | */ | ||
| 139 | testfmt("03.2E+00", "%08.1E", 3.25); | ||
| 140 | testfmt("003.25", "%06.2F", 3.25); | ||
| 141 | testfmt("0003.25", "%07.4G", 3.25); | ||
| 142 | |||
| 143 | testfmt("3.14159e-05", "%g", 3.14159e-5); | ||
| 144 | testfmt("0.000314159", "%g", 3.14159e-4); | ||
| 145 | testfmt("3.14159e+06", "%g", 3.14159e6); | ||
| 146 | testfmt("314159", "%g", 3.14159e5); | ||
| 147 | testfmt("314159.", "%#g", 3.14159e5); | ||
| 148 | |||
| 149 | testfmt(" 9.000000e+03", "%13e", 9000.0); | ||
| 150 | testfmt(" 9000.000000", "%12f", 9000.0); | ||
| 151 | testfmt(" 9000", "%5g", 9000.0); | ||
| 152 | testfmt(" 900000.", "%#8g", 900000.0); | ||
| 153 | testfmt(" 9e+06", "%6g", 9000000.0); | ||
| 154 | testfmt(" 9.000000e-04", "%13e", 0.0009); | ||
| 155 | testfmt(" 0.000900", "%9f", 0.0009); | ||
| 156 | testfmt(" 0.0009", "%7g", 0.0009); | ||
| 157 | testfmt(" 9e-05", "%6g", 0.00009); | ||
| 158 | testfmt(" 9.00000e-05", "%#12g", 0.00009); | ||
| 159 | testfmt(" 9.e-05", "%#7.1g", 0.00009); | ||
| 160 | |||
| 161 | testfmt(" 0.0", "%4.1f", 0.0); | ||
| 162 | testfmt("90.0", "%4.1f", 90.0); | ||
| 163 | testfmt(" 100", "%4.0f", 100.0); | ||
| 164 | testfmt("9.0e+01", "%4.1e", 90.0); | ||
| 165 | testfmt("1e+02", "%4.0e", 100.0); | ||
| 166 | |||
| 167 | /* | ||
| 168 | * Hexadecimal floating point (%a, %A) tests. Some of these | ||
| 169 | * are only valid if the implementation converts to hex digits | ||
| 170 | * on nibble boundaries. | ||
| 171 | */ | ||
| 172 | testfmt("0x0p+0", "%a", 0x0.0p0); | ||
| 173 | testfmt("0X0.P+0", "%#LA", 0x0.0p0L); | ||
| 174 | #ifdef NAN | ||
| 175 | testfmt("inf", "%La", (long double)INFINITY); | ||
| 176 | testfmt("+INF", "%+A", INFINITY); | ||
| 177 | testfmt("nan", "%La", (long double)NAN); | ||
| 178 | testfmt("NAN", "%A", NAN); | ||
| 179 | #endif /* NAN */ | ||
| 180 | |||
| 181 | testfmt(" 0x1.23p+0", "%10a", 0x1.23p0); | ||
| 182 | testfmt(" 0x1.23p-500", "%12a", 0x1.23p-500); | ||
| 183 | testfmt(" 0x1.2p+40", "%10.1a", 0x1.23p40); | ||
| 184 | testfmt(" 0X1.230000000000000000000000P-4", "%32.24A", 0x1.23p-4); | ||
| 185 | testfmt("0x1p-1074", "%a", 0x1p-1074); | ||
| 186 | testfmt("0x1.2345p-1024", "%a", 0x1.2345p-1024); | ||
| 187 | |||
| 188 | return (0); | ||
| 189 | } | ||
| 190 | |||
| 191 | void | ||
| 192 | smash_stack(void) | ||
| 193 | { | ||
| 194 | static uint32_t junk = 0xdeadbeef; | ||
| 195 | uint32_t buf[512]; | ||
| 196 | int i; | ||
| 197 | |||
| 198 | for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++) | ||
| 199 | buf[i] = junk; | ||
| 200 | } | ||
| 201 | |||
| 202 | void | ||
| 203 | _testfmt(const char *result, int line, const char *argstr, const char *fmt,...) | ||
| 204 | { | ||
| 205 | char s[100]; | ||
| 206 | va_list ap; | ||
| 207 | |||
| 208 | va_start(ap, fmt); | ||
| 209 | smash_stack(); | ||
| 210 | vsnprintf(s, sizeof(s), fmt, ap); | ||
| 211 | if (strcmp(result, s) != 0) { | ||
| 212 | fprintf(stderr, | ||
| 213 | "%d: printf(\"%s\", %s) ==> [%s], expected [%s]\n", | ||
| 214 | line, fmt, argstr, s, result); | ||
| 215 | abort(); | ||
| 216 | } | ||
| 217 | } | ||
diff --git a/src/regress/lib/libc/regex/Makefile b/src/regress/lib/libc/regex/Makefile new file mode 100644 index 0000000000..271debb5d3 --- /dev/null +++ b/src/regress/lib/libc/regex/Makefile | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.6 2004/08/13 14:54:12 millert Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $ | ||
| 3 | |||
| 4 | PROG= re | ||
| 5 | SRCS= main.c split.c debug.c regcomp.c regerror.c regexec.c regfree.c | ||
| 6 | .PATH: ${.CURDIR}/../../../../lib/libc/regex | ||
| 7 | |||
| 8 | CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex -DREDEBUG -DPOSIX_MISTAKE | ||
| 9 | |||
| 10 | TESTS= ${.CURDIR}/tests | ||
| 11 | |||
| 12 | REGRESS_TARGETS=do-reg do-reg-long do-reg-backref | ||
| 13 | |||
| 14 | do-reg: ${PROG} | ||
| 15 | ./re < ${TESTS} | ||
| 16 | do-reg-long: ${PROG} | ||
| 17 | ./re -el < ${TESTS} | ||
| 18 | do-reg-backref: ${PROG} | ||
| 19 | ./re -er < ${TESTS} | ||
| 20 | |||
| 21 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/regex/debug.c b/src/regress/lib/libc/regex/debug.c new file mode 100644 index 0000000000..11129e7249 --- /dev/null +++ b/src/regress/lib/libc/regex/debug.c | |||
| @@ -0,0 +1,245 @@ | |||
| 1 | /* $OpenBSD: debug.c,v 1.4 2003/07/31 21:48:03 deraadt Exp $ */ | ||
| 2 | /* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */ | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <ctype.h> | ||
| 7 | #include <limits.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include <sys/types.h> | ||
| 10 | #include <regex.h> | ||
| 11 | |||
| 12 | #include "utils.h" | ||
| 13 | #include "regex2.h" | ||
| 14 | #include "debug.ih" | ||
| 15 | |||
| 16 | /* | ||
| 17 | - regprint - print a regexp for debugging | ||
| 18 | == void regprint(regex_t *r, FILE *d); | ||
| 19 | */ | ||
| 20 | void | ||
| 21 | regprint(r, d) | ||
| 22 | regex_t *r; | ||
| 23 | FILE *d; | ||
| 24 | { | ||
| 25 | register struct re_guts *g = r->re_g; | ||
| 26 | register int i; | ||
| 27 | register int c; | ||
| 28 | register int last; | ||
| 29 | int nincat[NC]; | ||
| 30 | |||
| 31 | fprintf(d, "%ld states, %d categories", (long)g->nstates, | ||
| 32 | g->ncategories); | ||
| 33 | fprintf(d, ", first %ld last %ld", (long)g->firststate, | ||
| 34 | (long)g->laststate); | ||
| 35 | if (g->iflags&USEBOL) | ||
| 36 | fprintf(d, ", USEBOL"); | ||
| 37 | if (g->iflags&USEEOL) | ||
| 38 | fprintf(d, ", USEEOL"); | ||
| 39 | if (g->iflags&BAD) | ||
| 40 | fprintf(d, ", BAD"); | ||
| 41 | if (g->nsub > 0) | ||
| 42 | fprintf(d, ", nsub=%ld", (long)g->nsub); | ||
| 43 | if (g->must != NULL) | ||
| 44 | fprintf(d, ", must(%ld) `%*s'", (long)g->mlen, (int)g->mlen, | ||
| 45 | g->must); | ||
| 46 | if (g->backrefs) | ||
| 47 | fprintf(d, ", backrefs"); | ||
| 48 | if (g->nplus > 0) | ||
| 49 | fprintf(d, ", nplus %ld", (long)g->nplus); | ||
| 50 | fprintf(d, "\n"); | ||
| 51 | s_print(g, d); | ||
| 52 | for (i = 0; i < g->ncategories; i++) { | ||
| 53 | nincat[i] = 0; | ||
| 54 | for (c = CHAR_MIN; c <= CHAR_MAX; c++) | ||
| 55 | if (g->categories[c] == i) | ||
| 56 | nincat[i]++; | ||
| 57 | } | ||
| 58 | fprintf(d, "cc0#%d", nincat[0]); | ||
| 59 | for (i = 1; i < g->ncategories; i++) | ||
| 60 | if (nincat[i] == 1) { | ||
| 61 | for (c = CHAR_MIN; c <= CHAR_MAX; c++) | ||
| 62 | if (g->categories[c] == i) | ||
| 63 | break; | ||
| 64 | fprintf(d, ", %d=%s", i, regchar(c)); | ||
| 65 | } | ||
| 66 | fprintf(d, "\n"); | ||
| 67 | for (i = 1; i < g->ncategories; i++) | ||
| 68 | if (nincat[i] != 1) { | ||
| 69 | fprintf(d, "cc%d\t", i); | ||
| 70 | last = -1; | ||
| 71 | for (c = CHAR_MIN; c <= CHAR_MAX+1; c++) /* +1 does flush */ | ||
| 72 | if (c <= CHAR_MAX && g->categories[c] == i) { | ||
| 73 | if (last < 0) { | ||
| 74 | fprintf(d, "%s", regchar(c)); | ||
| 75 | last = c; | ||
| 76 | } | ||
| 77 | } else { | ||
| 78 | if (last >= 0) { | ||
| 79 | if (last != c-1) | ||
| 80 | fprintf(d, "-%s", | ||
| 81 | regchar(c-1)); | ||
| 82 | last = -1; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | fprintf(d, "\n"); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | /* | ||
| 90 | - s_print - print the strip for debugging | ||
| 91 | == static void s_print(register struct re_guts *g, FILE *d); | ||
| 92 | */ | ||
| 93 | static void | ||
| 94 | s_print(g, d) | ||
| 95 | register struct re_guts *g; | ||
| 96 | FILE *d; | ||
| 97 | { | ||
| 98 | register sop *s; | ||
| 99 | register cset *cs; | ||
| 100 | register int i; | ||
| 101 | register int done = 0; | ||
| 102 | register sop opnd; | ||
| 103 | register int col = 0; | ||
| 104 | register int last; | ||
| 105 | register sopno offset = 2; | ||
| 106 | # define GAP() { if (offset % 5 == 0) { \ | ||
| 107 | if (col > 40) { \ | ||
| 108 | fprintf(d, "\n\t"); \ | ||
| 109 | col = 0; \ | ||
| 110 | } else { \ | ||
| 111 | fprintf(d, " "); \ | ||
| 112 | col++; \ | ||
| 113 | } \ | ||
| 114 | } else \ | ||
| 115 | col++; \ | ||
| 116 | offset++; \ | ||
| 117 | } | ||
| 118 | |||
| 119 | if (OP(g->strip[0]) != OEND) | ||
| 120 | fprintf(d, "missing initial OEND!\n"); | ||
| 121 | for (s = &g->strip[1]; !done; s++) { | ||
| 122 | opnd = OPND(*s); | ||
| 123 | switch (OP(*s)) { | ||
| 124 | case OEND: | ||
| 125 | fprintf(d, "\n"); | ||
| 126 | done = 1; | ||
| 127 | break; | ||
| 128 | case OCHAR: | ||
| 129 | if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL) | ||
| 130 | fprintf(d, "\\%c", (char)opnd); | ||
| 131 | else | ||
| 132 | fprintf(d, "%s", regchar((char)opnd)); | ||
| 133 | break; | ||
| 134 | case OBOL: | ||
| 135 | fprintf(d, "^"); | ||
| 136 | break; | ||
| 137 | case OEOL: | ||
| 138 | fprintf(d, "$"); | ||
| 139 | break; | ||
| 140 | case OBOW: | ||
| 141 | fprintf(d, "\\{"); | ||
| 142 | break; | ||
| 143 | case OEOW: | ||
| 144 | fprintf(d, "\\}"); | ||
| 145 | break; | ||
| 146 | case OANY: | ||
| 147 | fprintf(d, "."); | ||
| 148 | break; | ||
| 149 | case OANYOF: | ||
| 150 | fprintf(d, "[(%ld)", (long)opnd); | ||
| 151 | cs = &g->sets[opnd]; | ||
| 152 | last = -1; | ||
| 153 | for (i = 0; i < g->csetsize+1; i++) /* +1 flushes */ | ||
| 154 | if (CHIN(cs, i) && i < g->csetsize) { | ||
| 155 | if (last < 0) { | ||
| 156 | fprintf(d, "%s", regchar(i)); | ||
| 157 | last = i; | ||
| 158 | } | ||
| 159 | } else { | ||
| 160 | if (last >= 0) { | ||
| 161 | if (last != i-1) | ||
| 162 | fprintf(d, "-%s", | ||
| 163 | regchar(i-1)); | ||
| 164 | last = -1; | ||
| 165 | } | ||
| 166 | } | ||
| 167 | fprintf(d, "]"); | ||
| 168 | break; | ||
| 169 | case OBACK_: | ||
| 170 | fprintf(d, "(\\<%ld>", (long)opnd); | ||
| 171 | break; | ||
| 172 | case O_BACK: | ||
| 173 | fprintf(d, "<%ld>\\)", (long)opnd); | ||
| 174 | break; | ||
| 175 | case OPLUS_: | ||
| 176 | fprintf(d, "(+"); | ||
| 177 | if (OP(*(s+opnd)) != O_PLUS) | ||
| 178 | fprintf(d, "<%ld>", (long)opnd); | ||
| 179 | break; | ||
| 180 | case O_PLUS: | ||
| 181 | if (OP(*(s-opnd)) != OPLUS_) | ||
| 182 | fprintf(d, "<%ld>", (long)opnd); | ||
| 183 | fprintf(d, "+)"); | ||
| 184 | break; | ||
| 185 | case OQUEST_: | ||
| 186 | fprintf(d, "(?"); | ||
| 187 | if (OP(*(s+opnd)) != O_QUEST) | ||
| 188 | fprintf(d, "<%ld>", (long)opnd); | ||
| 189 | break; | ||
| 190 | case O_QUEST: | ||
| 191 | if (OP(*(s-opnd)) != OQUEST_) | ||
| 192 | fprintf(d, "<%ld>", (long)opnd); | ||
| 193 | fprintf(d, "?)"); | ||
| 194 | break; | ||
| 195 | case OLPAREN: | ||
| 196 | fprintf(d, "((<%ld>", (long)opnd); | ||
| 197 | break; | ||
| 198 | case ORPAREN: | ||
| 199 | fprintf(d, "<%ld>))", (long)opnd); | ||
| 200 | break; | ||
| 201 | case OCH_: | ||
| 202 | fprintf(d, "<"); | ||
| 203 | if (OP(*(s+opnd)) != OOR2) | ||
| 204 | fprintf(d, "<%ld>", (long)opnd); | ||
| 205 | break; | ||
| 206 | case OOR1: | ||
| 207 | if (OP(*(s-opnd)) != OOR1 && OP(*(s-opnd)) != OCH_) | ||
| 208 | fprintf(d, "<%ld>", (long)opnd); | ||
| 209 | fprintf(d, "|"); | ||
| 210 | break; | ||
| 211 | case OOR2: | ||
| 212 | fprintf(d, "|"); | ||
| 213 | if (OP(*(s+opnd)) != OOR2 && OP(*(s+opnd)) != O_CH) | ||
| 214 | fprintf(d, "<%ld>", (long)opnd); | ||
| 215 | break; | ||
| 216 | case O_CH: | ||
| 217 | if (OP(*(s-opnd)) != OOR1) | ||
| 218 | fprintf(d, "<%ld>", (long)opnd); | ||
| 219 | fprintf(d, ">"); | ||
| 220 | break; | ||
| 221 | default: | ||
| 222 | fprintf(d, "!%ld(%ld)!", (long)OP(*s), (long)opnd); | ||
| 223 | break; | ||
| 224 | } | ||
| 225 | if (!done) | ||
| 226 | GAP(); | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 | /* | ||
| 231 | - regchar - make a character printable | ||
| 232 | == static char *regchar(int ch); | ||
| 233 | */ | ||
| 234 | static char * /* -> representation */ | ||
| 235 | regchar(ch) | ||
| 236 | int ch; | ||
| 237 | { | ||
| 238 | static char buf[10]; | ||
| 239 | |||
| 240 | if (isprint(ch) || ch == ' ') | ||
| 241 | snprintf(buf, sizeof buf, "%c", ch); | ||
| 242 | else | ||
| 243 | snprintf(buf, sizeof buf, "\\%o", ch); | ||
| 244 | return(buf); | ||
| 245 | } | ||
diff --git a/src/regress/lib/libc/regex/debug.ih b/src/regress/lib/libc/regex/debug.ih new file mode 100644 index 0000000000..9eb313af23 --- /dev/null +++ b/src/regress/lib/libc/regex/debug.ih | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | /* $OpenBSD: debug.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
| 2 | /* $NetBSD: debug.ih,v 1.2 1995/04/20 22:39:47 cgd Exp $ */ | ||
| 3 | |||
| 4 | /* ========= begin header generated by ./mkh ========= */ | ||
| 5 | #ifdef __cplusplus | ||
| 6 | extern "C" { | ||
| 7 | #endif | ||
| 8 | |||
| 9 | /* === debug.c === */ | ||
| 10 | void regprint(regex_t *r, FILE *d); | ||
| 11 | static void s_print(register struct re_guts *g, FILE *d); | ||
| 12 | static char *regchar(int ch); | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | } | ||
| 16 | #endif | ||
| 17 | /* ========= end header generated by ./mkh ========= */ | ||
diff --git a/src/regress/lib/libc/regex/main.c b/src/regress/lib/libc/regex/main.c new file mode 100644 index 0000000000..e0ed86f5e8 --- /dev/null +++ b/src/regress/lib/libc/regex/main.c | |||
| @@ -0,0 +1,516 @@ | |||
| 1 | /* $OpenBSD: main.c,v 1.7 2007/09/12 19:32:35 otto Exp $ */ | ||
| 2 | /* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */ | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <sys/types.h> | ||
| 8 | #include <regex.h> | ||
| 9 | #include <assert.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | |||
| 12 | #include "main.ih" | ||
| 13 | |||
| 14 | char *progname; | ||
| 15 | int debug = 0; | ||
| 16 | int line = 0; | ||
| 17 | int status = 0; | ||
| 18 | |||
| 19 | int copts = REG_EXTENDED; | ||
| 20 | int eopts = 0; | ||
| 21 | regoff_t startoff = 0; | ||
| 22 | regoff_t endoff = 0; | ||
| 23 | |||
| 24 | |||
| 25 | extern int split(char *, char *[], int, char *); | ||
| 26 | extern void regprint(regex_t *, FILE *); | ||
| 27 | |||
| 28 | /* | ||
| 29 | - main - do the simple case, hand off to regress() for regression | ||
| 30 | */ | ||
| 31 | int | ||
| 32 | main(int argc, char *argv[]) | ||
| 33 | |||
| 34 | { | ||
| 35 | regex_t re; | ||
| 36 | # define NS 10 | ||
| 37 | regmatch_t subs[NS]; | ||
| 38 | char erbuf[100]; | ||
| 39 | int err; | ||
| 40 | size_t len; | ||
| 41 | int c; | ||
| 42 | int errflg = 0; | ||
| 43 | register int i; | ||
| 44 | extern int optind; | ||
| 45 | extern char *optarg; | ||
| 46 | |||
| 47 | progname = argv[0]; | ||
| 48 | |||
| 49 | while ((c = getopt(argc, argv, "c:e:S:E:x")) != -1) | ||
| 50 | switch (c) { | ||
| 51 | case 'c': /* compile options */ | ||
| 52 | copts = options('c', optarg); | ||
| 53 | break; | ||
| 54 | case 'e': /* execute options */ | ||
| 55 | eopts = options('e', optarg); | ||
| 56 | break; | ||
| 57 | case 'S': /* start offset */ | ||
| 58 | startoff = (regoff_t)atoi(optarg); | ||
| 59 | break; | ||
| 60 | case 'E': /* end offset */ | ||
| 61 | endoff = (regoff_t)atoi(optarg); | ||
| 62 | break; | ||
| 63 | case 'x': /* Debugging. */ | ||
| 64 | debug++; | ||
| 65 | break; | ||
| 66 | case '?': | ||
| 67 | default: | ||
| 68 | errflg++; | ||
| 69 | break; | ||
| 70 | } | ||
| 71 | if (errflg) { | ||
| 72 | fprintf(stderr, "usage: %s ", progname); | ||
| 73 | fprintf(stderr, "[-c copt][-C][-d] [re]\n"); | ||
| 74 | exit(2); | ||
| 75 | } | ||
| 76 | |||
| 77 | if (optind >= argc) { | ||
| 78 | regress(stdin); | ||
| 79 | exit(status); | ||
| 80 | } | ||
| 81 | |||
| 82 | err = regcomp(&re, argv[optind++], copts); | ||
| 83 | if (err) { | ||
| 84 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
| 85 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", | ||
| 86 | eprint(err), len, sizeof(erbuf), erbuf); | ||
| 87 | exit(status); | ||
| 88 | } | ||
| 89 | regprint(&re, stdout); | ||
| 90 | |||
| 91 | if (optind >= argc) { | ||
| 92 | regfree(&re); | ||
| 93 | exit(status); | ||
| 94 | } | ||
| 95 | |||
| 96 | if (eopts®_STARTEND) { | ||
| 97 | subs[0].rm_so = startoff; | ||
| 98 | subs[0].rm_eo = strlen(argv[optind]) - endoff; | ||
| 99 | } | ||
| 100 | err = regexec(&re, argv[optind], (size_t)NS, subs, eopts); | ||
| 101 | if (err) { | ||
| 102 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
| 103 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", | ||
| 104 | eprint(err), len, sizeof(erbuf), erbuf); | ||
| 105 | exit(status); | ||
| 106 | } | ||
| 107 | if (!(copts®_NOSUB)) { | ||
| 108 | len = (size_t)(subs[0].rm_eo - subs[0].rm_so); | ||
| 109 | if (subs[0].rm_so != -1) { | ||
| 110 | if (len != 0) | ||
| 111 | printf("match `%.*s'\n", (int)len, | ||
| 112 | argv[optind] + subs[0].rm_so); | ||
| 113 | else | ||
| 114 | printf("match `'@%.1s\n", | ||
| 115 | argv[optind] + subs[0].rm_so); | ||
| 116 | } | ||
| 117 | for (i = 1; i < NS; i++) | ||
| 118 | if (subs[i].rm_so != -1) | ||
| 119 | printf("(%d) `%.*s'\n", i, | ||
| 120 | (int)(subs[i].rm_eo - subs[i].rm_so), | ||
| 121 | argv[optind] + subs[i].rm_so); | ||
| 122 | } | ||
| 123 | exit(status); | ||
| 124 | } | ||
| 125 | |||
| 126 | /* | ||
| 127 | - regress - main loop of regression test | ||
| 128 | == void regress(FILE *in); | ||
| 129 | */ | ||
| 130 | void | ||
| 131 | regress(in) | ||
| 132 | FILE *in; | ||
| 133 | { | ||
| 134 | char inbuf[1000]; | ||
| 135 | # define MAXF 10 | ||
| 136 | char *f[MAXF]; | ||
| 137 | int nf; | ||
| 138 | int i; | ||
| 139 | char erbuf[100]; | ||
| 140 | size_t ne; | ||
| 141 | char *badpat = "invalid regular expression"; | ||
| 142 | # define SHORT 10 | ||
| 143 | char *bpname = "REG_BADPAT"; | ||
| 144 | regex_t re; | ||
| 145 | |||
| 146 | while (fgets(inbuf, sizeof(inbuf), in) != NULL) { | ||
| 147 | line++; | ||
| 148 | if (inbuf[0] == '#' || inbuf[0] == '\n') | ||
| 149 | continue; /* NOTE CONTINUE */ | ||
| 150 | inbuf[strcspn(inbuf, "\n")] = '\0'; /* get rid of stupid \n */ | ||
| 151 | if (debug) | ||
| 152 | fprintf(stdout, "%d:\n", line); | ||
| 153 | nf = split(inbuf, f, MAXF, "\t\t"); | ||
| 154 | if (nf < 3) { | ||
| 155 | fprintf(stderr, "bad input, line %d\n", line); | ||
| 156 | exit(1); | ||
| 157 | } | ||
| 158 | for (i = 0; i < nf; i++) | ||
| 159 | if (strcmp(f[i], "\"\"") == 0) | ||
| 160 | f[i] = ""; | ||
| 161 | if (nf <= 3) | ||
| 162 | f[3] = NULL; | ||
| 163 | if (nf <= 4) | ||
| 164 | f[4] = NULL; | ||
| 165 | try(f[0], f[1], f[2], f[3], f[4], options('c', f[1])); | ||
| 166 | if (opt('&', f[1])) /* try with either type of RE */ | ||
| 167 | try(f[0], f[1], f[2], f[3], f[4], | ||
| 168 | options('c', f[1]) &~ REG_EXTENDED); | ||
| 169 | } | ||
| 170 | |||
| 171 | ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf)); | ||
| 172 | if (strcmp(erbuf, badpat) != 0 || ne != strlen(badpat)+1) { | ||
| 173 | fprintf(stderr, "end: regerror() test gave `%s' not `%s'\n", | ||
| 174 | erbuf, badpat); | ||
| 175 | status = 1; | ||
| 176 | } | ||
| 177 | ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, (size_t)SHORT); | ||
| 178 | if (strncmp(erbuf, badpat, SHORT-1) != 0 || erbuf[SHORT-1] != '\0' || | ||
| 179 | ne != strlen(badpat)+1) { | ||
| 180 | fprintf(stderr, "end: regerror() short test gave `%s' not `%.*s'\n", | ||
| 181 | erbuf, SHORT-1, badpat); | ||
| 182 | status = 1; | ||
| 183 | } | ||
| 184 | ne = regerror(REG_ITOA|REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf)); | ||
| 185 | if (strcmp(erbuf, bpname) != 0 || ne != strlen(bpname)+1) { | ||
| 186 | fprintf(stderr, "end: regerror() ITOA test gave `%s' not `%s'\n", | ||
| 187 | erbuf, bpname); | ||
| 188 | status = 1; | ||
| 189 | } | ||
| 190 | re.re_endp = bpname; | ||
| 191 | ne = regerror(REG_ATOI, &re, erbuf, sizeof(erbuf)); | ||
| 192 | if (atoi(erbuf) != (int)REG_BADPAT) { | ||
| 193 | fprintf(stderr, "end: regerror() ATOI test gave `%s' not `%ld'\n", | ||
| 194 | erbuf, (long)REG_BADPAT); | ||
| 195 | status = 1; | ||
| 196 | } else if (ne != strlen(erbuf)+1) { | ||
| 197 | fprintf(stderr, "end: regerror() ATOI test len(`%s') = %ld\n", | ||
| 198 | erbuf, (long)REG_BADPAT); | ||
| 199 | status = 1; | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | /* | ||
| 204 | - try - try it, and report on problems | ||
| 205 | == void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); | ||
| 206 | */ | ||
| 207 | void | ||
| 208 | try(f0, f1, f2, f3, f4, opts) | ||
| 209 | char *f0; | ||
| 210 | char *f1; | ||
| 211 | char *f2; | ||
| 212 | char *f3; | ||
| 213 | char *f4; | ||
| 214 | int opts; /* may not match f1 */ | ||
| 215 | { | ||
| 216 | regex_t re; | ||
| 217 | # define NSUBS 10 | ||
| 218 | regmatch_t subs[NSUBS]; | ||
| 219 | # define NSHOULD 15 | ||
| 220 | char *should[NSHOULD]; | ||
| 221 | int nshould; | ||
| 222 | char erbuf[100]; | ||
| 223 | int err; | ||
| 224 | int len; | ||
| 225 | char *type = (opts & REG_EXTENDED) ? "ERE" : "BRE"; | ||
| 226 | register int i; | ||
| 227 | char *grump; | ||
| 228 | char f0copy[1000]; | ||
| 229 | char f2copy[1000]; | ||
| 230 | |||
| 231 | strlcpy(f0copy, f0, sizeof f0copy); | ||
| 232 | re.re_endp = (opts®_PEND) ? f0copy + strlen(f0copy) : NULL; | ||
| 233 | fixstr(f0copy); | ||
| 234 | err = regcomp(&re, f0copy, opts); | ||
| 235 | if (err != 0 && (!opt('C', f1) || err != efind(f2))) { | ||
| 236 | /* unexpected error or wrong error */ | ||
| 237 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
| 238 | fprintf(stderr, "%d: %s error %s, %d/%zu `%s'\n", | ||
| 239 | line, type, eprint(err), len, | ||
| 240 | sizeof(erbuf), erbuf); | ||
| 241 | status = 1; | ||
| 242 | } else if (err == 0 && opt('C', f1)) { | ||
| 243 | /* unexpected success */ | ||
| 244 | fprintf(stderr, "%d: %s should have given REG_%s\n", | ||
| 245 | line, type, f2); | ||
| 246 | status = 1; | ||
| 247 | err = 1; /* so we won't try regexec */ | ||
| 248 | } | ||
| 249 | |||
| 250 | if (err != 0) { | ||
| 251 | regfree(&re); | ||
| 252 | return; | ||
| 253 | } | ||
| 254 | |||
| 255 | strlcpy(f2copy, f2, sizeof f2copy); | ||
| 256 | fixstr(f2copy); | ||
| 257 | |||
| 258 | if (options('e', f1)®_STARTEND) { | ||
| 259 | if (strchr(f2, '(') == NULL || strchr(f2, ')') == NULL) | ||
| 260 | fprintf(stderr, "%d: bad STARTEND syntax\n", line); | ||
| 261 | subs[0].rm_so = strchr(f2, '(') - f2 + 1; | ||
| 262 | subs[0].rm_eo = strchr(f2, ')') - f2; | ||
| 263 | } | ||
| 264 | err = regexec(&re, f2copy, NSUBS, subs, options('e', f1)); | ||
| 265 | |||
| 266 | if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) { | ||
| 267 | /* unexpected error or wrong error */ | ||
| 268 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
| 269 | fprintf(stderr, "%d: %s exec error %s, %d/%zu `%s'\n", | ||
| 270 | line, type, eprint(err), len, | ||
| 271 | sizeof(erbuf), erbuf); | ||
| 272 | status = 1; | ||
| 273 | } else if (err != 0) { | ||
| 274 | /* nothing more to check */ | ||
| 275 | } else if (f3 == NULL) { | ||
| 276 | /* unexpected success */ | ||
| 277 | fprintf(stderr, "%d: %s exec should have failed\n", | ||
| 278 | line, type); | ||
| 279 | status = 1; | ||
| 280 | err = 1; /* just on principle */ | ||
| 281 | } else if (opts®_NOSUB) { | ||
| 282 | /* nothing more to check */ | ||
| 283 | } else if ((grump = check(f2, subs[0], f3)) != NULL) { | ||
| 284 | fprintf(stderr, "%d: %s %s\n", line, type, grump); | ||
| 285 | status = 1; | ||
| 286 | err = 1; | ||
| 287 | } | ||
| 288 | |||
| 289 | if (err != 0 || f4 == NULL) { | ||
| 290 | regfree(&re); | ||
| 291 | return; | ||
| 292 | } | ||
| 293 | |||
| 294 | for (i = 1; i < NSHOULD; i++) | ||
| 295 | should[i] = NULL; | ||
| 296 | nshould = split(f4, should+1, NSHOULD-1, ","); | ||
| 297 | if (nshould == 0) { | ||
| 298 | nshould = 1; | ||
| 299 | should[1] = ""; | ||
| 300 | } | ||
| 301 | for (i = 1; i < NSUBS; i++) { | ||
| 302 | grump = check(f2, subs[i], should[i]); | ||
| 303 | if (grump != NULL) { | ||
| 304 | fprintf(stderr, "%d: %s $%d %s\n", line, | ||
| 305 | type, i, grump); | ||
| 306 | status = 1; | ||
| 307 | err = 1; | ||
| 308 | } | ||
| 309 | } | ||
| 310 | |||
| 311 | regfree(&re); | ||
| 312 | } | ||
| 313 | |||
| 314 | /* | ||
| 315 | - options - pick options out of a regression-test string | ||
| 316 | == int options(int type, char *s); | ||
| 317 | */ | ||
| 318 | int | ||
| 319 | options(type, s) | ||
| 320 | int type; /* 'c' compile, 'e' exec */ | ||
| 321 | char *s; | ||
| 322 | { | ||
| 323 | register char *p; | ||
| 324 | register int o = (type == 'c') ? copts : eopts; | ||
| 325 | register char *legal = (type == 'c') ? "bisnmp" : "^$#tl"; | ||
| 326 | |||
| 327 | for (p = s; *p != '\0'; p++) | ||
| 328 | if (strchr(legal, *p) != NULL) | ||
| 329 | switch (*p) { | ||
| 330 | case 'b': | ||
| 331 | o &= ~REG_EXTENDED; | ||
| 332 | break; | ||
| 333 | case 'i': | ||
| 334 | o |= REG_ICASE; | ||
| 335 | break; | ||
| 336 | case 's': | ||
| 337 | o |= REG_NOSUB; | ||
| 338 | break; | ||
| 339 | case 'n': | ||
| 340 | o |= REG_NEWLINE; | ||
| 341 | break; | ||
| 342 | case 'm': | ||
| 343 | o &= ~REG_EXTENDED; | ||
| 344 | o |= REG_NOSPEC; | ||
| 345 | break; | ||
| 346 | case 'p': | ||
| 347 | o |= REG_PEND; | ||
| 348 | break; | ||
| 349 | case '^': | ||
| 350 | o |= REG_NOTBOL; | ||
| 351 | break; | ||
| 352 | case '$': | ||
| 353 | o |= REG_NOTEOL; | ||
| 354 | break; | ||
| 355 | case '#': | ||
| 356 | o |= REG_STARTEND; | ||
| 357 | break; | ||
| 358 | case 't': /* trace */ | ||
| 359 | o |= REG_TRACE; | ||
| 360 | break; | ||
| 361 | case 'l': /* force long representation */ | ||
| 362 | o |= REG_LARGE; | ||
| 363 | break; | ||
| 364 | case 'r': /* force backref use */ | ||
| 365 | o |= REG_BACKR; | ||
| 366 | break; | ||
| 367 | } | ||
| 368 | return(o); | ||
| 369 | } | ||
| 370 | |||
| 371 | /* | ||
| 372 | - opt - is a particular option in a regression string? | ||
| 373 | == int opt(int c, char *s); | ||
| 374 | */ | ||
| 375 | int /* predicate */ | ||
| 376 | opt(c, s) | ||
| 377 | int c; | ||
| 378 | char *s; | ||
| 379 | { | ||
| 380 | return(strchr(s, c) != NULL); | ||
| 381 | } | ||
| 382 | |||
| 383 | /* | ||
| 384 | - fixstr - transform magic characters in strings | ||
| 385 | == void fixstr(register char *p); | ||
| 386 | */ | ||
| 387 | void | ||
| 388 | fixstr(p) | ||
| 389 | register char *p; | ||
| 390 | { | ||
| 391 | if (p == NULL) | ||
| 392 | return; | ||
| 393 | |||
| 394 | for (; *p != '\0'; p++) | ||
| 395 | if (*p == 'N') | ||
| 396 | *p = '\n'; | ||
| 397 | else if (*p == 'T') | ||
| 398 | *p = '\t'; | ||
| 399 | else if (*p == 'S') | ||
| 400 | *p = ' '; | ||
| 401 | else if (*p == 'Z') | ||
| 402 | *p = '\0'; | ||
| 403 | } | ||
| 404 | |||
| 405 | /* | ||
| 406 | - check - check a substring match | ||
| 407 | == char *check(char *str, regmatch_t sub, char *should); | ||
| 408 | */ | ||
| 409 | char * /* NULL or complaint */ | ||
| 410 | check(str, sub, should) | ||
| 411 | char *str; | ||
| 412 | regmatch_t sub; | ||
| 413 | char *should; | ||
| 414 | { | ||
| 415 | register int len; | ||
| 416 | register int shlen; | ||
| 417 | register char *p; | ||
| 418 | static char grump[500]; | ||
| 419 | register char *at = NULL; | ||
| 420 | |||
| 421 | if (should != NULL && strcmp(should, "-") == 0) | ||
| 422 | should = NULL; | ||
| 423 | if (should != NULL && should[0] == '@') { | ||
| 424 | at = should + 1; | ||
| 425 | should = ""; | ||
| 426 | } | ||
| 427 | |||
| 428 | /* check rm_so and rm_eo for consistency */ | ||
| 429 | if (sub.rm_so > sub.rm_eo || (sub.rm_so == -1 && sub.rm_eo != -1) || | ||
| 430 | (sub.rm_so != -1 && sub.rm_eo == -1) || | ||
| 431 | (sub.rm_so != -1 && sub.rm_so < 0) || | ||
| 432 | (sub.rm_eo != -1 && sub.rm_eo < 0) ) { | ||
| 433 | snprintf(grump, sizeof grump, | ||
| 434 | "start %ld end %ld", (long)sub.rm_so, | ||
| 435 | (long)sub.rm_eo); | ||
| 436 | return(grump); | ||
| 437 | } | ||
| 438 | |||
| 439 | /* check for no match */ | ||
| 440 | if (sub.rm_so == -1 && should == NULL) | ||
| 441 | return(NULL); | ||
| 442 | if (sub.rm_so == -1) | ||
| 443 | return("did not match"); | ||
| 444 | |||
| 445 | /* check for in range */ | ||
| 446 | if (sub.rm_eo > strlen(str)) { | ||
| 447 | snprintf(grump, sizeof grump, | ||
| 448 | "start %ld end %ld, past end of string", | ||
| 449 | (long)sub.rm_so, (long)sub.rm_eo); | ||
| 450 | return(grump); | ||
| 451 | } | ||
| 452 | |||
| 453 | len = (int)(sub.rm_eo - sub.rm_so); | ||
| 454 | shlen = (int)strlen(should); | ||
| 455 | p = str + sub.rm_so; | ||
| 456 | |||
| 457 | /* check for not supposed to match */ | ||
| 458 | if (should == NULL) { | ||
| 459 | snprintf(grump, sizeof grump, "matched `%.*s'", len, p); | ||
| 460 | return(grump); | ||
| 461 | } | ||
| 462 | |||
| 463 | /* check for wrong match */ | ||
| 464 | if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { | ||
| 465 | snprintf(grump, sizeof grump, "matched `%.*s' instead", len, p); | ||
| 466 | return(grump); | ||
| 467 | } | ||
| 468 | if (shlen > 0) | ||
| 469 | return(NULL); | ||
| 470 | |||
| 471 | /* check null match in right place */ | ||
| 472 | if (at == NULL) | ||
| 473 | return(NULL); | ||
| 474 | shlen = strlen(at); | ||
| 475 | if (shlen == 0) | ||
| 476 | shlen = 1; /* force check for end-of-string */ | ||
| 477 | if (strncmp(p, at, shlen) != 0) { | ||
| 478 | snprintf(grump, sizeof grump, "matched null at `%.20s'", p); | ||
| 479 | return(grump); | ||
| 480 | } | ||
| 481 | return(NULL); | ||
| 482 | } | ||
| 483 | |||
| 484 | /* | ||
| 485 | - eprint - convert error number to name | ||
| 486 | == static char *eprint(int err); | ||
| 487 | */ | ||
| 488 | static char * | ||
| 489 | eprint(err) | ||
| 490 | int err; | ||
| 491 | { | ||
| 492 | static char epbuf[100]; | ||
| 493 | size_t len; | ||
| 494 | |||
| 495 | len = regerror(REG_ITOA|err, (regex_t *)NULL, epbuf, sizeof(epbuf)); | ||
| 496 | assert(len <= sizeof(epbuf)); | ||
| 497 | return(epbuf); | ||
| 498 | } | ||
| 499 | |||
| 500 | /* | ||
| 501 | - efind - convert error name to number | ||
| 502 | == static int efind(char *name); | ||
| 503 | */ | ||
| 504 | static int | ||
| 505 | efind(name) | ||
| 506 | char *name; | ||
| 507 | { | ||
| 508 | static char efbuf[100]; | ||
| 509 | regex_t re; | ||
| 510 | |||
| 511 | snprintf(efbuf, sizeof efbuf, "REG_%s", name); | ||
| 512 | assert(strlen(efbuf) < sizeof(efbuf)); | ||
| 513 | re.re_endp = efbuf; | ||
| 514 | (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf)); | ||
| 515 | return(atoi(efbuf)); | ||
| 516 | } | ||
diff --git a/src/regress/lib/libc/regex/main.ih b/src/regress/lib/libc/regex/main.ih new file mode 100644 index 0000000000..0860e26333 --- /dev/null +++ b/src/regress/lib/libc/regex/main.ih | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | /* $OpenBSD: main.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
| 2 | /* $NetBSD: main.ih,v 1.2 1995/04/20 22:39:55 cgd Exp $ */ | ||
| 3 | |||
| 4 | /* ========= begin header generated by ./mkh ========= */ | ||
| 5 | #ifdef __cplusplus | ||
| 6 | extern "C" { | ||
| 7 | #endif | ||
| 8 | |||
| 9 | /* === main.c === */ | ||
| 10 | void regress(FILE *in); | ||
| 11 | void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); | ||
| 12 | int options(int type, char *s); | ||
| 13 | int opt(int c, char *s); | ||
| 14 | void fixstr(register char *p); | ||
| 15 | char *check(char *str, regmatch_t sub, char *should); | ||
| 16 | static char *eprint(int err); | ||
| 17 | static int efind(char *name); | ||
| 18 | |||
| 19 | #ifdef __cplusplus | ||
| 20 | } | ||
| 21 | #endif | ||
| 22 | /* ========= end header generated by ./mkh ========= */ | ||
diff --git a/src/regress/lib/libc/regex/split.c b/src/regress/lib/libc/regex/split.c new file mode 100644 index 0000000000..fcd81a3503 --- /dev/null +++ b/src/regress/lib/libc/regex/split.c | |||
| @@ -0,0 +1,317 @@ | |||
| 1 | /* $OpenBSD: split.c,v 1.5 2007/09/09 23:25:12 chl Exp $ */ | ||
| 2 | /* $NetBSD: split.c,v 1.2 1995/04/20 22:39:57 cgd Exp $ */ | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | #include <string.h> | ||
| 6 | |||
| 7 | int split(char *string, char *fields[], int nfields, char *sep); | ||
| 8 | |||
| 9 | /* | ||
| 10 | - split - divide a string into fields, like awk split() | ||
| 11 | = int split(char *string, char *fields[], int nfields, char *sep); | ||
| 12 | */ | ||
| 13 | int /* number of fields, including overflow */ | ||
| 14 | split(char *string, char *fields[], int nfields, char *sep) | ||
| 15 | { | ||
| 16 | register char *p = string; | ||
| 17 | register char c; /* latest character */ | ||
| 18 | register char sepc = sep[0]; | ||
| 19 | register char sepc2; | ||
| 20 | register int fn; | ||
| 21 | register char **fp = fields; | ||
| 22 | register char *sepp; | ||
| 23 | register int trimtrail; | ||
| 24 | |||
| 25 | /* white space */ | ||
| 26 | if (sepc == '\0') { | ||
| 27 | while ((c = *p++) == ' ' || c == '\t') | ||
| 28 | continue; | ||
| 29 | p--; | ||
| 30 | trimtrail = 1; | ||
| 31 | sep = " \t"; /* note, code below knows this is 2 long */ | ||
| 32 | sepc = ' '; | ||
| 33 | } else | ||
| 34 | trimtrail = 0; | ||
| 35 | sepc2 = sep[1]; /* now we can safely pick this up */ | ||
| 36 | |||
| 37 | /* catch empties */ | ||
| 38 | if (*p == '\0') | ||
| 39 | return(0); | ||
| 40 | |||
| 41 | /* single separator */ | ||
| 42 | if (sepc2 == '\0') { | ||
| 43 | fn = nfields; | ||
| 44 | for (;;) { | ||
| 45 | *fp++ = p; | ||
| 46 | fn--; | ||
| 47 | if (fn == 0) | ||
| 48 | break; | ||
| 49 | while ((c = *p++) != sepc) | ||
| 50 | if (c == '\0') | ||
| 51 | return(nfields - fn); | ||
| 52 | *(p-1) = '\0'; | ||
| 53 | } | ||
| 54 | /* we have overflowed the fields vector -- just count them */ | ||
| 55 | fn = nfields; | ||
| 56 | for (;;) { | ||
| 57 | while ((c = *p++) != sepc) | ||
| 58 | if (c == '\0') | ||
| 59 | return(fn); | ||
| 60 | fn++; | ||
| 61 | } | ||
| 62 | /* not reached */ | ||
| 63 | } | ||
| 64 | |||
| 65 | /* two separators */ | ||
| 66 | if (sep[2] == '\0') { | ||
| 67 | fn = nfields; | ||
| 68 | for (;;) { | ||
| 69 | *fp++ = p; | ||
| 70 | fn--; | ||
| 71 | while ((c = *p++) != sepc && c != sepc2) | ||
| 72 | if (c == '\0') { | ||
| 73 | if (trimtrail && **(fp-1) == '\0') | ||
| 74 | fn++; | ||
| 75 | return(nfields - fn); | ||
| 76 | } | ||
| 77 | if (fn == 0) | ||
| 78 | break; | ||
| 79 | *(p-1) = '\0'; | ||
| 80 | while ((c = *p++) == sepc || c == sepc2) | ||
| 81 | continue; | ||
| 82 | p--; | ||
| 83 | } | ||
| 84 | /* we have overflowed the fields vector -- just count them */ | ||
| 85 | fn = nfields; | ||
| 86 | while (c != '\0') { | ||
| 87 | while ((c = *p++) == sepc || c == sepc2) | ||
| 88 | continue; | ||
| 89 | p--; | ||
| 90 | fn++; | ||
| 91 | while ((c = *p++) != '\0' && c != sepc && c != sepc2) | ||
| 92 | continue; | ||
| 93 | } | ||
| 94 | /* might have to trim trailing white space */ | ||
| 95 | if (trimtrail) { | ||
| 96 | p--; | ||
| 97 | while ((c = *--p) == sepc || c == sepc2) | ||
| 98 | continue; | ||
| 99 | p++; | ||
| 100 | if (*p != '\0') { | ||
| 101 | if (fn == nfields+1) | ||
| 102 | *p = '\0'; | ||
| 103 | fn--; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | return(fn); | ||
| 107 | } | ||
| 108 | |||
| 109 | /* n separators */ | ||
| 110 | fn = 0; | ||
| 111 | for (;;) { | ||
| 112 | if (fn < nfields) | ||
| 113 | *fp++ = p; | ||
| 114 | fn++; | ||
| 115 | for (;;) { | ||
| 116 | c = *p++; | ||
| 117 | if (c == '\0') | ||
| 118 | return(fn); | ||
| 119 | sepp = sep; | ||
| 120 | while ((sepc = *sepp++) != '\0' && sepc != c) | ||
| 121 | continue; | ||
| 122 | if (sepc != '\0') /* it was a separator */ | ||
| 123 | break; | ||
| 124 | } | ||
| 125 | if (fn < nfields) | ||
| 126 | *(p-1) = '\0'; | ||
| 127 | for (;;) { | ||
| 128 | c = *p++; | ||
| 129 | sepp = sep; | ||
| 130 | while ((sepc = *sepp++) != '\0' && sepc != c) | ||
| 131 | continue; | ||
| 132 | if (sepc == '\0') /* it wasn't a separator */ | ||
| 133 | break; | ||
| 134 | } | ||
| 135 | p--; | ||
| 136 | } | ||
| 137 | |||
| 138 | /* not reached */ | ||
| 139 | } | ||
| 140 | |||
| 141 | #ifdef TEST_SPLIT | ||
| 142 | |||
| 143 | |||
| 144 | /* | ||
| 145 | * test program | ||
| 146 | * pgm runs regression | ||
| 147 | * pgm sep splits stdin lines by sep | ||
| 148 | * pgm str sep splits str by sep | ||
| 149 | * pgm str sep n splits str by sep n times | ||
| 150 | */ | ||
| 151 | int | ||
| 152 | main(argc, argv) | ||
| 153 | int argc; | ||
| 154 | char *argv[]; | ||
| 155 | { | ||
| 156 | char buf[512]; | ||
| 157 | register int n; | ||
| 158 | # define MNF 10 | ||
| 159 | char *fields[MNF]; | ||
| 160 | |||
| 161 | if (argc > 4) | ||
| 162 | for (n = atoi(argv[3]); n > 0; n--) { | ||
| 163 | (void) strlcpy(buf, argv[1], sizeof buf); | ||
| 164 | } | ||
| 165 | else if (argc > 3) | ||
| 166 | for (n = atoi(argv[3]); n > 0; n--) { | ||
| 167 | (void) strlcpy(buf, argv[1], sizeof buf); | ||
| 168 | (void) split(buf, fields, MNF, argv[2]); | ||
| 169 | } | ||
| 170 | else if (argc > 2) | ||
| 171 | dosplit(argv[1], argv[2]); | ||
| 172 | else if (argc > 1) | ||
| 173 | while (fgets(buf, sizeof(buf), stdin) != NULL) { | ||
| 174 | buf[strcspn(buf, "\n")] = '\0'; /* stomp newline */ | ||
| 175 | dosplit(buf, argv[1]); | ||
| 176 | } | ||
| 177 | else | ||
| 178 | regress(); | ||
| 179 | |||
| 180 | exit(0); | ||
| 181 | } | ||
| 182 | |||
| 183 | dosplit(string, seps) | ||
| 184 | char *string; | ||
| 185 | char *seps; | ||
| 186 | { | ||
| 187 | # define NF 5 | ||
| 188 | char *fields[NF]; | ||
| 189 | register int nf; | ||
| 190 | |||
| 191 | nf = split(string, fields, NF, seps); | ||
| 192 | print(nf, NF, fields); | ||
| 193 | } | ||
| 194 | |||
| 195 | print(nf, nfp, fields) | ||
| 196 | int nf; | ||
| 197 | int nfp; | ||
| 198 | char *fields[]; | ||
| 199 | { | ||
| 200 | register int fn; | ||
| 201 | register int bound; | ||
| 202 | |||
| 203 | bound = (nf > nfp) ? nfp : nf; | ||
| 204 | printf("%d:\t", nf); | ||
| 205 | for (fn = 0; fn < bound; fn++) | ||
| 206 | printf("\"%s\"%s", fields[fn], (fn+1 < nf) ? ", " : "\n"); | ||
| 207 | } | ||
| 208 | |||
| 209 | #define RNF 5 /* some table entries know this */ | ||
| 210 | struct { | ||
| 211 | char *str; | ||
| 212 | char *seps; | ||
| 213 | int nf; | ||
| 214 | char *fi[RNF]; | ||
| 215 | } tests[] = { | ||
| 216 | "", " ", 0, { "" }, | ||
| 217 | " ", " ", 2, { "", "" }, | ||
| 218 | "x", " ", 1, { "x" }, | ||
| 219 | "xy", " ", 1, { "xy" }, | ||
| 220 | "x y", " ", 2, { "x", "y" }, | ||
| 221 | "abc def g ", " ", 5, { "abc", "def", "", "g", "" }, | ||
| 222 | " a bcd", " ", 4, { "", "", "a", "bcd" }, | ||
| 223 | "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" }, | ||
| 224 | " a b c d ", " ", 6, { "", "a", "b", "c", "d " }, | ||
| 225 | |||
| 226 | "", " _", 0, { "" }, | ||
| 227 | " ", " _", 2, { "", "" }, | ||
| 228 | "x", " _", 1, { "x" }, | ||
| 229 | "x y", " _", 2, { "x", "y" }, | ||
| 230 | "ab _ cd", " _", 2, { "ab", "cd" }, | ||
| 231 | " a_b c ", " _", 5, { "", "a", "b", "c", "" }, | ||
| 232 | "a b c_d e f", " _", 6, { "a", "b", "c", "d", "e f" }, | ||
| 233 | " a b c d ", " _", 6, { "", "a", "b", "c", "d " }, | ||
| 234 | |||
| 235 | "", " _~", 0, { "" }, | ||
| 236 | " ", " _~", 2, { "", "" }, | ||
| 237 | "x", " _~", 1, { "x" }, | ||
| 238 | "x y", " _~", 2, { "x", "y" }, | ||
| 239 | "ab _~ cd", " _~", 2, { "ab", "cd" }, | ||
| 240 | " a_b c~", " _~", 5, { "", "a", "b", "c", "" }, | ||
| 241 | "a b_c d~e f", " _~", 6, { "a", "b", "c", "d", "e f" }, | ||
| 242 | "~a b c d ", " _~", 6, { "", "a", "b", "c", "d " }, | ||
| 243 | |||
| 244 | "", " _~-", 0, { "" }, | ||
| 245 | " ", " _~-", 2, { "", "" }, | ||
| 246 | "x", " _~-", 1, { "x" }, | ||
| 247 | "x y", " _~-", 2, { "x", "y" }, | ||
| 248 | "ab _~- cd", " _~-", 2, { "ab", "cd" }, | ||
| 249 | " a_b c~", " _~-", 5, { "", "a", "b", "c", "" }, | ||
| 250 | "a b_c-d~e f", " _~-", 6, { "a", "b", "c", "d", "e f" }, | ||
| 251 | "~a-b c d ", " _~-", 6, { "", "a", "b", "c", "d " }, | ||
| 252 | |||
| 253 | "", " ", 0, { "" }, | ||
| 254 | " ", " ", 2, { "", "" }, | ||
| 255 | "x", " ", 1, { "x" }, | ||
| 256 | "xy", " ", 1, { "xy" }, | ||
| 257 | "x y", " ", 2, { "x", "y" }, | ||
| 258 | "abc def g ", " ", 4, { "abc", "def", "g", "" }, | ||
| 259 | " a bcd", " ", 3, { "", "a", "bcd" }, | ||
| 260 | "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" }, | ||
| 261 | " a b c d ", " ", 6, { "", "a", "b", "c", "d " }, | ||
| 262 | |||
| 263 | "", "", 0, { "" }, | ||
| 264 | " ", "", 0, { "" }, | ||
| 265 | "x", "", 1, { "x" }, | ||
| 266 | "xy", "", 1, { "xy" }, | ||
| 267 | "x y", "", 2, { "x", "y" }, | ||
| 268 | "abc def g ", "", 3, { "abc", "def", "g" }, | ||
| 269 | "\t a bcd", "", 2, { "a", "bcd" }, | ||
| 270 | " a \tb\t c ", "", 3, { "a", "b", "c" }, | ||
| 271 | "a b c d e ", "", 5, { "a", "b", "c", "d", "e" }, | ||
| 272 | "a b\tc d e f", "", 6, { "a", "b", "c", "d", "e f" }, | ||
| 273 | " a b c d e f ", "", 6, { "a", "b", "c", "d", "e f " }, | ||
| 274 | |||
| 275 | NULL, NULL, 0, { NULL }, | ||
| 276 | }; | ||
| 277 | |||
| 278 | regress() | ||
| 279 | { | ||
| 280 | char buf[512]; | ||
| 281 | register int n; | ||
| 282 | char *fields[RNF+1]; | ||
| 283 | register int nf; | ||
| 284 | register int i; | ||
| 285 | register int printit; | ||
| 286 | register char *f; | ||
| 287 | |||
| 288 | for (n = 0; tests[n].str != NULL; n++) { | ||
| 289 | (void) strlcpy(buf, tests[n].str, sizeof buf); | ||
| 290 | fields[RNF] = NULL; | ||
| 291 | nf = split(buf, fields, RNF, tests[n].seps); | ||
| 292 | printit = 0; | ||
| 293 | if (nf != tests[n].nf) { | ||
| 294 | printf("split `%s' by `%s' gave %d fields, not %d\n", | ||
| 295 | tests[n].str, tests[n].seps, nf, tests[n].nf); | ||
| 296 | printit = 1; | ||
| 297 | } else if (fields[RNF] != NULL) { | ||
| 298 | printf("split() went beyond array end\n"); | ||
| 299 | printit = 1; | ||
| 300 | } else { | ||
| 301 | for (i = 0; i < nf && i < RNF; i++) { | ||
| 302 | f = fields[i]; | ||
| 303 | if (f == NULL) | ||
| 304 | f = "(NULL)"; | ||
| 305 | if (strcmp(f, tests[n].fi[i]) != 0) { | ||
| 306 | printf("split `%s' by `%s', field %d is `%s', not `%s'\n", | ||
| 307 | tests[n].str, tests[n].seps, | ||
| 308 | i, fields[i], tests[n].fi[i]); | ||
| 309 | printit = 1; | ||
| 310 | } | ||
| 311 | } | ||
| 312 | } | ||
| 313 | if (printit) | ||
| 314 | print(nf, RNF, fields); | ||
| 315 | } | ||
| 316 | } | ||
| 317 | #endif | ||
diff --git a/src/regress/lib/libc/regex/tests b/src/regress/lib/libc/regex/tests new file mode 100644 index 0000000000..c827c868b7 --- /dev/null +++ b/src/regress/lib/libc/regex/tests | |||
| @@ -0,0 +1,503 @@ | |||
| 1 | # $OpenBSD: tests,v 1.5 2004/11/29 16:50:31 otto Exp $ | ||
| 2 | # $NetBSD: tests,v 1.5 1995/04/20 22:40:00 cgd Exp $ | ||
| 3 | |||
| 4 | # regular expression test set | ||
| 5 | # Lines are at least three fields, separated by one or more tabs. "" stands | ||
| 6 | # for an empty field. First field is an RE. Second field is flags. If | ||
| 7 | # C flag given, regcomp() is expected to fail, and the third field is the | ||
| 8 | # error name (minus the leading REG_). | ||
| 9 | # | ||
| 10 | # Otherwise it is expected to succeed, and the third field is the string to | ||
| 11 | # try matching it against. If there is no fourth field, the match is | ||
| 12 | # expected to fail. If there is a fourth field, it is the substring that | ||
| 13 | # the RE is expected to match. If there is a fifth field, it is a comma- | ||
| 14 | # separated list of what the subexpressions should match, with - indicating | ||
| 15 | # no match for that one. In both the fourth and fifth fields, a (sub)field | ||
| 16 | # starting with @ indicates that the (sub)expression is expected to match | ||
| 17 | # a null string followed by the stuff after the @; this provides a way to | ||
| 18 | # test where null strings match. The character `N' in REs and strings | ||
| 19 | # is newline, `S' is space, `T' is tab, `Z' is NUL. | ||
| 20 | # | ||
| 21 | # The full list of flags: | ||
| 22 | # - placeholder, does nothing | ||
| 23 | # b RE is a BRE, not an ERE | ||
| 24 | # & try it as both an ERE and a BRE | ||
| 25 | # C regcomp() error expected, third field is error name | ||
| 26 | # i REG_ICASE | ||
| 27 | # m ("mundane") REG_NOSPEC | ||
| 28 | # s REG_NOSUB (not really testable) | ||
| 29 | # n REG_NEWLINE | ||
| 30 | # ^ REG_NOTBOL | ||
| 31 | # $ REG_NOTEOL | ||
| 32 | # # REG_STARTEND (see below) | ||
| 33 | # p REG_PEND | ||
| 34 | # | ||
| 35 | # For REG_STARTEND, the start/end offsets are those of the substring | ||
| 36 | # enclosed in (). | ||
| 37 | |||
| 38 | # basics | ||
| 39 | a & a a | ||
| 40 | abc & abc abc | ||
| 41 | abc|de - abc abc | ||
| 42 | a|b|c - abc a | ||
| 43 | |||
| 44 | # parentheses and perversions thereof | ||
| 45 | a(b)c - abc abc | ||
| 46 | a\(b\)c b abc abc | ||
| 47 | a( C EPAREN | ||
| 48 | a( b a( a( | ||
| 49 | a\( - a( a( | ||
| 50 | a\( bC EPAREN | ||
| 51 | a\(b bC EPAREN | ||
| 52 | a(b C EPAREN | ||
| 53 | a(b b a(b a(b | ||
| 54 | # gag me with a right parenthesis -- 1003.2 goofed here (my fault, partly) | ||
| 55 | a) - a) a) | ||
| 56 | ) - ) ) | ||
| 57 | # end gagging (in a just world, those *should* give EPAREN) | ||
| 58 | a) b a) a) | ||
| 59 | a\) bC EPAREN | ||
| 60 | \) bC EPAREN | ||
| 61 | a()b - ab ab | ||
| 62 | a\(\)b b ab ab | ||
| 63 | |||
| 64 | # anchoring and REG_NEWLINE | ||
| 65 | ^abc$ & abc abc | ||
| 66 | a^b - a^b | ||
| 67 | a^b b a^b a^b | ||
| 68 | a$b - a$b | ||
| 69 | a$b b a$b a$b | ||
| 70 | ^ & abc @abc | ||
| 71 | $ & abc @ | ||
| 72 | ^$ & "" @ | ||
| 73 | $^ - "" @ | ||
| 74 | \($\)\(^\) b "" @ | ||
| 75 | # stop retching, those are legitimate (although disgusting) | ||
| 76 | ^^ - "" @ | ||
| 77 | $$ - "" @ | ||
| 78 | b$ & abNc | ||
| 79 | b$ &n abNc b | ||
| 80 | ^b$ & aNbNc | ||
| 81 | ^b$ &n aNbNc b | ||
| 82 | ^$ &n aNNb @Nb | ||
| 83 | ^$ n abc | ||
| 84 | ^$ n abcN @ | ||
| 85 | $^ n aNNb @Nb | ||
| 86 | \($\)\(^\) bn aNNb @Nb | ||
| 87 | ^^ n^ aNNb @Nb | ||
| 88 | $$ n aNNb @NN | ||
| 89 | ^a ^ a | ||
| 90 | a$ $ a | ||
| 91 | ^a ^n aNb | ||
| 92 | ^b ^n aNb b | ||
| 93 | a$ $n bNa | ||
| 94 | b$ $n bNa b | ||
| 95 | a*(^b$)c* - b b | ||
| 96 | a*\(^b$\)c* b b b | ||
| 97 | |||
| 98 | # certain syntax errors and non-errors | ||
| 99 | | C EMPTY | ||
| 100 | | b | | | ||
| 101 | * C BADRPT | ||
| 102 | * b * * | ||
| 103 | + C BADRPT | ||
| 104 | ? C BADRPT | ||
| 105 | "" &C EMPTY | ||
| 106 | () - abc @abc | ||
| 107 | \(\) b abc @abc | ||
| 108 | a||b C EMPTY | ||
| 109 | |ab C EMPTY | ||
| 110 | ab| C EMPTY | ||
| 111 | (|a)b C EMPTY | ||
| 112 | (a|)b C EMPTY | ||
| 113 | (*a) C BADRPT | ||
| 114 | (+a) C BADRPT | ||
| 115 | (?a) C BADRPT | ||
| 116 | ({1}a) C BADRPT | ||
| 117 | \(\{1\}a\) bC BADRPT | ||
| 118 | (a|*b) C BADRPT | ||
| 119 | (a|+b) C BADRPT | ||
| 120 | (a|?b) C BADRPT | ||
| 121 | (a|{1}b) C BADRPT | ||
| 122 | ^* C BADRPT | ||
| 123 | ^* b * * | ||
| 124 | ^+ C BADRPT | ||
| 125 | ^? C BADRPT | ||
| 126 | ^{1} C BADRPT | ||
| 127 | ^\{1\} bC BADRPT | ||
| 128 | |||
| 129 | # metacharacters, backslashes | ||
| 130 | a.c & abc abc | ||
| 131 | a[bc]d & abd abd | ||
| 132 | a\*c & a*c a*c | ||
| 133 | a\\b & a\b a\b | ||
| 134 | a\\\*b & a\*b a\*b | ||
| 135 | a\bc & abc abc | ||
| 136 | a\ &C EESCAPE | ||
| 137 | a\\bc & a\bc a\bc | ||
| 138 | \{ bC BADRPT | ||
| 139 | a\[b & a[b a[b | ||
| 140 | a[b &C EBRACK | ||
| 141 | # trailing $ is a peculiar special case for the BRE code | ||
| 142 | a$ & a a | ||
| 143 | a$ & a$ | ||
| 144 | a\$ & a | ||
| 145 | a\$ & a$ a$ | ||
| 146 | a\\$ & a | ||
| 147 | a\\$ & a$ | ||
| 148 | a\\$ & a\$ | ||
| 149 | a\\$ & a\ a\ | ||
| 150 | |||
| 151 | # back references, ugh | ||
| 152 | a\(b\)\2c bC ESUBREG | ||
| 153 | a\(b\1\)c bC ESUBREG | ||
| 154 | a\(b*\)c\1d b abbcbbd abbcbbd bb | ||
| 155 | a\(b*\)c\1d b abbcbd | ||
| 156 | a\(b*\)c\1d b abbcbbbd | ||
| 157 | ^\(.\)\1 b abc | ||
| 158 | a\([bc]\)\1d b abcdabbd abbd b | ||
| 159 | a\(\([bc]\)\2\)*d b abbccd abbccd | ||
| 160 | a\(\([bc]\)\2\)*d b abbcbd | ||
| 161 | # actually, this next one probably ought to fail, but the spec is unclear | ||
| 162 | a\(\(b\)*\2\)*d b abbbd abbbd | ||
| 163 | # here is a case that no NFA implementation does right | ||
| 164 | \(ab*\)[ab]*\1 b ababaaa ababaaa a | ||
| 165 | # check out normal matching in the presence of back refs | ||
| 166 | \(a\)\1bcd b aabcd aabcd | ||
| 167 | \(a\)\1bc*d b aabcd aabcd | ||
| 168 | \(a\)\1bc*d b aabd aabd | ||
| 169 | \(a\)\1bc*d b aabcccd aabcccd | ||
| 170 | \(a\)\1bc*[ce]d b aabcccd aabcccd | ||
| 171 | ^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd | ||
| 172 | \(b*\)\(a*\1\)* b ab a | ||
| 173 | \([^_]*\)\(_*\1\)* b foo_foo_bar_bar_bar_baz foo_foo foo,_foo | ||
| 174 | \([^_]*\)\(_*\1\)* b bar_bar_bar_baz bar_bar_bar bar,_bar | ||
| 175 | \([^_]*\)\(_*\1\)* b foo_bar_baz foo foo | ||
| 176 | \(.*\)\1 b "" "" | ||
| 177 | \(.*\)\1 b a "" | ||
| 178 | \(.*\)\1 b aa aa | ||
| 179 | \(.*\)\1 b aaa aa | ||
| 180 | \(.*\)\1 b aaaa aaaa | ||
| 181 | \([^_]*\)\1 b "" "" | ||
| 182 | \([^_]*\)\1 b a "" | ||
| 183 | \([^_]*\)\1 b aa aa | ||
| 184 | \([^_]*\)\1 b aaa aa | ||
| 185 | \([^_]*\)\1 b aaaa aaaa | ||
| 186 | foo\(.*\)bar\1 b foolbarl foolbarl l | ||
| 187 | foo\(.*\)bar\1 b foobar foobar "" | ||
| 188 | \(\(.\)b\)*\1 b aba | ||
| 189 | \(\(.\)b\)*\1 b abba | ||
| 190 | \(\(.\)b\)*\1 b abbba | ||
| 191 | \(\(.\)b\)*\1 b abbbba bbbb bb,b | ||
| 192 | \(\(.\)b\)*\1 b abbbbba abbbbb bb,b | ||
| 193 | \(\(.\)b\)*\1 b abbbbbba abbbbb bb,b | ||
| 194 | \(\(.\)b\)*\1 b abbbbbbbbbbbbbba abbbbbbbbbbbbb bb,b | ||
| 195 | \(\(.\)b\)*\1 b abbbbbbbbbbbbbbba abbbbbbbbbbbbbbb bb,b | ||
| 196 | |||
| 197 | # ordinary repetitions | ||
| 198 | ab*c & abc abc | ||
| 199 | ab+c - abc abc | ||
| 200 | ab?c - abc abc | ||
| 201 | a\(*\)b b a*b a*b | ||
| 202 | a\(**\)b b ab ab | ||
| 203 | a\(***\)b bC BADRPT | ||
| 204 | *a b *a *a | ||
| 205 | **a b a a | ||
| 206 | ***a bC BADRPT | ||
| 207 | |||
| 208 | # the dreaded bounded repetitions | ||
| 209 | { & { { | ||
| 210 | {abc & {abc {abc | ||
| 211 | {1 C BADRPT | ||
| 212 | {1} C BADRPT | ||
| 213 | a{b & a{b a{b | ||
| 214 | a{1}b - ab ab | ||
| 215 | a\{1\}b b ab ab | ||
| 216 | a{1,}b - ab ab | ||
| 217 | a\{1,\}b b ab ab | ||
| 218 | a{1,2}b - aab aab | ||
| 219 | a\{1,2\}b b aab aab | ||
| 220 | a{1 C EBRACE | ||
| 221 | a\{1 bC EBRACE | ||
| 222 | a{1a C EBRACE | ||
| 223 | a\{1a bC EBRACE | ||
| 224 | a{1a} C BADBR | ||
| 225 | a\{1a\} bC BADBR | ||
| 226 | a{,2} - a{,2} a{,2} | ||
| 227 | a\{,2\} bC BADBR | ||
| 228 | a{,} - a{,} a{,} | ||
| 229 | a\{,\} bC BADBR | ||
| 230 | a{1,x} C BADBR | ||
| 231 | a\{1,x\} bC BADBR | ||
| 232 | a{1,x C EBRACE | ||
| 233 | a\{1,x bC EBRACE | ||
| 234 | a{300} C BADBR | ||
| 235 | a\{300\} bC BADBR | ||
| 236 | a{1,0} C BADBR | ||
| 237 | a\{1,0\} bC BADBR | ||
| 238 | ab{0,0}c - abcac ac | ||
| 239 | ab\{0,0\}c b abcac ac | ||
| 240 | ab{0,1}c - abcac abc | ||
| 241 | ab\{0,1\}c b abcac abc | ||
| 242 | ab{0,3}c - abbcac abbc | ||
| 243 | ab\{0,3\}c b abbcac abbc | ||
| 244 | ab{1,1}c - acabc abc | ||
| 245 | ab\{1,1\}c b acabc abc | ||
| 246 | ab{1,3}c - acabc abc | ||
| 247 | ab\{1,3\}c b acabc abc | ||
| 248 | ab{2,2}c - abcabbc abbc | ||
| 249 | ab\{2,2\}c b abcabbc abbc | ||
| 250 | ab{2,4}c - abcabbc abbc | ||
| 251 | ab\{2,4\}c b abcabbc abbc | ||
| 252 | ((a{1,10}){1,10}){1,10} - a a a,a | ||
| 253 | |||
| 254 | # multiple repetitions | ||
| 255 | a** &C BADRPT | ||
| 256 | a++ C BADRPT | ||
| 257 | a?? C BADRPT | ||
| 258 | a*+ C BADRPT | ||
| 259 | a*? C BADRPT | ||
| 260 | a+* C BADRPT | ||
| 261 | a+? C BADRPT | ||
| 262 | a?* C BADRPT | ||
| 263 | a?+ C BADRPT | ||
| 264 | a{1}{1} C BADRPT | ||
| 265 | a*{1} C BADRPT | ||
| 266 | a+{1} C BADRPT | ||
| 267 | a?{1} C BADRPT | ||
| 268 | a{1}* C BADRPT | ||
| 269 | a{1}+ C BADRPT | ||
| 270 | a{1}? C BADRPT | ||
| 271 | a*{b} - a{b} a{b} | ||
| 272 | a\{1\}\{1\} bC BADRPT | ||
| 273 | a*\{1\} bC BADRPT | ||
| 274 | a\{1\}* bC BADRPT | ||
| 275 | |||
| 276 | # brackets, and numerous perversions thereof | ||
| 277 | a[b]c & abc abc | ||
| 278 | a[ab]c & abc abc | ||
| 279 | a[^ab]c & adc adc | ||
| 280 | a[]b]c & a]c a]c | ||
| 281 | a[[b]c & a[c a[c | ||
| 282 | a[-b]c & a-c a-c | ||
| 283 | a[^]b]c & adc adc | ||
| 284 | a[^-b]c & adc adc | ||
| 285 | a[b-]c & a-c a-c | ||
| 286 | a[b &C EBRACK | ||
| 287 | a[] &C EBRACK | ||
| 288 | a[1-3]c & a2c a2c | ||
| 289 | a[3-1]c &C ERANGE | ||
| 290 | a[1-3-5]c &C ERANGE | ||
| 291 | a[[.-.]--]c & a-c a-c | ||
| 292 | a[1- &C ERANGE | ||
| 293 | a[[. &C EBRACK | ||
| 294 | a[[.x &C EBRACK | ||
| 295 | a[[.x. &C EBRACK | ||
| 296 | a[[.x.] &C EBRACK | ||
| 297 | a[[.x.]] & ax ax | ||
| 298 | a[[.x,.]] &C ECOLLATE | ||
| 299 | a[[.one.]]b & a1b a1b | ||
| 300 | a[[.notdef.]]b &C ECOLLATE | ||
| 301 | a[[.].]]b & a]b a]b | ||
| 302 | a[[:alpha:]]c & abc abc | ||
| 303 | a[[:notdef:]]c &C ECTYPE | ||
| 304 | a[[: &C EBRACK | ||
| 305 | a[[:alpha &C EBRACK | ||
| 306 | a[[:alpha:] &C EBRACK | ||
| 307 | a[[:alpha,:] &C ECTYPE | ||
| 308 | a[[:]:]]b &C ECTYPE | ||
| 309 | a[[:-:]]b &C ECTYPE | ||
| 310 | a[[:alph:]] &C ECTYPE | ||
| 311 | a[[:alphabet:]] &C ECTYPE | ||
| 312 | [[:alnum:]]+ - -%@a0X- a0X | ||
| 313 | [[:alpha:]]+ - -%@aX0- aX | ||
| 314 | [[:blank:]]+ - aSSTb SST | ||
| 315 | [[:cntrl:]]+ - aNTb NT | ||
| 316 | [[:digit:]]+ - a019b 019 | ||
| 317 | [[:graph:]]+ - Sa%bS a%b | ||
| 318 | [[:lower:]]+ - AabC ab | ||
| 319 | [[:print:]]+ - NaSbN aSb | ||
| 320 | [[:punct:]]+ - S%-&T %-& | ||
| 321 | [[:space:]]+ - aSNTb SNT | ||
| 322 | [[:upper:]]+ - aBCd BC | ||
| 323 | [[:xdigit:]]+ - p0f3Cq 0f3C | ||
| 324 | a[[=b=]]c & abc abc | ||
| 325 | a[[= &C EBRACK | ||
| 326 | a[[=b &C EBRACK | ||
| 327 | a[[=b= &C EBRACK | ||
| 328 | a[[=b=] &C EBRACK | ||
| 329 | a[[=b,=]] &C ECOLLATE | ||
| 330 | a[[=one=]]b & a1b a1b | ||
| 331 | |||
| 332 | # complexities | ||
| 333 | a(((b)))c - abc abc | ||
| 334 | a(b|(c))d - abd abd | ||
| 335 | a(b*|c)d - abbd abbd | ||
| 336 | # just gotta have one DFA-buster, of course | ||
| 337 | a[ab]{20} - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab | ||
| 338 | # and an inline expansion in case somebody gets tricky | ||
| 339 | a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab | ||
| 340 | # and in case somebody just slips in an NFA... | ||
| 341 | a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night) - aaaaabaaaabaaaabaaaabweeknights aaaaabaaaabaaaabaaaabweeknights | ||
| 342 | # fish for anomalies as the number of states passes 32 | ||
| 343 | 12345678901234567890123456789 - a12345678901234567890123456789b 12345678901234567890123456789 | ||
| 344 | 123456789012345678901234567890 - a123456789012345678901234567890b 123456789012345678901234567890 | ||
| 345 | 1234567890123456789012345678901 - a1234567890123456789012345678901b 1234567890123456789012345678901 | ||
| 346 | 12345678901234567890123456789012 - a12345678901234567890123456789012b 12345678901234567890123456789012 | ||
| 347 | 123456789012345678901234567890123 - a123456789012345678901234567890123b 123456789012345678901234567890123 | ||
| 348 | # and one really big one, beyond any plausible word width | ||
| 349 | 1234567890123456789012345678901234567890123456789012345678901234567890 - a1234567890123456789012345678901234567890123456789012345678901234567890b 1234567890123456789012345678901234567890123456789012345678901234567890 | ||
| 350 | # fish for problems as brackets go past 8 | ||
| 351 | [ab][cd][ef][gh][ij][kl][mn] - xacegikmoq acegikm | ||
| 352 | [ab][cd][ef][gh][ij][kl][mn][op] - xacegikmoq acegikmo | ||
| 353 | [ab][cd][ef][gh][ij][kl][mn][op][qr] - xacegikmoqy acegikmoq | ||
| 354 | [ab][cd][ef][gh][ij][kl][mn][op][q] - xacegikmoqy acegikmoq | ||
| 355 | |||
| 356 | # subtleties of matching | ||
| 357 | abc & xabcy abc | ||
| 358 | a\(b\)?c\1d b acd | ||
| 359 | aBc i Abc Abc | ||
| 360 | a[Bc]*d i abBCcd abBCcd | ||
| 361 | 0[[:upper:]]1 &i 0a1 0a1 | ||
| 362 | 0[[:lower:]]1 &i 0A1 0A1 | ||
| 363 | a[^b]c &i abc | ||
| 364 | a[^b]c &i aBc | ||
| 365 | a[^b]c &i adc adc | ||
| 366 | [a]b[c] - abc abc | ||
| 367 | [a]b[a] - aba aba | ||
| 368 | [abc]b[abc] - abc abc | ||
| 369 | [abc]b[abd] - abd abd | ||
| 370 | a(b?c)+d - accd accd | ||
| 371 | (wee|week)(knights|night) - weeknights weeknights | ||
| 372 | (we|wee|week|frob)(knights|night|day) - weeknights weeknights | ||
| 373 | a[bc]d - xyzaaabcaababdacd abd | ||
| 374 | a[ab]c - aaabc abc | ||
| 375 | abc s abc abc | ||
| 376 | a* & b @b | ||
| 377 | |||
| 378 | # Let's have some fun -- try to match a C comment. | ||
| 379 | # first the obvious, which looks okay at first glance... | ||
| 380 | /\*.*\*/ - /*x*/ /*x*/ | ||
| 381 | # but... | ||
| 382 | /\*.*\*/ - /*x*/y/*z*/ /*x*/y/*z*/ | ||
| 383 | # okay, we must not match */ inside; try to do that... | ||
| 384 | /\*([^*]|\*[^/])*\*/ - /*x*/ /*x*/ | ||
| 385 | /\*([^*]|\*[^/])*\*/ - /*x*/y/*z*/ /*x*/ | ||
| 386 | # but... | ||
| 387 | /\*([^*]|\*[^/])*\*/ - /*x**/y/*z*/ /*x**/y/*z*/ | ||
| 388 | # and a still fancier version, which does it right (I think)... | ||
| 389 | /\*([^*]|\*+[^*/])*\*+/ - /*x*/ /*x*/ | ||
| 390 | /\*([^*]|\*+[^*/])*\*+/ - /*x*/y/*z*/ /*x*/ | ||
| 391 | /\*([^*]|\*+[^*/])*\*+/ - /*x**/y/*z*/ /*x**/ | ||
| 392 | /\*([^*]|\*+[^*/])*\*+/ - /*x****/y/*z*/ /*x****/ | ||
| 393 | /\*([^*]|\*+[^*/])*\*+/ - /*x**x*/y/*z*/ /*x**x*/ | ||
| 394 | /\*([^*]|\*+[^*/])*\*+/ - /*x***x/y/*z*/ /*x***x/y/*z*/ | ||
| 395 | |||
| 396 | # subexpressions | ||
| 397 | a(b)(c)d - abcd abcd b,c | ||
| 398 | a(((b)))c - abc abc b,b,b | ||
| 399 | a(b|(c))d - abd abd b,- | ||
| 400 | a(b*|c|e)d - abbd abbd bb | ||
| 401 | a(b*|c|e)d - acd acd c | ||
| 402 | a(b*|c|e)d - ad ad @d | ||
| 403 | a(b?)c - abc abc b | ||
| 404 | a(b?)c - ac ac @c | ||
| 405 | a(b+)c - abc abc b | ||
| 406 | a(b+)c - abbbc abbbc bbb | ||
| 407 | a(b*)c - ac ac @c | ||
| 408 | (a|ab)(bc([de]+)f|cde) - abcdef abcdef a,bcdef,de | ||
| 409 | # the regression tester only asks for 9 subexpressions | ||
| 410 | a(b)(c)(d)(e)(f)(g)(h)(i)(j)k - abcdefghijk abcdefghijk b,c,d,e,f,g,h,i,j | ||
| 411 | a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l - abcdefghijkl abcdefghijkl b,c,d,e,f,g,h,i,j,k | ||
| 412 | a([bc]?)c - abc abc b | ||
| 413 | a([bc]?)c - ac ac @c | ||
| 414 | a([bc]+)c - abc abc b | ||
| 415 | a([bc]+)c - abcc abcc bc | ||
| 416 | a([bc]+)bc - abcbc abcbc bc | ||
| 417 | a(bb+|b)b - abb abb b | ||
| 418 | a(bbb+|bb+|b)b - abb abb b | ||
| 419 | a(bbb+|bb+|b)b - abbb abbb bb | ||
| 420 | a(bbb+|bb+|b)bb - abbb abbb b | ||
| 421 | (.*).* - abcdef abcdef abcdef | ||
| 422 | (a*)* - bc @b @b | ||
| 423 | |||
| 424 | # do we get the right subexpression when it is used more than once? | ||
| 425 | a(b|c)*d - ad ad - | ||
| 426 | a(b|c)*d - abcd abcd c | ||
| 427 | a(b|c)+d - abd abd b | ||
| 428 | a(b|c)+d - abcd abcd c | ||
| 429 | a(b|c?)+d - ad ad @d | ||
| 430 | a(b|c?)+d - abcd abcd @d | ||
| 431 | a(b|c){0,0}d - ad ad - | ||
| 432 | a(b|c){0,1}d - ad ad - | ||
| 433 | a(b|c){0,1}d - abd abd b | ||
| 434 | a(b|c){0,2}d - ad ad - | ||
| 435 | a(b|c){0,2}d - abcd abcd c | ||
| 436 | a(b|c){0,}d - ad ad - | ||
| 437 | a(b|c){0,}d - abcd abcd c | ||
| 438 | a(b|c){1,1}d - abd abd b | ||
| 439 | a(b|c){1,1}d - acd acd c | ||
| 440 | a(b|c){1,2}d - abd abd b | ||
| 441 | a(b|c){1,2}d - abcd abcd c | ||
| 442 | a(b|c){1,}d - abd abd b | ||
| 443 | a(b|c){1,}d - abcd abcd c | ||
| 444 | a(b|c){2,2}d - acbd acbd b | ||
| 445 | a(b|c){2,2}d - abcd abcd c | ||
| 446 | a(b|c){2,4}d - abcd abcd c | ||
| 447 | a(b|c){2,4}d - abcbd abcbd b | ||
| 448 | a(b|c){2,4}d - abcbcd abcbcd c | ||
| 449 | a(b|c){2,}d - abcd abcd c | ||
| 450 | a(b|c){2,}d - abcbd abcbd b | ||
| 451 | a(b+|((c)*))+d - abd abd @d,@d,- | ||
| 452 | a(b+|((c)*))+d - abcd abcd @d,@d,- | ||
| 453 | |||
| 454 | # check out the STARTEND option | ||
| 455 | [abc] &# a(b)c b | ||
| 456 | [abc] &# a(d)c | ||
| 457 | [abc] &# a(bc)d b | ||
| 458 | [abc] &# a(dc)d c | ||
| 459 | . &# a()c | ||
| 460 | b.*c &# b(bc)c bc | ||
| 461 | b.* &# b(bc)c bc | ||
| 462 | .*c &# b(bc)c bc | ||
| 463 | |||
| 464 | # plain strings, with the NOSPEC flag | ||
| 465 | abc m abc abc | ||
| 466 | abc m xabcy abc | ||
| 467 | abc m xyz | ||
| 468 | a*b m aba*b a*b | ||
| 469 | a*b m ab | ||
| 470 | "" mC EMPTY | ||
| 471 | |||
| 472 | # cases involving NULs | ||
| 473 | aZb & a a | ||
| 474 | aZb &p a | ||
| 475 | aZb &p# (aZb) aZb | ||
| 476 | aZ*b &p# (ab) ab | ||
| 477 | a.b &# (aZb) aZb | ||
| 478 | a.* &# (aZb)c aZb | ||
| 479 | |||
| 480 | # word boundaries (ick) | ||
| 481 | [[:<:]]a & a a | ||
| 482 | [[:<:]]a & ba | ||
| 483 | [[:<:]]a & -a a | ||
| 484 | a[[:>:]] & a a | ||
| 485 | a[[:>:]] & ab | ||
| 486 | a[[:>:]] & a- a | ||
| 487 | [[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc abc | ||
| 488 | [[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc-q abc | ||
| 489 | [[:<:]]a.c[[:>:]] & axc-dayc-dazce-abc axc | ||
| 490 | [[:<:]]b.c[[:>:]] & a_bxc-byc_d-bzc-q bzc | ||
| 491 | [[:<:]].x..[[:>:]] & y_xa_-_xb_y-_xc_-axdc _xc_ | ||
| 492 | [[:<:]]a_b[[:>:]] & x_a_b | ||
| 493 | |||
| 494 | # past problems, and suspected problems | ||
| 495 | (A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A]) - A1 A1 | ||
| 496 | abcdefghijklmnop i abcdefghijklmnop abcdefghijklmnop | ||
| 497 | abcdefghijklmnopqrstuv i abcdefghijklmnopqrstuv abcdefghijklmnopqrstuv | ||
| 498 | (ALAK)|(ALT[AB])|(CC[123]1)|(CM[123]1)|(GAMC)|(LC[23][EO ])|(SEM[1234])|(SL[ES][12])|(SLWW)|(SLF )|(SLDT)|(VWH[12])|(WH[34][EW])|(WP1[ESN]) - CC11 CC11 | ||
| 499 | CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11 | ||
| 500 | Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz | ||
| 501 | a?b - ab ab | ||
| 502 | -\{0,1\}[0-9]*$ b -5 -5 | ||
| 503 | |||
diff --git a/src/regress/lib/libc/setjmp-signal/Makefile b/src/regress/lib/libc/setjmp-signal/Makefile new file mode 100644 index 0000000000..a9649a8abe --- /dev/null +++ b/src/regress/lib/libc/setjmp-signal/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2002/07/31 05:18:24 art Exp $ | ||
| 2 | |||
| 3 | PROG= setjmp-signal | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/setjmp-signal/setjmp-signal.c b/src/regress/lib/libc/setjmp-signal/setjmp-signal.c new file mode 100644 index 0000000000..310e4052ef --- /dev/null +++ b/src/regress/lib/libc/setjmp-signal/setjmp-signal.c | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | /* $OpenBSD: setjmp-signal.c,v 1.3 2003/01/03 20:46:05 miod Exp $ */ | ||
| 2 | /* | ||
| 3 | * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain. | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <setjmp.h> | ||
| 7 | #include <signal.h> | ||
| 8 | |||
| 9 | jmp_buf jb; | ||
| 10 | |||
| 11 | void | ||
| 12 | segv_handler(int signum) | ||
| 13 | { | ||
| 14 | longjmp(jb, 1); | ||
| 15 | } | ||
| 16 | |||
| 17 | int | ||
| 18 | main() | ||
| 19 | { | ||
| 20 | signal(SIGSEGV, segv_handler); | ||
| 21 | if (setjmp(jb) == 0) { | ||
| 22 | *((int *)0L) = 0; | ||
| 23 | return (1); | ||
| 24 | } | ||
| 25 | return (0); | ||
| 26 | } | ||
diff --git a/src/regress/lib/libc/setjmp/Makefile b/src/regress/lib/libc/setjmp/Makefile new file mode 100644 index 0000000000..fc68e8d44c --- /dev/null +++ b/src/regress/lib/libc/setjmp/Makefile | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2002/01/01 23:00:51 art Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.2 1995/04/20 22:40:13 cgd Exp $ | ||
| 3 | |||
| 4 | PROG= setjmptest | ||
| 5 | SRCS= jmptest.c | ||
| 6 | |||
| 7 | CFLAGS+= -DTEST_SETJMP | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/setjmp/jmptest.c b/src/regress/lib/libc/setjmp/jmptest.c new file mode 100644 index 0000000000..9512c9ee34 --- /dev/null +++ b/src/regress/lib/libc/setjmp/jmptest.c | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | /* $OpenBSD: jmptest.c,v 1.7 2003/09/02 23:52:16 david Exp $ */ | ||
| 2 | /* $NetBSD: jmptest.c,v 1.2 1995/01/01 20:55:35 jtc Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (c) 1994 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed by Christopher G. Demetriou | ||
| 19 | * for the NetBSD Project. | ||
| 20 | * 4. The name of the author may not be used to endorse or promote products | ||
| 21 | * derived from this software without specific prior written permission | ||
| 22 | * | ||
| 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 33 | */ | ||
| 34 | |||
| 35 | #include <sys/types.h> | ||
| 36 | #include <err.h> | ||
| 37 | #include <setjmp.h> | ||
| 38 | #include <signal.h> | ||
| 39 | #include <stdio.h> | ||
| 40 | #include <stdlib.h> | ||
| 41 | #include <string.h> | ||
| 42 | #include <unistd.h> | ||
| 43 | |||
| 44 | #if (TEST_SETJMP + TEST_U_SETJMP + TEST_SIGSETJMP) != 1 | ||
| 45 | #error one of TEST_SETJMP, TEST_U_SETJMP, or TEST_SIGSETJMP must be defined | ||
| 46 | #endif | ||
| 47 | |||
| 48 | #ifdef TEST_SETJMP | ||
| 49 | #define BUF jmp_buf | ||
| 50 | #define SET(b, m) setjmp(b) | ||
| 51 | #define JMP(b, v) longjmp(b, v) | ||
| 52 | #endif | ||
| 53 | |||
| 54 | #ifdef TEST_U_SETJMP | ||
| 55 | #define BUF jmp_buf | ||
| 56 | #define SET(b, m) _setjmp(b) | ||
| 57 | #define JMP(b, v) _longjmp(b, v) | ||
| 58 | #endif | ||
| 59 | |||
| 60 | #ifdef TEST_SIGSETJMP | ||
| 61 | #define BUF sigjmp_buf | ||
| 62 | #define SET(b, m) sigsetjmp(b, m) | ||
| 63 | #define JMP(b, v) siglongjmp(b, v) | ||
| 64 | #endif | ||
| 65 | |||
| 66 | int expectsignal; | ||
| 67 | |||
| 68 | static void | ||
| 69 | aborthandler(int signo) | ||
| 70 | { | ||
| 71 | |||
| 72 | if (expectsignal) | ||
| 73 | _exit(0); | ||
| 74 | else { | ||
| 75 | warnx("kill(SIGABRT) succeeded"); | ||
| 76 | _exit(1); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | int | ||
| 81 | main(int argc, char *argv[]) | ||
| 82 | { | ||
| 83 | struct sigaction sa; | ||
| 84 | BUF jb; | ||
| 85 | sigset_t ss; | ||
| 86 | int i, x; | ||
| 87 | |||
| 88 | i = getpid(); | ||
| 89 | |||
| 90 | #ifdef TEST_SETJMP | ||
| 91 | expectsignal = 0; | ||
| 92 | #endif | ||
| 93 | #ifdef TEST_U_SETJMP | ||
| 94 | expectsignal = 1; | ||
| 95 | #endif | ||
| 96 | #ifdef TEST_SIGSETJMP | ||
| 97 | if (argc != 2 || | ||
| 98 | (strcmp(argv[1], "save") && strcmp(argv[1], "nosave"))) { | ||
| 99 | fprintf(stderr, "usage: %s [save|nosave]\n", argv[0]); | ||
| 100 | exit(1); | ||
| 101 | } | ||
| 102 | expectsignal = (strcmp(argv[1], "save") != 0); | ||
| 103 | #endif | ||
| 104 | |||
| 105 | sa.sa_handler = aborthandler; | ||
| 106 | sigemptyset(&sa.sa_mask); | ||
| 107 | sa.sa_flags = 0; | ||
| 108 | if (sigaction(SIGABRT, &sa, NULL) == -1) | ||
| 109 | err(1, "sigaction failed"); | ||
| 110 | |||
| 111 | if (sigemptyset(&ss) == -1) | ||
| 112 | err(1, "sigemptyset failed"); | ||
| 113 | if (sigaddset(&ss, SIGABRT) == -1) | ||
| 114 | err(1, "sigaddset failed"); | ||
| 115 | if (sigprocmask(SIG_BLOCK, &ss, NULL) == -1) | ||
| 116 | err(1, "sigprocmask (1) failed"); | ||
| 117 | |||
| 118 | x = SET(jb, !expectsignal); | ||
| 119 | if (x != 0) { | ||
| 120 | if (x != i) | ||
| 121 | errx(1, "setjmp returned wrong value"); | ||
| 122 | |||
| 123 | kill(i, SIGABRT); | ||
| 124 | if (expectsignal) | ||
| 125 | errx(1, "kill(SIGABRT) failed"); | ||
| 126 | else | ||
| 127 | exit(0); | ||
| 128 | } | ||
| 129 | |||
| 130 | if (sigprocmask(SIG_UNBLOCK, &ss, NULL) == -1) | ||
| 131 | err(1, "sigprocmask (2) failed"); | ||
| 132 | |||
| 133 | JMP(jb, i); | ||
| 134 | |||
| 135 | errx(1, "jmp failed"); | ||
| 136 | } | ||
diff --git a/src/regress/lib/libc/sigreturn/Makefile b/src/regress/lib/libc/sigreturn/Makefile new file mode 100644 index 0000000000..9891ba9e05 --- /dev/null +++ b/src/regress/lib/libc/sigreturn/Makefile | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2002/09/02 20:01:43 avsm Exp $ | ||
| 2 | |||
| 3 | PROG= sigret | ||
| 4 | |||
| 5 | DEBUG+= -ggdb | ||
| 6 | |||
| 7 | REGRESS_TARGETS+= sigret-normal sigret-indirect sigret-altstack | ||
| 8 | |||
| 9 | sigret-normal: ${PROG} | ||
| 10 | ./${PROG} | ||
| 11 | |||
| 12 | sigret-indirect: ${PROG} | ||
| 13 | ./${PROG} -i | ||
| 14 | |||
| 15 | sigret-altstack: ${PROG} | ||
| 16 | ./${PROG} -a | ||
| 17 | |||
| 18 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sigreturn/sigret.c b/src/regress/lib/libc/sigreturn/sigret.c new file mode 100644 index 0000000000..72945fa503 --- /dev/null +++ b/src/regress/lib/libc/sigreturn/sigret.c | |||
| @@ -0,0 +1,181 @@ | |||
| 1 | /* | ||
| 2 | * $OpenBSD: sigret.c,v 1.5 2003/07/31 21:48:04 deraadt Exp $ | ||
| 3 | * | ||
| 4 | * Public Domain | ||
| 5 | * | ||
| 6 | * Playing games with sigreturn. Check if calling sigreturn from a | ||
| 7 | * signal handler screws anything up. | ||
| 8 | * | ||
| 9 | * Run with: | ||
| 10 | * -a: use an alternate signal stack | ||
| 11 | * | ||
| 12 | * -b: call sigreturn from outside of a signal handler | ||
| 13 | * An error is OK | ||
| 14 | * | ||
| 15 | * -c: clobber the sigcontext before calling sigreturn | ||
| 16 | * the program should die | ||
| 17 | * | ||
| 18 | * -f: don't use sigreturn -- fall through the signal handler | ||
| 19 | * -c, and -i options ignored when used | ||
| 20 | * | ||
| 21 | * -i: call sigreturn from a function called by the signal handler | ||
| 22 | * | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include <sys/time.h> | ||
| 26 | |||
| 27 | #include <err.h> | ||
| 28 | #include <signal.h> | ||
| 29 | #include <stdarg.h> | ||
| 30 | #include <stdio.h> | ||
| 31 | #include <stdlib.h> | ||
| 32 | #include <string.h> | ||
| 33 | #include <unistd.h> | ||
| 34 | |||
| 35 | /* | ||
| 36 | * sigalarm occurs 50 times/second. Stop running after 10 seconds | ||
| 37 | * (100 interrupts). | ||
| 38 | */ | ||
| 39 | #define MAX_INTERRUPTS 500 | ||
| 40 | |||
| 41 | int failed; | ||
| 42 | int altstack; | ||
| 43 | int badcall; | ||
| 44 | int clobbercall; | ||
| 45 | int fallthru; | ||
| 46 | int indirect; | ||
| 47 | |||
| 48 | volatile int count; | ||
| 49 | struct sigcontext gscp; | ||
| 50 | int gscp_loaded; | ||
| 51 | |||
| 52 | static void | ||
| 53 | usage(const char * err, ...) | ||
| 54 | { | ||
| 55 | extern const char * __progname; | ||
| 56 | |||
| 57 | if (err) { | ||
| 58 | va_list ap; | ||
| 59 | va_start(ap, err); | ||
| 60 | vwarnx(err, ap); | ||
| 61 | va_end(ap); | ||
| 62 | } | ||
| 63 | fprintf(stderr, "usage: %s [-abcfi]\n", __progname); | ||
| 64 | exit(1); | ||
| 65 | } | ||
| 66 | |||
| 67 | static void | ||
| 68 | indirect_return(struct sigcontext * scp) | ||
| 69 | { | ||
| 70 | sigreturn(scp); | ||
| 71 | } | ||
| 72 | |||
| 73 | static void | ||
| 74 | sig_handler(int sig, siginfo_t *blah, void *x) | ||
| 75 | { | ||
| 76 | struct sigcontext * scp = x; | ||
| 77 | |||
| 78 | count++; | ||
| 79 | |||
| 80 | if (!fallthru) { | ||
| 81 | if (clobbercall) | ||
| 82 | memset(scp, 0, sizeof *scp); | ||
| 83 | if (indirect) | ||
| 84 | indirect_return(scp); | ||
| 85 | else if (badcall) { | ||
| 86 | gscp = *scp; | ||
| 87 | gscp_loaded = 1; | ||
| 88 | } else | ||
| 89 | sigreturn(scp); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | static void | ||
| 94 | test2(char *fmt) | ||
| 95 | { | ||
| 96 | char *ofmt = fmt; | ||
| 97 | |||
| 98 | if (gscp_loaded) { | ||
| 99 | gscp_loaded = 0; | ||
| 100 | sigreturn(&gscp); | ||
| 101 | } | ||
| 102 | |||
| 103 | for (; *fmt; fmt++) | ||
| 104 | switch (*fmt) { | ||
| 105 | case 'i': | ||
| 106 | case 'c': | ||
| 107 | case 'l': | ||
| 108 | case 'p': | ||
| 109 | break; | ||
| 110 | default: | ||
| 111 | failed = 1; | ||
| 112 | fprintf(stderr, | ||
| 113 | "unexpected character 0x%02x `%c' in %s: count %d\n", | ||
| 114 | *fmt, *fmt, ofmt, count); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | int | ||
| 119 | main(int argc, char * argv[]) | ||
| 120 | { | ||
| 121 | extern char *optarg; | ||
| 122 | extern int optind; | ||
| 123 | |||
| 124 | int opt; | ||
| 125 | |||
| 126 | struct sigaction act; | ||
| 127 | struct sigaltstack ss; | ||
| 128 | |||
| 129 | while ((opt = getopt(argc, argv, "abcfi")) != -1) { | ||
| 130 | switch (opt) { | ||
| 131 | case 'a': | ||
| 132 | /* use sigaltstack */ | ||
| 133 | altstack = 1; | ||
| 134 | break; | ||
| 135 | case 'b': | ||
| 136 | /* call outside of sig_handler */ | ||
| 137 | badcall = 1; | ||
| 138 | break; | ||
| 139 | case 'c': | ||
| 140 | /* force error by munging sigcontext */ | ||
| 141 | clobbercall = 1; | ||
| 142 | break; | ||
| 143 | case 'f': | ||
| 144 | /* don't use sigreturn */ | ||
| 145 | fallthru = 1; | ||
| 146 | break; | ||
| 147 | case 'i': | ||
| 148 | /* call sigreturn indirectly */ | ||
| 149 | indirect = 1; | ||
| 150 | break; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | /* make sure there is no other cruft left on the command line */ | ||
| 155 | if (optind != argc) | ||
| 156 | usage("unknown argument -- %s", argv[ optind ]); | ||
| 157 | |||
| 158 | if (altstack) { | ||
| 159 | if ((ss.ss_sp = malloc(SIGSTKSZ)) == NULL) | ||
| 160 | errx(1, "ss_sp malloc"); | ||
| 161 | |||
| 162 | ss.ss_size = SIGSTKSZ; | ||
| 163 | ss.ss_flags = 0; | ||
| 164 | if (sigaltstack(&ss,0) == -1) | ||
| 165 | err(1, "sigaltstack"); | ||
| 166 | } | ||
| 167 | |||
| 168 | sigfillset(&act.sa_mask); | ||
| 169 | act.sa_sigaction = sig_handler; | ||
| 170 | act.sa_flags = SA_RESTART; | ||
| 171 | if (altstack) | ||
| 172 | act.sa_flags |= SA_ONSTACK; | ||
| 173 | sigaction(SIGALRM, &act, NULL); | ||
| 174 | |||
| 175 | ualarm(10000, 10000); | ||
| 176 | |||
| 177 | while (count < MAX_INTERRUPTS) | ||
| 178 | test2("iclp"); | ||
| 179 | |||
| 180 | return failed; | ||
| 181 | } | ||
diff --git a/src/regress/lib/libc/sigsetjmp/Makefile b/src/regress/lib/libc/sigsetjmp/Makefile new file mode 100644 index 0000000000..f88bea3b47 --- /dev/null +++ b/src/regress/lib/libc/sigsetjmp/Makefile | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2002/09/02 20:01:43 avsm Exp $ | ||
| 2 | |||
| 3 | PROG= sigsetjmptest | ||
| 4 | SRCS= jmptest.c | ||
| 5 | |||
| 6 | CFLAGS+= -DTEST_SIGSETJMP | ||
| 7 | |||
| 8 | .PATH: ${.CURDIR}/../setjmp | ||
| 9 | |||
| 10 | REGRESS_TARGETS=sigsetjmp-save sigsetjmp-nosave | ||
| 11 | |||
| 12 | sigsetjmp-save: ${PROG} | ||
| 13 | ./${PROG} save | ||
| 14 | sigsetjmp-nosave: ${PROG} | ||
| 15 | ./${PROG} nosave | ||
| 16 | |||
| 17 | .PHONY: ${REGRESS_TARGETS} | ||
| 18 | |||
| 19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sleep/Makefile b/src/regress/lib/libc/sleep/Makefile new file mode 100644 index 0000000000..3700b1662a --- /dev/null +++ b/src/regress/lib/libc/sleep/Makefile | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2009/12/14 05:08:19 guenther Exp $ | ||
| 2 | |||
| 3 | NOMAN= | ||
| 4 | PROG=sleep_test | ||
| 5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
| 6 | |||
| 7 | run-regress-${PROG}: ${PROG} | ||
| 8 | [ x$$(./${PROG} 1) = x0 ] || exit 1 | ||
| 9 | file=$$(mktemp -t sleep.XXXXXXXXXX); ./${PROG} 4 >$$file & pid=$$!; \ | ||
| 10 | sleep 1; kill $$pid; sleep 1; v=$$(cat $$file); rm -f $$file; \ | ||
| 11 | { [ $$v -gt 0 ] && [ $$v -lt 4 ] ; } || exit 2 | ||
| 12 | |||
| 13 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sleep/sleep_test.c b/src/regress/lib/libc/sleep/sleep_test.c new file mode 100644 index 0000000000..c9ab0d095f --- /dev/null +++ b/src/regress/lib/libc/sleep/sleep_test.c | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | /* $OpenBSD: sleep_test.c,v 1.1 2009/12/14 05:08:19 guenther Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2009 Philip Guenther | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * | ||
| 11 | * - Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * - Redistributions in binary form must reproduce the above | ||
| 14 | * copyright notice, this list of conditions and the following | ||
| 15 | * disclaimer in the documentation and/or other materials provided | ||
| 16 | * with the distribution. | ||
| 17 | * | ||
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| 28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | |||
| 32 | /* | ||
| 33 | * Test whether sleep returns the correct value | ||
| 34 | */ | ||
| 35 | |||
| 36 | #include <sys/types.h> | ||
| 37 | #include <err.h> | ||
| 38 | #include <errno.h> | ||
| 39 | #include <limits.h> | ||
| 40 | #include <signal.h> | ||
| 41 | #include <stddef.h> | ||
| 42 | #include <stdio.h> | ||
| 43 | #include <stdlib.h> | ||
| 44 | #include <unistd.h> | ||
| 45 | |||
| 46 | static void | ||
| 47 | handler(int sig) | ||
| 48 | { | ||
| 49 | return; | ||
| 50 | } | ||
| 51 | |||
| 52 | static void * | ||
| 53 | garbage(void) | ||
| 54 | { | ||
| 55 | char buf[20]; | ||
| 56 | strlcpy(buf, "012354678901235467890123546789", sizeof buf); | ||
| 57 | return buf; | ||
| 58 | } | ||
| 59 | |||
| 60 | int | ||
| 61 | main(int argc, char *argv[]) | ||
| 62 | { | ||
| 63 | struct sigaction sa; | ||
| 64 | char const *errstr; | ||
| 65 | int i; | ||
| 66 | |||
| 67 | if (argc != 2) | ||
| 68 | return (1); | ||
| 69 | errno = 0; | ||
| 70 | i = strtonum(argv[1], 0, INT_MAX, &errstr); | ||
| 71 | if (i == 0 && errno != 0) { | ||
| 72 | fprintf(stderr, "%s\n", errstr); | ||
| 73 | return (1); | ||
| 74 | } | ||
| 75 | |||
| 76 | memset(&sa, 0, sizeof sa); | ||
| 77 | sa.sa_handler = &handler; | ||
| 78 | if (sigaction(SIGTERM, &sa, NULL)) | ||
| 79 | err(3, "sigaction"); | ||
| 80 | garbage(); | ||
| 81 | printf("%d\n", sleep(i)); | ||
| 82 | return (0); | ||
| 83 | } | ||
| 84 | |||
diff --git a/src/regress/lib/libc/sprintf/Makefile b/src/regress/lib/libc/sprintf/Makefile new file mode 100644 index 0000000000..47bab9cdd3 --- /dev/null +++ b/src/regress/lib/libc/sprintf/Makefile | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2003/05/15 04:23:49 deraadt Exp $ | ||
| 2 | |||
| 3 | NOMAN= | ||
| 4 | PROG=sprintf_test | ||
| 5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
| 6 | |||
| 7 | run-regress-atexit_test: ${PROG} | ||
| 8 | ./${PROG} | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sprintf/sprintf_test.c b/src/regress/lib/libc/sprintf/sprintf_test.c new file mode 100644 index 0000000000..61c58f2f09 --- /dev/null +++ b/src/regress/lib/libc/sprintf/sprintf_test.c | |||
| @@ -0,0 +1,102 @@ | |||
| 1 | /* $OpenBSD: sprintf_test.c,v 1.4 2004/09/18 19:31:32 otto Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2003 Theo de Raadt | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * | ||
| 11 | * - Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * - Redistributions in binary form must reproduce the above | ||
| 14 | * copyright notice, this list of conditions and the following | ||
| 15 | * disclaimer in the documentation and/or other materials provided | ||
| 16 | * with the distribution. | ||
| 17 | * | ||
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| 28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include <stddef.h> | ||
| 33 | #include <stdio.h> | ||
| 34 | #include <stdlib.h> | ||
| 35 | #include <string.h> | ||
| 36 | #include <signal.h> | ||
| 37 | |||
| 38 | char correct[] = | ||
| 39 | "|xx 01 02 03 04\n" | ||
| 40 | "|xx 05 06 07 08\n" | ||
| 41 | "|xx 09 10 11 12\n" | ||
| 42 | "|xx 13 14 15 16\n" | ||
| 43 | "|xx 17 18 19 20\n" | ||
| 44 | "|xx 21 22 23 24\n" | ||
| 45 | "|xx 25 26 27 28\n" | ||
| 46 | "|xx 29 30 31 32\n" | ||
| 47 | "|xx 33 34 35 36\n" | ||
| 48 | "|xx 37 38 39 40\n" | ||
| 49 | "|xx 41 42 43 44\n" | ||
| 50 | "|xx 45 -1 1 -1 1\n"; | ||
| 51 | |||
| 52 | char correct2[] = | ||
| 53 | "1 0 -1 1 1 2 1 3 -1 4 1 \n" | ||
| 54 | "1 -1 1 1 -1 1 \n"; | ||
| 55 | |||
| 56 | int | ||
| 57 | main(int argc, char *argv[]) | ||
| 58 | { | ||
| 59 | char buf[1024]; | ||
| 60 | size_t sz1, sz2, sz3, sz4; | ||
| 61 | ptrdiff_t p1, p2, p3, p4; | ||
| 62 | |||
| 63 | /* Test positional arguments */ | ||
| 64 | snprintf(buf, sizeof buf, | ||
| 65 | "|xx %1$s %2$s %3$s %4$s\n" | ||
| 66 | "|xx %5$s %6$s %7$s %8$s\n" | ||
| 67 | "|xx %9$s %10$s %11$s %12$s\n" | ||
| 68 | "|xx %13$s %14$s %15$s %16$s\n" | ||
| 69 | "|xx %17$s %18$s %19$s %20$s\n" | ||
| 70 | "|xx %21$s %22$s %23$s %24$s\n" | ||
| 71 | "|xx %25$s %26$s %27$s %28$s\n" | ||
| 72 | "|xx %29$s %30$s %31$s %32$s\n" | ||
| 73 | "|xx %33$s %34$s %35$s %36$s\n" | ||
| 74 | "|xx %37$s %38$s %39$s %40$s\n" | ||
| 75 | "|xx %41$s %42$s %43$s %44$s\n" | ||
| 76 | "|xx %45$d %46$ld %47$lld %48$d %49$lld\n", | ||
| 77 | "01", "02", "03", "04", "05", "06", | ||
| 78 | "07", "08", "09", "10", "11", "12", | ||
| 79 | "13", "14", "15", "16", "17", "18", | ||
| 80 | "19", "20", "21", "22", "23", "24", | ||
| 81 | "25", "26", "27", "28", "29", "30", | ||
| 82 | "31", "32", "33", "34", "35", "36", | ||
| 83 | "37", "38", "39", "40", "41", "42", | ||
| 84 | "43", "44", 45, -1L, 1LL, -1, 1LL | ||
| 85 | ); | ||
| 86 | |||
| 87 | if (strcmp(buf, correct) != 0) | ||
| 88 | exit(1); | ||
| 89 | |||
| 90 | sz1 = (size_t)1; | ||
| 91 | sz2 = (size_t)-1; | ||
| 92 | p1 = (ptrdiff_t)1; | ||
| 93 | p2 = (ptrdiff_t)-1; | ||
| 94 | snprintf(buf, sizeof buf, | ||
| 95 | "%zx %d %zd %d %zu %d %tx %d %td %d %tu %zn %tn\n" | ||
| 96 | "%1$zx %3$zd %5$zu %7$tx %9$td %11$tu %14$zn %15$tn\n", | ||
| 97 | sz1, 0, sz2, 1, sz1, 2, p1, 3, p2, 4, p1, &sz3, &p3, &sz4, &p4); | ||
| 98 | if (strcmp(buf, correct2) != 0 || sz3 != 24 || p3 != 25 || | ||
| 99 | sz4 != 40 || p4 != 41) | ||
| 100 | exit(1); | ||
| 101 | exit(0); | ||
| 102 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/Makefile b/src/regress/lib/libc/stdio_threading/Makefile new file mode 100644 index 0000000000..e42481afc2 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/Makefile | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | SUBDIR += fopen fread fwrite fgetln fgets fputs | ||
| 2 | |||
| 3 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgetln/Makefile b/src/regress/lib/libc/stdio_threading/fgetln/Makefile new file mode 100644 index 0000000000..cad51e2b23 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fgetln/Makefile | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fgetln_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c b/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c new file mode 100755 index 0000000000..d5c4db2edf --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "local.h" | ||
| 18 | |||
| 19 | void | ||
| 20 | fgetln_thread(void *v) | ||
| 21 | { | ||
| 22 | FILE *file = v; | ||
| 23 | size_t len; | ||
| 24 | char *buf; | ||
| 25 | int i; | ||
| 26 | |||
| 27 | for (i = 0; i < 4096; i++) { | ||
| 28 | if ((buf = fgetln(file, &len)) == NULL) { | ||
| 29 | |||
| 30 | if (feof(file)) | ||
| 31 | break; | ||
| 32 | |||
| 33 | printf("OMG!!!\n"); | ||
| 34 | fflush(stdout); | ||
| 35 | break; | ||
| 36 | } | ||
| 37 | if (strncmp(buf, TEXT_N, sizeof(TEXT_N))) | ||
| 38 | err(1, "fgetln not atomic!!!"); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | int | ||
| 43 | main(void) | ||
| 44 | { | ||
| 45 | char sfn[24]; | ||
| 46 | char buf[sizeof(TEXT_N)]; | ||
| 47 | FILE *sfp; | ||
| 48 | int fd, i; | ||
| 49 | |||
| 50 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 51 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 52 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 53 | if (fd != -1) { | ||
| 54 | unlink(sfn); | ||
| 55 | close(fd); | ||
| 56 | } | ||
| 57 | err(1, "could not open temporary file"); | ||
| 58 | } | ||
| 59 | |||
| 60 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
| 61 | if (fwrite(TEXT_N, sizeof(char), strlen(TEXT_N), sfp) == 0) | ||
| 62 | err(1, "Could not populate test file"); | ||
| 63 | |||
| 64 | run_threads(fgetln_thread, sfp); | ||
| 65 | |||
| 66 | unlink(sfn); | ||
| 67 | close(fd); | ||
| 68 | |||
| 69 | exit(0); | ||
| 70 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgets/Makefile b/src/regress/lib/libc/stdio_threading/fgets/Makefile new file mode 100644 index 0000000000..52310fd429 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fgets/Makefile | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fgets_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c b/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c new file mode 100755 index 0000000000..685d4c8257 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "local.h" | ||
| 18 | |||
| 19 | void | ||
| 20 | fgets_thread(void *v) | ||
| 21 | { | ||
| 22 | char buf[sizeof(TEXT_N) + 1]; | ||
| 23 | FILE *file = v; | ||
| 24 | int i; | ||
| 25 | |||
| 26 | for (i = 0; i < 4096; i++) { | ||
| 27 | if (fgets(buf, sizeof(buf), file) == NULL) { | ||
| 28 | |||
| 29 | if (feof(file)) | ||
| 30 | break; | ||
| 31 | |||
| 32 | printf("OMG!!!\n"); | ||
| 33 | fflush(stdout); | ||
| 34 | break; | ||
| 35 | } | ||
| 36 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
| 37 | err(1, "Read not atomic!!!"); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | int | ||
| 42 | main(void) | ||
| 43 | { | ||
| 44 | char sfn[24]; | ||
| 45 | char buf[sizeof(TEXT)]; | ||
| 46 | FILE *sfp; | ||
| 47 | int fd, i; | ||
| 48 | |||
| 49 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 50 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 51 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 52 | if (fd != -1) { | ||
| 53 | unlink(sfn); | ||
| 54 | close(fd); | ||
| 55 | } | ||
| 56 | err(1, "could not open temporary file"); | ||
| 57 | } | ||
| 58 | |||
| 59 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
| 60 | if (fwrite(TEXT_N, sizeof(char), strlen(TEXT_N), sfp) == 0) | ||
| 61 | err(1, "Could not populate test file"); | ||
| 62 | |||
| 63 | run_threads(fgets_thread, sfp); | ||
| 64 | |||
| 65 | unlink(sfn); | ||
| 66 | close(fd); | ||
| 67 | |||
| 68 | exit(0); | ||
| 69 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fopen/Makefile b/src/regress/lib/libc/stdio_threading/fopen/Makefile new file mode 100644 index 0000000000..e51deeff1d --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fopen/Makefile | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fopen_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c b/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c new file mode 100755 index 0000000000..72359bb323 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <stdio.h> | ||
| 18 | #include <pthread.h> | ||
| 19 | #include "local.h" | ||
| 20 | |||
| 21 | int | ||
| 22 | writefn(void *cookie, const char *buf, int size) | ||
| 23 | { | ||
| 24 | return 0; | ||
| 25 | } | ||
| 26 | |||
| 27 | void | ||
| 28 | fopen_thread(void *v) | ||
| 29 | { | ||
| 30 | FILE *file; | ||
| 31 | int i; | ||
| 32 | |||
| 33 | for (i = 0; i < 4096; i++) { | ||
| 34 | file = fwopen(&i, writefn); | ||
| 35 | if (file != NULL) { | ||
| 36 | fputc('0', file); | ||
| 37 | pthread_yield(); | ||
| 38 | fclose(file); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | int | ||
| 44 | main(void) | ||
| 45 | { | ||
| 46 | run_threads(fopen_thread, NULL); | ||
| 47 | exit(0); | ||
| 48 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fputs/Makefile b/src/regress/lib/libc/stdio_threading/fputs/Makefile new file mode 100644 index 0000000000..e561745581 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fputs/Makefile | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fputs_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c b/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c new file mode 100755 index 0000000000..c0a617510e --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "local.h" | ||
| 18 | |||
| 19 | void | ||
| 20 | fputs_thread(void *v) | ||
| 21 | { | ||
| 22 | FILE *file = v; | ||
| 23 | int i; | ||
| 24 | |||
| 25 | for (i = 0; i < 4096; i++) { | ||
| 26 | if (fputs(TEXT, file) != 0) { | ||
| 27 | |||
| 28 | if (feof(file)) | ||
| 29 | break; | ||
| 30 | |||
| 31 | printf("OMG!!!\n"); | ||
| 32 | fflush(stdout); | ||
| 33 | break; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | int | ||
| 39 | main(void) | ||
| 40 | { | ||
| 41 | char sfn[24]; | ||
| 42 | char buf[sizeof(TEXT)]; | ||
| 43 | FILE *sfp; | ||
| 44 | int fd, i; | ||
| 45 | |||
| 46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 47 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 48 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 49 | if (fd != -1) { | ||
| 50 | unlink(sfn); | ||
| 51 | close(fd); | ||
| 52 | } | ||
| 53 | err(1, "could not open temporary file"); | ||
| 54 | } | ||
| 55 | |||
| 56 | run_threads(fputs_thread, sfp); | ||
| 57 | |||
| 58 | while (fgets(buf, sizeof(buf), sfp) != NULL) /* verify */ | ||
| 59 | if (strcmp(buf, TEXT)) | ||
| 60 | err(1, "Thread writes were not atomic!!!"); | ||
| 61 | |||
| 62 | unlink(sfn); | ||
| 63 | close(fd); | ||
| 64 | |||
| 65 | exit(0); | ||
| 66 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fread/Makefile b/src/regress/lib/libc/stdio_threading/fread/Makefile new file mode 100644 index 0000000000..25196dd7ab --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fread/Makefile | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fread_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fread/fread_test.c b/src/regress/lib/libc/stdio_threading/fread/fread_test.c new file mode 100755 index 0000000000..b2372f5ab6 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fread/fread_test.c | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <stdio.h> | ||
| 18 | #include <pthread.h> | ||
| 19 | #include "local.h" | ||
| 20 | |||
| 21 | void | ||
| 22 | fread_thread(void *v) | ||
| 23 | { | ||
| 24 | char buf[sizeof(TEXT)]; | ||
| 25 | FILE *file = v; | ||
| 26 | int i; | ||
| 27 | |||
| 28 | for (i = 0; i < 4096; i++) { | ||
| 29 | if (fread(buf, sizeof(char), strlen(TEXT), file) == 0) { | ||
| 30 | |||
| 31 | if (feof(file)) | ||
| 32 | break; | ||
| 33 | |||
| 34 | printf("OMG!!!\n"); | ||
| 35 | fflush(stdout); | ||
| 36 | break; | ||
| 37 | } | ||
| 38 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
| 39 | err(1, "Read not atomic!!!"); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | int | ||
| 44 | main(void) | ||
| 45 | { | ||
| 46 | char sfn[24]; | ||
| 47 | char buf[sizeof(TEXT)]; | ||
| 48 | FILE *sfp; | ||
| 49 | int fd, i; | ||
| 50 | |||
| 51 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 52 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 53 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 54 | if (fd != -1) { | ||
| 55 | unlink(sfn); | ||
| 56 | close(fd); | ||
| 57 | } | ||
| 58 | err(1, "could not open temporary file"); | ||
| 59 | } | ||
| 60 | |||
| 61 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
| 62 | if (fwrite(TEXT, sizeof(char), strlen(TEXT), sfp) == 0) | ||
| 63 | err(1, "Could not populate test file"); | ||
| 64 | |||
| 65 | run_threads(fread_thread, sfp); | ||
| 66 | |||
| 67 | unlink(sfn); | ||
| 68 | close(fd); | ||
| 69 | |||
| 70 | exit(0); | ||
| 71 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fwrite/Makefile b/src/regress/lib/libc/stdio_threading/fwrite/Makefile new file mode 100644 index 0000000000..e79899c475 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fwrite/Makefile | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fwrite_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c b/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c new file mode 100755 index 0000000000..39bfb51ef0 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "local.h" | ||
| 18 | |||
| 19 | void | ||
| 20 | fwrite_thread(void *v) | ||
| 21 | { | ||
| 22 | FILE *file = v; | ||
| 23 | int i; | ||
| 24 | |||
| 25 | for (i = 0; i < 4096; i++) { | ||
| 26 | if (fwrite(TEXT, sizeof(char), strlen(TEXT), file) == 0) { | ||
| 27 | |||
| 28 | if (feof(file)) | ||
| 29 | break; | ||
| 30 | |||
| 31 | printf("OMG!!!\n"); | ||
| 32 | fflush(stdout); | ||
| 33 | break; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | int | ||
| 39 | main(void) | ||
| 40 | { | ||
| 41 | char sfn[24]; | ||
| 42 | char buf[sizeof(TEXT)]; | ||
| 43 | FILE *sfp; | ||
| 44 | int fd, i; | ||
| 45 | |||
| 46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 47 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 48 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 49 | if (fd != -1) { | ||
| 50 | unlink(sfn); | ||
| 51 | close(fd); | ||
| 52 | } | ||
| 53 | err(1, "could not open temporary file"); | ||
| 54 | } | ||
| 55 | |||
| 56 | run_threads(fwrite_thread, sfp); | ||
| 57 | |||
| 58 | while (fread(buf, sizeof(char), strlen(TEXT), sfp)) /* verify */ | ||
| 59 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
| 60 | err(1, "Thread writes were not atomic!!!"); | ||
| 61 | |||
| 62 | unlink(sfn); | ||
| 63 | close(fd); | ||
| 64 | |||
| 65 | exit(0); | ||
| 66 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/include/local.h b/src/regress/lib/libc/stdio_threading/include/local.h new file mode 100644 index 0000000000..e2ad4e31e0 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/include/local.h | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <stdio.h> | ||
| 18 | #include <stdlib.h> | ||
| 19 | #include <string.h> | ||
| 20 | #include <unistd.h> | ||
| 21 | #include <pthread.h> | ||
| 22 | |||
| 23 | #define THREAD_COUNT 64 | ||
| 24 | |||
| 25 | #define TEXT "barnacles" | ||
| 26 | #define TEXT_N "barnacles\n" | ||
| 27 | |||
| 28 | void run_threads(void (*)(void *), void *); | ||
| 29 | |||
| 30 | static pthread_rwlock_t start; | ||
| 31 | static void (*real_func)(void *); | ||
| 32 | |||
| 33 | static void * | ||
| 34 | thread(void *arg) | ||
| 35 | { | ||
| 36 | int r; | ||
| 37 | |||
| 38 | if ((r = pthread_rwlock_rdlock(&start))) | ||
| 39 | errx(1, "could not obtain lock in thread: %s", strerror(r)); | ||
| 40 | real_func(arg); | ||
| 41 | if ((r = pthread_rwlock_unlock(&start))) | ||
| 42 | errx(1, "could not release lock in thread: %s", strerror(r)); | ||
| 43 | return NULL; | ||
| 44 | } | ||
| 45 | |||
| 46 | void | ||
| 47 | run_threads(void (*func)(void *), void *arg) | ||
| 48 | { | ||
| 49 | pthread_t self, pthread[THREAD_COUNT]; | ||
| 50 | int i, r; | ||
| 51 | |||
| 52 | self = pthread_self(); | ||
| 53 | real_func = func; | ||
| 54 | if ((r = pthread_rwlock_init(&start, NULL))) | ||
| 55 | errx(1, "could not initialize lock: %s", strerror(r)); | ||
| 56 | |||
| 57 | if ((r = pthread_rwlock_wrlock(&start))) /* block */ | ||
| 58 | errx(1, "could not lock lock: %s", strerror(r)); | ||
| 59 | |||
| 60 | for (i = 0; i < THREAD_COUNT; i++) | ||
| 61 | if ((r = pthread_create(&pthread[i], NULL, thread, arg))) { | ||
| 62 | warnx("could not create thread: %s", strerror(r)); | ||
| 63 | pthread[i] = self; | ||
| 64 | } | ||
| 65 | |||
| 66 | |||
| 67 | if ((r = pthread_rwlock_unlock(&start))) /* unleash */ | ||
| 68 | errx(1, "could not release lock: %s", strerror(r)); | ||
| 69 | |||
| 70 | sleep(1); | ||
| 71 | |||
| 72 | if ((r = pthread_rwlock_wrlock(&start))) /* sync */ | ||
| 73 | errx(1, "parent could not sync with children: %s", | ||
| 74 | strerror(r)); | ||
| 75 | |||
| 76 | for (i = 0; i < THREAD_COUNT; i++) | ||
| 77 | if (! pthread_equal(pthread[i], self) && | ||
| 78 | (r = pthread_join(pthread[i], NULL))) | ||
| 79 | warnx("could not join thread: %s", strerror(r)); | ||
| 80 | } | ||
| 81 | |||
diff --git a/src/regress/lib/libc/strerror/Makefile b/src/regress/lib/libc/strerror/Makefile new file mode 100644 index 0000000000..448b6da903 --- /dev/null +++ b/src/regress/lib/libc/strerror/Makefile | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2004/04/30 17:15:12 espie Exp $ | ||
| 2 | |||
| 3 | NOMAN= | ||
| 4 | PROG=strerror_test | ||
| 5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
| 6 | CLEANFILES+= invalid.out valid.out | ||
| 7 | |||
| 8 | run-regress-strerror_test: ${PROG} | ||
| 9 | ./${PROG} >${.OBJDIR}/valid.out | ||
| 10 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok | ||
| 11 | |||
| 12 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strerror/strerror_test.c b/src/regress/lib/libc/strerror/strerror_test.c new file mode 100644 index 0000000000..700080cd3e --- /dev/null +++ b/src/regress/lib/libc/strerror/strerror_test.c | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | /* $OpenBSD: strerror_test.c,v 1.4 2005/05/13 07:06:20 otto Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | #include <signal.h> | ||
| 18 | #include <string.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <limits.h> | ||
| 21 | #include <errno.h> | ||
| 22 | |||
| 23 | void | ||
| 24 | check_strerror_r(int val) | ||
| 25 | { | ||
| 26 | char buffer[NL_TEXTMAX + 1]; | ||
| 27 | int i, r; | ||
| 28 | |||
| 29 | memset(buffer, 'X', sizeof(buffer) - 1); | ||
| 30 | buffer[sizeof(buffer) - 1] = '\0'; | ||
| 31 | (void)strerror_r(val, NULL, 0); /* XXX */ | ||
| 32 | for (i = 0; i < 25; i++) { | ||
| 33 | r = strerror_r(val, buffer, i); | ||
| 34 | printf("%d %d %zu: %s\n", i, r, strlen(buffer), buffer); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | void | ||
| 39 | check_strsignal(int val) | ||
| 40 | { | ||
| 41 | char buffer[NL_TEXTMAX + 1]; | ||
| 42 | int i, r; | ||
| 43 | |||
| 44 | memset(buffer, 'X', sizeof(buffer) - 1); | ||
| 45 | buffer[sizeof(buffer) - 1] = '\0'; | ||
| 46 | (void)__strsignal(val, buffer); | ||
| 47 | printf("%s\n", buffer); | ||
| 48 | } | ||
| 49 | |||
| 50 | int | ||
| 51 | main() | ||
| 52 | { | ||
| 53 | printf("%s\n", strerror(21345)); | ||
| 54 | printf("%s\n", strerror(-21345)); | ||
| 55 | printf("%s\n", strerror(0)); | ||
| 56 | printf("%s\n", strerror(INT_MAX)); | ||
| 57 | printf("%s\n", strerror(INT_MIN)); | ||
| 58 | printf("%s\n", strerror(EPERM)); | ||
| 59 | check_strerror_r(EPERM); | ||
| 60 | check_strerror_r(21345); | ||
| 61 | check_strsignal(-1); | ||
| 62 | check_strsignal(0); | ||
| 63 | check_strsignal(10); | ||
| 64 | check_strsignal(NSIG-1); | ||
| 65 | check_strsignal(NSIG); | ||
| 66 | check_strsignal(100); | ||
| 67 | check_strsignal(INT_MAX); | ||
| 68 | check_strsignal(INT_MIN); | ||
| 69 | check_strsignal(UINT_MAX); | ||
| 70 | return 0; | ||
| 71 | } | ||
diff --git a/src/regress/lib/libc/strerror/valid.ok b/src/regress/lib/libc/strerror/valid.ok new file mode 100644 index 0000000000..cbc365c598 --- /dev/null +++ b/src/regress/lib/libc/strerror/valid.ok | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | Unknown error: 21345 | ||
| 2 | Unknown error: -21345 | ||
| 3 | Undefined error: 0 | ||
| 4 | Unknown error: 2147483647 | ||
| 5 | Unknown error: -2147483648 | ||
| 6 | Operation not permitted | ||
| 7 | 0 34 255: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
| 8 | 1 34 0: | ||
| 9 | 2 34 1: O | ||
| 10 | 3 34 2: Op | ||
| 11 | 4 34 3: Ope | ||
| 12 | 5 34 4: Oper | ||
| 13 | 6 34 5: Opera | ||
| 14 | 7 34 6: Operat | ||
| 15 | 8 34 7: Operati | ||
| 16 | 9 34 8: Operatio | ||
| 17 | 10 34 9: Operation | ||
| 18 | 11 34 10: Operation | ||
| 19 | 12 34 11: Operation n | ||
| 20 | 13 34 12: Operation no | ||
| 21 | 14 34 13: Operation not | ||
| 22 | 15 34 14: Operation not | ||
| 23 | 16 34 15: Operation not p | ||
| 24 | 17 34 16: Operation not pe | ||
| 25 | 18 34 17: Operation not per | ||
| 26 | 19 34 18: Operation not perm | ||
| 27 | 20 34 19: Operation not permi | ||
| 28 | 21 34 20: Operation not permit | ||
| 29 | 22 34 21: Operation not permitt | ||
| 30 | 23 34 22: Operation not permitte | ||
| 31 | 24 0 23: Operation not permitted | ||
| 32 | 0 34 255: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
| 33 | 1 34 0: | ||
| 34 | 2 34 1: U | ||
| 35 | 3 34 2: Un | ||
| 36 | 4 34 3: Unk | ||
| 37 | 5 34 4: Unkn | ||
| 38 | 6 34 5: Unkno | ||
| 39 | 7 34 6: Unknow | ||
| 40 | 8 34 7: Unknown | ||
| 41 | 9 34 8: Unknown | ||
| 42 | 10 34 9: Unknown e | ||
| 43 | 11 34 10: Unknown er | ||
| 44 | 12 34 11: Unknown err | ||
| 45 | 13 34 12: Unknown erro | ||
| 46 | 14 34 13: Unknown error | ||
| 47 | 15 34 14: Unknown error: | ||
| 48 | 16 34 15: Unknown error: | ||
| 49 | 17 34 15: Unknown error: | ||
| 50 | 18 34 15: Unknown error: | ||
| 51 | 19 34 15: Unknown error: | ||
| 52 | 20 34 15: Unknown error: | ||
| 53 | 21 22 20: Unknown error: 21345 | ||
| 54 | 22 22 20: Unknown error: 21345 | ||
| 55 | 23 22 20: Unknown error: 21345 | ||
| 56 | 24 22 20: Unknown error: 21345 | ||
| 57 | Unknown signal: 4294967295 | ||
| 58 | Signal 0 | ||
| 59 | Bus error | ||
| 60 | Thread AST | ||
| 61 | Unknown signal: 33 | ||
| 62 | Unknown signal: 100 | ||
| 63 | Unknown signal: 2147483647 | ||
| 64 | Unknown signal: 2147483648 | ||
| 65 | Unknown signal: 4294967295 | ||
diff --git a/src/regress/lib/libc/strnlen/Makefile b/src/regress/lib/libc/strnlen/Makefile new file mode 100644 index 0000000000..e7c74972e1 --- /dev/null +++ b/src/regress/lib/libc/strnlen/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2010/06/02 12:20:47 millert Exp $ | ||
| 2 | |||
| 3 | PROG= strnlentest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strnlen/strnlentest.c b/src/regress/lib/libc/strnlen/strnlentest.c new file mode 100644 index 0000000000..e67e6adfb8 --- /dev/null +++ b/src/regress/lib/libc/strnlen/strnlentest.c | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | /* $OpenBSD: strnlentest.c,v 1.1 2010/06/02 12:20:47 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <sys/types.h> | ||
| 20 | |||
| 21 | #include <stdio.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <unistd.h> | ||
| 25 | |||
| 26 | int main(int argc, char *argv[]) | ||
| 27 | { | ||
| 28 | char *buf; | ||
| 29 | int failures = 0; | ||
| 30 | size_t len, bufsize; | ||
| 31 | |||
| 32 | /* Enable malloc security options. */ | ||
| 33 | setenv("MALLOC_OPTIONS", "S", 0); | ||
| 34 | |||
| 35 | bufsize = getpagesize(); /* trigger guard pages easily */ | ||
| 36 | buf = malloc(bufsize); | ||
| 37 | if (buf == NULL) { | ||
| 38 | fprintf(stderr, "unable to allocate memory\n"); | ||
| 39 | return 1; | ||
| 40 | } | ||
| 41 | memset(buf, 'a', bufsize); | ||
| 42 | |||
| 43 | len = strnlen(buf, bufsize); | ||
| 44 | if (len != bufsize) { | ||
| 45 | fprintf(stderr, "strnlen: failed unterminated buffer test (1)"); | ||
| 46 | failures++; | ||
| 47 | } | ||
| 48 | |||
| 49 | len = strnlen(buf, bufsize / 2); | ||
| 50 | if (len != bufsize / 2) { | ||
| 51 | fprintf(stderr, "strnlen: failed unterminated buffer test (2)"); | ||
| 52 | failures++; | ||
| 53 | } | ||
| 54 | |||
| 55 | buf[bufsize - 1] = '\0'; | ||
| 56 | len = strnlen(buf, bufsize); | ||
| 57 | if (len != bufsize - 1) { | ||
| 58 | fprintf(stderr, "strnlen: failed NUL-terminated buffer test (1)"); | ||
| 59 | failures++; | ||
| 60 | } | ||
| 61 | |||
| 62 | len = strnlen(buf, (size_t)-1); | ||
| 63 | if (len != bufsize - 1) { | ||
| 64 | fprintf(stderr, "strnlen: failed NUL-terminated buffer test (2)"); | ||
| 65 | failures++; | ||
| 66 | } | ||
| 67 | |||
| 68 | return failures; | ||
| 69 | } | ||
diff --git a/src/regress/lib/libc/strtod/Makefile b/src/regress/lib/libc/strtod/Makefile new file mode 100644 index 0000000000..030c0e7f56 --- /dev/null +++ b/src/regress/lib/libc/strtod/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2006/09/29 11:00:24 otto Exp $ | ||
| 2 | |||
| 3 | PROG= strtodtest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strtod/strtodtest.c b/src/regress/lib/libc/strtod/strtodtest.c new file mode 100644 index 0000000000..0291365a75 --- /dev/null +++ b/src/regress/lib/libc/strtod/strtodtest.c | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | /* $OpenBSD: strtodtest.c,v 1.1 2006/09/29 11:00:24 otto Exp $ */ | ||
| 2 | /* Public domain, Otto Moerbeek <otto@drijf.net>, 2006. */ | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <errno.h> | ||
| 7 | |||
| 8 | /* | ||
| 9 | * Checks if strtod() reports underflow. | ||
| 10 | */ | ||
| 11 | |||
| 12 | int | ||
| 13 | main() | ||
| 14 | { | ||
| 15 | char *tmp="0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"; | ||
| 16 | double d; | ||
| 17 | |||
| 18 | d = strtod(tmp, NULL); | ||
| 19 | if (errno != ERANGE) | ||
| 20 | errx(1, "errno = %d", errno); | ||
| 21 | return (0); | ||
| 22 | } | ||
diff --git a/src/regress/lib/libc/strtonum/Makefile b/src/regress/lib/libc/strtonum/Makefile new file mode 100644 index 0000000000..e0e8ecd139 --- /dev/null +++ b/src/regress/lib/libc/strtonum/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2004/08/03 20:38:36 otto Exp $ | ||
| 2 | |||
| 3 | PROG= strtonumtest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strtonum/strtonumtest.c b/src/regress/lib/libc/strtonum/strtonumtest.c new file mode 100644 index 0000000000..7e82a007fe --- /dev/null +++ b/src/regress/lib/libc/strtonum/strtonumtest.c | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | /* $OpenBSD: strtonumtest.c,v 1.1 2004/08/03 20:38:36 otto Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2004 Otto Moerbeek <otto@drijf.net> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <limits.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | |||
| 22 | int fail; | ||
| 23 | |||
| 24 | void | ||
| 25 | test(const char *p, long long lb, long long ub, int ok) | ||
| 26 | { | ||
| 27 | long long val; | ||
| 28 | const char *q; | ||
| 29 | |||
| 30 | val = strtonum(p, lb, ub, &q); | ||
| 31 | if (ok && q != NULL) { | ||
| 32 | fprintf(stderr, "%s [%lld-%lld] ", p, lb, ub); | ||
| 33 | fprintf(stderr, "NUMBER NOT ACCEPTED %s\n", q); | ||
| 34 | fail = 1; | ||
| 35 | } else if (!ok && q == NULL) { | ||
| 36 | fprintf(stderr, "%s [%lld-%lld] %lld ", p, lb, ub, val); | ||
| 37 | fprintf(stderr, "NUMBER ACCEPTED\n"); | ||
| 38 | fail = 1; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | int main(int argc, char *argv[]) | ||
| 43 | { | ||
| 44 | test("1", 0, 10, 1); | ||
| 45 | test("0", -2, 5, 1); | ||
| 46 | test("0", 2, 5, 0); | ||
| 47 | test("0", 2, LLONG_MAX, 0); | ||
| 48 | test("-2", 0, LLONG_MAX, 0); | ||
| 49 | test("0", -5, LLONG_MAX, 1); | ||
| 50 | test("-3", -3, LLONG_MAX, 1); | ||
| 51 | test("-9223372036854775808", LLONG_MIN, LLONG_MAX, 1); | ||
| 52 | test("9223372036854775807", LLONG_MIN, LLONG_MAX, 1); | ||
| 53 | test("-9223372036854775809", LLONG_MIN, LLONG_MAX, 0); | ||
| 54 | test("9223372036854775808", LLONG_MIN, LLONG_MAX, 0); | ||
| 55 | test("1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0); | ||
| 56 | test("-1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0); | ||
| 57 | test("-2", 10, -1, 0); | ||
| 58 | test("-2", -10, -1, 1); | ||
| 59 | test("-20", -10, -1, 0); | ||
| 60 | test("20", -10, -1, 0); | ||
| 61 | |||
| 62 | return (fail); | ||
| 63 | } | ||
| 64 | |||
diff --git a/src/regress/lib/libc/telldir/Makefile b/src/regress/lib/libc/telldir/Makefile new file mode 100644 index 0000000000..0927779663 --- /dev/null +++ b/src/regress/lib/libc/telldir/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2006/03/25 20:27:11 otto Exp $ | ||
| 2 | |||
| 3 | PROG= telldir | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/telldir/telldir.c b/src/regress/lib/libc/telldir/telldir.c new file mode 100644 index 0000000000..fc1ca3e891 --- /dev/null +++ b/src/regress/lib/libc/telldir/telldir.c | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | /* $OpenBSD: telldir.c,v 1.2 2006/04/01 18:24:53 otto Exp $ */ | ||
| 2 | |||
| 3 | /* Written by Otto Moerbeek, 2006, Public domain. */ | ||
| 4 | |||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/stat.h> | ||
| 7 | #include <dirent.h> | ||
| 8 | #include <err.h> | ||
| 9 | #include <limits.h> | ||
| 10 | #include <fcntl.h> | ||
| 11 | #include <stdio.h> | ||
| 12 | #include <string.h> | ||
| 13 | #include <unistd.h> | ||
| 14 | |||
| 15 | |||
| 16 | #define NFILES 1000 | ||
| 17 | |||
| 18 | void | ||
| 19 | createfiles(void) | ||
| 20 | { | ||
| 21 | int i, fd; | ||
| 22 | char file[PATH_MAX]; | ||
| 23 | |||
| 24 | mkdir("d", 0755); | ||
| 25 | for (i = 0; i < NFILES; i++) { | ||
| 26 | snprintf(file, sizeof file, "d/%d", i); | ||
| 27 | if ((fd = open(file, O_CREAT | O_WRONLY, 0600)) == -1) | ||
| 28 | err(1, "open %s", file); | ||
| 29 | close(fd); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | void | ||
| 34 | delfiles(void) | ||
| 35 | { | ||
| 36 | DIR *dp; | ||
| 37 | struct dirent *f; | ||
| 38 | char file[PATH_MAX]; | ||
| 39 | |||
| 40 | dp = opendir("d"); | ||
| 41 | if (dp == NULL) | ||
| 42 | err(1, "opendir"); | ||
| 43 | while (f = readdir(dp)) { | ||
| 44 | if (strcmp(f->d_name, ".") == 0 || | ||
| 45 | strcmp(f->d_name, "..") == 0) | ||
| 46 | continue; | ||
| 47 | snprintf(file, sizeof file, "d/%s", f->d_name); | ||
| 48 | if (unlink(file) == -1) | ||
| 49 | err(1, "unlink %s", f->d_name); | ||
| 50 | } | ||
| 51 | closedir(dp); | ||
| 52 | if (rmdir("d") == -1) | ||
| 53 | err(1, "rmdir"); | ||
| 54 | } | ||
| 55 | |||
| 56 | void | ||
| 57 | loop(DIR *dp, int i) | ||
| 58 | { | ||
| 59 | struct dirent *f; | ||
| 60 | char file[PATH_MAX]; | ||
| 61 | long pos, remember = -1; | ||
| 62 | |||
| 63 | rewinddir(dp); | ||
| 64 | snprintf(file, sizeof file, "%d", i); | ||
| 65 | for (;;) { | ||
| 66 | pos = telldir(dp); | ||
| 67 | f = readdir(dp); | ||
| 68 | if (f == NULL) | ||
| 69 | break; | ||
| 70 | if (strcmp(file, f->d_name) == 0) | ||
| 71 | remember = pos; | ||
| 72 | } | ||
| 73 | if (remember == -1) | ||
| 74 | errx(1, "remember"); | ||
| 75 | seekdir(dp, remember); | ||
| 76 | if (telldir(dp) != remember) | ||
| 77 | errx(1, "tell after seek"); | ||
| 78 | if (telldir(dp) != remember) | ||
| 79 | errx(1, "tell after tell"); | ||
| 80 | f = readdir(dp); | ||
| 81 | if (f == NULL) | ||
| 82 | err(1, "seek to %s %ld", file, remember); | ||
| 83 | |||
| 84 | if (strcmp(f->d_name, file) != 0) | ||
| 85 | err(1, "name mismatch: %s != %s\n", f->d_name, file); | ||
| 86 | } | ||
| 87 | |||
| 88 | int | ||
| 89 | main(void) | ||
| 90 | { | ||
| 91 | DIR *dp; | ||
| 92 | int i; | ||
| 93 | |||
| 94 | createfiles(); | ||
| 95 | |||
| 96 | dp = opendir("d"); | ||
| 97 | if (dp == NULL) | ||
| 98 | err(1, "opendir"); | ||
| 99 | |||
| 100 | for (i = 0; i < NFILES; i++) | ||
| 101 | loop(dp, (i + NFILES/2) % NFILES); | ||
| 102 | |||
| 103 | closedir(dp); | ||
| 104 | delfiles(); | ||
| 105 | return 0; | ||
| 106 | } | ||
diff --git a/src/regress/lib/libc/time/Makefile b/src/regress/lib/libc/time/Makefile new file mode 100644 index 0000000000..28b5556027 --- /dev/null +++ b/src/regress/lib/libc/time/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2004/01/20 16:47:55 millert Exp $ | ||
| 2 | |||
| 3 | SUBDIR+=strptime | ||
| 4 | |||
| 5 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/time/strptime/Makefile b/src/regress/lib/libc/time/strptime/Makefile new file mode 100644 index 0000000000..f2c9ebaf2c --- /dev/null +++ b/src/regress/lib/libc/time/strptime/Makefile | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2004/01/21 18:13:48 david Exp $ | ||
| 2 | |||
| 3 | PROG= strptime_test | ||
| 4 | SRCS= main.c | ||
| 5 | CLEANFILES+= got | ||
| 6 | |||
| 7 | REGRESS_TARGETS=do-reg | ||
| 8 | do-reg: ${PROG} | ||
| 9 | ./${PROG} < ${.CURDIR}/tests > got | ||
| 10 | diff ${.CURDIR}/expected got | ||
| 11 | |||
| 12 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/time/strptime/expected b/src/regress/lib/libc/time/strptime/expected new file mode 100644 index 0000000000..d038d319af --- /dev/null +++ b/src/regress/lib/libc/time/strptime/expected | |||
| @@ -0,0 +1,346 @@ | |||
| 1 | --- ctime --- 1 | ||
| 2 | succeeded | ||
| 3 | 46 27 23 20 0 98 2 -1 | ||
| 4 | |||
| 5 | --- ctime --- 2 | ||
| 6 | succeeded | ||
| 7 | 46 27 23 20 0 98 2 -1 | ||
| 8 | |||
| 9 | --- ctime --- 3 | ||
| 10 | succeeded | ||
| 11 | 46 27 23 20 0 98 2 -1 | ||
| 12 | |||
| 13 | --- %a --- 1 | ||
| 14 | succeeded | ||
| 15 | -1 -1 -1 -1 -1 -1 0 -1 | ||
| 16 | |||
| 17 | --- %a --- 2 | ||
| 18 | succeeded | ||
| 19 | -1 -1 -1 -1 -1 -1 0 -1 | ||
| 20 | |||
| 21 | --- %a --- 3 | ||
| 22 | succeeded | ||
| 23 | -1 -1 -1 -1 -1 -1 1 -1 | ||
| 24 | |||
| 25 | --- %a --- 4 | ||
| 26 | succeeded | ||
| 27 | -1 -1 -1 -1 -1 -1 1 -1 | ||
| 28 | |||
| 29 | --- %a --- 5 | ||
| 30 | succeeded | ||
| 31 | -1 -1 -1 -1 -1 -1 2 -1 | ||
| 32 | |||
| 33 | --- %a --- 6 | ||
| 34 | succeeded | ||
| 35 | -1 -1 -1 -1 -1 -1 2 -1 | ||
| 36 | |||
| 37 | --- %a --- 7 | ||
| 38 | succeeded | ||
| 39 | -1 -1 -1 -1 -1 -1 3 -1 | ||
| 40 | |||
| 41 | --- %a --- 8 | ||
| 42 | succeeded | ||
| 43 | -1 -1 -1 -1 -1 -1 3 -1 | ||
| 44 | |||
| 45 | --- %a --- 9 | ||
| 46 | succeeded | ||
| 47 | -1 -1 -1 -1 -1 -1 4 -1 | ||
| 48 | |||
| 49 | --- %a --- 10 | ||
| 50 | succeeded | ||
| 51 | -1 -1 -1 -1 -1 -1 4 -1 | ||
| 52 | |||
| 53 | --- %a --- 11 | ||
| 54 | succeeded | ||
| 55 | -1 -1 -1 -1 -1 -1 5 -1 | ||
| 56 | |||
| 57 | --- %a --- 12 | ||
| 58 | succeeded | ||
| 59 | -1 -1 -1 -1 -1 -1 5 -1 | ||
| 60 | |||
| 61 | --- %a --- 13 | ||
| 62 | succeeded | ||
| 63 | -1 -1 -1 -1 -1 -1 6 -1 | ||
| 64 | |||
| 65 | --- %a --- 14 | ||
| 66 | succeeded | ||
| 67 | -1 -1 -1 -1 -1 -1 6 -1 | ||
| 68 | |||
| 69 | --- %a --- 15 | ||
| 70 | succeeded | ||
| 71 | -1 -1 -1 -1 -1 -1 6 -1 | ||
| 72 | urn | ||
| 73 | |||
| 74 | --- %a --- 16 | ||
| 75 | failed | ||
| 76 | --- %A --- 1 | ||
| 77 | succeeded | ||
| 78 | -1 -1 -1 -1 -1 -1 0 -1 | ||
| 79 | |||
| 80 | --- %A --- 2 | ||
| 81 | succeeded | ||
| 82 | -1 -1 -1 -1 -1 -1 0 -1 | ||
| 83 | |||
| 84 | --- %A --- 3 | ||
| 85 | succeeded | ||
| 86 | -1 -1 -1 -1 -1 -1 1 -1 | ||
| 87 | |||
| 88 | --- %A --- 4 | ||
| 89 | succeeded | ||
| 90 | -1 -1 -1 -1 -1 -1 1 -1 | ||
| 91 | |||
| 92 | --- %A --- 5 | ||
| 93 | succeeded | ||
| 94 | -1 -1 -1 -1 -1 -1 2 -1 | ||
| 95 | |||
| 96 | --- %A --- 6 | ||
| 97 | succeeded | ||
| 98 | -1 -1 -1 -1 -1 -1 2 -1 | ||
| 99 | |||
| 100 | --- %A --- 7 | ||
| 101 | succeeded | ||
| 102 | -1 -1 -1 -1 -1 -1 3 -1 | ||
| 103 | |||
| 104 | --- %A --- 8 | ||
| 105 | succeeded | ||
| 106 | -1 -1 -1 -1 -1 -1 3 -1 | ||
| 107 | |||
| 108 | --- %A --- 9 | ||
| 109 | succeeded | ||
| 110 | -1 -1 -1 -1 -1 -1 4 -1 | ||
| 111 | |||
| 112 | --- %A --- 10 | ||
| 113 | succeeded | ||
| 114 | -1 -1 -1 -1 -1 -1 4 -1 | ||
| 115 | |||
| 116 | --- %A --- 11 | ||
| 117 | succeeded | ||
| 118 | -1 -1 -1 -1 -1 -1 5 -1 | ||
| 119 | |||
| 120 | --- %A --- 12 | ||
| 121 | succeeded | ||
| 122 | -1 -1 -1 -1 -1 -1 5 -1 | ||
| 123 | |||
| 124 | --- %A --- 13 | ||
| 125 | succeeded | ||
| 126 | -1 -1 -1 -1 -1 -1 6 -1 | ||
| 127 | |||
| 128 | --- %A --- 14 | ||
| 129 | succeeded | ||
| 130 | -1 -1 -1 -1 -1 -1 6 -1 | ||
| 131 | |||
| 132 | --- %A --- 15 | ||
| 133 | succeeded | ||
| 134 | -1 -1 -1 -1 -1 -1 6 -1 | ||
| 135 | urn | ||
| 136 | |||
| 137 | --- %A --- 16 | ||
| 138 | failed | ||
| 139 | --- %b --- 1 | ||
| 140 | succeeded | ||
| 141 | -1 -1 -1 -1 0 -1 -1 -1 | ||
| 142 | |||
| 143 | --- %b --- 2 | ||
| 144 | succeeded | ||
| 145 | -1 -1 -1 -1 0 -1 -1 -1 | ||
| 146 | |||
| 147 | --- %b --- 3 | ||
| 148 | succeeded | ||
| 149 | -1 -1 -1 -1 1 -1 -1 -1 | ||
| 150 | |||
| 151 | --- %b --- 4 | ||
| 152 | succeeded | ||
| 153 | -1 -1 -1 -1 1 -1 -1 -1 | ||
| 154 | |||
| 155 | --- %b --- 5 | ||
| 156 | succeeded | ||
| 157 | -1 -1 -1 -1 2 -1 -1 -1 | ||
| 158 | |||
| 159 | --- %b --- 6 | ||
| 160 | succeeded | ||
| 161 | -1 -1 -1 -1 2 -1 -1 -1 | ||
| 162 | |||
| 163 | --- %b --- 7 | ||
| 164 | succeeded | ||
| 165 | -1 -1 -1 -1 3 -1 -1 -1 | ||
| 166 | |||
| 167 | --- %b --- 8 | ||
| 168 | succeeded | ||
| 169 | -1 -1 -1 -1 3 -1 -1 -1 | ||
| 170 | |||
| 171 | --- %b --- 9 | ||
| 172 | succeeded | ||
| 173 | -1 -1 -1 -1 4 -1 -1 -1 | ||
| 174 | |||
| 175 | --- %b --- 10 | ||
| 176 | succeeded | ||
| 177 | -1 -1 -1 -1 5 -1 -1 -1 | ||
| 178 | |||
| 179 | --- %b --- 11 | ||
| 180 | succeeded | ||
| 181 | -1 -1 -1 -1 5 -1 -1 -1 | ||
| 182 | |||
| 183 | --- %b --- 12 | ||
| 184 | succeeded | ||
| 185 | -1 -1 -1 -1 6 -1 -1 -1 | ||
| 186 | |||
| 187 | --- %b --- 13 | ||
| 188 | succeeded | ||
| 189 | -1 -1 -1 -1 6 -1 -1 -1 | ||
| 190 | |||
| 191 | --- %b --- 14 | ||
| 192 | succeeded | ||
| 193 | -1 -1 -1 -1 7 -1 -1 -1 | ||
| 194 | |||
| 195 | --- %b --- 15 | ||
| 196 | succeeded | ||
| 197 | -1 -1 -1 -1 7 -1 -1 -1 | ||
| 198 | |||
| 199 | --- %b --- 16 | ||
| 200 | succeeded | ||
| 201 | -1 -1 -1 -1 8 -1 -1 -1 | ||
| 202 | |||
| 203 | --- %b --- 17 | ||
| 204 | succeeded | ||
| 205 | -1 -1 -1 -1 8 -1 -1 -1 | ||
| 206 | |||
| 207 | --- %b --- 18 | ||
| 208 | succeeded | ||
| 209 | -1 -1 -1 -1 9 -1 -1 -1 | ||
| 210 | |||
| 211 | --- %b --- 19 | ||
| 212 | succeeded | ||
| 213 | -1 -1 -1 -1 9 -1 -1 -1 | ||
| 214 | |||
| 215 | --- %b --- 20 | ||
| 216 | succeeded | ||
| 217 | -1 -1 -1 -1 10 -1 -1 -1 | ||
| 218 | |||
| 219 | --- %b --- 21 | ||
| 220 | succeeded | ||
| 221 | -1 -1 -1 -1 10 -1 -1 -1 | ||
| 222 | |||
| 223 | --- %b --- 22 | ||
| 224 | succeeded | ||
| 225 | -1 -1 -1 -1 11 -1 -1 -1 | ||
| 226 | |||
| 227 | --- %b --- 23 | ||
| 228 | succeeded | ||
| 229 | -1 -1 -1 -1 11 -1 -1 -1 | ||
| 230 | |||
| 231 | --- %b --- 25 | ||
| 232 | succeeded | ||
| 233 | -1 -1 -1 -1 4 -1 -1 -1 | ||
| 234 | or | ||
| 235 | |||
| 236 | --- %b --- 24 | ||
| 237 | succeeded | ||
| 238 | -1 -1 -1 -1 2 -1 -1 -1 | ||
| 239 | s | ||
| 240 | |||
| 241 | --- %b --- 26 | ||
| 242 | failed | ||
| 243 | --- %B --- 1 | ||
| 244 | succeeded | ||
| 245 | -1 -1 -1 -1 0 -1 -1 -1 | ||
| 246 | |||
| 247 | --- %B --- 2 | ||
| 248 | succeeded | ||
| 249 | -1 -1 -1 -1 0 -1 -1 -1 | ||
| 250 | |||
| 251 | --- %B --- 3 | ||
| 252 | succeeded | ||
| 253 | -1 -1 -1 -1 1 -1 -1 -1 | ||
| 254 | |||
| 255 | --- %B --- 4 | ||
| 256 | succeeded | ||
| 257 | -1 -1 -1 -1 1 -1 -1 -1 | ||
| 258 | |||
| 259 | --- %B --- 5 | ||
| 260 | succeeded | ||
| 261 | -1 -1 -1 -1 2 -1 -1 -1 | ||
| 262 | |||
| 263 | --- %B --- 6 | ||
| 264 | succeeded | ||
| 265 | -1 -1 -1 -1 2 -1 -1 -1 | ||
| 266 | |||
| 267 | --- %B --- 7 | ||
| 268 | succeeded | ||
| 269 | -1 -1 -1 -1 3 -1 -1 -1 | ||
| 270 | |||
| 271 | --- %B --- 8 | ||
| 272 | succeeded | ||
| 273 | -1 -1 -1 -1 3 -1 -1 -1 | ||
| 274 | |||
| 275 | --- %B --- 9 | ||
| 276 | succeeded | ||
| 277 | -1 -1 -1 -1 4 -1 -1 -1 | ||
| 278 | |||
| 279 | --- %B --- 10 | ||
| 280 | succeeded | ||
| 281 | -1 -1 -1 -1 5 -1 -1 -1 | ||
| 282 | |||
| 283 | --- %B --- 11 | ||
| 284 | succeeded | ||
| 285 | -1 -1 -1 -1 5 -1 -1 -1 | ||
| 286 | |||
| 287 | --- %B --- 12 | ||
| 288 | succeeded | ||
| 289 | -1 -1 -1 -1 6 -1 -1 -1 | ||
| 290 | |||
| 291 | --- %B --- 13 | ||
| 292 | succeeded | ||
| 293 | -1 -1 -1 -1 6 -1 -1 -1 | ||
| 294 | |||
| 295 | --- %B --- 14 | ||
| 296 | succeeded | ||
| 297 | -1 -1 -1 -1 7 -1 -1 -1 | ||
| 298 | |||
| 299 | --- %B --- 15 | ||
| 300 | succeeded | ||
| 301 | -1 -1 -1 -1 7 -1 -1 -1 | ||
| 302 | |||
| 303 | --- %B --- 16 | ||
| 304 | succeeded | ||
| 305 | -1 -1 -1 -1 8 -1 -1 -1 | ||
| 306 | |||
| 307 | --- %B --- 17 | ||
| 308 | succeeded | ||
| 309 | -1 -1 -1 -1 8 -1 -1 -1 | ||
| 310 | |||
| 311 | --- %B --- 18 | ||
| 312 | succeeded | ||
| 313 | -1 -1 -1 -1 9 -1 -1 -1 | ||
| 314 | |||
| 315 | --- %B --- 19 | ||
| 316 | succeeded | ||
| 317 | -1 -1 -1 -1 9 -1 -1 -1 | ||
| 318 | |||
| 319 | --- %B --- 20 | ||
| 320 | succeeded | ||
| 321 | -1 -1 -1 -1 10 -1 -1 -1 | ||
| 322 | |||
| 323 | --- %B --- 21 | ||
| 324 | succeeded | ||
| 325 | -1 -1 -1 -1 10 -1 -1 -1 | ||
| 326 | |||
| 327 | --- %B --- 22 | ||
| 328 | succeeded | ||
| 329 | -1 -1 -1 -1 11 -1 -1 -1 | ||
| 330 | |||
| 331 | --- %B --- 23 | ||
| 332 | succeeded | ||
| 333 | -1 -1 -1 -1 11 -1 -1 -1 | ||
| 334 | |||
| 335 | --- %B --- 25 | ||
| 336 | succeeded | ||
| 337 | -1 -1 -1 -1 4 -1 -1 -1 | ||
| 338 | or | ||
| 339 | |||
| 340 | --- %B --- 24 | ||
| 341 | succeeded | ||
| 342 | -1 -1 -1 -1 2 -1 -1 -1 | ||
| 343 | s | ||
| 344 | |||
| 345 | --- %B --- 26 | ||
| 346 | failed | ||
diff --git a/src/regress/lib/libc/time/strptime/main.c b/src/regress/lib/libc/time/strptime/main.c new file mode 100644 index 0000000000..c4e06a9b59 --- /dev/null +++ b/src/regress/lib/libc/time/strptime/main.c | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | /* $OpenBSD: main.c,v 1.2 2008/06/26 05:42:05 ray Exp $ */ | ||
| 2 | /* $NetBSD: main.c,v 1.4 2002/02/21 07:38:18 itojun Exp $ */ | ||
| 3 | |||
| 4 | /*- | ||
| 5 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * | ||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | */ | ||
| 29 | #include <err.h> | ||
| 30 | #include <stdio.h> | ||
| 31 | #include <stdlib.h> | ||
| 32 | #include <string.h> | ||
| 33 | #include <time.h> | ||
| 34 | |||
| 35 | int main(int, char *[]); | ||
| 36 | void die(void); | ||
| 37 | |||
| 38 | void | ||
| 39 | die(void) | ||
| 40 | { | ||
| 41 | |||
| 42 | if (ferror(stdin)) | ||
| 43 | err(1, "fgetln"); | ||
| 44 | else | ||
| 45 | errx(1, "input is truncated"); | ||
| 46 | } | ||
| 47 | |||
| 48 | int | ||
| 49 | main(int argc, char *argv[]) | ||
| 50 | { | ||
| 51 | char *p, *title, *buf, *format; | ||
| 52 | size_t len; | ||
| 53 | struct tm tm; | ||
| 54 | |||
| 55 | for (;;) { | ||
| 56 | p = fgetln(stdin, &len); | ||
| 57 | if (p == 0) | ||
| 58 | die(); | ||
| 59 | title = malloc(len + 1); | ||
| 60 | memcpy(title, p, len); | ||
| 61 | title[len] = '\0'; | ||
| 62 | |||
| 63 | if (!strcmp(title, "EOF\n")) | ||
| 64 | return(0); | ||
| 65 | if (title[0] == '#' || title[0] == '\n') { | ||
| 66 | free(title); | ||
| 67 | continue; | ||
| 68 | } | ||
| 69 | |||
| 70 | p = fgetln(stdin, &len); | ||
| 71 | if (p == 0) | ||
| 72 | die(); | ||
| 73 | buf = malloc(len + 1); | ||
| 74 | memcpy(buf, p, len); | ||
| 75 | buf[len] = '\0'; | ||
| 76 | |||
| 77 | p = fgetln(stdin, &len); | ||
| 78 | if (p == 0) | ||
| 79 | die(); | ||
| 80 | format = malloc(len + 1); | ||
| 81 | memcpy(format, p, len); | ||
| 82 | format[len] = '\0'; | ||
| 83 | |||
| 84 | tm.tm_sec = -1; | ||
| 85 | tm.tm_min = -1; | ||
| 86 | tm.tm_hour = -1; | ||
| 87 | tm.tm_mday = -1; | ||
| 88 | tm.tm_mon = -1; | ||
| 89 | tm.tm_year = -1; | ||
| 90 | tm.tm_wday = -1; | ||
| 91 | tm.tm_yday = -1; | ||
| 92 | |||
| 93 | p = strptime(buf, format, &tm); | ||
| 94 | |||
| 95 | printf("%s", title); | ||
| 96 | if (p) { | ||
| 97 | printf("succeeded\n"); | ||
| 98 | printf("%d %d %d %d %d %d %d %d\n", | ||
| 99 | tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mday, | ||
| 100 | tm.tm_mon, tm.tm_year, tm.tm_wday, tm.tm_yday); | ||
| 101 | printf("%s\n", p); | ||
| 102 | } else { | ||
| 103 | printf("failed\n"); | ||
| 104 | } | ||
| 105 | |||
| 106 | free(title); | ||
| 107 | free(buf); | ||
| 108 | free(format); | ||
| 109 | } | ||
| 110 | } | ||
diff --git a/src/regress/lib/libc/time/strptime/tests b/src/regress/lib/libc/time/strptime/tests new file mode 100644 index 0000000000..d96393b2b7 --- /dev/null +++ b/src/regress/lib/libc/time/strptime/tests | |||
| @@ -0,0 +1,267 @@ | |||
| 1 | # some intial checks to make sure common things work | ||
| 2 | --- ctime --- 1 | ||
| 3 | Tue Jan 20 23:27:46 1998 | ||
| 4 | %a %b %d %T %Y | ||
| 5 | --- ctime --- 2 | ||
| 6 | Tue Jan 20 23:27:46 1998 | ||
| 7 | %a %b %d %H:%M:%S %Y | ||
| 8 | --- ctime --- 3 | ||
| 9 | Tue Jan 20 23:27:46 1998 | ||
| 10 | %c | ||
| 11 | |||
| 12 | # test some valid and invalid day names | ||
| 13 | --- %a --- 1 | ||
| 14 | Sun | ||
| 15 | %a | ||
| 16 | --- %a --- 2 | ||
| 17 | Sunday | ||
| 18 | %a | ||
| 19 | --- %a --- 3 | ||
| 20 | Mon | ||
| 21 | %a | ||
| 22 | --- %a --- 4 | ||
| 23 | Monday | ||
| 24 | %a | ||
| 25 | --- %a --- 5 | ||
| 26 | Tue | ||
| 27 | %a | ||
| 28 | --- %a --- 6 | ||
| 29 | Tuesday | ||
| 30 | %a | ||
| 31 | --- %a --- 7 | ||
| 32 | Wed | ||
| 33 | %a | ||
| 34 | --- %a --- 8 | ||
| 35 | Wednesday | ||
| 36 | %a | ||
| 37 | --- %a --- 9 | ||
| 38 | Thu | ||
| 39 | %a | ||
| 40 | --- %a --- 10 | ||
| 41 | Thursday | ||
| 42 | %a | ||
| 43 | --- %a --- 11 | ||
| 44 | Fri | ||
| 45 | %a | ||
| 46 | --- %a --- 12 | ||
| 47 | Friday | ||
| 48 | %a | ||
| 49 | --- %a --- 13 | ||
| 50 | Sat | ||
| 51 | %a | ||
| 52 | --- %a --- 14 | ||
| 53 | Saturday | ||
| 54 | %a | ||
| 55 | --- %a --- 15 | ||
| 56 | Saturn | ||
| 57 | %a | ||
| 58 | --- %a --- 16 | ||
| 59 | Moon | ||
| 60 | %a | ||
| 61 | --- %A --- 1 | ||
| 62 | Sun | ||
| 63 | %A | ||
| 64 | --- %A --- 2 | ||
| 65 | Sunday | ||
| 66 | %A | ||
| 67 | --- %A --- 3 | ||
| 68 | Mon | ||
| 69 | %A | ||
| 70 | --- %A --- 4 | ||
| 71 | Monday | ||
| 72 | %A | ||
| 73 | --- %A --- 5 | ||
| 74 | Tue | ||
| 75 | %A | ||
| 76 | --- %A --- 6 | ||
| 77 | Tuesday | ||
| 78 | %A | ||
| 79 | --- %A --- 7 | ||
| 80 | Wed | ||
| 81 | %A | ||
| 82 | --- %A --- 8 | ||
| 83 | Wednesday | ||
| 84 | %A | ||
| 85 | --- %A --- 9 | ||
| 86 | Thu | ||
| 87 | %A | ||
| 88 | --- %A --- 10 | ||
| 89 | Thursday | ||
| 90 | %A | ||
| 91 | --- %A --- 11 | ||
| 92 | Fri | ||
| 93 | %A | ||
| 94 | --- %A --- 12 | ||
| 95 | Friday | ||
| 96 | %A | ||
| 97 | --- %A --- 13 | ||
| 98 | Sat | ||
| 99 | %A | ||
| 100 | --- %A --- 14 | ||
| 101 | Saturday | ||
| 102 | %A | ||
| 103 | --- %A --- 15 | ||
| 104 | Saturn | ||
| 105 | %A | ||
| 106 | --- %A --- 16 | ||
| 107 | Moon | ||
| 108 | %A | ||
| 109 | |||
| 110 | # test some valid and invalid month names | ||
| 111 | --- %b --- 1 | ||
| 112 | Jan | ||
| 113 | %b | ||
| 114 | --- %b --- 2 | ||
| 115 | January | ||
| 116 | %b | ||
| 117 | --- %b --- 3 | ||
| 118 | Feb | ||
| 119 | %b | ||
| 120 | --- %b --- 4 | ||
| 121 | February | ||
| 122 | %b | ||
| 123 | --- %b --- 5 | ||
| 124 | Mar | ||
| 125 | %b | ||
| 126 | --- %b --- 6 | ||
| 127 | March | ||
| 128 | %b | ||
| 129 | --- %b --- 7 | ||
| 130 | Apr | ||
| 131 | %b | ||
| 132 | --- %b --- 8 | ||
| 133 | April | ||
| 134 | %b | ||
| 135 | --- %b --- 9 | ||
| 136 | May | ||
| 137 | %b | ||
| 138 | --- %b --- 10 | ||
| 139 | Jun | ||
| 140 | %b | ||
| 141 | --- %b --- 11 | ||
| 142 | June | ||
| 143 | %b | ||
| 144 | --- %b --- 12 | ||
| 145 | Jul | ||
| 146 | %b | ||
| 147 | --- %b --- 13 | ||
| 148 | July | ||
| 149 | %b | ||
| 150 | --- %b --- 14 | ||
| 151 | Aug | ||
| 152 | %b | ||
| 153 | --- %b --- 15 | ||
| 154 | August | ||
| 155 | %b | ||
| 156 | --- %b --- 16 | ||
| 157 | Sep | ||
| 158 | %b | ||
| 159 | --- %b --- 17 | ||
| 160 | September | ||
| 161 | %b | ||
| 162 | --- %b --- 18 | ||
| 163 | Oct | ||
| 164 | %b | ||
| 165 | --- %b --- 19 | ||
| 166 | October | ||
| 167 | %b | ||
| 168 | --- %b --- 20 | ||
| 169 | Nov | ||
| 170 | %b | ||
| 171 | --- %b --- 21 | ||
| 172 | November | ||
| 173 | %b | ||
| 174 | --- %b --- 22 | ||
| 175 | Dec | ||
| 176 | %b | ||
| 177 | --- %b --- 23 | ||
| 178 | December | ||
| 179 | %b | ||
| 180 | --- %b --- 25 | ||
| 181 | Mayor | ||
| 182 | %b | ||
| 183 | --- %b --- 24 | ||
| 184 | Mars | ||
| 185 | %b | ||
| 186 | --- %b --- 26 | ||
| 187 | Rover | ||
| 188 | %b | ||
| 189 | --- %B --- 1 | ||
| 190 | Jan | ||
| 191 | %B | ||
| 192 | --- %B --- 2 | ||
| 193 | January | ||
| 194 | %B | ||
| 195 | --- %B --- 3 | ||
| 196 | Feb | ||
| 197 | %B | ||
| 198 | --- %B --- 4 | ||
| 199 | February | ||
| 200 | %B | ||
| 201 | --- %B --- 5 | ||
| 202 | Mar | ||
| 203 | %B | ||
| 204 | --- %B --- 6 | ||
| 205 | March | ||
| 206 | %B | ||
| 207 | --- %B --- 7 | ||
| 208 | Apr | ||
| 209 | %B | ||
| 210 | --- %B --- 8 | ||
| 211 | April | ||
| 212 | %B | ||
| 213 | --- %B --- 9 | ||
| 214 | May | ||
| 215 | %B | ||
| 216 | --- %B --- 10 | ||
| 217 | Jun | ||
| 218 | %B | ||
| 219 | --- %B --- 11 | ||
| 220 | June | ||
| 221 | %B | ||
| 222 | --- %B --- 12 | ||
| 223 | Jul | ||
| 224 | %B | ||
| 225 | --- %B --- 13 | ||
| 226 | July | ||
| 227 | %B | ||
| 228 | --- %B --- 14 | ||
| 229 | Aug | ||
| 230 | %B | ||
| 231 | --- %B --- 15 | ||
| 232 | August | ||
| 233 | %B | ||
| 234 | --- %B --- 16 | ||
| 235 | Sep | ||
| 236 | %B | ||
| 237 | --- %B --- 17 | ||
| 238 | September | ||
| 239 | %B | ||
| 240 | --- %B --- 18 | ||
| 241 | Oct | ||
| 242 | %B | ||
| 243 | --- %B --- 19 | ||
| 244 | October | ||
| 245 | %B | ||
| 246 | --- %B --- 20 | ||
| 247 | Nov | ||
| 248 | %B | ||
| 249 | --- %B --- 21 | ||
| 250 | November | ||
| 251 | %B | ||
| 252 | --- %B --- 22 | ||
| 253 | Dec | ||
| 254 | %B | ||
| 255 | --- %B --- 23 | ||
| 256 | December | ||
| 257 | %B | ||
| 258 | --- %B --- 25 | ||
| 259 | Mayor | ||
| 260 | %B | ||
| 261 | --- %B --- 24 | ||
| 262 | Mars | ||
| 263 | %B | ||
| 264 | --- %B --- 26 | ||
| 265 | Rover | ||
| 266 | %B | ||
| 267 | EOF | ||
diff --git a/src/regress/lib/libc/vis/Makefile b/src/regress/lib/libc/vis/Makefile new file mode 100644 index 0000000000..13e560bbf7 --- /dev/null +++ b/src/regress/lib/libc/vis/Makefile | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2005/08/29 18:41:56 otto Exp $ | ||
| 2 | |||
| 3 | PROG= vis_test | ||
| 4 | CLEANFILES+= valid.out | ||
| 5 | |||
| 6 | run-regress-vis_test: ${PROG} | ||
| 7 | ./${PROG} >${.OBJDIR}/valid.out | ||
| 8 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/vis/valid.ok b/src/regress/lib/libc/vis/valid.ok new file mode 100644 index 0000000000..f8c0efa503 --- /dev/null +++ b/src/regress/lib/libc/vis/valid.ok | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | \^@\^A\^B\^C\^D\^E\^F\^G\^H | ||
| 2 | \^K\^L\^M\^N\^O\^P\^Q\^R\^S\^T\^U\^V\^W\^X\^Y\^Z\^[\^\\^]\^^\^_ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\^?\M^@\M^A\M^B\M^C\M^D\M^E\M^F\M^G\M^H\M^I\M^J\M^K\M^L\M^M\M^N\M^O\M^P\M^Q\M^R\M^S\M^T\M^U\M^V\M^W\M^X\M^Y\M^Z\M^[\M^\\M^]\M^^\M^_\240\M-!\M-"\M-#\M-$\M-%\M-&\M-'\M-(\M-)\M-*\M-+\M-,\M--\M-.\M-/\M-0\M-1\M-2\M-3\M-4\M-5\M-6\M-7\M-8\M-9\M-:\M-;\M-<\M-=\M->\M-?\M-@\M-A\M-B\M-C\M-D\M-E\M-F\M-G\M-H\M-I\M-J\M-K\M-L\M-M\M-N\M-O\M-P\M-Q\M-R\M-S\M-T\M-U\M-V\M-W\M-X\M-Y\M-Z\M-[\M-\\M-]\M-^\M-_\M-`\M-a\M-b\M-c\M-d\M-e\M-f\M-g\M-h\M-i\M-j\M-k\M-l\M-m\M-n\M-o\M-p\M-q\M-r\M-s\M-t\M-u\M-v\M-w\M-x\M-y\M-z\M-{\M-|\M-}\M-~\M^? | ||
diff --git a/src/regress/lib/libc/vis/vis_test.c b/src/regress/lib/libc/vis/vis_test.c new file mode 100644 index 0000000000..054befd44f --- /dev/null +++ b/src/regress/lib/libc/vis/vis_test.c | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | /* $OpenBSD: vis_test.c,v 1.2 2009/06/21 00:38:22 martynas Exp $ */ | ||
| 2 | |||
| 3 | /* Public domain. 2005, Otto Moerbeek */ | ||
| 4 | |||
| 5 | #include <limits.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <stdio.h> | ||
| 8 | #include <vis.h> | ||
| 9 | |||
| 10 | int | ||
| 11 | main() | ||
| 12 | { | ||
| 13 | char inp[UCHAR_MAX + 1]; | ||
| 14 | char out[4 * UCHAR_MAX + 1]; | ||
| 15 | int i; | ||
| 16 | |||
| 17 | for (i = 0; i <= UCHAR_MAX; i++) { | ||
| 18 | inp[i] = i; | ||
| 19 | } | ||
| 20 | strvisx(out, inp, UCHAR_MAX + 1, 0); | ||
| 21 | printf("%s\n", out); | ||
| 22 | exit(0); | ||
| 23 | } | ||
