summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libc')
-rw-r--r--src/regress/lib/libc/Makefile15
-rw-r--r--src/regress/lib/libc/_setjmp/Makefile11
-rw-r--r--src/regress/lib/libc/arch/alpha/Makefile9
-rw-r--r--src/regress/lib/libc/arch/alpha/divremtest/Makefile30
-rw-r--r--src/regress/lib/libc/arch/alpha/divremtest/divremtest.c184
-rw-r--r--src/regress/lib/libc/arch/alpha/divremtest/mkcases.c64
-rw-r--r--src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c68
-rw-r--r--src/regress/lib/libc/atexit/Makefile12
-rw-r--r--src/regress/lib/libc/atexit/atexit_test.c131
-rw-r--r--src/regress/lib/libc/atexit/invalid.ok4
-rw-r--r--src/regress/lib/libc/atexit/valid.ok5
-rw-r--r--src/regress/lib/libc/db/Makefile22
-rw-r--r--src/regress/lib/libc/db/README69
-rw-r--r--src/regress/lib/libc/db/dbtest.c753
-rw-r--r--src/regress/lib/libc/db/run.test707
-rw-r--r--src/regress/lib/libc/getaddrinfo/Makefile19
-rw-r--r--src/regress/lib/libc/getaddrinfo/answer104
-rw-r--r--src/regress/lib/libc/getaddrinfo/gaitest.c185
-rw-r--r--src/regress/lib/libc/getaddrinfo/testsuite.sh89
-rw-r--r--src/regress/lib/libc/ieeefp/Makefile8
-rw-r--r--src/regress/lib/libc/ieeefp/except/Makefile5
-rw-r--r--src/regress/lib/libc/ieeefp/except/except.c90
-rw-r--r--src/regress/lib/libc/ieeefp/inf/Makefile9
-rw-r--r--src/regress/lib/libc/ieeefp/inf/inf.c16
-rw-r--r--src/regress/lib/libc/ieeefp/round/Makefile5
-rw-r--r--src/regress/lib/libc/ieeefp/round/round.c45
-rw-r--r--src/regress/lib/libc/longjmp/Makefile13
-rw-r--r--src/regress/lib/libc/longjmp/longjmp.c71
-rw-r--r--src/regress/lib/libc/malloc/Makefile5
-rw-r--r--src/regress/lib/libc/malloc/malloc0test.c133
-rw-r--r--src/regress/lib/libc/popen/Makefile5
-rw-r--r--src/regress/lib/libc/popen/popen.c104
-rw-r--r--src/regress/lib/libc/regex/Makefile20
-rw-r--r--src/regress/lib/libc/regex/debug.c245
-rw-r--r--src/regress/lib/libc/regex/debug.ih17
-rw-r--r--src/regress/lib/libc/regex/main.c515
-rw-r--r--src/regress/lib/libc/regex/main.ih22
-rw-r--r--src/regress/lib/libc/regex/split.c319
-rw-r--r--src/regress/lib/libc/regex/tests478
-rw-r--r--src/regress/lib/libc/setjmp-signal/Makefile5
-rw-r--r--src/regress/lib/libc/setjmp-signal/setjmp-signal.c26
-rw-r--r--src/regress/lib/libc/setjmp/Makefile9
-rw-r--r--src/regress/lib/libc/setjmp/jmptest.c138
-rw-r--r--src/regress/lib/libc/sigreturn/Makefile18
-rw-r--r--src/regress/lib/libc/sigreturn/sigret.c181
-rw-r--r--src/regress/lib/libc/sigsetjmp/Makefile19
46 files changed, 5002 insertions, 0 deletions
diff --git a/src/regress/lib/libc/Makefile b/src/regress/lib/libc/Makefile
new file mode 100644
index 0000000000..d383b58371
--- /dev/null
+++ b/src/regress/lib/libc/Makefile
@@ -0,0 +1,15 @@
1# $OpenBSD: Makefile,v 1.9 2002/08/30 07:58:08 dhartmei Exp $
2
3SUBDIR+= _setjmp db getaddrinfo regex setjmp sigsetjmp malloc sigreturn popen
4SUBDIR+= longjmp atexit
5.if (${MACHINE_ARCH} != "vax")
6SUBDIR+= ieeefp
7.endif
8
9.if exists(arch/${MACHINE_ARCH})
10SUBDIR+= arch/${MACHINE_ARCH}
11.endif
12
13install:
14
15.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
4PROG= _setjmptest
5SRCS= jmptest.c
6
7CFLAGS+= -DTEST_U_SETJMP
8
9.PATH: ${.CURDIR}/../setjmp
10
11.include <bsd.regress.mk>
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
5SUBDIR=
6
7install:
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
4PROG= divremtest
5NOMAN=
6
7CLEANFILES+= mkcases cases.c mktestcases testcases
8
9divremtest.c: cases.c
10
11cases.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
22testcases: mktestcases divremtest
23 /bin/rm -f testcases
24 mktestcases | divremtest -g > testcases
25
26regress:
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
39void testfile();
40void usage();
41
42int generate;
43
44int
45main(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
84void
85testfile()
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
178void
179usage()
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
35char *tab[4] = { "u_int", "int", "u_long", "long" };
36
37int
38main()
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
37int
38main()
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..89625e2a7b
--- /dev/null
+++ b/src/regress/lib/libc/atexit/Makefile
@@ -0,0 +1,12 @@
1# $OpenBSD: Makefile,v 1.2 2002/09/02 19:59:51 avsm Exp $
2
3NOMAN=
4PROG=atexit_test
5
6run-regress-atexit_test: ${PROG}
7 ./${PROG} -valid 2>${.OBJDIR}/valid.out
8 cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok
9 ./${PROG} -invalid 2>${.OBJDIR}/invalid.out
10 cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok
11
12.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..fcfe95cb02
--- /dev/null
+++ b/src/regress/lib/libc/atexit/atexit_test.c
@@ -0,0 +1,131 @@
1/* $OpenBSD: atexit_test.c,v 1.1 2002/07/29 19:51:41 dhartmei 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 <signal.h>
40#include "/usr/src/lib/libc/stdlib/atexit.h"
41
42extern struct atexit *__atexit;
43extern void (*__cleanup)();
44
45void handle_first();
46void handle_middle();
47void handle_last();
48void handle_invalid();
49void handle_cleanup();
50void handle_signal(int);
51
52static int counter;
53
54int
55main(int argc, char *argv[])
56{
57 int i;
58
59 if (argc != 2 || (strcmp(argv[1], "-valid") &&
60 strcmp(argv[1], "-invalid"))) {
61 fprintf(stderr, "%s -valid/-invalid\n", 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], "-valid")) {
81 signal(SIGSEGV, handle_signal);
82 __atexit->fns[0] = handle_invalid;
83 }
84 __cleanup = handle_cleanup;
85 counter = 0;
86 fprintf(stderr, "main() returns\n");
87 return (0);
88}
89
90void
91handle_first()
92{
93 fprintf(stderr, "handle_first() counter == %i\n", counter);
94}
95
96void
97handle_middle()
98{
99 counter++;
100}
101
102void
103handle_last()
104{
105 fprintf(stderr, "handle_last() counter == %i\n", counter);
106}
107
108void
109handle_cleanup()
110{
111 fprintf(stderr, "handle_cleanup()\n");
112}
113
114void
115handle_invalid()
116{
117 fprintf(stderr, "handle_invalid() THIS SHOULD HAVE SEGFAULTED INSTEAD!\n");
118}
119
120void
121handle_signal(int sigraised)
122{
123 switch (sigraised) {
124 case SIGSEGV:
125 fprintf(stderr, "SIGSEGV\n");
126 exit(0);
127 default:
128 fprintf(stderr, "unexpected signal caught\n");
129 exit(1);
130 }
131}
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 @@
1main()
2SIGSEGV
3handle_first() counter == 0
4handle_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 @@
1main()
2main() returns
3handle_first() counter == 0
4handle_last() counter == 65535
5handle_cleanup()
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
4PROG= 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
8CFLAGS+= -g -D__DBINTERFACE_PRIVATE -DDEBUG
9CLEANFILES+= t1 t2 t3 log
10
11DBTARGETS=1 2 3 4 5 6 7 8 9 10 11 12 13 20
12
13.for DT in ${DBTARGETS}
14db-${DT}: ${PROG}
15 sh ${.CURDIR}/run.test ${DT}
16REGRESS_TARGETS+=db-${DT}
17.PHONY: db-${DT}
18.endfor
19
20REGRESS_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
5To run the tests, enter "make regress".
6
7Fairly large files (the command files) are built in this directory during
8the 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
10variable TMPDIR to a directory where the files can be built.
11
12=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
13The script file consists of lines with an initial character which is
14the command for that line, or an initial character indicating a key
15or data entry for a previous command.
16
17Legal command characters are as follows:
18
19c: 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.
23e: 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.
26f: set the flags for the next command
27 + no value zero's the flags
28g: do a get command
29 + must be followed by [kK]
30 + writes out the retrieved data DBT.
31o [r]: dump [reverse]
32 + dump the database out, if 'r' is set, in reverse order.
33p: do a put command
34 + must be followed by [kK][dD]
35r: do a del command
36 + must be followed by [kK] unless R_CURSOR flag set.
37S: sync the database
38s: do a seq command
39 + must be followed by [kK] if R_CURSOR flag set.
40 + writes out the retrieved data DBT.
41
42Legal key/data characters are as follows:
43
44D [file]: data file
45 + set the current data value to the contents of the file
46d [data]:
47 + set the current key value to the contents of the line.
48K [file]: key file
49 + set the current key value to the contents of the file
50k [data]:
51 + set the current key value to the contents of the line.
52
53Blank lines, lines with leading white space, and lines with leading
54hash marks (#) are ignored.
55
56Options 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
68Dbtest requires two arguments, the type of access "hash", "recno"
69or "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..a48e19c452
--- /dev/null
+++ b/src/regress/lib/libc/db/dbtest.c
@@ -0,0 +1,753 @@
1/* $OpenBSD: dbtest.c,v 1.9 2002/02/19 19:39:38 millert 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. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#ifndef lint
38static char copyright[] =
39"@(#) Copyright (c) 1992, 1993, 1994\n\
40 The Regents of the University of California. All rights reserved.\n";
41#endif /* not lint */
42
43#ifndef lint
44#if 0
45static char sccsid[] = "@(#)dbtest.c 8.17 (Berkeley) 9/1/94";
46#else
47static char rcsid[] = "$OpenBSD: dbtest.c,v 1.9 2002/02/19 19:39:38 millert Exp $";
48#endif
49#endif /* not lint */
50
51#include <sys/param.h>
52#include <sys/stat.h>
53
54#include <ctype.h>
55#include <errno.h>
56#include <fcntl.h>
57#include <limits.h>
58#include <stdio.h>
59#include <stdlib.h>
60#include <string.h>
61#include <stdarg.h>
62#include <unistd.h>
63
64#include <db.h>
65
66enum S { COMMAND, COMPARE, GET, PUT, REMOVE, SEQ, SEQFLAG, KEY, DATA };
67
68void compare(DBT *, DBT *);
69DBTYPE dbtype(char *);
70void dump(DB *, int);
71void dberr(const char *, ...);
72void get(DB *, DBT *);
73void getdata(DB *, DBT *, DBT *);
74void put(DB *, DBT *, DBT *);
75void rem(DB *, DBT *);
76char *sflags(int);
77void synk(DB *);
78void *rfile(char *, size_t *);
79void seq(DB *, DBT *);
80u_int setflags(char *);
81void *setinfo(DBTYPE, char *);
82void usage(void);
83void *xmalloc(char *, size_t);
84
85DBTYPE type; /* Database type. */
86void *infop; /* Iflags. */
87u_long lineno; /* Current line in test script. */
88u_int flags; /* Current DB flags. */
89int ofd = STDOUT_FILENO; /* Standard output fd. */
90
91DB *XXdbp; /* Global for gdb. */
92int XXlineno; /* Fast breakpoint for gdb. */
93
94int
95main(argc, argv)
96 int argc;
97 char *argv[];
98{
99 extern int optind;
100 extern char *optarg;
101 enum S command, state;
102 DB *dbp;
103 DBT data, key, keydata;
104 size_t len;
105 int ch, oflags, sflag;
106 char *fname, *infoarg, *p, *t, buf[8 * 1024];
107
108 infoarg = NULL;
109 fname = NULL;
110 oflags = O_CREAT | O_RDWR;
111 sflag = 0;
112 while ((ch = getopt(argc, argv, "f:i:lo:s")) != -1)
113 switch (ch) {
114 case 'f':
115 fname = optarg;
116 break;
117 case 'i':
118 infoarg = optarg;
119 break;
120 case 'l':
121 oflags |= DB_LOCK;
122 break;
123 case 'o':
124 if ((ofd = open(optarg,
125 O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
126 dberr("%s: %s", optarg, strerror(errno));
127 break;
128 case 's':
129 sflag = 1;
130 break;
131 case '?':
132 default:
133 usage();
134 }
135 argc -= optind;
136 argv += optind;
137
138 if (argc != 2)
139 usage();
140
141 /* Set the type. */
142 type = dbtype(*argv++);
143
144 /* Open the descriptor file. */
145 if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL)
146 dberr("%s: %s", *argv, strerror(errno));
147
148 /* Set up the db structure as necessary. */
149 if (infoarg == NULL)
150 infop = NULL;
151 else
152 for (p = strtok(infoarg, ",\t "); p != NULL;
153 p = strtok(0, ",\t "))
154 if (*p != '\0')
155 infop = setinfo(type, p);
156
157 /*
158 * Open the DB. Delete any preexisting copy, you almost never
159 * want it around, and it often screws up tests.
160 */
161 if (fname == NULL) {
162 p = getenv("TMPDIR");
163 if (p == NULL)
164 p = "/var/tmp";
165 (void)sprintf(buf, "%s/__dbtest", p);
166 fname = buf;
167 (void)unlink(buf);
168 } else if (!sflag)
169 (void)unlink(fname);
170
171 if ((dbp = dbopen(fname,
172 oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL)
173 dberr("dbopen: %s", strerror(errno));
174 XXdbp = dbp;
175
176 state = COMMAND;
177 for (lineno = 1;
178 (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) {
179 /* Delete the newline, displaying the key/data is easier. */
180 if (ofd == STDOUT_FILENO && (t = strchr(p, '\n')) != NULL)
181 *t = '\0';
182 if ((len = strlen(buf)) == 0 || isspace(*p) || *p == '#')
183 continue;
184
185 /* Convenient gdb break point. */
186 if (XXlineno == lineno)
187 XXlineno = 1;
188 switch (*p) {
189 case 'c': /* compare */
190 if (state != COMMAND)
191 dberr("line %lu: not expecting command",
192 lineno);
193 state = KEY;
194 command = COMPARE;
195 break;
196 case 'e': /* echo */
197 if (state != COMMAND)
198 dberr("line %lu: not expecting command",
199 lineno);
200 /* Don't display the newline, if CR at EOL. */
201 if (p[len - 2] == '\r')
202 --len;
203 if (write(ofd, p + 1, len - 1) != len - 1 ||
204 write(ofd, "\n", 1) != 1)
205 dberr("write: %s", strerror(errno));
206 break;
207 case 'g': /* get */
208 if (state != COMMAND)
209 dberr("line %lu: not expecting command",
210 lineno);
211 state = KEY;
212 command = GET;
213 break;
214 case 'p': /* put */
215 if (state != COMMAND)
216 dberr("line %lu: not expecting command",
217 lineno);
218 state = KEY;
219 command = PUT;
220 break;
221 case 'r': /* remove */
222 if (state != COMMAND)
223 dberr("line %lu: not expecting command",
224 lineno);
225 if (flags == R_CURSOR) {
226 rem(dbp, &key);
227 state = COMMAND;
228 } else {
229 state = KEY;
230 command = REMOVE;
231 }
232 break;
233 case 'S': /* sync */
234 if (state != COMMAND)
235 dberr("line %lu: not expecting command",
236 lineno);
237 synk(dbp);
238 state = COMMAND;
239 break;
240 case 's': /* seq */
241 if (state != COMMAND)
242 dberr("line %lu: not expecting command",
243 lineno);
244 if (flags == R_CURSOR) {
245 state = KEY;
246 command = SEQ;
247 } else
248 seq(dbp, &key);
249 break;
250 case 'f':
251 flags = setflags(p + 1);
252 break;
253 case 'D': /* data file */
254 if (state != DATA)
255 dberr("line %lu: not expecting data", lineno);
256 data.data = rfile(p + 1, &data.size);
257 goto ldata;
258 case 'd': /* data */
259 if (state != DATA)
260 dberr("line %lu: not expecting data", lineno);
261 data.data = xmalloc(p + 1, len - 1);
262 data.size = len - 1;
263ldata: switch (command) {
264 case COMPARE:
265 compare(&keydata, &data);
266 break;
267 case PUT:
268 put(dbp, &key, &data);
269 break;
270 default:
271 dberr("line %lu: command doesn't take data",
272 lineno);
273 }
274 if (type != DB_RECNO)
275 free(key.data);
276 free(data.data);
277 state = COMMAND;
278 break;
279 case 'K': /* key file */
280 if (state != KEY)
281 dberr("line %lu: not expecting a key", lineno);
282 if (type == DB_RECNO)
283 dberr("line %lu: 'K' not available for recno",
284 lineno);
285 key.data = rfile(p + 1, &key.size);
286 goto lkey;
287 case 'k': /* key */
288 if (state != KEY)
289 dberr("line %lu: not expecting a key", lineno);
290 if (type == DB_RECNO) {
291 static recno_t recno;
292 recno = atoi(p + 1);
293 key.data = &recno;
294 key.size = sizeof(recno);
295 } else {
296 key.data = xmalloc(p + 1, len - 1);
297 key.size = len - 1;
298 }
299lkey: switch (command) {
300 case COMPARE:
301 getdata(dbp, &key, &keydata);
302 state = DATA;
303 break;
304 case GET:
305 get(dbp, &key);
306 if (type != DB_RECNO)
307 free(key.data);
308 state = COMMAND;
309 break;
310 case PUT:
311 state = DATA;
312 break;
313 case REMOVE:
314 rem(dbp, &key);
315 if ((type != DB_RECNO) && (flags != R_CURSOR))
316 free(key.data);
317 state = COMMAND;
318 break;
319 case SEQ:
320 seq(dbp, &key);
321 if ((type != DB_RECNO) && (flags != R_CURSOR))
322 free(key.data);
323 state = COMMAND;
324 break;
325 default:
326 dberr("line %lu: command doesn't take a key",
327 lineno);
328 }
329 break;
330 case 'o':
331 dump(dbp, p[1] == 'r');
332 break;
333 default:
334 dberr("line %lu: %s: unknown command character",
335 lineno, p);
336 }
337 }
338#ifdef STATISTICS
339 /*
340 * -l must be used (DB_LOCK must be set) for this to be
341 * used, otherwise a page will be locked and it will fail.
342 */
343 if (type == DB_BTREE && oflags & DB_LOCK)
344 __bt_stat(dbp);
345#endif
346 if (dbp->close(dbp))
347 dberr("db->close: %s", strerror(errno));
348 (void)close(ofd);
349 exit(0);
350}
351
352#define NOOVERWRITE "put failed, would overwrite key\n"
353
354void
355compare(db1, db2)
356 DBT *db1, *db2;
357{
358 register size_t len;
359 register u_char *p1, *p2;
360
361 if (db1->size != db2->size)
362 printf("compare failed: key->data len %lu != data len %lu\n",
363 db1->size, db2->size);
364
365 len = MIN(db1->size, db2->size);
366 for (p1 = db1->data, p2 = db2->data; len--;)
367 if (*p1++ != *p2++) {
368 printf("compare failed at offset %d\n",
369 p1 - (u_char *)db1->data);
370 break;
371 }
372}
373
374void
375get(dbp, kp)
376 DB *dbp;
377 DBT *kp;
378{
379 DBT data;
380
381 switch (dbp->get(dbp, kp, &data, flags)) {
382 case 0:
383 (void)write(ofd, data.data, data.size);
384 if (ofd == STDOUT_FILENO)
385 (void)write(ofd, "\n", 1);
386 break;
387 case -1:
388 dberr("line %lu: get: %s", lineno, strerror(errno));
389 /* NOTREACHED */
390 case 1:
391#define NOSUCHKEY "get failed, no such key\n"
392 if (ofd != STDOUT_FILENO)
393 (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1);
394 else
395 (void)fprintf(stderr, "%d: %.*s: %s",
396 lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY);
397#undef NOSUCHKEY
398 break;
399 }
400}
401
402void
403getdata(dbp, kp, dp)
404 DB *dbp;
405 DBT *kp, *dp;
406{
407 switch (dbp->get(dbp, kp, dp, flags)) {
408 case 0:
409 return;
410 case -1:
411 dberr("line %lu: getdata: %s", lineno, strerror(errno));
412 /* NOTREACHED */
413 case 1:
414 dberr("line %lu: getdata failed, no such key", lineno);
415 /* NOTREACHED */
416 }
417}
418
419void
420put(dbp, kp, dp)
421 DB *dbp;
422 DBT *kp, *dp;
423{
424 switch (dbp->put(dbp, kp, dp, flags)) {
425 case 0:
426 break;
427 case -1:
428 dberr("line %lu: put: %s", lineno, strerror(errno));
429 /* NOTREACHED */
430 case 1:
431 (void)write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1);
432 break;
433 }
434}
435
436void
437rem(dbp, kp)
438 DB *dbp;
439 DBT *kp;
440{
441 switch (dbp->del(dbp, kp, flags)) {
442 case 0:
443 break;
444 case -1:
445 dberr("line %lu: rem: %s", lineno, strerror(errno));
446 /* NOTREACHED */
447 case 1:
448#define NOSUCHKEY "rem failed, no such key\n"
449 if (ofd != STDOUT_FILENO)
450 (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1);
451 else if (flags != R_CURSOR)
452 (void)fprintf(stderr, "%d: %.*s: %s",
453 lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY);
454 else
455 (void)fprintf(stderr,
456 "%d: rem of cursor failed\n", lineno);
457#undef NOSUCHKEY
458 break;
459 }
460}
461
462void
463synk(dbp)
464 DB *dbp;
465{
466 switch (dbp->sync(dbp, flags)) {
467 case 0:
468 break;
469 case -1:
470 dberr("line %lu: synk: %s", lineno, strerror(errno));
471 /* NOTREACHED */
472 }
473}
474
475void
476seq(dbp, kp)
477 DB *dbp;
478 DBT *kp;
479{
480 DBT data;
481
482 switch (dbp->seq(dbp, kp, &data, flags)) {
483 case 0:
484 (void)write(ofd, data.data, data.size);
485 if (ofd == STDOUT_FILENO)
486 (void)write(ofd, "\n", 1);
487 break;
488 case -1:
489 dberr("line %lu: seq: %s", lineno, strerror(errno));
490 /* NOTREACHED */
491 case 1:
492#define NOSUCHKEY "seq failed, no such key\n"
493 if (ofd != STDOUT_FILENO)
494 (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1);
495 else if (flags == R_CURSOR)
496 (void)fprintf(stderr, "%d: %.*s: %s",
497 lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY);
498 else
499 (void)fprintf(stderr,
500 "%d: seq (%s) failed\n", lineno, sflags(flags));
501#undef NOSUCHKEY
502 break;
503 }
504}
505
506void
507dump(dbp, rev)
508 DB *dbp;
509 int rev;
510{
511 DBT key, data;
512 int flags, nflags;
513
514 if (rev) {
515 flags = R_LAST;
516 nflags = R_PREV;
517 } else {
518 flags = R_FIRST;
519 nflags = R_NEXT;
520 }
521 for (;; flags = nflags)
522 switch (dbp->seq(dbp, &key, &data, flags)) {
523 case 0:
524 (void)write(ofd, data.data, data.size);
525 if (ofd == STDOUT_FILENO)
526 (void)write(ofd, "\n", 1);
527 break;
528 case 1:
529 goto done;
530 case -1:
531 dberr("line %lu: (dump) seq: %s",
532 lineno, strerror(errno));
533 /* NOTREACHED */
534 }
535done: return;
536}
537
538u_int
539setflags(s)
540 char *s;
541{
542 char *p;
543
544 for (; isspace(*s); ++s);
545 if (*s == '\n' || *s == '\0')
546 return (0);
547 if ((p = strchr(s, '\n')) != NULL)
548 *p = '\0';
549 if (!strcmp(s, "R_CURSOR")) return (R_CURSOR);
550 if (!strcmp(s, "R_FIRST")) return (R_FIRST);
551 if (!strcmp(s, "R_IAFTER")) return (R_IAFTER);
552 if (!strcmp(s, "R_IBEFORE")) return (R_IBEFORE);
553 if (!strcmp(s, "R_LAST")) return (R_LAST);
554 if (!strcmp(s, "R_NEXT")) return (R_NEXT);
555 if (!strcmp(s, "R_NOOVERWRITE")) return (R_NOOVERWRITE);
556 if (!strcmp(s, "R_PREV")) return (R_PREV);
557 if (!strcmp(s, "R_SETCURSOR")) return (R_SETCURSOR);
558
559 dberr("line %lu: %s: unknown flag", lineno, s);
560 /* NOTREACHED */
561}
562
563char *
564sflags(flags)
565 int flags;
566{
567 switch (flags) {
568 case R_CURSOR: return ("R_CURSOR");
569 case R_FIRST: return ("R_FIRST");
570 case R_IAFTER: return ("R_IAFTER");
571 case R_IBEFORE: return ("R_IBEFORE");
572 case R_LAST: return ("R_LAST");
573 case R_NEXT: return ("R_NEXT");
574 case R_NOOVERWRITE: return ("R_NOOVERWRITE");
575 case R_PREV: return ("R_PREV");
576 case R_SETCURSOR: return ("R_SETCURSOR");
577 }
578
579 return ("UNKNOWN!");
580}
581
582DBTYPE
583dbtype(s)
584 char *s;
585{
586 if (!strcmp(s, "btree"))
587 return (DB_BTREE);
588 if (!strcmp(s, "hash"))
589 return (DB_HASH);
590 if (!strcmp(s, "recno"))
591 return (DB_RECNO);
592 dberr("%s: unknown type (use btree, hash or recno)", s);
593 /* NOTREACHED */
594}
595
596void *
597setinfo(type, s)
598 DBTYPE type;
599 char *s;
600{
601 static BTREEINFO ib;
602 static HASHINFO ih;
603 static RECNOINFO rh;
604 char *eq;
605
606 if ((eq = strchr(s, '=')) == NULL)
607 dberr("%s: illegal structure set statement", s);
608 *eq++ = '\0';
609 if (!isdigit(*eq))
610 dberr("%s: structure set statement must be a number", s);
611
612 switch (type) {
613 case DB_BTREE:
614 if (!strcmp("flags", s)) {
615 ib.flags = atoi(eq);
616 return (&ib);
617 }
618 if (!strcmp("cachesize", s)) {
619 ib.cachesize = atoi(eq);
620 return (&ib);
621 }
622 if (!strcmp("maxkeypage", s)) {
623 ib.maxkeypage = atoi(eq);
624 return (&ib);
625 }
626 if (!strcmp("minkeypage", s)) {
627 ib.minkeypage = atoi(eq);
628 return (&ib);
629 }
630 if (!strcmp("lorder", s)) {
631 ib.lorder = atoi(eq);
632 return (&ib);
633 }
634 if (!strcmp("psize", s)) {
635 ib.psize = atoi(eq);
636 return (&ib);
637 }
638 break;
639 case DB_HASH:
640 if (!strcmp("bsize", s)) {
641 ih.bsize = atoi(eq);
642 return (&ih);
643 }
644 if (!strcmp("ffactor", s)) {
645 ih.ffactor = atoi(eq);
646 return (&ih);
647 }
648 if (!strcmp("nelem", s)) {
649 ih.nelem = atoi(eq);
650 return (&ih);
651 }
652 if (!strcmp("cachesize", s)) {
653 ih.cachesize = atoi(eq);
654 return (&ih);
655 }
656 if (!strcmp("lorder", s)) {
657 ih.lorder = atoi(eq);
658 return (&ih);
659 }
660 break;
661 case DB_RECNO:
662 if (!strcmp("flags", s)) {
663 rh.flags = atoi(eq);
664 return (&rh);
665 }
666 if (!strcmp("cachesize", s)) {
667 rh.cachesize = atoi(eq);
668 return (&rh);
669 }
670 if (!strcmp("lorder", s)) {
671 rh.lorder = atoi(eq);
672 return (&rh);
673 }
674 if (!strcmp("reclen", s)) {
675 rh.reclen = atoi(eq);
676 return (&rh);
677 }
678 if (!strcmp("bval", s)) {
679 rh.bval = atoi(eq);
680 return (&rh);
681 }
682 if (!strcmp("psize", s)) {
683 rh.psize = atoi(eq);
684 return (&rh);
685 }
686 break;
687 }
688 dberr("%s: unknown structure value", s);
689 /* NOTREACHED */
690}
691
692void *
693rfile(name, lenp)
694 char *name;
695 size_t *lenp;
696{
697 struct stat sb;
698 void *p;
699 int fd;
700 char *np;
701
702 for (; isspace(*name); ++name);
703 if ((np = strchr(name, '\n')) != NULL)
704 *np = '\0';
705 if ((fd = open(name, O_RDONLY, 0)) < 0 ||
706 fstat(fd, &sb))
707 dberr("%s: %s\n", name, strerror(errno));
708#ifdef NOT_PORTABLE
709 if (sb.st_size > (off_t)SIZE_T_MAX)
710 dberr("%s: %s\n", name, strerror(E2BIG));
711#endif
712 if ((p = (void *)malloc((u_int)sb.st_size)) == NULL)
713 dberr("%s", strerror(errno));
714 (void)read(fd, p, (int)sb.st_size);
715 *lenp = sb.st_size;
716 (void)close(fd);
717 return (p);
718}
719
720void *
721xmalloc(text, len)
722 char *text;
723 size_t len;
724{
725 void *p;
726
727 if ((p = (void *)malloc(len)) == NULL)
728 dberr("%s", strerror(errno));
729 memmove(p, text, len);
730 return (p);
731}
732
733void
734usage()
735{
736 (void)fprintf(stderr,
737 "usage: dbtest [-l] [-f file] [-i info] [-o file] type script\n");
738 exit(1);
739}
740
741void
742dberr(const char *fmt, ...)
743{
744 va_list ap;
745
746 va_start(ap, fmt);
747 (void)fprintf(stderr, "dbtest: ");
748 (void)vfprintf(stderr, fmt, ap);
749 va_end(ap);
750 (void)fprintf(stderr, "\n");
751 exit(1);
752 /* NOTREACHED */
753}
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
9main()
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.
63test1()
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.
100test2()
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.
137test3()
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.
197test4()
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.
261test5()
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.
297test6()
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
349test7()
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.
392test8()
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
416test9()
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
449test10()
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.
498test11()
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.
534test12()
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.
559test13()
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
596test20()
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:\
636bsize=$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:\
649bsize=$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:\
662bsize=$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:\
675bsize=$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:\
688bsize=$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:\
701bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"
702 exit 1
703 fi
704 done
705}
706
707main $*
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
3PROG= gaitest
4SRCS= gaitest.c
5NOMAN= # defined
6CLEANFILES+= out
7
8REGRESS_TARGETS=do-test
9
10do-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..f626f8f7d8
--- /dev/null
+++ b/src/regress/lib/libc/getaddrinfo/answer
@@ -0,0 +1,104 @@
1== basic ones
2arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv http
3ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv www
4arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv http
5ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv www
6arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv http
7ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv www cname "localhost"
8ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv www cname "localhost"
9arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv tftp
10ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69
11arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv tftp
12ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69
13arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv tftp
14ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 cname "localhost"
15ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 cname "localhost"
16arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv echo
17ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv echo
18ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv echo
19arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv echo
20ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv echo
21ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv echo
22arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv echo
23ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv echo cname "localhost"
24ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv echo cname "localhost"
25ai3: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv echo cname "localhost"
26ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv echo cname "localhost"
27
28== specific address family
29arg: flags 0x2 family 2 socktype 0 protocol 0 addrlen 0 host localhost serv http
30ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv www cname "localhost"
31arg: flags 0x2 family 24 socktype 0 protocol 0 addrlen 0 host localhost serv http
32ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv www cname "localhost"
33
34== empty hostname
35arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http
36ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv www
37ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv www
38arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo
39ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv echo
40ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv echo
41ai3: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv echo
42ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv echo
43arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp
44ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69
45ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69
46arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80
47service not supported for ai_socktype
48arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http
49ai1: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv www
50ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv www
51arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo
52ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv echo
53ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv echo
54ai3: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv echo
55ai4: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv echo
56arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp
57ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 69
58ai2: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 69
59arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80
60service not supported for ai_socktype
61arg: flags 0x2 family 0 socktype 1 protocol 0 addrlen 0 host (empty) serv 80
62ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv www
63ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv www
64arg: flags 0x2 family 0 socktype 2 protocol 0 addrlen 0 host (empty) serv 80
65ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv www
66ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv www
67
68== empty servname
69arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv (empty)
70ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0
71ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0
72arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv (empty)
73ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0
74ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0
75arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv (empty)
76ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 cname "localhost"
77ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 cname "localhost"
78ai3: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 cname "localhost"
79ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 cname "localhost"
80arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv (empty)
81name or service is not known
82
83== sock_raw
84arg: flags 0x2 family 0 socktype 3 protocol 0 addrlen 0 host localhost serv (empty)
85ai1: flags 0x2 family 24 socktype 3 protocol 0 addrlen 28 host ::1 serv 0 cname "localhost"
86ai2: flags 0x2 family 2 socktype 3 protocol 0 addrlen 16 host 127.0.0.1 serv 0 cname "localhost"
87arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv (empty)
88ai1: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 cname "localhost"
89ai2: flags 0x2 family 2 socktype 3 protocol 59 addrlen 16 host 127.0.0.1 serv 0 cname "localhost"
90arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv 80
91service not supported for ai_socktype
92arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv www
93service not supported for ai_socktype
94arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host ::1 serv (empty)
95ai1: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0
96
97== unsupported family
98arg: flags 0x2 family 99 socktype 0 protocol 0 addrlen 0 host localhost serv (empty)
99ai_family not supported
100
101== the following items are specified in jinmei scopeaddr format doc.
102arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host fe80::1%lo0 serv http
103ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host fe80::1%lo0 serv www
104
diff --git a/src/regress/lib/libc/getaddrinfo/gaitest.c b/src/regress/lib/libc/getaddrinfo/gaitest.c
new file mode 100644
index 0000000000..edd56288f5
--- /dev/null
+++ b/src/regress/lib/libc/getaddrinfo/gaitest.c
@@ -0,0 +1,185 @@
1/* $OpenBSD: gaitest.c,v 1.2 2002/08/09 20:26:44 jsyn 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#include <sys/types.h>
34#include <sys/socket.h>
35#include <netinet/in.h>
36#include <arpa/inet.h>
37#include <netdb.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include <unistd.h>
41
42struct addrinfo ai;
43
44char host[NI_MAXHOST];
45char serv[NI_MAXSERV];
46int vflag = 0;
47
48static void usage(void);
49static void print1(const char *, const struct addrinfo *, char *, char *);
50int main(int, char *[]);
51
52static void
53usage()
54{
55 fprintf(stderr, "usage: test [-f family] [-s socktype] [-p proto] [-DPRSv46] host serv\n");
56}
57
58static void
59print1(title, res, h, s)
60 const char *title;
61 const struct addrinfo *res;
62 char *h;
63 char *s;
64{
65 char *start, *end;
66 int error;
67 const int niflag = NI_NUMERICHOST;
68
69 if (res->ai_addr) {
70 error = getnameinfo(res->ai_addr, res->ai_addr->sa_len,
71 host, sizeof(host), serv, sizeof(serv),
72 niflag);
73 h = host;
74 s = serv;
75 } else
76 error = 0;
77
78 if (vflag) {
79 start = "\t";
80 end = "\n";
81 } else {
82 start = " ";
83 end = "";
84 }
85 printf("%s%s", title, end);
86 printf("%sflags 0x%x%s", start, res->ai_flags, end);
87 printf("%sfamily %d%s", start, res->ai_family, end);
88 printf("%ssocktype %d%s", start, res->ai_socktype, end);
89 printf("%sprotocol %d%s", start, res->ai_protocol, end);
90 printf("%saddrlen %d%s", start, res->ai_addrlen, end);
91 if (error)
92 printf("%serror %d%s", start, error, end);
93 else {
94 printf("%shost %s%s", start, h, end);
95 printf("%sserv %s%s", start, s, end);
96 }
97 if (res->ai_canonname)
98 printf("%scname \"%s\"%s", start, res->ai_canonname, end);
99 if (!vflag)
100 printf("\n");
101
102}
103
104int
105main(argc, argv)
106 int argc;
107 char *argv[];
108{
109 struct addrinfo *res;
110 int error, i;
111 char *p, *q;
112 extern int optind;
113 extern char *optarg;
114 int c;
115 char nbuf[10];
116
117 memset(&ai, 0, sizeof(ai));
118 ai.ai_family = PF_UNSPEC;
119 ai.ai_flags |= AI_CANONNAME;
120 while ((c = getopt(argc, argv, "Df:p:PRs:Sv46")) != -1) {
121 switch (c) {
122 case 'D':
123 ai.ai_socktype = SOCK_DGRAM;
124 break;
125 case 'f':
126 ai.ai_family = atoi(optarg);
127 break;
128 case 'p':
129 ai.ai_protocol = atoi(optarg);
130 break;
131 case 'P':
132 ai.ai_flags |= AI_PASSIVE;
133 break;
134 case 'R':
135 ai.ai_socktype = SOCK_RAW;
136 break;
137 case 's':
138 ai.ai_socktype = atoi(optarg);
139 break;
140 case 'S':
141 ai.ai_socktype = SOCK_STREAM;
142 break;
143 case 'v':
144 vflag++;
145 break;
146 case '4':
147 ai.ai_family = PF_INET;
148 break;
149 case '6':
150 ai.ai_family = PF_INET6;
151 break;
152 default:
153 usage();
154 exit(1);
155 }
156 }
157 argc -= optind;
158 argv += optind;
159
160 if (argc != 2){
161 usage();
162 exit(1);
163 }
164
165 p = *argv[0] ? argv[0] : NULL;
166 q = *argv[1] ? argv[1] : NULL;
167
168 print1("arg:", &ai, p ? p : "(empty)", q ? q : "(empty)");
169
170 error = getaddrinfo(p, q, &ai, &res);
171 if (error) {
172 printf("%s\n", gai_strerror(error));
173 exit(1);
174 }
175
176 i = 1;
177 do {
178 snprintf(nbuf, sizeof(nbuf), "ai%d:", i);
179 print1(nbuf, res, NULL, NULL);
180
181 i++;
182 } while ((res = res->ai_next) != NULL);
183
184 exit(0);
185}
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
33TEST=./gaitest
34#TEST='./test -v'
35#IF=`ifconfig -a | grep -v '^ ' | sed -e 's/:.*//' | head -1 | awk '{print $1}'`
36
37echo '== 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
47echo
48
49echo '== specific address family'
50$TEST -4 localhost http
51$TEST -6 localhost http
52echo
53
54echo '== 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
65echo
66
67echo '== empty servname'
68$TEST ::1 ''
69$TEST 127.0.0.1 ''
70$TEST localhost ''
71$TEST '' ''
72echo
73
74echo '== 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 ''
80echo
81
82echo '== unsupported family'
83$TEST -f 99 localhost ''
84echo
85
86echo '== the following items are specified in jinmei scopeaddr format doc.'
87$TEST fe80::1%lo0 http
88#$TEST fe80::1%$IF http
89echo
diff --git a/src/regress/lib/libc/ieeefp/Makefile b/src/regress/lib/libc/ieeefp/Makefile
new file mode 100644
index 0000000000..f9a6035fa9
--- /dev/null
+++ b/src/regress/lib/libc/ieeefp/Makefile
@@ -0,0 +1,8 @@
1# $OpenBSD: Makefile,v 1.5 2002/02/23 01:25:11 art Exp $
2# $NetBSD: Makefile,v 1.5 1996/04/09 16:54:18 phil Exp $
3
4SUBDIR+= except inf round
5
6install:
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..ff620e016b
--- /dev/null
+++ b/src/regress/lib/libc/ieeefp/except/Makefile
@@ -0,0 +1,5 @@
1# $OpenBSD: Makefile,v 1.4 2002/02/18 11:22:26 art Exp $
2
3PROG=except
4
5.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..6b65e8f3c4
--- /dev/null
+++ b/src/regress/lib/libc/ieeefp/except/except.c
@@ -0,0 +1,90 @@
1/* $OpenBSD: except.c,v 1.3 2001/01/29 02:05:42 niklas Exp $ */
2
3#include <stdio.h>
4#include <signal.h>
5#include <assert.h>
6#include <ieeefp.h>
7#include <float.h>
8
9void sigfpe();
10volatile sig_atomic_t signal_cought;
11
12static volatile const double one = 1.0;
13static volatile const double zero = 0.0;
14static volatile const double huge = DBL_MAX;
15static volatile const double tiny = DBL_MIN;
16
17int
18main()
19{
20 volatile double x;
21
22 /*
23 * check to make sure that all exceptions are masked and
24 * that the accumulated exception status is clear.
25 */
26 assert(fpgetmask() == 0);
27 assert(fpgetsticky() == 0);
28
29 /* set up signal handler */
30 signal (SIGFPE, sigfpe);
31 signal_cought = 0;
32
33 /* trip divide by zero */
34 x = one / zero;
35 assert (fpgetsticky() & FP_X_DZ);
36 assert (signal_cought == 0);
37 fpsetsticky(0);
38
39 /* trip invalid operation */
40 x = zero / zero;
41 assert (fpgetsticky() & FP_X_INV);
42 assert (signal_cought == 0);
43 fpsetsticky(0);
44
45 /* trip overflow */
46 x = huge * huge;
47 assert (fpgetsticky() & FP_X_OFL);
48 assert (signal_cought == 0);
49 fpsetsticky(0);
50
51 /* trip underflow */
52 x = tiny * tiny;
53 assert (fpgetsticky() & FP_X_UFL);
54 assert (signal_cought == 0);
55 fpsetsticky(0);
56
57#if 0
58 /* unmask and then trip divide by zero */
59 fpsetmask(FP_X_DZ);
60 x = one / zero;
61 assert (signal_cought == 1);
62 signal_cought = 0;
63
64 /* unmask and then trip invalid operation */
65 fpsetmask(FP_X_INV);
66 x = zero / zero;
67 assert (signal_cought == 1);
68 signal_cought = 0;
69
70 /* unmask and then trip overflow */
71 fpsetmask(FP_X_OFL);
72 x = huge * huge;
73 assert (signal_cought == 1);
74 signal_cought = 0;
75
76 /* unmask and then trip underflow */
77 fpsetmask(FP_X_UFL);
78 x = tiny * tiny;
79 assert (signal_cought == 1);
80 signal_cought = 0;
81#endif
82
83 exit(0);
84}
85
86void
87sigfpe()
88{
89 signal_cought = 1;
90}
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
3PROG= inf
4SRCS= inf.c
5
6LDADD+= -lm
7DPADD+= ${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..b6116b0df1
--- /dev/null
+++ b/src/regress/lib/libc/ieeefp/inf/inf.c
@@ -0,0 +1,16 @@
1/* $OpenBSD: inf.c,v 1.2 2002/02/18 11:24:13 art Exp $ */
2
3/*
4 * Peter Valchev <pvalchev@openbsd.org> Public Domain, 2002.
5 */
6
7#include <math.h>
8
9int
10main()
11{
12 if (isinf(HUGE_VAL))
13 return 0;
14
15 return 1;
16}
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
3PROG= 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..086c4fdf10
--- /dev/null
+++ b/src/regress/lib/libc/ieeefp/round/round.c
@@ -0,0 +1,45 @@
1/* $OpenBSD: round.c,v 1.2 2001/01/29 02:05:43 niklas 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
14int
15main()
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/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 $
2PROG= longjmp
3
4do-longjmp: ${PROG}
5 ./longjmp
6
7do-_longjmp: ${PROG}
8 ./longjmp -_
9
10REGRESS_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
16jmp_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 */
24int
25main(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..0e8eee5478
--- /dev/null
+++ b/src/regress/lib/libc/malloc/Makefile
@@ -0,0 +1,5 @@
1# $OpenBSD: Makefile,v 1.3 2002/02/18 11:29:50 art Exp $
2
3PROG= malloc0test
4
5.include <bsd.regress.mk>
diff --git a/src/regress/lib/libc/malloc/malloc0test.c b/src/regress/lib/libc/malloc/malloc0test.c
new file mode 100644
index 0000000000..71e077e1c3
--- /dev/null
+++ b/src/regress/lib/libc/malloc/malloc0test.c
@@ -0,0 +1,133 @@
1/* $OpenBSD: malloc0test.c,v 1.5 2002/02/18 11:29:50 art 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
14volatile sig_atomic_t got;
15jmp_buf jmp;
16
17void
18catch(int signo)
19{
20 got++;
21 longjmp(jmp, 1);
22}
23
24int
25test(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
36char *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 */
58int
59main(int argc, char *argv[])
60{
61 caddr_t rblob = malloc(1);
62 caddr_t zblob = malloc(0);
63 caddr_t *blobp, blob;
64 int size, rsize, tsize;
65 int prot;
66 int rval = 0, fuckup = 0;
67 long limit = 200000, count;
68 int ch, silent = 0;
69 char *ep;
70 extern char *__progname;
71
72 while ((ch = getopt(argc, argv, "sn:")) != -1) {
73 switch (ch) {
74 case 's':
75 silent = 1;
76 break;
77 case 'n':
78 errno = 0;
79 limit = strtol(optarg, &ep, 10);
80 if (optarg[0] == '\0' || *ep != '\0' ||
81 (errno == ERANGE &&
82 (limit == LONG_MAX || limit == LONG_MIN)))
83 goto usage;
84 break;
85 default:
86usage:
87 fprintf(stderr, "Usage: %s [-s][-n <count>]\n",
88 __progname);
89 exit(1);
90 }
91 }
92
93 if (limit == 0)
94 limit = LONG_MAX;
95
96 for (count = 0; count < limit; count++) {
97 size = arc4random() % SIZE;
98 blob = malloc(size);
99 if (blob == NULL) {
100 fprintf(stderr, "success: out of memory\n");
101 exit(rval);
102 }
103
104 if (size == 0) {
105 blobp = &zblob;
106 tsize = 16;
107 } else {
108 blobp = &rblob;
109 tsize = size;
110 }
111
112 rsize = blob - *blobp;
113 fuckup = SIZE < 16 && size >= rsize;
114 prot = test(blob, tsize);
115
116 if (size == 0 && rsize < 16)
117 fuckup = 1;
118 if (size == 0 && prot < 2)
119 fuckup = 1;
120
121 if (fuckup) {
122 printf("%8p %6d %6d %20s %10s\n", blob, size, rsize,
123 prot_table[prot], fuckup ? "fuckup" : "");
124 rval = 1;
125 }
126 *blobp = blob;
127
128 if (!silent && count % 100000 == 0 && count != 0)
129 fprintf(stderr, "count = %d\n", count);
130 }
131
132 return rval;
133} \ No newline at end of file
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
3PROG=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..491c5becea
--- /dev/null
+++ b/src/regress/lib/libc/popen/popen.c
@@ -0,0 +1,104 @@
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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#include <sys/param.h>
40
41#include <errno.h>
42#include <paths.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <time.h>
46#include <unistd.h>
47
48#define _PATH_CAT "/bin/cat"
49#define BUFSIZE (640*1024)
50 /* 640KB ought to be enough for everyone. */
51#define DATAFILE "popen.data"
52
53int
54main(int argc, char **argv)
55{
56 char *buffer, command[MAXPATHLEN];
57 int index, in;
58 FILE *pipe;
59
60 if ((buffer = malloc(BUFSIZE*sizeof(char))) == NULL)
61 err(1, NULL);
62
63 for (index=0; index<BUFSIZE; index++)
64 buffer[index]=arc4random();
65
66 (void)snprintf(command, sizeof(command), "%s >%s",
67 _PATH_CAT, DATAFILE);
68 if ((pipe = popen(command, "w")) == NULL)
69 err(1, "popen write");
70
71 if (fwrite(buffer, sizeof(char), BUFSIZE, pipe) != BUFSIZE)
72 err(1, "write");
73
74 if (pclose(pipe) == -1)
75 err(1, "pclose");
76
77 (void)snprintf(command, sizeof(command), "%s %s",
78 _PATH_CAT, DATAFILE);
79 if ((pipe = popen(command, "r")) == NULL)
80 err(1, "popen read");
81
82 index = 0;
83 while ((in = fgetc(pipe)) != EOF)
84 if (index == BUFSIZE) {
85 errno = EFBIG;
86 err(1, "read");
87 }
88 else
89 if ((char)in != buffer[index++]) {
90 errno = EINVAL;
91 err(1, "read");
92 }
93
94 if (index < BUFSIZE) {
95 errno = EIO;
96 err(1, "read");
97 }
98
99 if (pclose(pipe) == -1)
100 err(1, "pclose");
101
102 (void)unlink(DATAFILE);
103 return 0;
104}
diff --git a/src/regress/lib/libc/regex/Makefile b/src/regress/lib/libc/regex/Makefile
new file mode 100644
index 0000000000..a29686bca4
--- /dev/null
+++ b/src/regress/lib/libc/regex/Makefile
@@ -0,0 +1,20 @@
1# $OpenBSD: Makefile,v 1.5 2002/09/02 20:01:43 avsm Exp $
2# $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $
3
4PROG= re
5SRCS= main.c split.c debug.c
6
7CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex
8
9TESTS= ${.CURDIR}/tests
10
11REGRESS_TARGETS=do-reg do-reg-long do-reg-backref
12
13do-reg: ${PROG}
14 ./re < ${TESTS}
15do-reg-long: ${PROG}
16 ./re -el < ${TESTS}
17do-reg-backref: ${PROG}
18 ./re -er < ${TESTS}
19
20.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..7834e970c7
--- /dev/null
+++ b/src/regress/lib/libc/regex/debug.c
@@ -0,0 +1,245 @@
1/* $OpenBSD: debug.c,v 1.3 2001/01/29 02:05:43 niklas 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 */
20void
21regprint(r, d)
22regex_t *r;
23FILE *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 */
93static void
94s_print(g, d)
95register struct re_guts *g;
96FILE *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 */
234static char * /* -> representation */
235regchar(ch)
236int ch;
237{
238 static char buf[10];
239
240 if (isprint(ch) || ch == ' ')
241 sprintf(buf, "%c", ch);
242 else
243 sprintf(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
6extern "C" {
7#endif
8
9/* === debug.c === */
10void regprint(regex_t *r, FILE *d);
11static void s_print(register struct re_guts *g, FILE *d);
12static 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..6e63ffc235
--- /dev/null
+++ b/src/regress/lib/libc/regex/main.c
@@ -0,0 +1,515 @@
1/* $OpenBSD: main.c,v 1.3 1997/01/15 23:41:07 millert 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
14char *progname;
15int debug = 0;
16int line = 0;
17int status = 0;
18
19int copts = REG_EXTENDED;
20int eopts = 0;
21regoff_t startoff = 0;
22regoff_t endoff = 0;
23
24
25extern int split();
26extern void regprint();
27
28/*
29 - main - do the simple case, hand off to regress() for regression
30 */
31int
32main(argc, argv)
33int argc;
34char *argv[];
35{
36 regex_t re;
37# define NS 10
38 regmatch_t subs[NS];
39 char erbuf[100];
40 int err;
41 size_t len;
42 int c;
43 int errflg = 0;
44 register int i;
45 extern int optind;
46 extern char *optarg;
47
48 progname = argv[0];
49
50 while ((c = getopt(argc, argv, "c:e:S:E:x")) != -1)
51 switch (c) {
52 case 'c': /* compile options */
53 copts = options('c', optarg);
54 break;
55 case 'e': /* execute options */
56 eopts = options('e', optarg);
57 break;
58 case 'S': /* start offset */
59 startoff = (regoff_t)atoi(optarg);
60 break;
61 case 'E': /* end offset */
62 endoff = (regoff_t)atoi(optarg);
63 break;
64 case 'x': /* Debugging. */
65 debug++;
66 break;
67 case '?':
68 default:
69 errflg++;
70 break;
71 }
72 if (errflg) {
73 fprintf(stderr, "usage: %s ", progname);
74 fprintf(stderr, "[-c copt][-C][-d] [re]\n");
75 exit(2);
76 }
77
78 if (optind >= argc) {
79 regress(stdin);
80 exit(status);
81 }
82
83 err = regcomp(&re, argv[optind++], copts);
84 if (err) {
85 len = regerror(err, &re, erbuf, sizeof(erbuf));
86 fprintf(stderr, "error %s, %d/%d `%s'\n",
87 eprint(err), len, sizeof(erbuf), erbuf);
88 exit(status);
89 }
90 regprint(&re, stdout);
91
92 if (optind >= argc) {
93 regfree(&re);
94 exit(status);
95 }
96
97 if (eopts&REG_STARTEND) {
98 subs[0].rm_so = startoff;
99 subs[0].rm_eo = strlen(argv[optind]) - endoff;
100 }
101 err = regexec(&re, argv[optind], (size_t)NS, subs, eopts);
102 if (err) {
103 len = regerror(err, &re, erbuf, sizeof(erbuf));
104 fprintf(stderr, "error %s, %d/%d `%s'\n",
105 eprint(err), len, sizeof(erbuf), erbuf);
106 exit(status);
107 }
108 if (!(copts&REG_NOSUB)) {
109 len = (size_t)(subs[0].rm_eo - subs[0].rm_so);
110 if (subs[0].rm_so != -1) {
111 if (len != 0)
112 printf("match `%.*s'\n", (int)len,
113 argv[optind] + subs[0].rm_so);
114 else
115 printf("match `'@%.1s\n",
116 argv[optind] + subs[0].rm_so);
117 }
118 for (i = 1; i < NS; i++)
119 if (subs[i].rm_so != -1)
120 printf("(%d) `%.*s'\n", i,
121 (int)(subs[i].rm_eo - subs[i].rm_so),
122 argv[optind] + subs[i].rm_so);
123 }
124 exit(status);
125}
126
127/*
128 - regress - main loop of regression test
129 == void regress(FILE *in);
130 */
131void
132regress(in)
133FILE *in;
134{
135 char inbuf[1000];
136# define MAXF 10
137 char *f[MAXF];
138 int nf;
139 int i;
140 char erbuf[100];
141 size_t ne;
142 char *badpat = "invalid regular expression";
143# define SHORT 10
144 char *bpname = "REG_BADPAT";
145 regex_t re;
146
147 while (fgets(inbuf, sizeof(inbuf), in) != NULL) {
148 line++;
149 if (inbuf[0] == '#' || inbuf[0] == '\n')
150 continue; /* NOTE CONTINUE */
151 inbuf[strlen(inbuf)-1] = '\0'; /* get rid of stupid \n */
152 if (debug)
153 fprintf(stdout, "%d:\n", line);
154 nf = split(inbuf, f, MAXF, "\t\t");
155 if (nf < 3) {
156 fprintf(stderr, "bad input, line %d\n", line);
157 exit(1);
158 }
159 for (i = 0; i < nf; i++)
160 if (strcmp(f[i], "\"\"") == 0)
161 f[i] = "";
162 if (nf <= 3)
163 f[3] = NULL;
164 if (nf <= 4)
165 f[4] = NULL;
166 try(f[0], f[1], f[2], f[3], f[4], options('c', f[1]));
167 if (opt('&', f[1])) /* try with either type of RE */
168 try(f[0], f[1], f[2], f[3], f[4],
169 options('c', f[1]) &~ REG_EXTENDED);
170 }
171
172 ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf));
173 if (strcmp(erbuf, badpat) != 0 || ne != strlen(badpat)+1) {
174 fprintf(stderr, "end: regerror() test gave `%s' not `%s'\n",
175 erbuf, badpat);
176 status = 1;
177 }
178 ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, (size_t)SHORT);
179 if (strncmp(erbuf, badpat, SHORT-1) != 0 || erbuf[SHORT-1] != '\0' ||
180 ne != strlen(badpat)+1) {
181 fprintf(stderr, "end: regerror() short test gave `%s' not `%.*s'\n",
182 erbuf, SHORT-1, badpat);
183 status = 1;
184 }
185 ne = regerror(REG_ITOA|REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf));
186 if (strcmp(erbuf, bpname) != 0 || ne != strlen(bpname)+1) {
187 fprintf(stderr, "end: regerror() ITOA test gave `%s' not `%s'\n",
188 erbuf, bpname);
189 status = 1;
190 }
191 re.re_endp = bpname;
192 ne = regerror(REG_ATOI, &re, erbuf, sizeof(erbuf));
193 if (atoi(erbuf) != (int)REG_BADPAT) {
194 fprintf(stderr, "end: regerror() ATOI test gave `%s' not `%ld'\n",
195 erbuf, (long)REG_BADPAT);
196 status = 1;
197 } else if (ne != strlen(erbuf)+1) {
198 fprintf(stderr, "end: regerror() ATOI test len(`%s') = %ld\n",
199 erbuf, (long)REG_BADPAT);
200 status = 1;
201 }
202}
203
204/*
205 - try - try it, and report on problems
206 == void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts);
207 */
208void
209try(f0, f1, f2, f3, f4, opts)
210char *f0;
211char *f1;
212char *f2;
213char *f3;
214char *f4;
215int opts; /* may not match f1 */
216{
217 regex_t re;
218# define NSUBS 10
219 regmatch_t subs[NSUBS];
220# define NSHOULD 15
221 char *should[NSHOULD];
222 int nshould;
223 char erbuf[100];
224 int err;
225 int len;
226 char *type = (opts & REG_EXTENDED) ? "ERE" : "BRE";
227 register int i;
228 char *grump;
229 char f0copy[1000];
230 char f2copy[1000];
231
232 strcpy(f0copy, f0);
233 re.re_endp = (opts&REG_PEND) ? f0copy + strlen(f0copy) : NULL;
234 fixstr(f0copy);
235 err = regcomp(&re, f0copy, opts);
236 if (err != 0 && (!opt('C', f1) || err != efind(f2))) {
237 /* unexpected error or wrong error */
238 len = regerror(err, &re, erbuf, sizeof(erbuf));
239 fprintf(stderr, "%d: %s error %s, %d/%d `%s'\n",
240 line, type, eprint(err), len,
241 sizeof(erbuf), erbuf);
242 status = 1;
243 } else if (err == 0 && opt('C', f1)) {
244 /* unexpected success */
245 fprintf(stderr, "%d: %s should have given REG_%s\n",
246 line, type, f2);
247 status = 1;
248 err = 1; /* so we won't try regexec */
249 }
250
251 if (err != 0) {
252 regfree(&re);
253 return;
254 }
255
256 strcpy(f2copy, f2);
257 fixstr(f2copy);
258
259 if (options('e', f1)&REG_STARTEND) {
260 if (strchr(f2, '(') == NULL || strchr(f2, ')') == NULL)
261 fprintf(stderr, "%d: bad STARTEND syntax\n", line);
262 subs[0].rm_so = strchr(f2, '(') - f2 + 1;
263 subs[0].rm_eo = strchr(f2, ')') - f2;
264 }
265 err = regexec(&re, f2copy, NSUBS, subs, options('e', f1));
266
267 if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) {
268 /* unexpected error or wrong error */
269 len = regerror(err, &re, erbuf, sizeof(erbuf));
270 fprintf(stderr, "%d: %s exec error %s, %d/%d `%s'\n",
271 line, type, eprint(err), len,
272 sizeof(erbuf), erbuf);
273 status = 1;
274 } else if (err != 0) {
275 /* nothing more to check */
276 } else if (f3 == NULL) {
277 /* unexpected success */
278 fprintf(stderr, "%d: %s exec should have failed\n",
279 line, type);
280 status = 1;
281 err = 1; /* just on principle */
282 } else if (opts&REG_NOSUB) {
283 /* nothing more to check */
284 } else if ((grump = check(f2, subs[0], f3)) != NULL) {
285 fprintf(stderr, "%d: %s %s\n", line, type, grump);
286 status = 1;
287 err = 1;
288 }
289
290 if (err != 0 || f4 == NULL) {
291 regfree(&re);
292 return;
293 }
294
295 for (i = 1; i < NSHOULD; i++)
296 should[i] = NULL;
297 nshould = split(f4, should+1, NSHOULD-1, ",");
298 if (nshould == 0) {
299 nshould = 1;
300 should[1] = "";
301 }
302 for (i = 1; i < NSUBS; i++) {
303 grump = check(f2, subs[i], should[i]);
304 if (grump != NULL) {
305 fprintf(stderr, "%d: %s $%d %s\n", line,
306 type, i, grump);
307 status = 1;
308 err = 1;
309 }
310 }
311
312 regfree(&re);
313}
314
315/*
316 - options - pick options out of a regression-test string
317 == int options(int type, char *s);
318 */
319int
320options(type, s)
321int type; /* 'c' compile, 'e' exec */
322char *s;
323{
324 register char *p;
325 register int o = (type == 'c') ? copts : eopts;
326 register char *legal = (type == 'c') ? "bisnmp" : "^$#tl";
327
328 for (p = s; *p != '\0'; p++)
329 if (strchr(legal, *p) != NULL)
330 switch (*p) {
331 case 'b':
332 o &= ~REG_EXTENDED;
333 break;
334 case 'i':
335 o |= REG_ICASE;
336 break;
337 case 's':
338 o |= REG_NOSUB;
339 break;
340 case 'n':
341 o |= REG_NEWLINE;
342 break;
343 case 'm':
344 o &= ~REG_EXTENDED;
345 o |= REG_NOSPEC;
346 break;
347 case 'p':
348 o |= REG_PEND;
349 break;
350 case '^':
351 o |= REG_NOTBOL;
352 break;
353 case '$':
354 o |= REG_NOTEOL;
355 break;
356 case '#':
357 o |= REG_STARTEND;
358 break;
359 case 't': /* trace */
360 o |= REG_TRACE;
361 break;
362 case 'l': /* force long representation */
363 o |= REG_LARGE;
364 break;
365 case 'r': /* force backref use */
366 o |= REG_BACKR;
367 break;
368 }
369 return(o);
370}
371
372/*
373 - opt - is a particular option in a regression string?
374 == int opt(int c, char *s);
375 */
376int /* predicate */
377opt(c, s)
378int c;
379char *s;
380{
381 return(strchr(s, c) != NULL);
382}
383
384/*
385 - fixstr - transform magic characters in strings
386 == void fixstr(register char *p);
387 */
388void
389fixstr(p)
390register char *p;
391{
392 if (p == NULL)
393 return;
394
395 for (; *p != '\0'; p++)
396 if (*p == 'N')
397 *p = '\n';
398 else if (*p == 'T')
399 *p = '\t';
400 else if (*p == 'S')
401 *p = ' ';
402 else if (*p == 'Z')
403 *p = '\0';
404}
405
406/*
407 - check - check a substring match
408 == char *check(char *str, regmatch_t sub, char *should);
409 */
410char * /* NULL or complaint */
411check(str, sub, should)
412char *str;
413regmatch_t sub;
414char *should;
415{
416 register int len;
417 register int shlen;
418 register char *p;
419 static char grump[500];
420 register char *at = NULL;
421
422 if (should != NULL && strcmp(should, "-") == 0)
423 should = NULL;
424 if (should != NULL && should[0] == '@') {
425 at = should + 1;
426 should = "";
427 }
428
429 /* check rm_so and rm_eo for consistency */
430 if (sub.rm_so > sub.rm_eo || (sub.rm_so == -1 && sub.rm_eo != -1) ||
431 (sub.rm_so != -1 && sub.rm_eo == -1) ||
432 (sub.rm_so != -1 && sub.rm_so < 0) ||
433 (sub.rm_eo != -1 && sub.rm_eo < 0) ) {
434 sprintf(grump, "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 sprintf(grump, "start %ld end %ld, past end of string",
448 (long)sub.rm_so, (long)sub.rm_eo);
449 return(grump);
450 }
451
452 len = (int)(sub.rm_eo - sub.rm_so);
453 shlen = (int)strlen(should);
454 p = str + sub.rm_so;
455
456 /* check for not supposed to match */
457 if (should == NULL) {
458 sprintf(grump, "matched `%.*s'", len, p);
459 return(grump);
460 }
461
462 /* check for wrong match */
463 if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) {
464 sprintf(grump, "matched `%.*s' instead", len, p);
465 return(grump);
466 }
467 if (shlen > 0)
468 return(NULL);
469
470 /* check null match in right place */
471 if (at == NULL)
472 return(NULL);
473 shlen = strlen(at);
474 if (shlen == 0)
475 shlen = 1; /* force check for end-of-string */
476 if (strncmp(p, at, shlen) != 0) {
477 sprintf(grump, "matched null at `%.20s'", p);
478 return(grump);
479 }
480 return(NULL);
481}
482
483/*
484 - eprint - convert error number to name
485 == static char *eprint(int err);
486 */
487static char *
488eprint(err)
489int err;
490{
491 static char epbuf[100];
492 size_t len;
493
494 len = regerror(REG_ITOA|err, (regex_t *)NULL, epbuf, sizeof(epbuf));
495 assert(len <= sizeof(epbuf));
496 return(epbuf);
497}
498
499/*
500 - efind - convert error name to number
501 == static int efind(char *name);
502 */
503static int
504efind(name)
505char *name;
506{
507 static char efbuf[100];
508 regex_t re;
509
510 sprintf(efbuf, "REG_%s", name);
511 assert(strlen(efbuf) < sizeof(efbuf));
512 re.re_endp = efbuf;
513 (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf));
514 return(atoi(efbuf));
515}
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
6extern "C" {
7#endif
8
9/* === main.c === */
10void regress(FILE *in);
11void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts);
12int options(int type, char *s);
13int opt(int c, char *s);
14void fixstr(register char *p);
15char *check(char *str, regmatch_t sub, char *should);
16static char *eprint(int err);
17static 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..52cb6c681e
--- /dev/null
+++ b/src/regress/lib/libc/regex/split.c
@@ -0,0 +1,319 @@
1/* $OpenBSD: split.c,v 1.2 2001/01/29 02:05:44 niklas 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/*
8 - split - divide a string into fields, like awk split()
9 = int split(char *string, char *fields[], int nfields, char *sep);
10 */
11int /* number of fields, including overflow */
12split(string, fields, nfields, sep)
13char *string;
14char *fields[]; /* list is not NULL-terminated */
15int nfields; /* number of entries available in fields[] */
16char *sep; /* "" white, "c" single char, "ab" [ab]+ */
17{
18 register char *p = string;
19 register char c; /* latest character */
20 register char sepc = sep[0];
21 register char sepc2;
22 register int fn;
23 register char **fp = fields;
24 register char *sepp;
25 register int trimtrail;
26
27 /* white space */
28 if (sepc == '\0') {
29 while ((c = *p++) == ' ' || c == '\t')
30 continue;
31 p--;
32 trimtrail = 1;
33 sep = " \t"; /* note, code below knows this is 2 long */
34 sepc = ' ';
35 } else
36 trimtrail = 0;
37 sepc2 = sep[1]; /* now we can safely pick this up */
38
39 /* catch empties */
40 if (*p == '\0')
41 return(0);
42
43 /* single separator */
44 if (sepc2 == '\0') {
45 fn = nfields;
46 for (;;) {
47 *fp++ = p;
48 fn--;
49 if (fn == 0)
50 break;
51 while ((c = *p++) != sepc)
52 if (c == '\0')
53 return(nfields - fn);
54 *(p-1) = '\0';
55 }
56 /* we have overflowed the fields vector -- just count them */
57 fn = nfields;
58 for (;;) {
59 while ((c = *p++) != sepc)
60 if (c == '\0')
61 return(fn);
62 fn++;
63 }
64 /* not reached */
65 }
66
67 /* two separators */
68 if (sep[2] == '\0') {
69 fn = nfields;
70 for (;;) {
71 *fp++ = p;
72 fn--;
73 while ((c = *p++) != sepc && c != sepc2)
74 if (c == '\0') {
75 if (trimtrail && **(fp-1) == '\0')
76 fn++;
77 return(nfields - fn);
78 }
79 if (fn == 0)
80 break;
81 *(p-1) = '\0';
82 while ((c = *p++) == sepc || c == sepc2)
83 continue;
84 p--;
85 }
86 /* we have overflowed the fields vector -- just count them */
87 fn = nfields;
88 while (c != '\0') {
89 while ((c = *p++) == sepc || c == sepc2)
90 continue;
91 p--;
92 fn++;
93 while ((c = *p++) != '\0' && c != sepc && c != sepc2)
94 continue;
95 }
96 /* might have to trim trailing white space */
97 if (trimtrail) {
98 p--;
99 while ((c = *--p) == sepc || c == sepc2)
100 continue;
101 p++;
102 if (*p != '\0') {
103 if (fn == nfields+1)
104 *p = '\0';
105 fn--;
106 }
107 }
108 return(fn);
109 }
110
111 /* n separators */
112 fn = 0;
113 for (;;) {
114 if (fn < nfields)
115 *fp++ = p;
116 fn++;
117 for (;;) {
118 c = *p++;
119 if (c == '\0')
120 return(fn);
121 sepp = sep;
122 while ((sepc = *sepp++) != '\0' && sepc != c)
123 continue;
124 if (sepc != '\0') /* it was a separator */
125 break;
126 }
127 if (fn < nfields)
128 *(p-1) = '\0';
129 for (;;) {
130 c = *p++;
131 sepp = sep;
132 while ((sepc = *sepp++) != '\0' && sepc != c)
133 continue;
134 if (sepc == '\0') /* it wasn't a separator */
135 break;
136 }
137 p--;
138 }
139
140 /* not reached */
141}
142
143#ifdef TEST_SPLIT
144
145
146/*
147 * test program
148 * pgm runs regression
149 * pgm sep splits stdin lines by sep
150 * pgm str sep splits str by sep
151 * pgm str sep n splits str by sep n times
152 */
153int
154main(argc, argv)
155int argc;
156char *argv[];
157{
158 char buf[512];
159 register int n;
160# define MNF 10
161 char *fields[MNF];
162
163 if (argc > 4)
164 for (n = atoi(argv[3]); n > 0; n--) {
165 (void) strcpy(buf, argv[1]);
166 }
167 else if (argc > 3)
168 for (n = atoi(argv[3]); n > 0; n--) {
169 (void) strcpy(buf, argv[1]);
170 (void) split(buf, fields, MNF, argv[2]);
171 }
172 else if (argc > 2)
173 dosplit(argv[1], argv[2]);
174 else if (argc > 1)
175 while (fgets(buf, sizeof(buf), stdin) != NULL) {
176 buf[strlen(buf)-1] = '\0'; /* stomp newline */
177 dosplit(buf, argv[1]);
178 }
179 else
180 regress();
181
182 exit(0);
183}
184
185dosplit(string, seps)
186char *string;
187char *seps;
188{
189# define NF 5
190 char *fields[NF];
191 register int nf;
192
193 nf = split(string, fields, NF, seps);
194 print(nf, NF, fields);
195}
196
197print(nf, nfp, fields)
198int nf;
199int nfp;
200char *fields[];
201{
202 register int fn;
203 register int bound;
204
205 bound = (nf > nfp) ? nfp : nf;
206 printf("%d:\t", nf);
207 for (fn = 0; fn < bound; fn++)
208 printf("\"%s\"%s", fields[fn], (fn+1 < nf) ? ", " : "\n");
209}
210
211#define RNF 5 /* some table entries know this */
212struct {
213 char *str;
214 char *seps;
215 int nf;
216 char *fi[RNF];
217} tests[] = {
218 "", " ", 0, { "" },
219 " ", " ", 2, { "", "" },
220 "x", " ", 1, { "x" },
221 "xy", " ", 1, { "xy" },
222 "x y", " ", 2, { "x", "y" },
223 "abc def g ", " ", 5, { "abc", "def", "", "g", "" },
224 " a bcd", " ", 4, { "", "", "a", "bcd" },
225 "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" },
226 " a b c d ", " ", 6, { "", "a", "b", "c", "d " },
227
228 "", " _", 0, { "" },
229 " ", " _", 2, { "", "" },
230 "x", " _", 1, { "x" },
231 "x y", " _", 2, { "x", "y" },
232 "ab _ cd", " _", 2, { "ab", "cd" },
233 " a_b c ", " _", 5, { "", "a", "b", "c", "" },
234 "a b c_d e f", " _", 6, { "a", "b", "c", "d", "e f" },
235 " a b c d ", " _", 6, { "", "a", "b", "c", "d " },
236
237 "", " _~", 0, { "" },
238 " ", " _~", 2, { "", "" },
239 "x", " _~", 1, { "x" },
240 "x y", " _~", 2, { "x", "y" },
241 "ab _~ cd", " _~", 2, { "ab", "cd" },
242 " a_b c~", " _~", 5, { "", "a", "b", "c", "" },
243 "a b_c d~e f", " _~", 6, { "a", "b", "c", "d", "e f" },
244 "~a b c d ", " _~", 6, { "", "a", "b", "c", "d " },
245
246 "", " _~-", 0, { "" },
247 " ", " _~-", 2, { "", "" },
248 "x", " _~-", 1, { "x" },
249 "x y", " _~-", 2, { "x", "y" },
250 "ab _~- cd", " _~-", 2, { "ab", "cd" },
251 " a_b c~", " _~-", 5, { "", "a", "b", "c", "" },
252 "a b_c-d~e f", " _~-", 6, { "a", "b", "c", "d", "e f" },
253 "~a-b c d ", " _~-", 6, { "", "a", "b", "c", "d " },
254
255 "", " ", 0, { "" },
256 " ", " ", 2, { "", "" },
257 "x", " ", 1, { "x" },
258 "xy", " ", 1, { "xy" },
259 "x y", " ", 2, { "x", "y" },
260 "abc def g ", " ", 4, { "abc", "def", "g", "" },
261 " a bcd", " ", 3, { "", "a", "bcd" },
262 "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" },
263 " a b c d ", " ", 6, { "", "a", "b", "c", "d " },
264
265 "", "", 0, { "" },
266 " ", "", 0, { "" },
267 "x", "", 1, { "x" },
268 "xy", "", 1, { "xy" },
269 "x y", "", 2, { "x", "y" },
270 "abc def g ", "", 3, { "abc", "def", "g" },
271 "\t a bcd", "", 2, { "a", "bcd" },
272 " a \tb\t c ", "", 3, { "a", "b", "c" },
273 "a b c d e ", "", 5, { "a", "b", "c", "d", "e" },
274 "a b\tc d e f", "", 6, { "a", "b", "c", "d", "e f" },
275 " a b c d e f ", "", 6, { "a", "b", "c", "d", "e f " },
276
277 NULL, NULL, 0, { NULL },
278};
279
280regress()
281{
282 char buf[512];
283 register int n;
284 char *fields[RNF+1];
285 register int nf;
286 register int i;
287 register int printit;
288 register char *f;
289
290 for (n = 0; tests[n].str != NULL; n++) {
291 (void) strcpy(buf, tests[n].str);
292 fields[RNF] = NULL;
293 nf = split(buf, fields, RNF, tests[n].seps);
294 printit = 0;
295 if (nf != tests[n].nf) {
296 printf("split `%s' by `%s' gave %d fields, not %d\n",
297 tests[n].str, tests[n].seps, nf, tests[n].nf);
298 printit = 1;
299 } else if (fields[RNF] != NULL) {
300 printf("split() went beyond array end\n");
301 printit = 1;
302 } else {
303 for (i = 0; i < nf && i < RNF; i++) {
304 f = fields[i];
305 if (f == NULL)
306 f = "(NULL)";
307 if (strcmp(f, tests[n].fi[i]) != 0) {
308 printf("split `%s' by `%s', field %d is `%s', not `%s'\n",
309 tests[n].str, tests[n].seps,
310 i, fields[i], tests[n].fi[i]);
311 printit = 1;
312 }
313 }
314 }
315 if (printit)
316 print(nf, RNF, fields);
317 }
318}
319#endif
diff --git a/src/regress/lib/libc/regex/tests b/src/regress/lib/libc/regex/tests
new file mode 100644
index 0000000000..c89b9ec164
--- /dev/null
+++ b/src/regress/lib/libc/regex/tests
@@ -0,0 +1,478 @@
1# $OpenBSD: tests,v 1.2 2001/01/29 02:05:44 niklas 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
39a & a a
40abc & abc abc
41abc|de - abc abc
42a|b|c - abc a
43
44# parentheses and perversions thereof
45a(b)c - abc abc
46a\(b\)c b abc abc
47a( C EPAREN
48a( b a( a(
49a\( - a( a(
50a\( bC EPAREN
51a\(b bC EPAREN
52a(b C EPAREN
53a(b b a(b a(b
54# gag me with a right parenthesis -- 1003.2 goofed here (my fault, partly)
55a) - a) a)
56) - ) )
57# end gagging (in a just world, those *should* give EPAREN)
58a) b a) a)
59a\) bC EPAREN
60\) bC EPAREN
61a()b - ab ab
62a\(\)b b ab ab
63
64# anchoring and REG_NEWLINE
65^abc$ & abc abc
66a^b - a^b
67a^b b a^b a^b
68a$b - a$b
69a$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$$ - "" @
78b$ & abNc
79b$ &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
90a$ $ a
91^a ^n aNb
92^b ^n aNb b
93a$ $n bNa
94b$ $n bNa b
95a*(^b$)c* - b b
96a*\(^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
108a||b C EMPTY
109|ab C EMPTY
110ab| 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
130a.c & abc abc
131a[bc]d & abd abd
132a\*c & a*c a*c
133a\\b & a\b a\b
134a\\\*b & a\*b a\*b
135a\bc & abc abc
136a\ &C EESCAPE
137a\\bc & a\bc a\bc
138\{ bC BADRPT
139a\[b & a[b a[b
140a[b &C EBRACK
141# trailing $ is a peculiar special case for the BRE code
142a$ & a a
143a$ & a$
144a\$ & a
145a\$ & a$ a$
146a\\$ & a
147a\\$ & a$
148a\\$ & a\$
149a\\$ & a\ a\
150
151# back references, ugh
152a\(b\)\2c bC ESUBREG
153a\(b\1\)c bC ESUBREG
154a\(b*\)c\1d b abbcbbd abbcbbd bb
155a\(b*\)c\1d b abbcbd
156a\(b*\)c\1d b abbcbbbd
157^\(.\)\1 b abc
158a\([bc]\)\1d b abcdabbd abbd b
159a\(\([bc]\)\2\)*d b abbccd abbccd
160a\(\([bc]\)\2\)*d b abbcbd
161# actually, this next one probably ought to fail, but the spec is unclear
162a\(\(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
173# ordinary repetitions
174ab*c & abc abc
175ab+c - abc abc
176ab?c - abc abc
177a\(*\)b b a*b a*b
178a\(**\)b b ab ab
179a\(***\)b bC BADRPT
180*a b *a *a
181**a b a a
182***a bC BADRPT
183
184# the dreaded bounded repetitions
185{ & { {
186{abc & {abc {abc
187{1 C BADRPT
188{1} C BADRPT
189a{b & a{b a{b
190a{1}b - ab ab
191a\{1\}b b ab ab
192a{1,}b - ab ab
193a\{1,\}b b ab ab
194a{1,2}b - aab aab
195a\{1,2\}b b aab aab
196a{1 C EBRACE
197a\{1 bC EBRACE
198a{1a C EBRACE
199a\{1a bC EBRACE
200a{1a} C BADBR
201a\{1a\} bC BADBR
202a{,2} - a{,2} a{,2}
203a\{,2\} bC BADBR
204a{,} - a{,} a{,}
205a\{,\} bC BADBR
206a{1,x} C BADBR
207a\{1,x\} bC BADBR
208a{1,x C EBRACE
209a\{1,x bC EBRACE
210a{300} C BADBR
211a\{300\} bC BADBR
212a{1,0} C BADBR
213a\{1,0\} bC BADBR
214ab{0,0}c - abcac ac
215ab\{0,0\}c b abcac ac
216ab{0,1}c - abcac abc
217ab\{0,1\}c b abcac abc
218ab{0,3}c - abbcac abbc
219ab\{0,3\}c b abbcac abbc
220ab{1,1}c - acabc abc
221ab\{1,1\}c b acabc abc
222ab{1,3}c - acabc abc
223ab\{1,3\}c b acabc abc
224ab{2,2}c - abcabbc abbc
225ab\{2,2\}c b abcabbc abbc
226ab{2,4}c - abcabbc abbc
227ab\{2,4\}c b abcabbc abbc
228((a{1,10}){1,10}){1,10} - a a a,a
229
230# multiple repetitions
231a** &C BADRPT
232a++ C BADRPT
233a?? C BADRPT
234a*+ C BADRPT
235a*? C BADRPT
236a+* C BADRPT
237a+? C BADRPT
238a?* C BADRPT
239a?+ C BADRPT
240a{1}{1} C BADRPT
241a*{1} C BADRPT
242a+{1} C BADRPT
243a?{1} C BADRPT
244a{1}* C BADRPT
245a{1}+ C BADRPT
246a{1}? C BADRPT
247a*{b} - a{b} a{b}
248a\{1\}\{1\} bC BADRPT
249a*\{1\} bC BADRPT
250a\{1\}* bC BADRPT
251
252# brackets, and numerous perversions thereof
253a[b]c & abc abc
254a[ab]c & abc abc
255a[^ab]c & adc adc
256a[]b]c & a]c a]c
257a[[b]c & a[c a[c
258a[-b]c & a-c a-c
259a[^]b]c & adc adc
260a[^-b]c & adc adc
261a[b-]c & a-c a-c
262a[b &C EBRACK
263a[] &C EBRACK
264a[1-3]c & a2c a2c
265a[3-1]c &C ERANGE
266a[1-3-5]c &C ERANGE
267a[[.-.]--]c & a-c a-c
268a[1- &C ERANGE
269a[[. &C EBRACK
270a[[.x &C EBRACK
271a[[.x. &C EBRACK
272a[[.x.] &C EBRACK
273a[[.x.]] & ax ax
274a[[.x,.]] &C ECOLLATE
275a[[.one.]]b & a1b a1b
276a[[.notdef.]]b &C ECOLLATE
277a[[.].]]b & a]b a]b
278a[[:alpha:]]c & abc abc
279a[[:notdef:]]c &C ECTYPE
280a[[: &C EBRACK
281a[[:alpha &C EBRACK
282a[[:alpha:] &C EBRACK
283a[[:alpha,:] &C ECTYPE
284a[[:]:]]b &C ECTYPE
285a[[:-:]]b &C ECTYPE
286a[[:alph:]] &C ECTYPE
287a[[:alphabet:]] &C ECTYPE
288[[:alnum:]]+ - -%@a0X- a0X
289[[:alpha:]]+ - -%@aX0- aX
290[[:blank:]]+ - aSSTb SST
291[[:cntrl:]]+ - aNTb NT
292[[:digit:]]+ - a019b 019
293[[:graph:]]+ - Sa%bS a%b
294[[:lower:]]+ - AabC ab
295[[:print:]]+ - NaSbN aSb
296[[:punct:]]+ - S%-&T %-&
297[[:space:]]+ - aSNTb SNT
298[[:upper:]]+ - aBCd BC
299[[:xdigit:]]+ - p0f3Cq 0f3C
300a[[=b=]]c & abc abc
301a[[= &C EBRACK
302a[[=b &C EBRACK
303a[[=b= &C EBRACK
304a[[=b=] &C EBRACK
305a[[=b,=]] &C ECOLLATE
306a[[=one=]]b & a1b a1b
307
308# complexities
309a(((b)))c - abc abc
310a(b|(c))d - abd abd
311a(b*|c)d - abbd abbd
312# just gotta have one DFA-buster, of course
313a[ab]{20} - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
314# and an inline expansion in case somebody gets tricky
315a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
316# and in case somebody just slips in an NFA...
317a[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
318# fish for anomalies as the number of states passes 32
31912345678901234567890123456789 - a12345678901234567890123456789b 12345678901234567890123456789
320123456789012345678901234567890 - a123456789012345678901234567890b 123456789012345678901234567890
3211234567890123456789012345678901 - a1234567890123456789012345678901b 1234567890123456789012345678901
32212345678901234567890123456789012 - a12345678901234567890123456789012b 12345678901234567890123456789012
323123456789012345678901234567890123 - a123456789012345678901234567890123b 123456789012345678901234567890123
324# and one really big one, beyond any plausible word width
3251234567890123456789012345678901234567890123456789012345678901234567890 - a1234567890123456789012345678901234567890123456789012345678901234567890b 1234567890123456789012345678901234567890123456789012345678901234567890
326# fish for problems as brackets go past 8
327[ab][cd][ef][gh][ij][kl][mn] - xacegikmoq acegikm
328[ab][cd][ef][gh][ij][kl][mn][op] - xacegikmoq acegikmo
329[ab][cd][ef][gh][ij][kl][mn][op][qr] - xacegikmoqy acegikmoq
330[ab][cd][ef][gh][ij][kl][mn][op][q] - xacegikmoqy acegikmoq
331
332# subtleties of matching
333abc & xabcy abc
334a\(b\)?c\1d b acd
335aBc i Abc Abc
336a[Bc]*d i abBCcd abBCcd
3370[[:upper:]]1 &i 0a1 0a1
3380[[:lower:]]1 &i 0A1 0A1
339a[^b]c &i abc
340a[^b]c &i aBc
341a[^b]c &i adc adc
342[a]b[c] - abc abc
343[a]b[a] - aba aba
344[abc]b[abc] - abc abc
345[abc]b[abd] - abd abd
346a(b?c)+d - accd accd
347(wee|week)(knights|night) - weeknights weeknights
348(we|wee|week|frob)(knights|night|day) - weeknights weeknights
349a[bc]d - xyzaaabcaababdacd abd
350a[ab]c - aaabc abc
351abc s abc abc
352a* & b @b
353
354# Let's have some fun -- try to match a C comment.
355# first the obvious, which looks okay at first glance...
356/\*.*\*/ - /*x*/ /*x*/
357# but...
358/\*.*\*/ - /*x*/y/*z*/ /*x*/y/*z*/
359# okay, we must not match */ inside; try to do that...
360/\*([^*]|\*[^/])*\*/ - /*x*/ /*x*/
361/\*([^*]|\*[^/])*\*/ - /*x*/y/*z*/ /*x*/
362# but...
363/\*([^*]|\*[^/])*\*/ - /*x**/y/*z*/ /*x**/y/*z*/
364# and a still fancier version, which does it right (I think)...
365/\*([^*]|\*+[^*/])*\*+/ - /*x*/ /*x*/
366/\*([^*]|\*+[^*/])*\*+/ - /*x*/y/*z*/ /*x*/
367/\*([^*]|\*+[^*/])*\*+/ - /*x**/y/*z*/ /*x**/
368/\*([^*]|\*+[^*/])*\*+/ - /*x****/y/*z*/ /*x****/
369/\*([^*]|\*+[^*/])*\*+/ - /*x**x*/y/*z*/ /*x**x*/
370/\*([^*]|\*+[^*/])*\*+/ - /*x***x/y/*z*/ /*x***x/y/*z*/
371
372# subexpressions
373a(b)(c)d - abcd abcd b,c
374a(((b)))c - abc abc b,b,b
375a(b|(c))d - abd abd b,-
376a(b*|c|e)d - abbd abbd bb
377a(b*|c|e)d - acd acd c
378a(b*|c|e)d - ad ad @d
379a(b?)c - abc abc b
380a(b?)c - ac ac @c
381a(b+)c - abc abc b
382a(b+)c - abbbc abbbc bbb
383a(b*)c - ac ac @c
384(a|ab)(bc([de]+)f|cde) - abcdef abcdef a,bcdef,de
385# the regression tester only asks for 9 subexpressions
386a(b)(c)(d)(e)(f)(g)(h)(i)(j)k - abcdefghijk abcdefghijk b,c,d,e,f,g,h,i,j
387a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l - abcdefghijkl abcdefghijkl b,c,d,e,f,g,h,i,j,k
388a([bc]?)c - abc abc b
389a([bc]?)c - ac ac @c
390a([bc]+)c - abc abc b
391a([bc]+)c - abcc abcc bc
392a([bc]+)bc - abcbc abcbc bc
393a(bb+|b)b - abb abb b
394a(bbb+|bb+|b)b - abb abb b
395a(bbb+|bb+|b)b - abbb abbb bb
396a(bbb+|bb+|b)bb - abbb abbb b
397(.*).* - abcdef abcdef abcdef
398(a*)* - bc @b @b
399
400# do we get the right subexpression when it is used more than once?
401a(b|c)*d - ad ad -
402a(b|c)*d - abcd abcd c
403a(b|c)+d - abd abd b
404a(b|c)+d - abcd abcd c
405a(b|c?)+d - ad ad @d
406a(b|c?)+d - abcd abcd @d
407a(b|c){0,0}d - ad ad -
408a(b|c){0,1}d - ad ad -
409a(b|c){0,1}d - abd abd b
410a(b|c){0,2}d - ad ad -
411a(b|c){0,2}d - abcd abcd c
412a(b|c){0,}d - ad ad -
413a(b|c){0,}d - abcd abcd c
414a(b|c){1,1}d - abd abd b
415a(b|c){1,1}d - acd acd c
416a(b|c){1,2}d - abd abd b
417a(b|c){1,2}d - abcd abcd c
418a(b|c){1,}d - abd abd b
419a(b|c){1,}d - abcd abcd c
420a(b|c){2,2}d - acbd acbd b
421a(b|c){2,2}d - abcd abcd c
422a(b|c){2,4}d - abcd abcd c
423a(b|c){2,4}d - abcbd abcbd b
424a(b|c){2,4}d - abcbcd abcbcd c
425a(b|c){2,}d - abcd abcd c
426a(b|c){2,}d - abcbd abcbd b
427a(b+|((c)*))+d - abd abd @d,@d,-
428a(b+|((c)*))+d - abcd abcd @d,@d,-
429
430# check out the STARTEND option
431[abc] &# a(b)c b
432[abc] &# a(d)c
433[abc] &# a(bc)d b
434[abc] &# a(dc)d c
435. &# a()c
436b.*c &# b(bc)c bc
437b.* &# b(bc)c bc
438.*c &# b(bc)c bc
439
440# plain strings, with the NOSPEC flag
441abc m abc abc
442abc m xabcy abc
443abc m xyz
444a*b m aba*b a*b
445a*b m ab
446"" mC EMPTY
447
448# cases involving NULs
449aZb & a a
450aZb &p a
451aZb &p# (aZb) aZb
452aZ*b &p# (ab) ab
453a.b &# (aZb) aZb
454a.* &# (aZb)c aZb
455
456# word boundaries (ick)
457[[:<:]]a & a a
458[[:<:]]a & ba
459[[:<:]]a & -a a
460a[[:>:]] & a a
461a[[:>:]] & ab
462a[[:>:]] & a- a
463[[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc abc
464[[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc-q abc
465[[:<:]]a.c[[:>:]] & axc-dayc-dazce-abc axc
466[[:<:]]b.c[[:>:]] & a_bxc-byc_d-bzc-q bzc
467[[:<:]].x..[[:>:]] & y_xa_-_xb_y-_xc_-axdc _xc_
468[[:<:]]a_b[[:>:]] & x_a_b
469
470# past problems, and suspected problems
471(A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A]) - A1 A1
472abcdefghijklmnop i abcdefghijklmnop abcdefghijklmnop
473abcdefghijklmnopqrstuv i abcdefghijklmnopqrstuv abcdefghijklmnopqrstuv
474(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
475CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11
476Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz
477a?b - ab ab
478-\{0,1\}[0-9]*$ b -5 -5
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
3PROG= 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..84947f372d
--- /dev/null
+++ b/src/regress/lib/libc/setjmp-signal/setjmp-signal.c
@@ -0,0 +1,26 @@
1/* $OpenBSD: setjmp-signal.c,v 1.2 2002/07/31 05:25:55 art Exp $ */
2/*
3 * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain.
4 */
5
6#include <setjmp.h>
7#include <signal.h>
8
9jmp_buf jb;
10
11void
12segv_handler(int signum)
13{
14 longjmp(jb, 1);
15}
16
17int
18main()
19{
20 signal(SIGSEGV, segv_handler);
21 if (setjmp(jb) == 0) {
22 *((int *)addr) = 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
4PROG= setjmptest
5SRCS= jmptest.c
6
7CFLAGS+= -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..de6e70d9f6
--- /dev/null
+++ b/src/regress/lib/libc/setjmp/jmptest.c
@@ -0,0 +1,138 @@
1/* $OpenBSD: jmptest.c,v 1.5 2001/11/11 23:26:35 deraadt 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 <unistd.h>
42
43#if (TEST_SETJMP + TEST_U_SETJMP + TEST_SIGSETJMP) != 1
44#error one of TEST_SETJMP, TEST_U_SETJMP, or TEST_SIGSETJMP must be defined
45#endif
46
47#ifdef TEST_SETJMP
48#define BUF jmp_buf
49#define SET(b, m) setjmp(b)
50#define JMP(b, v) longjmp(b, v)
51#endif
52
53#ifdef TEST_U_SETJMP
54#define BUF jmp_buf
55#define SET(b, m) _setjmp(b)
56#define JMP(b, v) _longjmp(b, v)
57#endif
58
59#ifdef TEST_SIGSETJMP
60#define BUF sigjmp_buf
61#define SET(b, m) sigsetjmp(b, m)
62#define JMP(b, v) siglongjmp(b, v)
63#endif
64
65int expectsignal;
66
67void
68aborthandler(signo)
69 int signo;
70{
71
72 if (expectsignal)
73 _exit(0);
74 else {
75 warnx("kill(SIGABRT) succeeded");
76 _exit(1);
77 }
78}
79
80int
81main(argc, argv)
82 int argc;
83 char *argv[];
84{
85 struct sigaction sa;
86 BUF jb;
87 sigset_t ss;
88 int i, x;
89
90 i = getpid();
91
92#ifdef TEST_SETJMP
93 expectsignal = 0;
94#endif
95#ifdef TEST_U_SETJMP
96 expectsignal = 1;
97#endif
98#ifdef TEST_SIGSETJMP
99 if (argc != 2 ||
100 (strcmp(argv[1], "save") && strcmp(argv[1], "nosave"))) {
101 fprintf(stderr, "usage: %s [save|nosave]\n", argv[0]);
102 exit(1);
103 }
104 expectsignal = (strcmp(argv[1], "save") != 0);
105#endif
106
107 sa.sa_handler = aborthandler;
108 sigemptyset(&sa.sa_mask);
109 sa.sa_flags = 0;
110 if (sigaction(SIGABRT, &sa, NULL) == -1)
111 err(1, "sigaction failed");
112
113 if (sigemptyset(&ss) == -1)
114 err(1, "sigemptyset failed");
115 if (sigaddset(&ss, SIGABRT) == -1)
116 err(1, "sigaddset failed");
117 if (sigprocmask(SIG_BLOCK, &ss, NULL) == -1)
118 err(1, "sigprocmask (1) failed");
119
120 x = SET(jb, !expectsignal);
121 if (x != 0) {
122 if (x != i)
123 errx(1, "setjmp returned wrong value");
124
125 kill(i, SIGABRT);
126 if (expectsignal)
127 errx(1, "kill(SIGABRT) failed");
128 else
129 exit(0);
130 }
131
132 if (sigprocmask(SIG_UNBLOCK, &ss, NULL) == -1)
133 err(1, "sigprocmask (2) failed");
134
135 JMP(jb, i);
136
137 errx(1, "jmp failed");
138}
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
3PROG= sigret
4
5DEBUG+= -ggdb
6
7REGRESS_TARGETS+= sigret-normal sigret-indirect sigret-altstack
8
9sigret-normal: ${PROG}
10 ./${PROG}
11
12sigret-indirect: ${PROG}
13 ./${PROG} -i
14
15sigret-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..416869007a
--- /dev/null
+++ b/src/regress/lib/libc/sigreturn/sigret.c
@@ -0,0 +1,181 @@
1/*
2 * $OpenBSD: sigret.c,v 1.4 2002/04/30 01:59:47 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
41int failed;
42int altstack;
43int badcall;
44int clobbercall;
45int fallthru;
46int indirect;
47
48volatile int count;
49struct sigcontext gscp;
50int gscp_loaded;
51
52static void
53usage(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
67void
68indirect_return(struct sigcontext * scp)
69{
70 sigreturn(scp);
71}
72
73void
74sig_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
93void
94test2(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
118int
119main(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
3PROG= sigsetjmptest
4SRCS= jmptest.c
5
6CFLAGS+= -DTEST_SIGSETJMP
7
8.PATH: ${.CURDIR}/../setjmp
9
10REGRESS_TARGETS=sigsetjmp-save sigsetjmp-nosave
11
12sigsetjmp-save: ${PROG}
13 ./${PROG} save
14sigsetjmp-nosave: ${PROG}
15 ./${PROG} nosave
16
17.PHONY: ${REGRESS_TARGETS}
18
19.include <bsd.regress.mk>