diff options
Diffstat (limited to 'src/regress/lib/libc')
312 files changed, 0 insertions, 40607 deletions
diff --git a/src/regress/lib/libc/Makefile b/src/regress/lib/libc/Makefile deleted file mode 100644 index 3cd970e49d..0000000000 --- a/src/regress/lib/libc/Makefile +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.59 2024/07/14 09:48:48 jca Exp $ | ||
2 | |||
3 | SUBDIR+= _setjmp | ||
4 | SUBDIR+= alloca arc4random-fork atexit | ||
5 | SUBDIR+= basename | ||
6 | SUBDIR+= cephes cxa-atexit | ||
7 | SUBDIR+= db dirname | ||
8 | SUBDIR+= elf_aux_info | ||
9 | SUBDIR+= env explicit_bzero | ||
10 | SUBDIR+= ffs fmemopen fnmatch fpclassify fread | ||
11 | SUBDIR+= gcvt getaddrinfo getcap getopt getopt_long glob | ||
12 | SUBDIR+= hsearch | ||
13 | SUBDIR+= ieeefp ifnameindex | ||
14 | SUBDIR+= ldexp locale longjmp | ||
15 | SUBDIR+= malloc mkstemp modf | ||
16 | SUBDIR+= netdb | ||
17 | SUBDIR+= open_memstream orientation | ||
18 | SUBDIR+= popen printf | ||
19 | SUBDIR+= qsort | ||
20 | SUBDIR+= regex | ||
21 | SUBDIR+= setjmp setjmp-signal sigsetjmp sigthr sleep sprintf stdio_threading | ||
22 | SUBDIR+= stpncpy strchr strerror strlcat strlcpy strnlen strtod strtol strtonum | ||
23 | SUBDIR+= sys | ||
24 | SUBDIR+= telldir time timingsafe | ||
25 | SUBDIR+= uuid | ||
26 | SUBDIR+= vis | ||
27 | SUBDIR+= wprintf | ||
28 | |||
29 | .if defined(REGRESS_FULL) || make(clean) || make(cleandir) || make(obj) | ||
30 | SUBDIR+= setjmp-fpu | ||
31 | .endif | ||
32 | |||
33 | .if exists(arch/${MACHINE_ARCH}) | ||
34 | SUBDIR+= arch/${MACHINE_ARCH} | ||
35 | .endif | ||
36 | |||
37 | # XXX asr tests to not use bsd.regress.mk and works completly different | ||
38 | # SUBDIR+= asr | ||
39 | |||
40 | install: | ||
41 | |||
42 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/_setjmp/Makefile b/src/regress/lib/libc/_setjmp/Makefile deleted file mode 100644 index 5d58242523..0000000000 --- a/src/regress/lib/libc/_setjmp/Makefile +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2002/01/01 23:00:51 art Exp $ | ||
2 | # $NetBSD: Makefile,v 1.2 1995/04/20 22:38:44 cgd Exp $ | ||
3 | |||
4 | PROG= _setjmptest | ||
5 | SRCS= jmptest.c | ||
6 | |||
7 | CFLAGS+= -DTEST_U_SETJMP | ||
8 | |||
9 | .PATH: ${.CURDIR}/../setjmp | ||
10 | |||
11 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/alloca/Makefile b/src/regress/lib/libc/alloca/Makefile deleted file mode 100644 index f31417cda7..0000000000 --- a/src/regress/lib/libc/alloca/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2003/02/12 06:49:04 mickey Exp $ | ||
2 | |||
3 | PROG= alloca | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/alloca/alloca.c b/src/regress/lib/libc/alloca/alloca.c deleted file mode 100644 index 54fa90edae..0000000000 --- a/src/regress/lib/libc/alloca/alloca.c +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | /* $OpenBSD: alloca.c,v 1.7 2004/03/10 01:17:45 deraadt Exp $ */ | ||
2 | |||
3 | /* Written by Michael Shalayeff, 2003, Public Domain. */ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <string.h> | ||
8 | |||
9 | int | ||
10 | main(int argc, char *argv[]) | ||
11 | { | ||
12 | char *q, *p; | ||
13 | |||
14 | p = alloca(41); | ||
15 | strlcpy(p, "hellow world", 41); | ||
16 | |||
17 | q = alloca(53); | ||
18 | strlcpy(q, "hellow world", 53); | ||
19 | |||
20 | exit(strcmp(p, q)); | ||
21 | } | ||
diff --git a/src/regress/lib/libc/arc4random-fork/Makefile b/src/regress/lib/libc/arc4random-fork/Makefile deleted file mode 100644 index 05762e33ff..0000000000 --- a/src/regress/lib/libc/arc4random-fork/Makefile +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2014/06/18 08:24:00 matthew Exp $ | ||
2 | |||
3 | PROG= arc4random-fork | ||
4 | |||
5 | REGRESS_TARGETS= \ | ||
6 | run \ | ||
7 | run-buf \ | ||
8 | run-prefork \ | ||
9 | run-buf-prefork | ||
10 | |||
11 | run: ${PROG} | ||
12 | ./${PROG} | ||
13 | |||
14 | run-buf: ${PROG} | ||
15 | ./${PROG} -b | ||
16 | |||
17 | run-prefork: ${PROG} | ||
18 | ./${PROG} -p | ||
19 | |||
20 | run-buf-prefork: ${PROG} | ||
21 | ./${PROG} -bp | ||
22 | |||
23 | .PHONY: ${REGRESS_TARGETS} | ||
24 | |||
25 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/arc4random-fork/arc4random-fork.c b/src/regress/lib/libc/arc4random-fork/arc4random-fork.c deleted file mode 100644 index 9b334945af..0000000000 --- a/src/regress/lib/libc/arc4random-fork/arc4random-fork.c +++ /dev/null | |||
@@ -1,171 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2014 Google Inc. | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <sys/mman.h> | ||
18 | #include <sys/wait.h> | ||
19 | #include <assert.h> | ||
20 | #include <err.h> | ||
21 | #include <errno.h> | ||
22 | #include <signal.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <string.h> | ||
25 | #include <unistd.h> | ||
26 | #include <stdint.h> | ||
27 | |||
28 | #define CHECK(x) assert(x) | ||
29 | #define CHECK_EQ(a, b) assert((a) == (b)) | ||
30 | #define CHECK_NE(a, b) assert((a) != (b)) | ||
31 | #define CHECK_GE(a, b) assert((a) >= (b)) | ||
32 | #define CHECK_LE(a, b) assert((a) <= (b)) | ||
33 | |||
34 | /* Test arc4random_buf(3) instead of arc4random(3). */ | ||
35 | static int flagbuf; | ||
36 | |||
37 | /* Initialize arc4random(3) before forking. */ | ||
38 | static int flagprefork; | ||
39 | |||
40 | enum { | ||
41 | N = 4096 | ||
42 | }; | ||
43 | |||
44 | typedef struct { | ||
45 | uint32_t x[N]; | ||
46 | } Buf; | ||
47 | |||
48 | static int | ||
49 | isfullbuf(const Buf *buf) | ||
50 | { | ||
51 | size_t i; | ||
52 | for (i = 0; i < N; i++) | ||
53 | if (buf->x[i]) | ||
54 | return (1); | ||
55 | return (0); | ||
56 | } | ||
57 | |||
58 | static void | ||
59 | fillbuf(Buf *buf) | ||
60 | { | ||
61 | if (flagbuf) { | ||
62 | arc4random_buf(buf->x, sizeof(buf->x)); | ||
63 | } else { | ||
64 | size_t i; | ||
65 | for (i = 0; i < N; i++) | ||
66 | buf->x[i] = arc4random(); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | static void | ||
71 | usage() | ||
72 | { | ||
73 | errx(1, "usage: arc4random-fork [-bp]"); | ||
74 | } | ||
75 | |||
76 | static pid_t | ||
77 | safewaitpid(pid_t pid, int *status, int options) | ||
78 | { | ||
79 | pid_t ret; | ||
80 | do { | ||
81 | ret = waitpid(pid, status, options); | ||
82 | } while (ret == -1 && errno == EINTR); | ||
83 | return (ret); | ||
84 | } | ||
85 | |||
86 | int | ||
87 | main(int argc, char *argv[]) | ||
88 | { | ||
89 | int opt, status; | ||
90 | Buf *bufparent, *bufchildone, *bufchildtwo; | ||
91 | pid_t pidone, pidtwo; | ||
92 | size_t i, countone = 0, counttwo = 0, countkids = 0; | ||
93 | |||
94 | /* Ensure SIGCHLD isn't set to SIG_IGN. */ | ||
95 | const struct sigaction sa = { | ||
96 | .sa_handler = SIG_DFL, | ||
97 | }; | ||
98 | CHECK_EQ(0, sigaction(SIGCHLD, &sa, NULL)); | ||
99 | |||
100 | while ((opt = getopt(argc, argv, "bp")) != -1) { | ||
101 | switch (opt) { | ||
102 | case 'b': | ||
103 | flagbuf = 1; | ||
104 | break; | ||
105 | case 'p': | ||
106 | flagprefork = 1; | ||
107 | break; | ||
108 | default: | ||
109 | usage(); | ||
110 | } | ||
111 | } | ||
112 | |||
113 | if (flagprefork) | ||
114 | (void)arc4random(); | ||
115 | |||
116 | bufparent = mmap(NULL, sizeof(Buf), PROT_READ|PROT_WRITE, | ||
117 | MAP_ANON|MAP_PRIVATE, -1, 0); | ||
118 | CHECK_NE(MAP_FAILED, bufparent); | ||
119 | |||
120 | bufchildone = mmap(NULL, sizeof(Buf), PROT_READ|PROT_WRITE, | ||
121 | MAP_ANON|MAP_SHARED, -1, 0); | ||
122 | CHECK_NE(MAP_FAILED, bufchildone); | ||
123 | |||
124 | bufchildtwo = mmap(NULL, sizeof(Buf), PROT_READ|PROT_WRITE, | ||
125 | MAP_ANON|MAP_SHARED, -1, 0); | ||
126 | CHECK_NE(MAP_FAILED, bufchildtwo); | ||
127 | |||
128 | pidone = fork(); | ||
129 | CHECK_GE(pidone, 0); | ||
130 | if (pidone == 0) { | ||
131 | fillbuf(bufchildone); | ||
132 | _exit(0); | ||
133 | } | ||
134 | |||
135 | pidtwo = fork(); | ||
136 | CHECK_GE(pidtwo, 0); | ||
137 | if (pidtwo == 0) { | ||
138 | fillbuf(bufchildtwo); | ||
139 | _exit(0); | ||
140 | } | ||
141 | |||
142 | fillbuf(bufparent); | ||
143 | |||
144 | CHECK_EQ(pidone, safewaitpid(pidone, &status, 0)); | ||
145 | CHECK(WIFEXITED(status)); | ||
146 | CHECK_EQ(0, WEXITSTATUS(status)); | ||
147 | |||
148 | CHECK_EQ(pidtwo, safewaitpid(pidtwo, &status, 0)); | ||
149 | CHECK(WIFEXITED(status)); | ||
150 | CHECK_EQ(0, WEXITSTATUS(status)); | ||
151 | |||
152 | CHECK(isfullbuf(bufchildone)); | ||
153 | CHECK(isfullbuf(bufchildtwo)); | ||
154 | |||
155 | for (i = 0; i < N; i++) { | ||
156 | countone += bufparent->x[i] == bufchildone->x[i]; | ||
157 | counttwo += bufparent->x[i] == bufchildtwo->x[i]; | ||
158 | countkids += bufchildone->x[i] == bufchildtwo->x[i]; | ||
159 | } | ||
160 | |||
161 | /* | ||
162 | * These checks are inherently probabilistic and theoretically risk | ||
163 | * flaking, but there's less than a 1 in 2^40 chance of more than | ||
164 | * one pairwise match between two vectors of 4096 32-bit integers. | ||
165 | */ | ||
166 | CHECK_LE(countone, 1); | ||
167 | CHECK_LE(counttwo, 1); | ||
168 | CHECK_LE(countkids, 1); | ||
169 | |||
170 | return (0); | ||
171 | } | ||
diff --git a/src/regress/lib/libc/arch/alpha/Makefile b/src/regress/lib/libc/arch/alpha/Makefile deleted file mode 100644 index 8c4dfb735c..0000000000 --- a/src/regress/lib/libc/arch/alpha/Makefile +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2002/02/23 01:25:11 art Exp $ | ||
2 | # $NetBSD: Makefile,v 1.1 1995/04/24 05:53:31 cgd Exp $ | ||
3 | |||
4 | # do nothing here; none of the tests here can be run automatically | ||
5 | SUBDIR= | ||
6 | |||
7 | install: | ||
8 | |||
9 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/Makefile b/src/regress/lib/libc/arch/alpha/divremtest/Makefile deleted file mode 100644 index 1da3ac8494..0000000000 --- a/src/regress/lib/libc/arch/alpha/divremtest/Makefile +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2001/01/29 02:05:39 niklas Exp $ | ||
2 | # $NetBSD: Makefile,v 1.1 1995/04/24 05:53:34 cgd Exp $ | ||
3 | |||
4 | PROG= divremtest | ||
5 | NOMAN= | ||
6 | |||
7 | CLEANFILES+= mkcases cases.c mktestcases testcases | ||
8 | |||
9 | divremtest.c: cases.c | ||
10 | |||
11 | cases.c: mkcases | ||
12 | /bin/rm -f cases.c | ||
13 | mkcases > cases.c | ||
14 | |||
15 | # a typical strategy to use this: | ||
16 | # compile a NetBSD divremtest binary, an OSF/1 divremtest binary, and an | ||
17 | # OSF/1 mktestcases binary. You then run mktestecases | divremtest -g | ||
18 | # on an OSF/1 machine, and pipe the output to an rsh to a NetBSD machine | ||
19 | # which then runs divremtest. You can test an infinite number of random | ||
20 | # values that way; I like to put a 'dd' in, so I can see how much I've done. | ||
21 | |||
22 | testcases: mktestcases divremtest | ||
23 | /bin/rm -f testcases | ||
24 | mktestcases | divremtest -g > testcases | ||
25 | |||
26 | regress: | ||
27 | @echo THIS TEST CANNOT BE RUN AUTOMATICALLY. | ||
28 | @false | ||
29 | |||
30 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c b/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c deleted file mode 100644 index 3d9e8a6de2..0000000000 --- a/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c +++ /dev/null | |||
@@ -1,184 +0,0 @@ | |||
1 | /* $OpenBSD: divremtest.c,v 1.2 2001/01/29 02:05:39 niklas Exp $ */ | ||
2 | /* $NetBSD: divremtest.c,v 1.1 1995/04/24 05:53:35 cgd Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * 3. All advertising materials mentioning features or use of this software | ||
17 | * must display the following acknowledgement: | ||
18 | * This product includes software developed by Christopher G. Demetriou | ||
19 | * for the NetBSD Project. | ||
20 | * 4. The name of the author may not be used to endorse or promote products | ||
21 | * derived from this software without specific prior written permission | ||
22 | * | ||
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | |||
35 | #include <stdio.h> | ||
36 | #include <unistd.h> | ||
37 | #include <signal.h> | ||
38 | |||
39 | void testfile(); | ||
40 | void usage(); | ||
41 | |||
42 | int generate; | ||
43 | |||
44 | int | ||
45 | main(argc, argv) | ||
46 | int argc; | ||
47 | char **argv; | ||
48 | { | ||
49 | int c; | ||
50 | |||
51 | signal(SIGFPE, SIG_IGN); | ||
52 | |||
53 | while ((c = getopt(argc, argv, "g")) != -1) | ||
54 | switch (c) { | ||
55 | case 'g': | ||
56 | generate = 1; | ||
57 | break; | ||
58 | |||
59 | default: | ||
60 | usage(); | ||
61 | break; | ||
62 | } | ||
63 | |||
64 | argc -= optind; | ||
65 | argv += optind; | ||
66 | |||
67 | if (argc == 0) | ||
68 | testfile(); | ||
69 | else | ||
70 | for (; argc != 0; argc--, argv++) { | ||
71 | if (freopen(argv[0], "r", stdin) == NULL) { | ||
72 | fprintf(stderr, | ||
73 | "divremtest: couldn't open %s\n", | ||
74 | argv[0]); | ||
75 | exit(1); | ||
76 | } | ||
77 | |||
78 | testfile(); | ||
79 | } | ||
80 | |||
81 | exit(0); | ||
82 | } | ||
83 | |||
84 | void | ||
85 | testfile() | ||
86 | { | ||
87 | union operand { | ||
88 | unsigned long input; | ||
89 | int op_int; | ||
90 | unsigned int op_u_int; | ||
91 | long op_long; | ||
92 | unsigned long op_u_long; | ||
93 | } op1, op2, divres, modres, divwant, modwant; | ||
94 | char opspec[6]; | ||
95 | int encoded, i; | ||
96 | |||
97 | while (scanf("%6c %lx %lx %lx %lx\n", opspec, &op1.input, | ||
98 | &op2.input, &divwant.input, &modwant.input) != EOF) { | ||
99 | |||
100 | encoded = 0; | ||
101 | |||
102 | for (i = 0; i < 6; i += 2) { | ||
103 | int posval; | ||
104 | |||
105 | switch (opspec[i]) { | ||
106 | case '.': | ||
107 | posval = 0; | ||
108 | break; | ||
109 | case '-': | ||
110 | posval = 1; | ||
111 | break; | ||
112 | default: | ||
113 | fprintf(stderr, | ||
114 | "unknown signedness spec %c\n", | ||
115 | opspec[i]); | ||
116 | exit(1); | ||
117 | } | ||
118 | encoded |= posval << ((5 - i) * 4); | ||
119 | } | ||
120 | |||
121 | for (i = 1; i < 6; i += 2) { | ||
122 | int posval; | ||
123 | |||
124 | switch (opspec[i]) { | ||
125 | case 'i': | ||
126 | posval = 0; | ||
127 | break; | ||
128 | case 'l': | ||
129 | posval = 1; | ||
130 | break; | ||
131 | default: | ||
132 | fprintf(stderr, "unknown length spec %c\n", | ||
133 | opspec[i]); | ||
134 | exit(1); | ||
135 | } | ||
136 | encoded |= posval << ((5 - i) * 4); | ||
137 | } | ||
138 | |||
139 | /* KILL ME!!! */ | ||
140 | switch (encoded) { | ||
141 | |||
142 | #define TRY_IT(a, b, c) \ | ||
143 | divres.a = op1.b / op2.c; \ | ||
144 | modres.a = op1.b % op2.c; \ | ||
145 | if (generate) { \ | ||
146 | printf("%6s 0x%016lx 0x%016lx 0x%016lx 0x%016lx\n", \ | ||
147 | opspec, op1.input, op2.input, \ | ||
148 | divres.a, modres.a); \ | ||
149 | } else { \ | ||
150 | if ((divres.a != divwant.a) || \ | ||
151 | (modres.a != modwant.a)) { \ | ||
152 | fprintf(stderr, "%6s 0x%016lx 0x%016lx\n", \ | ||
153 | opspec, op1.input, op2.input); \ | ||
154 | fprintf(stderr, "FAILED:\n"); \ | ||
155 | fprintf(stderr, \ | ||
156 | "div:\twanted 0x%16lx, got 0x%16lx\n", \ | ||
157 | divwant.a, divres.a); \ | ||
158 | fprintf(stderr, \ | ||
159 | "mod:\twanted 0x%16lx, got 0x%16lx\n", \ | ||
160 | modwant.a, modres.a); \ | ||
161 | \ | ||
162 | exit(1); \ | ||
163 | } \ | ||
164 | } | ||
165 | |||
166 | #include "cases.c" | ||
167 | |||
168 | #undef TRY_IT | ||
169 | |||
170 | default: | ||
171 | fprintf(stderr, | ||
172 | "INTERNAL ERROR: unknown encoding %x\n", encoded); | ||
173 | exit(1); | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | |||
178 | void | ||
179 | usage() | ||
180 | { | ||
181 | |||
182 | fprintf(stderr, "usage: divremtest [-v] [testfile ...]\n"); | ||
183 | exit(1); | ||
184 | } | ||
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/mkcases.c b/src/regress/lib/libc/arch/alpha/divremtest/mkcases.c deleted file mode 100644 index fcb4765b8c..0000000000 --- a/src/regress/lib/libc/arch/alpha/divremtest/mkcases.c +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | /* $OpenBSD: mkcases.c,v 1.2 2001/01/29 02:05:39 niklas Exp $ */ | ||
2 | /* $NetBSD: mkcases.c,v 1.1 1995/04/24 05:53:36 cgd Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * 3. All advertising materials mentioning features or use of this software | ||
17 | * must display the following acknowledgement: | ||
18 | * This product includes software developed by Christopher G. Demetriou | ||
19 | * for the NetBSD Project. | ||
20 | * 4. The name of the author may not be used to endorse or promote products | ||
21 | * derived from this software without specific prior written permission | ||
22 | * | ||
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | |||
35 | char *tab[4] = { "u_int", "int", "u_long", "long" }; | ||
36 | |||
37 | int | ||
38 | main() | ||
39 | { | ||
40 | int i; | ||
41 | |||
42 | for (i = 0; i < 64; i++) { | ||
43 | printf( | ||
44 | " case 0x%d%d%d%d%d%d: /* %s <= %s op %s */\n", | ||
45 | (i >> 5) & 1, | ||
46 | (i >> 4) & 1, | ||
47 | (i >> 3) & 1, | ||
48 | (i >> 2) & 1, | ||
49 | (i >> 1) & 1, | ||
50 | (i >> 0) & 1, | ||
51 | tab[(i >> 4) & 0x3], | ||
52 | tab[(i >> 2) & 0x3], | ||
53 | tab[(i >> 0) & 0x3]); | ||
54 | printf( | ||
55 | " TRY_IT(op_%s, op_%s, op_%s);\n", | ||
56 | tab[(i >> 4) & 0x3], | ||
57 | tab[(i >> 2) & 0x3], | ||
58 | tab[(i >> 0) & 0x3]); | ||
59 | printf( | ||
60 | " break;\n\n"); | ||
61 | } | ||
62 | |||
63 | exit(0); | ||
64 | } | ||
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c b/src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c deleted file mode 100644 index 3b01653f32..0000000000 --- a/src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
1 | /* $OpenBSD: mktestcases.c,v 1.2 2001/01/29 02:05:40 niklas Exp $ */ | ||
2 | /* $NetBSD: mktestcases.c,v 1.1 1995/04/24 05:53:37 cgd Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * 3. All advertising materials mentioning features or use of this software | ||
17 | * must display the following acknowledgement: | ||
18 | * This product includes software developed by Christopher G. Demetriou | ||
19 | * for the NetBSD Project. | ||
20 | * 4. The name of the author may not be used to endorse or promote products | ||
21 | * derived from this software without specific prior written permission | ||
22 | * | ||
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | |||
35 | #include <stdio.h> | ||
36 | |||
37 | int | ||
38 | main() | ||
39 | { | ||
40 | int i, j; | ||
41 | unsigned long n1, n2; | ||
42 | |||
43 | srandom(time(NULL)); | ||
44 | |||
45 | for (i = 1; /* i < 10240 */ 1; i++) { | ||
46 | n1 = (unsigned) | ||
47 | (random() & ((random() & random()) | 0x80000000)); | ||
48 | n1 <<= 32; | ||
49 | n1 |= (unsigned)(random() & random() & random()); | ||
50 | |||
51 | n2 = (unsigned) | ||
52 | (random() & ((random() & random()) | 0x80000000)); | ||
53 | n2 <<= 32; | ||
54 | n2 |= (unsigned)(random() & random() & random()); | ||
55 | |||
56 | for (j = 0; j < 64; j++) { | ||
57 | char *tab[] = { ".i", ".l", "-i", "-l" }; | ||
58 | |||
59 | printf("%s%s%s 0x%lx 0x%lx 0 0\n", | ||
60 | tab[(j >> 4) & 0x3], | ||
61 | tab[(j >> 2) & 0x3], | ||
62 | tab[(j >> 0) & 0x3], | ||
63 | n1, n2); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | exit(0); | ||
68 | } | ||
diff --git a/src/regress/lib/libc/asr/Makefile b/src/regress/lib/libc/asr/Makefile deleted file mode 100644 index 12e59536e0..0000000000 --- a/src/regress/lib/libc/asr/Makefile +++ /dev/null | |||
@@ -1,52 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.4 2017/03/10 17:23:48 eric Exp $ | ||
2 | |||
3 | # | ||
4 | # Notes on building and running the regression tests | ||
5 | # | ||
6 | # The regress suite builds two sets of static executables: the former linked | ||
7 | # against the system libc, and the latter against the libc found in /usr/obj | ||
8 | # The idea is to compare the output of all programs with internal changes in | ||
9 | # the libc (more specifically the resolver). They will be run in a chrooted | ||
10 | # environment to test various /etc configurations without touching the local | ||
11 | # machine config files. | ||
12 | # | ||
13 | # First, build a libc that needs testing, then: | ||
14 | # | ||
15 | # $ make | ||
16 | # $ doas make install | ||
17 | # $ doas make regress | ||
18 | # | ||
19 | # Tests output goes into a $REGRESSDIR/tmp.XXXXXXXXXX directory, and a digest | ||
20 | # is displayed at the end. | ||
21 | # | ||
22 | |||
23 | REGRESSDIR?= /tmp/regress-asr | ||
24 | REGRESS?= regress.sh | ||
25 | |||
26 | A?= .a | ||
27 | B?= .b | ||
28 | |||
29 | DIRA?= /usr/lib | ||
30 | DIRB?= /usr/obj/lib/libc | ||
31 | |||
32 | |||
33 | all: build | ||
34 | |||
35 | build: | ||
36 | cd bin && EXT=${A} LDFLAGS=-L${DIRA} make | ||
37 | cd bin && EXT=${B} LDFLAGS=-L${DIRB} make | ||
38 | |||
39 | clean: | ||
40 | cd bin && EXT=${A} make clean | ||
41 | cd bin && EXT=${B} make clean | ||
42 | |||
43 | install: | ||
44 | mkdir -p ${REGRESSDIR}/bin | ||
45 | cd bin && BINDIR=${REGRESSDIR}/bin EXT=${A} make install | ||
46 | cd bin && BINDIR=${REGRESSDIR}/bin EXT=${B} make install | ||
47 | |||
48 | uninstall: | ||
49 | rm -rf ${REGRESSDIR} | ||
50 | |||
51 | regress: | ||
52 | RUNDIR=${REGRESSDIR} A=${A} B=${B} sh ${.CURDIR}/${REGRESS} | ||
diff --git a/src/regress/lib/libc/asr/bin/Makefile b/src/regress/lib/libc/asr/bin/Makefile deleted file mode 100644 index 1f986a8e69..0000000000 --- a/src/regress/lib/libc/asr/bin/Makefile +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | SUBDIR= res_mkquery | ||
2 | SUBDIR+= res_query | ||
3 | SUBDIR+= gethostnamadr | ||
4 | SUBDIR+= getnetnamadr | ||
5 | SUBDIR+= getrrsetbyname | ||
6 | SUBDIR+= getnameinfo | ||
7 | SUBDIR+= getaddrinfo | ||
8 | SUBDIR+= threads | ||
9 | |||
10 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/Makefile.inc b/src/regress/lib/libc/asr/bin/Makefile.inc deleted file mode 100644 index 80b4805136..0000000000 --- a/src/regress/lib/libc/asr/bin/Makefile.inc +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # $OpenBSD: Makefile.inc,v 1.2 2012/09/05 21:21:13 eric Exp $ | ||
2 | |||
3 | NOMAN= noman | ||
4 | |||
5 | SRCS+= common.c | ||
6 | CFLAGS+= -Wall -Wstrict-prototypes -Werror -Wundef -g | ||
7 | LDSTATIC= ${STATIC} | ||
8 | PROG:= ${PROG}${EXT} | ||
diff --git a/src/regress/lib/libc/asr/bin/common.c b/src/regress/lib/libc/asr/bin/common.c deleted file mode 100644 index 08a7bccbb7..0000000000 --- a/src/regress/lib/libc/asr/bin/common.c +++ /dev/null | |||
@@ -1,693 +0,0 @@ | |||
1 | /* $OpenBSD: common.c,v 1.4 2018/12/15 15:16:12 eric Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | #include <sys/types.h> | ||
18 | #include <sys/socket.h> | ||
19 | #include <netinet/in.h> | ||
20 | #include <arpa/inet.h> | ||
21 | #include <arpa/nameser.h> | ||
22 | |||
23 | #include <err.h> | ||
24 | #include <errno.h> | ||
25 | #include <inttypes.h> | ||
26 | #include <netdb.h> | ||
27 | #include <resolv.h> | ||
28 | #include <stdio.h> | ||
29 | #include <string.h> | ||
30 | |||
31 | #include "common.h" | ||
32 | |||
33 | int long_err; | ||
34 | int gai_errno; | ||
35 | int rrset_errno; | ||
36 | |||
37 | |||
38 | char * | ||
39 | gethostarg(char *n) | ||
40 | { | ||
41 | if (n == NULL) | ||
42 | return (n); | ||
43 | if (!strcmp(n, "NULL")) | ||
44 | return (NULL); | ||
45 | if (!strcmp(n, "EMPTY")) | ||
46 | return (""); | ||
47 | return (n); | ||
48 | } | ||
49 | |||
50 | const char *rrsetstrerror(int); | ||
51 | char * print_addr(const struct sockaddr *, char *, size_t); | ||
52 | |||
53 | struct kv { int code; const char *name; }; | ||
54 | |||
55 | struct kv kv_family[] = { | ||
56 | { AF_UNIX, "unix" }, | ||
57 | { AF_INET, "inet" }, | ||
58 | { AF_INET6, "inet6" }, | ||
59 | { 0, NULL, } | ||
60 | }; | ||
61 | struct kv kv_socktype[] = { | ||
62 | { SOCK_STREAM, "stream" }, | ||
63 | { SOCK_DGRAM, "dgram" }, | ||
64 | { SOCK_RAW, "raw" }, | ||
65 | { SOCK_SEQPACKET, "seqpacket" }, | ||
66 | { 0, NULL, } | ||
67 | }; | ||
68 | struct kv kv_protocol[] = { | ||
69 | { IPPROTO_UDP, "udp" }, | ||
70 | { IPPROTO_TCP, "tcp" }, | ||
71 | { IPPROTO_ICMP, "icmp" }, | ||
72 | { IPPROTO_ICMPV6, "icmpv6" }, | ||
73 | { 0, NULL, } | ||
74 | }; | ||
75 | |||
76 | static const char * | ||
77 | kv_lookup_name(struct kv *kv, int code, char *buf, size_t sz) | ||
78 | { | ||
79 | while (kv->name) { | ||
80 | if (kv->code == code) | ||
81 | return (kv->name); | ||
82 | kv++; | ||
83 | } | ||
84 | snprintf(buf, sz, "%i", code); | ||
85 | return (buf); | ||
86 | } | ||
87 | |||
88 | struct keyval { | ||
89 | const char *key; | ||
90 | int value; | ||
91 | }; | ||
92 | |||
93 | static struct keyval kv_class[] = { | ||
94 | { "IN", C_IN }, | ||
95 | { "CHAOS", C_CHAOS }, | ||
96 | { "HS", C_HS }, | ||
97 | { "ANY", C_ANY }, | ||
98 | { NULL, 0 }, | ||
99 | }; | ||
100 | |||
101 | static struct keyval kv_type[] = { | ||
102 | { "A", T_A }, | ||
103 | { "NS", T_NS }, | ||
104 | { "MD", T_MD }, | ||
105 | { "MF", T_MF }, | ||
106 | { "CNAME", T_CNAME }, | ||
107 | { "SOA", T_SOA }, | ||
108 | { "MB", T_MB }, | ||
109 | { "MG", T_MG }, | ||
110 | { "MR", T_MR }, | ||
111 | { "NULL", T_NULL }, | ||
112 | { "WKS", T_WKS }, | ||
113 | { "PTR", T_PTR }, | ||
114 | { "HINFO", T_HINFO }, | ||
115 | { "MINFO", T_MINFO }, | ||
116 | { "MX", T_MX }, | ||
117 | { "TXT", T_TXT }, | ||
118 | |||
119 | { "AAAA", T_AAAA }, | ||
120 | |||
121 | { "AXFR", T_AXFR }, | ||
122 | { "MAILB", T_MAILB }, | ||
123 | { "MAILA", T_MAILA }, | ||
124 | { "ANY", T_ANY }, | ||
125 | { NULL, 0 }, | ||
126 | }; | ||
127 | |||
128 | static struct keyval kv_rcode[] = { | ||
129 | { "NOERROR", NOERROR }, | ||
130 | { "FORMERR", FORMERR }, | ||
131 | { "SERVFAIL", SERVFAIL }, | ||
132 | { "NXDOMAIN", NXDOMAIN }, | ||
133 | { "NOTIMP", NOTIMP }, | ||
134 | { "REFUSED", REFUSED }, | ||
135 | { NULL, 0 }, | ||
136 | }; | ||
137 | |||
138 | static struct keyval kv_resopt[] = { | ||
139 | { "DEBUG", RES_DEBUG }, | ||
140 | { "AAONLY", RES_AAONLY }, | ||
141 | { "USEVC", RES_USEVC }, | ||
142 | { "PRIMARY", RES_PRIMARY }, | ||
143 | { "IGNTC", RES_IGNTC }, | ||
144 | { "RECURSE", RES_RECURSE }, | ||
145 | { "DEFNAMES", RES_DEFNAMES }, | ||
146 | { "STAYOPEN", RES_STAYOPEN }, | ||
147 | { "DNSRCH", RES_DNSRCH }, | ||
148 | { "INSECURE1", RES_INSECURE1 }, | ||
149 | { "INSECURE2", RES_INSECURE2 }, | ||
150 | { "NOALIASES", RES_NOALIASES }, | ||
151 | { "USE_INET6", RES_USE_INET6 }, | ||
152 | { "USE_EDNS0", RES_USE_EDNS0 }, | ||
153 | { "USE_DNSSEC", RES_USE_DNSSEC }, | ||
154 | { NULL, 0 }, | ||
155 | }; | ||
156 | |||
157 | const char * | ||
158 | rcodetostr(uint16_t v) | ||
159 | { | ||
160 | static char buf[16]; | ||
161 | size_t i; | ||
162 | |||
163 | for(i = 0; kv_rcode[i].key; i++) | ||
164 | if (kv_rcode[i].value == v) | ||
165 | return (kv_rcode[i].key); | ||
166 | |||
167 | snprintf(buf, sizeof buf, "%"PRIu16"?", v); | ||
168 | |||
169 | return (buf); | ||
170 | } | ||
171 | |||
172 | const char * | ||
173 | typetostr(uint16_t v) | ||
174 | { | ||
175 | static char buf[16]; | ||
176 | size_t i; | ||
177 | |||
178 | for(i = 0; kv_type[i].key; i++) | ||
179 | if (kv_type[i].value == v) | ||
180 | return (kv_type[i].key); | ||
181 | |||
182 | snprintf(buf, sizeof buf, "%"PRIu16"?", v); | ||
183 | |||
184 | return (buf); | ||
185 | } | ||
186 | |||
187 | const char * | ||
188 | classtostr(uint16_t v) | ||
189 | { | ||
190 | static char buf[16]; | ||
191 | size_t i; | ||
192 | |||
193 | for(i = 0; kv_class[i].key; i++) | ||
194 | if (kv_class[i].value == v) | ||
195 | return (kv_class[i].key); | ||
196 | |||
197 | snprintf(buf, sizeof buf, "%"PRIu16"?", v); | ||
198 | |||
199 | return (buf); | ||
200 | } | ||
201 | |||
202 | uint16_t | ||
203 | strtotype(const char *name) | ||
204 | { | ||
205 | size_t i; | ||
206 | |||
207 | for(i = 0; kv_type[i].key; i++) | ||
208 | if (!strcasecmp(kv_type[i].key, name)) | ||
209 | return (kv_type[i].value); | ||
210 | |||
211 | return (0); | ||
212 | } | ||
213 | |||
214 | uint16_t | ||
215 | strtoclass(const char *name) | ||
216 | { | ||
217 | size_t i; | ||
218 | |||
219 | for(i = 0; kv_class[i].key; i++) | ||
220 | if (!strcasecmp(kv_class[i].key, name)) | ||
221 | return (kv_class[i].value); | ||
222 | |||
223 | return (0); | ||
224 | } | ||
225 | |||
226 | int | ||
227 | strtoresopt(const char *name) | ||
228 | { | ||
229 | size_t i; | ||
230 | |||
231 | for(i = 0; kv_resopt[i].key; i++) | ||
232 | if (!strcasecmp(kv_resopt[i].key, name)) | ||
233 | return (kv_resopt[i].value); | ||
234 | |||
235 | return (0); | ||
236 | } | ||
237 | |||
238 | void | ||
239 | parseresopt(const char *name) | ||
240 | { | ||
241 | static int init = 0; | ||
242 | int flag, neg = 0; | ||
243 | |||
244 | if (init == 0) { | ||
245 | res_init(); | ||
246 | init = 1; | ||
247 | } | ||
248 | |||
249 | if (name[0] == '-') { | ||
250 | neg = 1; | ||
251 | name++; | ||
252 | } | ||
253 | else if (name[0] == '+') | ||
254 | name++; | ||
255 | |||
256 | flag = strtoresopt(name); | ||
257 | if (flag == 0) | ||
258 | errx(1, "unknown reslover option %s", name); | ||
259 | |||
260 | if (neg) | ||
261 | _res.options &= ~flag; | ||
262 | else | ||
263 | _res.options |= flag; | ||
264 | } | ||
265 | |||
266 | void | ||
267 | print_hostent(struct hostent *e) | ||
268 | { | ||
269 | char buf[256], **c; | ||
270 | |||
271 | printf("name = \"%s\"\n", e->h_name); | ||
272 | printf("aliases ="); | ||
273 | for(c = e->h_aliases; *c; c++) | ||
274 | printf(" \"%s\"", *c); | ||
275 | printf("\n"); | ||
276 | printf("addrtype = %i\n", e->h_addrtype); | ||
277 | printf("addrlength = %i\n", e->h_length); | ||
278 | printf("addr_list ="); | ||
279 | for(c = e->h_addr_list; *c; c++) { | ||
280 | printf(" %s", inet_ntop(e->h_addrtype, *c, buf, sizeof buf)); | ||
281 | } | ||
282 | printf("\n"); | ||
283 | } | ||
284 | |||
285 | void | ||
286 | print_netent(struct netent *e) | ||
287 | { | ||
288 | char buf[256], **c; | ||
289 | uint32_t addr; | ||
290 | |||
291 | /* network number are given in host order */ | ||
292 | addr = htonl(e->n_net); | ||
293 | |||
294 | printf("name = \"%s\"\n", e->n_name); | ||
295 | printf("aliases ="); | ||
296 | for (c = e->n_aliases; *c; c++) | ||
297 | printf(" \"%s\"", *c); | ||
298 | printf("\n"); | ||
299 | printf("addrtype = %i\n", e->n_addrtype); | ||
300 | printf("net = %s\n", inet_ntop(e->n_addrtype, &addr, buf, sizeof buf)); | ||
301 | } | ||
302 | |||
303 | void | ||
304 | print_addrinfo(struct addrinfo *ai) | ||
305 | { | ||
306 | char buf[256], bf[64], bt[64], bp[64]; | ||
307 | |||
308 | printf("family=%s socktype=%s protocol=%s addr=%s canonname=%s\n", | ||
309 | kv_lookup_name(kv_family, ai->ai_family, bf, sizeof bf), | ||
310 | kv_lookup_name(kv_socktype, ai->ai_socktype, bt, sizeof bt), | ||
311 | kv_lookup_name(kv_protocol, ai->ai_protocol, bp, sizeof bp), | ||
312 | print_addr(ai->ai_addr, buf, sizeof buf), | ||
313 | ai->ai_canonname); | ||
314 | } | ||
315 | |||
316 | const char * | ||
317 | rrsetstrerror(int e) | ||
318 | { | ||
319 | switch (e) { | ||
320 | case 0: | ||
321 | return "OK"; | ||
322 | case ERRSET_NONAME: | ||
323 | return "ERRSET_NONAME"; | ||
324 | case ERRSET_NODATA: | ||
325 | return "ERRSET_NODATA"; | ||
326 | case ERRSET_NOMEMORY: | ||
327 | return "ERRSET_NOMEMORY"; | ||
328 | case ERRSET_INVAL: | ||
329 | return "ERRSET_INVAL"; | ||
330 | case ERRSET_FAIL: | ||
331 | return "ERRSET_FAIL"; | ||
332 | default: | ||
333 | return "???"; | ||
334 | } | ||
335 | } | ||
336 | |||
337 | void | ||
338 | print_rrsetinfo(struct rrsetinfo * rrset) | ||
339 | { | ||
340 | printf("rri_flags=%u\n", rrset->rri_flags); | ||
341 | printf("rri_rdclass=%u\n", rrset->rri_rdclass); | ||
342 | printf("rri_rdtype=%u\n", rrset->rri_rdtype); | ||
343 | printf("rri_ttl=%u\n", rrset->rri_ttl); | ||
344 | printf("rri_nrdatas=%u\n", rrset->rri_nrdatas); | ||
345 | printf("rri_nsigs=%u\n", rrset->rri_nsigs); | ||
346 | printf("rri_name=\"%s\"\n", rrset->rri_name); | ||
347 | } | ||
348 | |||
349 | void | ||
350 | print_errors(void) | ||
351 | { | ||
352 | switch (long_err) { | ||
353 | case 0: | ||
354 | return; | ||
355 | case 1: | ||
356 | printf(" => errno %i, h_errno %i", errno, h_errno); | ||
357 | printf(", rrset_errno %i", rrset_errno); | ||
358 | printf(", gai_errno %i", gai_errno); | ||
359 | printf ("\n"); | ||
360 | return; | ||
361 | default: | ||
362 | printf(" => errno %i: %s\n => h_errno %i: %s\n => rrset_errno %i: %s\n", | ||
363 | errno, errno ? strerror(errno) : "ok", | ||
364 | h_errno, h_errno ? hstrerror(h_errno) : "ok", | ||
365 | rrset_errno, rrset_errno ? rrsetstrerror(rrset_errno) : "ok"); | ||
366 | printf(" => gai_errno %i: %s\n", | ||
367 | gai_errno, gai_errno ? gai_strerror(gai_errno) : "ok"); | ||
368 | } | ||
369 | } | ||
370 | |||
371 | |||
372 | static char * | ||
373 | print_host(const struct sockaddr *sa, char *buf, size_t len) | ||
374 | { | ||
375 | switch (sa->sa_family) { | ||
376 | case AF_INET: | ||
377 | inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, | ||
378 | buf, len); | ||
379 | break; | ||
380 | case AF_INET6: | ||
381 | inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr, | ||
382 | buf, len); | ||
383 | break; | ||
384 | default: | ||
385 | buf[0] = '\0'; | ||
386 | } | ||
387 | return (buf); | ||
388 | } | ||
389 | |||
390 | |||
391 | char * | ||
392 | print_addr(const struct sockaddr *sa, char *buf, size_t len) | ||
393 | { | ||
394 | char h[256]; | ||
395 | |||
396 | print_host(sa, h, sizeof h); | ||
397 | |||
398 | switch (sa->sa_family) { | ||
399 | case AF_INET: | ||
400 | snprintf(buf, len, "%s:%i", h, | ||
401 | ntohs(((struct sockaddr_in*)(sa))->sin_port)); | ||
402 | break; | ||
403 | case AF_INET6: | ||
404 | snprintf(buf, len, "[%s]:%i", h, | ||
405 | ntohs(((struct sockaddr_in6*)(sa))->sin6_port)); | ||
406 | break; | ||
407 | default: | ||
408 | snprintf(buf, len, "?"); | ||
409 | break; | ||
410 | } | ||
411 | |||
412 | return (buf); | ||
413 | } | ||
414 | |||
415 | void | ||
416 | packed_init(struct packed *pack, char *data, size_t len) | ||
417 | { | ||
418 | pack->data = data; | ||
419 | pack->len = len; | ||
420 | pack->offset = 0; | ||
421 | pack->err = NULL; | ||
422 | } | ||
423 | |||
424 | |||
425 | static ssize_t | ||
426 | dname_expand(const unsigned char *data, size_t len, size_t offset, | ||
427 | size_t *newoffset, char *dst, size_t max) | ||
428 | { | ||
429 | size_t n, count, end, ptr, start; | ||
430 | ssize_t res; | ||
431 | |||
432 | if (offset >= len) | ||
433 | return (-1); | ||
434 | |||
435 | res = 0; | ||
436 | end = start = offset; | ||
437 | |||
438 | for(; (n = data[offset]); ) { | ||
439 | if ((n & 0xc0) == 0xc0) { | ||
440 | if (offset + 2 > len) | ||
441 | return (-1); | ||
442 | ptr = 256 * (n & ~0xc0) + data[offset + 1]; | ||
443 | if (ptr >= start) | ||
444 | return (-1); | ||
445 | if (end < offset + 2) | ||
446 | end = offset + 2; | ||
447 | offset = ptr; | ||
448 | continue; | ||
449 | } | ||
450 | if (offset + n + 1 > len) | ||
451 | return (-1); | ||
452 | |||
453 | |||
454 | /* copy n + at offset+1 */ | ||
455 | if (dst != NULL && max != 0) { | ||
456 | count = (max < n + 1) ? (max) : (n + 1); | ||
457 | memmove(dst, data + offset, count); | ||
458 | dst += count; | ||
459 | max -= count; | ||
460 | } | ||
461 | res += n + 1; | ||
462 | offset += n + 1; | ||
463 | if (end < offset) | ||
464 | end = offset; | ||
465 | } | ||
466 | if (end < offset + 1) | ||
467 | end = offset + 1; | ||
468 | |||
469 | if (dst != NULL && max != 0) | ||
470 | dst[0] = 0; | ||
471 | if (newoffset) | ||
472 | *newoffset = end; | ||
473 | return (res + 1); | ||
474 | } | ||
475 | |||
476 | static int | ||
477 | unpack_data(struct packed *p, void *data, size_t len) | ||
478 | { | ||
479 | if (p->err) | ||
480 | return (-1); | ||
481 | |||
482 | if (p->len - p->offset < len) { | ||
483 | p->err = "too short"; | ||
484 | return (-1); | ||
485 | } | ||
486 | |||
487 | memmove(data, p->data + p->offset, len); | ||
488 | p->offset += len; | ||
489 | |||
490 | return (0); | ||
491 | } | ||
492 | |||
493 | static int | ||
494 | unpack_u16(struct packed *p, uint16_t *u16) | ||
495 | { | ||
496 | if (unpack_data(p, u16, 2) == -1) | ||
497 | return (-1); | ||
498 | |||
499 | *u16 = ntohs(*u16); | ||
500 | |||
501 | return (0); | ||
502 | } | ||
503 | |||
504 | static int | ||
505 | unpack_u32(struct packed *p, uint32_t *u32) | ||
506 | { | ||
507 | if (unpack_data(p, u32, 4) == -1) | ||
508 | return (-1); | ||
509 | |||
510 | *u32 = ntohl(*u32); | ||
511 | |||
512 | return (0); | ||
513 | } | ||
514 | |||
515 | static int | ||
516 | unpack_inaddr(struct packed *p, struct in_addr *a) | ||
517 | { | ||
518 | return (unpack_data(p, a, 4)); | ||
519 | } | ||
520 | |||
521 | static int | ||
522 | unpack_in6addr(struct packed *p, struct in6_addr *a6) | ||
523 | { | ||
524 | return (unpack_data(p, a6, 16)); | ||
525 | } | ||
526 | |||
527 | static int | ||
528 | unpack_dname(struct packed *p, char *dst, size_t max) | ||
529 | { | ||
530 | ssize_t e; | ||
531 | |||
532 | if (p->err) | ||
533 | return (-1); | ||
534 | |||
535 | e = dname_expand(p->data, p->len, p->offset, &p->offset, dst, max); | ||
536 | if (e == -1) { | ||
537 | p->err = "bad domain name"; | ||
538 | return (-1); | ||
539 | } | ||
540 | if (e < 0 || e > MAXDNAME) { | ||
541 | p->err = "domain name too long"; | ||
542 | return (-1); | ||
543 | } | ||
544 | |||
545 | return (0); | ||
546 | } | ||
547 | |||
548 | int | ||
549 | unpack_header(struct packed *p, struct header *h) | ||
550 | { | ||
551 | if (unpack_data(p, h, HFIXEDSZ) == -1) | ||
552 | return (-1); | ||
553 | |||
554 | h->flags = ntohs(h->flags); | ||
555 | h->qdcount = ntohs(h->qdcount); | ||
556 | h->ancount = ntohs(h->ancount); | ||
557 | h->nscount = ntohs(h->nscount); | ||
558 | h->arcount = ntohs(h->arcount); | ||
559 | |||
560 | return (0); | ||
561 | } | ||
562 | |||
563 | int | ||
564 | unpack_query(struct packed *p, struct query *q) | ||
565 | { | ||
566 | unpack_dname(p, q->q_dname, sizeof(q->q_dname)); | ||
567 | unpack_u16(p, &q->q_type); | ||
568 | unpack_u16(p, &q->q_class); | ||
569 | |||
570 | return (p->err) ? (-1) : (0); | ||
571 | } | ||
572 | |||
573 | int | ||
574 | unpack_rr(struct packed *p, struct rr *rr) | ||
575 | { | ||
576 | uint16_t rdlen; | ||
577 | size_t save_offset; | ||
578 | |||
579 | unpack_dname(p, rr->rr_dname, sizeof(rr->rr_dname)); | ||
580 | unpack_u16(p, &rr->rr_type); | ||
581 | unpack_u16(p, &rr->rr_class); | ||
582 | unpack_u32(p, &rr->rr_ttl); | ||
583 | unpack_u16(p, &rdlen); | ||
584 | |||
585 | if (p->err) | ||
586 | return (-1); | ||
587 | |||
588 | if (p->len - p->offset < rdlen) { | ||
589 | p->err = "too short"; | ||
590 | return (-1); | ||
591 | } | ||
592 | |||
593 | save_offset = p->offset; | ||
594 | |||
595 | switch(rr->rr_type) { | ||
596 | |||
597 | case T_CNAME: | ||
598 | unpack_dname(p, rr->rr.cname.cname, sizeof(rr->rr.cname.cname)); | ||
599 | break; | ||
600 | |||
601 | case T_MX: | ||
602 | unpack_u16(p, &rr->rr.mx.preference); | ||
603 | unpack_dname(p, rr->rr.mx.exchange, sizeof(rr->rr.mx.exchange)); | ||
604 | break; | ||
605 | |||
606 | case T_NS: | ||
607 | unpack_dname(p, rr->rr.ns.nsname, sizeof(rr->rr.ns.nsname)); | ||
608 | break; | ||
609 | |||
610 | case T_PTR: | ||
611 | unpack_dname(p, rr->rr.ptr.ptrname, sizeof(rr->rr.ptr.ptrname)); | ||
612 | break; | ||
613 | |||
614 | case T_SOA: | ||
615 | unpack_dname(p, rr->rr.soa.mname, sizeof(rr->rr.soa.mname)); | ||
616 | unpack_dname(p, rr->rr.soa.rname, sizeof(rr->rr.soa.rname)); | ||
617 | unpack_u32(p, &rr->rr.soa.serial); | ||
618 | unpack_u32(p, &rr->rr.soa.refresh); | ||
619 | unpack_u32(p, &rr->rr.soa.retry); | ||
620 | unpack_u32(p, &rr->rr.soa.expire); | ||
621 | unpack_u32(p, &rr->rr.soa.minimum); | ||
622 | break; | ||
623 | |||
624 | case T_A: | ||
625 | if (rr->rr_class != C_IN) | ||
626 | goto other; | ||
627 | unpack_inaddr(p, &rr->rr.in_a.addr); | ||
628 | break; | ||
629 | |||
630 | case T_AAAA: | ||
631 | if (rr->rr_class != C_IN) | ||
632 | goto other; | ||
633 | unpack_in6addr(p, &rr->rr.in_aaaa.addr6); | ||
634 | break; | ||
635 | default: | ||
636 | other: | ||
637 | rr->rr.other.rdata = p->data + p->offset; | ||
638 | rr->rr.other.rdlen = rdlen; | ||
639 | p->offset += rdlen; | ||
640 | } | ||
641 | |||
642 | if (p->err) | ||
643 | return (-1); | ||
644 | |||
645 | /* make sure that the advertised rdlen is really ok */ | ||
646 | if (p->offset - save_offset != rdlen) | ||
647 | p->err = "bad dlen"; | ||
648 | |||
649 | return (p->err) ? (-1) : (0); | ||
650 | } | ||
651 | |||
652 | int | ||
653 | sockaddr_from_str(struct sockaddr *sa, int family, const char *str) | ||
654 | { | ||
655 | struct in_addr ina; | ||
656 | struct in6_addr in6a; | ||
657 | struct sockaddr_in *sin; | ||
658 | struct sockaddr_in6 *sin6; | ||
659 | |||
660 | switch (family) { | ||
661 | case PF_UNSPEC: | ||
662 | if (sockaddr_from_str(sa, PF_INET, str) == 0) | ||
663 | return (0); | ||
664 | return sockaddr_from_str(sa, PF_INET6, str); | ||
665 | |||
666 | case PF_INET: | ||
667 | if (inet_pton(PF_INET, str, &ina) != 1) | ||
668 | return (-1); | ||
669 | |||
670 | sin = (struct sockaddr_in *)sa; | ||
671 | memset(sin, 0, sizeof *sin); | ||
672 | sin->sin_len = sizeof(struct sockaddr_in); | ||
673 | sin->sin_family = PF_INET; | ||
674 | sin->sin_addr.s_addr = ina.s_addr; | ||
675 | return (0); | ||
676 | |||
677 | case PF_INET6: | ||
678 | if (inet_pton(PF_INET6, str, &in6a) != 1) | ||
679 | return (-1); | ||
680 | |||
681 | sin6 = (struct sockaddr_in6 *)sa; | ||
682 | memset(sin6, 0, sizeof *sin6); | ||
683 | sin6->sin6_len = sizeof(struct sockaddr_in6); | ||
684 | sin6->sin6_family = PF_INET6; | ||
685 | sin6->sin6_addr = in6a; | ||
686 | return (0); | ||
687 | |||
688 | default: | ||
689 | break; | ||
690 | } | ||
691 | |||
692 | return (-1); | ||
693 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/common.h b/src/regress/lib/libc/asr/bin/common.h deleted file mode 100644 index 6a6b90a34f..0000000000 --- a/src/regress/lib/libc/asr/bin/common.h +++ /dev/null | |||
@@ -1,138 +0,0 @@ | |||
1 | /* $OpenBSD: common.h,v 1.2 2018/12/15 15:16:12 eric Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | #include <sys/types.h> | ||
18 | #include <sys/socket.h> | ||
19 | |||
20 | #include <arpa/nameser.h> | ||
21 | |||
22 | #include <netinet/in.h> | ||
23 | |||
24 | #include <netdb.h> | ||
25 | |||
26 | |||
27 | #define unpack_rr __unpack_rr | ||
28 | #define unpack_header __unpack_header | ||
29 | #define packed_init __packed_init | ||
30 | #define unpack_query __unpack_query | ||
31 | #define sockaddr_from_str __sockaddr_from_str | ||
32 | #define print_addr __print_addr | ||
33 | |||
34 | extern int long_err; | ||
35 | extern int gai_errno; | ||
36 | extern int rrset_errno; | ||
37 | |||
38 | const char *classtostr(uint16_t); | ||
39 | const char *typetostr(uint16_t); | ||
40 | const char *rcodetostr(uint16_t); | ||
41 | |||
42 | uint16_t strtotype(const char*); | ||
43 | uint16_t strtoclass(const char*); | ||
44 | int strtoresopt(const char*); | ||
45 | void parseresopt(const char*); | ||
46 | |||
47 | void print_rrsetinfo(struct rrsetinfo *); | ||
48 | void print_addrinfo(struct addrinfo *); | ||
49 | void print_errors(void); | ||
50 | void print_hostent(struct hostent *); | ||
51 | void print_netent(struct netent *); | ||
52 | |||
53 | int sockaddr_from_str(struct sockaddr *, int, const char *); | ||
54 | int addr_from_str(char *, int *, int *, const char *); | ||
55 | char* gethostarg(char *); | ||
56 | |||
57 | #define QR_MASK (0x1 << 15) | ||
58 | #define OPCODE_MASK (0xf << 11) | ||
59 | #define AA_MASK (0x1 << 10) | ||
60 | #define TC_MASK (0x1 << 9) | ||
61 | #define RD_MASK (0x1 << 8) | ||
62 | #define RA_MASK (0x1 << 7) | ||
63 | #define Z_MASK (0x7 << 4) | ||
64 | #define RCODE_MASK (0xf) | ||
65 | |||
66 | #define OPCODE(v) ((v) & OPCODE_MASK) | ||
67 | #define RCODE(v) ((v) & RCODE_MASK) | ||
68 | |||
69 | |||
70 | struct packed { | ||
71 | char *data; | ||
72 | size_t len; | ||
73 | size_t offset; | ||
74 | const char *err; | ||
75 | }; | ||
76 | |||
77 | struct header { | ||
78 | uint16_t id; | ||
79 | uint16_t flags; | ||
80 | uint16_t qdcount; | ||
81 | uint16_t ancount; | ||
82 | uint16_t nscount; | ||
83 | uint16_t arcount; | ||
84 | }; | ||
85 | |||
86 | struct query { | ||
87 | char q_dname[MAXDNAME]; | ||
88 | uint16_t q_type; | ||
89 | uint16_t q_class; | ||
90 | }; | ||
91 | |||
92 | struct rr { | ||
93 | char rr_dname[MAXDNAME]; | ||
94 | uint16_t rr_type; | ||
95 | uint16_t rr_class; | ||
96 | uint32_t rr_ttl; | ||
97 | union { | ||
98 | struct { | ||
99 | char cname[MAXDNAME]; | ||
100 | } cname; | ||
101 | struct { | ||
102 | uint16_t preference; | ||
103 | char exchange[MAXDNAME]; | ||
104 | } mx; | ||
105 | struct { | ||
106 | char nsname[MAXDNAME]; | ||
107 | } ns; | ||
108 | struct { | ||
109 | char ptrname[MAXDNAME]; | ||
110 | } ptr; | ||
111 | struct { | ||
112 | char mname[MAXDNAME]; | ||
113 | char rname[MAXDNAME]; | ||
114 | uint32_t serial; | ||
115 | uint32_t refresh; | ||
116 | uint32_t retry; | ||
117 | uint32_t expire; | ||
118 | uint32_t minimum; | ||
119 | } soa; | ||
120 | struct { | ||
121 | struct in_addr addr; | ||
122 | } in_a; | ||
123 | struct { | ||
124 | struct in6_addr addr6; | ||
125 | } in_aaaa; | ||
126 | struct { | ||
127 | uint16_t rdlen; | ||
128 | const void *rdata; | ||
129 | } other; | ||
130 | } rr; | ||
131 | }; | ||
132 | |||
133 | void packed_init(struct packed*, char*, size_t); | ||
134 | int pack_header(struct packed*, const struct header*); | ||
135 | int pack_query(struct packed*, uint16_t, uint16_t, const char*); | ||
136 | int unpack_header(struct packed*, struct header*); | ||
137 | int unpack_query(struct packed*, struct query*); | ||
138 | int unpack_rr(struct packed*, struct rr*); | ||
diff --git a/src/regress/lib/libc/asr/bin/getaddrinfo.c b/src/regress/lib/libc/asr/bin/getaddrinfo.c deleted file mode 100644 index 6605a00c1b..0000000000 --- a/src/regress/lib/libc/asr/bin/getaddrinfo.c +++ /dev/null | |||
@@ -1,138 +0,0 @@ | |||
1 | /* $OpenBSD: getaddrinfo.c,v 1.3 2018/12/15 15:16:12 eric Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | #include <sys/types.h> | ||
18 | #include <sys/socket.h> | ||
19 | |||
20 | #include <netinet/in.h> | ||
21 | |||
22 | #include <err.h> | ||
23 | #include <errno.h> | ||
24 | #include <getopt.h> | ||
25 | #include <netdb.h> | ||
26 | #include <stdio.h> | ||
27 | #include <stdlib.h> | ||
28 | #include <string.h> | ||
29 | |||
30 | #include "common.h" | ||
31 | |||
32 | static void | ||
33 | usage(void) | ||
34 | { | ||
35 | extern const char * __progname; | ||
36 | |||
37 | fprintf(stderr, "usage: %s [-CHSPe] [-f family] [-p proto] " | ||
38 | "[-s servname]\n [-t socktype] <host...>\n", __progname); | ||
39 | exit(1); | ||
40 | } | ||
41 | |||
42 | int | ||
43 | main(int argc, char *argv[]) | ||
44 | { | ||
45 | struct addrinfo *ai, *res, hints; | ||
46 | char *servname = NULL, *host; | ||
47 | int i, ch; | ||
48 | |||
49 | memset(&hints, 0, sizeof hints); | ||
50 | |||
51 | while((ch = getopt(argc, argv, "CFHPR:Sef:p:s:t:")) != -1) { | ||
52 | switch(ch) { | ||
53 | case 'C': | ||
54 | hints.ai_flags |= AI_CANONNAME; | ||
55 | break; | ||
56 | case 'F': | ||
57 | hints.ai_flags |= AI_FQDN; | ||
58 | break; | ||
59 | case 'H': | ||
60 | hints.ai_flags |= AI_NUMERICHOST; | ||
61 | break; | ||
62 | case 'P': | ||
63 | hints.ai_flags |= AI_PASSIVE; | ||
64 | break; | ||
65 | case 'R': | ||
66 | parseresopt(optarg); | ||
67 | break; | ||
68 | case 'S': | ||
69 | hints.ai_flags |= AI_NUMERICSERV; | ||
70 | break; | ||
71 | case 'e': | ||
72 | long_err += 1; | ||
73 | break; | ||
74 | case 'f': | ||
75 | if (!strcmp(optarg, "inet")) | ||
76 | hints.ai_family = AF_INET; | ||
77 | else if (!strcmp(optarg, "inet6")) | ||
78 | hints.ai_family = AF_INET6; | ||
79 | else | ||
80 | usage(); | ||
81 | break; | ||
82 | case 'p': | ||
83 | if (!strcmp(optarg, "udp")) | ||
84 | hints.ai_protocol = IPPROTO_UDP; | ||
85 | else if (!strcmp(optarg, "tcp")) | ||
86 | hints.ai_protocol = IPPROTO_TCP; | ||
87 | else if (!strcmp(optarg, "icmp")) | ||
88 | hints.ai_protocol = IPPROTO_ICMP; | ||
89 | else if (!strcmp(optarg, "icmpv6")) | ||
90 | hints.ai_protocol = IPPROTO_ICMPV6; | ||
91 | else | ||
92 | usage(); | ||
93 | break; | ||
94 | case 's': | ||
95 | servname = optarg; | ||
96 | break; | ||
97 | case 't': | ||
98 | if (!strcmp(optarg, "stream")) | ||
99 | hints.ai_socktype = SOCK_STREAM; | ||
100 | else if (!strcmp(optarg, "dgram")) | ||
101 | hints.ai_socktype = SOCK_DGRAM; | ||
102 | else if (!strcmp(optarg, "raw")) | ||
103 | hints.ai_socktype = SOCK_RAW; | ||
104 | else | ||
105 | usage(); | ||
106 | break; | ||
107 | default: | ||
108 | usage(); | ||
109 | /* NOTREACHED */ | ||
110 | } | ||
111 | } | ||
112 | argc -= optind; | ||
113 | argv += optind; | ||
114 | |||
115 | for(i = 0; i < argc; i++) { | ||
116 | |||
117 | if (i) | ||
118 | printf("\n"); | ||
119 | printf("===> \"%s\"\n", argv[i]); | ||
120 | host = gethostarg(argv[i]); | ||
121 | |||
122 | errno = 0; | ||
123 | h_errno = 0; | ||
124 | gai_errno = 0; | ||
125 | rrset_errno = 0; | ||
126 | |||
127 | gai_errno = getaddrinfo(host, servname, &hints, &ai); | ||
128 | |||
129 | print_errors(); | ||
130 | if (gai_errno == 0) { | ||
131 | for (res = ai; res; res = res->ai_next) | ||
132 | print_addrinfo(res); | ||
133 | freeaddrinfo(ai); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | return (0); | ||
138 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/getaddrinfo/Makefile b/src/regress/lib/libc/asr/bin/getaddrinfo/Makefile deleted file mode 100644 index ec2f104ec7..0000000000 --- a/src/regress/lib/libc/asr/bin/getaddrinfo/Makefile +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
2 | |||
3 | .PATH: ${.CURDIR}/.. | ||
4 | |||
5 | PROG= getaddrinfo | ||
6 | SRCS+= getaddrinfo.c | ||
7 | |||
8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/gethostnamadr.c b/src/regress/lib/libc/asr/bin/gethostnamadr.c deleted file mode 100644 index 9cdf7ed448..0000000000 --- a/src/regress/lib/libc/asr/bin/gethostnamadr.c +++ /dev/null | |||
@@ -1,116 +0,0 @@ | |||
1 | /* $OpenBSD: gethostnamadr.c,v 1.3 2018/12/15 15:16:12 eric Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | #include <sys/types.h> | ||
18 | #include <sys/socket.h> | ||
19 | #include <netinet/in.h> | ||
20 | #include <arpa/inet.h> | ||
21 | |||
22 | #include <err.h> | ||
23 | #include <errno.h> | ||
24 | #include <getopt.h> | ||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <string.h> | ||
28 | |||
29 | #include "common.h" | ||
30 | |||
31 | static void | ||
32 | usage(void) | ||
33 | { | ||
34 | extern const char * __progname; | ||
35 | |||
36 | fprintf(stderr, "usage: %s [-46e] <host...>\n", __progname); | ||
37 | exit(1); | ||
38 | } | ||
39 | |||
40 | int | ||
41 | main(int argc, char *argv[]) | ||
42 | { | ||
43 | int i, ch, aflag, family = AF_INET; | ||
44 | struct hostent *h; | ||
45 | char *host; | ||
46 | char addr[16]; | ||
47 | int addrlen; | ||
48 | |||
49 | aflag = 0; | ||
50 | while((ch = getopt(argc, argv, "46R:ae")) != -1) { | ||
51 | switch(ch) { | ||
52 | case '4': | ||
53 | family = AF_INET; | ||
54 | break; | ||
55 | case '6': | ||
56 | family = AF_INET6; | ||
57 | break; | ||
58 | case 'R': | ||
59 | parseresopt(optarg); | ||
60 | break; | ||
61 | case 'a': | ||
62 | aflag = 1; | ||
63 | break; | ||
64 | case 'e': | ||
65 | long_err += 1; | ||
66 | break; | ||
67 | default: | ||
68 | usage(); | ||
69 | /* NOTREACHED */ | ||
70 | } | ||
71 | } | ||
72 | argc -= optind; | ||
73 | argv += optind; | ||
74 | |||
75 | for(i = 0; i < argc; i++) { | ||
76 | |||
77 | if (i) | ||
78 | printf("\n"); | ||
79 | printf("===> \"%s\"\n", argv[i]); | ||
80 | host = gethostarg(argv[i]); | ||
81 | |||
82 | if (aflag && addr_from_str(addr, &family, &addrlen, host) == -1) | ||
83 | errx(1, "bad address"); | ||
84 | |||
85 | errno = 0; | ||
86 | h_errno = 0; | ||
87 | gai_errno = 0; | ||
88 | rrset_errno = 0; | ||
89 | |||
90 | if (aflag == 0) | ||
91 | h = gethostbyname2(host, family); | ||
92 | else | ||
93 | h = gethostbyaddr(addr, addrlen, family); | ||
94 | if (h) | ||
95 | print_hostent(h); | ||
96 | print_errors(); | ||
97 | } | ||
98 | |||
99 | return (0); | ||
100 | } | ||
101 | |||
102 | int | ||
103 | addr_from_str(char *addr, int *family, int *len, const char *src) | ||
104 | { | ||
105 | if (inet_pton(AF_INET6, src, addr) == 1) { | ||
106 | *family = AF_INET6; | ||
107 | *len = 16; | ||
108 | return (0); | ||
109 | } | ||
110 | if (inet_pton(AF_INET, src, addr) == 1) { | ||
111 | *family = AF_INET; | ||
112 | *len = 4; | ||
113 | return (0); | ||
114 | } | ||
115 | return (-1); | ||
116 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/gethostnamadr/Makefile b/src/regress/lib/libc/asr/bin/gethostnamadr/Makefile deleted file mode 100644 index 84906ffbbd..0000000000 --- a/src/regress/lib/libc/asr/bin/gethostnamadr/Makefile +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
2 | |||
3 | .PATH: ${.CURDIR}/.. | ||
4 | |||
5 | PROG= gethostnamadr | ||
6 | SRCS+= gethostnamadr.c | ||
7 | |||
8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/getnameinfo.c b/src/regress/lib/libc/asr/bin/getnameinfo.c deleted file mode 100644 index bd0fbe224f..0000000000 --- a/src/regress/lib/libc/asr/bin/getnameinfo.c +++ /dev/null | |||
@@ -1,115 +0,0 @@ | |||
1 | /* $OpenBSD: getnameinfo.c,v 1.2 2018/12/15 15:16:12 eric Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <err.h> | ||
19 | #include <errno.h> | ||
20 | #include <getopt.h> | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | |||
25 | #include "common.h" | ||
26 | |||
27 | static void | ||
28 | usage(void) | ||
29 | { | ||
30 | extern const char * __progname; | ||
31 | |||
32 | fprintf(stderr, "usage: %s [-DFHNSe] [-p portno] <addr...>\n", __progname); | ||
33 | exit(1); | ||
34 | } | ||
35 | |||
36 | int | ||
37 | main(int argc, char *argv[]) | ||
38 | { | ||
39 | char serv[1024]; | ||
40 | char host[1024]; | ||
41 | const char *e; | ||
42 | int i, ch, flags = 0, port = 0; | ||
43 | struct sockaddr_storage ss; | ||
44 | struct sockaddr *sa; | ||
45 | |||
46 | sa = (struct sockaddr*)&ss; | ||
47 | |||
48 | while((ch = getopt(argc, argv, "DFHNR:Saep:")) != -1) { | ||
49 | switch(ch) { | ||
50 | case 'D': | ||
51 | flags |= NI_DGRAM; | ||
52 | break; | ||
53 | case 'F': | ||
54 | flags |= NI_NOFQDN; | ||
55 | break; | ||
56 | case 'H': | ||
57 | flags |= NI_NUMERICHOST; | ||
58 | break; | ||
59 | case 'N': | ||
60 | flags |= NI_NAMEREQD; | ||
61 | break; | ||
62 | case 'R': | ||
63 | parseresopt(optarg); | ||
64 | break; | ||
65 | case 'S': | ||
66 | flags |= NI_NUMERICSERV; | ||
67 | break; | ||
68 | case 'e': | ||
69 | long_err += 1; | ||
70 | break; | ||
71 | case 'p': | ||
72 | port = strtonum(optarg, 0, 65535, &e); | ||
73 | if (e) | ||
74 | usage(); | ||
75 | break; | ||
76 | default: | ||
77 | usage(); | ||
78 | /* NOTREACHED */ | ||
79 | } | ||
80 | } | ||
81 | argc -= optind; | ||
82 | argv += optind; | ||
83 | |||
84 | for(i = 0; i < argc; i++) { | ||
85 | |||
86 | if (i) | ||
87 | printf("\n"); | ||
88 | printf("===> \"%s\"\n", argv[i]); | ||
89 | |||
90 | if (sockaddr_from_str(sa, AF_UNSPEC, argv[i]) == -1) { | ||
91 | printf(" => invalid address\n"); | ||
92 | continue; | ||
93 | } | ||
94 | |||
95 | if (sa->sa_family == PF_INET) | ||
96 | ((struct sockaddr_in *)sa)->sin_port = htons(port); | ||
97 | else if (sa->sa_family == PF_INET6) | ||
98 | ((struct sockaddr_in6 *)sa)->sin6_port = htons(port); | ||
99 | |||
100 | errno = 0; | ||
101 | h_errno = 0; | ||
102 | gai_errno = 0; | ||
103 | rrset_errno = 0; | ||
104 | |||
105 | gai_errno = getnameinfo(sa, sa->sa_len, host, sizeof host, serv, | ||
106 | sizeof serv, flags); | ||
107 | |||
108 | if (gai_errno == 0) | ||
109 | printf(" %s:%s\n", host, serv); | ||
110 | print_errors(); | ||
111 | |||
112 | } | ||
113 | |||
114 | return (0); | ||
115 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/getnameinfo/Makefile b/src/regress/lib/libc/asr/bin/getnameinfo/Makefile deleted file mode 100644 index 4927ee9486..0000000000 --- a/src/regress/lib/libc/asr/bin/getnameinfo/Makefile +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
2 | |||
3 | .PATH: ${.CURDIR}/.. | ||
4 | |||
5 | PROG= getnameinfo | ||
6 | SRCS+= getnameinfo.c | ||
7 | |||
8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/getnetnamadr.c b/src/regress/lib/libc/asr/bin/getnetnamadr.c deleted file mode 100644 index e615e8663f..0000000000 --- a/src/regress/lib/libc/asr/bin/getnetnamadr.c +++ /dev/null | |||
@@ -1,88 +0,0 @@ | |||
1 | /* $OpenBSD: getnetnamadr.c,v 1.2 2018/12/15 15:16:12 eric Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | #include <sys/types.h> | ||
18 | #include <sys/socket.h> | ||
19 | #include <netinet/in.h> | ||
20 | #include <arpa/inet.h> | ||
21 | |||
22 | #include <err.h> | ||
23 | #include <errno.h> | ||
24 | #include <getopt.h> | ||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <string.h> | ||
28 | |||
29 | #include "common.h" | ||
30 | |||
31 | static void | ||
32 | usage(void) | ||
33 | { | ||
34 | extern const char * __progname; | ||
35 | |||
36 | fprintf(stderr, "usage: %s [-aen] [host...]\n", __progname); | ||
37 | exit(1); | ||
38 | } | ||
39 | |||
40 | int | ||
41 | main(int argc, char *argv[]) | ||
42 | { | ||
43 | int i, ch, nflag = 0; | ||
44 | struct netent *n; | ||
45 | char *host; | ||
46 | |||
47 | while((ch = getopt(argc, argv, "R:en")) != -1) { | ||
48 | switch(ch) { | ||
49 | case 'R': | ||
50 | parseresopt(optarg); | ||
51 | break; | ||
52 | case 'e': | ||
53 | long_err += 1; | ||
54 | break; | ||
55 | case 'n': | ||
56 | nflag = 1; | ||
57 | break; | ||
58 | default: | ||
59 | usage(); | ||
60 | /* NOTREACHED */ | ||
61 | } | ||
62 | } | ||
63 | argc -= optind; | ||
64 | argv += optind; | ||
65 | |||
66 | for(i = 0; i < argc; i++) { | ||
67 | |||
68 | if (i) | ||
69 | printf("\n"); | ||
70 | printf("===> \"%s\"\n", argv[i]); | ||
71 | host = gethostarg(argv[i]); | ||
72 | |||
73 | errno = 0; | ||
74 | h_errno = 0; | ||
75 | gai_errno = 0; | ||
76 | rrset_errno = 0; | ||
77 | |||
78 | if (nflag) | ||
79 | n = getnetbyname(host); | ||
80 | else | ||
81 | n = getnetbyaddr(inet_network(host), AF_INET); | ||
82 | if (n) | ||
83 | print_netent(n); | ||
84 | print_errors(); | ||
85 | } | ||
86 | |||
87 | return (0); | ||
88 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/getnetnamadr/Makefile b/src/regress/lib/libc/asr/bin/getnetnamadr/Makefile deleted file mode 100644 index 521bf8eb7e..0000000000 --- a/src/regress/lib/libc/asr/bin/getnetnamadr/Makefile +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
2 | |||
3 | .PATH: ${.CURDIR}/.. | ||
4 | |||
5 | PROG= getnetnamadr | ||
6 | SRCS+= getnetnamadr.c | ||
7 | |||
8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/getrrsetbyname.c b/src/regress/lib/libc/asr/bin/getrrsetbyname.c deleted file mode 100644 index 8f48501a3f..0000000000 --- a/src/regress/lib/libc/asr/bin/getrrsetbyname.c +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | /* $OpenBSD: getrrsetbyname.c,v 1.2 2018/12/15 15:16:12 eric Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <sys/types.h> | ||
19 | |||
20 | #include <netinet/in.h> | ||
21 | #include <arpa/nameser.h> | ||
22 | |||
23 | #include <err.h> | ||
24 | #include <errno.h> | ||
25 | #include <getopt.h> | ||
26 | #include <resolv.h> | ||
27 | #include <stdio.h> | ||
28 | #include <stdlib.h> | ||
29 | #include <string.h> | ||
30 | |||
31 | #include "common.h" | ||
32 | |||
33 | static void | ||
34 | usage(void) | ||
35 | { | ||
36 | extern const char * __progname; | ||
37 | |||
38 | fprintf(stderr, "usage: %s [-e] [-t type] [host...]\n", | ||
39 | __progname); | ||
40 | exit(1); | ||
41 | } | ||
42 | |||
43 | int | ||
44 | main(int argc, char *argv[]) | ||
45 | { | ||
46 | int ch, i; | ||
47 | uint16_t type = T_A; | ||
48 | char *host; | ||
49 | struct rrsetinfo *rrset; | ||
50 | |||
51 | while((ch = getopt(argc, argv, "R:et:")) != -1) { | ||
52 | switch(ch) { | ||
53 | case 'R': | ||
54 | parseresopt(optarg); | ||
55 | break; | ||
56 | case 'e': | ||
57 | long_err += 1; | ||
58 | break; | ||
59 | case 't': | ||
60 | if ((type = strtotype(optarg)) == 0) | ||
61 | usage(); | ||
62 | break; | ||
63 | default: | ||
64 | usage(); | ||
65 | /* NOTREACHED */ | ||
66 | } | ||
67 | } | ||
68 | argc -= optind; | ||
69 | argv += optind; | ||
70 | |||
71 | for (i = 0; i < argc; i++) { | ||
72 | |||
73 | if (i) | ||
74 | printf("\n"); | ||
75 | printf("===> \"%s\"\n", argv[i]); | ||
76 | host = gethostarg(argv[i]); | ||
77 | |||
78 | errno = 0; | ||
79 | h_errno = 0; | ||
80 | gai_errno = 0; | ||
81 | rrset_errno = 0; | ||
82 | |||
83 | rrset_errno = getrrsetbyname(host, C_IN, type, 0, &rrset); | ||
84 | |||
85 | if (rrset_errno == 0) | ||
86 | print_rrsetinfo(rrset); | ||
87 | print_errors(); | ||
88 | } | ||
89 | |||
90 | return (0); | ||
91 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/getrrsetbyname/Makefile b/src/regress/lib/libc/asr/bin/getrrsetbyname/Makefile deleted file mode 100644 index 131403bea1..0000000000 --- a/src/regress/lib/libc/asr/bin/getrrsetbyname/Makefile +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
2 | |||
3 | .PATH: ${.CURDIR}/.. | ||
4 | |||
5 | PROG= getrrsetbyname | ||
6 | SRCS+= getrrsetbyname.c | ||
7 | |||
8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/res_mkquery.c b/src/regress/lib/libc/asr/bin/res_mkquery.c deleted file mode 100644 index ed41e1120d..0000000000 --- a/src/regress/lib/libc/asr/bin/res_mkquery.c +++ /dev/null | |||
@@ -1,322 +0,0 @@ | |||
1 | /* $OpenBSD: res_mkquery.c,v 1.3 2022/01/20 14:18:10 naddy Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <sys/types.h> | ||
19 | #include <sys/socket.h> | ||
20 | |||
21 | #include <netinet/in.h> | ||
22 | #include <arpa/nameser.h> | ||
23 | #include <arpa/inet.h> | ||
24 | |||
25 | #include <err.h> | ||
26 | #include <errno.h> | ||
27 | #include <getopt.h> | ||
28 | #include <inttypes.h> | ||
29 | #include <resolv.h> | ||
30 | #include <stdio.h> | ||
31 | #include <stdlib.h> | ||
32 | #include <string.h> | ||
33 | |||
34 | #include "common.h" | ||
35 | |||
36 | /* in asr.c but we don't want them exposed right now */ | ||
37 | static void dump_packet(const void *, size_t); | ||
38 | |||
39 | static char *print_query(struct query *, char *, size_t); | ||
40 | static char *print_rr(struct rr *, char *, size_t); | ||
41 | static char *print_host(const struct sockaddr *, char *, size_t); | ||
42 | static char* print_dname(const char *, char *, size_t); | ||
43 | |||
44 | |||
45 | static void | ||
46 | usage(void) | ||
47 | { | ||
48 | extern const char * __progname; | ||
49 | |||
50 | fprintf(stderr, "usage: %s [-deq] [-t type] [host...]\n", | ||
51 | __progname); | ||
52 | exit(1); | ||
53 | } | ||
54 | |||
55 | int | ||
56 | main(int argc, char *argv[]) | ||
57 | { | ||
58 | int ch, i, r; | ||
59 | uint16_t type = T_A; | ||
60 | char buf[1024], *host; | ||
61 | |||
62 | while((ch = getopt(argc, argv, "R:et:")) != -1) { | ||
63 | switch(ch) { | ||
64 | case 'R': | ||
65 | parseresopt(optarg); | ||
66 | break; | ||
67 | case 'e': | ||
68 | long_err += 1; | ||
69 | break; | ||
70 | case 't': | ||
71 | if ((type = strtotype(optarg)) == 0) | ||
72 | usage(); | ||
73 | break; | ||
74 | default: | ||
75 | usage(); | ||
76 | /* NOTREACHED */ | ||
77 | } | ||
78 | } | ||
79 | argc -= optind; | ||
80 | argv += optind; | ||
81 | |||
82 | for (i = 0; i < argc; i++) { | ||
83 | |||
84 | if (i) | ||
85 | printf("\n"); | ||
86 | |||
87 | printf("===> \"%s\"\n", argv[i]); | ||
88 | host = gethostarg(argv[i]); | ||
89 | |||
90 | errno = 0; | ||
91 | h_errno = 0; | ||
92 | gai_errno = 0; | ||
93 | rrset_errno = 0; | ||
94 | |||
95 | r = res_mkquery(QUERY, host, C_IN, type, NULL, 0, NULL, buf, sizeof(buf)); | ||
96 | if (r != -1) { | ||
97 | dump_packet(buf, r); | ||
98 | printf(";; MSG SIZE %i\n", r); | ||
99 | } | ||
100 | print_errors(); | ||
101 | } | ||
102 | |||
103 | return (0); | ||
104 | } | ||
105 | |||
106 | #define OPCODE_SHIFT 11 | ||
107 | #define Z_SHIFT 4 | ||
108 | |||
109 | static char* | ||
110 | print_header(struct header *h, char *buf, size_t max) | ||
111 | { | ||
112 | snprintf(buf, max, | ||
113 | "id:0x.... %s op:%i %s %s %s %s z:%i r:%s qd:%i an:%i ns:%i ar:%i", | ||
114 | (h->flags & QR_MASK) ? "QR":" ", | ||
115 | (int)(OPCODE(h->flags) >> OPCODE_SHIFT), | ||
116 | (h->flags & AA_MASK) ? "AA":" ", | ||
117 | (h->flags & TC_MASK) ? "TC":" ", | ||
118 | (h->flags & RD_MASK) ? "RD":" ", | ||
119 | (h->flags & RA_MASK) ? "RA":" ", | ||
120 | ((h->flags & Z_MASK) >> Z_SHIFT), | ||
121 | rcodetostr(RCODE(h->flags)), | ||
122 | h->qdcount, h->ancount, h->nscount, h->arcount); | ||
123 | |||
124 | return buf; | ||
125 | } | ||
126 | |||
127 | static void | ||
128 | dump_packet(const void *data, size_t len) | ||
129 | { | ||
130 | char buf[1024]; | ||
131 | struct packed p; | ||
132 | struct header h; | ||
133 | struct query q; | ||
134 | struct rr rr; | ||
135 | int i, an, ns, ar, n; | ||
136 | |||
137 | packed_init(&p, (char *)data, len); | ||
138 | |||
139 | if (unpack_header(&p, &h) == -1) { | ||
140 | printf(";; BAD PACKET: %s\n", p.err); | ||
141 | return; | ||
142 | } | ||
143 | |||
144 | printf(";; HEADER %s\n", print_header(&h, buf, sizeof buf)); | ||
145 | |||
146 | if (h.qdcount) | ||
147 | printf(";; QUERY SECTION:\n"); | ||
148 | for (i = 0; i < h.qdcount; i++) { | ||
149 | if (unpack_query(&p, &q) == -1) | ||
150 | goto error; | ||
151 | printf("%s\n", print_query(&q, buf, sizeof buf)); | ||
152 | } | ||
153 | |||
154 | an = 0; | ||
155 | ns = an + h.ancount; | ||
156 | ar = ns + h.nscount; | ||
157 | n = ar + h.arcount; | ||
158 | |||
159 | for (i = 0; i < n; i++) { | ||
160 | if (i == an) | ||
161 | printf("\n;; ANSWER SECTION:\n"); | ||
162 | if (i == ns) | ||
163 | printf("\n;; AUTHORITY SECTION:\n"); | ||
164 | if (i == ar) | ||
165 | printf("\n;; ADDITIONAL SECTION:\n"); | ||
166 | |||
167 | if (unpack_rr(&p, &rr) == -1) | ||
168 | goto error; | ||
169 | printf("%s\n", print_rr(&rr, buf, sizeof buf)); | ||
170 | } | ||
171 | |||
172 | if (p.offset != len) | ||
173 | printf(";; REMAINING GARBAGE %zu\n", len - p.offset); | ||
174 | |||
175 | error: | ||
176 | if (p.err) | ||
177 | printf(";; ERROR AT OFFSET %zu/%zu: %s\n", p.offset, p.len, | ||
178 | p.err); | ||
179 | } | ||
180 | |||
181 | static const char * | ||
182 | inet6_ntoa(struct in6_addr a) | ||
183 | { | ||
184 | static char buf[256]; | ||
185 | struct sockaddr_in6 si; | ||
186 | |||
187 | si.sin6_len = sizeof(si); | ||
188 | si.sin6_family = PF_INET6; | ||
189 | si.sin6_addr = a; | ||
190 | |||
191 | return print_host((struct sockaddr*)&si, buf, sizeof buf); | ||
192 | } | ||
193 | |||
194 | static char* | ||
195 | print_rr(struct rr *rr, char *buf, size_t max) | ||
196 | { | ||
197 | char *res; | ||
198 | char tmp[256]; | ||
199 | char tmp2[256]; | ||
200 | int r; | ||
201 | |||
202 | res = buf; | ||
203 | |||
204 | r = snprintf(buf, max, "%s %u %s %s ", | ||
205 | print_dname(rr->rr_dname, tmp, sizeof tmp), | ||
206 | rr->rr_ttl, | ||
207 | classtostr(rr->rr_class), | ||
208 | typetostr(rr->rr_type)); | ||
209 | if (r == -1) { | ||
210 | buf[0] = '\0'; | ||
211 | return buf; | ||
212 | } | ||
213 | |||
214 | if ((size_t)r >= max) | ||
215 | return buf; | ||
216 | |||
217 | max -= r; | ||
218 | buf += r; | ||
219 | |||
220 | switch(rr->rr_type) { | ||
221 | case T_CNAME: | ||
222 | print_dname(rr->rr.cname.cname, buf, max); | ||
223 | break; | ||
224 | case T_MX: | ||
225 | snprintf(buf, max, "%"PRIu32" %s", | ||
226 | rr->rr.mx.preference, | ||
227 | print_dname(rr->rr.mx.exchange, tmp, sizeof tmp)); | ||
228 | break; | ||
229 | case T_NS: | ||
230 | print_dname(rr->rr.ns.nsname, buf, max); | ||
231 | break; | ||
232 | case T_PTR: | ||
233 | print_dname(rr->rr.ptr.ptrname, buf, max); | ||
234 | break; | ||
235 | case T_SOA: | ||
236 | snprintf(buf, max, | ||
237 | "%s %s %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32, | ||
238 | print_dname(rr->rr.soa.rname, tmp, sizeof tmp), | ||
239 | print_dname(rr->rr.soa.mname, tmp2, sizeof tmp2), | ||
240 | rr->rr.soa.serial, | ||
241 | rr->rr.soa.refresh, | ||
242 | rr->rr.soa.retry, | ||
243 | rr->rr.soa.expire, | ||
244 | rr->rr.soa.minimum); | ||
245 | break; | ||
246 | case T_A: | ||
247 | if (rr->rr_class != C_IN) | ||
248 | goto other; | ||
249 | snprintf(buf, max, "%s", inet_ntoa(rr->rr.in_a.addr)); | ||
250 | break; | ||
251 | case T_AAAA: | ||
252 | if (rr->rr_class != C_IN) | ||
253 | goto other; | ||
254 | snprintf(buf, max, "%s", inet6_ntoa(rr->rr.in_aaaa.addr6)); | ||
255 | break; | ||
256 | default: | ||
257 | other: | ||
258 | snprintf(buf, max, "(rdlen=%"PRIu16 ")", rr->rr.other.rdlen); | ||
259 | break; | ||
260 | } | ||
261 | |||
262 | return (res); | ||
263 | } | ||
264 | |||
265 | static char* | ||
266 | print_query(struct query *q, char *buf, size_t max) | ||
267 | { | ||
268 | char b[256]; | ||
269 | |||
270 | snprintf(buf, max, "%s %s %s", | ||
271 | print_dname(q->q_dname, b, sizeof b), | ||
272 | classtostr(q->q_class), typetostr(q->q_type)); | ||
273 | |||
274 | return (buf); | ||
275 | } | ||
276 | |||
277 | |||
278 | static char * | ||
279 | print_host(const struct sockaddr *sa, char *buf, size_t len) | ||
280 | { | ||
281 | switch (sa->sa_family) { | ||
282 | case AF_INET: | ||
283 | inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, buf, len); | ||
284 | break; | ||
285 | case AF_INET6: | ||
286 | inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr, buf, len); | ||
287 | break; | ||
288 | default: | ||
289 | buf[0] = '\0'; | ||
290 | } | ||
291 | return (buf); | ||
292 | } | ||
293 | |||
294 | static char* | ||
295 | print_dname(const char *_dname, char *buf, size_t max) | ||
296 | { | ||
297 | const unsigned char *dname = _dname; | ||
298 | char *res; | ||
299 | size_t left, count; | ||
300 | |||
301 | if (_dname[0] == 0) { | ||
302 | strlcpy(buf, ".", max); | ||
303 | return buf; | ||
304 | } | ||
305 | |||
306 | res = buf; | ||
307 | left = max - 1; | ||
308 | while (dname[0] && left) { | ||
309 | count = (dname[0] < (left - 1)) ? dname[0] : (left - 1); | ||
310 | memmove(buf, dname + 1, count); | ||
311 | dname += dname[0] + 1; | ||
312 | left -= count; | ||
313 | buf += count; | ||
314 | if (left) { | ||
315 | left -= 1; | ||
316 | *buf++ = '.'; | ||
317 | } | ||
318 | } | ||
319 | buf[0] = 0; | ||
320 | |||
321 | return (res); | ||
322 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/res_mkquery/Makefile b/src/regress/lib/libc/asr/bin/res_mkquery/Makefile deleted file mode 100644 index 4ae259e45d..0000000000 --- a/src/regress/lib/libc/asr/bin/res_mkquery/Makefile +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2017/03/09 08:26:42 eric Exp $ | ||
2 | |||
3 | .PATH: ${.CURDIR}/.. | ||
4 | |||
5 | PROG= res_mkquery | ||
6 | SRCS+= res_mkquery.c | ||
7 | |||
8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/res_query.c b/src/regress/lib/libc/asr/bin/res_query.c deleted file mode 100644 index a2c3686ca3..0000000000 --- a/src/regress/lib/libc/asr/bin/res_query.c +++ /dev/null | |||
@@ -1,358 +0,0 @@ | |||
1 | /* $OpenBSD: res_query.c,v 1.4 2022/01/20 14:18:10 naddy Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <sys/types.h> | ||
19 | #include <sys/socket.h> | ||
20 | #include <sys/time.h> | ||
21 | |||
22 | #include <netinet/in.h> | ||
23 | #include <arpa/nameser.h> | ||
24 | #include <arpa/inet.h> | ||
25 | |||
26 | #include <err.h> | ||
27 | #include <errno.h> | ||
28 | #include <getopt.h> | ||
29 | #include <inttypes.h> | ||
30 | #include <resolv.h> | ||
31 | #include <stdio.h> | ||
32 | #include <stdlib.h> | ||
33 | #include <string.h> | ||
34 | |||
35 | #include "common.h" | ||
36 | |||
37 | /* in asr.c but we don't want them exposed right now */ | ||
38 | static void dump_packet(const void *, size_t); | ||
39 | |||
40 | static char *print_query(struct query *, char *, size_t); | ||
41 | static char *print_rr(struct rr *, char *, size_t); | ||
42 | static char *print_host(const struct sockaddr *, char *, size_t); | ||
43 | static char* print_dname(const char *, char *, size_t); | ||
44 | |||
45 | |||
46 | static int | ||
47 | msec(struct timeval start, struct timeval end) | ||
48 | { | ||
49 | return (int)((end.tv_sec - start.tv_sec) * 1000 | ||
50 | + (end.tv_usec - start.tv_usec) / 1000); | ||
51 | } | ||
52 | |||
53 | static void | ||
54 | usage(void) | ||
55 | { | ||
56 | extern const char * __progname; | ||
57 | |||
58 | fprintf(stderr, "usage: %s [-deq] [-t type] [host...]\n", | ||
59 | __progname); | ||
60 | exit(1); | ||
61 | } | ||
62 | |||
63 | int | ||
64 | main(int argc, char *argv[]) | ||
65 | { | ||
66 | struct timeval start, end; | ||
67 | time_t when; | ||
68 | int ch, i, qflag, dflag, r; | ||
69 | uint16_t type = T_A; | ||
70 | char buf[1024], *host; | ||
71 | |||
72 | dflag = 0; | ||
73 | qflag = 0; | ||
74 | |||
75 | while((ch = getopt(argc, argv, "R:deqt:")) != -1) { | ||
76 | switch(ch) { | ||
77 | case 'R': | ||
78 | parseresopt(optarg); | ||
79 | break; | ||
80 | case 'd': | ||
81 | dflag = 1; | ||
82 | break; | ||
83 | case 'e': | ||
84 | long_err += 1; | ||
85 | break; | ||
86 | case 'q': | ||
87 | qflag = 1; | ||
88 | break; | ||
89 | case 't': | ||
90 | if ((type = strtotype(optarg)) == 0) | ||
91 | usage(); | ||
92 | break; | ||
93 | default: | ||
94 | usage(); | ||
95 | /* NOTREACHED */ | ||
96 | } | ||
97 | } | ||
98 | argc -= optind; | ||
99 | argv += optind; | ||
100 | |||
101 | for (i = 0; i < argc; i++) { | ||
102 | |||
103 | if (i) | ||
104 | printf("\n"); | ||
105 | |||
106 | printf("===> \"%s\"\n", argv[i]); | ||
107 | host = gethostarg(argv[i]); | ||
108 | |||
109 | errno = 0; | ||
110 | h_errno = 0; | ||
111 | gai_errno = 0; | ||
112 | rrset_errno = 0; | ||
113 | |||
114 | if (gettimeofday(&start, NULL) != 0) | ||
115 | err(1, "gettimeofday"); | ||
116 | |||
117 | if (qflag) | ||
118 | r = res_query(host, C_IN, type, buf, sizeof(buf)); | ||
119 | else | ||
120 | r = res_search(host, C_IN, type, buf, sizeof(buf)); | ||
121 | |||
122 | if (gettimeofday(&end, NULL) != 0) | ||
123 | err(1, "gettimeofday"); | ||
124 | |||
125 | if (r != -1) { | ||
126 | dump_packet(buf, r); | ||
127 | printf("\n"); | ||
128 | if (dflag) { | ||
129 | printf(";; Query time: %d msec\n", | ||
130 | msec(start, end)); | ||
131 | when = time(NULL); | ||
132 | printf(";; WHEN: %s", ctime(&when)); | ||
133 | } | ||
134 | printf(";; MSG SIZE rcvd: %i\n", r); | ||
135 | } | ||
136 | print_errors(); | ||
137 | } | ||
138 | |||
139 | return (0); | ||
140 | } | ||
141 | |||
142 | #define OPCODE_SHIFT 11 | ||
143 | #define Z_SHIFT 4 | ||
144 | |||
145 | static char* | ||
146 | print_header(struct header *h, char *buf, size_t max) | ||
147 | { | ||
148 | snprintf(buf, max, | ||
149 | "id:0x.... %s op:%i %s %s %s %s z:%i r:%s qd:%i an:%i ns:%i ar:%i", | ||
150 | (h->flags & QR_MASK) ? "QR":" ", | ||
151 | (int)(OPCODE(h->flags) >> OPCODE_SHIFT), | ||
152 | (h->flags & AA_MASK) ? "AA":" ", | ||
153 | (h->flags & TC_MASK) ? "TC":" ", | ||
154 | (h->flags & RD_MASK) ? "RD":" ", | ||
155 | (h->flags & RA_MASK) ? "RA":" ", | ||
156 | ((h->flags & Z_MASK) >> Z_SHIFT), | ||
157 | rcodetostr(RCODE(h->flags)), | ||
158 | h->qdcount, h->ancount, h->nscount, h->arcount); | ||
159 | |||
160 | return buf; | ||
161 | } | ||
162 | |||
163 | static void | ||
164 | dump_packet(const void *data, size_t len) | ||
165 | { | ||
166 | char buf[1024]; | ||
167 | struct packed p; | ||
168 | struct header h; | ||
169 | struct query q; | ||
170 | struct rr rr; | ||
171 | int i, an, ns, ar, n; | ||
172 | |||
173 | packed_init(&p, (char *)data, len); | ||
174 | |||
175 | if (unpack_header(&p, &h) == -1) { | ||
176 | printf(";; BAD PACKET: %s\n", p.err); | ||
177 | return; | ||
178 | } | ||
179 | |||
180 | printf(";; HEADER %s\n", print_header(&h, buf, sizeof buf)); | ||
181 | |||
182 | if (h.qdcount) | ||
183 | printf(";; QUERY SECTION:\n"); | ||
184 | for (i = 0; i < h.qdcount; i++) { | ||
185 | if (unpack_query(&p, &q) == -1) | ||
186 | goto error; | ||
187 | printf("%s\n", print_query(&q, buf, sizeof buf)); | ||
188 | } | ||
189 | |||
190 | an = 0; | ||
191 | ns = an + h.ancount; | ||
192 | ar = ns + h.nscount; | ||
193 | n = ar + h.arcount; | ||
194 | |||
195 | for (i = 0; i < n; i++) { | ||
196 | if (i == an) | ||
197 | printf("\n;; ANSWER SECTION:\n"); | ||
198 | if (i == ns) | ||
199 | printf("\n;; AUTHORITY SECTION:\n"); | ||
200 | if (i == ar) | ||
201 | printf("\n;; ADDITIONAL SECTION:\n"); | ||
202 | |||
203 | if (unpack_rr(&p, &rr) == -1) | ||
204 | goto error; | ||
205 | printf("%s\n", print_rr(&rr, buf, sizeof buf)); | ||
206 | } | ||
207 | |||
208 | if (p.offset != len) | ||
209 | printf(";; REMAINING GARBAGE %zu\n", len - p.offset); | ||
210 | |||
211 | error: | ||
212 | if (p.err) | ||
213 | printf(";; ERROR AT OFFSET %zu/%zu: %s\n", p.offset, p.len, | ||
214 | p.err); | ||
215 | } | ||
216 | |||
217 | static const char * | ||
218 | inet6_ntoa(struct in6_addr a) | ||
219 | { | ||
220 | static char buf[256]; | ||
221 | struct sockaddr_in6 si; | ||
222 | |||
223 | si.sin6_len = sizeof(si); | ||
224 | si.sin6_family = PF_INET6; | ||
225 | si.sin6_addr = a; | ||
226 | |||
227 | return print_host((struct sockaddr*)&si, buf, sizeof buf); | ||
228 | } | ||
229 | |||
230 | static char* | ||
231 | print_rr(struct rr *rr, char *buf, size_t max) | ||
232 | { | ||
233 | char *res; | ||
234 | char tmp[256]; | ||
235 | char tmp2[256]; | ||
236 | int r; | ||
237 | |||
238 | res = buf; | ||
239 | |||
240 | r = snprintf(buf, max, "%s %u %s %s ", | ||
241 | print_dname(rr->rr_dname, tmp, sizeof tmp), | ||
242 | rr->rr_ttl, | ||
243 | classtostr(rr->rr_class), | ||
244 | typetostr(rr->rr_type)); | ||
245 | if (r == -1) { | ||
246 | buf[0] = '\0'; | ||
247 | return buf; | ||
248 | } | ||
249 | |||
250 | if ((size_t)r >= max) | ||
251 | return buf; | ||
252 | |||
253 | max -= r; | ||
254 | buf += r; | ||
255 | |||
256 | switch(rr->rr_type) { | ||
257 | case T_CNAME: | ||
258 | print_dname(rr->rr.cname.cname, buf, max); | ||
259 | break; | ||
260 | case T_MX: | ||
261 | snprintf(buf, max, "%"PRIu32" %s", | ||
262 | rr->rr.mx.preference, | ||
263 | print_dname(rr->rr.mx.exchange, tmp, sizeof tmp)); | ||
264 | break; | ||
265 | case T_NS: | ||
266 | print_dname(rr->rr.ns.nsname, buf, max); | ||
267 | break; | ||
268 | case T_PTR: | ||
269 | print_dname(rr->rr.ptr.ptrname, buf, max); | ||
270 | break; | ||
271 | case T_SOA: | ||
272 | snprintf(buf, max, | ||
273 | "%s %s %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32, | ||
274 | print_dname(rr->rr.soa.rname, tmp, sizeof tmp), | ||
275 | print_dname(rr->rr.soa.mname, tmp2, sizeof tmp2), | ||
276 | rr->rr.soa.serial, | ||
277 | rr->rr.soa.refresh, | ||
278 | rr->rr.soa.retry, | ||
279 | rr->rr.soa.expire, | ||
280 | rr->rr.soa.minimum); | ||
281 | break; | ||
282 | case T_A: | ||
283 | if (rr->rr_class != C_IN) | ||
284 | goto other; | ||
285 | snprintf(buf, max, "%s", inet_ntoa(rr->rr.in_a.addr)); | ||
286 | break; | ||
287 | case T_AAAA: | ||
288 | if (rr->rr_class != C_IN) | ||
289 | goto other; | ||
290 | snprintf(buf, max, "%s", inet6_ntoa(rr->rr.in_aaaa.addr6)); | ||
291 | break; | ||
292 | default: | ||
293 | other: | ||
294 | snprintf(buf, max, "(rdlen=%"PRIu16 ")", rr->rr.other.rdlen); | ||
295 | break; | ||
296 | } | ||
297 | |||
298 | return (res); | ||
299 | } | ||
300 | |||
301 | static char* | ||
302 | print_query(struct query *q, char *buf, size_t max) | ||
303 | { | ||
304 | char b[256]; | ||
305 | |||
306 | snprintf(buf, max, "%s %s %s", | ||
307 | print_dname(q->q_dname, b, sizeof b), | ||
308 | classtostr(q->q_class), typetostr(q->q_type)); | ||
309 | |||
310 | return (buf); | ||
311 | } | ||
312 | |||
313 | |||
314 | static char * | ||
315 | print_host(const struct sockaddr *sa, char *buf, size_t len) | ||
316 | { | ||
317 | switch (sa->sa_family) { | ||
318 | case AF_INET: | ||
319 | inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, buf, len); | ||
320 | break; | ||
321 | case AF_INET6: | ||
322 | inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr, buf, len); | ||
323 | break; | ||
324 | default: | ||
325 | buf[0] = '\0'; | ||
326 | } | ||
327 | return (buf); | ||
328 | } | ||
329 | |||
330 | static char* | ||
331 | print_dname(const char *_dname, char *buf, size_t max) | ||
332 | { | ||
333 | const unsigned char *dname = _dname; | ||
334 | char *res; | ||
335 | size_t left, count; | ||
336 | |||
337 | if (_dname[0] == 0) { | ||
338 | strlcpy(buf, ".", max); | ||
339 | return buf; | ||
340 | } | ||
341 | |||
342 | res = buf; | ||
343 | left = max - 1; | ||
344 | while (dname[0] && left) { | ||
345 | count = (dname[0] < (left - 1)) ? dname[0] : (left - 1); | ||
346 | memmove(buf, dname + 1, count); | ||
347 | dname += dname[0] + 1; | ||
348 | left -= count; | ||
349 | buf += count; | ||
350 | if (left) { | ||
351 | left -= 1; | ||
352 | *buf++ = '.'; | ||
353 | } | ||
354 | } | ||
355 | buf[0] = 0; | ||
356 | |||
357 | return (res); | ||
358 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/res_query/Makefile b/src/regress/lib/libc/asr/bin/res_query/Makefile deleted file mode 100644 index 6f4d83392b..0000000000 --- a/src/regress/lib/libc/asr/bin/res_query/Makefile +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2017/03/09 08:26:42 eric Exp $ | ||
2 | |||
3 | .PATH: ${.CURDIR}/.. | ||
4 | |||
5 | PROG= res_query | ||
6 | SRCS+= res_query.c | ||
7 | |||
8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/threads.c b/src/regress/lib/libc/asr/bin/threads.c deleted file mode 100644 index f296f1d6f7..0000000000 --- a/src/regress/lib/libc/asr/bin/threads.c +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | /* $OpenBSD: threads.c,v 1.1.1.1 2012/07/13 17:49:53 eric Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | #include <sys/time.h> | ||
18 | #include <sys/resource.h> | ||
19 | |||
20 | #include <assert.h> | ||
21 | #include <err.h> | ||
22 | #include <getopt.h> | ||
23 | #include <pthread.h> | ||
24 | #include <stdio.h> | ||
25 | #include <stdlib.h> | ||
26 | #include <time.h> | ||
27 | |||
28 | #include <netdb.h> | ||
29 | |||
30 | #define MAX_THREADS 50 | ||
31 | |||
32 | int ac; | ||
33 | char **av; | ||
34 | int loop; | ||
35 | int nthreads; | ||
36 | |||
37 | int long_err; | ||
38 | int gai_errno; | ||
39 | int rrset_errno; | ||
40 | |||
41 | void async_resolver_done(void *); | ||
42 | |||
43 | void stats(void) | ||
44 | { | ||
45 | struct rusage ru; | ||
46 | |||
47 | getrusage(RUSAGE_SELF, &ru); | ||
48 | printf("%li\n", ru.ru_maxrss); | ||
49 | } | ||
50 | |||
51 | void* | ||
52 | task(void *arg) | ||
53 | { | ||
54 | int id, i, j, c; | ||
55 | struct addrinfo *ai, *n; | ||
56 | |||
57 | id = *((int*) arg); | ||
58 | |||
59 | n = NULL; c =0; | ||
60 | |||
61 | for(j = 0; j < loop; j++) | ||
62 | for(i = 0; i < ac; i++) { | ||
63 | if (getaddrinfo(av[i], NULL, NULL, &ai) == 0) { | ||
64 | /* | ||
65 | for (c = 0, n = ai; n; c++, n = n->ai_next); | ||
66 | printf("%i:%s: ok: %i\n", id, av[i], c); | ||
67 | */ | ||
68 | freeaddrinfo(ai); | ||
69 | } else { | ||
70 | /* | ||
71 | printf("%i:%s: fail\n", id, av[i]); | ||
72 | */ | ||
73 | } | ||
74 | } | ||
75 | return (NULL); | ||
76 | } | ||
77 | |||
78 | void | ||
79 | usage(void) | ||
80 | { | ||
81 | extern const char *__progname; | ||
82 | fprintf(stderr, "usage: %s [-L loop] [-l loop] [-t threads] <host> ...\n", | ||
83 | __progname); | ||
84 | } | ||
85 | |||
86 | int | ||
87 | main(int argc, char **argv) | ||
88 | { | ||
89 | pthread_t th[MAX_THREADS]; | ||
90 | int th_args[MAX_THREADS], r, i, ch; | ||
91 | int n, LOOP; | ||
92 | |||
93 | nthreads = 1; | ||
94 | loop = 1; | ||
95 | LOOP = 1; | ||
96 | |||
97 | while ((ch = getopt(argc, argv, "L:l:t:")) != -1) { | ||
98 | switch (ch) { | ||
99 | case 'L': | ||
100 | LOOP = atoi(optarg); | ||
101 | break; | ||
102 | case 'l': | ||
103 | loop = atoi(optarg); | ||
104 | break; | ||
105 | case 't': | ||
106 | nthreads = atoi(optarg); | ||
107 | if (nthreads > MAX_THREADS) | ||
108 | nthreads = MAX_THREADS; | ||
109 | break; | ||
110 | default: | ||
111 | usage(); | ||
112 | /* NOTREACHED */ | ||
113 | } | ||
114 | } | ||
115 | |||
116 | argc -= optind; | ||
117 | argv += optind; | ||
118 | |||
119 | ac = argc; | ||
120 | av = argv; | ||
121 | |||
122 | printf("%i %i %i\n", LOOP, nthreads, loop); | ||
123 | for (n = 0; n < LOOP; n ++) { | ||
124 | for (i = 0; i < nthreads; i++) { | ||
125 | th_args[i] = i; | ||
126 | r = pthread_create(&th[i], NULL, task, (void *) &th_args[i]); | ||
127 | if (r == -1) | ||
128 | errx(1, "pthread_create"); | ||
129 | } | ||
130 | for (i = 0; i < nthreads; i++) | ||
131 | pthread_join(th[i], NULL); | ||
132 | |||
133 | if (nthreads == 0) | ||
134 | task(&n); | ||
135 | |||
136 | stats(); | ||
137 | } | ||
138 | |||
139 | return (0); | ||
140 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/threads/Makefile b/src/regress/lib/libc/asr/bin/threads/Makefile deleted file mode 100644 index 3252511cd1..0000000000 --- a/src/regress/lib/libc/asr/bin/threads/Makefile +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
2 | |||
3 | .PATH: ${.CURDIR}/.. | ||
4 | |||
5 | PROG= threads | ||
6 | SRCS+= threads.c | ||
7 | |||
8 | LDADD= -lpthread | ||
9 | |||
10 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/regress.sh b/src/regress/lib/libc/asr/regress.sh deleted file mode 100644 index a0950cefde..0000000000 --- a/src/regress/lib/libc/asr/regress.sh +++ /dev/null | |||
@@ -1,111 +0,0 @@ | |||
1 | # $OpenBSD: regress.sh,v 1.7 2017/03/10 17:23:48 eric Exp $ | ||
2 | |||
3 | . regress.subr | ||
4 | |||
5 | test_res_mkquery() | ||
6 | { | ||
7 | for i in $@; do | ||
8 | regress res_mkquery $i | ||
9 | done | ||
10 | } | ||
11 | |||
12 | test_res_query() | ||
13 | { | ||
14 | for i in $@; do | ||
15 | regress res_query $i | ||
16 | regress res_query -q $i | ||
17 | done | ||
18 | } | ||
19 | |||
20 | test_getrrsetbyname() | ||
21 | { | ||
22 | for i in $@; do | ||
23 | regress getrrsetbyname $i | ||
24 | regress getrrsetbyname -t MX $i | ||
25 | regress getrrsetbyname -t AAAA $i | ||
26 | done | ||
27 | } | ||
28 | |||
29 | test_gethostbyname() | ||
30 | { | ||
31 | for i in $@; do | ||
32 | regress gethostnamadr $i | ||
33 | regress gethostnamadr -4 $i | ||
34 | regress gethostnamadr -6 $i | ||
35 | done | ||
36 | } | ||
37 | |||
38 | test_gethostbyaddr() | ||
39 | { | ||
40 | for i in $@; do | ||
41 | regress gethostnamadr -a $i | ||
42 | done | ||
43 | } | ||
44 | |||
45 | test_getaddrinfo() | ||
46 | { | ||
47 | for i in $@; do | ||
48 | regress getaddrinfo $i | ||
49 | regress getaddrinfo -C $i | ||
50 | regress getaddrinfo -F $i | ||
51 | regress getaddrinfo -CF $i | ||
52 | regress getaddrinfo -P $i | ||
53 | regress getaddrinfo -PF $i | ||
54 | regress getaddrinfo -PC $i | ||
55 | regress getaddrinfo -H $i | ||
56 | regress getaddrinfo -p tcp $i | ||
57 | regress getaddrinfo -p udp $i | ||
58 | regress getaddrinfo -s www $i | ||
59 | regress getaddrinfo -s bad $i | ||
60 | regress getaddrinfo -S -s 8081 $i | ||
61 | regress getaddrinfo -S -s bad $i | ||
62 | regress getaddrinfo -P -s syslog $i | ||
63 | regress getaddrinfo -P -s syslog -p tcp $i | ||
64 | regress getaddrinfo -P -s syslog -p udp $i | ||
65 | done | ||
66 | } | ||
67 | |||
68 | test_getaddrinfo2() | ||
69 | { | ||
70 | for i in $@; do | ||
71 | regress getaddrinfo -f inet6 -t raw -p icmpv6 $i | ||
72 | done | ||
73 | } | ||
74 | |||
75 | test_getnameinfo() | ||
76 | { | ||
77 | for i in $@; do | ||
78 | regress getnameinfo $i | ||
79 | regress getnameinfo -D $i | ||
80 | regress getnameinfo -F $i | ||
81 | regress getnameinfo -H $i | ||
82 | regress getnameinfo -N $i | ||
83 | regress getnameinfo -S $i | ||
84 | regress getnameinfo -p 80 $i | ||
85 | regress getnameinfo -p 514 $i | ||
86 | regress getnameinfo -p 514 -D $i | ||
87 | regress getnameinfo -p 5566 $i | ||
88 | done | ||
89 | } | ||
90 | |||
91 | WEIRD="EMPTY . .. ..." | ||
92 | BASIC="localhost $(hostname -s) $(hostname)" | ||
93 | EXTRA="undeadly.org www.openbsd.org cvs.openbsd.org www.google.com www.bing.com" | ||
94 | |||
95 | ADDRS="0.0.0.0 :: 127.0.0.1 ::1 212.227.193.194" | ||
96 | |||
97 | for e in file bind local; do | ||
98 | regress_setenv $e | ||
99 | |||
100 | test_res_mkquery $WEIRD $BASIC | ||
101 | test_res_query $WEIRD $BASIC $EXTRA | ||
102 | test_getrrsetbyname $WEIRD $BASIC $EXTRA | ||
103 | test_gethostbyname $WEIRD $BASIC $EXTRA | ||
104 | test_gethostbyaddr $ADDRS | ||
105 | test_getaddrinfo NULL $WEIRD $BASIC $EXTRA | ||
106 | test_getaddrinfo2 undeadly.org www.kame.net | ||
107 | test_getnameinfo $ADDRS | ||
108 | test_gethostbyname $ADDRS | ||
109 | done | ||
110 | |||
111 | regress_digest | ||
diff --git a/src/regress/lib/libc/asr/regress.subr b/src/regress/lib/libc/asr/regress.subr deleted file mode 100644 index 6ce645bc33..0000000000 --- a/src/regress/lib/libc/asr/regress.subr +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | # $OpenBSD: regress.subr,v 1.4 2017/03/14 20:22:06 eric Exp $ | ||
3 | |||
4 | set -e | ||
5 | |||
6 | fail() | ||
7 | { | ||
8 | echo "*** ERROR: $@" | ||
9 | exit 1 | ||
10 | } | ||
11 | |||
12 | regress() | ||
13 | { | ||
14 | local cmd="$1" | ||
15 | local bin0="/bin/${cmd}${A}" | ||
16 | local bin1="/bin/${cmd}${B}" | ||
17 | local out="${OUTDIR}/test-${COUNT}.out" | ||
18 | local out0="${OUTDIR}/test-${COUNT}${A}.out" | ||
19 | local out1="${OUTDIR}/test-${COUNT}${B}.out" | ||
20 | local err0="${OUTDIR}/test-${COUNT}${A}.err" | ||
21 | local err1="${OUTDIR}/test-${COUNT}${B}.err" | ||
22 | local outdiff="${OUTDIR}/test-${COUNT}${A}${B}.diff" | ||
23 | shift | ||
24 | |||
25 | test -x "${ROOTDIR}${bin0}" || fail "${ROOTDIR}${bin0}" not executable | ||
26 | test -x "${ROOTDIR}${bin1}" || fail "${ROOTDIR}${bin1}" not executable | ||
27 | |||
28 | echo -n "${cmd} $@ ." | ||
29 | |||
30 | set +e | ||
31 | chroot -u bin "${ROOTDIR}" ${bin0} $@ > ${out0} | ||
32 | echo -n . | ||
33 | chroot -u bin "${ROOTDIR}" ${bin1} $@ > ${out1} | ||
34 | echo -n "." | ||
35 | |||
36 | diff -u ${out0} ${out1} > ${outdiff} | ||
37 | set -e | ||
38 | if test -s ${outdiff}; then | ||
39 | FAIL=$((FAIL+1)) | ||
40 | echo fail | ||
41 | echo "### FAIL [#${COUNT} env=${REGRESSENV}] ${cmd} $@" >> $ERR | ||
42 | cat ${outdiff} >> $ERR | ||
43 | echo >> $ERR | ||
44 | else | ||
45 | rm ${outdiff} | ||
46 | rm ${out1} | ||
47 | mv ${out0} ${out} | ||
48 | OK=$((OK+1)) | ||
49 | echo ok | ||
50 | echo "### OK [#${COUNT} env=$REGRESSENV] ${cmd} $@" >> $OUT | ||
51 | cat ${out} >> $OUT | ||
52 | echo >> $OUT | ||
53 | fi | ||
54 | |||
55 | COUNT=$((COUNT+1)) | ||
56 | } | ||
57 | |||
58 | regress_setenv() | ||
59 | { | ||
60 | local _name="$1" | ||
61 | |||
62 | echo "==> using env $_name" | ||
63 | |||
64 | mkdir -p "${ROOTDIR}/etc/" | ||
65 | cp /etc/hosts "${ROOTDIR}/etc/" | ||
66 | cp /etc/resolv.conf "${ROOTDIR}/etc/" | ||
67 | cp /etc/protocols "${ROOTDIR}/etc/" | ||
68 | cp /etc/networks "${ROOTDIR}/etc/" | ||
69 | cp /etc/services "${ROOTDIR}/etc/" | ||
70 | |||
71 | case $_name in | ||
72 | empty) | ||
73 | rm -f "${ROOTDIR}/etc/*" | ||
74 | ;; | ||
75 | local) | ||
76 | ;; | ||
77 | file) | ||
78 | grep -v lookup /etc/resolv.conf > "${ROOTDIR}/etc/resolv.conf" | ||
79 | echo "lookup file" >> "${ROOTDIR}/etc/resolv.conf" | ||
80 | ;; | ||
81 | bind) | ||
82 | grep -v lookup /etc/resolv.conf > "${ROOTDIR}/etc/resolv.conf" | ||
83 | echo "lookup bind" >> "${ROOTDIR}/etc/resolv.conf" | ||
84 | ;; | ||
85 | *) | ||
86 | fail unknown env $_name | ||
87 | ;; | ||
88 | esac | ||
89 | REGRESSENV=$_name | ||
90 | } | ||
91 | |||
92 | regress_digest() | ||
93 | { | ||
94 | echo "===> done" | ||
95 | test -f $ERR && (echo; cat $ERR; echo "===> errfile=$ERR") | ||
96 | echo "===> logfile=$OUT" | ||
97 | echo "===> run=$COUNT ok=$OK fail=$FAIL error=$ERROR" | ||
98 | |||
99 | } | ||
100 | |||
101 | # needed for chroot | ||
102 | test "$(id -u)" -ne 0 && fail need root privileges to run this script | ||
103 | |||
104 | # we really really want to avoid erasing /etc later | ||
105 | test "${RUNDIR}" || fail RUNDIR is not set | ||
106 | |||
107 | ROOTDIR=$(readlink -fn ${RUNDIR}) | ||
108 | test "${ROOTDIR}" == "/" && fail RUNDIR is root dir: ${RUNDIR} | ||
109 | |||
110 | COUNT=0 | ||
111 | OK=0 | ||
112 | FAIL=0 | ||
113 | ERROR=0 | ||
114 | A=${A:=.a} | ||
115 | B=${B:=.b} | ||
116 | |||
117 | OUTDIR=$(mktemp -d -p $ROOTDIR) | ||
118 | chmod a+rx ${OUTDIR} | ||
119 | echo "===> ${OUTDIR}" | ||
120 | |||
121 | OUT=$OUTDIR/regress.log | ||
122 | ERR=$OUTDIR/regress.err | ||
diff --git a/src/regress/lib/libc/atexit/Makefile b/src/regress/lib/libc/atexit/Makefile deleted file mode 100644 index eb8c55e91e..0000000000 --- a/src/regress/lib/libc/atexit/Makefile +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.7 2017/07/27 15:08:37 bluhm Exp $ | ||
2 | |||
3 | PROG = atexit_test | ||
4 | CPPFLAGS = -I${.CURDIR}/../../../../lib/libc | ||
5 | CLEANFILES = invalid.out valid.out | ||
6 | LDADD = -static | ||
7 | |||
8 | run-regress-${PROG}: ${PROG} | ||
9 | ./${PROG} -valid 2>${.OBJDIR}/valid.out | ||
10 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok | ||
11 | ./${PROG} -invalid-atexit 2>${.OBJDIR}/invalid.out | ||
12 | cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok | ||
13 | ./${PROG} -invalid-cleanup 2>${.OBJDIR}/invalid.out | ||
14 | cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok | ||
15 | |||
16 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/atexit/atexit_test.c b/src/regress/lib/libc/atexit/atexit_test.c deleted file mode 100644 index f00a81a6c9..0000000000 --- a/src/regress/lib/libc/atexit/atexit_test.c +++ /dev/null | |||
@@ -1,152 +0,0 @@ | |||
1 | /* $OpenBSD: atexit_test.c,v 1.10 2024/03/05 19:27:47 miod Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2002 Daniel Hartmeier | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * | ||
11 | * - Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * - Redistributions in binary form must reproduce the above | ||
14 | * copyright notice, this list of conditions and the following | ||
15 | * disclaimer in the documentation and/or other materials provided | ||
16 | * with the distribution. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
29 | * POSSIBILITY OF SUCH DAMAGE. | ||
30 | * | ||
31 | * Effort sponsored in part by the Defense Advanced Research Projects | ||
32 | * Agency (DARPA) and Air Force Research Laboratory, Air Force | ||
33 | * Materiel Command, USAF, under agreement number F30602-01-2-0537. | ||
34 | * | ||
35 | */ | ||
36 | |||
37 | #include <stdio.h> | ||
38 | #include <stdlib.h> | ||
39 | #include <string.h> | ||
40 | #include <signal.h> | ||
41 | #include <unistd.h> | ||
42 | |||
43 | /* | ||
44 | * XXX Provide a prototype for aligned_alloc on pre-C11 compilers to prevent | ||
45 | * inclusion of hidden/stdlib.h below to cause a missing prototype error. | ||
46 | */ | ||
47 | #if (__ISO_C_VISIBLE - 0) < 2011 | ||
48 | void *aligned_alloc(size_t, size_t); | ||
49 | #endif | ||
50 | |||
51 | #include "include/namespace.h" | ||
52 | #include "hidden/stdlib.h" | ||
53 | #include "stdlib/atexit.h" | ||
54 | |||
55 | void handle_first(void); | ||
56 | void handle_middle(void); | ||
57 | void handle_last(void); | ||
58 | void handle_invalid(void *); | ||
59 | void handle_cleanup(void); | ||
60 | void handle_signal(int); | ||
61 | |||
62 | static int counter; | ||
63 | |||
64 | int | ||
65 | main(int argc, char *argv[]) | ||
66 | { | ||
67 | int i; | ||
68 | |||
69 | if (argc != 2 || (strcmp(argv[1], "-valid") && | ||
70 | strcmp(argv[1], "-invalid-atexit") && | ||
71 | strcmp(argv[1], "-invalid-cleanup"))) { | ||
72 | fprintf(stderr, "%s -valid/-invalid-atexit/-invalid-cleanup\n", | ||
73 | argv[0]); | ||
74 | return (1); | ||
75 | } | ||
76 | fprintf(stderr, "main()\n"); | ||
77 | if (atexit(handle_last)) { | ||
78 | perror("atexit(handle_last) failed"); | ||
79 | return (1); | ||
80 | } | ||
81 | for (i = 0; i < 65535; ++i) { | ||
82 | if (atexit(handle_middle)) { | ||
83 | perror("atexit(handle_middle) failed"); | ||
84 | return (1); | ||
85 | } | ||
86 | } | ||
87 | if (atexit(handle_first)) { | ||
88 | perror("atexit(handle_first) failed"); | ||
89 | return (1); | ||
90 | } | ||
91 | /* this is supposed to segfault */ | ||
92 | if (!strcmp(argv[1], "-invalid-atexit")) { | ||
93 | signal(SIGSEGV, handle_signal); | ||
94 | __atexit->fns[0].fn_ptr = handle_invalid; | ||
95 | } else if (!strcmp(argv[1], "-invalid-cleanup")) { | ||
96 | struct atexit *p = __atexit; | ||
97 | |||
98 | signal(SIGSEGV, handle_signal); | ||
99 | while (p != NULL && p->next != NULL) | ||
100 | p = p->next; | ||
101 | if (p == NULL) | ||
102 | fprintf(stderr, "p == NULL, no page found\n"); | ||
103 | p->fns[0].fn_ptr = handle_invalid; | ||
104 | } | ||
105 | __atexit_register_cleanup(handle_cleanup); | ||
106 | counter = 0; | ||
107 | fprintf(stderr, "main() returns\n"); | ||
108 | return (0); | ||
109 | } | ||
110 | |||
111 | void | ||
112 | handle_first(void) | ||
113 | { | ||
114 | fprintf(stderr, "handle_first() counter == %i\n", counter); | ||
115 | } | ||
116 | |||
117 | void | ||
118 | handle_middle(void) | ||
119 | { | ||
120 | counter++; | ||
121 | } | ||
122 | |||
123 | void | ||
124 | handle_last(void) | ||
125 | { | ||
126 | fprintf(stderr, "handle_last() counter == %i\n", counter); | ||
127 | } | ||
128 | |||
129 | void | ||
130 | handle_cleanup(void) | ||
131 | { | ||
132 | fprintf(stderr, "handle_cleanup()\n"); | ||
133 | } | ||
134 | |||
135 | void | ||
136 | handle_invalid(void *arg) | ||
137 | { | ||
138 | fprintf(stderr, "handle_invalid() THIS SHOULD HAVE SEGFAULTED INSTEAD!\n"); | ||
139 | } | ||
140 | |||
141 | void | ||
142 | handle_signal(int sigraised) | ||
143 | { | ||
144 | switch (sigraised) { | ||
145 | case SIGSEGV: | ||
146 | dprintf(STDERR_FILENO, "SIGSEGV\n"); | ||
147 | exit(0); | ||
148 | default: | ||
149 | dprintf(STDERR_FILENO, "unexpected signal caught\n"); | ||
150 | exit(1); | ||
151 | } | ||
152 | } | ||
diff --git a/src/regress/lib/libc/atexit/invalid.ok b/src/regress/lib/libc/atexit/invalid.ok deleted file mode 100644 index 98cbf8c1de..0000000000 --- a/src/regress/lib/libc/atexit/invalid.ok +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | main() | ||
2 | SIGSEGV | ||
3 | handle_first() counter == 0 | ||
4 | handle_last() counter == 65535 | ||
diff --git a/src/regress/lib/libc/atexit/valid.ok b/src/regress/lib/libc/atexit/valid.ok deleted file mode 100644 index 6509e827a7..0000000000 --- a/src/regress/lib/libc/atexit/valid.ok +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | main() | ||
2 | main() returns | ||
3 | handle_first() counter == 0 | ||
4 | handle_last() counter == 65535 | ||
5 | handle_cleanup() | ||
diff --git a/src/regress/lib/libc/basename/Makefile b/src/regress/lib/libc/basename/Makefile deleted file mode 100644 index 958b06fd11..0000000000 --- a/src/regress/lib/libc/basename/Makefile +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | PROG=basename_test | ||
2 | |||
3 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/basename/basename_test.c b/src/regress/lib/libc/basename/basename_test.c deleted file mode 100644 index 7272c46b1d..0000000000 --- a/src/regress/lib/libc/basename/basename_test.c +++ /dev/null | |||
@@ -1,77 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2007 Bret S. Lambert <blambert@gsipt.net> | ||
3 | * | ||
4 | * Public domain. | ||
5 | */ | ||
6 | |||
7 | #include <libgen.h> | ||
8 | #include <stdio.h> | ||
9 | #include <string.h> | ||
10 | #include <limits.h> | ||
11 | #include <errno.h> | ||
12 | |||
13 | int | ||
14 | main(void) | ||
15 | { | ||
16 | char path[2 * PATH_MAX]; | ||
17 | const char *dir = "junk/"; | ||
18 | const char *fname = "file.name.ext"; | ||
19 | char *str; | ||
20 | int i; | ||
21 | |||
22 | /* Test normal functioning */ | ||
23 | strlcpy(path, "/", sizeof(path)); | ||
24 | strlcat(path, dir, sizeof(path)); | ||
25 | strlcat(path, fname, sizeof(path)); | ||
26 | str = basename(path); | ||
27 | if (strcmp(str, fname) != 0) | ||
28 | goto fail; | ||
29 | |||
30 | /* | ||
31 | * There are four states that require special handling: | ||
32 | * | ||
33 | * 1) path is NULL | ||
34 | * 2) path is the empty string | ||
35 | * 3) path is composed entirely of slashes | ||
36 | * 4) the resulting name is larger than PATH_MAX | ||
37 | * | ||
38 | * The first two cases require that a pointer | ||
39 | * to the string "." be returned. | ||
40 | * | ||
41 | * The third case requires that a pointer | ||
42 | * to the string "/" be returned. | ||
43 | * | ||
44 | * The final case requires that NULL be returned | ||
45 | * and errno * be set to ENAMETOOLONG. | ||
46 | */ | ||
47 | /* Case 1 */ | ||
48 | str = basename(NULL); | ||
49 | if (strcmp(str, ".") != 0) | ||
50 | goto fail; | ||
51 | |||
52 | /* Case 2 */ | ||
53 | strlcpy(path, "", sizeof(path)); | ||
54 | str = basename(path); | ||
55 | if (strcmp(str, ".") != 0) | ||
56 | goto fail; | ||
57 | |||
58 | /* Case 3 */ | ||
59 | for (i = 0; i < PATH_MAX - 1; i++) | ||
60 | strlcat(path, "/", sizeof(path)); /* path cleared above */ | ||
61 | str = basename(path); | ||
62 | if (strcmp(str, "/") != 0) | ||
63 | goto fail; | ||
64 | |||
65 | /* Case 4 */ | ||
66 | strlcpy(path, "/", sizeof(path)); | ||
67 | strlcat(path, dir, sizeof(path)); | ||
68 | for (i = 0; i <= PATH_MAX; i += sizeof(fname)) | ||
69 | strlcat(path, fname, sizeof(path)); | ||
70 | str = basename(path); | ||
71 | if (str != NULL || errno != ENAMETOOLONG) | ||
72 | goto fail; | ||
73 | |||
74 | return (0); | ||
75 | fail: | ||
76 | return (1); | ||
77 | } | ||
diff --git a/src/regress/lib/libc/cephes/Makefile b/src/regress/lib/libc/cephes/Makefile deleted file mode 100644 index 75cc85f4a8..0000000000 --- a/src/regress/lib/libc/cephes/Makefile +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2011/07/02 18:11:01 martynas Exp $ | ||
2 | |||
3 | PROG = ieetst | ||
4 | SRCS = drand.c econst.c eexp.c elog.c epow.c etanh.c etodec.c ieee.c \ | ||
5 | ieetst.c mtherr.c | ||
6 | |||
7 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/cephes/drand.c b/src/regress/lib/libc/cephes/drand.c deleted file mode 100644 index 7f7000b4e8..0000000000 --- a/src/regress/lib/libc/cephes/drand.c +++ /dev/null | |||
@@ -1,174 +0,0 @@ | |||
1 | /* $OpenBSD: drand.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* drand.c | ||
20 | * | ||
21 | * Pseudorandom number generator | ||
22 | * | ||
23 | * | ||
24 | * | ||
25 | * SYNOPSIS: | ||
26 | * | ||
27 | * double y, drand(); | ||
28 | * | ||
29 | * drand( &y ); | ||
30 | * | ||
31 | * | ||
32 | * | ||
33 | * DESCRIPTION: | ||
34 | * | ||
35 | * Yields a random number 1.0 <= y < 2.0. | ||
36 | * | ||
37 | * The three-generator congruential algorithm by Brian | ||
38 | * Wichmann and David Hill (BYTE magazine, March, 1987, | ||
39 | * pp 127-8) is used. The period, given by them, is | ||
40 | * 6953607871644. | ||
41 | * | ||
42 | * Versions invoked by the different arithmetic compile | ||
43 | * time options DEC, IBMPC, and MIEEE, produce | ||
44 | * approximately the same sequences, differing only in the | ||
45 | * least significant bits of the numbers. The UNK option | ||
46 | * implements the algorithm as recommended in the BYTE | ||
47 | * article. It may be used on all computers. However, | ||
48 | * the low order bits of a double precision number may | ||
49 | * not be adequately random, and may vary due to arithmetic | ||
50 | * implementation details on different computers. | ||
51 | * | ||
52 | * The other compile options generate an additional random | ||
53 | * integer that overwrites the low order bits of the double | ||
54 | * precision number. This reduces the period by a factor of | ||
55 | * two but tends to overcome the problems mentioned. | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include "mconf.h" | ||
60 | |||
61 | |||
62 | /* Three-generator random number algorithm | ||
63 | * of Brian Wichmann and David Hill | ||
64 | * BYTE magazine, March, 1987 pp 127-8 | ||
65 | * | ||
66 | * The period, given by them, is (p-1)(q-1)(r-1)/4 = 6.95e12. | ||
67 | */ | ||
68 | |||
69 | static int sx = 1; | ||
70 | static int sy = 10000; | ||
71 | static int sz = 3000; | ||
72 | |||
73 | static union { | ||
74 | double d; | ||
75 | unsigned short s[4]; | ||
76 | } unkans; | ||
77 | |||
78 | /* This function implements the three | ||
79 | * congruential generators. | ||
80 | */ | ||
81 | |||
82 | static int ranwh() | ||
83 | { | ||
84 | int r, s; | ||
85 | |||
86 | /* sx = sx * 171 mod 30269 */ | ||
87 | r = sx/177; | ||
88 | s = sx - 177 * r; | ||
89 | sx = 171 * s - 2 * r; | ||
90 | if( sx < 0 ) | ||
91 | sx += 30269; | ||
92 | |||
93 | |||
94 | /* sy = sy * 172 mod 30307 */ | ||
95 | r = sy/176; | ||
96 | s = sy - 176 * r; | ||
97 | sy = 172 * s - 35 * r; | ||
98 | if( sy < 0 ) | ||
99 | sy += 30307; | ||
100 | |||
101 | /* sz = 170 * sz mod 30323 */ | ||
102 | r = sz/178; | ||
103 | s = sz - 178 * r; | ||
104 | sz = 170 * s - 63 * r; | ||
105 | if( sz < 0 ) | ||
106 | sz += 30323; | ||
107 | /* The results are in static sx, sy, sz. */ | ||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | /* drand.c | ||
112 | * | ||
113 | * Random double precision floating point number between 1 and 2. | ||
114 | * | ||
115 | * C callable: | ||
116 | * drand( &x ); | ||
117 | */ | ||
118 | |||
119 | int drand( a ) | ||
120 | double *a; | ||
121 | { | ||
122 | unsigned short r; | ||
123 | #ifdef DEC | ||
124 | unsigned short s, t; | ||
125 | #endif | ||
126 | |||
127 | /* This algorithm of Wichmann and Hill computes a floating point | ||
128 | * result: | ||
129 | */ | ||
130 | ranwh(); | ||
131 | unkans.d = sx/30269.0 + sy/30307.0 + sz/30323.0; | ||
132 | r = unkans.d; | ||
133 | unkans.d -= r; | ||
134 | unkans.d += 1.0; | ||
135 | |||
136 | /* if UNK option, do nothing further. | ||
137 | * Otherwise, make a random 16 bit integer | ||
138 | * to overwrite the least significant word | ||
139 | * of unkans. | ||
140 | */ | ||
141 | #ifdef UNK | ||
142 | /* do nothing */ | ||
143 | #else | ||
144 | ranwh(); | ||
145 | r = sx * sy + sz; | ||
146 | #endif | ||
147 | |||
148 | #ifdef DEC | ||
149 | /* To make the numbers as similar as possible | ||
150 | * in all arithmetics, the random integer has | ||
151 | * to be inserted 3 bits higher up in a DEC number. | ||
152 | * An alternative would be put it 3 bits lower down | ||
153 | * in all the other number types. | ||
154 | */ | ||
155 | s = unkans.s[2]; | ||
156 | t = s & 07; /* save these bits to put in at the bottom */ | ||
157 | s &= 0177770; | ||
158 | s |= (r >> 13) & 07; | ||
159 | unkans.s[2] = s; | ||
160 | t |= r << 3; | ||
161 | unkans.s[3] = t; | ||
162 | #endif | ||
163 | |||
164 | #ifdef IBMPC | ||
165 | unkans.s[0] = r; | ||
166 | #endif | ||
167 | |||
168 | #ifdef MIEEE | ||
169 | unkans.s[3] = r; | ||
170 | #endif | ||
171 | |||
172 | *a = unkans.d; | ||
173 | return 0; | ||
174 | } | ||
diff --git a/src/regress/lib/libc/cephes/econst.c b/src/regress/lib/libc/cephes/econst.c deleted file mode 100644 index 4232059e4c..0000000000 --- a/src/regress/lib/libc/cephes/econst.c +++ /dev/null | |||
@@ -1,114 +0,0 @@ | |||
1 | /* $OpenBSD: econst.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* econst.c */ | ||
20 | /* e type constants used by high precision check routines */ | ||
21 | |||
22 | #include "ehead.h" | ||
23 | |||
24 | |||
25 | #if NE == 10 | ||
26 | /* 0.0 */ | ||
27 | unsigned short ezero[NE] = | ||
28 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
29 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,}; | ||
30 | |||
31 | /* 5.0E-1 */ | ||
32 | unsigned short ehalf[NE] = | ||
33 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
34 | 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,}; | ||
35 | |||
36 | /* 1.0E0 */ | ||
37 | unsigned short eone[NE] = | ||
38 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
39 | 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,}; | ||
40 | |||
41 | /* 2.0E0 */ | ||
42 | unsigned short etwo[NE] = | ||
43 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
44 | 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,}; | ||
45 | |||
46 | /* 3.2E1 */ | ||
47 | unsigned short e32[NE] = | ||
48 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
49 | 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,}; | ||
50 | |||
51 | /* 6.93147180559945309417232121458176568075500134360255E-1 */ | ||
52 | unsigned short elog2[NE] = | ||
53 | {0x40f3, 0xf6af, 0x03f2, 0xb398, | ||
54 | 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,}; | ||
55 | |||
56 | /* 1.41421356237309504880168872420969807856967187537695E0 */ | ||
57 | unsigned short esqrt2[NE] = | ||
58 | {0x1d6f, 0xbe9f, 0x754a, 0x89b3, | ||
59 | 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,}; | ||
60 | |||
61 | /* 3.14159265358979323846264338327950288419716939937511E0 */ | ||
62 | unsigned short epi[NE] = | ||
63 | {0x2902, 0x1cd1, 0x80dc, 0x628b, | ||
64 | 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,}; | ||
65 | |||
66 | /* 5.7721566490153286060651209008240243104215933593992E-1 */ | ||
67 | unsigned short eeul[NE] = { | ||
68 | 0xd1be,0xc7a4,0076660,0063743,0111704,0x3ffe,}; | ||
69 | |||
70 | #else | ||
71 | |||
72 | /* 0.0 */ | ||
73 | unsigned short ezero[NE] = { | ||
74 | 0, 0000000,0000000,0000000,0000000,0000000,}; | ||
75 | /* 5.0E-1 */ | ||
76 | unsigned short ehalf[NE] = { | ||
77 | 0, 0000000,0000000,0000000,0100000,0x3ffe,}; | ||
78 | /* 1.0E0 */ | ||
79 | unsigned short eone[NE] = { | ||
80 | 0, 0000000,0000000,0000000,0100000,0x3fff,}; | ||
81 | /* 2.0E0 */ | ||
82 | unsigned short etwo[NE] = { | ||
83 | 0, 0000000,0000000,0000000,0100000,0040000,}; | ||
84 | /* 3.2E1 */ | ||
85 | unsigned short e32[NE] = { | ||
86 | 0, 0000000,0000000,0000000,0100000,0040004,}; | ||
87 | /* 6.93147180559945309417232121458176568075500134360255E-1 */ | ||
88 | unsigned short elog2[NE] = { | ||
89 | 0xc9e4,0x79ab,0150717,0013767,0130562,0x3ffe,}; | ||
90 | /* 1.41421356237309504880168872420969807856967187537695E0 */ | ||
91 | unsigned short esqrt2[NE] = { | ||
92 | 0x597e,0x6484,0174736,0171463,0132404,0x3fff,}; | ||
93 | /* 2/sqrt(PI) = | ||
94 | * 1.12837916709551257389615890312154517168810125865800E0 */ | ||
95 | unsigned short eoneopi[NE] = { | ||
96 | 0x71d5,0x688d,0012333,0135202,0110156,0x3fff,}; | ||
97 | /* 3.14159265358979323846264338327950288419716939937511E0 */ | ||
98 | unsigned short epi[NE] = { | ||
99 | 0xc4c6,0xc234,0020550,0155242,0144417,0040000,}; | ||
100 | /* 5.7721566490153286060651209008240243104215933593992E-1 */ | ||
101 | unsigned short eeul[NE] = { | ||
102 | 0xd1be,0xc7a4,0076660,0063743,0111704,0x3ffe,}; | ||
103 | #endif | ||
104 | extern unsigned short ezero[]; | ||
105 | extern unsigned short ehalf[]; | ||
106 | extern unsigned short eone[]; | ||
107 | extern unsigned short etwo[]; | ||
108 | extern unsigned short e32[]; | ||
109 | extern unsigned short elog2[]; | ||
110 | extern unsigned short esqrt2[]; | ||
111 | extern unsigned short eoneopi[]; | ||
112 | extern unsigned short epi[]; | ||
113 | extern unsigned short eeul[]; | ||
114 | |||
diff --git a/src/regress/lib/libc/cephes/eexp.c b/src/regress/lib/libc/cephes/eexp.c deleted file mode 100644 index 74f0d6adb3..0000000000 --- a/src/regress/lib/libc/cephes/eexp.c +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | /* $OpenBSD: eexp.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* xexp.c */ | ||
20 | /* exponential function check routine */ | ||
21 | /* by Stephen L. Moshier. */ | ||
22 | |||
23 | |||
24 | #include "ehead.h" | ||
25 | |||
26 | void eexp( x, y ) | ||
27 | unsigned short *x, *y; | ||
28 | { | ||
29 | unsigned short num[NE], den[NE], x2[NE]; | ||
30 | long i; | ||
31 | unsigned short sign, expchk; | ||
32 | |||
33 | /* range reduction theory: x = i + f, 0<=f<1; | ||
34 | * e**x = e**i * e**f | ||
35 | * e**i = 2**(i/log 2). | ||
36 | * Let i/log2 = i1 + f1, 0<=f1<1. | ||
37 | * Then e**i = 2**i1 * 2**f1, so | ||
38 | * e**x = 2**i1 * e**(log 2 * f1) * e**f. | ||
39 | */ | ||
40 | if( ecmp(x, ezero) == 0 ) | ||
41 | { | ||
42 | emov( eone, y ); | ||
43 | return; | ||
44 | } | ||
45 | emov(x, x2); | ||
46 | expchk = x2[NE-1]; | ||
47 | sign = expchk & 0x8000; | ||
48 | x2[NE-1] &= 0x7fff; | ||
49 | |||
50 | /* Test for excessively large argument */ | ||
51 | expchk &= 0x7fff; | ||
52 | if( expchk > (EXONE + 15) ) | ||
53 | { | ||
54 | eclear( y ); | ||
55 | if( sign == 0 ) | ||
56 | einfin( y ); | ||
57 | return; | ||
58 | } | ||
59 | |||
60 | eifrac( x2, &i, num ); /* x = i + f */ | ||
61 | |||
62 | if( i != 0 ) | ||
63 | { | ||
64 | ltoe( &i, den ); /* floating point i */ | ||
65 | ediv( elog2, den, den ); /* i/log 2 */ | ||
66 | eifrac( den, &i, den ); /* i/log 2 = i1 + f1 */ | ||
67 | emul( elog2, den, den ); /* log 2 * f1 */ | ||
68 | eadd( den, num, x2 ); /* log 2 * f1 + f */ | ||
69 | } | ||
70 | |||
71 | /*x2[NE-1] -= 1;*/ | ||
72 | eldexp( x2, -1L, x2 ); /* divide by 2 */ | ||
73 | etanh( x2, x2 ); /* tanh( x/2 ) */ | ||
74 | eadd( x2, eone, num ); /* 1 + tanh */ | ||
75 | eneg( x2 ); | ||
76 | eadd( x2, eone, den ); /* 1 - tanh */ | ||
77 | ediv( den, num, y ); /* (1 + tanh)/(1 - tanh) */ | ||
78 | |||
79 | /*y[NE-1] += i;*/ | ||
80 | if( sign ) | ||
81 | { | ||
82 | ediv( y, eone, y ); | ||
83 | i = -i; | ||
84 | } | ||
85 | eldexp( y, i, y ); /* multiply by 2**i */ | ||
86 | } | ||
diff --git a/src/regress/lib/libc/cephes/ehead.h b/src/regress/lib/libc/cephes/ehead.h deleted file mode 100644 index 009bcf89cc..0000000000 --- a/src/regress/lib/libc/cephes/ehead.h +++ /dev/null | |||
@@ -1,59 +0,0 @@ | |||
1 | /* $OpenBSD: ehead.h,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* Include file for extended precision arithmetic programs. | ||
20 | */ | ||
21 | |||
22 | /* Number of 16 bit words in external x type format */ | ||
23 | #define NE 10 | ||
24 | |||
25 | /* Number of 16 bit words in internal format */ | ||
26 | #define NI (NE+3) | ||
27 | |||
28 | /* Array offset to exponent */ | ||
29 | #define E 1 | ||
30 | |||
31 | /* Array offset to high guard word */ | ||
32 | #define M 2 | ||
33 | |||
34 | /* Number of bits of precision */ | ||
35 | #define NBITS ((NI-4)*16) | ||
36 | |||
37 | /* Maximum number of decimal digits in ASCII conversion | ||
38 | * = NBITS*log10(2) | ||
39 | */ | ||
40 | #define NDEC (NBITS*8/27) | ||
41 | |||
42 | /* The exponent of 1.0 */ | ||
43 | #define EXONE (0x3fff) | ||
44 | |||
45 | void eadd(), esub(), emul(), ediv(); | ||
46 | int ecmp(), enormlz(), eshift(); | ||
47 | void eshup1(), eshup8(), eshup6(), eshdn1(), eshdn8(), eshdn6(); | ||
48 | void eabs(), eneg(), emov(), eclear(), einfin(), efloor(); | ||
49 | void eldexp(), efrexp(), eifrac(), ltoe(); | ||
50 | void esqrt(), elog(), eexp(), etanh(), epow(); | ||
51 | void asctoe(), asctoe24(), asctoe53(), asctoe64(); | ||
52 | void etoasc(), e24toasc(), e53toasc(), e64toasc(); | ||
53 | void etoe64(), etoe53(), etoe24(), e64toe(), e53toe(), e24toe(); | ||
54 | int mtherr(); | ||
55 | extern unsigned short ezero[], ehalf[], eone[], etwo[]; | ||
56 | extern unsigned short elog2[], esqrt2[]; | ||
57 | |||
58 | |||
59 | /* by Stephen L. Moshier. */ | ||
diff --git a/src/regress/lib/libc/cephes/elog.c b/src/regress/lib/libc/cephes/elog.c deleted file mode 100644 index 079cc754f4..0000000000 --- a/src/regress/lib/libc/cephes/elog.c +++ /dev/null | |||
@@ -1,110 +0,0 @@ | |||
1 | /* $OpenBSD: elog.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* xlog.c */ | ||
20 | /* natural logarithm */ | ||
21 | /* by Stephen L. Moshier. */ | ||
22 | |||
23 | #include "mconf.h" | ||
24 | #include "ehead.h" | ||
25 | |||
26 | |||
27 | |||
28 | void elog( x, y ) | ||
29 | unsigned short *x, *y; | ||
30 | { | ||
31 | unsigned short xx[NE], z[NE], a[NE], b[NE], t[NE], qj[NE]; | ||
32 | long ex; | ||
33 | int fex; | ||
34 | |||
35 | |||
36 | if( x[NE-1] & (unsigned short )0x8000 ) | ||
37 | { | ||
38 | eclear(y); | ||
39 | mtherr( "elog", DOMAIN ); | ||
40 | return; | ||
41 | } | ||
42 | if( ecmp( x, ezero ) == 0 ) | ||
43 | { | ||
44 | einfin( y ); | ||
45 | eneg(y); | ||
46 | mtherr( "elog", SING ); | ||
47 | return; | ||
48 | } | ||
49 | if( ecmp( x, eone ) == 0 ) | ||
50 | { | ||
51 | eclear( y ); | ||
52 | return; | ||
53 | } | ||
54 | |||
55 | /* range reduction: log x = log( 2**ex * m ) = ex * log2 + log m */ | ||
56 | efrexp( x, &fex, xx ); | ||
57 | /* | ||
58 | emov(x, xx ); | ||
59 | ex = xx[NX-1] & 0x7fff; | ||
60 | ex -= 0x3ffe; | ||
61 | xx[NX-1] = 0x3ffe; | ||
62 | */ | ||
63 | |||
64 | /* Adjust range to 1/sqrt(2), sqrt(2) */ | ||
65 | esqrt2[NE-1] -= 1; | ||
66 | if( ecmp( xx, esqrt2 ) < 0 ) | ||
67 | { | ||
68 | fex -= 1; | ||
69 | emul( xx, etwo, xx ); | ||
70 | } | ||
71 | esqrt2[NE-1] += 1; | ||
72 | |||
73 | esub( eone, xx, a ); | ||
74 | if( a[NE-1] == 0 ) | ||
75 | { | ||
76 | eclear( y ); | ||
77 | goto logdon; | ||
78 | } | ||
79 | eadd( eone, xx, b ); | ||
80 | ediv( b, a, y ); /* store (x-1)/(x+1) in y */ | ||
81 | |||
82 | emul( y, y, z ); | ||
83 | |||
84 | emov( eone, a ); | ||
85 | emov( eone, b ); | ||
86 | emov( eone, qj ); | ||
87 | do | ||
88 | { | ||
89 | eadd( etwo, qj, qj ); /* 2 * i + 1 */ | ||
90 | emul( z, a, a ); | ||
91 | ediv( qj, a, t ); | ||
92 | eadd( t, b, b ); | ||
93 | } | ||
94 | while( ((b[NE-1] & 0x7fff) - (t[NE-1] & 0x7fff)) < NBITS ); | ||
95 | |||
96 | |||
97 | emul( b, y, y ); | ||
98 | emul( y, etwo, y ); | ||
99 | |||
100 | logdon: | ||
101 | |||
102 | /* now add log of 2**ex */ | ||
103 | if( fex != 0 ) | ||
104 | { | ||
105 | ex = fex; | ||
106 | ltoe( &ex, b ); | ||
107 | emul( elog2, b, b ); | ||
108 | eadd( b, y, y ); | ||
109 | } | ||
110 | } | ||
diff --git a/src/regress/lib/libc/cephes/epow.c b/src/regress/lib/libc/cephes/epow.c deleted file mode 100644 index 646268fce7..0000000000 --- a/src/regress/lib/libc/cephes/epow.c +++ /dev/null | |||
@@ -1,187 +0,0 @@ | |||
1 | /* $OpenBSD: epow.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* epow.c */ | ||
20 | /* power function: z = x**y */ | ||
21 | /* by Stephen L. Moshier. */ | ||
22 | |||
23 | |||
24 | #include "ehead.h" | ||
25 | |||
26 | extern int rndprc; | ||
27 | void epowi(); | ||
28 | |||
29 | void epow( x, y, z ) | ||
30 | unsigned short *x, *y, *z; | ||
31 | { | ||
32 | unsigned short w[NE]; | ||
33 | int rndsav; | ||
34 | long li; | ||
35 | |||
36 | efloor( y, w ); | ||
37 | if( ecmp(y,w) == 0 ) | ||
38 | { | ||
39 | eifrac( y, &li, w ); | ||
40 | if( li < 0 ) | ||
41 | li = -li; | ||
42 | if( (li < 0x7fffffff) && (li != 0x80000000) ) | ||
43 | { | ||
44 | epowi( x, y, z ); | ||
45 | return; | ||
46 | } | ||
47 | } | ||
48 | /* z = exp( y * log(x) ) */ | ||
49 | rndsav = rndprc; | ||
50 | rndprc = NBITS; | ||
51 | elog( x, w ); | ||
52 | emul( y, w, w ); | ||
53 | eexp( w, z ); | ||
54 | rndprc = rndsav; | ||
55 | emul( eone, z, z ); | ||
56 | } | ||
57 | |||
58 | |||
59 | /* y is integer valued. */ | ||
60 | |||
61 | void epowi( x, y, z ) | ||
62 | unsigned short x[], y[], z[]; | ||
63 | { | ||
64 | unsigned short w[NE]; | ||
65 | long li, lx; | ||
66 | unsigned long lu; | ||
67 | int rndsav; | ||
68 | unsigned short signx; | ||
69 | /* unsigned short signy; */ | ||
70 | |||
71 | rndsav = rndprc; | ||
72 | eifrac( y, &li, w ); | ||
73 | if( li < 0 ) | ||
74 | lx = -li; | ||
75 | else | ||
76 | lx = li; | ||
77 | |||
78 | if( (lx == 0x7fffffff) || (lx == 0x80000000) ) | ||
79 | { | ||
80 | epow( x, y, z ); | ||
81 | goto done; | ||
82 | } | ||
83 | |||
84 | if( (x[NE-1] & (unsigned short )0x7fff) == 0 ) | ||
85 | { | ||
86 | if( li == 0 ) | ||
87 | { | ||
88 | emov( eone, z ); | ||
89 | return; | ||
90 | } | ||
91 | else if( li < 0 ) | ||
92 | { | ||
93 | einfin( z ); | ||
94 | return; | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | eclear( z ); | ||
99 | return; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | if( li == 0L ) | ||
104 | { | ||
105 | emov( eone, z ); | ||
106 | return; | ||
107 | } | ||
108 | |||
109 | emov( x, w ); | ||
110 | signx = w[NE-1] & (unsigned short )0x8000; | ||
111 | w[NE-1] &= (unsigned short )0x7fff; | ||
112 | |||
113 | /* Overflow detection */ | ||
114 | /* | ||
115 | lx = li * (w[NE-1] - 0x3fff); | ||
116 | if( lx > 16385L ) | ||
117 | { | ||
118 | einfin( z ); | ||
119 | mtherr( "epowi", OVERFLOW ); | ||
120 | goto done; | ||
121 | } | ||
122 | if( lx < -16450L ) | ||
123 | { | ||
124 | eclear( z ); | ||
125 | return; | ||
126 | } | ||
127 | */ | ||
128 | rndprc = NBITS; | ||
129 | |||
130 | if( li < 0 ) | ||
131 | { | ||
132 | lu = (unsigned int )( -li ); | ||
133 | /* signy = 0xffff;*/ | ||
134 | ediv( w, eone, w ); | ||
135 | } | ||
136 | else | ||
137 | { | ||
138 | lu = (unsigned int )li; | ||
139 | /* signy = 0;*/ | ||
140 | } | ||
141 | |||
142 | /* First bit of the power */ | ||
143 | if( lu & 1 ) | ||
144 | { | ||
145 | emov( w, z ); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | emov( eone, z ); | ||
150 | signx = 0; | ||
151 | } | ||
152 | |||
153 | |||
154 | lu >>= 1; | ||
155 | while( lu != 0L ) | ||
156 | { | ||
157 | emul( w, w, w ); /* arg to the 2-to-the-kth power */ | ||
158 | if( lu & 1L ) /* if that bit is set, then include in product */ | ||
159 | emul( w, z, z ); | ||
160 | lu >>= 1; | ||
161 | } | ||
162 | |||
163 | |||
164 | done: | ||
165 | |||
166 | if( signx ) | ||
167 | eneg( z ); /* odd power of negative number */ | ||
168 | |||
169 | /* | ||
170 | if( signy ) | ||
171 | { | ||
172 | if( ecmp( z, ezero ) != 0 ) | ||
173 | { | ||
174 | ediv( z, eone, z ); | ||
175 | } | ||
176 | else | ||
177 | { | ||
178 | einfin( z ); | ||
179 | printf( "epowi OVERFLOW\n" ); | ||
180 | } | ||
181 | } | ||
182 | */ | ||
183 | rndprc = rndsav; | ||
184 | emul( eone, z, z ); | ||
185 | } | ||
186 | |||
187 | |||
diff --git a/src/regress/lib/libc/cephes/etanh.c b/src/regress/lib/libc/cephes/etanh.c deleted file mode 100644 index 4ac5ff1c21..0000000000 --- a/src/regress/lib/libc/cephes/etanh.c +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | /* $OpenBSD: etanh.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* xtanh.c */ | ||
20 | /* hyperbolic tangent check routine */ | ||
21 | /* this subroutine is used by the exponential function routine */ | ||
22 | /* by Stephen L. Moshier. */ | ||
23 | |||
24 | |||
25 | |||
26 | #include "ehead.h" | ||
27 | |||
28 | |||
29 | void etanh( x, y ) | ||
30 | unsigned short *x, *y; | ||
31 | { | ||
32 | unsigned short e[NE], r[NE], j[NE], xx[NE], m2[NE]; | ||
33 | short i, n; | ||
34 | long lj; | ||
35 | |||
36 | emov( x, r ); | ||
37 | r[NE-1] &= (unsigned short )0x7fff; | ||
38 | if( ecmp(r, eone) >= 0 ) | ||
39 | { | ||
40 | /* tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x)) | ||
41 | * Note eexp() calls xtanh, but with an argument less than (1 + log 2)/2. | ||
42 | */ | ||
43 | eexp( r, e ); | ||
44 | ediv( e, eone, r ); | ||
45 | esub( r, e, xx ); | ||
46 | eadd( r, e, j ); | ||
47 | ediv( j, xx, y ); | ||
48 | return; | ||
49 | } | ||
50 | |||
51 | emov( etwo, m2 ); | ||
52 | eneg( m2 ); | ||
53 | |||
54 | n = NBITS/8; /* Number of terms to do in the continued fraction */ | ||
55 | lj = 2 * n + 1; | ||
56 | ltoe( &lj, j ); | ||
57 | |||
58 | emov( j, e ); | ||
59 | emul( x, x, xx ); | ||
60 | |||
61 | /* continued fraction */ | ||
62 | for( i=0; i<n; i++) | ||
63 | { | ||
64 | ediv( e, xx, r ); | ||
65 | eadd( m2, j, j ); | ||
66 | eadd( r, j, e ); | ||
67 | } | ||
68 | |||
69 | ediv( e, x, y ); | ||
70 | } | ||
diff --git a/src/regress/lib/libc/cephes/etodec.c b/src/regress/lib/libc/cephes/etodec.c deleted file mode 100644 index a15845efb6..0000000000 --- a/src/regress/lib/libc/cephes/etodec.c +++ /dev/null | |||
@@ -1,199 +0,0 @@ | |||
1 | /* $OpenBSD: etodec.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include "ehead.h" | ||
20 | void emovi(), emovo(), ecleaz(), eshdn8(), emdnorm(); | ||
21 | void todec(); | ||
22 | /* | ||
23 | ; convert DEC double precision to e type | ||
24 | ; double d; | ||
25 | ; short e[NE]; | ||
26 | ; dectoe( &d, e ); | ||
27 | */ | ||
28 | void dectoe( d, e ) | ||
29 | unsigned short *d; | ||
30 | unsigned short *e; | ||
31 | { | ||
32 | unsigned short y[NI]; | ||
33 | register unsigned short r, *p; | ||
34 | |||
35 | ecleaz(y); /* start with a zero */ | ||
36 | p = y; /* point to our number */ | ||
37 | r = *d; /* get DEC exponent word */ | ||
38 | if( *d & (unsigned int )0x8000 ) | ||
39 | *p = 0xffff; /* fill in our sign */ | ||
40 | ++p; /* bump pointer to our exponent word */ | ||
41 | r &= 0x7fff; /* strip the sign bit */ | ||
42 | if( r == 0 ) /* answer = 0 if high order DEC word = 0 */ | ||
43 | goto done; | ||
44 | |||
45 | |||
46 | r >>= 7; /* shift exponent word down 7 bits */ | ||
47 | r += EXONE - 0201; /* subtract DEC exponent offset */ | ||
48 | /* add our e type exponent offset */ | ||
49 | *p++ = r; /* to form our exponent */ | ||
50 | |||
51 | r = *d++; /* now do the high order mantissa */ | ||
52 | r &= 0177; /* strip off the DEC exponent and sign bits */ | ||
53 | r |= 0200; /* the DEC understood high order mantissa bit */ | ||
54 | *p++ = r; /* put result in our high guard word */ | ||
55 | |||
56 | *p++ = *d++; /* fill in the rest of our mantissa */ | ||
57 | *p++ = *d++; | ||
58 | *p = *d; | ||
59 | |||
60 | eshdn8(y); /* shift our mantissa down 8 bits */ | ||
61 | done: | ||
62 | emovo( y, e ); | ||
63 | } | ||
64 | |||
65 | |||
66 | |||
67 | /* | ||
68 | ; convert e type to DEC double precision | ||
69 | ; double d; | ||
70 | ; short e[NE]; | ||
71 | ; etodec( e, &d ); | ||
72 | */ | ||
73 | #if 0 | ||
74 | static unsigned short decbit[NI] = {0,0,0,0,0,0,0200,0}; | ||
75 | void etodec( x, d ) | ||
76 | unsigned short *x, *d; | ||
77 | { | ||
78 | unsigned short xi[NI]; | ||
79 | register unsigned short r; | ||
80 | int i, j; | ||
81 | |||
82 | emovi( x, xi ); | ||
83 | *d = 0; | ||
84 | if( xi[0] != 0 ) | ||
85 | *d = 0100000; | ||
86 | r = xi[E]; | ||
87 | if( r < (EXONE - 128) ) | ||
88 | goto zout; | ||
89 | i = xi[M+4]; | ||
90 | if( (i & 0200) != 0 ) | ||
91 | { | ||
92 | if( (i & 0377) == 0200 ) | ||
93 | { | ||
94 | if( (i & 0400) != 0 ) | ||
95 | { | ||
96 | /* check all less significant bits */ | ||
97 | for( j=M+5; j<NI; j++ ) | ||
98 | { | ||
99 | if( xi[j] != 0 ) | ||
100 | goto yesrnd; | ||
101 | } | ||
102 | } | ||
103 | goto nornd; | ||
104 | } | ||
105 | yesrnd: | ||
106 | eaddm( decbit, xi ); | ||
107 | r -= enormlz(xi); | ||
108 | } | ||
109 | |||
110 | nornd: | ||
111 | |||
112 | r -= EXONE; | ||
113 | r += 0201; | ||
114 | if( r < 0 ) | ||
115 | { | ||
116 | zout: | ||
117 | *d++ = 0; | ||
118 | *d++ = 0; | ||
119 | *d++ = 0; | ||
120 | *d++ = 0; | ||
121 | return; | ||
122 | } | ||
123 | if( r >= 0377 ) | ||
124 | { | ||
125 | *d++ = 077777; | ||
126 | *d++ = -1; | ||
127 | *d++ = -1; | ||
128 | *d++ = -1; | ||
129 | return; | ||
130 | } | ||
131 | r &= 0377; | ||
132 | r <<= 7; | ||
133 | eshup8( xi ); | ||
134 | xi[M] &= 0177; | ||
135 | r |= xi[M]; | ||
136 | *d++ |= r; | ||
137 | *d++ = xi[M+1]; | ||
138 | *d++ = xi[M+2]; | ||
139 | *d++ = xi[M+3]; | ||
140 | } | ||
141 | #else | ||
142 | |||
143 | extern int rndprc; | ||
144 | |||
145 | void etodec( x, d ) | ||
146 | unsigned short *x, *d; | ||
147 | { | ||
148 | unsigned short xi[NI]; | ||
149 | long exp; | ||
150 | int rndsav; | ||
151 | |||
152 | emovi( x, xi ); | ||
153 | exp = (long )xi[E] - (EXONE - 0201); /* adjust exponent for offsets */ | ||
154 | /* round off to nearest or even */ | ||
155 | rndsav = rndprc; | ||
156 | rndprc = 56; | ||
157 | emdnorm( xi, 0, 0, exp, 64 ); | ||
158 | rndprc = rndsav; | ||
159 | todec( xi, d ); | ||
160 | } | ||
161 | |||
162 | void todec( x, y ) | ||
163 | unsigned short *x, *y; | ||
164 | { | ||
165 | unsigned short i; | ||
166 | unsigned short *p; | ||
167 | |||
168 | p = x; | ||
169 | *y = 0; | ||
170 | if( *p++ ) | ||
171 | *y = 0100000; | ||
172 | i = *p++; | ||
173 | if( i == 0 ) | ||
174 | { | ||
175 | *y++ = 0; | ||
176 | *y++ = 0; | ||
177 | *y++ = 0; | ||
178 | *y++ = 0; | ||
179 | return; | ||
180 | } | ||
181 | if( i > 0377 ) | ||
182 | { | ||
183 | *y++ |= 077777; | ||
184 | *y++ = 0xffff; | ||
185 | *y++ = 0xffff; | ||
186 | *y++ = 0xffff; | ||
187 | return; | ||
188 | } | ||
189 | i &= 0377; | ||
190 | i <<= 7; | ||
191 | eshup8( x ); | ||
192 | x[M] &= 0177; | ||
193 | i |= x[M]; | ||
194 | *y++ |= i; | ||
195 | *y++ = x[M+1]; | ||
196 | *y++ = x[M+2]; | ||
197 | *y++ = x[M+3]; | ||
198 | } | ||
199 | #endif | ||
diff --git a/src/regress/lib/libc/cephes/ieee.c b/src/regress/lib/libc/cephes/ieee.c deleted file mode 100644 index e2b8aa7b99..0000000000 --- a/src/regress/lib/libc/cephes/ieee.c +++ /dev/null | |||
@@ -1,4153 +0,0 @@ | |||
1 | /* $OpenBSD: ieee.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* ieee.c | ||
20 | * | ||
21 | * Extended precision IEEE binary floating point arithmetic routines | ||
22 | * | ||
23 | * Numbers are stored in C language as arrays of 16-bit unsigned | ||
24 | * short integers. The arguments of the routines are pointers to | ||
25 | * the arrays. | ||
26 | * | ||
27 | * | ||
28 | * External e type data structure, simulates Intel 8087 chip | ||
29 | * temporary real format but possibly with a larger significand: | ||
30 | * | ||
31 | * NE-1 significand words (least significant word first, | ||
32 | * most significant bit is normally set) | ||
33 | * exponent (value = EXONE for 1.0, | ||
34 | * top bit is the sign) | ||
35 | * | ||
36 | * | ||
37 | * Internal data structure of a number (a "word" is 16 bits): | ||
38 | * | ||
39 | * ei[0] sign word (0 for positive, 0xffff for negative) | ||
40 | * ei[1] biased exponent (value = EXONE for the number 1.0) | ||
41 | * ei[2] high guard word (always zero after normalization) | ||
42 | * ei[3] | ||
43 | * to ei[NI-2] significand (NI-4 significand words, | ||
44 | * most significant word first, | ||
45 | * most significant bit is set) | ||
46 | * ei[NI-1] low guard word (0x8000 bit is rounding place) | ||
47 | * | ||
48 | * | ||
49 | * | ||
50 | * Routines for external format numbers | ||
51 | * | ||
52 | * asctoe( string, e ) ASCII string to extended double e type | ||
53 | * asctoe64( string, &d ) ASCII string to long double | ||
54 | * asctoe53( string, &d ) ASCII string to double | ||
55 | * asctoe24( string, &f ) ASCII string to single | ||
56 | * asctoeg( string, e, prec ) ASCII string to specified precision | ||
57 | * e24toe( &f, e ) IEEE single precision to e type | ||
58 | * e53toe( &d, e ) IEEE double precision to e type | ||
59 | * e64toe( &d, e ) IEEE long double precision to e type | ||
60 | * eabs(e) absolute value | ||
61 | * eadd( a, b, c ) c = b + a | ||
62 | * eclear(e) e = 0 | ||
63 | * ecmp (a, b) Returns 1 if a > b, 0 if a == b, | ||
64 | * -1 if a < b, -2 if either a or b is a NaN. | ||
65 | * ediv( a, b, c ) c = b / a | ||
66 | * efloor( a, b ) truncate to integer, toward -infinity | ||
67 | * efrexp( a, exp, s ) extract exponent and significand | ||
68 | * eifrac( e, &l, frac ) e to long integer and e type fraction | ||
69 | * euifrac( e, &l, frac ) e to unsigned long integer and e type fraction | ||
70 | * einfin( e ) set e to infinity, leaving its sign alone | ||
71 | * eldexp( a, n, b ) multiply by 2**n | ||
72 | * emov( a, b ) b = a | ||
73 | * emul( a, b, c ) c = b * a | ||
74 | * eneg(e) e = -e | ||
75 | * eround( a, b ) b = nearest integer value to a | ||
76 | * esub( a, b, c ) c = b - a | ||
77 | * e24toasc( &f, str, n ) single to ASCII string, n digits after decimal | ||
78 | * e53toasc( &d, str, n ) double to ASCII string, n digits after decimal | ||
79 | * e64toasc( &d, str, n ) long double to ASCII string | ||
80 | * etoasc( e, str, n ) e to ASCII string, n digits after decimal | ||
81 | * etoe24( e, &f ) convert e type to IEEE single precision | ||
82 | * etoe53( e, &d ) convert e type to IEEE double precision | ||
83 | * etoe64( e, &d ) convert e type to IEEE long double precision | ||
84 | * ltoe( &l, e ) long (32 bit) integer to e type | ||
85 | * ultoe( &l, e ) unsigned long (32 bit) integer to e type | ||
86 | * eisneg( e ) 1 if sign bit of e != 0, else 0 | ||
87 | * eisinf( e ) 1 if e has maximum exponent (non-IEEE) | ||
88 | * or is infinite (IEEE) | ||
89 | * eisnan( e ) 1 if e is a NaN | ||
90 | * esqrt( a, b ) b = square root of a | ||
91 | * | ||
92 | * | ||
93 | * Routines for internal format numbers | ||
94 | * | ||
95 | * eaddm( ai, bi ) add significands, bi = bi + ai | ||
96 | * ecleaz(ei) ei = 0 | ||
97 | * ecleazs(ei) set ei = 0 but leave its sign alone | ||
98 | * ecmpm( ai, bi ) compare significands, return 1, 0, or -1 | ||
99 | * edivm( ai, bi ) divide significands, bi = bi / ai | ||
100 | * emdnorm(ai,l,s,exp) normalize and round off | ||
101 | * emovi( a, ai ) convert external a to internal ai | ||
102 | * emovo( ai, a ) convert internal ai to external a | ||
103 | * emovz( ai, bi ) bi = ai, low guard word of bi = 0 | ||
104 | * emulm( ai, bi ) multiply significands, bi = bi * ai | ||
105 | * enormlz(ei) left-justify the significand | ||
106 | * eshdn1( ai ) shift significand and guards down 1 bit | ||
107 | * eshdn8( ai ) shift down 8 bits | ||
108 | * eshdn6( ai ) shift down 16 bits | ||
109 | * eshift( ai, n ) shift ai n bits up (or down if n < 0) | ||
110 | * eshup1( ai ) shift significand and guards up 1 bit | ||
111 | * eshup8( ai ) shift up 8 bits | ||
112 | * eshup6( ai ) shift up 16 bits | ||
113 | * esubm( ai, bi ) subtract significands, bi = bi - ai | ||
114 | * | ||
115 | * | ||
116 | * The result is always normalized and rounded to NI-4 word precision | ||
117 | * after each arithmetic operation. | ||
118 | * | ||
119 | * Exception flags are NOT fully supported. | ||
120 | * | ||
121 | * Define INFINITY in mconf.h for support of infinity; otherwise a | ||
122 | * saturation arithmetic is implemented. | ||
123 | * | ||
124 | * Define NANS for support of Not-a-Number items; otherwise the | ||
125 | * arithmetic will never produce a NaN output, and might be confused | ||
126 | * by a NaN input. | ||
127 | * If NaN's are supported, the output of ecmp(a,b) is -2 if | ||
128 | * either a or b is a NaN. This means asking if(ecmp(a,b) < 0) | ||
129 | * may not be legitimate. Use if(ecmp(a,b) == -1) for less-than | ||
130 | * if in doubt. | ||
131 | * Signaling NaN's are NOT supported; they are treated the same | ||
132 | * as quiet NaN's. | ||
133 | * | ||
134 | * Denormals are always supported here where appropriate (e.g., not | ||
135 | * for conversion to DEC numbers). | ||
136 | */ | ||
137 | |||
138 | /* | ||
139 | * Revision history: | ||
140 | * | ||
141 | * 5 Jan 84 PDP-11 assembly language version | ||
142 | * 2 Mar 86 fixed bug in asctoq() | ||
143 | * 6 Dec 86 C language version | ||
144 | * 30 Aug 88 100 digit version, improved rounding | ||
145 | * 15 May 92 80-bit long double support | ||
146 | * | ||
147 | * Author: S. L. Moshier. | ||
148 | */ | ||
149 | |||
150 | #include <stdio.h> | ||
151 | #include "mconf.h" | ||
152 | #include "ehead.h" | ||
153 | |||
154 | /* Change UNK into something else. */ | ||
155 | #ifdef UNK | ||
156 | #undef UNK | ||
157 | #if BIGENDIAN | ||
158 | #define MIEEE 1 | ||
159 | #else | ||
160 | #define IBMPC 1 | ||
161 | #endif | ||
162 | #endif | ||
163 | |||
164 | /* NaN's require infinity support. */ | ||
165 | #ifdef NANS | ||
166 | #ifndef INFINITY | ||
167 | #define INFINITY | ||
168 | #endif | ||
169 | #endif | ||
170 | |||
171 | /* This handles 64-bit long ints. */ | ||
172 | #define LONGBITS (8 * sizeof(long)) | ||
173 | |||
174 | /* Control register for rounding precision. | ||
175 | * This can be set to 80 (if NE=6), 64, 56, 53, or 24 bits. | ||
176 | */ | ||
177 | int rndprc = NBITS; | ||
178 | extern int rndprc; | ||
179 | |||
180 | void eaddm(), esubm(), emdnorm(), asctoeg(), enan(); | ||
181 | static void toe24(), toe53(), toe64(), toe113(); | ||
182 | void eremain(), einit(), eiremain(); | ||
183 | int ecmpm(), edivm(), emulm(), eisneg(), eisinf(); | ||
184 | void emovi(), emovo(), emovz(), ecleaz(), eadd1(); | ||
185 | void etodec(), todec(), dectoe(); | ||
186 | int eisnan(), eiisnan(); | ||
187 | |||
188 | |||
189 | |||
190 | void einit() | ||
191 | { | ||
192 | } | ||
193 | |||
194 | /* | ||
195 | ; Clear out entire external format number. | ||
196 | ; | ||
197 | ; unsigned short x[]; | ||
198 | ; eclear( x ); | ||
199 | */ | ||
200 | |||
201 | void eclear( x ) | ||
202 | register unsigned short *x; | ||
203 | { | ||
204 | register int i; | ||
205 | |||
206 | for( i=0; i<NE; i++ ) | ||
207 | *x++ = 0; | ||
208 | } | ||
209 | |||
210 | |||
211 | |||
212 | /* Move external format number from a to b. | ||
213 | * | ||
214 | * emov( a, b ); | ||
215 | */ | ||
216 | |||
217 | void emov( a, b ) | ||
218 | register unsigned short *a, *b; | ||
219 | { | ||
220 | register int i; | ||
221 | |||
222 | for( i=0; i<NE; i++ ) | ||
223 | *b++ = *a++; | ||
224 | } | ||
225 | |||
226 | |||
227 | /* | ||
228 | ; Absolute value of external format number | ||
229 | ; | ||
230 | ; short x[NE]; | ||
231 | ; eabs( x ); | ||
232 | */ | ||
233 | |||
234 | void eabs(x) | ||
235 | unsigned short x[]; /* x is the memory address of a short */ | ||
236 | { | ||
237 | |||
238 | x[NE-1] &= 0x7fff; /* sign is top bit of last word of external format */ | ||
239 | } | ||
240 | |||
241 | |||
242 | |||
243 | |||
244 | /* | ||
245 | ; Negate external format number | ||
246 | ; | ||
247 | ; unsigned short x[NE]; | ||
248 | ; eneg( x ); | ||
249 | */ | ||
250 | |||
251 | void eneg(x) | ||
252 | unsigned short x[]; | ||
253 | { | ||
254 | |||
255 | #ifdef NANS | ||
256 | if( eisnan(x) ) | ||
257 | return; | ||
258 | #endif | ||
259 | x[NE-1] ^= 0x8000; /* Toggle the sign bit */ | ||
260 | } | ||
261 | |||
262 | |||
263 | |||
264 | /* Return 1 if external format number is negative, | ||
265 | * else return zero. | ||
266 | */ | ||
267 | int eisneg(x) | ||
268 | unsigned short x[]; | ||
269 | { | ||
270 | |||
271 | #ifdef NANS | ||
272 | if( eisnan(x) ) | ||
273 | return( 0 ); | ||
274 | #endif | ||
275 | if( x[NE-1] & 0x8000 ) | ||
276 | return( 1 ); | ||
277 | else | ||
278 | return( 0 ); | ||
279 | } | ||
280 | |||
281 | |||
282 | /* Return 1 if external format number has maximum possible exponent, | ||
283 | * else return zero. | ||
284 | */ | ||
285 | int eisinf(x) | ||
286 | unsigned short x[]; | ||
287 | { | ||
288 | |||
289 | if( (x[NE-1] & 0x7fff) == 0x7fff ) | ||
290 | { | ||
291 | #ifdef NANS | ||
292 | if( eisnan(x) ) | ||
293 | return( 0 ); | ||
294 | #endif | ||
295 | return( 1 ); | ||
296 | } | ||
297 | else | ||
298 | return( 0 ); | ||
299 | } | ||
300 | |||
301 | /* Check if e-type number is not a number. | ||
302 | */ | ||
303 | int eisnan(x) | ||
304 | unsigned short x[]; | ||
305 | { | ||
306 | |||
307 | #ifdef NANS | ||
308 | int i; | ||
309 | /* NaN has maximum exponent */ | ||
310 | if( (x[NE-1] & 0x7fff) != 0x7fff ) | ||
311 | return (0); | ||
312 | /* ... and non-zero significand field. */ | ||
313 | for( i=0; i<NE-1; i++ ) | ||
314 | { | ||
315 | if( *x++ != 0 ) | ||
316 | return (1); | ||
317 | } | ||
318 | #endif | ||
319 | return (0); | ||
320 | } | ||
321 | |||
322 | /* | ||
323 | ; Fill entire number, including exponent and significand, with | ||
324 | ; largest possible number. These programs implement a saturation | ||
325 | ; value that is an ordinary, legal number. A special value | ||
326 | ; "infinity" may also be implemented; this would require tests | ||
327 | ; for that value and implementation of special rules for arithmetic | ||
328 | ; operations involving inifinity. | ||
329 | */ | ||
330 | |||
331 | void einfin(x) | ||
332 | register unsigned short *x; | ||
333 | { | ||
334 | register int i; | ||
335 | |||
336 | #ifdef INFINITY | ||
337 | for( i=0; i<NE-1; i++ ) | ||
338 | *x++ = 0; | ||
339 | *x |= 32767; | ||
340 | #else | ||
341 | for( i=0; i<NE-1; i++ ) | ||
342 | *x++ = 0xffff; | ||
343 | *x |= 32766; | ||
344 | if( rndprc < NBITS ) | ||
345 | { | ||
346 | if (rndprc == 113) | ||
347 | { | ||
348 | *(x - 9) = 0; | ||
349 | *(x - 8) = 0; | ||
350 | } | ||
351 | if( rndprc == 64 ) | ||
352 | { | ||
353 | *(x-5) = 0; | ||
354 | } | ||
355 | if( rndprc == 53 ) | ||
356 | { | ||
357 | *(x-4) = 0xf800; | ||
358 | } | ||
359 | else | ||
360 | { | ||
361 | *(x-4) = 0; | ||
362 | *(x-3) = 0; | ||
363 | *(x-2) = 0xff00; | ||
364 | } | ||
365 | } | ||
366 | #endif | ||
367 | } | ||
368 | |||
369 | |||
370 | |||
371 | /* Move in external format number, | ||
372 | * converting it to internal format. | ||
373 | */ | ||
374 | void emovi( a, b ) | ||
375 | unsigned short *a, *b; | ||
376 | { | ||
377 | register unsigned short *p, *q; | ||
378 | int i; | ||
379 | |||
380 | q = b; | ||
381 | p = a + (NE-1); /* point to last word of external number */ | ||
382 | /* get the sign bit */ | ||
383 | if( *p & 0x8000 ) | ||
384 | *q++ = 0xffff; | ||
385 | else | ||
386 | *q++ = 0; | ||
387 | /* get the exponent */ | ||
388 | *q = *p--; | ||
389 | *q++ &= 0x7fff; /* delete the sign bit */ | ||
390 | #ifdef INFINITY | ||
391 | if( (*(q-1) & 0x7fff) == 0x7fff ) | ||
392 | { | ||
393 | #ifdef NANS | ||
394 | if( eisnan(a) ) | ||
395 | { | ||
396 | *q++ = 0; | ||
397 | for( i=3; i<NI; i++ ) | ||
398 | *q++ = *p--; | ||
399 | return; | ||
400 | } | ||
401 | #endif | ||
402 | for( i=2; i<NI; i++ ) | ||
403 | *q++ = 0; | ||
404 | return; | ||
405 | } | ||
406 | #endif | ||
407 | /* clear high guard word */ | ||
408 | *q++ = 0; | ||
409 | /* move in the significand */ | ||
410 | for( i=0; i<NE-1; i++ ) | ||
411 | *q++ = *p--; | ||
412 | /* clear low guard word */ | ||
413 | *q = 0; | ||
414 | } | ||
415 | |||
416 | |||
417 | /* Move internal format number out, | ||
418 | * converting it to external format. | ||
419 | */ | ||
420 | void emovo( a, b ) | ||
421 | unsigned short *a, *b; | ||
422 | { | ||
423 | register unsigned short *p, *q; | ||
424 | unsigned short i; | ||
425 | |||
426 | p = a; | ||
427 | q = b + (NE-1); /* point to output exponent */ | ||
428 | /* combine sign and exponent */ | ||
429 | i = *p++; | ||
430 | if( i ) | ||
431 | *q-- = *p++ | 0x8000; | ||
432 | else | ||
433 | *q-- = *p++; | ||
434 | #ifdef INFINITY | ||
435 | if( *(p-1) == 0x7fff ) | ||
436 | { | ||
437 | #ifdef NANS | ||
438 | if( eiisnan(a) ) | ||
439 | { | ||
440 | enan( b, NBITS ); | ||
441 | return; | ||
442 | } | ||
443 | #endif | ||
444 | einfin(b); | ||
445 | return; | ||
446 | } | ||
447 | #endif | ||
448 | /* skip over guard word */ | ||
449 | ++p; | ||
450 | /* move the significand */ | ||
451 | for( i=0; i<NE-1; i++ ) | ||
452 | *q-- = *p++; | ||
453 | } | ||
454 | |||
455 | |||
456 | |||
457 | |||
458 | /* Clear out internal format number. | ||
459 | */ | ||
460 | |||
461 | void ecleaz( xi ) | ||
462 | register unsigned short *xi; | ||
463 | { | ||
464 | register int i; | ||
465 | |||
466 | for( i=0; i<NI; i++ ) | ||
467 | *xi++ = 0; | ||
468 | } | ||
469 | |||
470 | /* same, but don't touch the sign. */ | ||
471 | |||
472 | void ecleazs( xi ) | ||
473 | register unsigned short *xi; | ||
474 | { | ||
475 | register int i; | ||
476 | |||
477 | ++xi; | ||
478 | for(i=0; i<NI-1; i++) | ||
479 | *xi++ = 0; | ||
480 | } | ||
481 | |||
482 | |||
483 | |||
484 | |||
485 | /* Move internal format number from a to b. | ||
486 | */ | ||
487 | void emovz( a, b ) | ||
488 | register unsigned short *a, *b; | ||
489 | { | ||
490 | register int i; | ||
491 | |||
492 | for( i=0; i<NI-1; i++ ) | ||
493 | *b++ = *a++; | ||
494 | /* clear low guard word */ | ||
495 | *b = 0; | ||
496 | } | ||
497 | |||
498 | /* Return nonzero if internal format number is a NaN. | ||
499 | */ | ||
500 | |||
501 | int eiisnan (x) | ||
502 | unsigned short x[]; | ||
503 | { | ||
504 | int i; | ||
505 | |||
506 | if( (x[E] & 0x7fff) == 0x7fff ) | ||
507 | { | ||
508 | for( i=M+1; i<NI; i++ ) | ||
509 | { | ||
510 | if( x[i] != 0 ) | ||
511 | return(1); | ||
512 | } | ||
513 | } | ||
514 | return(0); | ||
515 | } | ||
516 | |||
517 | #ifdef INFINITY | ||
518 | /* Return nonzero if internal format number is infinite. */ | ||
519 | |||
520 | static int | ||
521 | eiisinf (x) | ||
522 | unsigned short x[]; | ||
523 | { | ||
524 | |||
525 | #ifdef NANS | ||
526 | if (eiisnan (x)) | ||
527 | return (0); | ||
528 | #endif | ||
529 | if ((x[E] & 0x7fff) == 0x7fff) | ||
530 | return (1); | ||
531 | return (0); | ||
532 | } | ||
533 | #endif | ||
534 | |||
535 | /* | ||
536 | ; Compare significands of numbers in internal format. | ||
537 | ; Guard words are included in the comparison. | ||
538 | ; | ||
539 | ; unsigned short a[NI], b[NI]; | ||
540 | ; cmpm( a, b ); | ||
541 | ; | ||
542 | ; for the significands: | ||
543 | ; returns +1 if a > b | ||
544 | ; 0 if a == b | ||
545 | ; -1 if a < b | ||
546 | */ | ||
547 | int ecmpm( a, b ) | ||
548 | register unsigned short *a, *b; | ||
549 | { | ||
550 | int i; | ||
551 | |||
552 | a += M; /* skip up to significand area */ | ||
553 | b += M; | ||
554 | for( i=M; i<NI; i++ ) | ||
555 | { | ||
556 | if( *a++ != *b++ ) | ||
557 | goto difrnt; | ||
558 | } | ||
559 | return(0); | ||
560 | |||
561 | difrnt: | ||
562 | if( *(--a) > *(--b) ) | ||
563 | return(1); | ||
564 | else | ||
565 | return(-1); | ||
566 | } | ||
567 | |||
568 | |||
569 | /* | ||
570 | ; Shift significand down by 1 bit | ||
571 | */ | ||
572 | |||
573 | void eshdn1(x) | ||
574 | register unsigned short *x; | ||
575 | { | ||
576 | register unsigned short bits; | ||
577 | int i; | ||
578 | |||
579 | x += M; /* point to significand area */ | ||
580 | |||
581 | bits = 0; | ||
582 | for( i=M; i<NI; i++ ) | ||
583 | { | ||
584 | if( *x & 1 ) | ||
585 | bits |= 1; | ||
586 | *x >>= 1; | ||
587 | if( bits & 2 ) | ||
588 | *x |= 0x8000; | ||
589 | bits <<= 1; | ||
590 | ++x; | ||
591 | } | ||
592 | } | ||
593 | |||
594 | |||
595 | |||
596 | /* | ||
597 | ; Shift significand up by 1 bit | ||
598 | */ | ||
599 | |||
600 | void eshup1(x) | ||
601 | register unsigned short *x; | ||
602 | { | ||
603 | register unsigned short bits; | ||
604 | int i; | ||
605 | |||
606 | x += NI-1; | ||
607 | bits = 0; | ||
608 | |||
609 | for( i=M; i<NI; i++ ) | ||
610 | { | ||
611 | if( *x & 0x8000 ) | ||
612 | bits |= 1; | ||
613 | *x <<= 1; | ||
614 | if( bits & 2 ) | ||
615 | *x |= 1; | ||
616 | bits <<= 1; | ||
617 | --x; | ||
618 | } | ||
619 | } | ||
620 | |||
621 | |||
622 | |||
623 | /* | ||
624 | ; Shift significand down by 8 bits | ||
625 | */ | ||
626 | |||
627 | void eshdn8(x) | ||
628 | register unsigned short *x; | ||
629 | { | ||
630 | register unsigned short newbyt, oldbyt; | ||
631 | int i; | ||
632 | |||
633 | x += M; | ||
634 | oldbyt = 0; | ||
635 | for( i=M; i<NI; i++ ) | ||
636 | { | ||
637 | newbyt = *x << 8; | ||
638 | *x >>= 8; | ||
639 | *x |= oldbyt; | ||
640 | oldbyt = newbyt; | ||
641 | ++x; | ||
642 | } | ||
643 | } | ||
644 | |||
645 | /* | ||
646 | ; Shift significand up by 8 bits | ||
647 | */ | ||
648 | |||
649 | void eshup8(x) | ||
650 | register unsigned short *x; | ||
651 | { | ||
652 | int i; | ||
653 | register unsigned short newbyt, oldbyt; | ||
654 | |||
655 | x += NI-1; | ||
656 | oldbyt = 0; | ||
657 | |||
658 | for( i=M; i<NI; i++ ) | ||
659 | { | ||
660 | newbyt = *x >> 8; | ||
661 | *x <<= 8; | ||
662 | *x |= oldbyt; | ||
663 | oldbyt = newbyt; | ||
664 | --x; | ||
665 | } | ||
666 | } | ||
667 | |||
668 | /* | ||
669 | ; Shift significand up by 16 bits | ||
670 | */ | ||
671 | |||
672 | void eshup6(x) | ||
673 | register unsigned short *x; | ||
674 | { | ||
675 | int i; | ||
676 | register unsigned short *p; | ||
677 | |||
678 | p = x + M; | ||
679 | x += M + 1; | ||
680 | |||
681 | for( i=M; i<NI-1; i++ ) | ||
682 | *p++ = *x++; | ||
683 | |||
684 | *p = 0; | ||
685 | } | ||
686 | |||
687 | /* | ||
688 | ; Shift significand down by 16 bits | ||
689 | */ | ||
690 | |||
691 | void eshdn6(x) | ||
692 | register unsigned short *x; | ||
693 | { | ||
694 | int i; | ||
695 | register unsigned short *p; | ||
696 | |||
697 | x += NI-1; | ||
698 | p = x + 1; | ||
699 | |||
700 | for( i=M; i<NI-1; i++ ) | ||
701 | *(--p) = *(--x); | ||
702 | |||
703 | *(--p) = 0; | ||
704 | } | ||
705 | |||
706 | /* | ||
707 | ; Add significands | ||
708 | ; x + y replaces y | ||
709 | */ | ||
710 | |||
711 | void eaddm( x, y ) | ||
712 | unsigned short *x, *y; | ||
713 | { | ||
714 | register unsigned long a; | ||
715 | int i; | ||
716 | unsigned int carry; | ||
717 | |||
718 | x += NI-1; | ||
719 | y += NI-1; | ||
720 | carry = 0; | ||
721 | for( i=M; i<NI; i++ ) | ||
722 | { | ||
723 | a = (unsigned long )(*x) + (unsigned long )(*y) + carry; | ||
724 | if( a & 0x10000 ) | ||
725 | carry = 1; | ||
726 | else | ||
727 | carry = 0; | ||
728 | *y = (unsigned short )a; | ||
729 | --x; | ||
730 | --y; | ||
731 | } | ||
732 | } | ||
733 | |||
734 | /* | ||
735 | ; Subtract significands | ||
736 | ; y - x replaces y | ||
737 | */ | ||
738 | |||
739 | void esubm( x, y ) | ||
740 | unsigned short *x, *y; | ||
741 | { | ||
742 | unsigned long a; | ||
743 | int i; | ||
744 | unsigned int carry; | ||
745 | |||
746 | x += NI-1; | ||
747 | y += NI-1; | ||
748 | carry = 0; | ||
749 | for( i=M; i<NI; i++ ) | ||
750 | { | ||
751 | a = (unsigned long )(*y) - (unsigned long )(*x) - carry; | ||
752 | if( a & 0x10000 ) | ||
753 | carry = 1; | ||
754 | else | ||
755 | carry = 0; | ||
756 | *y = (unsigned short )a; | ||
757 | --x; | ||
758 | --y; | ||
759 | } | ||
760 | } | ||
761 | |||
762 | |||
763 | /* Divide significands */ | ||
764 | |||
765 | static unsigned short equot[NI] = {0}; /* was static */ | ||
766 | |||
767 | #if 0 | ||
768 | int edivm( den, num ) | ||
769 | unsigned short den[], num[]; | ||
770 | { | ||
771 | int i; | ||
772 | register unsigned short *p, *q; | ||
773 | unsigned short j; | ||
774 | |||
775 | p = &equot[0]; | ||
776 | *p++ = num[0]; | ||
777 | *p++ = num[1]; | ||
778 | |||
779 | for( i=M; i<NI; i++ ) | ||
780 | { | ||
781 | *p++ = 0; | ||
782 | } | ||
783 | |||
784 | /* Use faster compare and subtraction if denominator | ||
785 | * has only 15 bits of significance. | ||
786 | */ | ||
787 | p = &den[M+2]; | ||
788 | if( *p++ == 0 ) | ||
789 | { | ||
790 | for( i=M+3; i<NI; i++ ) | ||
791 | { | ||
792 | if( *p++ != 0 ) | ||
793 | goto fulldiv; | ||
794 | } | ||
795 | if( (den[M+1] & 1) != 0 ) | ||
796 | goto fulldiv; | ||
797 | eshdn1(num); | ||
798 | eshdn1(den); | ||
799 | |||
800 | p = &den[M+1]; | ||
801 | q = &num[M+1]; | ||
802 | |||
803 | for( i=0; i<NBITS+2; i++ ) | ||
804 | { | ||
805 | if( *p <= *q ) | ||
806 | { | ||
807 | *q -= *p; | ||
808 | j = 1; | ||
809 | } | ||
810 | else | ||
811 | { | ||
812 | j = 0; | ||
813 | } | ||
814 | eshup1(equot); | ||
815 | equot[NI-2] |= j; | ||
816 | eshup1(num); | ||
817 | } | ||
818 | goto divdon; | ||
819 | } | ||
820 | |||
821 | /* The number of quotient bits to calculate is | ||
822 | * NBITS + 1 scaling guard bit + 1 roundoff bit. | ||
823 | */ | ||
824 | fulldiv: | ||
825 | |||
826 | p = &equot[NI-2]; | ||
827 | for( i=0; i<NBITS+2; i++ ) | ||
828 | { | ||
829 | if( ecmpm(den,num) <= 0 ) | ||
830 | { | ||
831 | esubm(den, num); | ||
832 | j = 1; /* quotient bit = 1 */ | ||
833 | } | ||
834 | else | ||
835 | j = 0; | ||
836 | eshup1(equot); | ||
837 | *p |= j; | ||
838 | eshup1(num); | ||
839 | } | ||
840 | |||
841 | divdon: | ||
842 | |||
843 | eshdn1( equot ); | ||
844 | eshdn1( equot ); | ||
845 | |||
846 | /* test for nonzero remainder after roundoff bit */ | ||
847 | p = &num[M]; | ||
848 | j = 0; | ||
849 | for( i=M; i<NI; i++ ) | ||
850 | { | ||
851 | j |= *p++; | ||
852 | } | ||
853 | if( j ) | ||
854 | j = 1; | ||
855 | |||
856 | |||
857 | for( i=0; i<NI; i++ ) | ||
858 | num[i] = equot[i]; | ||
859 | return( (int )j ); | ||
860 | } | ||
861 | |||
862 | /* Multiply significands */ | ||
863 | int emulm( a, b ) | ||
864 | unsigned short a[], b[]; | ||
865 | { | ||
866 | unsigned short *p, *q; | ||
867 | int i, j, k; | ||
868 | |||
869 | equot[0] = b[0]; | ||
870 | equot[1] = b[1]; | ||
871 | for( i=M; i<NI; i++ ) | ||
872 | equot[i] = 0; | ||
873 | |||
874 | p = &a[NI-2]; | ||
875 | k = NBITS; | ||
876 | while( *p == 0 ) /* significand is not supposed to be all zero */ | ||
877 | { | ||
878 | eshdn6(a); | ||
879 | k -= 16; | ||
880 | } | ||
881 | if( (*p & 0xff) == 0 ) | ||
882 | { | ||
883 | eshdn8(a); | ||
884 | k -= 8; | ||
885 | } | ||
886 | |||
887 | q = &equot[NI-1]; | ||
888 | j = 0; | ||
889 | for( i=0; i<k; i++ ) | ||
890 | { | ||
891 | if( *p & 1 ) | ||
892 | eaddm(b, equot); | ||
893 | /* remember if there were any nonzero bits shifted out */ | ||
894 | if( *q & 1 ) | ||
895 | j |= 1; | ||
896 | eshdn1(a); | ||
897 | eshdn1(equot); | ||
898 | } | ||
899 | |||
900 | for( i=0; i<NI; i++ ) | ||
901 | b[i] = equot[i]; | ||
902 | |||
903 | /* return flag for lost nonzero bits */ | ||
904 | return(j); | ||
905 | } | ||
906 | |||
907 | #else | ||
908 | |||
909 | /* Multiply significand of e-type number b | ||
910 | by 16-bit quantity a, e-type result to c. */ | ||
911 | |||
912 | void m16m( a, b, c ) | ||
913 | unsigned short a; | ||
914 | unsigned short b[], c[]; | ||
915 | { | ||
916 | register unsigned short *pp; | ||
917 | register unsigned long carry; | ||
918 | unsigned short *ps; | ||
919 | unsigned short p[NI]; | ||
920 | unsigned long aa, m; | ||
921 | int i; | ||
922 | |||
923 | aa = a; | ||
924 | pp = &p[NI-2]; | ||
925 | *pp++ = 0; | ||
926 | *pp = 0; | ||
927 | ps = &b[NI-1]; | ||
928 | |||
929 | for( i=M+1; i<NI; i++ ) | ||
930 | { | ||
931 | if( *ps == 0 ) | ||
932 | { | ||
933 | --ps; | ||
934 | --pp; | ||
935 | *(pp-1) = 0; | ||
936 | } | ||
937 | else | ||
938 | { | ||
939 | m = (unsigned long) aa * *ps--; | ||
940 | carry = (m & 0xffff) + *pp; | ||
941 | *pp-- = (unsigned short )carry; | ||
942 | carry = (carry >> 16) + (m >> 16) + *pp; | ||
943 | *pp = (unsigned short )carry; | ||
944 | *(pp-1) = carry >> 16; | ||
945 | } | ||
946 | } | ||
947 | for( i=M; i<NI; i++ ) | ||
948 | c[i] = p[i]; | ||
949 | } | ||
950 | |||
951 | |||
952 | /* Divide significands. Neither the numerator nor the denominator | ||
953 | is permitted to have its high guard word nonzero. */ | ||
954 | |||
955 | |||
956 | int edivm( den, num ) | ||
957 | unsigned short den[], num[]; | ||
958 | { | ||
959 | int i; | ||
960 | register unsigned short *p; | ||
961 | unsigned long tnum; | ||
962 | unsigned short j, tdenm, tquot; | ||
963 | unsigned short tprod[NI+1]; | ||
964 | |||
965 | p = &equot[0]; | ||
966 | *p++ = num[0]; | ||
967 | *p++ = num[1]; | ||
968 | |||
969 | for( i=M; i<NI; i++ ) | ||
970 | { | ||
971 | *p++ = 0; | ||
972 | } | ||
973 | eshdn1( num ); | ||
974 | tdenm = den[M+1]; | ||
975 | for( i=M; i<NI; i++ ) | ||
976 | { | ||
977 | /* Find trial quotient digit (the radix is 65536). */ | ||
978 | tnum = (((unsigned long) num[M]) << 16) + num[M+1]; | ||
979 | |||
980 | /* Do not execute the divide instruction if it will overflow. */ | ||
981 | if( (tdenm * 0xffffL) < tnum ) | ||
982 | tquot = 0xffff; | ||
983 | else | ||
984 | tquot = tnum / tdenm; | ||
985 | |||
986 | /* Prove that the divide worked. */ | ||
987 | /* | ||
988 | tcheck = (unsigned long )tquot * tdenm; | ||
989 | if( tnum - tcheck > tdenm ) | ||
990 | tquot = 0xffff; | ||
991 | */ | ||
992 | /* Multiply denominator by trial quotient digit. */ | ||
993 | m16m( tquot, den, tprod ); | ||
994 | /* The quotient digit may have been overestimated. */ | ||
995 | if( ecmpm( tprod, num ) > 0 ) | ||
996 | { | ||
997 | tquot -= 1; | ||
998 | esubm( den, tprod ); | ||
999 | if( ecmpm( tprod, num ) > 0 ) | ||
1000 | { | ||
1001 | tquot -= 1; | ||
1002 | esubm( den, tprod ); | ||
1003 | } | ||
1004 | } | ||
1005 | /* | ||
1006 | if( ecmpm( tprod, num ) > 0 ) | ||
1007 | { | ||
1008 | eshow( "tprod", tprod ); | ||
1009 | eshow( "num ", num ); | ||
1010 | printf( "tnum = %08lx, tden = %04x, tquot = %04x\n", | ||
1011 | tnum, den[M+1], tquot ); | ||
1012 | } | ||
1013 | */ | ||
1014 | esubm( tprod, num ); | ||
1015 | /* | ||
1016 | if( ecmpm( num, den ) >= 0 ) | ||
1017 | { | ||
1018 | eshow( "num ", num ); | ||
1019 | eshow( "den ", den ); | ||
1020 | printf( "tnum = %08lx, tden = %04x, tquot = %04x\n", | ||
1021 | tnum, den[M+1], tquot ); | ||
1022 | } | ||
1023 | */ | ||
1024 | equot[i] = tquot; | ||
1025 | eshup6(num); | ||
1026 | } | ||
1027 | /* test for nonzero remainder after roundoff bit */ | ||
1028 | p = &num[M]; | ||
1029 | j = 0; | ||
1030 | for( i=M; i<NI; i++ ) | ||
1031 | { | ||
1032 | j |= *p++; | ||
1033 | } | ||
1034 | if( j ) | ||
1035 | j = 1; | ||
1036 | |||
1037 | for( i=0; i<NI; i++ ) | ||
1038 | num[i] = equot[i]; | ||
1039 | |||
1040 | return( (int )j ); | ||
1041 | } | ||
1042 | |||
1043 | |||
1044 | |||
1045 | /* Multiply significands */ | ||
1046 | int emulm( a, b ) | ||
1047 | unsigned short a[], b[]; | ||
1048 | { | ||
1049 | unsigned short *p, *q; | ||
1050 | unsigned short pprod[NI]; | ||
1051 | unsigned short j; | ||
1052 | int i; | ||
1053 | |||
1054 | equot[0] = b[0]; | ||
1055 | equot[1] = b[1]; | ||
1056 | for( i=M; i<NI; i++ ) | ||
1057 | equot[i] = 0; | ||
1058 | |||
1059 | j = 0; | ||
1060 | p = &a[NI-1]; | ||
1061 | q = &equot[NI-1]; | ||
1062 | for( i=M+1; i<NI; i++ ) | ||
1063 | { | ||
1064 | if( *p == 0 ) | ||
1065 | { | ||
1066 | --p; | ||
1067 | } | ||
1068 | else | ||
1069 | { | ||
1070 | m16m( *p--, b, pprod ); | ||
1071 | eaddm(pprod, equot); | ||
1072 | } | ||
1073 | j |= *q; | ||
1074 | eshdn6(equot); | ||
1075 | } | ||
1076 | |||
1077 | for( i=0; i<NI; i++ ) | ||
1078 | b[i] = equot[i]; | ||
1079 | |||
1080 | /* return flag for lost nonzero bits */ | ||
1081 | return( (int)j ); | ||
1082 | } | ||
1083 | |||
1084 | |||
1085 | /* | ||
1086 | eshow(str, x) | ||
1087 | char *str; | ||
1088 | unsigned short *x; | ||
1089 | { | ||
1090 | int i; | ||
1091 | |||
1092 | printf( "%s ", str ); | ||
1093 | for( i=0; i<NI; i++ ) | ||
1094 | printf( "%04x ", *x++ ); | ||
1095 | printf( "\n" ); | ||
1096 | } | ||
1097 | */ | ||
1098 | #endif | ||
1099 | |||
1100 | |||
1101 | |||
1102 | /* | ||
1103 | * Normalize and round off. | ||
1104 | * | ||
1105 | * The internal format number to be rounded is "s". | ||
1106 | * Input "lost" indicates whether the number is exact. | ||
1107 | * This is the so-called sticky bit. | ||
1108 | * | ||
1109 | * Input "subflg" indicates whether the number was obtained | ||
1110 | * by a subtraction operation. In that case if lost is nonzero | ||
1111 | * then the number is slightly smaller than indicated. | ||
1112 | * | ||
1113 | * Input "exp" is the biased exponent, which may be negative. | ||
1114 | * the exponent field of "s" is ignored but is replaced by | ||
1115 | * "exp" as adjusted by normalization and rounding. | ||
1116 | * | ||
1117 | * Input "rcntrl" is the rounding control. | ||
1118 | */ | ||
1119 | |||
1120 | static int rlast = -1; | ||
1121 | static int rw = 0; | ||
1122 | static unsigned short rmsk = 0; | ||
1123 | static unsigned short rmbit = 0; | ||
1124 | static unsigned short rebit = 0; | ||
1125 | static int re = 0; | ||
1126 | static unsigned short rbit[NI] = {0,0,0,0,0,0,0,0}; | ||
1127 | |||
1128 | void emdnorm( s, lost, subflg, exp, rcntrl ) | ||
1129 | unsigned short s[]; | ||
1130 | int lost; | ||
1131 | int subflg; | ||
1132 | long exp; | ||
1133 | int rcntrl; | ||
1134 | { | ||
1135 | int i, j; | ||
1136 | unsigned short r; | ||
1137 | |||
1138 | /* Normalize */ | ||
1139 | j = enormlz( s ); | ||
1140 | |||
1141 | /* a blank significand could mean either zero or infinity. */ | ||
1142 | #ifndef INFINITY | ||
1143 | if( j > NBITS ) | ||
1144 | { | ||
1145 | ecleazs( s ); | ||
1146 | return; | ||
1147 | } | ||
1148 | #endif | ||
1149 | exp -= j; | ||
1150 | #ifndef INFINITY | ||
1151 | if( exp >= 32767L ) | ||
1152 | goto overf; | ||
1153 | #else | ||
1154 | if( (j > NBITS) && (exp < 32767L) ) | ||
1155 | { | ||
1156 | ecleazs( s ); | ||
1157 | return; | ||
1158 | } | ||
1159 | #endif | ||
1160 | if( exp < 0L ) | ||
1161 | { | ||
1162 | if( exp > (long )(-NBITS-1) ) | ||
1163 | { | ||
1164 | j = (int )exp; | ||
1165 | i = eshift( s, j ); | ||
1166 | if( i ) | ||
1167 | lost = 1; | ||
1168 | } | ||
1169 | else | ||
1170 | { | ||
1171 | ecleazs( s ); | ||
1172 | return; | ||
1173 | } | ||
1174 | } | ||
1175 | /* Round off, unless told not to by rcntrl. */ | ||
1176 | if( rcntrl == 0 ) | ||
1177 | goto mdfin; | ||
1178 | /* Set up rounding parameters if the control register changed. */ | ||
1179 | if( rndprc != rlast ) | ||
1180 | { | ||
1181 | ecleaz( rbit ); | ||
1182 | switch( rndprc ) | ||
1183 | { | ||
1184 | default: | ||
1185 | case NBITS: | ||
1186 | rw = NI-1; /* low guard word */ | ||
1187 | rmsk = 0xffff; | ||
1188 | rmbit = 0x8000; | ||
1189 | rebit = 1; | ||
1190 | re = rw - 1; | ||
1191 | break; | ||
1192 | case 113: | ||
1193 | rw = 10; | ||
1194 | rmsk = 0x7fff; | ||
1195 | rmbit = 0x4000; | ||
1196 | rebit = 0x8000; | ||
1197 | re = rw; | ||
1198 | break; | ||
1199 | case 64: | ||
1200 | rw = 7; | ||
1201 | rmsk = 0xffff; | ||
1202 | rmbit = 0x8000; | ||
1203 | rebit = 1; | ||
1204 | re = rw-1; | ||
1205 | break; | ||
1206 | /* For DEC arithmetic */ | ||
1207 | case 56: | ||
1208 | rw = 6; | ||
1209 | rmsk = 0xff; | ||
1210 | rmbit = 0x80; | ||
1211 | rebit = 0x100; | ||
1212 | re = rw; | ||
1213 | break; | ||
1214 | case 53: | ||
1215 | rw = 6; | ||
1216 | rmsk = 0x7ff; | ||
1217 | rmbit = 0x0400; | ||
1218 | rebit = 0x800; | ||
1219 | re = rw; | ||
1220 | break; | ||
1221 | case 24: | ||
1222 | rw = 4; | ||
1223 | rmsk = 0xff; | ||
1224 | rmbit = 0x80; | ||
1225 | rebit = 0x100; | ||
1226 | re = rw; | ||
1227 | break; | ||
1228 | } | ||
1229 | rbit[re] = rebit; | ||
1230 | rlast = rndprc; | ||
1231 | } | ||
1232 | |||
1233 | /* Shift down 1 temporarily if the data structure has an implied | ||
1234 | * most significant bit and the number is denormal. | ||
1235 | * For rndprc = 64 or NBITS, there is no implied bit. | ||
1236 | * But Intel long double denormals lose one bit of significance even so. | ||
1237 | */ | ||
1238 | #ifdef IBMPC | ||
1239 | if( (exp <= 0) && (rndprc != NBITS) ) | ||
1240 | #else | ||
1241 | if( (exp <= 0) && (rndprc != 64) && (rndprc != NBITS) ) | ||
1242 | #endif | ||
1243 | { | ||
1244 | lost |= s[NI-1] & 1; | ||
1245 | eshdn1(s); | ||
1246 | } | ||
1247 | /* Clear out all bits below the rounding bit, | ||
1248 | * remembering in r if any were nonzero. | ||
1249 | */ | ||
1250 | r = s[rw] & rmsk; | ||
1251 | if( rndprc < NBITS ) | ||
1252 | { | ||
1253 | i = rw + 1; | ||
1254 | while( i < NI ) | ||
1255 | { | ||
1256 | if( s[i] ) | ||
1257 | r |= 1; | ||
1258 | s[i] = 0; | ||
1259 | ++i; | ||
1260 | } | ||
1261 | } | ||
1262 | s[rw] &= ~rmsk; | ||
1263 | if( (r & rmbit) != 0 ) | ||
1264 | { | ||
1265 | if( r == rmbit ) | ||
1266 | { | ||
1267 | if( lost == 0 ) | ||
1268 | { /* round to even */ | ||
1269 | if( (s[re] & rebit) == 0 ) | ||
1270 | goto mddone; | ||
1271 | } | ||
1272 | else | ||
1273 | { | ||
1274 | if( subflg != 0 ) | ||
1275 | goto mddone; | ||
1276 | } | ||
1277 | } | ||
1278 | eaddm( rbit, s ); | ||
1279 | } | ||
1280 | mddone: | ||
1281 | #ifdef IBMPC | ||
1282 | if( (exp <= 0) && (rndprc != NBITS) ) | ||
1283 | #else | ||
1284 | if( (exp <= 0) && (rndprc != 64) && (rndprc != NBITS) ) | ||
1285 | #endif | ||
1286 | { | ||
1287 | eshup1(s); | ||
1288 | } | ||
1289 | if( s[2] != 0 ) | ||
1290 | { /* overflow on roundoff */ | ||
1291 | eshdn1(s); | ||
1292 | exp += 1; | ||
1293 | } | ||
1294 | mdfin: | ||
1295 | s[NI-1] = 0; | ||
1296 | if( exp >= 32767L ) | ||
1297 | { | ||
1298 | #ifndef INFINITY | ||
1299 | overf: | ||
1300 | #endif | ||
1301 | #ifdef INFINITY | ||
1302 | s[1] = 32767; | ||
1303 | for( i=2; i<NI-1; i++ ) | ||
1304 | s[i] = 0; | ||
1305 | #else | ||
1306 | s[1] = 32766; | ||
1307 | s[2] = 0; | ||
1308 | for( i=M+1; i<NI-1; i++ ) | ||
1309 | s[i] = 0xffff; | ||
1310 | s[NI-1] = 0; | ||
1311 | if( (rndprc < 64) || (rndprc == 113) ) | ||
1312 | { | ||
1313 | s[rw] &= ~rmsk; | ||
1314 | if( rndprc == 24 ) | ||
1315 | { | ||
1316 | s[5] = 0; | ||
1317 | s[6] = 0; | ||
1318 | } | ||
1319 | } | ||
1320 | #endif | ||
1321 | return; | ||
1322 | } | ||
1323 | if( exp < 0 ) | ||
1324 | s[1] = 0; | ||
1325 | else | ||
1326 | s[1] = (unsigned short )exp; | ||
1327 | } | ||
1328 | |||
1329 | |||
1330 | |||
1331 | /* | ||
1332 | ; Subtract external format numbers. | ||
1333 | ; | ||
1334 | ; unsigned short a[NE], b[NE], c[NE]; | ||
1335 | ; esub( a, b, c ); c = b - a | ||
1336 | */ | ||
1337 | |||
1338 | static int subflg = 0; | ||
1339 | |||
1340 | void esub( a, b, c ) | ||
1341 | unsigned short *a, *b, *c; | ||
1342 | { | ||
1343 | |||
1344 | #ifdef NANS | ||
1345 | if( eisnan(a) ) | ||
1346 | { | ||
1347 | emov (a, c); | ||
1348 | return; | ||
1349 | } | ||
1350 | if( eisnan(b) ) | ||
1351 | { | ||
1352 | emov(b,c); | ||
1353 | return; | ||
1354 | } | ||
1355 | /* Infinity minus infinity is a NaN. | ||
1356 | * Test for subtracting infinities of the same sign. | ||
1357 | */ | ||
1358 | if( eisinf(a) && eisinf(b) && ((eisneg (a) ^ eisneg (b)) == 0)) | ||
1359 | { | ||
1360 | mtherr( "esub", DOMAIN ); | ||
1361 | enan( c, NBITS ); | ||
1362 | return; | ||
1363 | } | ||
1364 | #endif | ||
1365 | subflg = 1; | ||
1366 | eadd1( a, b, c ); | ||
1367 | } | ||
1368 | |||
1369 | |||
1370 | /* | ||
1371 | ; Add. | ||
1372 | ; | ||
1373 | ; unsigned short a[NE], b[NE], c[NE]; | ||
1374 | ; eadd( a, b, c ); c = b + a | ||
1375 | */ | ||
1376 | void eadd( a, b, c ) | ||
1377 | unsigned short *a, *b, *c; | ||
1378 | { | ||
1379 | |||
1380 | #ifdef NANS | ||
1381 | /* NaN plus anything is a NaN. */ | ||
1382 | if( eisnan(a) ) | ||
1383 | { | ||
1384 | emov(a,c); | ||
1385 | return; | ||
1386 | } | ||
1387 | if( eisnan(b) ) | ||
1388 | { | ||
1389 | emov(b,c); | ||
1390 | return; | ||
1391 | } | ||
1392 | /* Infinity minus infinity is a NaN. | ||
1393 | * Test for adding infinities of opposite signs. | ||
1394 | */ | ||
1395 | if( eisinf(a) && eisinf(b) | ||
1396 | && ((eisneg(a) ^ eisneg(b)) != 0) ) | ||
1397 | { | ||
1398 | mtherr( "eadd", DOMAIN ); | ||
1399 | enan( c, NBITS ); | ||
1400 | return; | ||
1401 | } | ||
1402 | #endif | ||
1403 | subflg = 0; | ||
1404 | eadd1( a, b, c ); | ||
1405 | } | ||
1406 | |||
1407 | void eadd1( a, b, c ) | ||
1408 | unsigned short *a, *b, *c; | ||
1409 | { | ||
1410 | unsigned short ai[NI], bi[NI], ci[NI]; | ||
1411 | int i, lost, j, k; | ||
1412 | long lt, lta, ltb; | ||
1413 | |||
1414 | #ifdef INFINITY | ||
1415 | if( eisinf(a) ) | ||
1416 | { | ||
1417 | emov(a,c); | ||
1418 | if( subflg ) | ||
1419 | eneg(c); | ||
1420 | return; | ||
1421 | } | ||
1422 | if( eisinf(b) ) | ||
1423 | { | ||
1424 | emov(b,c); | ||
1425 | return; | ||
1426 | } | ||
1427 | #endif | ||
1428 | emovi( a, ai ); | ||
1429 | emovi( b, bi ); | ||
1430 | if( subflg ) | ||
1431 | ai[0] = ~ai[0]; | ||
1432 | |||
1433 | /* compare exponents */ | ||
1434 | lta = ai[E]; | ||
1435 | ltb = bi[E]; | ||
1436 | lt = lta - ltb; | ||
1437 | if( lt > 0L ) | ||
1438 | { /* put the larger number in bi */ | ||
1439 | emovz( bi, ci ); | ||
1440 | emovz( ai, bi ); | ||
1441 | emovz( ci, ai ); | ||
1442 | ltb = bi[E]; | ||
1443 | lt = -lt; | ||
1444 | } | ||
1445 | lost = 0; | ||
1446 | if( lt != 0L ) | ||
1447 | { | ||
1448 | if( lt < (long )(-NBITS-1) ) | ||
1449 | goto done; /* answer same as larger addend */ | ||
1450 | k = (int )lt; | ||
1451 | lost = eshift( ai, k ); /* shift the smaller number down */ | ||
1452 | } | ||
1453 | else | ||
1454 | { | ||
1455 | /* exponents were the same, so must compare significands */ | ||
1456 | i = ecmpm( ai, bi ); | ||
1457 | if( i == 0 ) | ||
1458 | { /* the numbers are identical in magnitude */ | ||
1459 | /* if different signs, result is zero */ | ||
1460 | if( ai[0] != bi[0] ) | ||
1461 | { | ||
1462 | eclear(c); | ||
1463 | return; | ||
1464 | } | ||
1465 | /* if same sign, result is double */ | ||
1466 | /* double denomalized tiny number */ | ||
1467 | if( (bi[E] == 0) && ((bi[3] & 0x8000) == 0) ) | ||
1468 | { | ||
1469 | eshup1( bi ); | ||
1470 | goto done; | ||
1471 | } | ||
1472 | /* add 1 to exponent unless both are zero! */ | ||
1473 | for( j=1; j<NI-1; j++ ) | ||
1474 | { | ||
1475 | if( bi[j] != 0 ) | ||
1476 | { | ||
1477 | ltb += 1; | ||
1478 | if( ltb >= 0x7fff ) | ||
1479 | { | ||
1480 | eclear(c); | ||
1481 | einfin(c); | ||
1482 | if( ai[0] != 0 ) | ||
1483 | eneg(c); | ||
1484 | return; | ||
1485 | } | ||
1486 | break; | ||
1487 | } | ||
1488 | } | ||
1489 | bi[E] = (unsigned short )ltb; | ||
1490 | goto done; | ||
1491 | } | ||
1492 | if( i > 0 ) | ||
1493 | { /* put the larger number in bi */ | ||
1494 | emovz( bi, ci ); | ||
1495 | emovz( ai, bi ); | ||
1496 | emovz( ci, ai ); | ||
1497 | } | ||
1498 | } | ||
1499 | if( ai[0] == bi[0] ) | ||
1500 | { | ||
1501 | eaddm( ai, bi ); | ||
1502 | subflg = 0; | ||
1503 | } | ||
1504 | else | ||
1505 | { | ||
1506 | esubm( ai, bi ); | ||
1507 | subflg = 1; | ||
1508 | } | ||
1509 | emdnorm( bi, lost, subflg, ltb, 64 ); | ||
1510 | |||
1511 | done: | ||
1512 | emovo( bi, c ); | ||
1513 | } | ||
1514 | |||
1515 | |||
1516 | |||
1517 | /* | ||
1518 | ; Divide. | ||
1519 | ; | ||
1520 | ; unsigned short a[NE], b[NE], c[NE]; | ||
1521 | ; ediv( a, b, c ); c = b / a | ||
1522 | */ | ||
1523 | void ediv( a, b, c ) | ||
1524 | unsigned short *a, *b, *c; | ||
1525 | { | ||
1526 | unsigned short ai[NI], bi[NI]; | ||
1527 | int i, sign; | ||
1528 | long lt, lta, ltb; | ||
1529 | |||
1530 | /* IEEE says if result is not a NaN, the sign is "-" if and only if | ||
1531 | operands have opposite signs -- but flush -0 to 0 later if not IEEE. */ | ||
1532 | sign = eisneg(a) ^ eisneg(b); | ||
1533 | |||
1534 | #ifdef NANS | ||
1535 | /* Return any NaN input. */ | ||
1536 | if( eisnan(a) ) | ||
1537 | { | ||
1538 | emov(a,c); | ||
1539 | return; | ||
1540 | } | ||
1541 | if( eisnan(b) ) | ||
1542 | { | ||
1543 | emov(b,c); | ||
1544 | return; | ||
1545 | } | ||
1546 | /* Zero over zero, or infinity over infinity, is a NaN. */ | ||
1547 | if( ((ecmp(a,ezero) == 0) && (ecmp(b,ezero) == 0)) | ||
1548 | || (eisinf (a) && eisinf (b)) ) | ||
1549 | { | ||
1550 | mtherr( "ediv", DOMAIN ); | ||
1551 | enan( c, NBITS ); | ||
1552 | return; | ||
1553 | } | ||
1554 | #endif | ||
1555 | /* Infinity over anything else is infinity. */ | ||
1556 | #ifdef INFINITY | ||
1557 | if( eisinf(b) ) | ||
1558 | { | ||
1559 | einfin(c); | ||
1560 | goto divsign; | ||
1561 | } | ||
1562 | if( eisinf(a) ) | ||
1563 | { | ||
1564 | eclear(c); | ||
1565 | goto divsign; | ||
1566 | } | ||
1567 | #endif | ||
1568 | emovi( a, ai ); | ||
1569 | emovi( b, bi ); | ||
1570 | lta = ai[E]; | ||
1571 | ltb = bi[E]; | ||
1572 | if( bi[E] == 0 ) | ||
1573 | { /* See if numerator is zero. */ | ||
1574 | for( i=1; i<NI-1; i++ ) | ||
1575 | { | ||
1576 | if( bi[i] != 0 ) | ||
1577 | { | ||
1578 | ltb -= enormlz( bi ); | ||
1579 | goto dnzro1; | ||
1580 | } | ||
1581 | } | ||
1582 | eclear(c); | ||
1583 | goto divsign; | ||
1584 | } | ||
1585 | dnzro1: | ||
1586 | |||
1587 | if( ai[E] == 0 ) | ||
1588 | { /* possible divide by zero */ | ||
1589 | for( i=1; i<NI-1; i++ ) | ||
1590 | { | ||
1591 | if( ai[i] != 0 ) | ||
1592 | { | ||
1593 | lta -= enormlz( ai ); | ||
1594 | goto dnzro2; | ||
1595 | } | ||
1596 | } | ||
1597 | einfin(c); | ||
1598 | mtherr( "ediv", SING ); | ||
1599 | goto divsign; | ||
1600 | } | ||
1601 | dnzro2: | ||
1602 | |||
1603 | i = edivm( ai, bi ); | ||
1604 | /* calculate exponent */ | ||
1605 | lt = ltb - lta + EXONE; | ||
1606 | emdnorm( bi, i, 0, lt, 64 ); | ||
1607 | emovo( bi, c ); | ||
1608 | |||
1609 | divsign: | ||
1610 | |||
1611 | if( sign ) | ||
1612 | *(c+(NE-1)) |= 0x8000; | ||
1613 | else | ||
1614 | *(c+(NE-1)) &= ~0x8000; | ||
1615 | } | ||
1616 | |||
1617 | |||
1618 | |||
1619 | /* | ||
1620 | ; Multiply. | ||
1621 | ; | ||
1622 | ; unsigned short a[NE], b[NE], c[NE]; | ||
1623 | ; emul( a, b, c ); c = b * a | ||
1624 | */ | ||
1625 | void emul( a, b, c ) | ||
1626 | unsigned short *a, *b, *c; | ||
1627 | { | ||
1628 | unsigned short ai[NI], bi[NI]; | ||
1629 | int i, j, sign; | ||
1630 | long lt, lta, ltb; | ||
1631 | |||
1632 | /* IEEE says if result is not a NaN, the sign is "-" if and only if | ||
1633 | operands have opposite signs -- but flush -0 to 0 later if not IEEE. */ | ||
1634 | sign = eisneg(a) ^ eisneg(b); | ||
1635 | |||
1636 | #ifdef NANS | ||
1637 | /* NaN times anything is the same NaN. */ | ||
1638 | if( eisnan(a) ) | ||
1639 | { | ||
1640 | emov(a,c); | ||
1641 | return; | ||
1642 | } | ||
1643 | if( eisnan(b) ) | ||
1644 | { | ||
1645 | emov(b,c); | ||
1646 | return; | ||
1647 | } | ||
1648 | /* Zero times infinity is a NaN. */ | ||
1649 | if( (eisinf(a) && (ecmp(b,ezero) == 0)) | ||
1650 | || (eisinf(b) && (ecmp(a,ezero) == 0)) ) | ||
1651 | { | ||
1652 | mtherr( "emul", DOMAIN ); | ||
1653 | enan( c, NBITS ); | ||
1654 | return; | ||
1655 | } | ||
1656 | #endif | ||
1657 | /* Infinity times anything else is infinity. */ | ||
1658 | #ifdef INFINITY | ||
1659 | if( eisinf(a) || eisinf(b) ) | ||
1660 | { | ||
1661 | einfin(c); | ||
1662 | goto mulsign; | ||
1663 | } | ||
1664 | #endif | ||
1665 | emovi( a, ai ); | ||
1666 | emovi( b, bi ); | ||
1667 | lta = ai[E]; | ||
1668 | ltb = bi[E]; | ||
1669 | if( ai[E] == 0 ) | ||
1670 | { | ||
1671 | for( i=1; i<NI-1; i++ ) | ||
1672 | { | ||
1673 | if( ai[i] != 0 ) | ||
1674 | { | ||
1675 | lta -= enormlz( ai ); | ||
1676 | goto mnzer1; | ||
1677 | } | ||
1678 | } | ||
1679 | eclear(c); | ||
1680 | goto mulsign; | ||
1681 | } | ||
1682 | mnzer1: | ||
1683 | |||
1684 | if( bi[E] == 0 ) | ||
1685 | { | ||
1686 | for( i=1; i<NI-1; i++ ) | ||
1687 | { | ||
1688 | if( bi[i] != 0 ) | ||
1689 | { | ||
1690 | ltb -= enormlz( bi ); | ||
1691 | goto mnzer2; | ||
1692 | } | ||
1693 | } | ||
1694 | eclear(c); | ||
1695 | goto mulsign; | ||
1696 | } | ||
1697 | mnzer2: | ||
1698 | |||
1699 | /* Multiply significands */ | ||
1700 | j = emulm( ai, bi ); | ||
1701 | /* calculate exponent */ | ||
1702 | lt = lta + ltb - (EXONE - 1); | ||
1703 | emdnorm( bi, j, 0, lt, 64 ); | ||
1704 | emovo( bi, c ); | ||
1705 | /* IEEE says sign is "-" if and only if operands have opposite signs. */ | ||
1706 | mulsign: | ||
1707 | if( sign ) | ||
1708 | *(c+(NE-1)) |= 0x8000; | ||
1709 | else | ||
1710 | *(c+(NE-1)) &= ~0x8000; | ||
1711 | } | ||
1712 | |||
1713 | |||
1714 | |||
1715 | |||
1716 | /* | ||
1717 | ; Convert IEEE double precision to e type | ||
1718 | ; double d; | ||
1719 | ; unsigned short x[N+2]; | ||
1720 | ; e53toe( &d, x ); | ||
1721 | */ | ||
1722 | void e53toe( pe, y ) | ||
1723 | unsigned short *pe, *y; | ||
1724 | { | ||
1725 | #ifdef DEC | ||
1726 | |||
1727 | dectoe( pe, y ); /* see etodec.c */ | ||
1728 | |||
1729 | #else | ||
1730 | |||
1731 | register unsigned short r; | ||
1732 | register unsigned short *p, *e; | ||
1733 | unsigned short yy[NI]; | ||
1734 | int denorm, k; | ||
1735 | |||
1736 | e = pe; | ||
1737 | denorm = 0; /* flag if denormalized number */ | ||
1738 | ecleaz(yy); | ||
1739 | #ifdef IBMPC | ||
1740 | e += 3; | ||
1741 | #endif | ||
1742 | r = *e; | ||
1743 | yy[0] = 0; | ||
1744 | if( r & 0x8000 ) | ||
1745 | yy[0] = 0xffff; | ||
1746 | yy[M] = (r & 0x0f) | 0x10; | ||
1747 | r &= ~0x800f; /* strip sign and 4 significand bits */ | ||
1748 | #ifdef INFINITY | ||
1749 | if( r == 0x7ff0 ) | ||
1750 | { | ||
1751 | #ifdef NANS | ||
1752 | #ifdef IBMPC | ||
1753 | if( ((pe[3] & 0xf) != 0) || (pe[2] != 0) | ||
1754 | || (pe[1] != 0) || (pe[0] != 0) ) | ||
1755 | { | ||
1756 | enan( y, NBITS ); | ||
1757 | return; | ||
1758 | } | ||
1759 | #else | ||
1760 | if( ((pe[0] & 0xf) != 0) || (pe[1] != 0) | ||
1761 | || (pe[2] != 0) || (pe[3] != 0) ) | ||
1762 | { | ||
1763 | enan( y, NBITS ); | ||
1764 | return; | ||
1765 | } | ||
1766 | #endif | ||
1767 | #endif /* NANS */ | ||
1768 | eclear( y ); | ||
1769 | einfin( y ); | ||
1770 | if( yy[0] ) | ||
1771 | eneg(y); | ||
1772 | return; | ||
1773 | } | ||
1774 | #endif | ||
1775 | r >>= 4; | ||
1776 | /* If zero exponent, then the significand is denormalized. | ||
1777 | * So, take back the understood high significand bit. */ | ||
1778 | if( r == 0 ) | ||
1779 | { | ||
1780 | denorm = 1; | ||
1781 | yy[M] &= ~0x10; | ||
1782 | } | ||
1783 | r += EXONE - 01777; | ||
1784 | yy[E] = r; | ||
1785 | p = &yy[M+1]; | ||
1786 | #ifdef IBMPC | ||
1787 | *p++ = *(--e); | ||
1788 | *p++ = *(--e); | ||
1789 | *p++ = *(--e); | ||
1790 | #endif | ||
1791 | #ifdef MIEEE | ||
1792 | ++e; | ||
1793 | *p++ = *e++; | ||
1794 | *p++ = *e++; | ||
1795 | *p++ = *e++; | ||
1796 | #endif | ||
1797 | (void )eshift( yy, -5 ); | ||
1798 | if( denorm ) | ||
1799 | { /* if zero exponent, then normalize the significand */ | ||
1800 | if( (k = enormlz(yy)) > NBITS ) | ||
1801 | ecleazs(yy); | ||
1802 | else | ||
1803 | yy[E] -= (unsigned short )(k-1); | ||
1804 | } | ||
1805 | emovo( yy, y ); | ||
1806 | #endif /* not DEC */ | ||
1807 | } | ||
1808 | |||
1809 | void e64toe( pe, y ) | ||
1810 | unsigned short *pe, *y; | ||
1811 | { | ||
1812 | unsigned short yy[NI]; | ||
1813 | unsigned short *p, *q, *e; | ||
1814 | int i; | ||
1815 | |||
1816 | e = pe; | ||
1817 | p = yy; | ||
1818 | for( i=0; i<NE-5; i++ ) | ||
1819 | *p++ = 0; | ||
1820 | #ifdef IBMPC | ||
1821 | for( i=0; i<5; i++ ) | ||
1822 | *p++ = *e++; | ||
1823 | #endif | ||
1824 | #ifdef DEC | ||
1825 | for( i=0; i<5; i++ ) | ||
1826 | *p++ = *e++; | ||
1827 | #endif | ||
1828 | #ifdef MIEEE | ||
1829 | p = &yy[0] + (NE-1); | ||
1830 | *p-- = *e++; | ||
1831 | ++e; | ||
1832 | for( i=0; i<4; i++ ) | ||
1833 | *p-- = *e++; | ||
1834 | #endif | ||
1835 | |||
1836 | #ifdef IBMPC | ||
1837 | /* For Intel long double, shift denormal significand up 1 | ||
1838 | -- but only if the top significand bit is zero. */ | ||
1839 | if((yy[NE-1] & 0x7fff) == 0 && (yy[NE-2] & 0x8000) == 0) | ||
1840 | { | ||
1841 | unsigned short temp[NI+1]; | ||
1842 | emovi(yy, temp); | ||
1843 | eshup1(temp); | ||
1844 | emovo(temp,y); | ||
1845 | return; | ||
1846 | } | ||
1847 | #endif | ||
1848 | #ifdef INFINITY | ||
1849 | /* Point to the exponent field. */ | ||
1850 | p = &yy[NE-1]; | ||
1851 | if ((*p & 0x7fff) == 0x7fff) | ||
1852 | { | ||
1853 | #ifdef NANS | ||
1854 | #ifdef IBMPC | ||
1855 | for( i=0; i<4; i++ ) | ||
1856 | { | ||
1857 | if((i != 3 && pe[i] != 0) | ||
1858 | /* Check for Intel long double infinity pattern. */ | ||
1859 | || (i == 3 && pe[i] != 0x8000)) | ||
1860 | { | ||
1861 | enan( y, NBITS ); | ||
1862 | return; | ||
1863 | } | ||
1864 | } | ||
1865 | #else | ||
1866 | /* In Motorola extended precision format, the most significant | ||
1867 | bit of an infinity mantissa could be either 1 or 0. It is | ||
1868 | the lower order bits that tell whether the value is a NaN. */ | ||
1869 | if ((pe[2] & 0x7fff) != 0) | ||
1870 | goto bigend_nan; | ||
1871 | |||
1872 | for( i=3; i<=5; i++ ) | ||
1873 | { | ||
1874 | if( pe[i] != 0 ) | ||
1875 | { | ||
1876 | bigend_nan: | ||
1877 | enan( y, NBITS ); | ||
1878 | return; | ||
1879 | } | ||
1880 | } | ||
1881 | #endif | ||
1882 | #endif /* NANS */ | ||
1883 | eclear( y ); | ||
1884 | einfin( y ); | ||
1885 | if( *p & 0x8000 ) | ||
1886 | eneg(y); | ||
1887 | return; | ||
1888 | } | ||
1889 | #endif | ||
1890 | p = yy; | ||
1891 | q = y; | ||
1892 | for( i=0; i<NE; i++ ) | ||
1893 | *q++ = *p++; | ||
1894 | } | ||
1895 | |||
1896 | void e113toe(pe,y) | ||
1897 | unsigned short *pe, *y; | ||
1898 | { | ||
1899 | register unsigned short r; | ||
1900 | unsigned short *e, *p; | ||
1901 | unsigned short yy[NI]; | ||
1902 | int denorm, i; | ||
1903 | |||
1904 | e = pe; | ||
1905 | denorm = 0; | ||
1906 | ecleaz(yy); | ||
1907 | #ifdef IBMPC | ||
1908 | e += 7; | ||
1909 | #endif | ||
1910 | r = *e; | ||
1911 | yy[0] = 0; | ||
1912 | if( r & 0x8000 ) | ||
1913 | yy[0] = 0xffff; | ||
1914 | r &= 0x7fff; | ||
1915 | #ifdef INFINITY | ||
1916 | if( r == 0x7fff ) | ||
1917 | { | ||
1918 | #ifdef NANS | ||
1919 | #ifdef IBMPC | ||
1920 | for( i=0; i<7; i++ ) | ||
1921 | { | ||
1922 | if( pe[i] != 0 ) | ||
1923 | { | ||
1924 | enan( y, NBITS ); | ||
1925 | return; | ||
1926 | } | ||
1927 | } | ||
1928 | #else | ||
1929 | for( i=1; i<8; i++ ) | ||
1930 | { | ||
1931 | if( pe[i] != 0 ) | ||
1932 | { | ||
1933 | enan( y, NBITS ); | ||
1934 | return; | ||
1935 | } | ||
1936 | } | ||
1937 | #endif | ||
1938 | #endif /* NANS */ | ||
1939 | eclear( y ); | ||
1940 | einfin( y ); | ||
1941 | if( *e & 0x8000 ) | ||
1942 | eneg(y); | ||
1943 | return; | ||
1944 | } | ||
1945 | #endif /* INFINITY */ | ||
1946 | yy[E] = r; | ||
1947 | p = &yy[M + 1]; | ||
1948 | #ifdef IBMPC | ||
1949 | for( i=0; i<7; i++ ) | ||
1950 | *p++ = *(--e); | ||
1951 | #endif | ||
1952 | #ifdef MIEEE | ||
1953 | ++e; | ||
1954 | for( i=0; i<7; i++ ) | ||
1955 | *p++ = *e++; | ||
1956 | #endif | ||
1957 | /* If denormal, remove the implied bit; else shift down 1. */ | ||
1958 | if( r == 0 ) | ||
1959 | { | ||
1960 | yy[M] = 0; | ||
1961 | } | ||
1962 | else | ||
1963 | { | ||
1964 | yy[M] = 1; | ||
1965 | eshift( yy, -1 ); | ||
1966 | } | ||
1967 | emovo(yy,y); | ||
1968 | } | ||
1969 | |||
1970 | |||
1971 | /* | ||
1972 | ; Convert IEEE single precision to e type | ||
1973 | ; float d; | ||
1974 | ; unsigned short x[N+2]; | ||
1975 | ; dtox( &d, x ); | ||
1976 | */ | ||
1977 | void e24toe( pe, y ) | ||
1978 | unsigned short *pe, *y; | ||
1979 | { | ||
1980 | register unsigned short r; | ||
1981 | register unsigned short *p, *e; | ||
1982 | unsigned short yy[NI]; | ||
1983 | int denorm, k; | ||
1984 | |||
1985 | e = pe; | ||
1986 | denorm = 0; /* flag if denormalized number */ | ||
1987 | ecleaz(yy); | ||
1988 | #ifdef IBMPC | ||
1989 | e += 1; | ||
1990 | #endif | ||
1991 | #ifdef DEC | ||
1992 | e += 1; | ||
1993 | #endif | ||
1994 | r = *e; | ||
1995 | yy[0] = 0; | ||
1996 | if( r & 0x8000 ) | ||
1997 | yy[0] = 0xffff; | ||
1998 | yy[M] = (r & 0x7f) | 0200; | ||
1999 | r &= ~0x807f; /* strip sign and 7 significand bits */ | ||
2000 | #ifdef INFINITY | ||
2001 | if( r == 0x7f80 ) | ||
2002 | { | ||
2003 | #ifdef NANS | ||
2004 | #ifdef MIEEE | ||
2005 | if( ((pe[0] & 0x7f) != 0) || (pe[1] != 0) ) | ||
2006 | { | ||
2007 | enan( y, NBITS ); | ||
2008 | return; | ||
2009 | } | ||
2010 | #else | ||
2011 | if( ((pe[1] & 0x7f) != 0) || (pe[0] != 0) ) | ||
2012 | { | ||
2013 | enan( y, NBITS ); | ||
2014 | return; | ||
2015 | } | ||
2016 | #endif | ||
2017 | #endif /* NANS */ | ||
2018 | eclear( y ); | ||
2019 | einfin( y ); | ||
2020 | if( yy[0] ) | ||
2021 | eneg(y); | ||
2022 | return; | ||
2023 | } | ||
2024 | #endif | ||
2025 | r >>= 7; | ||
2026 | /* If zero exponent, then the significand is denormalized. | ||
2027 | * So, take back the understood high significand bit. */ | ||
2028 | if( r == 0 ) | ||
2029 | { | ||
2030 | denorm = 1; | ||
2031 | yy[M] &= ~0200; | ||
2032 | } | ||
2033 | r += EXONE - 0177; | ||
2034 | yy[E] = r; | ||
2035 | p = &yy[M+1]; | ||
2036 | #ifdef IBMPC | ||
2037 | *p++ = *(--e); | ||
2038 | #endif | ||
2039 | #ifdef DEC | ||
2040 | *p++ = *(--e); | ||
2041 | #endif | ||
2042 | #ifdef MIEEE | ||
2043 | ++e; | ||
2044 | *p++ = *e++; | ||
2045 | #endif | ||
2046 | (void )eshift( yy, -8 ); | ||
2047 | if( denorm ) | ||
2048 | { /* if zero exponent, then normalize the significand */ | ||
2049 | if( (k = enormlz(yy)) > NBITS ) | ||
2050 | ecleazs(yy); | ||
2051 | else | ||
2052 | yy[E] -= (unsigned short )(k-1); | ||
2053 | } | ||
2054 | emovo( yy, y ); | ||
2055 | } | ||
2056 | |||
2057 | void etoe113(x,e) | ||
2058 | unsigned short *x, *e; | ||
2059 | { | ||
2060 | unsigned short xi[NI]; | ||
2061 | long exp; | ||
2062 | int rndsav; | ||
2063 | |||
2064 | #ifdef NANS | ||
2065 | if( eisnan(x) ) | ||
2066 | { | ||
2067 | enan( e, 113 ); | ||
2068 | return; | ||
2069 | } | ||
2070 | #endif | ||
2071 | emovi( x, xi ); | ||
2072 | exp = (long )xi[E]; | ||
2073 | #ifdef INFINITY | ||
2074 | if( eisinf(x) ) | ||
2075 | goto nonorm; | ||
2076 | #endif | ||
2077 | /* round off to nearest or even */ | ||
2078 | rndsav = rndprc; | ||
2079 | rndprc = 113; | ||
2080 | emdnorm( xi, 0, 0, exp, 64 ); | ||
2081 | rndprc = rndsav; | ||
2082 | nonorm: | ||
2083 | toe113 (xi, e); | ||
2084 | } | ||
2085 | |||
2086 | /* move out internal format to ieee long double */ | ||
2087 | static void toe113(a,b) | ||
2088 | unsigned short *a, *b; | ||
2089 | { | ||
2090 | register unsigned short *p, *q; | ||
2091 | unsigned short i; | ||
2092 | |||
2093 | #ifdef NANS | ||
2094 | if( eiisnan(a) ) | ||
2095 | { | ||
2096 | enan( b, 113 ); | ||
2097 | return; | ||
2098 | } | ||
2099 | #endif | ||
2100 | p = a; | ||
2101 | #ifdef MIEEE | ||
2102 | q = b; | ||
2103 | #else | ||
2104 | q = b + 7; /* point to output exponent */ | ||
2105 | #endif | ||
2106 | |||
2107 | /* If not denormal, delete the implied bit. */ | ||
2108 | if( a[E] != 0 ) | ||
2109 | { | ||
2110 | eshup1 (a); | ||
2111 | } | ||
2112 | /* combine sign and exponent */ | ||
2113 | i = *p++; | ||
2114 | #ifdef MIEEE | ||
2115 | if( i ) | ||
2116 | *q++ = *p++ | 0x8000; | ||
2117 | else | ||
2118 | *q++ = *p++; | ||
2119 | #else | ||
2120 | if( i ) | ||
2121 | *q-- = *p++ | 0x8000; | ||
2122 | else | ||
2123 | *q-- = *p++; | ||
2124 | #endif | ||
2125 | /* skip over guard word */ | ||
2126 | ++p; | ||
2127 | /* move the significand */ | ||
2128 | #ifdef MIEEE | ||
2129 | for (i = 0; i < 7; i++) | ||
2130 | *q++ = *p++; | ||
2131 | #else | ||
2132 | for (i = 0; i < 7; i++) | ||
2133 | *q-- = *p++; | ||
2134 | #endif | ||
2135 | } | ||
2136 | |||
2137 | |||
2138 | void etoe64( x, e ) | ||
2139 | unsigned short *x, *e; | ||
2140 | { | ||
2141 | unsigned short xi[NI]; | ||
2142 | long exp; | ||
2143 | int rndsav; | ||
2144 | |||
2145 | #ifdef NANS | ||
2146 | if( eisnan(x) ) | ||
2147 | { | ||
2148 | enan( e, 64 ); | ||
2149 | return; | ||
2150 | } | ||
2151 | #endif | ||
2152 | emovi( x, xi ); | ||
2153 | exp = (long )xi[E]; /* adjust exponent for offset */ | ||
2154 | #ifdef INFINITY | ||
2155 | if( eisinf(x) ) | ||
2156 | goto nonorm; | ||
2157 | #endif | ||
2158 | /* round off to nearest or even */ | ||
2159 | rndsav = rndprc; | ||
2160 | rndprc = 64; | ||
2161 | emdnorm( xi, 0, 0, exp, 64 ); | ||
2162 | rndprc = rndsav; | ||
2163 | nonorm: | ||
2164 | toe64( xi, e ); | ||
2165 | } | ||
2166 | |||
2167 | /* move out internal format to ieee long double */ | ||
2168 | static void toe64( a, b ) | ||
2169 | unsigned short *a, *b; | ||
2170 | { | ||
2171 | register unsigned short *p, *q; | ||
2172 | unsigned short i; | ||
2173 | |||
2174 | #ifdef NANS | ||
2175 | if( eiisnan(a) ) | ||
2176 | { | ||
2177 | enan( b, 64 ); | ||
2178 | return; | ||
2179 | } | ||
2180 | #endif | ||
2181 | #ifdef IBMPC | ||
2182 | /* Shift Intel denormal significand down 1. */ | ||
2183 | if( a[E] == 0 ) | ||
2184 | eshdn1(a); | ||
2185 | #endif | ||
2186 | p = a; | ||
2187 | #ifdef MIEEE | ||
2188 | q = b; | ||
2189 | #else | ||
2190 | q = b + 4; /* point to output exponent */ | ||
2191 | #if 1 | ||
2192 | /* NOTE: if data type is 96 bits wide, clear the last word here. */ | ||
2193 | *(q+1)= 0; | ||
2194 | #endif | ||
2195 | #endif | ||
2196 | |||
2197 | /* combine sign and exponent */ | ||
2198 | i = *p++; | ||
2199 | #ifdef MIEEE | ||
2200 | if( i ) | ||
2201 | *q++ = *p++ | 0x8000; | ||
2202 | else | ||
2203 | *q++ = *p++; | ||
2204 | *q++ = 0; | ||
2205 | #else | ||
2206 | if( i ) | ||
2207 | *q-- = *p++ | 0x8000; | ||
2208 | else | ||
2209 | *q-- = *p++; | ||
2210 | #endif | ||
2211 | /* skip over guard word */ | ||
2212 | ++p; | ||
2213 | /* move the significand */ | ||
2214 | #ifdef MIEEE | ||
2215 | for( i=0; i<4; i++ ) | ||
2216 | *q++ = *p++; | ||
2217 | #else | ||
2218 | #ifdef INFINITY | ||
2219 | if (eiisinf (a)) | ||
2220 | { | ||
2221 | /* Intel long double infinity. */ | ||
2222 | *q-- = 0x8000; | ||
2223 | *q-- = 0; | ||
2224 | *q-- = 0; | ||
2225 | *q = 0; | ||
2226 | return; | ||
2227 | } | ||
2228 | #endif | ||
2229 | for( i=0; i<4; i++ ) | ||
2230 | *q-- = *p++; | ||
2231 | #endif | ||
2232 | } | ||
2233 | |||
2234 | |||
2235 | /* | ||
2236 | ; e type to IEEE double precision | ||
2237 | ; double d; | ||
2238 | ; unsigned short x[NE]; | ||
2239 | ; etoe53( x, &d ); | ||
2240 | */ | ||
2241 | |||
2242 | #ifdef DEC | ||
2243 | |||
2244 | void etoe53( x, e ) | ||
2245 | unsigned short *x, *e; | ||
2246 | { | ||
2247 | etodec( x, e ); /* see etodec.c */ | ||
2248 | } | ||
2249 | |||
2250 | static void toe53( x, y ) | ||
2251 | unsigned short *x, *y; | ||
2252 | { | ||
2253 | todec( x, y ); | ||
2254 | } | ||
2255 | |||
2256 | #else | ||
2257 | |||
2258 | void etoe53( x, e ) | ||
2259 | unsigned short *x, *e; | ||
2260 | { | ||
2261 | unsigned short xi[NI]; | ||
2262 | long exp; | ||
2263 | int rndsav; | ||
2264 | |||
2265 | #ifdef NANS | ||
2266 | if( eisnan(x) ) | ||
2267 | { | ||
2268 | enan( e, 53 ); | ||
2269 | return; | ||
2270 | } | ||
2271 | #endif | ||
2272 | emovi( x, xi ); | ||
2273 | exp = (long )xi[E] - (EXONE - 0x3ff); /* adjust exponent for offsets */ | ||
2274 | #ifdef INFINITY | ||
2275 | if( eisinf(x) ) | ||
2276 | goto nonorm; | ||
2277 | #endif | ||
2278 | /* round off to nearest or even */ | ||
2279 | rndsav = rndprc; | ||
2280 | rndprc = 53; | ||
2281 | emdnorm( xi, 0, 0, exp, 64 ); | ||
2282 | rndprc = rndsav; | ||
2283 | nonorm: | ||
2284 | toe53( xi, e ); | ||
2285 | } | ||
2286 | |||
2287 | |||
2288 | static void toe53( x, y ) | ||
2289 | unsigned short *x, *y; | ||
2290 | { | ||
2291 | unsigned short i; | ||
2292 | unsigned short *p; | ||
2293 | |||
2294 | |||
2295 | #ifdef NANS | ||
2296 | if( eiisnan(x) ) | ||
2297 | { | ||
2298 | enan( y, 53 ); | ||
2299 | return; | ||
2300 | } | ||
2301 | #endif | ||
2302 | p = &x[0]; | ||
2303 | #ifdef IBMPC | ||
2304 | y += 3; | ||
2305 | #endif | ||
2306 | *y = 0; /* output high order */ | ||
2307 | if( *p++ ) | ||
2308 | *y = 0x8000; /* output sign bit */ | ||
2309 | |||
2310 | i = *p++; | ||
2311 | if( i >= (unsigned int )2047 ) | ||
2312 | { /* Saturate at largest number less than infinity. */ | ||
2313 | #ifdef INFINITY | ||
2314 | *y |= 0x7ff0; | ||
2315 | #ifdef IBMPC | ||
2316 | *(--y) = 0; | ||
2317 | *(--y) = 0; | ||
2318 | *(--y) = 0; | ||
2319 | #endif | ||
2320 | #ifdef MIEEE | ||
2321 | ++y; | ||
2322 | *y++ = 0; | ||
2323 | *y++ = 0; | ||
2324 | *y++ = 0; | ||
2325 | #endif | ||
2326 | #else | ||
2327 | *y |= (unsigned short )0x7fef; | ||
2328 | #ifdef IBMPC | ||
2329 | *(--y) = 0xffff; | ||
2330 | *(--y) = 0xffff; | ||
2331 | *(--y) = 0xffff; | ||
2332 | #endif | ||
2333 | #ifdef MIEEE | ||
2334 | ++y; | ||
2335 | *y++ = 0xffff; | ||
2336 | *y++ = 0xffff; | ||
2337 | *y++ = 0xffff; | ||
2338 | #endif | ||
2339 | #endif | ||
2340 | return; | ||
2341 | } | ||
2342 | if( i == 0 ) | ||
2343 | { | ||
2344 | (void )eshift( x, 4 ); | ||
2345 | } | ||
2346 | else | ||
2347 | { | ||
2348 | i <<= 4; | ||
2349 | (void )eshift( x, 5 ); | ||
2350 | } | ||
2351 | i |= *p++ & (unsigned short )0x0f; /* *p = xi[M] */ | ||
2352 | *y |= (unsigned short )i; /* high order output already has sign bit set */ | ||
2353 | #ifdef IBMPC | ||
2354 | *(--y) = *p++; | ||
2355 | *(--y) = *p++; | ||
2356 | *(--y) = *p; | ||
2357 | #endif | ||
2358 | #ifdef MIEEE | ||
2359 | ++y; | ||
2360 | *y++ = *p++; | ||
2361 | *y++ = *p++; | ||
2362 | *y++ = *p++; | ||
2363 | #endif | ||
2364 | } | ||
2365 | |||
2366 | #endif /* not DEC */ | ||
2367 | |||
2368 | |||
2369 | |||
2370 | /* | ||
2371 | ; e type to IEEE single precision | ||
2372 | ; float d; | ||
2373 | ; unsigned short x[N+2]; | ||
2374 | ; xtod( x, &d ); | ||
2375 | */ | ||
2376 | void etoe24( x, e ) | ||
2377 | unsigned short *x, *e; | ||
2378 | { | ||
2379 | long exp; | ||
2380 | unsigned short xi[NI]; | ||
2381 | int rndsav; | ||
2382 | |||
2383 | #ifdef NANS | ||
2384 | if( eisnan(x) ) | ||
2385 | { | ||
2386 | enan( e, 24 ); | ||
2387 | return; | ||
2388 | } | ||
2389 | #endif | ||
2390 | emovi( x, xi ); | ||
2391 | exp = (long )xi[E] - (EXONE - 0177); /* adjust exponent for offsets */ | ||
2392 | #ifdef INFINITY | ||
2393 | if( eisinf(x) ) | ||
2394 | goto nonorm; | ||
2395 | #endif | ||
2396 | /* round off to nearest or even */ | ||
2397 | rndsav = rndprc; | ||
2398 | rndprc = 24; | ||
2399 | emdnorm( xi, 0, 0, exp, 64 ); | ||
2400 | rndprc = rndsav; | ||
2401 | nonorm: | ||
2402 | toe24( xi, e ); | ||
2403 | } | ||
2404 | |||
2405 | static void toe24( x, y ) | ||
2406 | unsigned short *x, *y; | ||
2407 | { | ||
2408 | unsigned short i; | ||
2409 | unsigned short *p; | ||
2410 | |||
2411 | #ifdef NANS | ||
2412 | if( eiisnan(x) ) | ||
2413 | { | ||
2414 | enan( y, 24 ); | ||
2415 | return; | ||
2416 | } | ||
2417 | #endif | ||
2418 | p = &x[0]; | ||
2419 | #ifdef IBMPC | ||
2420 | y += 1; | ||
2421 | #endif | ||
2422 | #ifdef DEC | ||
2423 | y += 1; | ||
2424 | #endif | ||
2425 | *y = 0; /* output high order */ | ||
2426 | if( *p++ ) | ||
2427 | *y = 0x8000; /* output sign bit */ | ||
2428 | |||
2429 | i = *p++; | ||
2430 | if( i >= 255 ) | ||
2431 | { /* Saturate at largest number less than infinity. */ | ||
2432 | #ifdef INFINITY | ||
2433 | *y |= (unsigned short )0x7f80; | ||
2434 | #ifdef IBMPC | ||
2435 | *(--y) = 0; | ||
2436 | #endif | ||
2437 | #ifdef DEC | ||
2438 | *(--y) = 0; | ||
2439 | #endif | ||
2440 | #ifdef MIEEE | ||
2441 | ++y; | ||
2442 | *y = 0; | ||
2443 | #endif | ||
2444 | #else | ||
2445 | *y |= (unsigned short )0x7f7f; | ||
2446 | #ifdef IBMPC | ||
2447 | *(--y) = 0xffff; | ||
2448 | #endif | ||
2449 | #ifdef DEC | ||
2450 | *(--y) = 0xffff; | ||
2451 | #endif | ||
2452 | #ifdef MIEEE | ||
2453 | ++y; | ||
2454 | *y = 0xffff; | ||
2455 | #endif | ||
2456 | #endif | ||
2457 | return; | ||
2458 | } | ||
2459 | if( i == 0 ) | ||
2460 | { | ||
2461 | (void )eshift( x, 7 ); | ||
2462 | } | ||
2463 | else | ||
2464 | { | ||
2465 | i <<= 7; | ||
2466 | (void )eshift( x, 8 ); | ||
2467 | } | ||
2468 | i |= *p++ & (unsigned short )0x7f; /* *p = xi[M] */ | ||
2469 | *y |= i; /* high order output already has sign bit set */ | ||
2470 | #ifdef IBMPC | ||
2471 | *(--y) = *p; | ||
2472 | #endif | ||
2473 | #ifdef DEC | ||
2474 | *(--y) = *p; | ||
2475 | #endif | ||
2476 | #ifdef MIEEE | ||
2477 | ++y; | ||
2478 | *y = *p; | ||
2479 | #endif | ||
2480 | } | ||
2481 | |||
2482 | |||
2483 | /* Compare two e type numbers. | ||
2484 | * | ||
2485 | * unsigned short a[NE], b[NE]; | ||
2486 | * ecmp( a, b ); | ||
2487 | * | ||
2488 | * returns +1 if a > b | ||
2489 | * 0 if a == b | ||
2490 | * -1 if a < b | ||
2491 | * -2 if either a or b is a NaN. | ||
2492 | */ | ||
2493 | int ecmp( a, b ) | ||
2494 | unsigned short *a, *b; | ||
2495 | { | ||
2496 | unsigned short ai[NI], bi[NI]; | ||
2497 | register unsigned short *p, *q; | ||
2498 | register int i; | ||
2499 | int msign; | ||
2500 | |||
2501 | #ifdef NANS | ||
2502 | if (eisnan (a) || eisnan (b)) | ||
2503 | return( -2 ); | ||
2504 | #endif | ||
2505 | emovi( a, ai ); | ||
2506 | p = ai; | ||
2507 | emovi( b, bi ); | ||
2508 | q = bi; | ||
2509 | |||
2510 | if( *p != *q ) | ||
2511 | { /* the signs are different */ | ||
2512 | /* -0 equals + 0 */ | ||
2513 | for( i=1; i<NI-1; i++ ) | ||
2514 | { | ||
2515 | if( ai[i] != 0 ) | ||
2516 | goto nzro; | ||
2517 | if( bi[i] != 0 ) | ||
2518 | goto nzro; | ||
2519 | } | ||
2520 | return(0); | ||
2521 | nzro: | ||
2522 | if( *p == 0 ) | ||
2523 | return( 1 ); | ||
2524 | else | ||
2525 | return( -1 ); | ||
2526 | } | ||
2527 | /* both are the same sign */ | ||
2528 | if( *p == 0 ) | ||
2529 | msign = 1; | ||
2530 | else | ||
2531 | msign = -1; | ||
2532 | i = NI-1; | ||
2533 | do | ||
2534 | { | ||
2535 | if( *p++ != *q++ ) | ||
2536 | { | ||
2537 | goto diff; | ||
2538 | } | ||
2539 | } | ||
2540 | while( --i > 0 ); | ||
2541 | |||
2542 | return(0); /* equality */ | ||
2543 | |||
2544 | |||
2545 | |||
2546 | diff: | ||
2547 | |||
2548 | if( *(--p) > *(--q) ) | ||
2549 | return( msign ); /* p is bigger */ | ||
2550 | else | ||
2551 | return( -msign ); /* p is littler */ | ||
2552 | } | ||
2553 | |||
2554 | |||
2555 | |||
2556 | |||
2557 | /* Find nearest integer to x = floor( x + 0.5 ) | ||
2558 | * | ||
2559 | * unsigned short x[NE], y[NE] | ||
2560 | * eround( x, y ); | ||
2561 | */ | ||
2562 | void eround( x, y ) | ||
2563 | unsigned short *x, *y; | ||
2564 | { | ||
2565 | |||
2566 | eadd( ehalf, x, y ); | ||
2567 | efloor( y, y ); | ||
2568 | } | ||
2569 | |||
2570 | |||
2571 | |||
2572 | |||
2573 | /* | ||
2574 | ; convert long (32-bit) integer to e type | ||
2575 | ; | ||
2576 | ; long l; | ||
2577 | ; unsigned short x[NE]; | ||
2578 | ; ltoe( &l, x ); | ||
2579 | ; note &l is the memory address of l | ||
2580 | */ | ||
2581 | void ltoe( lp, y ) | ||
2582 | long *lp; /* lp is the memory address of a long integer */ | ||
2583 | unsigned short *y; /* y is the address of a short */ | ||
2584 | { | ||
2585 | unsigned short yi[NI]; | ||
2586 | unsigned long ll; | ||
2587 | int k; | ||
2588 | |||
2589 | ecleaz( yi ); | ||
2590 | if( *lp < 0 ) | ||
2591 | { | ||
2592 | ll = (unsigned long )( -(*lp) ); /* make it positive */ | ||
2593 | yi[0] = 0xffff; /* put correct sign in the e type number */ | ||
2594 | } | ||
2595 | else | ||
2596 | { | ||
2597 | ll = (unsigned long )( *lp ); | ||
2598 | } | ||
2599 | /* move the long integer to yi significand area */ | ||
2600 | if( sizeof(long) == 8 ) | ||
2601 | { | ||
2602 | yi[M] = (unsigned short) (ll >> (LONGBITS - 16)); | ||
2603 | yi[M + 1] = (unsigned short) (ll >> (LONGBITS - 32)); | ||
2604 | yi[M + 2] = (unsigned short) (ll >> 16); | ||
2605 | yi[M + 3] = (unsigned short) ll; | ||
2606 | yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */ | ||
2607 | } | ||
2608 | else | ||
2609 | { | ||
2610 | yi[M] = (unsigned short )(ll >> 16); | ||
2611 | yi[M+1] = (unsigned short )ll; | ||
2612 | yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */ | ||
2613 | } | ||
2614 | if( (k = enormlz( yi )) > NBITS ) /* normalize the significand */ | ||
2615 | ecleaz( yi ); /* it was zero */ | ||
2616 | else | ||
2617 | yi[E] -= (unsigned short )k; /* subtract shift count from exponent */ | ||
2618 | emovo( yi, y ); /* output the answer */ | ||
2619 | } | ||
2620 | |||
2621 | /* | ||
2622 | ; convert unsigned long (32-bit) integer to e type | ||
2623 | ; | ||
2624 | ; unsigned long l; | ||
2625 | ; unsigned short x[NE]; | ||
2626 | ; ltox( &l, x ); | ||
2627 | ; note &l is the memory address of l | ||
2628 | */ | ||
2629 | void ultoe( lp, y ) | ||
2630 | unsigned long *lp; /* lp is the memory address of a long integer */ | ||
2631 | unsigned short *y; /* y is the address of a short */ | ||
2632 | { | ||
2633 | unsigned short yi[NI]; | ||
2634 | unsigned long ll; | ||
2635 | int k; | ||
2636 | |||
2637 | ecleaz( yi ); | ||
2638 | ll = *lp; | ||
2639 | |||
2640 | /* move the long integer to ayi significand area */ | ||
2641 | if( sizeof(long) == 8 ) | ||
2642 | { | ||
2643 | yi[M] = (unsigned short) (ll >> (LONGBITS - 16)); | ||
2644 | yi[M + 1] = (unsigned short) (ll >> (LONGBITS - 32)); | ||
2645 | yi[M + 2] = (unsigned short) (ll >> 16); | ||
2646 | yi[M + 3] = (unsigned short) ll; | ||
2647 | yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */ | ||
2648 | } | ||
2649 | else | ||
2650 | { | ||
2651 | yi[M] = (unsigned short )(ll >> 16); | ||
2652 | yi[M+1] = (unsigned short )ll; | ||
2653 | yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */ | ||
2654 | } | ||
2655 | if( (k = enormlz( yi )) > NBITS ) /* normalize the significand */ | ||
2656 | ecleaz( yi ); /* it was zero */ | ||
2657 | else | ||
2658 | yi[E] -= (unsigned short )k; /* subtract shift count from exponent */ | ||
2659 | emovo( yi, y ); /* output the answer */ | ||
2660 | } | ||
2661 | |||
2662 | |||
2663 | /* | ||
2664 | ; Find long integer and fractional parts | ||
2665 | |||
2666 | ; long i; | ||
2667 | ; unsigned short x[NE], frac[NE]; | ||
2668 | ; xifrac( x, &i, frac ); | ||
2669 | |||
2670 | The integer output has the sign of the input. The fraction is | ||
2671 | the positive fractional part of abs(x). | ||
2672 | */ | ||
2673 | void eifrac( x, i, frac ) | ||
2674 | unsigned short *x; | ||
2675 | long *i; | ||
2676 | unsigned short *frac; | ||
2677 | { | ||
2678 | unsigned short xi[NI]; | ||
2679 | int j, k; | ||
2680 | unsigned long ll; | ||
2681 | |||
2682 | emovi( x, xi ); | ||
2683 | k = (int )xi[E] - (EXONE - 1); | ||
2684 | if( k <= 0 ) | ||
2685 | { | ||
2686 | /* if exponent <= 0, integer = 0 and real output is fraction */ | ||
2687 | *i = 0L; | ||
2688 | emovo( xi, frac ); | ||
2689 | return; | ||
2690 | } | ||
2691 | if( k > (8 * sizeof(long) - 1) ) | ||
2692 | { | ||
2693 | /* | ||
2694 | ; long integer overflow: output large integer | ||
2695 | ; and correct fraction | ||
2696 | */ | ||
2697 | j = 8 * sizeof(long) - 1; | ||
2698 | if( xi[0] ) | ||
2699 | *i = (long) ((unsigned long) 1) << j; | ||
2700 | else | ||
2701 | *i = (long) (((unsigned long) (~(0L))) >> 1); | ||
2702 | (void )eshift( xi, k ); | ||
2703 | } | ||
2704 | if( k > 16 ) | ||
2705 | { | ||
2706 | /* | ||
2707 | Shift more than 16 bits: shift up k-16 mod 16 | ||
2708 | then shift by 16's. | ||
2709 | */ | ||
2710 | j = k - ((k >> 4) << 4); | ||
2711 | eshift (xi, j); | ||
2712 | ll = xi[M]; | ||
2713 | k -= j; | ||
2714 | do | ||
2715 | { | ||
2716 | eshup6 (xi); | ||
2717 | ll = (ll << 16) | xi[M]; | ||
2718 | } | ||
2719 | while ((k -= 16) > 0); | ||
2720 | *i = ll; | ||
2721 | if (xi[0]) | ||
2722 | *i = -(*i); | ||
2723 | } | ||
2724 | else | ||
2725 | { | ||
2726 | /* shift not more than 16 bits */ | ||
2727 | eshift( xi, k ); | ||
2728 | *i = (long )xi[M] & 0xffff; | ||
2729 | if( xi[0] ) | ||
2730 | *i = -(*i); | ||
2731 | } | ||
2732 | xi[0] = 0; | ||
2733 | xi[E] = EXONE - 1; | ||
2734 | xi[M] = 0; | ||
2735 | if( (k = enormlz( xi )) > NBITS ) | ||
2736 | ecleaz( xi ); | ||
2737 | else | ||
2738 | xi[E] -= (unsigned short )k; | ||
2739 | |||
2740 | emovo( xi, frac ); | ||
2741 | } | ||
2742 | |||
2743 | |||
2744 | /* | ||
2745 | ; Find unsigned long integer and fractional parts | ||
2746 | |||
2747 | ; unsigned long i; | ||
2748 | ; unsigned short x[NE], frac[NE]; | ||
2749 | ; xifrac( x, &i, frac ); | ||
2750 | |||
2751 | A negative e type input yields integer output = 0 | ||
2752 | but correct fraction. | ||
2753 | */ | ||
2754 | void euifrac( x, i, frac ) | ||
2755 | unsigned short *x; | ||
2756 | unsigned long *i; | ||
2757 | unsigned short *frac; | ||
2758 | { | ||
2759 | unsigned short xi[NI]; | ||
2760 | int j, k; | ||
2761 | unsigned long ll; | ||
2762 | |||
2763 | emovi( x, xi ); | ||
2764 | k = (int )xi[E] - (EXONE - 1); | ||
2765 | if( k <= 0 ) | ||
2766 | { | ||
2767 | /* if exponent <= 0, integer = 0 and argument is fraction */ | ||
2768 | *i = 0L; | ||
2769 | emovo( xi, frac ); | ||
2770 | return; | ||
2771 | } | ||
2772 | if( k > (8 * sizeof(long)) ) | ||
2773 | { | ||
2774 | /* | ||
2775 | ; long integer overflow: output large integer | ||
2776 | ; and correct fraction | ||
2777 | */ | ||
2778 | *i = ~(0L); | ||
2779 | (void )eshift( xi, k ); | ||
2780 | } | ||
2781 | else if( k > 16 ) | ||
2782 | { | ||
2783 | /* | ||
2784 | Shift more than 16 bits: shift up k-16 mod 16 | ||
2785 | then shift up by 16's. | ||
2786 | */ | ||
2787 | j = k - ((k >> 4) << 4); | ||
2788 | eshift (xi, j); | ||
2789 | ll = xi[M]; | ||
2790 | k -= j; | ||
2791 | do | ||
2792 | { | ||
2793 | eshup6 (xi); | ||
2794 | ll = (ll << 16) | xi[M]; | ||
2795 | } | ||
2796 | while ((k -= 16) > 0); | ||
2797 | *i = ll; | ||
2798 | } | ||
2799 | else | ||
2800 | { | ||
2801 | /* shift not more than 16 bits */ | ||
2802 | eshift( xi, k ); | ||
2803 | *i = (long )xi[M] & 0xffff; | ||
2804 | } | ||
2805 | |||
2806 | if( xi[0] ) /* A negative value yields unsigned integer 0. */ | ||
2807 | *i = 0L; | ||
2808 | |||
2809 | xi[0] = 0; | ||
2810 | xi[E] = EXONE - 1; | ||
2811 | xi[M] = 0; | ||
2812 | if( (k = enormlz( xi )) > NBITS ) | ||
2813 | ecleaz( xi ); | ||
2814 | else | ||
2815 | xi[E] -= (unsigned short )k; | ||
2816 | |||
2817 | emovo( xi, frac ); | ||
2818 | } | ||
2819 | |||
2820 | |||
2821 | |||
2822 | /* | ||
2823 | ; Shift significand | ||
2824 | ; | ||
2825 | ; Shifts significand area up or down by the number of bits | ||
2826 | ; given by the variable sc. | ||
2827 | */ | ||
2828 | int eshift( x, sc ) | ||
2829 | unsigned short *x; | ||
2830 | int sc; | ||
2831 | { | ||
2832 | unsigned short lost; | ||
2833 | unsigned short *p; | ||
2834 | |||
2835 | if( sc == 0 ) | ||
2836 | return( 0 ); | ||
2837 | |||
2838 | lost = 0; | ||
2839 | p = x + NI-1; | ||
2840 | |||
2841 | if( sc < 0 ) | ||
2842 | { | ||
2843 | sc = -sc; | ||
2844 | while( sc >= 16 ) | ||
2845 | { | ||
2846 | lost |= *p; /* remember lost bits */ | ||
2847 | eshdn6(x); | ||
2848 | sc -= 16; | ||
2849 | } | ||
2850 | |||
2851 | while( sc >= 8 ) | ||
2852 | { | ||
2853 | lost |= *p & 0xff; | ||
2854 | eshdn8(x); | ||
2855 | sc -= 8; | ||
2856 | } | ||
2857 | |||
2858 | while( sc > 0 ) | ||
2859 | { | ||
2860 | lost |= *p & 1; | ||
2861 | eshdn1(x); | ||
2862 | sc -= 1; | ||
2863 | } | ||
2864 | } | ||
2865 | else | ||
2866 | { | ||
2867 | while( sc >= 16 ) | ||
2868 | { | ||
2869 | eshup6(x); | ||
2870 | sc -= 16; | ||
2871 | } | ||
2872 | |||
2873 | while( sc >= 8 ) | ||
2874 | { | ||
2875 | eshup8(x); | ||
2876 | sc -= 8; | ||
2877 | } | ||
2878 | |||
2879 | while( sc > 0 ) | ||
2880 | { | ||
2881 | eshup1(x); | ||
2882 | sc -= 1; | ||
2883 | } | ||
2884 | } | ||
2885 | if( lost ) | ||
2886 | lost = 1; | ||
2887 | return( (int )lost ); | ||
2888 | } | ||
2889 | |||
2890 | |||
2891 | |||
2892 | /* | ||
2893 | ; normalize | ||
2894 | ; | ||
2895 | ; Shift normalizes the significand area pointed to by argument | ||
2896 | ; shift count (up = positive) is returned. | ||
2897 | */ | ||
2898 | int enormlz(x) | ||
2899 | unsigned short x[]; | ||
2900 | { | ||
2901 | register unsigned short *p; | ||
2902 | int sc; | ||
2903 | |||
2904 | sc = 0; | ||
2905 | p = &x[M]; | ||
2906 | if( *p != 0 ) | ||
2907 | goto normdn; | ||
2908 | ++p; | ||
2909 | if( *p & 0x8000 ) | ||
2910 | return( 0 ); /* already normalized */ | ||
2911 | while( *p == 0 ) | ||
2912 | { | ||
2913 | eshup6(x); | ||
2914 | sc += 16; | ||
2915 | /* With guard word, there are NBITS+16 bits available. | ||
2916 | * return true if all are zero. | ||
2917 | */ | ||
2918 | if( sc > NBITS ) | ||
2919 | return( sc ); | ||
2920 | } | ||
2921 | /* see if high byte is zero */ | ||
2922 | while( (*p & 0xff00) == 0 ) | ||
2923 | { | ||
2924 | eshup8(x); | ||
2925 | sc += 8; | ||
2926 | } | ||
2927 | /* now shift 1 bit at a time */ | ||
2928 | while( (*p & 0x8000) == 0) | ||
2929 | { | ||
2930 | eshup1(x); | ||
2931 | sc += 1; | ||
2932 | if( sc > (NBITS+16) ) | ||
2933 | { | ||
2934 | mtherr( "enormlz", UNDERFLOW ); | ||
2935 | return( sc ); | ||
2936 | } | ||
2937 | } | ||
2938 | return( sc ); | ||
2939 | |||
2940 | /* Normalize by shifting down out of the high guard word | ||
2941 | of the significand */ | ||
2942 | normdn: | ||
2943 | |||
2944 | if( *p & 0xff00 ) | ||
2945 | { | ||
2946 | eshdn8(x); | ||
2947 | sc -= 8; | ||
2948 | } | ||
2949 | while( *p != 0 ) | ||
2950 | { | ||
2951 | eshdn1(x); | ||
2952 | sc -= 1; | ||
2953 | |||
2954 | if( sc < -NBITS ) | ||
2955 | { | ||
2956 | mtherr( "enormlz", OVERFLOW ); | ||
2957 | return( sc ); | ||
2958 | } | ||
2959 | } | ||
2960 | return( sc ); | ||
2961 | } | ||
2962 | |||
2963 | |||
2964 | |||
2965 | |||
2966 | /* Convert e type number to decimal format ASCII string. | ||
2967 | * The constants are for 64 bit precision. | ||
2968 | */ | ||
2969 | |||
2970 | #define NTEN 12 | ||
2971 | #define MAXP 4096 | ||
2972 | |||
2973 | #if NE == 10 | ||
2974 | static unsigned short etens[NTEN + 1][NE] = | ||
2975 | { | ||
2976 | {0x6576, 0x4a92, 0x804a, 0x153f, | ||
2977 | 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */ | ||
2978 | {0x6a32, 0xce52, 0x329a, 0x28ce, | ||
2979 | 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */ | ||
2980 | {0x526c, 0x50ce, 0xf18b, 0x3d28, | ||
2981 | 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,}, | ||
2982 | {0x9c66, 0x58f8, 0xbc50, 0x5c54, | ||
2983 | 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,}, | ||
2984 | {0x851e, 0xeab7, 0x98fe, 0x901b, | ||
2985 | 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,}, | ||
2986 | {0x0235, 0x0137, 0x36b1, 0x336c, | ||
2987 | 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,}, | ||
2988 | {0x50f8, 0x25fb, 0xc76b, 0x6b71, | ||
2989 | 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,}, | ||
2990 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
2991 | 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,}, | ||
2992 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
2993 | 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,}, | ||
2994 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
2995 | 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,}, | ||
2996 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
2997 | 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,}, | ||
2998 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
2999 | 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,}, | ||
3000 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
3001 | 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */ | ||
3002 | }; | ||
3003 | |||
3004 | static unsigned short emtens[NTEN + 1][NE] = | ||
3005 | { | ||
3006 | {0x2030, 0xcffc, 0xa1c3, 0x8123, | ||
3007 | 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */ | ||
3008 | {0x8264, 0xd2cb, 0xf2ea, 0x12d4, | ||
3009 | 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */ | ||
3010 | {0xf53f, 0xf698, 0x6bd3, 0x0158, | ||
3011 | 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,}, | ||
3012 | {0xe731, 0x04d4, 0xe3f2, 0xd332, | ||
3013 | 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,}, | ||
3014 | {0xa23e, 0x5308, 0xfefb, 0x1155, | ||
3015 | 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,}, | ||
3016 | {0xe26d, 0xdbde, 0xd05d, 0xb3f6, | ||
3017 | 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,}, | ||
3018 | {0x2a20, 0x6224, 0x47b3, 0x98d7, | ||
3019 | 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,}, | ||
3020 | {0x0b5b, 0x4af2, 0xa581, 0x18ed, | ||
3021 | 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,}, | ||
3022 | {0xbf71, 0xa9b3, 0x7989, 0xbe68, | ||
3023 | 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,}, | ||
3024 | {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b, | ||
3025 | 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,}, | ||
3026 | {0xc155, 0xa4a8, 0x404e, 0x6113, | ||
3027 | 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,}, | ||
3028 | {0xd70a, 0x70a3, 0x0a3d, 0xa3d7, | ||
3029 | 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,}, | ||
3030 | {0xcccd, 0xcccc, 0xcccc, 0xcccc, | ||
3031 | 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */ | ||
3032 | }; | ||
3033 | #else | ||
3034 | static unsigned short etens[NTEN+1][NE] = { | ||
3035 | {0xc94c,0x979a,0x8a20,0x5202,0xc460,0x7525,},/* 10**4096 */ | ||
3036 | {0xa74d,0x5de4,0xc53d,0x3b5d,0x9e8b,0x5a92,},/* 10**2048 */ | ||
3037 | {0x650d,0x0c17,0x8175,0x7586,0xc976,0x4d48,}, | ||
3038 | {0xcc65,0x91c6,0xa60e,0xa0ae,0xe319,0x46a3,}, | ||
3039 | {0xddbc,0xde8d,0x9df9,0xebfb,0xaa7e,0x4351,}, | ||
3040 | {0xc66f,0x8cdf,0x80e9,0x47c9,0x93ba,0x41a8,}, | ||
3041 | {0x3cbf,0xa6d5,0xffcf,0x1f49,0xc278,0x40d3,}, | ||
3042 | {0xf020,0xb59d,0x2b70,0xada8,0x9dc5,0x4069,}, | ||
3043 | {0x0000,0x0000,0x0400,0xc9bf,0x8e1b,0x4034,}, | ||
3044 | {0x0000,0x0000,0x0000,0x2000,0xbebc,0x4019,}, | ||
3045 | {0x0000,0x0000,0x0000,0x0000,0x9c40,0x400c,}, | ||
3046 | {0x0000,0x0000,0x0000,0x0000,0xc800,0x4005,}, | ||
3047 | {0x0000,0x0000,0x0000,0x0000,0xa000,0x4002,}, /* 10**1 */ | ||
3048 | }; | ||
3049 | |||
3050 | static unsigned short emtens[NTEN+1][NE] = { | ||
3051 | {0x2de4,0x9fde,0xd2ce,0x04c8,0xa6dd,0x0ad8,}, /* 10**-4096 */ | ||
3052 | {0x4925,0x2de4,0x3436,0x534f,0xceae,0x256b,}, /* 10**-2048 */ | ||
3053 | {0x87a6,0xc0bd,0xda57,0x82a5,0xa2a6,0x32b5,}, | ||
3054 | {0x7133,0xd21c,0xdb23,0xee32,0x9049,0x395a,}, | ||
3055 | {0xfa91,0x1939,0x637a,0x4325,0xc031,0x3cac,}, | ||
3056 | {0xac7d,0xe4a0,0x64bc,0x467c,0xddd0,0x3e55,}, | ||
3057 | {0x3f24,0xe9a5,0xa539,0xea27,0xa87f,0x3f2a,}, | ||
3058 | {0x67de,0x94ba,0x4539,0x1ead,0xcfb1,0x3f94,}, | ||
3059 | {0x4c2f,0xe15b,0xc44d,0x94be,0xe695,0x3fc9,}, | ||
3060 | {0xfdc2,0xcefc,0x8461,0x7711,0xabcc,0x3fe4,}, | ||
3061 | {0xd3c3,0x652b,0xe219,0x1758,0xd1b7,0x3ff1,}, | ||
3062 | {0x3d71,0xd70a,0x70a3,0x0a3d,0xa3d7,0x3ff8,}, | ||
3063 | {0xcccd,0xcccc,0xcccc,0xcccc,0xcccc,0x3ffb,}, /* 10**-1 */ | ||
3064 | }; | ||
3065 | #endif | ||
3066 | |||
3067 | void e24toasc( x, string, ndigs ) | ||
3068 | unsigned short x[]; | ||
3069 | char *string; | ||
3070 | int ndigs; | ||
3071 | { | ||
3072 | unsigned short w[NI]; | ||
3073 | |||
3074 | e24toe( x, w ); | ||
3075 | etoasc( w, string, ndigs ); | ||
3076 | } | ||
3077 | |||
3078 | |||
3079 | void e53toasc( x, string, ndigs ) | ||
3080 | unsigned short x[]; | ||
3081 | char *string; | ||
3082 | int ndigs; | ||
3083 | { | ||
3084 | unsigned short w[NI]; | ||
3085 | |||
3086 | e53toe( x, w ); | ||
3087 | etoasc( w, string, ndigs ); | ||
3088 | } | ||
3089 | |||
3090 | |||
3091 | void e64toasc( x, string, ndigs ) | ||
3092 | unsigned short x[]; | ||
3093 | char *string; | ||
3094 | int ndigs; | ||
3095 | { | ||
3096 | unsigned short w[NI]; | ||
3097 | |||
3098 | e64toe( x, w ); | ||
3099 | etoasc( w, string, ndigs ); | ||
3100 | } | ||
3101 | |||
3102 | void e113toasc (x, string, ndigs) | ||
3103 | unsigned short x[]; | ||
3104 | char *string; | ||
3105 | int ndigs; | ||
3106 | { | ||
3107 | unsigned short w[NI]; | ||
3108 | |||
3109 | e113toe (x, w); | ||
3110 | etoasc (w, string, ndigs); | ||
3111 | } | ||
3112 | |||
3113 | |||
3114 | void etoasc( x, string, ndigs ) | ||
3115 | unsigned short x[]; | ||
3116 | char *string; | ||
3117 | int ndigs; | ||
3118 | { | ||
3119 | long digit; | ||
3120 | unsigned short y[NI], t[NI], u[NI], w[NI]; | ||
3121 | unsigned short *p, *r, *ten; | ||
3122 | unsigned short sign; | ||
3123 | int i, j, k, expon, rndsav; | ||
3124 | char *s, *ss; | ||
3125 | unsigned short m; | ||
3126 | |||
3127 | rndsav = rndprc; | ||
3128 | #ifdef NANS | ||
3129 | if( eisnan(x) ) | ||
3130 | { | ||
3131 | sprintf( string, " NaN " ); | ||
3132 | goto bxit; | ||
3133 | } | ||
3134 | #endif | ||
3135 | rndprc = NBITS; /* set to full precision */ | ||
3136 | emov( x, y ); /* retain external format */ | ||
3137 | if( y[NE-1] & 0x8000 ) | ||
3138 | { | ||
3139 | sign = 0xffff; | ||
3140 | y[NE-1] &= 0x7fff; | ||
3141 | } | ||
3142 | else | ||
3143 | { | ||
3144 | sign = 0; | ||
3145 | } | ||
3146 | expon = 0; | ||
3147 | ten = &etens[NTEN][0]; | ||
3148 | emov( eone, t ); | ||
3149 | /* Test for zero exponent */ | ||
3150 | if( y[NE-1] == 0 ) | ||
3151 | { | ||
3152 | for( k=0; k<NE-1; k++ ) | ||
3153 | { | ||
3154 | if( y[k] != 0 ) | ||
3155 | goto tnzro; /* denormalized number */ | ||
3156 | } | ||
3157 | goto isone; /* legal all zeros */ | ||
3158 | } | ||
3159 | tnzro: | ||
3160 | |||
3161 | /* Test for infinity. | ||
3162 | */ | ||
3163 | if( y[NE-1] == 0x7fff ) | ||
3164 | { | ||
3165 | if( sign ) | ||
3166 | sprintf( string, " -Infinity " ); | ||
3167 | else | ||
3168 | sprintf( string, " Infinity " ); | ||
3169 | goto bxit; | ||
3170 | } | ||
3171 | |||
3172 | /* Test for exponent nonzero but significand denormalized. | ||
3173 | * This is an error condition. | ||
3174 | */ | ||
3175 | if( (y[NE-1] != 0) && ((y[NE-2] & 0x8000) == 0) ) | ||
3176 | { | ||
3177 | mtherr( "etoasc", DOMAIN ); | ||
3178 | sprintf( string, "NaN" ); | ||
3179 | goto bxit; | ||
3180 | } | ||
3181 | |||
3182 | /* Compare to 1.0 */ | ||
3183 | i = ecmp( eone, y ); | ||
3184 | if( i == 0 ) | ||
3185 | goto isone; | ||
3186 | |||
3187 | if( i < 0 ) | ||
3188 | { /* Number is greater than 1 */ | ||
3189 | /* Convert significand to an integer and strip trailing decimal zeros. */ | ||
3190 | emov( y, u ); | ||
3191 | u[NE-1] = EXONE + NBITS - 1; | ||
3192 | |||
3193 | p = &etens[NTEN-4][0]; | ||
3194 | m = 16; | ||
3195 | do | ||
3196 | { | ||
3197 | ediv( p, u, t ); | ||
3198 | efloor( t, w ); | ||
3199 | for( j=0; j<NE-1; j++ ) | ||
3200 | { | ||
3201 | if( t[j] != w[j] ) | ||
3202 | goto noint; | ||
3203 | } | ||
3204 | emov( t, u ); | ||
3205 | expon += (int )m; | ||
3206 | noint: | ||
3207 | p += NE; | ||
3208 | m >>= 1; | ||
3209 | } | ||
3210 | while( m != 0 ); | ||
3211 | |||
3212 | /* Rescale from integer significand */ | ||
3213 | u[NE-1] += y[NE-1] - (unsigned int )(EXONE + NBITS - 1); | ||
3214 | emov( u, y ); | ||
3215 | /* Find power of 10 */ | ||
3216 | emov( eone, t ); | ||
3217 | m = MAXP; | ||
3218 | p = &etens[0][0]; | ||
3219 | while( ecmp( ten, u ) <= 0 ) | ||
3220 | { | ||
3221 | if( ecmp( p, u ) <= 0 ) | ||
3222 | { | ||
3223 | ediv( p, u, u ); | ||
3224 | emul( p, t, t ); | ||
3225 | expon += (int )m; | ||
3226 | } | ||
3227 | m >>= 1; | ||
3228 | if( m == 0 ) | ||
3229 | break; | ||
3230 | p += NE; | ||
3231 | } | ||
3232 | } | ||
3233 | else | ||
3234 | { /* Number is less than 1.0 */ | ||
3235 | /* Pad significand with trailing decimal zeros. */ | ||
3236 | if( y[NE-1] == 0 ) | ||
3237 | { | ||
3238 | while( (y[NE-2] & 0x8000) == 0 ) | ||
3239 | { | ||
3240 | emul( ten, y, y ); | ||
3241 | expon -= 1; | ||
3242 | } | ||
3243 | } | ||
3244 | else | ||
3245 | { | ||
3246 | emovi( y, w ); | ||
3247 | for( i=0; i<NDEC+1; i++ ) | ||
3248 | { | ||
3249 | if( (w[NI-1] & 0x7) != 0 ) | ||
3250 | break; | ||
3251 | /* multiply by 10 */ | ||
3252 | emovz( w, u ); | ||
3253 | eshdn1( u ); | ||
3254 | eshdn1( u ); | ||
3255 | eaddm( w, u ); | ||
3256 | u[1] += 3; | ||
3257 | while( u[2] != 0 ) | ||
3258 | { | ||
3259 | eshdn1(u); | ||
3260 | u[1] += 1; | ||
3261 | } | ||
3262 | if( u[NI-1] != 0 ) | ||
3263 | break; | ||
3264 | if( eone[NE-1] <= u[1] ) | ||
3265 | break; | ||
3266 | emovz( u, w ); | ||
3267 | expon -= 1; | ||
3268 | } | ||
3269 | emovo( w, y ); | ||
3270 | } | ||
3271 | k = -MAXP; | ||
3272 | p = &emtens[0][0]; | ||
3273 | r = &etens[0][0]; | ||
3274 | emov( y, w ); | ||
3275 | emov( eone, t ); | ||
3276 | while( ecmp( eone, w ) > 0 ) | ||
3277 | { | ||
3278 | if( ecmp( p, w ) >= 0 ) | ||
3279 | { | ||
3280 | emul( r, w, w ); | ||
3281 | emul( r, t, t ); | ||
3282 | expon += k; | ||
3283 | } | ||
3284 | k /= 2; | ||
3285 | if( k == 0 ) | ||
3286 | break; | ||
3287 | p += NE; | ||
3288 | r += NE; | ||
3289 | } | ||
3290 | ediv( t, eone, t ); | ||
3291 | } | ||
3292 | isone: | ||
3293 | /* Find the first (leading) digit. */ | ||
3294 | emovi( t, w ); | ||
3295 | emovz( w, t ); | ||
3296 | emovi( y, w ); | ||
3297 | emovz( w, y ); | ||
3298 | eiremain( t, y ); | ||
3299 | digit = equot[NI-1]; | ||
3300 | while( (digit == 0) && (ecmp(y,ezero) != 0) ) | ||
3301 | { | ||
3302 | eshup1( y ); | ||
3303 | emovz( y, u ); | ||
3304 | eshup1( u ); | ||
3305 | eshup1( u ); | ||
3306 | eaddm( u, y ); | ||
3307 | eiremain( t, y ); | ||
3308 | digit = equot[NI-1]; | ||
3309 | expon -= 1; | ||
3310 | } | ||
3311 | s = string; | ||
3312 | if( sign ) | ||
3313 | *s++ = '-'; | ||
3314 | else | ||
3315 | *s++ = ' '; | ||
3316 | /* Examine number of digits requested by caller. */ | ||
3317 | if( ndigs < 0 ) | ||
3318 | ndigs = 0; | ||
3319 | if( ndigs > NDEC ) | ||
3320 | ndigs = NDEC; | ||
3321 | if( digit == 10 ) | ||
3322 | { | ||
3323 | *s++ = '1'; | ||
3324 | *s++ = '.'; | ||
3325 | if( ndigs > 0 ) | ||
3326 | { | ||
3327 | *s++ = '0'; | ||
3328 | ndigs -= 1; | ||
3329 | } | ||
3330 | expon += 1; | ||
3331 | } | ||
3332 | else | ||
3333 | { | ||
3334 | *s++ = (char )digit + '0'; | ||
3335 | *s++ = '.'; | ||
3336 | } | ||
3337 | /* Generate digits after the decimal point. */ | ||
3338 | for( k=0; k<=ndigs; k++ ) | ||
3339 | { | ||
3340 | /* multiply current number by 10, without normalizing */ | ||
3341 | eshup1( y ); | ||
3342 | emovz( y, u ); | ||
3343 | eshup1( u ); | ||
3344 | eshup1( u ); | ||
3345 | eaddm( u, y ); | ||
3346 | eiremain( t, y ); | ||
3347 | *s++ = (char )equot[NI-1] + '0'; | ||
3348 | } | ||
3349 | digit = equot[NI-1]; | ||
3350 | --s; | ||
3351 | ss = s; | ||
3352 | /* round off the ASCII string */ | ||
3353 | if( digit > 4 ) | ||
3354 | { | ||
3355 | /* Test for critical rounding case in ASCII output. */ | ||
3356 | if( digit == 5 ) | ||
3357 | { | ||
3358 | emovo( y, t ); | ||
3359 | if( ecmp(t,ezero) != 0 ) | ||
3360 | goto roun; /* round to nearest */ | ||
3361 | if( (*(s-1) & 1) == 0 ) | ||
3362 | goto doexp; /* round to even */ | ||
3363 | } | ||
3364 | /* Round up and propagate carry-outs */ | ||
3365 | roun: | ||
3366 | --s; | ||
3367 | k = *s & 0x7f; | ||
3368 | /* Carry out to most significant digit? */ | ||
3369 | if( k == '.' ) | ||
3370 | { | ||
3371 | --s; | ||
3372 | k = *s; | ||
3373 | k += 1; | ||
3374 | *s = (char )k; | ||
3375 | /* Most significant digit carries to 10? */ | ||
3376 | if( k > '9' ) | ||
3377 | { | ||
3378 | expon += 1; | ||
3379 | *s = '1'; | ||
3380 | } | ||
3381 | goto doexp; | ||
3382 | } | ||
3383 | /* Round up and carry out from less significant digits */ | ||
3384 | k += 1; | ||
3385 | *s = (char )k; | ||
3386 | if( k > '9' ) | ||
3387 | { | ||
3388 | *s = '0'; | ||
3389 | goto roun; | ||
3390 | } | ||
3391 | } | ||
3392 | doexp: | ||
3393 | /* | ||
3394 | if( expon >= 0 ) | ||
3395 | sprintf( ss, "e+%d", expon ); | ||
3396 | else | ||
3397 | sprintf( ss, "e%d", expon ); | ||
3398 | */ | ||
3399 | sprintf( ss, "E%d", expon ); | ||
3400 | bxit: | ||
3401 | rndprc = rndsav; | ||
3402 | } | ||
3403 | |||
3404 | |||
3405 | |||
3406 | |||
3407 | /* | ||
3408 | ; ASCTOQ | ||
3409 | ; ASCTOQ.MAC LATEST REV: 11 JAN 84 | ||
3410 | ; SLM, 3 JAN 78 | ||
3411 | ; | ||
3412 | ; Convert ASCII string to quadruple precision floating point | ||
3413 | ; | ||
3414 | ; Numeric input is free field decimal number | ||
3415 | ; with max of 15 digits with or without | ||
3416 | ; decimal point entered as ASCII from teletype. | ||
3417 | ; Entering E after the number followed by a second | ||
3418 | ; number causes the second number to be interpreted | ||
3419 | ; as a power of 10 to be multiplied by the first number | ||
3420 | ; (i.e., "scientific" notation). | ||
3421 | ; | ||
3422 | ; Usage: | ||
3423 | ; asctoq( string, q ); | ||
3424 | */ | ||
3425 | |||
3426 | /* ASCII to single */ | ||
3427 | void asctoe24( s, y ) | ||
3428 | char *s; | ||
3429 | unsigned short *y; | ||
3430 | { | ||
3431 | asctoeg( s, y, 24 ); | ||
3432 | } | ||
3433 | |||
3434 | |||
3435 | /* ASCII to double */ | ||
3436 | void asctoe53( s, y ) | ||
3437 | char *s; | ||
3438 | unsigned short *y; | ||
3439 | { | ||
3440 | #ifdef DEC | ||
3441 | asctoeg( s, y, 56 ); | ||
3442 | #else | ||
3443 | asctoeg( s, y, 53 ); | ||
3444 | #endif | ||
3445 | } | ||
3446 | |||
3447 | |||
3448 | /* ASCII to long double */ | ||
3449 | void asctoe64( s, y ) | ||
3450 | char *s; | ||
3451 | unsigned short *y; | ||
3452 | { | ||
3453 | asctoeg( s, y, 64 ); | ||
3454 | } | ||
3455 | |||
3456 | /* ASCII to 128-bit long double */ | ||
3457 | void asctoe113 (s, y) | ||
3458 | char *s; | ||
3459 | unsigned short *y; | ||
3460 | { | ||
3461 | asctoeg( s, y, 113 ); | ||
3462 | } | ||
3463 | |||
3464 | /* ASCII to super double */ | ||
3465 | void asctoe( s, y ) | ||
3466 | char *s; | ||
3467 | unsigned short *y; | ||
3468 | { | ||
3469 | asctoeg( s, y, NBITS ); | ||
3470 | } | ||
3471 | |||
3472 | /* Space to make a copy of the input string: */ | ||
3473 | static char lstr[82] = {0}; | ||
3474 | |||
3475 | void asctoeg( ss, y, oprec ) | ||
3476 | char *ss; | ||
3477 | unsigned short *y; | ||
3478 | int oprec; | ||
3479 | { | ||
3480 | unsigned short yy[NI], xt[NI], tt[NI]; | ||
3481 | int esign, decflg, sgnflg, nexp, exp, prec, lost; | ||
3482 | int k, trail, c, rndsav; | ||
3483 | long lexp; | ||
3484 | unsigned short nsign, *p; | ||
3485 | char *sp, *s; | ||
3486 | |||
3487 | /* Copy the input string. */ | ||
3488 | s = ss; | ||
3489 | while( *s == ' ' ) /* skip leading spaces */ | ||
3490 | ++s; | ||
3491 | sp = lstr; | ||
3492 | for( k=0; k<79; k++ ) | ||
3493 | { | ||
3494 | if( (*sp++ = *s++) == '\0' ) | ||
3495 | break; | ||
3496 | } | ||
3497 | *sp = '\0'; | ||
3498 | s = lstr; | ||
3499 | |||
3500 | rndsav = rndprc; | ||
3501 | rndprc = NBITS; /* Set to full precision */ | ||
3502 | lost = 0; | ||
3503 | nsign = 0; | ||
3504 | decflg = 0; | ||
3505 | sgnflg = 0; | ||
3506 | nexp = 0; | ||
3507 | exp = 0; | ||
3508 | prec = 0; | ||
3509 | ecleaz( yy ); | ||
3510 | trail = 0; | ||
3511 | |||
3512 | nxtcom: | ||
3513 | k = *s - '0'; | ||
3514 | if( (k >= 0) && (k <= 9) ) | ||
3515 | { | ||
3516 | /* Ignore leading zeros */ | ||
3517 | if( (prec == 0) && (decflg == 0) && (k == 0) ) | ||
3518 | goto donchr; | ||
3519 | /* Identify and strip trailing zeros after the decimal point. */ | ||
3520 | if( (trail == 0) && (decflg != 0) ) | ||
3521 | { | ||
3522 | sp = s; | ||
3523 | while( (*sp >= '0') && (*sp <= '9') ) | ||
3524 | ++sp; | ||
3525 | /* Check for syntax error */ | ||
3526 | c = *sp & 0x7f; | ||
3527 | if( (c != 'e') && (c != 'E') && (c != '\0') | ||
3528 | && (c != '\n') && (c != '\r') && (c != ' ') | ||
3529 | && (c != ',') ) | ||
3530 | goto error; | ||
3531 | --sp; | ||
3532 | while( *sp == '0' ) | ||
3533 | *sp-- = 'z'; | ||
3534 | trail = 1; | ||
3535 | if( *s == 'z' ) | ||
3536 | goto donchr; | ||
3537 | } | ||
3538 | /* If enough digits were given to more than fill up the yy register, | ||
3539 | * continuing until overflow into the high guard word yy[2] | ||
3540 | * guarantees that there will be a roundoff bit at the top | ||
3541 | * of the low guard word after normalization. | ||
3542 | */ | ||
3543 | if( yy[2] == 0 ) | ||
3544 | { | ||
3545 | if( decflg ) | ||
3546 | nexp += 1; /* count digits after decimal point */ | ||
3547 | eshup1( yy ); /* multiply current number by 10 */ | ||
3548 | emovz( yy, xt ); | ||
3549 | eshup1( xt ); | ||
3550 | eshup1( xt ); | ||
3551 | eaddm( xt, yy ); | ||
3552 | ecleaz( xt ); | ||
3553 | xt[NI-2] = (unsigned short )k; | ||
3554 | eaddm( xt, yy ); | ||
3555 | } | ||
3556 | else | ||
3557 | { | ||
3558 | /* Mark any lost non-zero digit. */ | ||
3559 | lost |= k; | ||
3560 | /* Count lost digits before the decimal point. */ | ||
3561 | if (decflg == 0) | ||
3562 | nexp -= 1; | ||
3563 | } | ||
3564 | prec += 1; | ||
3565 | goto donchr; | ||
3566 | } | ||
3567 | |||
3568 | switch( *s ) | ||
3569 | { | ||
3570 | case 'z': | ||
3571 | break; | ||
3572 | case 'E': | ||
3573 | case 'e': | ||
3574 | goto expnt; | ||
3575 | case '.': /* decimal point */ | ||
3576 | if( decflg ) | ||
3577 | goto error; | ||
3578 | ++decflg; | ||
3579 | break; | ||
3580 | case '-': | ||
3581 | nsign = 0xffff; | ||
3582 | if( sgnflg ) | ||
3583 | goto error; | ||
3584 | ++sgnflg; | ||
3585 | break; | ||
3586 | case '+': | ||
3587 | if( sgnflg ) | ||
3588 | goto error; | ||
3589 | ++sgnflg; | ||
3590 | break; | ||
3591 | case ',': | ||
3592 | case ' ': | ||
3593 | case '\0': | ||
3594 | case '\n': | ||
3595 | case '\r': | ||
3596 | goto daldone; | ||
3597 | case 'i': | ||
3598 | case 'I': | ||
3599 | goto infinite; | ||
3600 | default: | ||
3601 | error: | ||
3602 | #ifdef NANS | ||
3603 | enan( yy, NI*16 ); | ||
3604 | #else | ||
3605 | mtherr( "asctoe", DOMAIN ); | ||
3606 | ecleaz(yy); | ||
3607 | #endif | ||
3608 | goto aexit; | ||
3609 | } | ||
3610 | donchr: | ||
3611 | ++s; | ||
3612 | goto nxtcom; | ||
3613 | |||
3614 | /* Exponent interpretation */ | ||
3615 | expnt: | ||
3616 | |||
3617 | esign = 1; | ||
3618 | exp = 0; | ||
3619 | ++s; | ||
3620 | /* check for + or - */ | ||
3621 | if( *s == '-' ) | ||
3622 | { | ||
3623 | esign = -1; | ||
3624 | ++s; | ||
3625 | } | ||
3626 | if( *s == '+' ) | ||
3627 | ++s; | ||
3628 | while( (*s >= '0') && (*s <= '9') ) | ||
3629 | { | ||
3630 | exp *= 10; | ||
3631 | exp += *s++ - '0'; | ||
3632 | if (exp > 4977) | ||
3633 | { | ||
3634 | if (esign < 0) | ||
3635 | goto zero; | ||
3636 | else | ||
3637 | goto infinite; | ||
3638 | } | ||
3639 | } | ||
3640 | if( esign < 0 ) | ||
3641 | exp = -exp; | ||
3642 | if( exp > 4932 ) | ||
3643 | { | ||
3644 | infinite: | ||
3645 | ecleaz(yy); | ||
3646 | yy[E] = 0x7fff; /* infinity */ | ||
3647 | goto aexit; | ||
3648 | } | ||
3649 | if( exp < -4977 ) | ||
3650 | { | ||
3651 | zero: | ||
3652 | ecleaz(yy); | ||
3653 | goto aexit; | ||
3654 | } | ||
3655 | |||
3656 | daldone: | ||
3657 | nexp = exp - nexp; | ||
3658 | /* Pad trailing zeros to minimize power of 10, per IEEE spec. */ | ||
3659 | while( (nexp > 0) && (yy[2] == 0) ) | ||
3660 | { | ||
3661 | emovz( yy, xt ); | ||
3662 | eshup1( xt ); | ||
3663 | eshup1( xt ); | ||
3664 | eaddm( yy, xt ); | ||
3665 | eshup1( xt ); | ||
3666 | if( xt[2] != 0 ) | ||
3667 | break; | ||
3668 | nexp -= 1; | ||
3669 | emovz( xt, yy ); | ||
3670 | } | ||
3671 | if( (k = enormlz(yy)) > NBITS ) | ||
3672 | { | ||
3673 | ecleaz(yy); | ||
3674 | goto aexit; | ||
3675 | } | ||
3676 | lexp = (EXONE - 1 + NBITS) - k; | ||
3677 | emdnorm( yy, lost, 0, lexp, 64 ); | ||
3678 | /* convert to external format */ | ||
3679 | |||
3680 | |||
3681 | /* Multiply by 10**nexp. If precision is 64 bits, | ||
3682 | * the maximum relative error incurred in forming 10**n | ||
3683 | * for 0 <= n <= 324 is 8.2e-20, at 10**180. | ||
3684 | * For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947. | ||
3685 | * For 0 >= n >= -999, it is -1.55e-19 at 10**-435. | ||
3686 | */ | ||
3687 | lexp = yy[E]; | ||
3688 | if( nexp == 0 ) | ||
3689 | { | ||
3690 | k = 0; | ||
3691 | goto expdon; | ||
3692 | } | ||
3693 | esign = 1; | ||
3694 | if( nexp < 0 ) | ||
3695 | { | ||
3696 | nexp = -nexp; | ||
3697 | esign = -1; | ||
3698 | if( nexp > 4096 ) | ||
3699 | { /* Punt. Can't handle this without 2 divides. */ | ||
3700 | emovi( etens[0], tt ); | ||
3701 | lexp -= tt[E]; | ||
3702 | k = edivm( tt, yy ); | ||
3703 | lexp += EXONE; | ||
3704 | nexp -= 4096; | ||
3705 | } | ||
3706 | } | ||
3707 | p = &etens[NTEN][0]; | ||
3708 | emov( eone, xt ); | ||
3709 | exp = 1; | ||
3710 | do | ||
3711 | { | ||
3712 | if( exp & nexp ) | ||
3713 | emul( p, xt, xt ); | ||
3714 | p -= NE; | ||
3715 | exp = exp + exp; | ||
3716 | } | ||
3717 | while( exp <= MAXP ); | ||
3718 | |||
3719 | emovi( xt, tt ); | ||
3720 | if( esign < 0 ) | ||
3721 | { | ||
3722 | lexp -= tt[E]; | ||
3723 | k = edivm( tt, yy ); | ||
3724 | lexp += EXONE; | ||
3725 | } | ||
3726 | else | ||
3727 | { | ||
3728 | lexp += tt[E]; | ||
3729 | k = emulm( tt, yy ); | ||
3730 | lexp -= EXONE - 1; | ||
3731 | } | ||
3732 | |||
3733 | expdon: | ||
3734 | |||
3735 | /* Round and convert directly to the destination type */ | ||
3736 | if( oprec == 53 ) | ||
3737 | lexp -= EXONE - 0x3ff; | ||
3738 | else if( oprec == 24 ) | ||
3739 | lexp -= EXONE - 0177; | ||
3740 | #ifdef DEC | ||
3741 | else if( oprec == 56 ) | ||
3742 | lexp -= EXONE - 0201; | ||
3743 | #endif | ||
3744 | rndprc = oprec; | ||
3745 | emdnorm( yy, k, 0, lexp, 64 ); | ||
3746 | |||
3747 | aexit: | ||
3748 | |||
3749 | rndprc = rndsav; | ||
3750 | yy[0] = nsign; | ||
3751 | switch( oprec ) | ||
3752 | { | ||
3753 | #ifdef DEC | ||
3754 | case 56: | ||
3755 | todec( yy, y ); /* see etodec.c */ | ||
3756 | break; | ||
3757 | #endif | ||
3758 | case 53: | ||
3759 | toe53( yy, y ); | ||
3760 | break; | ||
3761 | case 24: | ||
3762 | toe24( yy, y ); | ||
3763 | break; | ||
3764 | case 64: | ||
3765 | toe64( yy, y ); | ||
3766 | break; | ||
3767 | case 113: | ||
3768 | toe113( yy, y ); | ||
3769 | break; | ||
3770 | case NBITS: | ||
3771 | emovo( yy, y ); | ||
3772 | break; | ||
3773 | } | ||
3774 | } | ||
3775 | |||
3776 | |||
3777 | |||
3778 | /* y = largest integer not greater than x | ||
3779 | * (truncated toward minus infinity) | ||
3780 | * | ||
3781 | * unsigned short x[NE], y[NE] | ||
3782 | * | ||
3783 | * efloor( x, y ); | ||
3784 | */ | ||
3785 | static unsigned short bmask[] = { | ||
3786 | 0xffff, | ||
3787 | 0xfffe, | ||
3788 | 0xfffc, | ||
3789 | 0xfff8, | ||
3790 | 0xfff0, | ||
3791 | 0xffe0, | ||
3792 | 0xffc0, | ||
3793 | 0xff80, | ||
3794 | 0xff00, | ||
3795 | 0xfe00, | ||
3796 | 0xfc00, | ||
3797 | 0xf800, | ||
3798 | 0xf000, | ||
3799 | 0xe000, | ||
3800 | 0xc000, | ||
3801 | 0x8000, | ||
3802 | 0x0000, | ||
3803 | }; | ||
3804 | |||
3805 | void efloor( x, y ) | ||
3806 | unsigned short x[], y[]; | ||
3807 | { | ||
3808 | register unsigned short *p; | ||
3809 | int e, expon, i; | ||
3810 | unsigned short f[NE]; | ||
3811 | |||
3812 | emov( x, f ); /* leave in external format */ | ||
3813 | expon = (int )f[NE-1]; | ||
3814 | e = (expon & 0x7fff) - (EXONE - 1); | ||
3815 | if( e <= 0 ) | ||
3816 | { | ||
3817 | eclear(y); | ||
3818 | goto isitneg; | ||
3819 | } | ||
3820 | /* number of bits to clear out */ | ||
3821 | e = NBITS - e; | ||
3822 | emov( f, y ); | ||
3823 | if( e <= 0 ) | ||
3824 | return; | ||
3825 | |||
3826 | p = &y[0]; | ||
3827 | while( e >= 16 ) | ||
3828 | { | ||
3829 | *p++ = 0; | ||
3830 | e -= 16; | ||
3831 | } | ||
3832 | /* clear the remaining bits */ | ||
3833 | *p &= bmask[e]; | ||
3834 | /* truncate negatives toward minus infinity */ | ||
3835 | isitneg: | ||
3836 | |||
3837 | if( (unsigned short )expon & (unsigned short )0x8000 ) | ||
3838 | { | ||
3839 | for( i=0; i<NE-1; i++ ) | ||
3840 | { | ||
3841 | if( f[i] != y[i] ) | ||
3842 | { | ||
3843 | esub( eone, y, y ); | ||
3844 | break; | ||
3845 | } | ||
3846 | } | ||
3847 | } | ||
3848 | } | ||
3849 | |||
3850 | |||
3851 | /* unsigned short x[], s[]; | ||
3852 | * long *exp; | ||
3853 | * | ||
3854 | * efrexp( x, exp, s ); | ||
3855 | * | ||
3856 | * Returns s and exp such that s * 2**exp = x and .5 <= s < 1. | ||
3857 | * For example, 1.1 = 0.55 * 2**1 | ||
3858 | * Handles denormalized numbers properly using long integer exp. | ||
3859 | */ | ||
3860 | void efrexp( x, exp, s ) | ||
3861 | unsigned short x[]; | ||
3862 | long *exp; | ||
3863 | unsigned short s[]; | ||
3864 | { | ||
3865 | unsigned short xi[NI]; | ||
3866 | long li; | ||
3867 | |||
3868 | emovi( x, xi ); | ||
3869 | li = (long )((short )xi[1]); | ||
3870 | |||
3871 | if( li == 0 ) | ||
3872 | { | ||
3873 | li -= enormlz( xi ); | ||
3874 | } | ||
3875 | xi[1] = 0x3ffe; | ||
3876 | emovo( xi, s ); | ||
3877 | *exp = li - 0x3ffe; | ||
3878 | } | ||
3879 | |||
3880 | |||
3881 | |||
3882 | /* unsigned short x[], y[]; | ||
3883 | * long pwr2; | ||
3884 | * | ||
3885 | * eldexp( x, pwr2, y ); | ||
3886 | * | ||
3887 | * Returns y = x * 2**pwr2. | ||
3888 | */ | ||
3889 | void eldexp( x, pwr2, y ) | ||
3890 | unsigned short x[]; | ||
3891 | long pwr2; | ||
3892 | unsigned short y[]; | ||
3893 | { | ||
3894 | unsigned short xi[NI]; | ||
3895 | long li; | ||
3896 | int i; | ||
3897 | |||
3898 | emovi( x, xi ); | ||
3899 | li = xi[1]; | ||
3900 | li += pwr2; | ||
3901 | i = 0; | ||
3902 | emdnorm( xi, i, i, li, 64 ); | ||
3903 | emovo( xi, y ); | ||
3904 | } | ||
3905 | |||
3906 | |||
3907 | /* c = remainder after dividing b by a | ||
3908 | * Least significant integer quotient bits left in equot[]. | ||
3909 | */ | ||
3910 | void eremain( a, b, c ) | ||
3911 | unsigned short a[], b[], c[]; | ||
3912 | { | ||
3913 | unsigned short den[NI], num[NI]; | ||
3914 | |||
3915 | #ifdef NANS | ||
3916 | if( eisinf(b) || (ecmp(a,ezero) == 0) || eisnan(a) || eisnan(b)) | ||
3917 | { | ||
3918 | enan( c, NBITS ); | ||
3919 | return; | ||
3920 | } | ||
3921 | #endif | ||
3922 | if( ecmp(a,ezero) == 0 ) | ||
3923 | { | ||
3924 | mtherr( "eremain", SING ); | ||
3925 | eclear( c ); | ||
3926 | return; | ||
3927 | } | ||
3928 | emovi( a, den ); | ||
3929 | emovi( b, num ); | ||
3930 | eiremain( den, num ); | ||
3931 | /* Sign of remainder = sign of quotient */ | ||
3932 | if( a[0] == b[0] ) | ||
3933 | num[0] = 0; | ||
3934 | else | ||
3935 | num[0] = 0xffff; | ||
3936 | emovo( num, c ); | ||
3937 | } | ||
3938 | |||
3939 | |||
3940 | void eiremain( den, num ) | ||
3941 | unsigned short den[], num[]; | ||
3942 | { | ||
3943 | long ld, ln; | ||
3944 | unsigned short j; | ||
3945 | |||
3946 | ld = den[E]; | ||
3947 | ld -= enormlz( den ); | ||
3948 | ln = num[E]; | ||
3949 | ln -= enormlz( num ); | ||
3950 | ecleaz( equot ); | ||
3951 | while( ln >= ld ) | ||
3952 | { | ||
3953 | if( ecmpm(den,num) <= 0 ) | ||
3954 | { | ||
3955 | esubm(den, num); | ||
3956 | j = 1; | ||
3957 | } | ||
3958 | else | ||
3959 | { | ||
3960 | j = 0; | ||
3961 | } | ||
3962 | eshup1(equot); | ||
3963 | equot[NI-1] |= j; | ||
3964 | eshup1(num); | ||
3965 | ln -= 1; | ||
3966 | } | ||
3967 | emdnorm( num, 0, 0, ln, 0 ); | ||
3968 | } | ||
3969 | |||
3970 | /* NaN bit patterns | ||
3971 | */ | ||
3972 | #ifdef MIEEE | ||
3973 | unsigned short nan113[8] = { | ||
3974 | 0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}; | ||
3975 | unsigned short nan64[6] = {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}; | ||
3976 | unsigned short nan53[4] = {0x7fff, 0xffff, 0xffff, 0xffff}; | ||
3977 | unsigned short nan24[2] = {0x7fff, 0xffff}; | ||
3978 | #endif | ||
3979 | |||
3980 | #ifdef IBMPC | ||
3981 | unsigned short nan113[8] = {0, 0, 0, 0, 0, 0, 0xc000, 0xffff}; | ||
3982 | unsigned short nan64[6] = {0, 0, 0, 0xc000, 0xffff, 0}; | ||
3983 | unsigned short nan53[4] = {0, 0, 0, 0xfff8}; | ||
3984 | unsigned short nan24[2] = {0, 0xffc0}; | ||
3985 | #endif | ||
3986 | |||
3987 | |||
3988 | void enan (nan, size) | ||
3989 | unsigned short *nan; | ||
3990 | int size; | ||
3991 | { | ||
3992 | int i, n; | ||
3993 | unsigned short *p; | ||
3994 | |||
3995 | switch( size ) | ||
3996 | { | ||
3997 | #ifndef DEC | ||
3998 | case 113: | ||
3999 | n = 8; | ||
4000 | p = nan113; | ||
4001 | break; | ||
4002 | |||
4003 | case 64: | ||
4004 | n = 6; | ||
4005 | p = nan64; | ||
4006 | break; | ||
4007 | |||
4008 | case 53: | ||
4009 | n = 4; | ||
4010 | p = nan53; | ||
4011 | break; | ||
4012 | |||
4013 | case 24: | ||
4014 | n = 2; | ||
4015 | p = nan24; | ||
4016 | break; | ||
4017 | |||
4018 | case NBITS: | ||
4019 | for( i=0; i<NE-2; i++ ) | ||
4020 | *nan++ = 0; | ||
4021 | *nan++ = 0xc000; | ||
4022 | *nan++ = 0x7fff; | ||
4023 | return; | ||
4024 | |||
4025 | case NI*16: | ||
4026 | *nan++ = 0; | ||
4027 | *nan++ = 0x7fff; | ||
4028 | *nan++ = 0; | ||
4029 | *nan++ = 0xc000; | ||
4030 | for( i=4; i<NI; i++ ) | ||
4031 | *nan++ = 0; | ||
4032 | return; | ||
4033 | #endif | ||
4034 | default: | ||
4035 | mtherr( "enan", DOMAIN ); | ||
4036 | return; | ||
4037 | } | ||
4038 | for (i=0; i < n; i++) | ||
4039 | *nan++ = *p++; | ||
4040 | } | ||
4041 | |||
4042 | |||
4043 | |||
4044 | /* Longhand square root. */ | ||
4045 | |||
4046 | static int esqinited = 0; | ||
4047 | static unsigned short sqrndbit[NI]; | ||
4048 | |||
4049 | void esqrt( x, y ) | ||
4050 | short *x, *y; | ||
4051 | { | ||
4052 | unsigned short temp[NI], num[NI], sq[NI], xx[NI]; | ||
4053 | int i, j, k, n, nlups; | ||
4054 | long m, exp; | ||
4055 | |||
4056 | if( esqinited == 0 ) | ||
4057 | { | ||
4058 | ecleaz( sqrndbit ); | ||
4059 | sqrndbit[NI-2] = 1; | ||
4060 | esqinited = 1; | ||
4061 | } | ||
4062 | /* Check for arg <= 0 */ | ||
4063 | i = ecmp( x, ezero ); | ||
4064 | if( i <= 0 ) | ||
4065 | { | ||
4066 | #ifdef NANS | ||
4067 | if (i == -2) | ||
4068 | { | ||
4069 | enan (y, NBITS); | ||
4070 | return; | ||
4071 | } | ||
4072 | #endif | ||
4073 | eclear(y); | ||
4074 | if( i < 0 ) | ||
4075 | mtherr( "esqrt", DOMAIN ); | ||
4076 | return; | ||
4077 | } | ||
4078 | |||
4079 | #ifdef INFINITY | ||
4080 | if( eisinf(x) ) | ||
4081 | { | ||
4082 | eclear(y); | ||
4083 | einfin(y); | ||
4084 | return; | ||
4085 | } | ||
4086 | #endif | ||
4087 | /* Bring in the arg and renormalize if it is denormal. */ | ||
4088 | emovi( x, xx ); | ||
4089 | m = (long )xx[1]; /* local long word exponent */ | ||
4090 | if( m == 0 ) | ||
4091 | m -= enormlz( xx ); | ||
4092 | |||
4093 | /* Divide exponent by 2 */ | ||
4094 | m -= 0x3ffe; | ||
4095 | exp = (unsigned short )( (m / 2) + 0x3ffe ); | ||
4096 | |||
4097 | /* Adjust if exponent odd */ | ||
4098 | if( (m & 1) != 0 ) | ||
4099 | { | ||
4100 | if( m > 0 ) | ||
4101 | exp += 1; | ||
4102 | eshdn1( xx ); | ||
4103 | } | ||
4104 | |||
4105 | ecleaz( sq ); | ||
4106 | ecleaz( num ); | ||
4107 | n = 8; /* get 8 bits of result per inner loop */ | ||
4108 | nlups = rndprc; | ||
4109 | j = 0; | ||
4110 | |||
4111 | while( nlups > 0 ) | ||
4112 | { | ||
4113 | /* bring in next word of arg */ | ||
4114 | if( j < NE ) | ||
4115 | num[NI-1] = xx[j+3]; | ||
4116 | /* Do additional bit on last outer loop, for roundoff. */ | ||
4117 | if( nlups <= 8 ) | ||
4118 | n = nlups + 1; | ||
4119 | for( i=0; i<n; i++ ) | ||
4120 | { | ||
4121 | /* Next 2 bits of arg */ | ||
4122 | eshup1( num ); | ||
4123 | eshup1( num ); | ||
4124 | /* Shift up answer */ | ||
4125 | eshup1( sq ); | ||
4126 | /* Make trial divisor */ | ||
4127 | for( k=0; k<NI; k++ ) | ||
4128 | temp[k] = sq[k]; | ||
4129 | eshup1( temp ); | ||
4130 | eaddm( sqrndbit, temp ); | ||
4131 | /* Subtract and insert answer bit if it goes in */ | ||
4132 | if( ecmpm( temp, num ) <= 0 ) | ||
4133 | { | ||
4134 | esubm( temp, num ); | ||
4135 | sq[NI-2] |= 1; | ||
4136 | } | ||
4137 | } | ||
4138 | nlups -= n; | ||
4139 | j += 1; | ||
4140 | } | ||
4141 | |||
4142 | /* Adjust for extra, roundoff loop done. */ | ||
4143 | exp += (NBITS - 1) - rndprc; | ||
4144 | |||
4145 | /* Sticky bit = 1 if the remainder is nonzero. */ | ||
4146 | k = 0; | ||
4147 | for( i=3; i<NI; i++ ) | ||
4148 | k |= (int )num[i]; | ||
4149 | |||
4150 | /* Renormalize and round off. */ | ||
4151 | emdnorm( sq, k, 0, exp, 64 ); | ||
4152 | emovo( sq, y ); | ||
4153 | } | ||
diff --git a/src/regress/lib/libc/cephes/ieetst.c b/src/regress/lib/libc/cephes/ieetst.c deleted file mode 100644 index 974fb65c13..0000000000 --- a/src/regress/lib/libc/cephes/ieetst.c +++ /dev/null | |||
@@ -1,881 +0,0 @@ | |||
1 | /* $OpenBSD: ieetst.c,v 1.3 2017/07/27 15:08:37 bluhm Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* Floating point to ASCII input and output string test program. | ||
20 | * | ||
21 | * Numbers in the native machine data structure are converted | ||
22 | * to e type, then to and from decimal ASCII strings. Native | ||
23 | * printf() and scanf() functions are also used to produce | ||
24 | * and read strings. The resulting e type binary values | ||
25 | * are compared, with diagnostic printouts of any discrepancies. | ||
26 | * | ||
27 | * Steve Moshier, 16 Dec 88 | ||
28 | * last revision: 16 May 92 | ||
29 | */ | ||
30 | |||
31 | #include <float.h> | ||
32 | #include <stdio.h> | ||
33 | |||
34 | #include "mconf.h" | ||
35 | #include "ehead.h" | ||
36 | |||
37 | /* Include tests of 80-bit long double precision: */ | ||
38 | #if LDBL_MANT_DIG == 64 | ||
39 | #define LDOUBLE 1 | ||
40 | #else /* LDBL_MANT_DIG == 64 */ | ||
41 | #define LDOUBLE 0 | ||
42 | #endif /* LDBL_MANT_DIG == 64 */ | ||
43 | /* Abort subtest after getting this many errors: */ | ||
44 | #define MAXERR 5 | ||
45 | /* Number of random arguments to try (set as large as you have | ||
46 | * patience for): */ | ||
47 | #define NRAND 100 | ||
48 | /* Perform internal consistency test: */ | ||
49 | #define CHKINTERNAL 0 | ||
50 | |||
51 | static unsigned short fullp[NE], rounded[NE]; | ||
52 | float prec24, sprec24, ssprec24; | ||
53 | double prec53, sprec53, ssprec53; | ||
54 | #if LDOUBLE | ||
55 | long double prec64, sprec64, ssprec64; | ||
56 | #endif | ||
57 | |||
58 | static unsigned short rprint[NE], rscan[NE]; | ||
59 | static unsigned short q1[NE], q2[NE], q5[NE]; | ||
60 | static unsigned short e1[NE], e2[NE], e3[NE]; | ||
61 | static double d1, d2; | ||
62 | static int errprint = 0; | ||
63 | static int errscan = 0; | ||
64 | static int identerr = 0; | ||
65 | static int errtot = 0; | ||
66 | static int count = 0; | ||
67 | static char str0[80], str1[80], str2[80], str3[80]; | ||
68 | static unsigned short eten[NE], maxm[NE]; | ||
69 | |||
70 | int m, n, k2, mprec, SPREC; | ||
71 | |||
72 | char *Ten = "10.0"; | ||
73 | char tformat[10]; | ||
74 | char *format24 = "%.8e"; | ||
75 | #ifdef DEC | ||
76 | char *format53 = "%.17e"; | ||
77 | #else | ||
78 | char *format53 = "%.16e"; | ||
79 | #endif | ||
80 | char *fformat24 = "%e"; | ||
81 | char *fformat53 = "%le"; | ||
82 | char *pct = "%"; | ||
83 | char *quo = "\042"; | ||
84 | #if LDOUBLE | ||
85 | char *format64 = "%.20Le"; | ||
86 | char *fformat64 = "%Le"; | ||
87 | #endif | ||
88 | char *format; | ||
89 | char *fformat; | ||
90 | char *toomany = "Too many errors; aborting this test.\n"; | ||
91 | |||
92 | static int mnrflag; | ||
93 | static int etrflag; | ||
94 | void chkit(), printerr(), mnrand(), etrand(), shownoncrit(); | ||
95 | void chkid(), pvec(); | ||
96 | |||
97 | int | ||
98 | main() | ||
99 | { | ||
100 | int i, iprec, retval = 0; | ||
101 | |||
102 | printf( "Steve Moshier's printf/scanf tester, version 0.2.\n\n" ); | ||
103 | #ifdef DEC | ||
104 | /* DEC PDP-11/VAX single precision not yet implemented */ | ||
105 | for( iprec = 1; iprec<2; iprec++ ) | ||
106 | #else | ||
107 | for( iprec = 0; iprec<3; iprec++ ) | ||
108 | /*for( iprec = 2; iprec<3; iprec++ )*/ | ||
109 | #endif | ||
110 | { | ||
111 | errscan = 0; | ||
112 | identerr = 0; | ||
113 | errprint = 0; | ||
114 | eclear( rprint ); | ||
115 | eclear( rscan ); | ||
116 | |||
117 | switch( iprec ) | ||
118 | { | ||
119 | case 0: | ||
120 | SPREC = 8; /* # digits after the decimal point */ | ||
121 | mprec = 24; /* # bits in the significand */ | ||
122 | m = 9; /* max # decimal digits for correct rounding */ | ||
123 | n = 13; /* max power of ten for correct rounding */ | ||
124 | k2 = -125; /* underflow beyond 2^-k2 */ | ||
125 | format = format24; /* printf format string */ | ||
126 | fformat = fformat24; /* scanf format string */ | ||
127 | mnrflag = 1; /* sets interval for random numbers */ | ||
128 | etrflag = 1; | ||
129 | printf( "Testing FLOAT precision.\n" ); | ||
130 | break; | ||
131 | |||
132 | case 1: | ||
133 | #ifdef DEC | ||
134 | SPREC = 17; | ||
135 | mprec = 56; | ||
136 | m = 17; | ||
137 | n = 27; | ||
138 | k2 = -125; | ||
139 | format = format53; | ||
140 | fformat = fformat53; | ||
141 | mnrflag = 2; | ||
142 | etrflag = 1; | ||
143 | printf( "Testing DEC DOUBLE precision.\n" ); | ||
144 | break; | ||
145 | #else | ||
146 | SPREC = 16; | ||
147 | mprec = 53; | ||
148 | m = 17; | ||
149 | n = 27; | ||
150 | k2 = -1021; | ||
151 | format = format53; | ||
152 | fformat = fformat53; | ||
153 | mnrflag = 2; | ||
154 | etrflag = 2; | ||
155 | printf( "Testing DOUBLE precision.\n" ); | ||
156 | break; | ||
157 | #endif | ||
158 | case 2: | ||
159 | #if LDOUBLE | ||
160 | SPREC = 20; | ||
161 | mprec = 64; | ||
162 | m = 20; | ||
163 | n = 34; | ||
164 | k2 = -16382; | ||
165 | format = format64; | ||
166 | fformat = fformat64; | ||
167 | mnrflag = 3; | ||
168 | etrflag = 3; | ||
169 | printf( "Testing LONG DOUBLE precision.\n" ); | ||
170 | break; | ||
171 | #else | ||
172 | goto nodenorm; | ||
173 | #endif | ||
174 | } | ||
175 | |||
176 | asctoe( Ten, eten ); | ||
177 | /* 10^m - 1 */ | ||
178 | d2 = m; | ||
179 | e53toe( &d2, e1 ); | ||
180 | epow( eten, e1, maxm ); | ||
181 | esub( eone, maxm, maxm ); | ||
182 | |||
183 | /* test 1 */ | ||
184 | printf( "1. Checking 10^n - 1 for n = %d to %d.\n", -m, m ); | ||
185 | emov( eone, q5 ); | ||
186 | for( count=0; count<=m; count++ ) | ||
187 | { | ||
188 | esub( eone, q5, fullp ); | ||
189 | chkit( 1 ); | ||
190 | ediv( q5, eone, q2 ); | ||
191 | esub( eone, q2, fullp ); | ||
192 | chkit( 1 ); | ||
193 | emul( eten, q5, q5 ); | ||
194 | if( errtot >= MAXERR ) | ||
195 | { | ||
196 | printf( "%s", toomany ); | ||
197 | goto end1; | ||
198 | } | ||
199 | } | ||
200 | end1: | ||
201 | printerr(); | ||
202 | |||
203 | |||
204 | /* test 2 */ | ||
205 | printf( "2. Checking powers of 10 from 10^-%d to 10^%d.\n", n, n ); | ||
206 | emov( eone, q5 ); | ||
207 | for( count=0; count<=n; count++ ) | ||
208 | { | ||
209 | emov( q5, fullp ); | ||
210 | chkit( 2 ); | ||
211 | ediv( q5, eone, fullp ); | ||
212 | chkit( 2 ); | ||
213 | emul( eten, q5, q5 ); | ||
214 | if( errtot >= MAXERR ) | ||
215 | { | ||
216 | printf( "%s", toomany ); | ||
217 | goto end2; | ||
218 | } | ||
219 | } | ||
220 | end2: | ||
221 | printerr(); | ||
222 | |||
223 | /* test 3 */ | ||
224 | printf( "3. Checking (10^%d-1)*10^n from n = -%d to %d.\n", m, n, n ); | ||
225 | emov( eone, q5 ); | ||
226 | for( count= -n; count<=n; count++ ) | ||
227 | { | ||
228 | emul( maxm, q5, fullp ); | ||
229 | chkit( 3 ); | ||
230 | emov( q5, fullp ); | ||
231 | ediv( fullp, eone, fullp ); | ||
232 | emul( maxm, fullp, fullp ); | ||
233 | chkit( 3 ); | ||
234 | emul( eten, q5, q5 ); | ||
235 | if( errtot >= MAXERR ) | ||
236 | { | ||
237 | printf( "%s", toomany ); | ||
238 | goto end3; | ||
239 | } | ||
240 | } | ||
241 | end3: | ||
242 | printerr(); | ||
243 | |||
244 | |||
245 | |||
246 | /* test 4 */ | ||
247 | printf( "4. Checking powers of 2 from 2^-24 to 2^+56.\n" ); | ||
248 | d1 = -24.0; | ||
249 | e53toe( &d1, q1 ); | ||
250 | epow( etwo, q1, q5 ); | ||
251 | |||
252 | for( count = -24; count <= 56; count++ ) | ||
253 | { | ||
254 | emov( q5, fullp ); | ||
255 | chkit( 4 ); | ||
256 | emul( etwo, q5, q5 ); | ||
257 | if( errtot >= MAXERR ) | ||
258 | { | ||
259 | printf( "%s", toomany ); | ||
260 | goto end4; | ||
261 | } | ||
262 | } | ||
263 | end4: | ||
264 | printerr(); | ||
265 | |||
266 | |||
267 | /* test 5 */ | ||
268 | printf( "5. Checking 2^n - 1 for n = 0 to %d.\n", mprec ); | ||
269 | emov( eone, q5 ); | ||
270 | for( count=0; count<=mprec; count++ ) | ||
271 | { | ||
272 | esub( eone, q5, fullp ); | ||
273 | chkit( 5 ); | ||
274 | emul( etwo, q5, q5 ); | ||
275 | if( errtot >= MAXERR ) | ||
276 | { | ||
277 | printf( "%s", toomany ); | ||
278 | goto end5; | ||
279 | } | ||
280 | } | ||
281 | end5: | ||
282 | printerr(); | ||
283 | |||
284 | /* test 6 */ | ||
285 | printf( "6. Checking 2^n + 1 for n = 0 to %d.\n", mprec ); | ||
286 | emov( eone, q5 ); | ||
287 | for( count=0; count<=mprec; count++ ) | ||
288 | { | ||
289 | eadd( eone, q5, fullp ); | ||
290 | chkit( 6 ); | ||
291 | emul( etwo, q5, q5 ); | ||
292 | if( errtot >= MAXERR ) | ||
293 | { | ||
294 | printf( "%s", toomany ); | ||
295 | goto end6; | ||
296 | } | ||
297 | } | ||
298 | end6: | ||
299 | printerr(); | ||
300 | |||
301 | /* test 7 */ | ||
302 | printf( | ||
303 | "7. Checking %d values M * 10^N with random integer M and N,\n", | ||
304 | NRAND ); | ||
305 | printf(" 1 <= M <= 10^%d - 1 and -%d <= N <= +%d.\n", m, n, n ); | ||
306 | for( i=0; i<NRAND; i++ ) | ||
307 | { | ||
308 | mnrand( fullp ); | ||
309 | chkit( 7 ); | ||
310 | if( errtot >= MAXERR ) | ||
311 | { | ||
312 | printf( "%s", toomany ); | ||
313 | goto end7; | ||
314 | } | ||
315 | } | ||
316 | end7: | ||
317 | printerr(); | ||
318 | |||
319 | /* test 8 */ | ||
320 | printf("8. Checking critical rounding cases.\n" ); | ||
321 | for( i=0; i<20; i++ ) | ||
322 | { | ||
323 | mnrand( fullp ); | ||
324 | eabs( fullp ); | ||
325 | if( ecmp( fullp, eone ) < 0 ) | ||
326 | ediv( fullp, eone, fullp ); | ||
327 | efloor( fullp, fullp ); | ||
328 | eadd( ehalf, fullp, fullp ); | ||
329 | chkit( 8 ); | ||
330 | if( errtot >= MAXERR ) | ||
331 | { | ||
332 | printf( "%s", toomany ); | ||
333 | goto end8; | ||
334 | } | ||
335 | } | ||
336 | end8: | ||
337 | printerr(); | ||
338 | |||
339 | |||
340 | |||
341 | /* test 9 */ | ||
342 | printf("9. Testing on %d random non-denormal values.\n", NRAND ); | ||
343 | for( i=0; i<NRAND; i++ ) | ||
344 | { | ||
345 | etrand( fullp ); | ||
346 | chkit( 9 ); | ||
347 | } | ||
348 | printerr(); | ||
349 | shownoncrit(); | ||
350 | |||
351 | /* test 10 */ | ||
352 | #if 0 | ||
353 | printf( | ||
354 | "Do you want to check denormal numbers in this precision ? (y/n) " ); | ||
355 | gets( str0 ); | ||
356 | if( str0[0] != 'y' ) | ||
357 | goto nodenorm; | ||
358 | #endif | ||
359 | |||
360 | printf( "10. Checking denormal numbers.\n" ); | ||
361 | |||
362 | /* Form 2^-starting power */ | ||
363 | d1 = k2; | ||
364 | e53toe( &d1, q1 ); | ||
365 | epow( etwo, q1, e1 ); | ||
366 | |||
367 | /* Find 2^-mprec less than starting power */ | ||
368 | d1 = -mprec + 4; | ||
369 | e53toe( &d1, q1 ); | ||
370 | epow( etwo, q1, e3 ); | ||
371 | emul( e1, e3, e3 ); | ||
372 | emov( e3, e2 ); | ||
373 | ediv( etwo, e2, e2 ); | ||
374 | |||
375 | while( ecmp(e1,e2) != 0 ) | ||
376 | { | ||
377 | eadd( e1, e2, fullp ); | ||
378 | switch( mprec ) | ||
379 | { | ||
380 | #if LDOUBLE | ||
381 | case 64: | ||
382 | etoe64( e1, &sprec64 ); | ||
383 | e64toe( &sprec64, q1 ); | ||
384 | etoe64( fullp, &prec64 ); | ||
385 | e64toe( &prec64, q2 ); | ||
386 | break; | ||
387 | #endif | ||
388 | #ifdef DEC | ||
389 | case 56: | ||
390 | #endif | ||
391 | case 53: | ||
392 | etoe53( e1, &sprec53 ); | ||
393 | e53toe( &sprec53, q1 ); | ||
394 | etoe53( fullp, &prec53 ); | ||
395 | e53toe( &prec53, q2 ); | ||
396 | break; | ||
397 | |||
398 | case 24: | ||
399 | etoe24( e1, &sprec24 ); | ||
400 | e24toe( &sprec24, q1 ); | ||
401 | etoe24( fullp, &prec24 ); | ||
402 | e24toe( &prec24, q2 ); | ||
403 | break; | ||
404 | } | ||
405 | if( ecmp( q2, ezero ) == 0 ) | ||
406 | goto maxden; | ||
407 | chkit(10); | ||
408 | if( ecmp(q1,q2) == 0 ) | ||
409 | { | ||
410 | ediv( etwo, e1, e1 ); | ||
411 | emov( e3, e2 ); | ||
412 | } | ||
413 | if( errtot >= MAXERR ) | ||
414 | { | ||
415 | printf( "%s", toomany ); | ||
416 | goto maxden; | ||
417 | } | ||
418 | ediv( etwo, e2, e2 ); | ||
419 | } | ||
420 | maxden: | ||
421 | printerr(); | ||
422 | nodenorm: | ||
423 | printf( "\n" ); | ||
424 | retval |= errscan | identerr | errprint; | ||
425 | } /* loop on precision */ | ||
426 | printf( "End of test.\n" ); | ||
427 | return (retval); | ||
428 | } | ||
429 | |||
430 | #if CHKINTERNAL | ||
431 | long double xprec64; | ||
432 | double xprec53; | ||
433 | float xprec24; | ||
434 | |||
435 | /* Check binary -> printf -> scanf -> binary identity | ||
436 | * of internal routines | ||
437 | */ | ||
438 | void chkinternal( ref, tst, string ) | ||
439 | unsigned short ref[], tst[]; | ||
440 | char *string; | ||
441 | { | ||
442 | |||
443 | if( ecmp(ref,tst) != 0 ) | ||
444 | { | ||
445 | printf( "internal identity compare error!\n" ); | ||
446 | chkid( ref, tst, string ); | ||
447 | } | ||
448 | } | ||
449 | #endif | ||
450 | |||
451 | |||
452 | /* Check binary -> printf -> scanf -> binary identity | ||
453 | */ | ||
454 | void chkid( print, scan, string ) | ||
455 | unsigned short print[], scan[]; | ||
456 | char *string; | ||
457 | { | ||
458 | /* Test printf-scanf identity */ | ||
459 | if( ecmp( print, scan ) != 0 ) | ||
460 | { | ||
461 | pvec( print, NE ); | ||
462 | printf( " ->printf-> %s ->scanf->\n", string ); | ||
463 | pvec( scan, NE ); | ||
464 | printf( " is not an identity.\n" ); | ||
465 | ++identerr; | ||
466 | } | ||
467 | } | ||
468 | |||
469 | |||
470 | /* Check scanf result | ||
471 | */ | ||
472 | void chkscan( ref, tst, string ) | ||
473 | unsigned short ref[], tst[]; | ||
474 | char *string; | ||
475 | { | ||
476 | /* Test scanf() */ | ||
477 | if( ecmp( ref, tst ) != 0 ) | ||
478 | { | ||
479 | printf( "scanf(%s) -> ", string ); | ||
480 | pvec( tst, NE ); | ||
481 | printf( "\n should be " ); | ||
482 | pvec( ref, NE ); | ||
483 | printf( ".\n" ); | ||
484 | ++errscan; | ||
485 | ++errtot; | ||
486 | } | ||
487 | } | ||
488 | |||
489 | |||
490 | /* Test printf() result | ||
491 | */ | ||
492 | void chkprint( ref, tst, string ) | ||
493 | unsigned short ref[], tst[]; | ||
494 | char *string; | ||
495 | { | ||
496 | if( ecmp(ref, tst) != 0 ) | ||
497 | { | ||
498 | printf( "printf( "); | ||
499 | pvec( ref, NE ); | ||
500 | printf( ") -> %s\n", string ); | ||
501 | printf( " = " ); | ||
502 | pvec( tst, NE ); | ||
503 | printf( ".\n" ); | ||
504 | ++errprint; | ||
505 | ++errtot; | ||
506 | } | ||
507 | } | ||
508 | |||
509 | |||
510 | /* Print array of n 16-bit shorts | ||
511 | */ | ||
512 | void pvec( x, n ) | ||
513 | unsigned short x[]; | ||
514 | int n; | ||
515 | { | ||
516 | int i; | ||
517 | |||
518 | for( i=0; i<n; i++ ) | ||
519 | { | ||
520 | printf( "%04x ", x[i] ); | ||
521 | } | ||
522 | } | ||
523 | |||
524 | /* Measure worst case printf rounding error | ||
525 | */ | ||
526 | void cmpprint( ref, tst ) | ||
527 | unsigned short ref[], tst[]; | ||
528 | { | ||
529 | unsigned short e[NE]; | ||
530 | |||
531 | if( ecmp( ref, ezero ) != 0 ) | ||
532 | { | ||
533 | esub( ref, tst, e ); | ||
534 | ediv( ref, e, e ); | ||
535 | eabs( e ); | ||
536 | if( ecmp( e, rprint ) > 0 ) | ||
537 | emov( e, rprint ); | ||
538 | } | ||
539 | } | ||
540 | |||
541 | /* Measure worst case scanf rounding error | ||
542 | */ | ||
543 | void cmpscan( ref, tst ) | ||
544 | unsigned short ref[], tst[]; | ||
545 | { | ||
546 | unsigned short er[NE]; | ||
547 | |||
548 | if( ecmp( ref, ezero ) != 0 ) | ||
549 | { | ||
550 | esub( ref, tst, er ); | ||
551 | ediv( ref, er, er ); | ||
552 | eabs( er ); | ||
553 | if( ecmp( er, rscan ) > 0 ) | ||
554 | emov( er, rscan ); | ||
555 | if( ecmp( er, ehalf ) > 0 ) | ||
556 | { | ||
557 | etoasc( tst, str1, 21 ); | ||
558 | printf( "Bad error: scanf(%s) = %s !\n", str0, str1 ); | ||
559 | } | ||
560 | } | ||
561 | } | ||
562 | |||
563 | /* Check rounded-down decimal string output of printf | ||
564 | */ | ||
565 | void cmptrunc( ref, tst ) | ||
566 | unsigned short ref[], tst[]; | ||
567 | { | ||
568 | if( ecmp( ref, tst ) != 0 ) | ||
569 | { | ||
570 | printf( "printf(%s%s%s, %s) -> %s\n", quo, tformat, quo, str1, str2 ); | ||
571 | printf( "should be %s .\n", str3 ); | ||
572 | errprint += 1; | ||
573 | } | ||
574 | } | ||
575 | |||
576 | |||
577 | void shownoncrit() | ||
578 | { | ||
579 | |||
580 | etoasc( rprint, str0, 3 ); | ||
581 | printf( "Maximum relative printf error found = %s .\n", str0 ); | ||
582 | etoasc( rscan, str0, 3 ); | ||
583 | printf( "Maximum relative scanf error found = %s .\n", str0 ); | ||
584 | } | ||
585 | |||
586 | |||
587 | |||
588 | /* Produce arguments and call comparison subroutines. | ||
589 | */ | ||
590 | void chkit( testno ) | ||
591 | int testno; | ||
592 | { | ||
593 | unsigned short t[NE], u[NE], v[NE]; | ||
594 | int j; | ||
595 | |||
596 | switch( mprec ) | ||
597 | { | ||
598 | #if LDOUBLE | ||
599 | case 64: | ||
600 | etoe64( fullp, &prec64 ); | ||
601 | e64toe( &prec64, rounded ); | ||
602 | #if CHKINTERNAL | ||
603 | e64toasc( &prec64, str1, SPREC ); | ||
604 | asctoe64( str1, &xprec64 ); | ||
605 | e64toe( &xprec64, t ); | ||
606 | chkinternal( rounded, t, str1 ); | ||
607 | #endif | ||
608 | /* check printf and scanf */ | ||
609 | sprintf( str2, format, prec64 ); | ||
610 | sscanf( str2, fformat, &sprec64 ); | ||
611 | e64toe( &sprec64, u ); | ||
612 | chkid( rounded, u, str2 ); | ||
613 | asctoe64( str2, &ssprec64 ); | ||
614 | e64toe( &ssprec64, v ); | ||
615 | chkscan( v, u, str2 ); | ||
616 | chkprint( rounded, v, str2 ); | ||
617 | if( testno < 8 ) | ||
618 | break; | ||
619 | /* rounding error measurement */ | ||
620 | etoasc( fullp, str0, 24 ); | ||
621 | etoe64( fullp, &ssprec64 ); | ||
622 | e64toe( &ssprec64, u ); | ||
623 | sprintf( str2, format, ssprec64 ); | ||
624 | asctoe( str2, t ); | ||
625 | cmpprint( u, t ); | ||
626 | sscanf( str0, fformat, &sprec64 ); | ||
627 | e64toe( &sprec64, t ); | ||
628 | cmpscan( fullp, t ); | ||
629 | if( testno < 8 ) | ||
630 | break; | ||
631 | /* strings rounded to less than maximum precision */ | ||
632 | e64toasc( &ssprec64, str1, 24 ); | ||
633 | for( j=SPREC-1; j>0; j-- ) | ||
634 | { | ||
635 | e64toasc( &ssprec64, str3, j ); | ||
636 | asctoe( str3, v ); | ||
637 | sprintf( tformat, "%s.%dLe", pct, j ); | ||
638 | sprintf( str2, tformat, ssprec64 ); | ||
639 | asctoe( str2, t ); | ||
640 | cmptrunc( v, t ); | ||
641 | } | ||
642 | break; | ||
643 | #endif | ||
644 | #ifdef DEC | ||
645 | case 56: | ||
646 | #endif | ||
647 | case 53: | ||
648 | etoe53( fullp, &prec53 ); | ||
649 | e53toe( &prec53, rounded ); | ||
650 | #if CHKINTERNAL | ||
651 | e53toasc( &prec53, str1, SPREC ); | ||
652 | asctoe53( str1, &xprec53 ); | ||
653 | e53toe( &xprec53, t ); | ||
654 | chkinternal( rounded, t, str1 ); | ||
655 | #endif | ||
656 | sprintf( str2, format, prec53 ); | ||
657 | sscanf( str2, fformat, &sprec53 ); | ||
658 | e53toe( &sprec53, u ); | ||
659 | chkid( rounded, u, str2 ); | ||
660 | asctoe53( str2, &ssprec53 ); | ||
661 | e53toe( &ssprec53, v ); | ||
662 | chkscan( v, u, str2 ); | ||
663 | chkprint( rounded, v, str2 ); | ||
664 | if( testno < 8 ) | ||
665 | break; | ||
666 | /* rounding error measurement */ | ||
667 | etoasc( fullp, str0, 24 ); | ||
668 | etoe53( fullp, &ssprec53 ); | ||
669 | e53toe( &ssprec53, u ); | ||
670 | sprintf( str2, format, ssprec53 ); | ||
671 | asctoe( str2, t ); | ||
672 | cmpprint( u, t ); | ||
673 | sscanf( str0, fformat, &sprec53 ); | ||
674 | e53toe( &sprec53, t ); | ||
675 | cmpscan( fullp, t ); | ||
676 | if( testno < 8 ) | ||
677 | break; | ||
678 | e53toasc( &ssprec53, str1, 24 ); | ||
679 | for( j=SPREC-1; j>0; j-- ) | ||
680 | { | ||
681 | e53toasc( &ssprec53, str3, j ); | ||
682 | asctoe( str3, v ); | ||
683 | sprintf( tformat, "%s.%de", pct, j ); | ||
684 | sprintf( str2, tformat, ssprec53 ); | ||
685 | asctoe( str2, t ); | ||
686 | cmptrunc( v, t ); | ||
687 | } | ||
688 | break; | ||
689 | |||
690 | case 24: | ||
691 | etoe24( fullp, &prec24 ); | ||
692 | e24toe( &prec24, rounded ); | ||
693 | #if CHKINTERNAL | ||
694 | e24toasc( &prec24, str1, SPREC ); | ||
695 | asctoe24( str1, &xprec24 ); | ||
696 | e24toe( &xprec24, t ); | ||
697 | chkinternal( rounded, t, str1 ); | ||
698 | #endif | ||
699 | sprintf( str2, format, prec24 ); | ||
700 | sscanf( str2, fformat, &sprec24 ); | ||
701 | e24toe( &sprec24, u ); | ||
702 | chkid( rounded, u, str2 ); | ||
703 | asctoe24( str2, &ssprec24 ); | ||
704 | e24toe( &ssprec24, v ); | ||
705 | chkscan( v, u, str2 ); | ||
706 | chkprint( rounded, v, str2 ); | ||
707 | if( testno < 8 ) | ||
708 | break; | ||
709 | /* rounding error measurement */ | ||
710 | etoasc( fullp, str0, 24 ); | ||
711 | etoe24( fullp, &ssprec24 ); | ||
712 | e24toe( &ssprec24, u ); | ||
713 | sprintf( str2, format, ssprec24 ); | ||
714 | asctoe( str2, t ); | ||
715 | cmpprint( u, t ); | ||
716 | sscanf( str0, fformat, &sprec24 ); | ||
717 | e24toe( &sprec24, t ); | ||
718 | cmpscan( fullp, t ); | ||
719 | /* | ||
720 | if( testno < 8 ) | ||
721 | break; | ||
722 | */ | ||
723 | e24toasc( &ssprec24, str1, 24 ); | ||
724 | for( j=SPREC-1; j>0; j-- ) | ||
725 | { | ||
726 | e24toasc( &ssprec24, str3, j ); | ||
727 | asctoe( str3, v ); | ||
728 | sprintf( tformat, "%s.%de", pct, j ); | ||
729 | sprintf( str2, tformat, ssprec24 ); | ||
730 | asctoe( str2, t ); | ||
731 | cmptrunc( v, t ); | ||
732 | } | ||
733 | break; | ||
734 | } | ||
735 | } | ||
736 | |||
737 | |||
738 | void printerr() | ||
739 | { | ||
740 | if( (errscan == 0) && (identerr == 0) && (errprint == 0) ) | ||
741 | printf( "No errors found.\n" ); | ||
742 | else | ||
743 | { | ||
744 | printf( "%d binary -> decimal errors found.\n", errprint ); | ||
745 | printf( "%d decimal -> binary errors found.\n", errscan ); | ||
746 | } | ||
747 | errscan = 0; /* reset for next test */ | ||
748 | identerr = 0; | ||
749 | errprint = 0; | ||
750 | errtot = 0; | ||
751 | } | ||
752 | |||
753 | |||
754 | /* Random number generator | ||
755 | * in the range M * 10^N, where 1 <= M <= 10^17 - 1 | ||
756 | * and -27 <= N <= +27. Test values of M are logarithmically distributed | ||
757 | * random integers; test values of N are uniformly distributed random integers. | ||
758 | */ | ||
759 | |||
760 | static char *fwidth = "1.036163291797320557783096e1"; /* log(sqrt(10^9-1)) */ | ||
761 | static char *dwidth = "1.957197329044938830915E1"; /* log(sqrt(10^17-1)) */ | ||
762 | static char *ldwidth = "2.302585092994045684017491e1"; /* log(sqrt(10^20-1)) */ | ||
763 | |||
764 | static char *a13 = "13.0"; | ||
765 | static char *a27 = "27.0"; | ||
766 | static char *a34 = "34.0"; | ||
767 | static char *a10m13 = "1.0e-13"; | ||
768 | static unsigned short LOW[ NE ], WIDTH[NE], e27[NE], e10m13[NE]; | ||
769 | |||
770 | |||
771 | void mnrand( erand ) | ||
772 | unsigned short erand[]; | ||
773 | { | ||
774 | unsigned short ea[NE], em[NE], en[NE], ex[NE]; | ||
775 | double x, a; | ||
776 | |||
777 | if( mnrflag ) | ||
778 | { | ||
779 | if( mnrflag == 3 ) | ||
780 | { | ||
781 | asctoe( ldwidth, WIDTH ); | ||
782 | asctoe( a34, e27 ); | ||
783 | } | ||
784 | if( mnrflag == 2 ) | ||
785 | { | ||
786 | asctoe( dwidth, WIDTH ); | ||
787 | asctoe( a27, e27 ); | ||
788 | } | ||
789 | if( mnrflag == 1 ) | ||
790 | { | ||
791 | asctoe( fwidth, WIDTH ); | ||
792 | asctoe( a13, e27 ); | ||
793 | } | ||
794 | asctoe( a10m13, e10m13 ); | ||
795 | mnrflag = 0; | ||
796 | } | ||
797 | drand( &x ); | ||
798 | e53toe( &x, ex ); /* x = WIDTH * ( x - 1.0 ) + LOW; */ | ||
799 | esub( eone, ex, ex ); | ||
800 | emul( WIDTH, ex, ex ); | ||
801 | eexp( ex, ex ); /* x = exp(x); */ | ||
802 | |||
803 | drand( &a ); | ||
804 | e53toe( &a, ea ); | ||
805 | emul( ea, ex, ea ); /* a = 1.0e-13 * x * a; */ | ||
806 | emul( e10m13, ea, ea ); | ||
807 | eabs( ea ); | ||
808 | eadd( ea, ex, ex ); /* add fuzz */ | ||
809 | emul( ex, ex, ex ); /* square it, to get range to 10^17 - 1 */ | ||
810 | efloor( ex, em ); /* this is M */ | ||
811 | |||
812 | /* Random power of 10 */ | ||
813 | drand( &a ); | ||
814 | e53toe( &a, ex ); | ||
815 | esub( eone, ex, ex ); /* y3 = 54.0 * ( y3 - 1.0 ) + 0.5; */ | ||
816 | emul( e27, ex, ex ); | ||
817 | eadd( ex, ex, ex ); | ||
818 | eadd( ehalf, ex, ex ); | ||
819 | efloor( ex, ex ); /* y3 = floor( y3 ) - 27.0; */ | ||
820 | esub( e27, ex, en ); /* this is N */ | ||
821 | epow( eten, en, ex ); | ||
822 | emul( ex, em, erand ); | ||
823 | } | ||
824 | |||
825 | /* -ln 2^16382 */ | ||
826 | char *ldemin = "-1.1355137111933024058873097E4"; | ||
827 | char *ldewid = "2.2710274223866048117746193E4"; | ||
828 | /* -ln 2^1022 */ | ||
829 | char *demin = "-7.0839641853226410622441123E2"; | ||
830 | char *dewid = "1.4167928370645282124488225E3"; | ||
831 | /* -ln 2^125 */ | ||
832 | char *femin = "-8.6643397569993163677154015E1"; | ||
833 | char *fewid = "1.7328679513998632735430803E2"; | ||
834 | |||
835 | void etrand( erand ) | ||
836 | unsigned short erand[]; | ||
837 | { | ||
838 | unsigned short ea[NE], ex[NE]; | ||
839 | double x, a; | ||
840 | |||
841 | if( etrflag ) | ||
842 | { | ||
843 | if( etrflag == 3 ) | ||
844 | { | ||
845 | asctoe( ldemin, LOW ); | ||
846 | asctoe( ldewid, WIDTH ); | ||
847 | asctoe( a34, e27 ); | ||
848 | } | ||
849 | if( etrflag == 2 ) | ||
850 | { | ||
851 | asctoe( demin, LOW ); | ||
852 | asctoe( dewid, WIDTH ); | ||
853 | asctoe( a27, e27 ); | ||
854 | } | ||
855 | if( etrflag == 1 ) | ||
856 | { | ||
857 | asctoe( femin, LOW ); | ||
858 | asctoe( fewid, WIDTH ); | ||
859 | asctoe( a13, e27 ); | ||
860 | } | ||
861 | asctoe( a10m13, e10m13 ); | ||
862 | etrflag = 0; | ||
863 | } | ||
864 | drand( &x ); | ||
865 | e53toe( &x, ex ); /* x = WIDTH * ( x - 1.0 ) + LOW; */ | ||
866 | esub( eone, ex, ex ); | ||
867 | emul( WIDTH, ex, ex ); | ||
868 | eadd( LOW, ex, ex ); | ||
869 | eexp( ex, ex ); /* x = exp(x); */ | ||
870 | |||
871 | /* add fuzz | ||
872 | */ | ||
873 | drand( &a ); | ||
874 | e53toe( &a, ea ); | ||
875 | emul( ea, ex, ea ); /* a = 1.0e-13 * x * a; */ | ||
876 | emul( e10m13, ea, ea ); | ||
877 | if( ecmp( ex, ezero ) > 0 ) | ||
878 | eneg( ea ); | ||
879 | eadd( ea, ex, erand ); | ||
880 | } | ||
881 | |||
diff --git a/src/regress/lib/libc/cephes/mconf.h b/src/regress/lib/libc/cephes/mconf.h deleted file mode 100644 index 410849c355..0000000000 --- a/src/regress/lib/libc/cephes/mconf.h +++ /dev/null | |||
@@ -1,189 +0,0 @@ | |||
1 | /* $OpenBSD: mconf.h,v 1.3 2017/07/27 15:08:37 bluhm Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* mconf.h | ||
20 | * | ||
21 | * Common include file for math routines | ||
22 | * | ||
23 | * | ||
24 | * | ||
25 | * SYNOPSIS: | ||
26 | * | ||
27 | * #include "mconf.h" | ||
28 | * | ||
29 | * | ||
30 | * | ||
31 | * DESCRIPTION: | ||
32 | * | ||
33 | * This file contains definitions for error codes that are | ||
34 | * passed to the common error handling routine mtherr() | ||
35 | * (which see). | ||
36 | * | ||
37 | * The file also includes a conditional assembly definition | ||
38 | * for the type of computer arithmetic (IEEE, DEC, Motorola | ||
39 | * IEEE, or UNKnown). | ||
40 | * | ||
41 | * For Digital Equipment PDP-11 and VAX computers, certain | ||
42 | * IBM systems, and others that use numbers with a 56-bit | ||
43 | * significand, the symbol DEC should be defined. In this | ||
44 | * mode, most floating point constants are given as arrays | ||
45 | * of octal integers to eliminate decimal to binary conversion | ||
46 | * errors that might be introduced by the compiler. | ||
47 | * | ||
48 | * For little-endian computers, such as IBM PC, that follow the | ||
49 | * IEEE Standard for Binary Floating Point Arithmetic (ANSI/IEEE | ||
50 | * Std 754-1985), the symbol IBMPC should be defined. These | ||
51 | * numbers have 53-bit significands. In this mode, constants | ||
52 | * are provided as arrays of hexadecimal 16 bit integers. | ||
53 | * | ||
54 | * Big-endian IEEE format is denoted MIEEE. On some RISC | ||
55 | * systems such as Sun SPARC, double precision constants | ||
56 | * must be stored on 8-byte address boundaries. Since integer | ||
57 | * arrays may be aligned differently, the MIEEE configuration | ||
58 | * may fail on such machines. | ||
59 | * | ||
60 | * To accommodate other types of computer arithmetic, all | ||
61 | * constants are also provided in a normal decimal radix | ||
62 | * which one can hope are correctly converted to a suitable | ||
63 | * format by the available C language compiler. To invoke | ||
64 | * this mode, define the symbol UNK. | ||
65 | * | ||
66 | * An important difference among these modes is a predefined | ||
67 | * set of machine arithmetic constants for each. The numbers | ||
68 | * MACHEP (the machine roundoff error), MAXNUM (largest number | ||
69 | * represented), and several other parameters are preset by | ||
70 | * the configuration symbol. Check the file const.c to | ||
71 | * ensure that these values are correct for your computer. | ||
72 | * | ||
73 | * Configurations NANS, INFINITIES, MINUSZERO, and DENORMAL | ||
74 | * may fail on many systems. Verify that they are supposed | ||
75 | * to work on your computer. | ||
76 | */ | ||
77 | |||
78 | #include <sys/types.h> | ||
79 | #include <endian.h> | ||
80 | |||
81 | /* Constant definitions for math error conditions | ||
82 | */ | ||
83 | |||
84 | #define DOMAIN 1 /* argument domain error */ | ||
85 | #define SING 2 /* argument singularity */ | ||
86 | #define OVERFLOW 3 /* overflow range error */ | ||
87 | #define UNDERFLOW 4 /* underflow range error */ | ||
88 | #define TLOSS 5 /* total loss of precision */ | ||
89 | #define PLOSS 6 /* partial loss of precision */ | ||
90 | |||
91 | #define EDOM 33 | ||
92 | #define ERANGE 34 | ||
93 | |||
94 | /* Complex numeral. */ | ||
95 | typedef struct | ||
96 | { | ||
97 | double r; | ||
98 | double i; | ||
99 | } cmplx; | ||
100 | |||
101 | /* Long double complex numeral. */ | ||
102 | typedef struct | ||
103 | { | ||
104 | double r; | ||
105 | double i; | ||
106 | } cmplxl; | ||
107 | |||
108 | /* Type of computer arithmetic */ | ||
109 | |||
110 | /* PDP-11, Pro350, VAX: | ||
111 | */ | ||
112 | #ifdef __vax__ | ||
113 | #define DEC 1 | ||
114 | #endif /* __vax__ */ | ||
115 | |||
116 | /* Intel IEEE, low order words come first: | ||
117 | */ | ||
118 | /* #define IBMPC 1 */ | ||
119 | |||
120 | /* Motorola IEEE, high order words come first | ||
121 | * (Sun 680x0 workstation): | ||
122 | */ | ||
123 | /* #define MIEEE 1 */ | ||
124 | |||
125 | /* UNKnown arithmetic, invokes coefficients given in | ||
126 | * normal decimal format. Beware of range boundary | ||
127 | * problems (MACHEP, MAXLOG, etc. in const.c) and | ||
128 | * roundoff problems in pow.c: | ||
129 | * (Sun SPARCstation) | ||
130 | */ | ||
131 | #ifndef __vax__ | ||
132 | #define UNK 1 | ||
133 | #endif /* !__vax__ */ | ||
134 | |||
135 | /* If you define UNK, then be sure to set BIGENDIAN properly. */ | ||
136 | #if BYTE_ORDER == BIG_ENDIAN | ||
137 | #define BIGENDIAN 1 | ||
138 | #endif /* BYTE_ORDER == BIG_ENDIAN */ | ||
139 | |||
140 | /* Define this `volatile' if your compiler thinks | ||
141 | * that floating point arithmetic obeys the associative | ||
142 | * and distributive laws. It will defeat some optimizations | ||
143 | * (but probably not enough of them). | ||
144 | * | ||
145 | * #define VOLATILE volatile | ||
146 | */ | ||
147 | #define VOLATILE | ||
148 | |||
149 | /* For 12-byte long doubles on an i386, pad a 16-bit short 0 | ||
150 | * to the end of real constants initialized by integer arrays. | ||
151 | * | ||
152 | * #define XPD 0, | ||
153 | * | ||
154 | * Otherwise, the type is 10 bytes long and XPD should be | ||
155 | * defined blank (e.g., Microsoft C). | ||
156 | * | ||
157 | * #define XPD | ||
158 | */ | ||
159 | #define XPD 0, | ||
160 | |||
161 | /* Define to support tiny denormal numbers, else undefine. */ | ||
162 | #ifndef __vax__ | ||
163 | #define DENORMAL 1 | ||
164 | #endif /* !__vax__ */ | ||
165 | |||
166 | /* Define to ask for infinity support, else undefine. */ | ||
167 | #ifndef __vax__ | ||
168 | #define INFINITIES 1 | ||
169 | #endif /* !__vax__ */ | ||
170 | |||
171 | /* Define to ask for support of numbers that are Not-a-Number, | ||
172 | else undefine. This may automatically define INFINITIES in some files. */ | ||
173 | #ifndef __vax__ | ||
174 | #define NANS 1 | ||
175 | #endif /* !__vax__ */ | ||
176 | |||
177 | /* Define to distinguish between -0.0 and +0.0. */ | ||
178 | #define MINUSZERO 1 | ||
179 | |||
180 | /* Define 1 for ANSI C atan2() function | ||
181 | See atan.c and clog.c. */ | ||
182 | #define ANSIC 1 | ||
183 | |||
184 | int mtherr(); | ||
185 | |||
186 | /* Variable for error reporting. See mtherr.c. */ | ||
187 | extern int merror; | ||
188 | |||
189 | int drand(double *); | ||
diff --git a/src/regress/lib/libc/cephes/mtherr.c b/src/regress/lib/libc/cephes/mtherr.c deleted file mode 100644 index 9a47a198bd..0000000000 --- a/src/regress/lib/libc/cephes/mtherr.c +++ /dev/null | |||
@@ -1,114 +0,0 @@ | |||
1 | /* $OpenBSD: mtherr.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* mtherr.c | ||
20 | * | ||
21 | * Library common error handling routine | ||
22 | * | ||
23 | * | ||
24 | * | ||
25 | * SYNOPSIS: | ||
26 | * | ||
27 | * char *fctnam; | ||
28 | * int code; | ||
29 | * int mtherr(); | ||
30 | * | ||
31 | * mtherr( fctnam, code ); | ||
32 | * | ||
33 | * | ||
34 | * | ||
35 | * DESCRIPTION: | ||
36 | * | ||
37 | * This routine may be called to report one of the following | ||
38 | * error conditions (in the include file mconf.h). | ||
39 | * | ||
40 | * Mnemonic Value Significance | ||
41 | * | ||
42 | * DOMAIN 1 argument domain error | ||
43 | * SING 2 function singularity | ||
44 | * OVERFLOW 3 overflow range error | ||
45 | * UNDERFLOW 4 underflow range error | ||
46 | * TLOSS 5 total loss of precision | ||
47 | * PLOSS 6 partial loss of precision | ||
48 | * EDOM 33 Unix domain error code | ||
49 | * ERANGE 34 Unix range error code | ||
50 | * | ||
51 | * The default version of the file prints the function name, | ||
52 | * passed to it by the pointer fctnam, followed by the | ||
53 | * error condition. The display is directed to the standard | ||
54 | * output device. The routine then returns to the calling | ||
55 | * program. Users may wish to modify the program to abort by | ||
56 | * calling exit() under severe error conditions such as domain | ||
57 | * errors. | ||
58 | * | ||
59 | * Since all error conditions pass control to this function, | ||
60 | * the display may be easily changed, eliminated, or directed | ||
61 | * to an error logging device. | ||
62 | * | ||
63 | * SEE ALSO: | ||
64 | * | ||
65 | * mconf.h | ||
66 | * | ||
67 | */ | ||
68 | |||
69 | #include <stdio.h> | ||
70 | #include "mconf.h" | ||
71 | |||
72 | int merror = 0; | ||
73 | |||
74 | /* Notice: the order of appearance of the following | ||
75 | * messages is bound to the error codes defined | ||
76 | * in mconf.h. | ||
77 | */ | ||
78 | static char *ermsg[7] = { | ||
79 | "unknown", /* error code 0 */ | ||
80 | "domain", /* error code 1 */ | ||
81 | "singularity", /* et seq. */ | ||
82 | "overflow", | ||
83 | "underflow", | ||
84 | "total loss of precision", | ||
85 | "partial loss of precision" | ||
86 | }; | ||
87 | |||
88 | |||
89 | int mtherr( name, code ) | ||
90 | char *name; | ||
91 | int code; | ||
92 | { | ||
93 | |||
94 | /* Display string passed by calling program, | ||
95 | * which is supposed to be the name of the | ||
96 | * function in which the error occurred: | ||
97 | */ | ||
98 | printf( "\n%s ", name ); | ||
99 | |||
100 | /* Set global error message word */ | ||
101 | merror = code; | ||
102 | |||
103 | /* Display error message defined | ||
104 | * by the code argument. | ||
105 | */ | ||
106 | if( (code <= 0) || (code >= 7) ) | ||
107 | code = 0; | ||
108 | printf( "%s error\n", ermsg[code] ); | ||
109 | |||
110 | /* Return to calling | ||
111 | * program | ||
112 | */ | ||
113 | return( 0 ); | ||
114 | } | ||
diff --git a/src/regress/lib/libc/cxa-atexit/Makefile b/src/regress/lib/libc/cxa-atexit/Makefile deleted file mode 100644 index a2821e01d3..0000000000 --- a/src/regress/lib/libc/cxa-atexit/Makefile +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2013/08/06 19:11:53 miod Exp $ | ||
2 | |||
3 | SUBDIR+= libgd1 libgd2 test1 | ||
4 | |||
5 | install: | ||
6 | |||
7 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd1/Makefile b/src/regress/lib/libc/cxa-atexit/libgd1/Makefile deleted file mode 100644 index 958b726d28..0000000000 --- a/src/regress/lib/libc/cxa-atexit/libgd1/Makefile +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2007/09/03 14:42:44 millert Exp $ | ||
2 | |||
3 | LIB=gd1 | ||
4 | SRCS= gd1.C | ||
5 | NOPROFILE=yes | ||
6 | |||
7 | regress: all | ||
8 | |||
9 | .include <bsd.lib.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd1/gd1.C b/src/regress/lib/libc/cxa-atexit/libgd1/gd1.C deleted file mode 100644 index b3ecd56d91..0000000000 --- a/src/regress/lib/libc/cxa-atexit/libgd1/gd1.C +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | /* $OpenBSD: gd1.C,v 1.1 2007/09/03 14:42:44 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <stdio.h> | ||
20 | |||
21 | extern int check1; | ||
22 | |||
23 | struct global_destructor_test_obj1 { | ||
24 | inline ~global_destructor_test_obj1() { | ||
25 | check1 = 0; | ||
26 | } | ||
27 | }; | ||
28 | |||
29 | extern "C" void gd_test1() | ||
30 | { | ||
31 | static global_destructor_test_obj1 gdt; | ||
32 | } | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd1/shlib_version b/src/regress/lib/libc/cxa-atexit/libgd1/shlib_version deleted file mode 100644 index 97c9f92d6b..0000000000 --- a/src/regress/lib/libc/cxa-atexit/libgd1/shlib_version +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | major=0 | ||
2 | minor=0 | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd2/Makefile b/src/regress/lib/libc/cxa-atexit/libgd2/Makefile deleted file mode 100644 index 7ca21d8bd2..0000000000 --- a/src/regress/lib/libc/cxa-atexit/libgd2/Makefile +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2007/09/03 14:42:44 millert Exp $ | ||
2 | |||
3 | LIB=gd2 | ||
4 | SRCS= gd2.C | ||
5 | NOPROFILE=yes | ||
6 | |||
7 | regress: all | ||
8 | |||
9 | .include <bsd.lib.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd2/gd2.C b/src/regress/lib/libc/cxa-atexit/libgd2/gd2.C deleted file mode 100644 index 69e7ffb220..0000000000 --- a/src/regress/lib/libc/cxa-atexit/libgd2/gd2.C +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | /* $OpenBSD: gd2.C,v 1.1 2007/09/03 14:42:44 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <stdio.h> | ||
20 | |||
21 | extern int check2; | ||
22 | |||
23 | struct global_destructor_test_obj2 { | ||
24 | inline ~global_destructor_test_obj2() { | ||
25 | check2 = 0; | ||
26 | } | ||
27 | }; | ||
28 | |||
29 | extern "C" void gd_test2() | ||
30 | { | ||
31 | static global_destructor_test_obj2 gdt; | ||
32 | } | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd2/shlib_version b/src/regress/lib/libc/cxa-atexit/libgd2/shlib_version deleted file mode 100644 index 97c9f92d6b..0000000000 --- a/src/regress/lib/libc/cxa-atexit/libgd2/shlib_version +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | major=0 | ||
2 | minor=0 | ||
diff --git a/src/regress/lib/libc/cxa-atexit/test1/Makefile b/src/regress/lib/libc/cxa-atexit/test1/Makefile deleted file mode 100644 index 162922b35a..0000000000 --- a/src/regress/lib/libc/cxa-atexit/test1/Makefile +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2015/05/29 04:17:11 miod Exp $ | ||
2 | |||
3 | .include <bsd.obj.mk> | ||
4 | |||
5 | GD1_DIR=${.CURDIR}/../libgd1 | ||
6 | GD1_OBJDIR!= if [ -d $(GD1_DIR)/${__objdir} ]; then \ | ||
7 | echo "$(GD1_DIR)/${__objdir}"; \ | ||
8 | else \ | ||
9 | echo "$(GD1_DIR)"; \ | ||
10 | fi | ||
11 | |||
12 | GD2_DIR=${.CURDIR}/../libgd2 | ||
13 | GD2_OBJDIR!= if [ -d $(GD2_DIR)/${__objdir} ]; then \ | ||
14 | echo "$(GD2_DIR)/${__objdir}"; \ | ||
15 | else \ | ||
16 | echo "$(GD2_DIR)"; \ | ||
17 | fi | ||
18 | |||
19 | PROG= test1 | ||
20 | |||
21 | SRCS= test1.C | ||
22 | |||
23 | CXXFLAGS+= -DLIBGD1="\"$(GD1_OBJDIR)/libgd1.so\"" | ||
24 | CXXFLAGS+= -DLIBGD2="\"$(GD2_OBJDIR)/libgd2.so\"" | ||
25 | LDFLAGS+= -Wl,-E | ||
26 | |||
27 | NOMAN= | ||
28 | |||
29 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/test1/test1.C b/src/regress/lib/libc/cxa-atexit/test1/test1.C deleted file mode 100644 index 75fb967a90..0000000000 --- a/src/regress/lib/libc/cxa-atexit/test1/test1.C +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
1 | /* $OpenBSD: test1.C,v 1.1 2007/09/03 14:42:44 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <dlfcn.h> | ||
20 | #include <err.h> | ||
21 | #include <stdio.h> | ||
22 | |||
23 | int check1, check2; | ||
24 | |||
25 | int | ||
26 | main() | ||
27 | { | ||
28 | void *libgd1, *libgd2; | ||
29 | void (*gd_test)(); | ||
30 | int i; | ||
31 | |||
32 | for (i=0; i < 50; i++) { | ||
33 | check1 = check2 = 1; | ||
34 | |||
35 | libgd1 = dlopen(LIBGD1, RTLD_LAZY); | ||
36 | if (libgd1 == NULL) | ||
37 | errx(1, "dlopen(%s, RTLD_LAZY) FAILED\n", LIBGD1); | ||
38 | |||
39 | gd_test = (void (*)())dlsym(libgd1, "gd_test1"); | ||
40 | if (gd_test == NULL) | ||
41 | errx(1, "dlsym(libgd1, \"gd_test1\") FAILED\n"); | ||
42 | |||
43 | (*gd_test)(); | ||
44 | |||
45 | libgd2 = dlopen(LIBGD2, RTLD_LAZY); | ||
46 | if (libgd2 == NULL) | ||
47 | errx(1, "dlopen(%s, RTLD_LAZY) FAILED\n", LIBGD2); | ||
48 | |||
49 | gd_test = (void (*)())dlsym(libgd2, "gd_test2"); | ||
50 | if (gd_test == NULL) | ||
51 | errx(1, "dlsym(libgd2, \"gd_test2\") FAILED\n"); | ||
52 | |||
53 | (*gd_test)(); | ||
54 | |||
55 | dlclose(libgd1); | ||
56 | dlclose(libgd2); | ||
57 | |||
58 | if (check1 || check2) | ||
59 | errx(1, "global destructors not called\n"); | ||
60 | } | ||
61 | |||
62 | return (0); | ||
63 | } | ||
diff --git a/src/regress/lib/libc/db/Makefile b/src/regress/lib/libc/db/Makefile deleted file mode 100644 index a7ba659707..0000000000 --- a/src/regress/lib/libc/db/Makefile +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.11 2021/09/27 18:47:46 bluhm Exp $ | ||
2 | # $NetBSD: Makefile,v 1.11 1995/12/12 01:54:15 cgd Exp $ | ||
3 | |||
4 | PROG= dbtest | ||
5 | |||
6 | # add -DSTATISTICS to CFLAGS to get usage statistics. Note that | ||
7 | # for this to work, libc must be compiled with -DSTATISTICS as well | ||
8 | CFLAGS+= -g -D__DBINTERFACE_PRIVATE -DDEBUG | ||
9 | CLEANFILES+= t1 t2 t3 log | ||
10 | |||
11 | DBTARGETS=1 2 3 4 5 6 7 8 9 10 11 12 13 20 | ||
12 | |||
13 | .for DT in ${DBTARGETS} | ||
14 | db-${DT}: ${PROG} | ||
15 | sh ${.CURDIR}/run.test ${DT} | ||
16 | REGRESS_TARGETS+=db-${DT} | ||
17 | .PHONY: db-${DT} | ||
18 | .endfor | ||
19 | |||
20 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/db/README b/src/regress/lib/libc/db/README deleted file mode 100644 index 23a1b77221..0000000000 --- a/src/regress/lib/libc/db/README +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | # $OpenBSD: README,v 1.3 2001/01/29 02:05:40 niklas Exp $ | ||
2 | # $NetBSD: README,v 1.5 1996/05/03 21:54:19 cgd Exp $ | ||
3 | # @(#)README 8.8 (Berkeley) 7/31/94 | ||
4 | |||
5 | To run the tests, enter "make regress". | ||
6 | |||
7 | Fairly large files (the command files) are built in this directory during | ||
8 | the test runs, and even larger files (the database files) are created in | ||
9 | "/var/tmp". If the latter directory doesn't exist, set the environmental | ||
10 | variable TMPDIR to a directory where the files can be built. | ||
11 | |||
12 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||
13 | The script file consists of lines with an initial character which is | ||
14 | the command for that line, or an initial character indicating a key | ||
15 | or data entry for a previous command. | ||
16 | |||
17 | Legal command characters are as follows: | ||
18 | |||
19 | c: compare a record | ||
20 | + must be followed by [kK][dD]; the data value in the database | ||
21 | associated with the specified key is compared to the specified | ||
22 | data value. | ||
23 | e: echo a string | ||
24 | + writes out the rest of the line into the output file; if the | ||
25 | last character is not a carriage-return, a newline is appended. | ||
26 | f: set the flags for the next command | ||
27 | + no value zero's the flags | ||
28 | g: do a get command | ||
29 | + must be followed by [kK] | ||
30 | + writes out the retrieved data DBT. | ||
31 | o [r]: dump [reverse] | ||
32 | + dump the database out, if 'r' is set, in reverse order. | ||
33 | p: do a put command | ||
34 | + must be followed by [kK][dD] | ||
35 | r: do a del command | ||
36 | + must be followed by [kK] unless R_CURSOR flag set. | ||
37 | S: sync the database | ||
38 | s: do a seq command | ||
39 | + must be followed by [kK] if R_CURSOR flag set. | ||
40 | + writes out the retrieved data DBT. | ||
41 | |||
42 | Legal key/data characters are as follows: | ||
43 | |||
44 | D [file]: data file | ||
45 | + set the current data value to the contents of the file | ||
46 | d [data]: | ||
47 | + set the current key value to the contents of the line. | ||
48 | K [file]: key file | ||
49 | + set the current key value to the contents of the file | ||
50 | k [data]: | ||
51 | + set the current key value to the contents of the line. | ||
52 | |||
53 | Blank lines, lines with leading white space, and lines with leading | ||
54 | hash marks (#) are ignored. | ||
55 | |||
56 | Options to dbtest are as follows: | ||
57 | |||
58 | -d: Set the DB_LOCK flag. | ||
59 | -f: Use the file argument as the database file. | ||
60 | -i: Use the rest of the argument to set elements in the info | ||
61 | structure. If the type is btree, then "-i cachesize=10240" | ||
62 | will set BTREEINFO.cachesize to 10240. | ||
63 | -o: The rest of the argument is the output file instead of | ||
64 | using stdout. | ||
65 | -s: Don't delete the database file before opening it, i.e. | ||
66 | use the database file from a previous run. | ||
67 | |||
68 | Dbtest requires two arguments, the type of access "hash", "recno" | ||
69 | or "btree", and the script name or "-" to indicate stdin. | ||
diff --git a/src/regress/lib/libc/db/dbtest.c b/src/regress/lib/libc/db/dbtest.c deleted file mode 100644 index 3207bafda3..0000000000 --- a/src/regress/lib/libc/db/dbtest.c +++ /dev/null | |||
@@ -1,729 +0,0 @@ | |||
1 | /* $OpenBSD: dbtest.c,v 1.21 2022/12/04 23:50:46 cheloha Exp $ */ | ||
2 | /* $NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 1992, 1993, 1994 | ||
6 | * The Regents of the University of California. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * 3. Neither the name of the University nor the names of its contributors | ||
17 | * may be used to endorse or promote products derived from this software | ||
18 | * without specific prior written permission. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
30 | * SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include <sys/stat.h> | ||
34 | |||
35 | #include <ctype.h> | ||
36 | #include <errno.h> | ||
37 | #include <fcntl.h> | ||
38 | #include <stdint.h> | ||
39 | #include <stdio.h> | ||
40 | #include <stdlib.h> | ||
41 | #include <string.h> | ||
42 | #include <stdarg.h> | ||
43 | #include <unistd.h> | ||
44 | |||
45 | #include <db.h> | ||
46 | |||
47 | #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) | ||
48 | |||
49 | enum S { COMMAND, COMPARE, GET, PUT, REMOVE, SEQ, SEQFLAG, KEY, DATA }; | ||
50 | |||
51 | void compare(DBT *, DBT *); | ||
52 | DBTYPE dbtype(char *); | ||
53 | void dump(DB *, int); | ||
54 | void __dead dberr(const char *, ...); | ||
55 | void get(DB *, DBT *); | ||
56 | void getdata(DB *, DBT *, DBT *); | ||
57 | void put(DB *, DBT *, DBT *); | ||
58 | void rem(DB *, DBT *); | ||
59 | char *sflags(int); | ||
60 | void synk(DB *); | ||
61 | void *rfile(char *, size_t *); | ||
62 | void seq(DB *, DBT *); | ||
63 | u_int setflags(char *); | ||
64 | void *setinfo(DBTYPE, char *); | ||
65 | void __dead usage(void); | ||
66 | void *xmalloc(char *, size_t); | ||
67 | |||
68 | DBTYPE type; /* Database type. */ | ||
69 | void *infop; /* Iflags. */ | ||
70 | u_long lineno; /* Current line in test script. */ | ||
71 | u_int flags; /* Current DB flags. */ | ||
72 | int ofd = STDOUT_FILENO; /* Standard output fd. */ | ||
73 | |||
74 | DB *XXdbp; /* Global for gdb. */ | ||
75 | int XXlineno; /* Fast breakpoint for gdb. */ | ||
76 | |||
77 | int | ||
78 | main(int argc, char *argv[]) | ||
79 | { | ||
80 | enum S command, state; | ||
81 | DB *dbp; | ||
82 | DBT data, key, keydata; | ||
83 | size_t len; | ||
84 | int ch, oflags, sflag; | ||
85 | char *fname, *infoarg, *p, *t, buf[8 * 1024]; | ||
86 | |||
87 | infoarg = NULL; | ||
88 | fname = NULL; | ||
89 | oflags = O_CREAT | O_RDWR; | ||
90 | sflag = 0; | ||
91 | while ((ch = getopt(argc, argv, "f:i:lo:s")) != -1) | ||
92 | switch (ch) { | ||
93 | case 'f': | ||
94 | fname = optarg; | ||
95 | break; | ||
96 | case 'i': | ||
97 | infoarg = optarg; | ||
98 | break; | ||
99 | case 'l': | ||
100 | oflags |= DB_LOCK; | ||
101 | break; | ||
102 | case 'o': | ||
103 | if ((ofd = open(optarg, | ||
104 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) | ||
105 | dberr("%s: %s", optarg, strerror(errno)); | ||
106 | break; | ||
107 | case 's': | ||
108 | sflag = 1; | ||
109 | break; | ||
110 | default: | ||
111 | usage(); | ||
112 | } | ||
113 | argc -= optind; | ||
114 | argv += optind; | ||
115 | |||
116 | if (argc != 2) | ||
117 | usage(); | ||
118 | |||
119 | /* Set the type. */ | ||
120 | type = dbtype(*argv++); | ||
121 | |||
122 | /* Open the descriptor file. */ | ||
123 | if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL) | ||
124 | dberr("%s: %s", *argv, strerror(errno)); | ||
125 | |||
126 | /* Set up the db structure as necessary. */ | ||
127 | if (infoarg == NULL) | ||
128 | infop = NULL; | ||
129 | else | ||
130 | for (p = strtok(infoarg, ",\t "); p != NULL; | ||
131 | p = strtok(0, ",\t ")) | ||
132 | if (*p != '\0') | ||
133 | infop = setinfo(type, p); | ||
134 | |||
135 | /* | ||
136 | * Open the DB. Delete any preexisting copy, you almost never | ||
137 | * want it around, and it often screws up tests. | ||
138 | */ | ||
139 | if (fname == NULL) { | ||
140 | p = getenv("TMPDIR"); | ||
141 | if (p == NULL) | ||
142 | p = "/tmp"; | ||
143 | (void)snprintf(buf, sizeof buf, "%s/__dbtest", p); | ||
144 | fname = buf; | ||
145 | (void)unlink(buf); | ||
146 | } else if (!sflag) | ||
147 | (void)unlink(fname); | ||
148 | |||
149 | if ((dbp = dbopen(fname, | ||
150 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) | ||
151 | dberr("dbopen: %s", strerror(errno)); | ||
152 | XXdbp = dbp; | ||
153 | |||
154 | state = COMMAND; | ||
155 | for (lineno = 1; | ||
156 | (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { | ||
157 | /* Delete the newline, displaying the key/data is easier. */ | ||
158 | if (ofd == STDOUT_FILENO && (t = strchr(p, '\n')) != NULL) | ||
159 | *t = '\0'; | ||
160 | if ((len = strlen(buf)) == 0 || isspace((unsigned char)*p) || *p == '#') | ||
161 | continue; | ||
162 | |||
163 | /* Convenient gdb break point. */ | ||
164 | if (XXlineno == lineno) | ||
165 | XXlineno = 1; | ||
166 | switch (*p) { | ||
167 | case 'c': /* compare */ | ||
168 | if (state != COMMAND) | ||
169 | dberr("line %lu: not expecting command", | ||
170 | lineno); | ||
171 | state = KEY; | ||
172 | command = COMPARE; | ||
173 | break; | ||
174 | case 'e': /* echo */ | ||
175 | if (state != COMMAND) | ||
176 | dberr("line %lu: not expecting command", | ||
177 | lineno); | ||
178 | /* Don't display the newline, if CR at EOL. */ | ||
179 | if (p[len - 2] == '\r') | ||
180 | --len; | ||
181 | if (write(ofd, p + 1, len - 1) != len - 1 || | ||
182 | write(ofd, "\n", 1) != 1) | ||
183 | dberr("write: %s", strerror(errno)); | ||
184 | break; | ||
185 | case 'g': /* get */ | ||
186 | if (state != COMMAND) | ||
187 | dberr("line %lu: not expecting command", | ||
188 | lineno); | ||
189 | state = KEY; | ||
190 | command = GET; | ||
191 | break; | ||
192 | case 'p': /* put */ | ||
193 | if (state != COMMAND) | ||
194 | dberr("line %lu: not expecting command", | ||
195 | lineno); | ||
196 | state = KEY; | ||
197 | command = PUT; | ||
198 | break; | ||
199 | case 'r': /* remove */ | ||
200 | if (state != COMMAND) | ||
201 | dberr("line %lu: not expecting command", | ||
202 | lineno); | ||
203 | if (flags == R_CURSOR) { | ||
204 | rem(dbp, &key); | ||
205 | state = COMMAND; | ||
206 | } else { | ||
207 | state = KEY; | ||
208 | command = REMOVE; | ||
209 | } | ||
210 | break; | ||
211 | case 'S': /* sync */ | ||
212 | if (state != COMMAND) | ||
213 | dberr("line %lu: not expecting command", | ||
214 | lineno); | ||
215 | synk(dbp); | ||
216 | state = COMMAND; | ||
217 | break; | ||
218 | case 's': /* seq */ | ||
219 | if (state != COMMAND) | ||
220 | dberr("line %lu: not expecting command", | ||
221 | lineno); | ||
222 | if (flags == R_CURSOR) { | ||
223 | state = KEY; | ||
224 | command = SEQ; | ||
225 | } else | ||
226 | seq(dbp, &key); | ||
227 | break; | ||
228 | case 'f': | ||
229 | flags = setflags(p + 1); | ||
230 | break; | ||
231 | case 'D': /* data file */ | ||
232 | if (state != DATA) | ||
233 | dberr("line %lu: not expecting data", lineno); | ||
234 | data.data = rfile(p + 1, &data.size); | ||
235 | goto ldata; | ||
236 | case 'd': /* data */ | ||
237 | if (state != DATA) | ||
238 | dberr("line %lu: not expecting data", lineno); | ||
239 | data.data = xmalloc(p + 1, len - 1); | ||
240 | data.size = len - 1; | ||
241 | ldata: switch (command) { | ||
242 | case COMPARE: | ||
243 | compare(&keydata, &data); | ||
244 | break; | ||
245 | case PUT: | ||
246 | put(dbp, &key, &data); | ||
247 | break; | ||
248 | default: | ||
249 | dberr("line %lu: command doesn't take data", | ||
250 | lineno); | ||
251 | } | ||
252 | if (type != DB_RECNO) | ||
253 | free(key.data); | ||
254 | free(data.data); | ||
255 | state = COMMAND; | ||
256 | break; | ||
257 | case 'K': /* key file */ | ||
258 | if (state != KEY) | ||
259 | dberr("line %lu: not expecting a key", lineno); | ||
260 | if (type == DB_RECNO) | ||
261 | dberr("line %lu: 'K' not available for recno", | ||
262 | lineno); | ||
263 | key.data = rfile(p + 1, &key.size); | ||
264 | goto lkey; | ||
265 | case 'k': /* key */ | ||
266 | if (state != KEY) | ||
267 | dberr("line %lu: not expecting a key", lineno); | ||
268 | if (type == DB_RECNO) { | ||
269 | static recno_t recno; | ||
270 | recno = atoi(p + 1); | ||
271 | key.data = &recno; | ||
272 | key.size = sizeof(recno); | ||
273 | } else { | ||
274 | key.data = xmalloc(p + 1, len - 1); | ||
275 | key.size = len - 1; | ||
276 | } | ||
277 | lkey: switch (command) { | ||
278 | case COMPARE: | ||
279 | getdata(dbp, &key, &keydata); | ||
280 | state = DATA; | ||
281 | break; | ||
282 | case GET: | ||
283 | get(dbp, &key); | ||
284 | if (type != DB_RECNO) | ||
285 | free(key.data); | ||
286 | state = COMMAND; | ||
287 | break; | ||
288 | case PUT: | ||
289 | state = DATA; | ||
290 | break; | ||
291 | case REMOVE: | ||
292 | rem(dbp, &key); | ||
293 | if ((type != DB_RECNO) && (flags != R_CURSOR)) | ||
294 | free(key.data); | ||
295 | state = COMMAND; | ||
296 | break; | ||
297 | case SEQ: | ||
298 | seq(dbp, &key); | ||
299 | if ((type != DB_RECNO) && (flags != R_CURSOR)) | ||
300 | free(key.data); | ||
301 | state = COMMAND; | ||
302 | break; | ||
303 | default: | ||
304 | dberr("line %lu: command doesn't take a key", | ||
305 | lineno); | ||
306 | } | ||
307 | break; | ||
308 | case 'o': | ||
309 | dump(dbp, p[1] == 'r'); | ||
310 | break; | ||
311 | default: | ||
312 | dberr("line %lu: %s: unknown command character", | ||
313 | lineno, p); | ||
314 | } | ||
315 | } | ||
316 | #ifdef STATISTICS | ||
317 | /* | ||
318 | * -l must be used (DB_LOCK must be set) for this to be | ||
319 | * used, otherwise a page will be locked and it will fail. | ||
320 | */ | ||
321 | if (type == DB_BTREE && oflags & DB_LOCK) | ||
322 | __bt_stat(dbp); | ||
323 | #endif | ||
324 | if (dbp->close(dbp)) | ||
325 | dberr("db->close: %s", strerror(errno)); | ||
326 | (void)close(ofd); | ||
327 | exit(0); | ||
328 | } | ||
329 | |||
330 | #define NOOVERWRITE "put failed, would overwrite key\n" | ||
331 | |||
332 | void | ||
333 | compare(db1, db2) | ||
334 | DBT *db1, *db2; | ||
335 | { | ||
336 | register size_t len; | ||
337 | register u_char *p1, *p2; | ||
338 | |||
339 | if (db1->size != db2->size) | ||
340 | printf("compare failed: key->data len %lu != data len %lu\n", | ||
341 | db1->size, db2->size); | ||
342 | |||
343 | len = MINIMUM(db1->size, db2->size); | ||
344 | for (p1 = db1->data, p2 = db2->data; len--;) | ||
345 | if (*p1++ != *p2++) { | ||
346 | printf("compare failed at offset %ld\n", | ||
347 | p1 - (u_char *)db1->data); | ||
348 | break; | ||
349 | } | ||
350 | } | ||
351 | |||
352 | void | ||
353 | get(dbp, kp) | ||
354 | DB *dbp; | ||
355 | DBT *kp; | ||
356 | { | ||
357 | DBT data; | ||
358 | |||
359 | switch (dbp->get(dbp, kp, &data, flags)) { | ||
360 | case 0: | ||
361 | (void)write(ofd, data.data, data.size); | ||
362 | if (ofd == STDOUT_FILENO) | ||
363 | (void)write(ofd, "\n", 1); | ||
364 | break; | ||
365 | case -1: | ||
366 | dberr("line %lu: get: %s", lineno, strerror(errno)); | ||
367 | /* NOTREACHED */ | ||
368 | case 1: | ||
369 | #define NOSUCHKEY "get failed, no such key\n" | ||
370 | if (ofd != STDOUT_FILENO) | ||
371 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
372 | else | ||
373 | (void)fprintf(stderr, "%lu: %.*s: %s", lineno, | ||
374 | MINIMUM((int)kp->size, 20), kp->data, NOSUCHKEY); | ||
375 | #undef NOSUCHKEY | ||
376 | break; | ||
377 | } | ||
378 | } | ||
379 | |||
380 | void | ||
381 | getdata(dbp, kp, dp) | ||
382 | DB *dbp; | ||
383 | DBT *kp, *dp; | ||
384 | { | ||
385 | switch (dbp->get(dbp, kp, dp, flags)) { | ||
386 | case 0: | ||
387 | return; | ||
388 | case -1: | ||
389 | dberr("line %lu: getdata: %s", lineno, strerror(errno)); | ||
390 | /* NOTREACHED */ | ||
391 | case 1: | ||
392 | dberr("line %lu: getdata failed, no such key", lineno); | ||
393 | /* NOTREACHED */ | ||
394 | } | ||
395 | } | ||
396 | |||
397 | void | ||
398 | put(dbp, kp, dp) | ||
399 | DB *dbp; | ||
400 | DBT *kp, *dp; | ||
401 | { | ||
402 | switch (dbp->put(dbp, kp, dp, flags)) { | ||
403 | case 0: | ||
404 | break; | ||
405 | case -1: | ||
406 | dberr("line %lu: put: %s", lineno, strerror(errno)); | ||
407 | /* NOTREACHED */ | ||
408 | case 1: | ||
409 | (void)write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1); | ||
410 | break; | ||
411 | } | ||
412 | } | ||
413 | |||
414 | void | ||
415 | rem(dbp, kp) | ||
416 | DB *dbp; | ||
417 | DBT *kp; | ||
418 | { | ||
419 | switch (dbp->del(dbp, kp, flags)) { | ||
420 | case 0: | ||
421 | break; | ||
422 | case -1: | ||
423 | dberr("line %lu: rem: %s", lineno, strerror(errno)); | ||
424 | /* NOTREACHED */ | ||
425 | case 1: | ||
426 | #define NOSUCHKEY "rem failed, no such key\n" | ||
427 | if (ofd != STDOUT_FILENO) | ||
428 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
429 | else if (flags != R_CURSOR) | ||
430 | (void)fprintf(stderr, "%lu: %.*s: %s", lineno, | ||
431 | MINIMUM((int)kp->size, 20), kp->data, NOSUCHKEY); | ||
432 | else | ||
433 | (void)fprintf(stderr, | ||
434 | "%lu: rem of cursor failed\n", lineno); | ||
435 | #undef NOSUCHKEY | ||
436 | break; | ||
437 | } | ||
438 | } | ||
439 | |||
440 | void | ||
441 | synk(dbp) | ||
442 | DB *dbp; | ||
443 | { | ||
444 | switch (dbp->sync(dbp, flags)) { | ||
445 | case 0: | ||
446 | break; | ||
447 | case -1: | ||
448 | dberr("line %lu: synk: %s", lineno, strerror(errno)); | ||
449 | /* NOTREACHED */ | ||
450 | } | ||
451 | } | ||
452 | |||
453 | void | ||
454 | seq(dbp, kp) | ||
455 | DB *dbp; | ||
456 | DBT *kp; | ||
457 | { | ||
458 | DBT data; | ||
459 | |||
460 | switch (dbp->seq(dbp, kp, &data, flags)) { | ||
461 | case 0: | ||
462 | (void)write(ofd, data.data, data.size); | ||
463 | if (ofd == STDOUT_FILENO) | ||
464 | (void)write(ofd, "\n", 1); | ||
465 | break; | ||
466 | case -1: | ||
467 | dberr("line %lu: seq: %s", lineno, strerror(errno)); | ||
468 | /* NOTREACHED */ | ||
469 | case 1: | ||
470 | #define NOSUCHKEY "seq failed, no such key\n" | ||
471 | if (ofd != STDOUT_FILENO) | ||
472 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
473 | else if (flags == R_CURSOR) | ||
474 | (void)fprintf(stderr, "%lu: %.*s: %s", lineno, | ||
475 | MINIMUM((int)kp->size, 20), kp->data, NOSUCHKEY); | ||
476 | else | ||
477 | (void)fprintf(stderr, | ||
478 | "%lu: seq (%s) failed\n", lineno, sflags(flags)); | ||
479 | #undef NOSUCHKEY | ||
480 | break; | ||
481 | } | ||
482 | } | ||
483 | |||
484 | void | ||
485 | dump(dbp, rev) | ||
486 | DB *dbp; | ||
487 | int rev; | ||
488 | { | ||
489 | DBT key, data; | ||
490 | int flags, nflags; | ||
491 | |||
492 | if (rev) { | ||
493 | flags = R_LAST; | ||
494 | nflags = R_PREV; | ||
495 | } else { | ||
496 | flags = R_FIRST; | ||
497 | nflags = R_NEXT; | ||
498 | } | ||
499 | for (;; flags = nflags) | ||
500 | switch (dbp->seq(dbp, &key, &data, flags)) { | ||
501 | case 0: | ||
502 | (void)write(ofd, data.data, data.size); | ||
503 | if (ofd == STDOUT_FILENO) | ||
504 | (void)write(ofd, "\n", 1); | ||
505 | break; | ||
506 | case 1: | ||
507 | goto done; | ||
508 | case -1: | ||
509 | dberr("line %lu: (dump) seq: %s", | ||
510 | lineno, strerror(errno)); | ||
511 | /* NOTREACHED */ | ||
512 | } | ||
513 | done: return; | ||
514 | } | ||
515 | |||
516 | u_int | ||
517 | setflags(s) | ||
518 | char *s; | ||
519 | { | ||
520 | char *p; | ||
521 | |||
522 | for (; isspace((unsigned char)*s); ++s); | ||
523 | if (*s == '\n' || *s == '\0') | ||
524 | return (0); | ||
525 | if ((p = strchr(s, '\n')) != NULL) | ||
526 | *p = '\0'; | ||
527 | if (!strcmp(s, "R_CURSOR")) return (R_CURSOR); | ||
528 | if (!strcmp(s, "R_FIRST")) return (R_FIRST); | ||
529 | if (!strcmp(s, "R_IAFTER")) return (R_IAFTER); | ||
530 | if (!strcmp(s, "R_IBEFORE")) return (R_IBEFORE); | ||
531 | if (!strcmp(s, "R_LAST")) return (R_LAST); | ||
532 | if (!strcmp(s, "R_NEXT")) return (R_NEXT); | ||
533 | if (!strcmp(s, "R_NOOVERWRITE")) return (R_NOOVERWRITE); | ||
534 | if (!strcmp(s, "R_PREV")) return (R_PREV); | ||
535 | if (!strcmp(s, "R_SETCURSOR")) return (R_SETCURSOR); | ||
536 | |||
537 | dberr("line %lu: %s: unknown flag", lineno, s); | ||
538 | /* NOTREACHED */ | ||
539 | } | ||
540 | |||
541 | char * | ||
542 | sflags(flags) | ||
543 | int flags; | ||
544 | { | ||
545 | switch (flags) { | ||
546 | case R_CURSOR: return ("R_CURSOR"); | ||
547 | case R_FIRST: return ("R_FIRST"); | ||
548 | case R_IAFTER: return ("R_IAFTER"); | ||
549 | case R_IBEFORE: return ("R_IBEFORE"); | ||
550 | case R_LAST: return ("R_LAST"); | ||
551 | case R_NEXT: return ("R_NEXT"); | ||
552 | case R_NOOVERWRITE: return ("R_NOOVERWRITE"); | ||
553 | case R_PREV: return ("R_PREV"); | ||
554 | case R_SETCURSOR: return ("R_SETCURSOR"); | ||
555 | } | ||
556 | |||
557 | return ("UNKNOWN!"); | ||
558 | } | ||
559 | |||
560 | DBTYPE | ||
561 | dbtype(s) | ||
562 | char *s; | ||
563 | { | ||
564 | if (!strcmp(s, "btree")) | ||
565 | return (DB_BTREE); | ||
566 | if (!strcmp(s, "hash")) | ||
567 | return (DB_HASH); | ||
568 | if (!strcmp(s, "recno")) | ||
569 | return (DB_RECNO); | ||
570 | dberr("%s: unknown type (use btree, hash or recno)", s); | ||
571 | /* NOTREACHED */ | ||
572 | } | ||
573 | |||
574 | void * | ||
575 | setinfo(type, s) | ||
576 | DBTYPE type; | ||
577 | char *s; | ||
578 | { | ||
579 | static BTREEINFO ib; | ||
580 | static HASHINFO ih; | ||
581 | static RECNOINFO rh; | ||
582 | char *eq; | ||
583 | |||
584 | if ((eq = strchr(s, '=')) == NULL) | ||
585 | dberr("%s: illegal structure set statement", s); | ||
586 | *eq++ = '\0'; | ||
587 | if (!isdigit((unsigned char)*eq)) | ||
588 | dberr("%s: structure set statement must be a number", s); | ||
589 | |||
590 | switch (type) { | ||
591 | case DB_BTREE: | ||
592 | if (!strcmp("flags", s)) { | ||
593 | ib.flags = atoi(eq); | ||
594 | return (&ib); | ||
595 | } | ||
596 | if (!strcmp("cachesize", s)) { | ||
597 | ib.cachesize = atoi(eq); | ||
598 | return (&ib); | ||
599 | } | ||
600 | if (!strcmp("maxkeypage", s)) { | ||
601 | ib.maxkeypage = atoi(eq); | ||
602 | return (&ib); | ||
603 | } | ||
604 | if (!strcmp("minkeypage", s)) { | ||
605 | ib.minkeypage = atoi(eq); | ||
606 | return (&ib); | ||
607 | } | ||
608 | if (!strcmp("lorder", s)) { | ||
609 | ib.lorder = atoi(eq); | ||
610 | return (&ib); | ||
611 | } | ||
612 | if (!strcmp("psize", s)) { | ||
613 | ib.psize = atoi(eq); | ||
614 | return (&ib); | ||
615 | } | ||
616 | break; | ||
617 | case DB_HASH: | ||
618 | if (!strcmp("bsize", s)) { | ||
619 | ih.bsize = atoi(eq); | ||
620 | return (&ih); | ||
621 | } | ||
622 | if (!strcmp("ffactor", s)) { | ||
623 | ih.ffactor = atoi(eq); | ||
624 | return (&ih); | ||
625 | } | ||
626 | if (!strcmp("nelem", s)) { | ||
627 | ih.nelem = atoi(eq); | ||
628 | return (&ih); | ||
629 | } | ||
630 | if (!strcmp("cachesize", s)) { | ||
631 | ih.cachesize = atoi(eq); | ||
632 | return (&ih); | ||
633 | } | ||
634 | if (!strcmp("lorder", s)) { | ||
635 | ih.lorder = atoi(eq); | ||
636 | return (&ih); | ||
637 | } | ||
638 | break; | ||
639 | case DB_RECNO: | ||
640 | if (!strcmp("flags", s)) { | ||
641 | rh.flags = atoi(eq); | ||
642 | return (&rh); | ||
643 | } | ||
644 | if (!strcmp("cachesize", s)) { | ||
645 | rh.cachesize = atoi(eq); | ||
646 | return (&rh); | ||
647 | } | ||
648 | if (!strcmp("lorder", s)) { | ||
649 | rh.lorder = atoi(eq); | ||
650 | return (&rh); | ||
651 | } | ||
652 | if (!strcmp("reclen", s)) { | ||
653 | rh.reclen = atoi(eq); | ||
654 | return (&rh); | ||
655 | } | ||
656 | if (!strcmp("bval", s)) { | ||
657 | rh.bval = atoi(eq); | ||
658 | return (&rh); | ||
659 | } | ||
660 | if (!strcmp("psize", s)) { | ||
661 | rh.psize = atoi(eq); | ||
662 | return (&rh); | ||
663 | } | ||
664 | break; | ||
665 | } | ||
666 | dberr("%s: unknown structure value", s); | ||
667 | /* NOTREACHED */ | ||
668 | } | ||
669 | |||
670 | void * | ||
671 | rfile(name, lenp) | ||
672 | char *name; | ||
673 | size_t *lenp; | ||
674 | { | ||
675 | struct stat sb; | ||
676 | void *p; | ||
677 | int fd; | ||
678 | char *np; | ||
679 | |||
680 | for (; isspace((unsigned char)*name); ++name); | ||
681 | if ((np = strchr(name, '\n')) != NULL) | ||
682 | *np = '\0'; | ||
683 | if ((fd = open(name, O_RDONLY)) < 0 || | ||
684 | fstat(fd, &sb)) | ||
685 | dberr("%s: %s\n", name, strerror(errno)); | ||
686 | if (sb.st_size > (off_t)INT_MAX) | ||
687 | dberr("%s: %s\n", name, strerror(E2BIG)); | ||
688 | if ((p = (void *)malloc((u_int)sb.st_size)) == NULL) | ||
689 | dberr("%s", strerror(errno)); | ||
690 | (void)read(fd, p, (int)sb.st_size); | ||
691 | *lenp = sb.st_size; | ||
692 | (void)close(fd); | ||
693 | return (p); | ||
694 | } | ||
695 | |||
696 | void * | ||
697 | xmalloc(text, len) | ||
698 | char *text; | ||
699 | size_t len; | ||
700 | { | ||
701 | void *p; | ||
702 | |||
703 | if ((p = (void *)malloc(len)) == NULL) | ||
704 | dberr("%s", strerror(errno)); | ||
705 | memmove(p, text, len); | ||
706 | return (p); | ||
707 | } | ||
708 | |||
709 | void __dead | ||
710 | usage() | ||
711 | { | ||
712 | (void)fprintf(stderr, | ||
713 | "usage: dbtest [-l] [-f file] [-i info] [-o file] type script\n"); | ||
714 | exit(1); | ||
715 | } | ||
716 | |||
717 | void __dead | ||
718 | dberr(const char *fmt, ...) | ||
719 | { | ||
720 | va_list ap; | ||
721 | |||
722 | va_start(ap, fmt); | ||
723 | (void)fprintf(stderr, "dbtest: "); | ||
724 | (void)vfprintf(stderr, fmt, ap); | ||
725 | va_end(ap); | ||
726 | (void)fprintf(stderr, "\n"); | ||
727 | exit(1); | ||
728 | /* NOTREACHED */ | ||
729 | } | ||
diff --git a/src/regress/lib/libc/db/run.test b/src/regress/lib/libc/db/run.test deleted file mode 100644 index 0d6837e360..0000000000 --- a/src/regress/lib/libc/db/run.test +++ /dev/null | |||
@@ -1,707 +0,0 @@ | |||
1 | #!/bin/sh - | ||
2 | # | ||
3 | # $OpenBSD: run.test,v 1.3 2001/01/29 02:05:41 niklas Exp $ | ||
4 | # $NetBSD: run.test,v 1.8 1996/05/03 21:57:51 cgd Exp $ | ||
5 | # @(#)run.test 8.10 (Berkeley) 7/26/94 | ||
6 | # | ||
7 | |||
8 | # db regression tests | ||
9 | main() | ||
10 | { | ||
11 | |||
12 | PROG=./dbtest | ||
13 | TMP1=t1 | ||
14 | TMP2=t2 | ||
15 | TMP3=t3 | ||
16 | |||
17 | if [ -f /usr/share/dict/words ]; then | ||
18 | DICT=/usr/share/dict/words | ||
19 | elif [ -f /usr/dict/words ]; then | ||
20 | DICT=/usr/dict/words | ||
21 | else | ||
22 | echo 'run.test: no dictionary' | ||
23 | exit 1 | ||
24 | fi | ||
25 | |||
26 | if [ $# -eq 0 ]; then | ||
27 | for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do | ||
28 | test$t | ||
29 | done | ||
30 | else | ||
31 | while [ $# -gt 0 ] | ||
32 | do case "$1" in | ||
33 | test*) | ||
34 | $1;; | ||
35 | [0-9]*) | ||
36 | test$1;; | ||
37 | btree) | ||
38 | for t in 1 2 3 7 8 9 10 12 13; do | ||
39 | test$t | ||
40 | done;; | ||
41 | hash) | ||
42 | for t in 1 2 3 8 13 20; do | ||
43 | test$t | ||
44 | done;; | ||
45 | recno) | ||
46 | for t in 1 2 3 4 5 6 7 10 11; do | ||
47 | test$t | ||
48 | done;; | ||
49 | *) | ||
50 | echo "run.test: unknown test $1" | ||
51 | echo "usage: run.test test# | type" | ||
52 | exit 1 | ||
53 | esac | ||
54 | shift | ||
55 | done | ||
56 | fi | ||
57 | rm -f $TMP1 $TMP2 $TMP3 | ||
58 | exit 0 | ||
59 | } | ||
60 | |||
61 | # Take the first hundred entries in the dictionary, and make them | ||
62 | # be key/data pairs. | ||
63 | test1() | ||
64 | { | ||
65 | echo "Test 1: btree, hash: small key, small data pairs" | ||
66 | sed 200q $DICT > $TMP1 | ||
67 | for type in btree hash; do | ||
68 | rm -f $TMP2 $TMP3 | ||
69 | for i in `sed 200q $DICT`; do | ||
70 | echo p | ||
71 | echo k$i | ||
72 | echo d$i | ||
73 | echo g | ||
74 | echo k$i | ||
75 | done > $TMP2 | ||
76 | $PROG -o $TMP3 $type $TMP2 | ||
77 | if (cmp -s $TMP1 $TMP3) ; then : | ||
78 | else | ||
79 | echo "test1: type $type: failed" | ||
80 | exit 1 | ||
81 | fi | ||
82 | done | ||
83 | echo "Test 1: recno: small key, small data pairs" | ||
84 | rm -f $TMP2 $TMP3 | ||
85 | sed 200q $DICT | | ||
86 | awk '{ | ||
87 | ++i; | ||
88 | printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); | ||
89 | }' > $TMP2 | ||
90 | $PROG -o $TMP3 recno $TMP2 | ||
91 | if (cmp -s $TMP1 $TMP3) ; then : | ||
92 | else | ||
93 | echo "test1: type recno: failed" | ||
94 | exit 1 | ||
95 | fi | ||
96 | } | ||
97 | |||
98 | # Take the first 200 entries in the dictionary, and give them | ||
99 | # each a medium size data entry. | ||
100 | test2() | ||
101 | { | ||
102 | echo "Test 2: btree, hash: small key, medium data pairs" | ||
103 | mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
104 | echo $mdata | | ||
105 | awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1 | ||
106 | for type in hash btree; do | ||
107 | rm -f $TMP2 $TMP3 | ||
108 | for i in `sed 200q $DICT`; do | ||
109 | echo p | ||
110 | echo k$i | ||
111 | echo d$mdata | ||
112 | echo g | ||
113 | echo k$i | ||
114 | done > $TMP2 | ||
115 | $PROG -o $TMP3 $type $TMP2 | ||
116 | if (cmp -s $TMP1 $TMP3) ; then : | ||
117 | else | ||
118 | echo "test2: type $type: failed" | ||
119 | exit 1 | ||
120 | fi | ||
121 | done | ||
122 | echo "Test 2: recno: small key, medium data pairs" | ||
123 | rm -f $TMP2 $TMP3 | ||
124 | echo $mdata | | ||
125 | awk '{ for (i = 1; i < 201; ++i) | ||
126 | printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); | ||
127 | }' > $TMP2 | ||
128 | $PROG -o $TMP3 recno $TMP2 | ||
129 | if (cmp -s $TMP1 $TMP3) ; then : | ||
130 | else | ||
131 | echo "test2: type recno: failed" | ||
132 | exit 1 | ||
133 | fi | ||
134 | } | ||
135 | |||
136 | # Insert the programs in /bin with their paths as their keys. | ||
137 | test3() | ||
138 | { | ||
139 | echo "Test 3: hash: small key, big data pairs" | ||
140 | rm -f $TMP1 | ||
141 | (find /bin -type f -print | xargs cat) > $TMP1 | ||
142 | for type in hash; do | ||
143 | rm -f $TMP2 $TMP3 | ||
144 | for i in `find /bin -type f -print`; do | ||
145 | echo p | ||
146 | echo k$i | ||
147 | echo D$i | ||
148 | echo g | ||
149 | echo k$i | ||
150 | done > $TMP2 | ||
151 | $PROG -o $TMP3 $type $TMP2 | ||
152 | if (cmp -s $TMP1 $TMP3) ; then : | ||
153 | else | ||
154 | echo "test3: $type: failed" | ||
155 | exit 1 | ||
156 | fi | ||
157 | done | ||
158 | echo "Test 3: btree: small key, big data pairs" | ||
159 | for psize in 512 16384 65536; do | ||
160 | echo " page size $psize" | ||
161 | for type in btree; do | ||
162 | rm -f $TMP2 $TMP3 | ||
163 | for i in `find /bin -type f -print`; do | ||
164 | echo p | ||
165 | echo k$i | ||
166 | echo D$i | ||
167 | echo g | ||
168 | echo k$i | ||
169 | done > $TMP2 | ||
170 | $PROG -i psize=$psize -o $TMP3 $type $TMP2 | ||
171 | if (cmp -s $TMP1 $TMP3) ; then : | ||
172 | else | ||
173 | echo "test3: $type: page size $psize: failed" | ||
174 | exit 1 | ||
175 | fi | ||
176 | done | ||
177 | done | ||
178 | echo "Test 3: recno: big data pairs" | ||
179 | rm -f $TMP2 $TMP3 | ||
180 | find /bin -type f -print | | ||
181 | awk '{ | ||
182 | ++i; | ||
183 | printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i); | ||
184 | }' > $TMP2 | ||
185 | for psize in 512 16384 65536; do | ||
186 | echo " page size $psize" | ||
187 | $PROG -i psize=$psize -o $TMP3 recno $TMP2 | ||
188 | if (cmp -s $TMP1 $TMP3) ; then : | ||
189 | else | ||
190 | echo "test3: recno: page size $psize: failed" | ||
191 | exit 1 | ||
192 | fi | ||
193 | done | ||
194 | } | ||
195 | |||
196 | # Do random recno entries. | ||
197 | test4() | ||
198 | { | ||
199 | echo "Test 4: recno: random entries" | ||
200 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
201 | awk '{ | ||
202 | for (i = 37; i <= 37 + 88 * 17; i += 17) { | ||
203 | if (i % 41) | ||
204 | s = substr($0, 1, i % 41); | ||
205 | else | ||
206 | s = substr($0, 1); | ||
207 | printf("input key %d: %s\n", i, s); | ||
208 | } | ||
209 | for (i = 1; i <= 15; ++i) { | ||
210 | if (i % 41) | ||
211 | s = substr($0, 1, i % 41); | ||
212 | else | ||
213 | s = substr($0, 1); | ||
214 | printf("input key %d: %s\n", i, s); | ||
215 | } | ||
216 | for (i = 19234; i <= 19234 + 61 * 27; i += 27) { | ||
217 | if (i % 41) | ||
218 | s = substr($0, 1, i % 41); | ||
219 | else | ||
220 | s = substr($0, 1); | ||
221 | printf("input key %d: %s\n", i, s); | ||
222 | } | ||
223 | exit | ||
224 | }' > $TMP1 | ||
225 | rm -f $TMP2 $TMP3 | ||
226 | cat $TMP1 | | ||
227 | awk 'BEGIN { | ||
228 | i = 37; | ||
229 | incr = 17; | ||
230 | } | ||
231 | { | ||
232 | printf("p\nk%d\nd%s\n", i, $0); | ||
233 | if (i == 19234 + 61 * 27) | ||
234 | exit; | ||
235 | if (i == 37 + 88 * 17) { | ||
236 | i = 1; | ||
237 | incr = 1; | ||
238 | } else if (i == 15) { | ||
239 | i = 19234; | ||
240 | incr = 27; | ||
241 | } else | ||
242 | i += incr; | ||
243 | } | ||
244 | END { | ||
245 | for (i = 37; i <= 37 + 88 * 17; i += 17) | ||
246 | printf("g\nk%d\n", i); | ||
247 | for (i = 1; i <= 15; ++i) | ||
248 | printf("g\nk%d\n", i); | ||
249 | for (i = 19234; i <= 19234 + 61 * 27; i += 27) | ||
250 | printf("g\nk%d\n", i); | ||
251 | }' > $TMP2 | ||
252 | $PROG -o $TMP3 recno $TMP2 | ||
253 | if (cmp -s $TMP1 $TMP3) ; then : | ||
254 | else | ||
255 | echo "test4: type recno: failed" | ||
256 | exit 1 | ||
257 | fi | ||
258 | } | ||
259 | |||
260 | # Do reverse order recno entries. | ||
261 | test5() | ||
262 | { | ||
263 | echo "Test 5: recno: reverse order entries" | ||
264 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
265 | awk ' { | ||
266 | for (i = 1500; i; --i) { | ||
267 | if (i % 34) | ||
268 | s = substr($0, 1, i % 34); | ||
269 | else | ||
270 | s = substr($0, 1); | ||
271 | printf("input key %d: %s\n", i, s); | ||
272 | } | ||
273 | exit; | ||
274 | }' > $TMP1 | ||
275 | rm -f $TMP2 $TMP3 | ||
276 | cat $TMP1 | | ||
277 | awk 'BEGIN { | ||
278 | i = 1500; | ||
279 | } | ||
280 | { | ||
281 | printf("p\nk%d\nd%s\n", i, $0); | ||
282 | --i; | ||
283 | } | ||
284 | END { | ||
285 | for (i = 1500; i; --i) | ||
286 | printf("g\nk%d\n", i); | ||
287 | }' > $TMP2 | ||
288 | $PROG -o $TMP3 recno $TMP2 | ||
289 | if (cmp -s $TMP1 $TMP3) ; then : | ||
290 | else | ||
291 | echo "test5: type recno: failed" | ||
292 | exit 1 | ||
293 | fi | ||
294 | } | ||
295 | |||
296 | # Do alternating order recno entries. | ||
297 | test6() | ||
298 | { | ||
299 | echo "Test 6: recno: alternating order entries" | ||
300 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
301 | awk ' { | ||
302 | for (i = 1; i < 1200; i += 2) { | ||
303 | if (i % 34) | ||
304 | s = substr($0, 1, i % 34); | ||
305 | else | ||
306 | s = substr($0, 1); | ||
307 | printf("input key %d: %s\n", i, s); | ||
308 | } | ||
309 | for (i = 2; i < 1200; i += 2) { | ||
310 | if (i % 34) | ||
311 | s = substr($0, 1, i % 34); | ||
312 | else | ||
313 | s = substr($0, 1); | ||
314 | printf("input key %d: %s\n", i, s); | ||
315 | } | ||
316 | exit; | ||
317 | }' > $TMP1 | ||
318 | rm -f $TMP2 $TMP3 | ||
319 | cat $TMP1 | | ||
320 | awk 'BEGIN { | ||
321 | i = 1; | ||
322 | even = 0; | ||
323 | } | ||
324 | { | ||
325 | printf("p\nk%d\nd%s\n", i, $0); | ||
326 | i += 2; | ||
327 | if (i >= 1200) { | ||
328 | if (even == 1) | ||
329 | exit; | ||
330 | even = 1; | ||
331 | i = 2; | ||
332 | } | ||
333 | } | ||
334 | END { | ||
335 | for (i = 1; i < 1200; ++i) | ||
336 | printf("g\nk%d\n", i); | ||
337 | }' > $TMP2 | ||
338 | $PROG -o $TMP3 recno $TMP2 | ||
339 | sort -o $TMP1 $TMP1 | ||
340 | sort -o $TMP3 $TMP3 | ||
341 | if (cmp -s $TMP1 $TMP3) ; then : | ||
342 | else | ||
343 | echo "test6: type recno: failed" | ||
344 | exit 1 | ||
345 | fi | ||
346 | } | ||
347 | |||
348 | # Delete cursor record | ||
349 | test7() | ||
350 | { | ||
351 | echo "Test 7: btree, recno: delete cursor record" | ||
352 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
353 | awk '{ | ||
354 | for (i = 1; i <= 120; ++i) | ||
355 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
356 | printf("%05d: input key %d: %s\n", 120, 120, $0); | ||
357 | printf("seq failed, no such key\n"); | ||
358 | printf("%05d: input key %d: %s\n", 1, 1, $0); | ||
359 | printf("%05d: input key %d: %s\n", 2, 2, $0); | ||
360 | exit; | ||
361 | }' > $TMP1 | ||
362 | rm -f $TMP2 $TMP3 | ||
363 | |||
364 | for type in btree recno; do | ||
365 | cat $TMP1 | | ||
366 | awk '{ | ||
367 | if (i == 120) | ||
368 | exit; | ||
369 | printf("p\nk%d\nd%s\n", ++i, $0); | ||
370 | } | ||
371 | END { | ||
372 | printf("fR_NEXT\n"); | ||
373 | for (i = 1; i <= 120; ++i) | ||
374 | printf("s\n"); | ||
375 | printf("fR_CURSOR\ns\nk120\n"); | ||
376 | printf("r\n"); | ||
377 | printf("fR_NEXT\ns\n"); | ||
378 | printf("fR_CURSOR\ns\nk1\n"); | ||
379 | printf("r\n"); | ||
380 | printf("fR_FIRST\ns\n"); | ||
381 | }' > $TMP2 | ||
382 | $PROG -o $TMP3 recno $TMP2 | ||
383 | if (cmp -s $TMP1 $TMP3) ; then : | ||
384 | else | ||
385 | echo "test7: type $type: failed" | ||
386 | exit 1 | ||
387 | fi | ||
388 | done | ||
389 | } | ||
390 | |||
391 | # Make sure that overflow pages are reused. | ||
392 | test8() | ||
393 | { | ||
394 | echo "Test 8: btree, hash: repeated small key, big data pairs" | ||
395 | rm -f $TMP1 | ||
396 | echo "" | | ||
397 | awk 'BEGIN { | ||
398 | for (i = 1; i <= 10; ++i) { | ||
399 | printf("p\nkkey1\nD/bin/sh\n"); | ||
400 | printf("p\nkkey2\nD/bin/csh\n"); | ||
401 | if (i % 8 == 0) { | ||
402 | printf("c\nkkey2\nD/bin/csh\n"); | ||
403 | printf("c\nkkey1\nD/bin/sh\n"); | ||
404 | printf("e\t%d of 10 (comparison)\n", i); | ||
405 | } else | ||
406 | printf("e\t%d of 10 \n", i); | ||
407 | printf("r\nkkey1\nr\nkkey2\n"); | ||
408 | } | ||
409 | }' > $TMP1 | ||
410 | $PROG btree $TMP1 | ||
411 | # $PROG hash $TMP1 | ||
412 | # No explicit test for success. | ||
413 | } | ||
414 | |||
415 | # Test btree duplicate keys | ||
416 | test9() | ||
417 | { | ||
418 | echo "Test 9: btree: duplicate keys" | ||
419 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
420 | awk '{ | ||
421 | for (i = 1; i <= 543; ++i) | ||
422 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
423 | exit; | ||
424 | }' > $TMP1 | ||
425 | rm -f $TMP2 $TMP3 | ||
426 | |||
427 | for type in btree; do | ||
428 | cat $TMP1 | | ||
429 | awk '{ | ||
430 | if (i++ % 2) | ||
431 | printf("p\nkduplicatekey\nd%s\n", $0); | ||
432 | else | ||
433 | printf("p\nkunique%dkey\nd%s\n", i, $0); | ||
434 | } | ||
435 | END { | ||
436 | printf("o\n"); | ||
437 | }' > $TMP2 | ||
438 | $PROG -iflags=1 -o $TMP3 $type $TMP2 | ||
439 | sort -o $TMP3 $TMP3 | ||
440 | if (cmp -s $TMP1 $TMP3) ; then : | ||
441 | else | ||
442 | echo "test9: type $type: failed" | ||
443 | exit 1 | ||
444 | fi | ||
445 | done | ||
446 | } | ||
447 | |||
448 | # Test use of cursor flags without initialization | ||
449 | test10() | ||
450 | { | ||
451 | echo "Test 10: btree, recno: test cursor flag use" | ||
452 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
453 | awk '{ | ||
454 | for (i = 1; i <= 20; ++i) | ||
455 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
456 | exit; | ||
457 | }' > $TMP1 | ||
458 | rm -f $TMP2 $TMP3 | ||
459 | |||
460 | # Test that R_CURSOR doesn't succeed before cursor initialized | ||
461 | for type in btree recno; do | ||
462 | cat $TMP1 | | ||
463 | awk '{ | ||
464 | if (i == 10) | ||
465 | exit; | ||
466 | printf("p\nk%d\nd%s\n", ++i, $0); | ||
467 | } | ||
468 | END { | ||
469 | printf("fR_CURSOR\nr\n"); | ||
470 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); | ||
471 | }' > $TMP2 | ||
472 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 | ||
473 | if [ -s $TMP3 ] ; then | ||
474 | echo "Test 10: delete: R_CURSOR SHOULD HAVE FAILED" | ||
475 | exit 1 | ||
476 | fi | ||
477 | done | ||
478 | for type in btree recno; do | ||
479 | cat $TMP1 | | ||
480 | awk '{ | ||
481 | if (i == 10) | ||
482 | exit; | ||
483 | printf("p\nk%d\nd%s\n", ++i, $0); | ||
484 | } | ||
485 | END { | ||
486 | printf("fR_CURSOR\np\nk1\ndsome data\n"); | ||
487 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); | ||
488 | }' > $TMP2 | ||
489 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 | ||
490 | if [ -s $TMP3 ] ; then | ||
491 | echo "Test 10: put: R_CURSOR SHOULD HAVE FAILED" | ||
492 | exit 1 | ||
493 | fi | ||
494 | done | ||
495 | } | ||
496 | |||
497 | # Test insert in reverse order. | ||
498 | test11() | ||
499 | { | ||
500 | echo "Test 11: recno: reverse order insert" | ||
501 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
502 | awk '{ | ||
503 | for (i = 1; i <= 779; ++i) | ||
504 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
505 | exit; | ||
506 | }' > $TMP1 | ||
507 | rm -f $TMP2 $TMP3 | ||
508 | |||
509 | for type in recno; do | ||
510 | cat $TMP1 | | ||
511 | awk '{ | ||
512 | if (i == 0) { | ||
513 | i = 1; | ||
514 | printf("p\nk1\nd%s\n", $0); | ||
515 | printf("%s\n", "fR_IBEFORE"); | ||
516 | } else | ||
517 | printf("p\nk1\nd%s\n", $0); | ||
518 | } | ||
519 | END { | ||
520 | printf("or\n"); | ||
521 | }' > $TMP2 | ||
522 | $PROG -o $TMP3 $type $TMP2 | ||
523 | if (cmp -s $TMP1 $TMP3) ; then : | ||
524 | else | ||
525 | echo "test11: type $type: failed" | ||
526 | exit 1 | ||
527 | fi | ||
528 | done | ||
529 | } | ||
530 | |||
531 | # Take the first 20000 entries in the dictionary, reverse them, and give | ||
532 | # them each a small size data entry. Use a small page size to make sure | ||
533 | # the btree split code gets hammered. | ||
534 | test12() | ||
535 | { | ||
536 | echo "Test 12: btree: lots of keys, small page size" | ||
537 | mdata=abcdefghijklmnopqrstuvwxy | ||
538 | echo $mdata | | ||
539 | awk '{ for (i = 1; i < 20001; ++i) print $0 }' > $TMP1 | ||
540 | for type in btree; do | ||
541 | rm -f $TMP2 $TMP3 | ||
542 | for i in `sed 20000q $DICT | rev`; do | ||
543 | echo p | ||
544 | echo k$i | ||
545 | echo d$mdata | ||
546 | echo g | ||
547 | echo k$i | ||
548 | done > $TMP2 | ||
549 | $PROG -i psize=512 -o $TMP3 $type $TMP2 | ||
550 | if (cmp -s $TMP1 $TMP3) ; then : | ||
551 | else | ||
552 | echo "test12: type $type: failed" | ||
553 | exit 1 | ||
554 | fi | ||
555 | done | ||
556 | } | ||
557 | |||
558 | # Test different byte orders. | ||
559 | test13() | ||
560 | { | ||
561 | echo "Test 13: btree, hash: differing byte orders" | ||
562 | sed 50q $DICT > $TMP1 | ||
563 | for order in 1234 4321; do | ||
564 | for type in btree hash; do | ||
565 | rm -f byte.file $TMP2 $TMP3 | ||
566 | for i in `sed 50q $DICT`; do | ||
567 | echo p | ||
568 | echo k$i | ||
569 | echo d$i | ||
570 | echo g | ||
571 | echo k$i | ||
572 | done > $TMP2 | ||
573 | $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | ||
574 | if (cmp -s $TMP1 $TMP3) ; then : | ||
575 | else | ||
576 | echo "test13: $type/$order put failed" | ||
577 | exit 1 | ||
578 | fi | ||
579 | for i in `sed 50q $DICT`; do | ||
580 | echo g | ||
581 | echo k$i | ||
582 | done > $TMP2 | ||
583 | $PROG -s \ | ||
584 | -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | ||
585 | if (cmp -s $TMP1 $TMP3) ; then : | ||
586 | else | ||
587 | echo "test13: $type/$order get failed" | ||
588 | exit 1 | ||
589 | fi | ||
590 | done | ||
591 | done | ||
592 | rm -f byte.file | ||
593 | } | ||
594 | |||
595 | # Try a variety of bucketsizes and fill factors for hashing | ||
596 | test20() | ||
597 | { | ||
598 | echo\ | ||
599 | "Test 20: hash: bucketsize, fill factor; nelem 25000 cachesize 65536" | ||
600 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
601 | awk '{ | ||
602 | for (i = 1; i <= 10000; ++i) { | ||
603 | if (i % 34) | ||
604 | s = substr($0, 1, i % 34); | ||
605 | else | ||
606 | s = substr($0, 1); | ||
607 | printf("%s\n", s); | ||
608 | } | ||
609 | exit; | ||
610 | }' > $TMP1 | ||
611 | sed 10000q $DICT | | ||
612 | awk 'BEGIN { | ||
613 | ds="abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | ||
614 | } | ||
615 | { | ||
616 | if (++i % 34) | ||
617 | s = substr(ds, 1, i % 34); | ||
618 | else | ||
619 | s = substr(ds, 1); | ||
620 | printf("p\nk%s\nd%s\n", $0, s); | ||
621 | }' > $TMP2 | ||
622 | sed 10000q $DICT | | ||
623 | awk '{ | ||
624 | ++i; | ||
625 | printf("g\nk%s\n", $0); | ||
626 | }' >> $TMP2 | ||
627 | bsize=256 | ||
628 | for ffactor in 11 14 21; do | ||
629 | echo " bucketsize $bsize, fill factor $ffactor" | ||
630 | $PROG -o$TMP3 \ | ||
631 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
632 | hash $TMP2 | ||
633 | if (cmp -s $TMP1 $TMP3) ; then : | ||
634 | else | ||
635 | echo "test20: type hash:\ | ||
636 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
637 | exit 1 | ||
638 | fi | ||
639 | done | ||
640 | bsize=512 | ||
641 | for ffactor in 21 28 43; do | ||
642 | echo " bucketsize $bsize, fill factor $ffactor" | ||
643 | $PROG -o$TMP3 \ | ||
644 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
645 | hash $TMP2 | ||
646 | if (cmp -s $TMP1 $TMP3) ; then : | ||
647 | else | ||
648 | echo "test20: type hash:\ | ||
649 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
650 | exit 1 | ||
651 | fi | ||
652 | done | ||
653 | bsize=1024 | ||
654 | for ffactor in 43 57 85; do | ||
655 | echo " bucketsize $bsize, fill factor $ffactor" | ||
656 | $PROG -o$TMP3 \ | ||
657 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
658 | hash $TMP2 | ||
659 | if (cmp -s $TMP1 $TMP3) ; then : | ||
660 | else | ||
661 | echo "test20: type hash:\ | ||
662 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
663 | exit 1 | ||
664 | fi | ||
665 | done | ||
666 | bsize=2048 | ||
667 | for ffactor in 85 114 171; do | ||
668 | echo " bucketsize $bsize, fill factor $ffactor" | ||
669 | $PROG -o$TMP3 \ | ||
670 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
671 | hash $TMP2 | ||
672 | if (cmp -s $TMP1 $TMP3) ; then : | ||
673 | else | ||
674 | echo "test20: type hash:\ | ||
675 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
676 | exit 1 | ||
677 | fi | ||
678 | done | ||
679 | bsize=4096 | ||
680 | for ffactor in 171 228 341; do | ||
681 | echo " bucketsize $bsize, fill factor $ffactor" | ||
682 | $PROG -o$TMP3 \ | ||
683 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
684 | hash $TMP2 | ||
685 | if (cmp -s $TMP1 $TMP3) ; then : | ||
686 | else | ||
687 | echo "test20: type hash:\ | ||
688 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
689 | exit 1 | ||
690 | fi | ||
691 | done | ||
692 | bsize=8192 | ||
693 | for ffactor in 341 455 683; do | ||
694 | echo " bucketsize $bsize, fill factor $ffactor" | ||
695 | $PROG -o$TMP3 \ | ||
696 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
697 | hash $TMP2 | ||
698 | if (cmp -s $TMP1 $TMP3) ; then : | ||
699 | else | ||
700 | echo "test20: type hash:\ | ||
701 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
702 | exit 1 | ||
703 | fi | ||
704 | done | ||
705 | } | ||
706 | |||
707 | main $* | ||
diff --git a/src/regress/lib/libc/dirname/Makefile b/src/regress/lib/libc/dirname/Makefile deleted file mode 100644 index fc152df954..0000000000 --- a/src/regress/lib/libc/dirname/Makefile +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | PROG=dirname_test | ||
2 | |||
3 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/dirname/dirname_test.c b/src/regress/lib/libc/dirname/dirname_test.c deleted file mode 100644 index 250b4def66..0000000000 --- a/src/regress/lib/libc/dirname/dirname_test.c +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2007 Bret S. Lambert <blambert@gsipt.net> | ||
3 | * | ||
4 | * Public domain. | ||
5 | */ | ||
6 | |||
7 | #include <libgen.h> | ||
8 | #include <stdio.h> | ||
9 | #include <string.h> | ||
10 | #include <limits.h> | ||
11 | #include <errno.h> | ||
12 | #include <err.h> | ||
13 | |||
14 | int | ||
15 | main(void) | ||
16 | { | ||
17 | char path[2 * PATH_MAX]; | ||
18 | char dname[128]; | ||
19 | const char *dir = "junk"; | ||
20 | const char *fname = "/file.name.ext"; | ||
21 | char *str; | ||
22 | int i; | ||
23 | |||
24 | /* Test normal functioning */ | ||
25 | strlcpy(path, "/", sizeof(path)); | ||
26 | strlcpy(dname, "/", sizeof(dname)); | ||
27 | strlcat(path, dir, sizeof(path)); | ||
28 | strlcat(dname, dir, sizeof(dname)); | ||
29 | strlcat(path, fname, sizeof(path)); | ||
30 | str = dirname(path); | ||
31 | if (strcmp(str, dname) != 0) | ||
32 | errx(1, "0: dirname(%s) = %s != %s", path, str, dname); | ||
33 | |||
34 | /* | ||
35 | * There are four states that require special handling: | ||
36 | * | ||
37 | * 1) path is NULL | ||
38 | * 2) path is the empty string | ||
39 | * 3) path is composed entirely of slashes | ||
40 | * 4) the resulting name is larger than PATH_MAX | ||
41 | * | ||
42 | * The first two cases require that a pointer | ||
43 | * to the string "." be returned. | ||
44 | * | ||
45 | * The third case requires that a pointer | ||
46 | * to the string "/" be returned. | ||
47 | * | ||
48 | * The final case requires that NULL be returned | ||
49 | * and errno * be set to ENAMETOOLONG. | ||
50 | */ | ||
51 | /* Case 1 */ | ||
52 | str = dirname(NULL); | ||
53 | if (strcmp(str, ".") != 0) | ||
54 | errx(1, "1: dirname(NULL) = %s != .", str); | ||
55 | |||
56 | /* Case 2 */ | ||
57 | strlcpy(path, "", sizeof(path)); | ||
58 | str = dirname(path); | ||
59 | if (strcmp(str, ".") != 0) | ||
60 | errx(1, "2: dirname(%s) = %s != .", path, str); | ||
61 | |||
62 | /* Case 3 */ | ||
63 | for (i = 0; i < PATH_MAX - 1; i++) | ||
64 | strlcat(path, "/", sizeof(path)); /* path cleared above */ | ||
65 | str = dirname(path); | ||
66 | if (strcmp(str, "/") != 0) | ||
67 | errx(1, "3: dirname(%s) = %s != /", path, str); | ||
68 | |||
69 | /* Case 4 */ | ||
70 | strlcpy(path, "/", sizeof(path)); /* reset path */ | ||
71 | for (i = 0; i <= PATH_MAX; i += strlen(dir)) | ||
72 | strlcat(path, dir, sizeof(path)); | ||
73 | strlcat(path, fname, sizeof(path)); | ||
74 | str = dirname(path); | ||
75 | if (str != NULL) | ||
76 | errx(1, "4: dirname(%s) = %s != NULL", path, str); | ||
77 | if (errno != ENAMETOOLONG) | ||
78 | errx(1, "4: dirname(%s) sets errno to %d", path, errno); | ||
79 | |||
80 | return (0); | ||
81 | } | ||
diff --git a/src/regress/lib/libc/elf_aux_info/Makefile b/src/regress/lib/libc/elf_aux_info/Makefile deleted file mode 100644 index 58dc58a830..0000000000 --- a/src/regress/lib/libc/elf_aux_info/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | PROG=elf_aux_info | ||
2 | |||
3 | WARNINGS=yes | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/elf_aux_info/elf_aux_info.c b/src/regress/lib/libc/elf_aux_info/elf_aux_info.c deleted file mode 100644 index 14870e253c..0000000000 --- a/src/regress/lib/libc/elf_aux_info/elf_aux_info.c +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | #include <sys/auxv.h> | ||
2 | |||
3 | #include <errno.h> | ||
4 | #include <stdio.h> | ||
5 | |||
6 | int | ||
7 | main(void) | ||
8 | { | ||
9 | int ret = 0; | ||
10 | int a; | ||
11 | unsigned long b; | ||
12 | |||
13 | /* Should always succeed */ | ||
14 | if (elf_aux_info(AT_PAGESZ, &a, sizeof(a))) | ||
15 | ret |= 1; | ||
16 | else | ||
17 | fprintf(stderr, "AT_PAGESZ %d\n", a); | ||
18 | |||
19 | /* Wrong size */ | ||
20 | if (elf_aux_info(AT_PAGESZ, &b, sizeof(b)) != EINVAL) | ||
21 | ret |= 2; | ||
22 | |||
23 | /* Invalid request */ | ||
24 | if (elf_aux_info(-1, &a, sizeof(a)) != EINVAL) | ||
25 | ret |= 4; | ||
26 | |||
27 | /* Should either succeed or fail with ENOENT if not supported */ | ||
28 | switch (elf_aux_info(AT_HWCAP, &b, sizeof(b))) { | ||
29 | case 0: | ||
30 | fprintf(stderr, "AT_HWCAP %lx\n", b); | ||
31 | break; | ||
32 | case ENOENT: | ||
33 | break; | ||
34 | default: | ||
35 | ret |= 8; | ||
36 | } | ||
37 | |||
38 | /* Should either succeed or fail with ENOENT if not supported */ | ||
39 | switch (elf_aux_info(AT_HWCAP2, &b, sizeof(b))) { | ||
40 | case 0: | ||
41 | fprintf(stderr, "AT_HWCAP2 %lx\n", b); | ||
42 | break; | ||
43 | case ENOENT: | ||
44 | break; | ||
45 | default: | ||
46 | ret |= 16; | ||
47 | } | ||
48 | |||
49 | if (ret) | ||
50 | fprintf(stderr, "FAILED (status %x)\n", ret); | ||
51 | |||
52 | return ret; | ||
53 | } | ||
diff --git a/src/regress/lib/libc/env/Makefile b/src/regress/lib/libc/env/Makefile deleted file mode 100644 index 92e04369f4..0000000000 --- a/src/regress/lib/libc/env/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2010/08/23 22:34:37 millert Exp $ | ||
2 | |||
3 | PROG= envtest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/env/envtest.c b/src/regress/lib/libc/env/envtest.c deleted file mode 100644 index 79a5c0655f..0000000000 --- a/src/regress/lib/libc/env/envtest.c +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | /* $OpenBSD: envtest.c,v 1.3 2021/09/01 09:26:32 jasper Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2010 Todd C. Miller <millert@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <sys/types.h> | ||
20 | |||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | #include <unistd.h> | ||
25 | |||
26 | extern char **environ; | ||
27 | |||
28 | static int | ||
29 | count_instances(const char *name) | ||
30 | { | ||
31 | int count = 0; | ||
32 | size_t namelen; | ||
33 | char **ep; | ||
34 | |||
35 | namelen = strlen(name); | ||
36 | for (ep = environ; *ep != NULL; ep++) { | ||
37 | if (strncmp(name, *ep, namelen) == 0 && (*ep)[namelen] == '=') | ||
38 | count++; | ||
39 | } | ||
40 | |||
41 | return count; | ||
42 | } | ||
43 | |||
44 | static void | ||
45 | fake_env(void) | ||
46 | { | ||
47 | static char *fakenv[7]; | ||
48 | |||
49 | fakenv[0] = "HOME=/root"; | ||
50 | fakenv[1] = "USER=root"; | ||
51 | fakenv[2] = "LOGNAME=root"; | ||
52 | fakenv[3] = "SHELL=/bin/sh"; | ||
53 | fakenv[4] = "USER=root"; | ||
54 | fakenv[5] = NULL; | ||
55 | |||
56 | environ = fakenv; | ||
57 | } | ||
58 | |||
59 | int | ||
60 | main(int argc, char *argv[]) | ||
61 | { | ||
62 | char *buf; | ||
63 | int n, failures = 0; | ||
64 | size_t len, bufsize; | ||
65 | |||
66 | fake_env(); | ||
67 | n = count_instances("USER"); | ||
68 | if (n != 2) { | ||
69 | fprintf(stderr, "initial: %d instances of USER, expected %d\n", | ||
70 | n, 2); | ||
71 | failures++; | ||
72 | } | ||
73 | |||
74 | if (unsetenv("USER") != 0) { | ||
75 | fprintf(stderr, "unsetenv: failed to remove USER\n"); | ||
76 | failures++; | ||
77 | } | ||
78 | n = count_instances("USER"); | ||
79 | if (n != 0) { | ||
80 | fprintf(stderr, "unsetenv: %d instances of USER, expected %d\n", | ||
81 | n, 0); | ||
82 | failures++; | ||
83 | } | ||
84 | |||
85 | fake_env(); | ||
86 | if (setenv("USER", "nobody", 0) != 0) { | ||
87 | fprintf(stderr, "setenv: failed to set USER\n"); | ||
88 | failures++; | ||
89 | } | ||
90 | n = count_instances("USER"); | ||
91 | if (n != 2) { | ||
92 | fprintf(stderr, "setenv: %d instances of USER, expected %d\n", | ||
93 | n, 2); | ||
94 | failures++; | ||
95 | } | ||
96 | |||
97 | fake_env(); | ||
98 | if (setenv("USER", "nobody", 1) != 0) { | ||
99 | fprintf(stderr, "setenv: failed to set USER\n"); | ||
100 | failures++; | ||
101 | } | ||
102 | n = count_instances("USER"); | ||
103 | if (n != 1) { | ||
104 | fprintf(stderr, "setenv: %d instances of USER, expected %d\n", | ||
105 | n, 1); | ||
106 | failures++; | ||
107 | } | ||
108 | |||
109 | fake_env(); | ||
110 | if (putenv("USER=nobody") != 0) { | ||
111 | fprintf(stderr, "putenv: failed to set USER\n"); | ||
112 | failures++; | ||
113 | } | ||
114 | n = count_instances("USER"); | ||
115 | if (n != 1) { | ||
116 | fprintf(stderr, "putenv: %d instances of USER, expected %d\n", | ||
117 | n, 1); | ||
118 | failures++; | ||
119 | } | ||
120 | |||
121 | return failures; | ||
122 | } | ||
diff --git a/src/regress/lib/libc/explicit_bzero/Makefile b/src/regress/lib/libc/explicit_bzero/Makefile deleted file mode 100644 index cd514a43a1..0000000000 --- a/src/regress/lib/libc/explicit_bzero/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2014/06/12 22:01:55 matthew Exp $ | ||
2 | |||
3 | PROG= explicit_bzero | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/explicit_bzero/explicit_bzero.c b/src/regress/lib/libc/explicit_bzero/explicit_bzero.c deleted file mode 100644 index 496bafb208..0000000000 --- a/src/regress/lib/libc/explicit_bzero/explicit_bzero.c +++ /dev/null | |||
@@ -1,225 +0,0 @@ | |||
1 | /* $OpenBSD: explicit_bzero.c,v 1.9 2022/02/10 08:39:32 tb Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Google Inc. | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <assert.h> | ||
19 | #include <errno.h> | ||
20 | #include <signal.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | #include <unistd.h> | ||
24 | |||
25 | #define ASSERT_EQ(a, b) assert((a) == (b)) | ||
26 | #define ASSERT_NE(a, b) assert((a) != (b)) | ||
27 | #define ASSERT_GE(a, b) assert((a) >= (b)) | ||
28 | |||
29 | #if defined(__has_feature) | ||
30 | #if __has_feature(address_sanitizer) | ||
31 | #define __SANITIZE_ADDRESS__ | ||
32 | #endif | ||
33 | #endif | ||
34 | #ifdef __SANITIZE_ADDRESS__ | ||
35 | #define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) | ||
36 | #else | ||
37 | #define ATTRIBUTE_NO_SANITIZE_ADDRESS | ||
38 | #endif | ||
39 | |||
40 | /* 128 bits of random data. */ | ||
41 | static const char secret[16] = { | ||
42 | 0xa0, 0x6c, 0x0c, 0x81, 0xba, 0xd8, 0x5b, 0x0c, | ||
43 | 0xb0, 0xd6, 0xd4, 0xe3, 0xeb, 0x52, 0x5f, 0x96, | ||
44 | }; | ||
45 | |||
46 | enum { | ||
47 | SECRETCOUNT = 64, | ||
48 | SECRETBYTES = SECRETCOUNT * sizeof(secret) | ||
49 | }; | ||
50 | |||
51 | /* | ||
52 | * As of glibc 2.34, when _GNU_SOURCE is defined, SIGSTKSZ is no longer | ||
53 | * constant on Linux. SIGSTKSZ is redefined to sysconf (_SC_SIGSTKSZ). | ||
54 | */ | ||
55 | static char *altstack; | ||
56 | #define ALTSTACK_SIZE (SIGSTKSZ + SECRETBYTES) | ||
57 | |||
58 | static void | ||
59 | setup_stack(void) | ||
60 | { | ||
61 | altstack = calloc(1, ALTSTACK_SIZE); | ||
62 | ASSERT_NE(NULL, altstack); | ||
63 | |||
64 | const stack_t sigstk = { | ||
65 | .ss_sp = altstack, | ||
66 | .ss_size = ALTSTACK_SIZE | ||
67 | }; | ||
68 | |||
69 | ASSERT_EQ(0, sigaltstack(&sigstk, NULL)); | ||
70 | } | ||
71 | |||
72 | static void | ||
73 | cleanup_stack(void) | ||
74 | { | ||
75 | free(altstack); | ||
76 | } | ||
77 | |||
78 | static void | ||
79 | assert_on_stack(void) | ||
80 | { | ||
81 | stack_t cursigstk; | ||
82 | ASSERT_EQ(0, sigaltstack(NULL, &cursigstk)); | ||
83 | ASSERT_EQ(SS_ONSTACK, cursigstk.ss_flags & (SS_DISABLE|SS_ONSTACK)); | ||
84 | } | ||
85 | |||
86 | static void | ||
87 | call_on_stack(void (*fn)(int)) | ||
88 | { | ||
89 | /* | ||
90 | * This is a bit more complicated than strictly necessary, but | ||
91 | * it ensures we don't have any flaky test failures due to | ||
92 | * inherited signal masks/actions/etc. | ||
93 | * | ||
94 | * On systems where SA_ONSTACK is not supported, this could | ||
95 | * alternatively be implemented using makecontext() or | ||
96 | * pthread_attr_setstack(). | ||
97 | */ | ||
98 | |||
99 | const struct sigaction sigact = { | ||
100 | .sa_handler = fn, | ||
101 | .sa_flags = SA_ONSTACK, | ||
102 | }; | ||
103 | struct sigaction oldsigact; | ||
104 | sigset_t sigset, oldsigset; | ||
105 | |||
106 | /* First, block all signals. */ | ||
107 | ASSERT_EQ(0, sigemptyset(&sigset)); | ||
108 | ASSERT_EQ(0, sigfillset(&sigset)); | ||
109 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &sigset, &oldsigset)); | ||
110 | |||
111 | /* Next setup the signal handler for SIGUSR1. */ | ||
112 | ASSERT_EQ(0, sigaction(SIGUSR1, &sigact, &oldsigact)); | ||
113 | |||
114 | /* Raise SIGUSR1 and momentarily unblock it to run the handler. */ | ||
115 | ASSERT_EQ(0, raise(SIGUSR1)); | ||
116 | ASSERT_EQ(0, sigdelset(&sigset, SIGUSR1)); | ||
117 | ASSERT_EQ(-1, sigsuspend(&sigset)); | ||
118 | ASSERT_EQ(EINTR, errno); | ||
119 | |||
120 | /* Restore the original signal action, stack, and mask. */ | ||
121 | ASSERT_EQ(0, sigaction(SIGUSR1, &oldsigact, NULL)); | ||
122 | ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &oldsigset, NULL)); | ||
123 | } | ||
124 | |||
125 | static void | ||
126 | populate_secret(char *buf, size_t len) | ||
127 | { | ||
128 | int i, fds[2]; | ||
129 | ASSERT_EQ(0, pipe(fds)); | ||
130 | |||
131 | for (i = 0; i < SECRETCOUNT; i++) | ||
132 | ASSERT_EQ(sizeof(secret), write(fds[1], secret, sizeof(secret))); | ||
133 | ASSERT_EQ(0, close(fds[1])); | ||
134 | |||
135 | ASSERT_EQ(len, read(fds[0], buf, len)); | ||
136 | ASSERT_EQ(0, close(fds[0])); | ||
137 | } | ||
138 | |||
139 | static int | ||
140 | count_secrets(const char *buf) | ||
141 | { | ||
142 | int res = 0; | ||
143 | size_t i; | ||
144 | for (i = 0; i < SECRETCOUNT; i++) { | ||
145 | if (memcmp(buf + i * sizeof(secret), secret, | ||
146 | sizeof(secret)) == 0) | ||
147 | res += 1; | ||
148 | } | ||
149 | return (res); | ||
150 | } | ||
151 | |||
152 | ATTRIBUTE_NO_SANITIZE_ADDRESS static char * | ||
153 | test_without_bzero(void) | ||
154 | { | ||
155 | char buf[SECRETBYTES]; | ||
156 | assert_on_stack(); | ||
157 | populate_secret(buf, sizeof(buf)); | ||
158 | char *res = memmem(altstack, ALTSTACK_SIZE, buf, sizeof(buf)); | ||
159 | ASSERT_NE(NULL, res); | ||
160 | return (res); | ||
161 | } | ||
162 | |||
163 | ATTRIBUTE_NO_SANITIZE_ADDRESS static char * | ||
164 | test_with_bzero(void) | ||
165 | { | ||
166 | char buf[SECRETBYTES]; | ||
167 | assert_on_stack(); | ||
168 | populate_secret(buf, sizeof(buf)); | ||
169 | char *res = memmem(altstack, ALTSTACK_SIZE, buf, sizeof(buf)); | ||
170 | ASSERT_NE(NULL, res); | ||
171 | explicit_bzero(buf, sizeof(buf)); | ||
172 | return (res); | ||
173 | } | ||
174 | |||
175 | static void | ||
176 | do_test_without_bzero(int signo) | ||
177 | { | ||
178 | char *buf = test_without_bzero(); | ||
179 | ASSERT_GE(count_secrets(buf), 1); | ||
180 | } | ||
181 | |||
182 | static void | ||
183 | do_test_with_bzero(int signo) | ||
184 | { | ||
185 | char *buf = test_with_bzero(); | ||
186 | ASSERT_EQ(count_secrets(buf), 0); | ||
187 | } | ||
188 | |||
189 | int | ||
190 | main(void) | ||
191 | { | ||
192 | setup_stack(); | ||
193 | |||
194 | /* | ||
195 | * Solaris and OS X clobber the signal stack after returning to the | ||
196 | * normal stack, so we need to inspect altstack while we're still | ||
197 | * running on it. Unfortunately, this means we risk clobbering the | ||
198 | * buffer ourselves. | ||
199 | * | ||
200 | * To minimize this risk, test_with{,out}_bzero() are responsible for | ||
201 | * locating the offset of their buf variable within altstack, and | ||
202 | * and returning that address. Then we can simply memcmp() repeatedly | ||
203 | * to count how many instances of secret we found. | ||
204 | */ | ||
205 | |||
206 | /* | ||
207 | * First, test that if we *don't* call explicit_bzero, that we | ||
208 | * *are* able to find at least one instance of the secret data still | ||
209 | * on the stack. This sanity checks that call_on_stack() and | ||
210 | * populate_secret() work as intended. | ||
211 | */ | ||
212 | memset(altstack, 0, ALTSTACK_SIZE); | ||
213 | call_on_stack(do_test_without_bzero); | ||
214 | |||
215 | /* | ||
216 | * Now test with a call to explicit_bzero() and check that we | ||
217 | * *don't* find any instances of the secret data. | ||
218 | */ | ||
219 | memset(altstack, 0, ALTSTACK_SIZE); | ||
220 | call_on_stack(do_test_with_bzero); | ||
221 | |||
222 | cleanup_stack(); | ||
223 | |||
224 | return (0); | ||
225 | } | ||
diff --git a/src/regress/lib/libc/ffs/Makefile b/src/regress/lib/libc/ffs/Makefile deleted file mode 100644 index 1ad004394f..0000000000 --- a/src/regress/lib/libc/ffs/Makefile +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | PROG= ffs_test | ||
2 | |||
3 | # prevent constant folding and inlining of __builtin_ffs() | ||
4 | CFLAGS+= -ffreestanding | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ffs/ffs_test.c b/src/regress/lib/libc/ffs/ffs_test.c deleted file mode 100644 index bc1e5c53c2..0000000000 --- a/src/regress/lib/libc/ffs/ffs_test.c +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | /* $OpenBSD: ffs_test.c,v 1.1 2020/06/26 20:16:22 naddy Exp $ */ | ||
2 | /* | ||
3 | * Written by Christian Weisgerber <naddy@openbsd.org>. | ||
4 | * Public domain. | ||
5 | */ | ||
6 | |||
7 | #include <assert.h> | ||
8 | #include <stdint.h> | ||
9 | #include <string.h> | ||
10 | |||
11 | int | ||
12 | main(void) | ||
13 | { | ||
14 | assert(ffs(0) == 0); | ||
15 | assert(ffs(0x8080) == 8); | ||
16 | assert(ffs(INT32_MIN) == 32); | ||
17 | return (0); | ||
18 | } | ||
diff --git a/src/regress/lib/libc/fmemopen/Makefile b/src/regress/lib/libc/fmemopen/Makefile deleted file mode 100644 index 9cfbfaa99c..0000000000 --- a/src/regress/lib/libc/fmemopen/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2013/01/01 17:43:07 mpi Exp $ | ||
2 | |||
3 | PROG= fmemopentest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/fmemopen/fmemopentest.c b/src/regress/lib/libc/fmemopen/fmemopentest.c deleted file mode 100644 index dd0c123fe6..0000000000 --- a/src/regress/lib/libc/fmemopen/fmemopentest.c +++ /dev/null | |||
@@ -1,263 +0,0 @@ | |||
1 | /* $OpenBSD: fmemopentest.c,v 1.4 2020/08/17 16:17:39 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <err.h> | ||
20 | #include <stdio.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | #include <unistd.h> | ||
24 | |||
25 | int | ||
26 | simpletest(void) | ||
27 | { | ||
28 | FILE *s1, *s2; | ||
29 | char string[] = "fmemopen test string!"; | ||
30 | char buffer[1024], *buf = NULL; | ||
31 | size_t len; | ||
32 | int c, failures = 0; | ||
33 | |||
34 | s1 = fmemopen(string, strlen(string) + 1, "r"); | ||
35 | if (s1 == NULL) { | ||
36 | warn("unable to open a stream s1"); | ||
37 | return (1); | ||
38 | } | ||
39 | |||
40 | s2 = fmemopen(buf, 22, "w+"); | ||
41 | if (s2 == NULL) { | ||
42 | warn("unable to create a stream s2"); | ||
43 | fclose(s1); | ||
44 | return (1); | ||
45 | } | ||
46 | |||
47 | while ((c = fgetc(s1)) != EOF) | ||
48 | fputc(c, s2); | ||
49 | |||
50 | if (ftell(s2) != strlen(string) + 1) { | ||
51 | warnx("failed copy test (1)"); | ||
52 | failures++; | ||
53 | } | ||
54 | fclose(s1); | ||
55 | |||
56 | fseek(s2, 0, SEEK_SET); | ||
57 | if (ftell(s2) != 0) { | ||
58 | warnx("failed seek test (2)"); | ||
59 | failures++; | ||
60 | } | ||
61 | |||
62 | len = fread(buffer, 1, sizeof(buffer) - 1, s2); | ||
63 | if (len != strlen(string) + 1) { | ||
64 | warnx("failed read test (3) %zu != %zu", | ||
65 | len, strlen(string) + 1); | ||
66 | failures++; | ||
67 | } | ||
68 | |||
69 | return (failures); | ||
70 | } | ||
71 | |||
72 | int | ||
73 | appendtest(const char *mode) | ||
74 | { | ||
75 | FILE *s1; | ||
76 | char string[] = "hello\0 test number 2"; | ||
77 | char buffer[256]; | ||
78 | size_t len; | ||
79 | int failures = 0; | ||
80 | |||
81 | s1 = fmemopen(string, 19, mode); | ||
82 | if (s1 == NULL) | ||
83 | return (1); | ||
84 | |||
85 | fseek(s1, 0, SEEK_SET); | ||
86 | if (ftell(s1) != 0) { | ||
87 | warnx("failed seek test [%s] (4)", mode); | ||
88 | failures++; | ||
89 | } | ||
90 | |||
91 | /* write should append even though seek position is 0 */ | ||
92 | len = fwrite(" world", 1, 6, s1); | ||
93 | if (len != 6) { | ||
94 | warnx("failed write test [%s] (5)", mode); | ||
95 | failures++; | ||
96 | } | ||
97 | |||
98 | if (ftell(s1) != strlen("hello world")) { | ||
99 | warnx("failed seek test [%s] (6)", mode); | ||
100 | failures++; | ||
101 | } | ||
102 | |||
103 | if (mode[1] == '+') { | ||
104 | fseek(s1, 0, SEEK_SET); | ||
105 | len = fread(buffer, 1, sizeof(buffer) - 1, s1); | ||
106 | if (len == 0 || strncmp(string, buffer, len)) { | ||
107 | warnx("failed compare test [%s] (7)", mode); | ||
108 | failures++; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | if (strcmp(string, "hello world")) { | ||
113 | warnx("failed compare test [%s] (8)", mode); | ||
114 | failures++; | ||
115 | } | ||
116 | |||
117 | if (strcmp(string + strlen(string) + 1, "number 2")) { | ||
118 | warnx("failed compare test [%s] (9)", mode); | ||
119 | failures++; | ||
120 | } | ||
121 | |||
122 | return (failures); | ||
123 | } | ||
124 | |||
125 | int | ||
126 | updatetest(void) | ||
127 | { | ||
128 | FILE *s1; | ||
129 | char string[] = "bah, what a day"; | ||
130 | char buffer[256]; | ||
131 | size_t len; | ||
132 | int failures = 0; | ||
133 | |||
134 | s1 = fmemopen(string, 19, "r+"); | ||
135 | if (s1 == NULL) | ||
136 | return (1); | ||
137 | |||
138 | if (ftell(s1) != 0) { | ||
139 | warnx("failed seek test (10)"); | ||
140 | failures++; | ||
141 | } | ||
142 | |||
143 | len = fwrite("oh frabjous", 1, 11, s1); | ||
144 | if (len != 11) { | ||
145 | warnx("failed write test (11)"); | ||
146 | failures++; | ||
147 | } | ||
148 | |||
149 | fseek(s1, 0, SEEK_SET); | ||
150 | len = fread(buffer, 1, sizeof(buffer) - 1, s1); | ||
151 | if (len == 0 || strncmp(string, buffer, len)) { | ||
152 | warnx("failed compare test (12)"); | ||
153 | failures++; | ||
154 | } | ||
155 | |||
156 | if (strcmp(string, "oh frabjous day")) { | ||
157 | warnx("failed compare test (13)"); | ||
158 | failures++; | ||
159 | } | ||
160 | |||
161 | return (failures); | ||
162 | } | ||
163 | |||
164 | int | ||
165 | writetest(const char *mode) | ||
166 | { | ||
167 | FILE *s1; | ||
168 | char string[] = "super test number 3"; | ||
169 | char buffer[256]; | ||
170 | size_t len, slen; | ||
171 | int failures = 0; | ||
172 | |||
173 | slen = strlen(string) + 1; | ||
174 | |||
175 | s1 = fmemopen(string, slen, mode); | ||
176 | if (s1 == NULL) | ||
177 | return (1); | ||
178 | |||
179 | len = fwrite("short", 1, 5, s1); | ||
180 | if (len != strlen("short")) { | ||
181 | warnx("failed write test [%s] (14)", mode); | ||
182 | failures++; | ||
183 | } | ||
184 | fclose(s1); | ||
185 | |||
186 | s1 = fmemopen(string, slen, "r"); | ||
187 | if (s1 == NULL) { | ||
188 | warnx("failed open test [%s] (15)", mode); | ||
189 | failures++; | ||
190 | } | ||
191 | |||
192 | len = fread(buffer, 1, sizeof(buffer) - 1, s1); | ||
193 | if (len == 0 || strncmp(string, buffer, len)) { | ||
194 | warnx("failed compare test [%s] (16)", mode); | ||
195 | failures++; | ||
196 | } | ||
197 | |||
198 | if (strcmp(string, "short")) { | ||
199 | warnx("failed compare test [%s] (17)", mode); | ||
200 | failures++; | ||
201 | } | ||
202 | |||
203 | if (strcmp(string + strlen(string) + 1, "test number 3")) { | ||
204 | warnx("failed compare test [%s] (18)", mode); | ||
205 | failures++; | ||
206 | } | ||
207 | |||
208 | return (failures); | ||
209 | } | ||
210 | |||
211 | int | ||
212 | seektest(void) | ||
213 | { | ||
214 | FILE *s1; | ||
215 | char string[] = "long string for testing seek"; | ||
216 | size_t len, slen; | ||
217 | int failures = 0; | ||
218 | |||
219 | slen = strlen(string) + 1; | ||
220 | |||
221 | s1 = fmemopen(string, slen, "r"); | ||
222 | if (s1 == NULL) | ||
223 | return (1); | ||
224 | |||
225 | if (fseek(s1, 8, SEEK_SET) != 0) { | ||
226 | warnx("failed to fseek. (19)"); | ||
227 | failures++; | ||
228 | } | ||
229 | |||
230 | if (ftell(s1) != 8) { | ||
231 | warnx("failed seek test. (20)"); | ||
232 | failures++; | ||
233 | } | ||
234 | |||
235 | /* Try to seek backward */ | ||
236 | if (fseek(s1, -1, SEEK_CUR) != 0) { | ||
237 | warnx("failed to fseek. (21)"); | ||
238 | failures++; | ||
239 | } | ||
240 | |||
241 | if (ftell(s1) != 7) { | ||
242 | warnx("failed seeking backward. (22)"); | ||
243 | failures++; | ||
244 | } | ||
245 | |||
246 | return (failures); | ||
247 | } | ||
248 | |||
249 | int | ||
250 | main(void) | ||
251 | { | ||
252 | int failures = 0; | ||
253 | |||
254 | failures += simpletest(); | ||
255 | failures += appendtest("a"); | ||
256 | failures += appendtest("a+"); | ||
257 | failures += updatetest(); | ||
258 | failures += writetest("w"); | ||
259 | failures += writetest("w+"); | ||
260 | failures += seektest(); | ||
261 | |||
262 | return (failures); | ||
263 | } | ||
diff --git a/src/regress/lib/libc/fnmatch/Makefile b/src/regress/lib/libc/fnmatch/Makefile deleted file mode 100644 index 4acdd351bc..0000000000 --- a/src/regress/lib/libc/fnmatch/Makefile +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2011/09/17 15:12:38 stsp Exp $ | ||
2 | |||
3 | PROG= fnm_test | ||
4 | LDADD+= -lutil | ||
5 | DPADD+= ${LIBUTIL} | ||
6 | |||
7 | run-regress-${PROG}: | ||
8 | ./${PROG} ${.CURDIR}/${PROG}.in | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/fnmatch/fnm_test.c b/src/regress/lib/libc/fnmatch/fnm_test.c deleted file mode 100644 index ee04f6335e..0000000000 --- a/src/regress/lib/libc/fnmatch/fnm_test.c +++ /dev/null | |||
@@ -1,62 +0,0 @@ | |||
1 | /* $OpenBSD: fnm_test.c,v 1.3 2019/01/25 00:19:26 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Public domain, 2008, Todd C. Miller <millert@openbsd.org> | ||
5 | */ | ||
6 | |||
7 | #include <err.h> | ||
8 | #include <fnmatch.h> | ||
9 | #include <stdio.h> | ||
10 | #include <stdlib.h> | ||
11 | #include <util.h> | ||
12 | |||
13 | int | ||
14 | main(int argc, char **argv) | ||
15 | { | ||
16 | FILE *fp = stdin; | ||
17 | char pattern[1024], string[1024]; | ||
18 | char *line; | ||
19 | const char delim[3] = {'\0', '\0', '#'}; | ||
20 | int errors = 0, flags, got, want; | ||
21 | |||
22 | if (argc > 1) { | ||
23 | if ((fp = fopen(argv[1], "r")) == NULL) | ||
24 | err(1, "%s", argv[1]); | ||
25 | } | ||
26 | |||
27 | /* | ||
28 | * Read in test file, which is formatted thusly: | ||
29 | * | ||
30 | * pattern string flags expected_result | ||
31 | * | ||
32 | * lines starting with '#' are comments | ||
33 | */ | ||
34 | for (;;) { | ||
35 | line = fparseln(fp, NULL, NULL, delim, 0); | ||
36 | if (!line) | ||
37 | break; | ||
38 | got = sscanf(line, "%s %s 0x%x %d", pattern, string, &flags, | ||
39 | &want); | ||
40 | if (got == EOF) { | ||
41 | free(line); | ||
42 | break; | ||
43 | } | ||
44 | if (pattern[0] == '#') { | ||
45 | free(line); | ||
46 | continue; | ||
47 | } | ||
48 | if (got == 4) { | ||
49 | got = fnmatch(pattern, string, flags); | ||
50 | if (got != want) { | ||
51 | warnx("%s %s %d: want %d, got %d", pattern, | ||
52 | string, flags, want, got); | ||
53 | errors++; | ||
54 | } | ||
55 | } else { | ||
56 | warnx("unrecognized line '%s'\n", line); | ||
57 | errors++; | ||
58 | } | ||
59 | free(line); | ||
60 | } | ||
61 | exit(errors); | ||
62 | } | ||
diff --git a/src/regress/lib/libc/fnmatch/fnm_test.in b/src/regress/lib/libc/fnmatch/fnm_test.in deleted file mode 100644 index c2f218ae1b..0000000000 --- a/src/regress/lib/libc/fnmatch/fnm_test.in +++ /dev/null | |||
@@ -1,260 +0,0 @@ | |||
1 | /bin/[[:alpha:][:alnum:]]* /bin/ls 0x2 0 | ||
2 | /bin/[[:upper:]][[:alnum:]] /bin/ls 0x10 0 | ||
3 | /bin/[[:opper:][:alnum:]]* /bin/ls 0x0 1 | ||
4 | [[:alpha:][:alnum:]]*.c foo1.c 0x4 0 | ||
5 | [[:upper:]]* FOO 0x0 0 | ||
6 | [![:space:]]* bar 0x0 0 | ||
7 | # 'te\st' 'test'; no match if FNM_NOESCAPE | ||
8 | te\st test 0x0 0 | ||
9 | te\st test 0x1 1 | ||
10 | te\st test 0x1e 0 | ||
11 | # 'te\\st' 'te\st'; no match if FNM_NOESCAPE | ||
12 | te\\st te\st 0x0 0 | ||
13 | te\\st te\st 0x1 1 | ||
14 | te\\st te\st 0x1e 0 | ||
15 | # 'te\*t' 'te*t'; no match if FNM_NOESCAPE | ||
16 | te\*t te*t 0x0 0 | ||
17 | te\*t te*t 0x1 1 | ||
18 | te\*t te*t 0x1e 0 | ||
19 | # 'te\*t' 'test'; no match | ||
20 | te\*t test 0x0 1 | ||
21 | te\*t test 0x1f 1 | ||
22 | # 'te\?t' 'te?t'; no match if FNM_NOESCAPE | ||
23 | te\?t te?t 0x0 0 | ||
24 | te\?t te?t 0x1 1 | ||
25 | te\?t te?t 0x1e 0 | ||
26 | # 'te\?t' 'test'; no match | ||
27 | te\?t test 0x0 1 | ||
28 | te\?t test 0x1f 1 | ||
29 | # 'tesT' 'test'; match if FNM_CASEFOLD | ||
30 | tesT test 0x0 1 | ||
31 | tesT test 0xf 1 | ||
32 | tesT test 0x10 0 | ||
33 | # 'test' 'Test'; match if FNM_CASEFOLD | ||
34 | test Test 0x0 1 | ||
35 | test Test 0xf 1 | ||
36 | test Test 0x10 0 | ||
37 | # 'tEst' 'teSt'; match if FNM_CASEFOLD | ||
38 | tEst teSt 0x0 1 | ||
39 | tEst teSt 0xf 1 | ||
40 | tEst teSt 0x10 0 | ||
41 | # '?est' 'test'; match always | ||
42 | ?est test 0x0 0 | ||
43 | ?est test 0x1f 0 | ||
44 | # 'te?t' 'test'; match always | ||
45 | te?t test 0x0 0 | ||
46 | te?t test 0x1f 0 | ||
47 | # 'tes?' 'test'; match always | ||
48 | tes? test 0x0 0 | ||
49 | tes? test 0x1f 0 | ||
50 | # 'test?' 'test'; no match | ||
51 | test? test 0x0 1 | ||
52 | test? test 0x1f 1 | ||
53 | # '*' always matches anything | ||
54 | * test 0x0 0 | ||
55 | * test 0x1f 0 | ||
56 | # '*test' 'test'; match always | ||
57 | *test test 0x0 0 | ||
58 | *test test 0x1f 0 | ||
59 | # '*est' 'test'; match always | ||
60 | *est test 0x0 0 | ||
61 | *est test 0x1f 0 | ||
62 | # '*st' 'test'; match always | ||
63 | *st test 0x0 0 | ||
64 | *st test 0x1f 0 | ||
65 | # 't*t' 'test'; match always | ||
66 | t*t test 0x0 0 | ||
67 | t*t test 0x1f 0 | ||
68 | # 'te*t' 'test'; match always | ||
69 | te*t test 0x0 0 | ||
70 | te*t test 0x1f 0 | ||
71 | # 'te*st' 'test'; match always | ||
72 | te*st test 0x0 0 | ||
73 | te*st test 0x1f 0 | ||
74 | # 'te*' 'test'; match always | ||
75 | te* test 0x0 0 | ||
76 | te* test 0x1f 0 | ||
77 | # 'tes*' 'test'; match always | ||
78 | tes* test 0x0 0 | ||
79 | tes* test 0x1f 0 | ||
80 | # 'test*' 'test'; match always | ||
81 | test* test 0x0 0 | ||
82 | test* test 0x1f 0 | ||
83 | # '.[\-\t]' '.t'; match always | ||
84 | .[\-\t] .t 0x0 0 | ||
85 | .[\-\t] .t 0x1f 0 | ||
86 | # 'test*?*[a-z]*' 'testgoop'; match always | ||
87 | test*?*[a-z]* testgoop 0x0 0 | ||
88 | test*?*[a-z]* testgoop 0x1f 0 | ||
89 | # 'te[^abc]t' 'test'; match always | ||
90 | te[^abc]t test 0x0 0 | ||
91 | te[^abc]t test 0x1f 0 | ||
92 | # 'te[^x]t' 'test'; match always | ||
93 | te[^x]t test 0x0 0 | ||
94 | te[^x]t test 0x1f 0 | ||
95 | # 'te[!x]t' 'test'; match always | ||
96 | te[!x]t test 0x0 0 | ||
97 | te[^x]t test 0x1f 0 | ||
98 | # 'te[^x]t' 'text'; no match | ||
99 | te[^x]t text 0x0 1 | ||
100 | te[^x]t text 0x1f 1 | ||
101 | # 'te[^\x]t' 'text'; no match | ||
102 | te[^\x]t text 0x0 1 | ||
103 | te[^\x]t text 0x1f 1 | ||
104 | # 'te[^\x' 'text'; no match | ||
105 | te[^\x text 0x0 1 | ||
106 | te[^\x text 0x1f 1 | ||
107 | # 'te[/]t' 'text'; no match | ||
108 | te[/]t text 0x0 1 | ||
109 | te[/]t text 0x1f 1 | ||
110 | # 'te[S]t' 'test'; match if FNM_CASEFOLD | ||
111 | te[S]t test 0x0 1 | ||
112 | te[S]t test 0xf 1 | ||
113 | te[S]t test 0x10 0 | ||
114 | # 'te[r-t]t' 'test'; match always | ||
115 | te[r-t]t test 0x0 0 | ||
116 | te[r-t]t test 0x1f 0 | ||
117 | # 'te[r-t]t' 'teSt'; match if FNM_CASEFOLD | ||
118 | te[r-t]t teSt 0x0 1 | ||
119 | te[r-t]t teSt 0xf 1 | ||
120 | te[r-t]t teSt 0x10 0 | ||
121 | # 'te[r-T]t' 'test'; match if FNM_CASEFOLD | ||
122 | te[r-T]t test 0x0 1 | ||
123 | te[r-T]t test 0xf 1 | ||
124 | te[r-T]t test 0x10 0 | ||
125 | # 'te[R-T]t' 'test'; match if FNM_CASEFOLD | ||
126 | te[R-T]t test 0x0 1 | ||
127 | te[R-T]t test 0xf 1 | ||
128 | te[R-T]t test 0x10 0 | ||
129 | # 'te[r-Tz]t' 'tezt'; match always | ||
130 | te[r-Tz]t tezt 0x0 0 | ||
131 | te[r-Tz]t tezt 0x1f 0 | ||
132 | # 'te[R-T]t' 'tent'; no match | ||
133 | te[R-T]t tent 0x0 1 | ||
134 | te[R-T]t tent 0x1f 1 | ||
135 | # 'tes[]t]' 'test'; match always | ||
136 | tes[]t] test 0x0 0 | ||
137 | tes[]t] test 0x1f 0 | ||
138 | # 'tes[t-]' 'test'; match always | ||
139 | tes[t-] test 0x0 0 | ||
140 | tes[t-] test 0x1f 0 | ||
141 | # 'tes[t-]]' 'test]'; match always | ||
142 | tes[t-]] test] 0x0 0 | ||
143 | tes[t-]] test] 0x1f 0 | ||
144 | # 'tes[t-]]' 'test'; no match | ||
145 | tes[t-]] test 0x0 1 | ||
146 | tes[t-]] test 0x1f 1 | ||
147 | # 'tes[u-]' 'test'; no match | ||
148 | tes[u-] test 0x0 1 | ||
149 | tes[u-] test 0x1f 1 | ||
150 | # 'tes[t-]' 'tes[t-]'; no match | ||
151 | tes[t-] test[t-] 0x0 1 | ||
152 | tes[t-] test[t-] 0x1f 1 | ||
153 | # 'test[/-/]' 'test[/-/]'; no match | ||
154 | test[/-/] test/-/ 0x0 1 | ||
155 | test[/-/] test/-/ 0x1f 1 | ||
156 | # 'test[\/-/]' 'test[/-/]'; no match | ||
157 | test[\/-/] test/-/ 0x0 1 | ||
158 | test[\/-/] test/-/ 0x1f 1 | ||
159 | # 'test[/-\/]' 'test[/-/]'; no match | ||
160 | test[/-\/] test/-/ 0x0 1 | ||
161 | test[/-\/] test/-/ 0x1f 1 | ||
162 | # 'test[/-/]' 'test/'; no match if APR_FNM_PATHNAME | ||
163 | test[/-/] test/ 0x0 0 | ||
164 | test[/-/] test/ 0x2 1 | ||
165 | test[/-/] test/ 0x1d 0 | ||
166 | # 'test[\/-/]' 'test/'; no match if APR_FNM_PATHNAME | ||
167 | test[\/-/] test/ 0x0 0 | ||
168 | test[\/-/] test/ 0x2 1 | ||
169 | test[\/-/] test/ 0x1d 0 | ||
170 | # 'test[/-\/]' 'test/'; no match if APR_FNM_PATHNAME | ||
171 | test[/-\/] test/ 0x0 0 | ||
172 | test[/-\/] test/ 0x2 1 | ||
173 | test[/-\/] test/ 0x1d 0 | ||
174 | # '/test' 'test'; no match | ||
175 | /test test 0x0 1 | ||
176 | /test test 0x1f 1 | ||
177 | # 'test' '/test'; no match | ||
178 | test /test 0x0 1 | ||
179 | test /test 0x1f 1 | ||
180 | # 'test/' 'test'; no match | ||
181 | test/ test 0x0 1 | ||
182 | test/ test 0x1f 1 | ||
183 | # 'test' 'test/'; match if FNM_LEADING_DIR | ||
184 | test test/ 0x0 1 | ||
185 | test test/ 0x17 1 | ||
186 | test test/ 0x8 0 | ||
187 | # '\/test' '/test'; match unless FNM_NOESCAPE | ||
188 | \/test /test 0x0 0 | ||
189 | \/test /test 0x1 1 | ||
190 | \/test /test 0x1e 0 | ||
191 | # '*test' '/test'; match unless FNM_PATHNAME | ||
192 | *test /test 0x0 0 | ||
193 | *test /test 0x2 1 | ||
194 | *test /test 0x1d 0 | ||
195 | # '/*/test' '/test'; no match | ||
196 | /*/test /test 0x0 1 | ||
197 | /*/test /test 0x1f 1 | ||
198 | # '/*/test' '/test/test'; match always | ||
199 | /*/test /test/test 0x0 0 | ||
200 | /*/test /test/test 0x1f 0 | ||
201 | # 'test/this' 'test/'; match never | ||
202 | test/this test/ 0x0 1 | ||
203 | test/this test/ 0x1f 1 | ||
204 | # 'test/' 'test/this'; match never | ||
205 | test/ test/this 0x0 1 | ||
206 | test/ test/this 0x1f 1 | ||
207 | # 'test*/this' 'test/this'; match always | ||
208 | test*/this test/this 0x0 0 | ||
209 | test*/this test/this 0x1f 0 | ||
210 | # 'test*/this' 'test/that'; match never | ||
211 | test*/this test/that 0x0 1 | ||
212 | test*/this test/that 0x1f 1 | ||
213 | # 'test/*this' 'test/this'; match always | ||
214 | test/*this test/this 0x0 0 | ||
215 | test/*this test/this 0x1f 0 | ||
216 | # '.*' '.this'; match always | ||
217 | .* .this 0x0 0 | ||
218 | .* .this 0x1f 0 | ||
219 | # '*' '.this'; fails if FNM_PERIOD | ||
220 | * .this 0x0 0 | ||
221 | * .this 0x4 1 | ||
222 | * .this 0x1b 0 | ||
223 | # '?this' '.this'; fails if FNM_PERIOD | ||
224 | ?this .this 0x0 0 | ||
225 | ?this .this 0x4 1 | ||
226 | ?this .this 0x1b 0 | ||
227 | # '[.]this' '.this'; fails if FNM_PERIOD | ||
228 | [.]this .this 0x0 0 | ||
229 | [.]this .this 0x4 1 | ||
230 | [.]this .this 0x1b 0 | ||
231 | # 'test/this' 'test/this'; match always | ||
232 | test/this test/this 0x0 0 | ||
233 | test/this test/this 0x1f 0 | ||
234 | # 'test?this' 'test/this'; fails if FNM_PATHNAME | ||
235 | test?this test/this 0x0 0 | ||
236 | test?this test/this 0x2 1 | ||
237 | test?this test/this 0x1d 0 | ||
238 | # 'test*this' 'test/this'; fails if FNM_PATHNAME | ||
239 | test*this test/this 0x0 0 | ||
240 | test*this test/this 0x2 1 | ||
241 | test*this test/this 0x1d 0 | ||
242 | # 'test[/]this' 'test/this'; fails if FNM_PATHNAME | ||
243 | test[/]this test/this 0x0 0 | ||
244 | test[/]this test/this 0x2 1 | ||
245 | test[/]this test/this 0x1d 0 | ||
246 | # 'test/.*' 'test/.this'; match always | ||
247 | test/.* test/.this 0x0 0 | ||
248 | test/.* test/.this 0x1f 0 | ||
249 | # 'test/*' 'test/.this'; fails if FNM_PERIOD and FNM_PATHNAME | ||
250 | test/* test/.this 0x0 0 | ||
251 | test/* test/.this 0x6 1 | ||
252 | test/* test/.this 0x19 0 | ||
253 | # 'test/?' 'test/.this'; fails if FNM_PERIOD and FNM_PATHNAME | ||
254 | test/?this test/.this 0x0 0 | ||
255 | test/?this test/.this 0x6 1 | ||
256 | test/?this test/.this 0x19 0 | ||
257 | # 'test/[.]this' 'test/.this'; fails if FNM_PERIOD and FNM_PATHNAME | ||
258 | test/[.]this test/.this 0x0 0 | ||
259 | test/[.]this test/.this 0x6 1 | ||
260 | test/[.]this test/.this 0x19 0 | ||
diff --git a/src/regress/lib/libc/fpclassify/Makefile b/src/regress/lib/libc/fpclassify/Makefile deleted file mode 100644 index 96916d20e7..0000000000 --- a/src/regress/lib/libc/fpclassify/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2008/09/07 20:36:10 martynas Exp $ | ||
2 | |||
3 | PROG= fpclassify | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/fpclassify/fpclassify.c b/src/regress/lib/libc/fpclassify/fpclassify.c deleted file mode 100644 index 174c04d983..0000000000 --- a/src/regress/lib/libc/fpclassify/fpclassify.c +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | /* $OpenBSD: fpclassify.c,v 1.1 2008/09/07 20:36:10 martynas Exp $ */ | ||
2 | /*- | ||
3 | * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * | ||
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
25 | * SUCH DAMAGE. | ||
26 | * | ||
27 | * $FreeBSD: src/tools/regression/lib/libc/gen/test-fpclassify.c,v 1.3 2003/03/27 05:32:28 das Exp $ | ||
28 | */ | ||
29 | |||
30 | #include <assert.h> | ||
31 | #include <float.h> | ||
32 | #include <math.h> | ||
33 | #include <stdlib.h> | ||
34 | |||
35 | int | ||
36 | main(void) | ||
37 | { | ||
38 | |||
39 | assert(fpclassify((float)0) == FP_ZERO); | ||
40 | assert(fpclassify((float)-0.0) == FP_ZERO); | ||
41 | assert(fpclassify((float)1) == FP_NORMAL); | ||
42 | assert(fpclassify((float)1000) == FP_NORMAL); | ||
43 | #ifndef __alpha__ | ||
44 | assert(fpclassify(0x1.2p-150f) == FP_SUBNORMAL); | ||
45 | #endif /* !__alpha__ */ | ||
46 | assert(fpclassify(HUGE_VALF) == FP_INFINITE); | ||
47 | assert(fpclassify((float)HUGE_VAL) == FP_INFINITE); | ||
48 | assert(fpclassify((float)HUGE_VALL) == FP_INFINITE); | ||
49 | assert(fpclassify(NAN) == FP_NAN); | ||
50 | |||
51 | assert(fpclassify((double)0) == FP_ZERO); | ||
52 | assert(fpclassify((double)-0) == FP_ZERO); | ||
53 | assert(fpclassify((double)1) == FP_NORMAL); | ||
54 | assert(fpclassify((double)1000) == FP_NORMAL); | ||
55 | #ifndef __alpha__ | ||
56 | assert(fpclassify(0x1.2p-1075) == FP_SUBNORMAL); | ||
57 | #endif /* !__alpha__ */ | ||
58 | assert(fpclassify(HUGE_VAL) == FP_INFINITE); | ||
59 | assert(fpclassify((double)HUGE_VALF) == FP_INFINITE); | ||
60 | assert(fpclassify((double)HUGE_VALL) == FP_INFINITE); | ||
61 | assert(fpclassify((double)NAN) == FP_NAN); | ||
62 | |||
63 | assert(fpclassify((long double)0) == FP_ZERO); | ||
64 | assert(fpclassify((long double)-0.0) == FP_ZERO); | ||
65 | assert(fpclassify((long double)1) == FP_NORMAL); | ||
66 | assert(fpclassify((long double)1000) == FP_NORMAL); | ||
67 | #if (LDBL_MANT_DIG > DBL_MANT_DIG) | ||
68 | assert(fpclassify(0x1.2p-16383L) == FP_SUBNORMAL); | ||
69 | #endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) */ | ||
70 | assert(fpclassify(HUGE_VALL) == FP_INFINITE); | ||
71 | assert(fpclassify((long double)HUGE_VALF) == FP_INFINITE); | ||
72 | assert(fpclassify((long double)HUGE_VAL) == FP_INFINITE); | ||
73 | assert(fpclassify((long double)NAN) == FP_NAN); | ||
74 | |||
75 | return (0); | ||
76 | } | ||
diff --git a/src/regress/lib/libc/fread/Makefile b/src/regress/lib/libc/fread/Makefile deleted file mode 100644 index fddc3b853a..0000000000 --- a/src/regress/lib/libc/fread/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2018/12/16 15:36:27 millert Exp $ | ||
2 | |||
3 | PROG= fread | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/fread/fread.c b/src/regress/lib/libc/fread/fread.c deleted file mode 100644 index 84e0ba0f65..0000000000 --- a/src/regress/lib/libc/fread/fread.c +++ /dev/null | |||
@@ -1,153 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2018 Todd C. Miller <millert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <sys/socket.h> | ||
18 | #include <sys/wait.h> | ||
19 | |||
20 | #include <err.h> | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | #include <unistd.h> | ||
25 | |||
26 | /* | ||
27 | * Test reading from a socket until EOF with multiple writes on | ||
28 | * the other end. The send and receive buffer sizes are reduced | ||
29 | * to force multiple read(2) and write(2) calls to happen. | ||
30 | * | ||
31 | * Tests unbuffered, line buffered and fully-buffers. | ||
32 | * | ||
33 | * This test catches bugs in stdio/fread.c revs 1.13 and 1.17. | ||
34 | */ | ||
35 | |||
36 | static char test_string[] = | ||
37 | "Now is the time for all good men to come to the aid of the party\n" | ||
38 | "The quick brown fox jumps over the lazy dog\n" | ||
39 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n" | ||
40 | "Insert test text here..\n"; | ||
41 | |||
42 | static char * | ||
43 | iomode2str(int iomode) | ||
44 | { | ||
45 | switch (iomode) { | ||
46 | case _IOFBF: | ||
47 | return "fully buffered"; | ||
48 | case _IOLBF: | ||
49 | return "line buffered"; | ||
50 | case _IONBF: | ||
51 | return "unbuffered"; | ||
52 | default: | ||
53 | return "unknown"; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | static void | ||
58 | dochild(int fd) | ||
59 | { | ||
60 | size_t left; | ||
61 | ssize_t nwritten; | ||
62 | char *ts = test_string; | ||
63 | |||
64 | left = strlen(test_string); | ||
65 | while (left != 0) { | ||
66 | nwritten = write(fd, ts, left); | ||
67 | if (nwritten == -1) | ||
68 | err(1, "write"); | ||
69 | left -= nwritten; | ||
70 | ts += nwritten; | ||
71 | } | ||
72 | close(fd); | ||
73 | _exit(0); | ||
74 | } | ||
75 | |||
76 | int | ||
77 | dotest(int iomode, char *iobuf, size_t iolen) | ||
78 | { | ||
79 | char *ts = test_string; | ||
80 | size_t nread, total = 0, off = 0; | ||
81 | int sv[2], val; | ||
82 | char buf[21]; | ||
83 | pid_t child; | ||
84 | FILE *fp; | ||
85 | |||
86 | if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) == -1) | ||
87 | err(1, "socketpair"); | ||
88 | val = 16; | ||
89 | if (setsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)) == -1) | ||
90 | err(1, "setsockopt(sv[0], SOL_SOCKET, SO_SNDBUF)"); | ||
91 | if (setsockopt(sv[0], SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)) == -1) | ||
92 | err(1, "setsockopt(sv[0], SOL_SOCKET, SO_RCVBUF)"); | ||
93 | if (setsockopt(sv[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)) == -1) | ||
94 | err(1, "setsockopt(sv[1], SOL_SOCKET, SO_SNDBUF)"); | ||
95 | if (setsockopt(sv[1], SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)) == -1) | ||
96 | err(1, "setsockopt(sv[1], SOL_SOCKET, SO_RCVBUF)"); | ||
97 | |||
98 | if ((fp = fdopen(sv[0], "r")) == NULL) | ||
99 | err(1, "fdopen"); | ||
100 | |||
101 | setvbuf(fp, iobuf, iomode, iolen); | ||
102 | |||
103 | switch ((child = fork())) { | ||
104 | case -1: | ||
105 | err(1, "fork"); | ||
106 | case 0: | ||
107 | close(sv[0]); | ||
108 | dochild(sv[1]); | ||
109 | default: | ||
110 | close(sv[1]); | ||
111 | break; | ||
112 | } | ||
113 | |||
114 | while ((nread = fread(buf, 1, sizeof(buf), fp)) != 0) { | ||
115 | if (nread > sizeof(buf)) { | ||
116 | warnx("%s: max %zu bytes but got %zu", | ||
117 | iomode2str(iomode), sizeof(buf), nread); | ||
118 | return 1; | ||
119 | } | ||
120 | if (strncmp(buf, test_string + off, nread) != 0) { | ||
121 | warnx("%s: mismatch: expected %.*s, got %.*s", | ||
122 | iomode2str(iomode), (int)nread, test_string + off, | ||
123 | (int)nread, buf); | ||
124 | return 1; | ||
125 | } | ||
126 | total += nread; | ||
127 | off += nread; | ||
128 | } | ||
129 | if (!feof(fp)) { | ||
130 | if (ferror(fp)) | ||
131 | warn("%s: read error", iomode2str(iomode)); | ||
132 | else | ||
133 | warnx("%s: missing EOF", iomode2str(iomode)); | ||
134 | return 1; | ||
135 | } | ||
136 | fclose(fp); | ||
137 | waitpid(child, NULL, 0); | ||
138 | |||
139 | return 0; | ||
140 | } | ||
141 | |||
142 | int | ||
143 | main(int argc, char *argv[]) | ||
144 | { | ||
145 | char iobuf[4096]; | ||
146 | int errors = 0; | ||
147 | |||
148 | errors += dotest(_IOFBF, iobuf, sizeof(iobuf)); | ||
149 | errors += dotest(_IOLBF, iobuf, sizeof(iobuf)); | ||
150 | errors += dotest(_IONBF, NULL, 0); | ||
151 | |||
152 | return errors; | ||
153 | } | ||
diff --git a/src/regress/lib/libc/gcvt/Makefile b/src/regress/lib/libc/gcvt/Makefile deleted file mode 100644 index d8efaa9362..0000000000 --- a/src/regress/lib/libc/gcvt/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2010/09/17 19:51:38 millert Exp $ | ||
2 | |||
3 | PROG= gcvt_test | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/gcvt/gcvt_test.c b/src/regress/lib/libc/gcvt/gcvt_test.c deleted file mode 100644 index d687cb8063..0000000000 --- a/src/regress/lib/libc/gcvt/gcvt_test.c +++ /dev/null | |||
@@ -1,120 +0,0 @@ | |||
1 | /* $OpenBSD: gcvt_test.c,v 1.5 2019/01/25 00:19:26 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Public domain, 2010, Todd C. Miller <millert@openbsd.org> | ||
5 | */ | ||
6 | |||
7 | #include <stdio.h> | ||
8 | #include <stdlib.h> | ||
9 | #include <string.h> | ||
10 | |||
11 | static struct test_vector { | ||
12 | double d; | ||
13 | int ndig; | ||
14 | char *expect; | ||
15 | } test_vectors[] = { | ||
16 | /* adapted from perl's Configure test */ | ||
17 | { 0.1, 8, "0.1" }, | ||
18 | { 0.01, 8, "0.01" }, | ||
19 | { 0.001, 8, "0.001" }, | ||
20 | { 0.0001, 8, "0.0001" }, | ||
21 | { 0.00009, 8, "9e-05" }, | ||
22 | { 1.0, 8, "1" }, | ||
23 | { 1.1, 8, "1.1" }, | ||
24 | { 1.01, 8, "1.01" }, | ||
25 | { 1.001, 8, "1.001" }, | ||
26 | { 1.0001, 8, "1.0001" }, | ||
27 | { 1.00001, 8, "1.00001" }, | ||
28 | { 1.000001, 8, "1.000001" }, | ||
29 | { 0.0, 8, "0" }, | ||
30 | { -1.0, 8, "-1" }, | ||
31 | { 100000.0, 8, "100000" }, | ||
32 | { -100000.0, 8, "-100000" }, | ||
33 | { 123.456, 8, "123.456" }, | ||
34 | { 1e34, 8, "1e+34" }, | ||
35 | /* adapted from emx */ | ||
36 | { 0.0, -1, "0" }, | ||
37 | { 0.0, 0, "0" }, | ||
38 | { 0.0, 1, "0" }, | ||
39 | { 0.0, 2, "0" }, | ||
40 | { 1.0, -1, "1" }, | ||
41 | { 1.0, 0, "1" }, | ||
42 | { 1.0, 2, "1" }, | ||
43 | { 1.0, 10, "1" }, | ||
44 | { 1.236, -1, "1.236" }, | ||
45 | { 1.236, 0, "1" }, | ||
46 | { 1.236, 1, "1" }, | ||
47 | { 1.236, 2, "1.2" }, | ||
48 | { 1.236, 3, "1.24" }, | ||
49 | { 1.236, 4, "1.236" }, | ||
50 | { 1.236, 5, "1.236" }, | ||
51 | { 1.236, 6, "1.236" }, | ||
52 | { 12.36, -1, "12.36" }, | ||
53 | { 12.36, 0, "1e+01" }, | ||
54 | { 12.36, 1, "1e+01" }, | ||
55 | { 12.36, 2, "12" }, | ||
56 | { 12.36, 3, "12.4" }, | ||
57 | { 12.36, 4, "12.36" }, | ||
58 | { 12.36, 5, "12.36" }, | ||
59 | { 12.36, 6, "12.36" }, | ||
60 | { 123.6, -1, "123.6" }, | ||
61 | { 123.6, 0, "1e+02" }, | ||
62 | { 123.6, 1, "1e+02" }, | ||
63 | { 123.6, 2, "1.2e+02" }, | ||
64 | { 123.6, 3, "124" }, | ||
65 | { 123.6, 4, "123.6" }, | ||
66 | { 123.6, 5, "123.6" }, | ||
67 | { 123.6, 6, "123.6" }, | ||
68 | { 1236.0, -1, "1236" }, | ||
69 | { 1236.0, 0, "1e+03" }, | ||
70 | { 1236.0, 1, "1e+03" }, | ||
71 | { 1236.0, 2, "1.2e+03" }, | ||
72 | { 1236.0, 3, "1.24e+03" }, | ||
73 | { 1236.0, 4, "1236" }, | ||
74 | { 1236.0, 5, "1236" }, | ||
75 | { 1236.0, 6, "1236" }, | ||
76 | { 1e100, 10, "1e+100" }, | ||
77 | { 1e100, 20, "1.0000000000000000159e+100" }, | ||
78 | { 0.01236, -1, "0.01236" }, | ||
79 | { 0.01236, 0, "0.01" }, | ||
80 | { 0.01236, 1, "0.01" }, | ||
81 | { 0.01236, 2, "0.012" }, | ||
82 | { 0.01236, 3, "0.0124" }, | ||
83 | { 0.01236, 4, "0.01236" }, | ||
84 | { 1e-100, 20, "1.00000000000000002e-100" }, | ||
85 | { 1e-100, -1, "1e-100" }, | ||
86 | { -1.2, 5, "-1.2" }, | ||
87 | { -0.03, 5, "-0.03" }, | ||
88 | { 0.1, 1, "0.1" }, | ||
89 | { 0.1, 0, "0.1" }, | ||
90 | { 0.099999, 10, "0.099999" }, | ||
91 | { 0.99999, 10, "0.99999" }, | ||
92 | }; | ||
93 | |||
94 | #define NTESTVEC (sizeof(test_vectors) / sizeof(test_vectors[0])) | ||
95 | |||
96 | static int | ||
97 | dotest(struct test_vector *tv) | ||
98 | { | ||
99 | char buf[256], *got; | ||
100 | |||
101 | got = gcvt(tv->d, tv->ndig, buf); | ||
102 | if (strcmp(tv->expect, got) != 0) { | ||
103 | fprintf(stderr, "%g @ %d: expected %s, got %s\n", | ||
104 | tv->d, tv->ndig, tv->expect, got); | ||
105 | return 1; | ||
106 | } | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | int | ||
111 | main(int argc, char *argv[]) | ||
112 | { | ||
113 | int i, failures = 0; | ||
114 | |||
115 | for (i = 0; i < NTESTVEC; i++) { | ||
116 | failures += dotest(&test_vectors[i]); | ||
117 | } | ||
118 | |||
119 | return failures; | ||
120 | } | ||
diff --git a/src/regress/lib/libc/getaddrinfo/Makefile b/src/regress/lib/libc/getaddrinfo/Makefile deleted file mode 100644 index 7a78438a12..0000000000 --- a/src/regress/lib/libc/getaddrinfo/Makefile +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.5 2017/07/27 17:43:24 bluhm Exp $ | ||
2 | |||
3 | PROG = gaitest | ||
4 | CLEANFILES = out | ||
5 | |||
6 | run-regress-${PROG}: ${PROG} | ||
7 | sh ${.CURDIR}/testsuite.sh >out 2>&1 | ||
8 | diff -u10 out ${.CURDIR}/answer | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getaddrinfo/answer b/src/regress/lib/libc/getaddrinfo/answer deleted file mode 100644 index af6d069bbe..0000000000 --- a/src/regress/lib/libc/getaddrinfo/answer +++ /dev/null | |||
@@ -1,110 +0,0 @@ | |||
1 | == basic ones | ||
2 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv http | ||
3 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
4 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv http | ||
5 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
6 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv http | ||
7 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
8 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
9 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv tftp | ||
10 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 | ||
11 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv tftp | ||
12 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 | ||
13 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv tftp | ||
14 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 | ||
15 | ai2: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 | ||
16 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv echo | ||
17 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7 | ||
18 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7 | ||
19 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv echo | ||
20 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7 | ||
21 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7 | ||
22 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv echo | ||
23 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7 | ||
24 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7 | ||
25 | ai3: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7 | ||
26 | ai4: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7 | ||
27 | |||
28 | == specific address family | ||
29 | arg: flags 0x2 family 2 socktype 0 protocol 0 addrlen 0 host localhost serv http | ||
30 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
31 | arg: flags 0x2 family 24 socktype 0 protocol 0 addrlen 0 host localhost serv http | ||
32 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
33 | |||
34 | == empty hostname | ||
35 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http | ||
36 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
37 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
38 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo | ||
39 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7 | ||
40 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7 | ||
41 | ai3: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7 | ||
42 | ai4: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7 | ||
43 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp | ||
44 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 | ||
45 | ai2: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 | ||
46 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80 | ||
47 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 80 | ||
48 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
49 | ai3: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 80 | ||
50 | ai4: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
51 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http | ||
52 | ai1: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 80 | ||
53 | ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 80 | ||
54 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo | ||
55 | ai1: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 7 | ||
56 | ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 7 | ||
57 | ai3: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 7 | ||
58 | ai4: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 7 | ||
59 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp | ||
60 | ai1: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 69 | ||
61 | ai2: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 69 | ||
62 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80 | ||
63 | ai1: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 80 | ||
64 | ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 80 | ||
65 | ai3: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 80 | ||
66 | ai4: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 80 | ||
67 | arg: flags 0x2 family 0 socktype 1 protocol 0 addrlen 0 host (empty) serv 80 | ||
68 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
69 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
70 | arg: flags 0x2 family 0 socktype 2 protocol 0 addrlen 0 host (empty) serv 80 | ||
71 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 80 | ||
72 | ai2: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 80 | ||
73 | |||
74 | == empty servname | ||
75 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv (empty) | ||
76 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 | ||
77 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 | ||
78 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv (empty) | ||
79 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 | ||
80 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 | ||
81 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv (empty) | ||
82 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 | ||
83 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 | ||
84 | ai3: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 | ||
85 | ai4: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 | ||
86 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv (empty) | ||
87 | name or service is not known | ||
88 | |||
89 | == sock_raw | ||
90 | arg: flags 0x2 family 0 socktype 3 protocol 0 addrlen 0 host localhost serv (empty) | ||
91 | ai1: flags 0x2 family 2 socktype 3 protocol 0 addrlen 16 host 127.0.0.1 serv 0 | ||
92 | ai2: flags 0x2 family 24 socktype 3 protocol 0 addrlen 28 host ::1 serv 0 | ||
93 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv (empty) | ||
94 | ai1: flags 0x2 family 2 socktype 3 protocol 59 addrlen 16 host 127.0.0.1 serv 0 | ||
95 | ai2: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 | ||
96 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv 80 | ||
97 | service not supported for ai_socktype | ||
98 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv www | ||
99 | service not supported for ai_socktype | ||
100 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host ::1 serv (empty) | ||
101 | ai1: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 | ||
102 | |||
103 | == unsupported family | ||
104 | arg: flags 0x2 family 99 socktype 0 protocol 0 addrlen 0 host localhost serv (empty) | ||
105 | ai_family not supported | ||
106 | |||
107 | == the following items are specified in jinmei scopeaddr format doc. | ||
108 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host fe80::1%lo0 serv http | ||
109 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host fe80::1%lo0 serv 80 | ||
110 | |||
diff --git a/src/regress/lib/libc/getaddrinfo/gaitest.c b/src/regress/lib/libc/getaddrinfo/gaitest.c deleted file mode 100644 index 2508c05e02..0000000000 --- a/src/regress/lib/libc/getaddrinfo/gaitest.c +++ /dev/null | |||
@@ -1,193 +0,0 @@ | |||
1 | /* $OpenBSD: gaitest.c,v 1.7 2020/02/14 19:17:33 schwarze Exp $ */ | ||
2 | /* $NetBSD: gaitest.c,v 1.3 2002/07/05 15:47:43 itojun Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * 3. Neither the name of the project nor the names of its contributors | ||
17 | * may be used to endorse or promote products derived from this software | ||
18 | * without specific prior written permission. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | ||
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | ||
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
30 | * SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | /* | ||
34 | * Please note: the order of the responses (and the regress test) | ||
35 | * is dependent on the "family" keywords in resolv.conf. | ||
36 | * | ||
37 | * This expects the default behaviour of "family inet4 inet6" | ||
38 | */ | ||
39 | |||
40 | #include <sys/types.h> | ||
41 | #include <sys/socket.h> | ||
42 | #include <netinet/in.h> | ||
43 | #include <arpa/inet.h> | ||
44 | #include <netdb.h> | ||
45 | #include <stdio.h> | ||
46 | #include <stdlib.h> | ||
47 | #include <string.h> | ||
48 | #include <unistd.h> | ||
49 | |||
50 | struct addrinfo ai; | ||
51 | |||
52 | char host[NI_MAXHOST]; | ||
53 | char serv[NI_MAXSERV]; | ||
54 | int vflag = 0; | ||
55 | |||
56 | static void usage(void); | ||
57 | static void print1(const char *, const struct addrinfo *, char *, char *); | ||
58 | int main(int, char *[]); | ||
59 | |||
60 | static void | ||
61 | usage() | ||
62 | { | ||
63 | fprintf(stderr, "usage: test [-f family] [-s socktype] [-p proto] [-DPRSv46] host serv\n"); | ||
64 | } | ||
65 | |||
66 | static void | ||
67 | print1(title, res, h, s) | ||
68 | const char *title; | ||
69 | const struct addrinfo *res; | ||
70 | char *h; | ||
71 | char *s; | ||
72 | { | ||
73 | char *start, *end; | ||
74 | int error; | ||
75 | const int niflag = NI_NUMERICHOST | NI_NUMERICSERV; | ||
76 | |||
77 | if (res->ai_addr) { | ||
78 | error = getnameinfo(res->ai_addr, res->ai_addr->sa_len, | ||
79 | host, sizeof(host), serv, sizeof(serv), | ||
80 | niflag); | ||
81 | h = host; | ||
82 | s = serv; | ||
83 | } else | ||
84 | error = 0; | ||
85 | |||
86 | if (vflag) { | ||
87 | start = "\t"; | ||
88 | end = "\n"; | ||
89 | } else { | ||
90 | start = " "; | ||
91 | end = ""; | ||
92 | } | ||
93 | printf("%s%s", title, end); | ||
94 | printf("%sflags 0x%x%s", start, res->ai_flags, end); | ||
95 | printf("%sfamily %d%s", start, res->ai_family, end); | ||
96 | printf("%ssocktype %d%s", start, res->ai_socktype, end); | ||
97 | printf("%sprotocol %d%s", start, res->ai_protocol, end); | ||
98 | printf("%saddrlen %d%s", start, res->ai_addrlen, end); | ||
99 | if (error) | ||
100 | printf("%serror %d%s", start, error, end); | ||
101 | else { | ||
102 | printf("%shost %s%s", start, h, end); | ||
103 | printf("%sserv %s%s", start, s, end); | ||
104 | } | ||
105 | #if 0 | ||
106 | if (res->ai_canonname) | ||
107 | printf("%scname \"%s\"%s", start, res->ai_canonname, end); | ||
108 | #endif | ||
109 | if (!vflag) | ||
110 | printf("\n"); | ||
111 | |||
112 | } | ||
113 | |||
114 | int | ||
115 | main(argc, argv) | ||
116 | int argc; | ||
117 | char *argv[]; | ||
118 | { | ||
119 | struct addrinfo *res; | ||
120 | int error, i; | ||
121 | char *p, *q; | ||
122 | int c; | ||
123 | char nbuf[10]; | ||
124 | |||
125 | memset(&ai, 0, sizeof(ai)); | ||
126 | ai.ai_family = PF_UNSPEC; | ||
127 | ai.ai_flags |= AI_CANONNAME; | ||
128 | while ((c = getopt(argc, argv, "Df:p:PRs:Sv46")) != -1) { | ||
129 | switch (c) { | ||
130 | case 'D': | ||
131 | ai.ai_socktype = SOCK_DGRAM; | ||
132 | break; | ||
133 | case 'f': | ||
134 | ai.ai_family = atoi(optarg); | ||
135 | break; | ||
136 | case 'p': | ||
137 | ai.ai_protocol = atoi(optarg); | ||
138 | break; | ||
139 | case 'P': | ||
140 | ai.ai_flags |= AI_PASSIVE; | ||
141 | break; | ||
142 | case 'R': | ||
143 | ai.ai_socktype = SOCK_RAW; | ||
144 | break; | ||
145 | case 's': | ||
146 | ai.ai_socktype = atoi(optarg); | ||
147 | break; | ||
148 | case 'S': | ||
149 | ai.ai_socktype = SOCK_STREAM; | ||
150 | break; | ||
151 | case 'v': | ||
152 | vflag++; | ||
153 | break; | ||
154 | case '4': | ||
155 | ai.ai_family = PF_INET; | ||
156 | break; | ||
157 | case '6': | ||
158 | ai.ai_family = PF_INET6; | ||
159 | break; | ||
160 | default: | ||
161 | usage(); | ||
162 | exit(1); | ||
163 | } | ||
164 | } | ||
165 | argc -= optind; | ||
166 | argv += optind; | ||
167 | |||
168 | if (argc != 2){ | ||
169 | usage(); | ||
170 | exit(1); | ||
171 | } | ||
172 | |||
173 | p = *argv[0] ? argv[0] : NULL; | ||
174 | q = *argv[1] ? argv[1] : NULL; | ||
175 | |||
176 | print1("arg:", &ai, p ? p : "(empty)", q ? q : "(empty)"); | ||
177 | |||
178 | error = getaddrinfo(p, q, &ai, &res); | ||
179 | if (error) { | ||
180 | printf("%s\n", gai_strerror(error)); | ||
181 | exit(1); | ||
182 | } | ||
183 | |||
184 | i = 1; | ||
185 | do { | ||
186 | snprintf(nbuf, sizeof(nbuf), "ai%d:", i); | ||
187 | print1(nbuf, res, NULL, NULL); | ||
188 | |||
189 | i++; | ||
190 | } while ((res = res->ai_next) != NULL); | ||
191 | |||
192 | exit(0); | ||
193 | } | ||
diff --git a/src/regress/lib/libc/getaddrinfo/testsuite.sh b/src/regress/lib/libc/getaddrinfo/testsuite.sh deleted file mode 100644 index 1e4e524054..0000000000 --- a/src/regress/lib/libc/getaddrinfo/testsuite.sh +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | # $OpenBSD: testsuite.sh,v 1.1 2002/07/05 15:54:30 itojun Exp $ | ||
2 | # $NetBSD: testsuite.sh,v 1.3 2002/07/05 15:49:11 itojun Exp $ | ||
3 | |||
4 | # | ||
5 | # Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project. | ||
6 | # All rights reserved. | ||
7 | # | ||
8 | # Redistribution and use in source and binary forms, with or without | ||
9 | # modification, are permitted provided that the following conditions | ||
10 | # are met: | ||
11 | # 1. Redistributions of source code must retain the above copyright | ||
12 | # notice, this list of conditions and the following disclaimer. | ||
13 | # 2. Redistributions in binary form must reproduce the above copyright | ||
14 | # notice, this list of conditions and the following disclaimer in the | ||
15 | # documentation and/or other materials provided with the distribution. | ||
16 | # 3. Neither the name of the project nor the names of its contributors | ||
17 | # may be used to endorse or promote products derived from this software | ||
18 | # without specific prior written permission. | ||
19 | # | ||
20 | # THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | ||
21 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | ||
24 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
25 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
26 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
27 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
29 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
30 | # SUCH DAMAGE. | ||
31 | # | ||
32 | |||
33 | TEST=./gaitest | ||
34 | #TEST='./test -v' | ||
35 | #IF=`ifconfig -a | grep -v '^ ' | sed -e 's/:.*//' | head -1 | awk '{print $1}'` | ||
36 | |||
37 | echo '== basic ones' | ||
38 | $TEST ::1 http | ||
39 | $TEST 127.0.0.1 http | ||
40 | $TEST localhost http | ||
41 | $TEST ::1 tftp | ||
42 | $TEST 127.0.0.1 tftp | ||
43 | $TEST localhost tftp | ||
44 | $TEST ::1 echo | ||
45 | $TEST 127.0.0.1 echo | ||
46 | $TEST localhost echo | ||
47 | echo | ||
48 | |||
49 | echo '== specific address family' | ||
50 | $TEST -4 localhost http | ||
51 | $TEST -6 localhost http | ||
52 | echo | ||
53 | |||
54 | echo '== empty hostname' | ||
55 | $TEST '' http | ||
56 | $TEST '' echo | ||
57 | $TEST '' tftp | ||
58 | $TEST '' 80 | ||
59 | $TEST -P '' http | ||
60 | $TEST -P '' echo | ||
61 | $TEST -P '' tftp | ||
62 | $TEST -P '' 80 | ||
63 | $TEST -S '' 80 | ||
64 | $TEST -D '' 80 | ||
65 | echo | ||
66 | |||
67 | echo '== empty servname' | ||
68 | $TEST ::1 '' | ||
69 | $TEST 127.0.0.1 '' | ||
70 | $TEST localhost '' | ||
71 | $TEST '' '' | ||
72 | echo | ||
73 | |||
74 | echo '== sock_raw' | ||
75 | $TEST -R -p 0 localhost '' | ||
76 | $TEST -R -p 59 localhost '' | ||
77 | $TEST -R -p 59 localhost 80 | ||
78 | $TEST -R -p 59 localhost www | ||
79 | $TEST -R -p 59 ::1 '' | ||
80 | echo | ||
81 | |||
82 | echo '== unsupported family' | ||
83 | $TEST -f 99 localhost '' | ||
84 | echo | ||
85 | |||
86 | echo '== the following items are specified in jinmei scopeaddr format doc.' | ||
87 | $TEST fe80::1%lo0 http | ||
88 | #$TEST fe80::1%$IF http | ||
89 | echo | ||
diff --git a/src/regress/lib/libc/getcap/Makefile b/src/regress/lib/libc/getcap/Makefile deleted file mode 100644 index 7b7ae394ff..0000000000 --- a/src/regress/lib/libc/getcap/Makefile +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2009/06/09 18:16:40 phessler Exp $ | ||
2 | |||
3 | PROG= getcaptest | ||
4 | |||
5 | REGRESS_TARGETS=shortcap | ||
6 | |||
7 | shortcap: getcaptest | ||
8 | ./getcaptest ${.CURDIR}/shortcap.in | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getcap/getcaptest.c b/src/regress/lib/libc/getcap/getcaptest.c deleted file mode 100644 index 0f4464b6c5..0000000000 --- a/src/regress/lib/libc/getcap/getcaptest.c +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | /* $OpenBSD: getcaptest.c,v 1.1 2006/03/10 05:28:57 ray Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Written by Raymond Lai <ray@cyth.net>. | ||
5 | * Public domain. | ||
6 | */ | ||
7 | |||
8 | #include <stdio.h> | ||
9 | #include <stdlib.h> | ||
10 | |||
11 | int | ||
12 | main(int argc, char *argv[]) | ||
13 | { | ||
14 | char *buf, *db_array[2]; | ||
15 | |||
16 | if (argc != 2) | ||
17 | return (1); | ||
18 | |||
19 | db_array[0] = argv[1]; | ||
20 | db_array[1] = NULL; | ||
21 | |||
22 | while (cgetnext(&buf, db_array) > 0) | ||
23 | puts(buf); | ||
24 | |||
25 | return (0); | ||
26 | } | ||
diff --git a/src/regress/lib/libc/getcap/shortcap.in b/src/regress/lib/libc/getcap/shortcap.in deleted file mode 100644 index 573541ac97..0000000000 --- a/src/regress/lib/libc/getcap/shortcap.in +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | 0 | ||
diff --git a/src/regress/lib/libc/getopt/Makefile b/src/regress/lib/libc/getopt/Makefile deleted file mode 100644 index bdafc965fe..0000000000 --- a/src/regress/lib/libc/getopt/Makefile +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2020/03/23 03:01:21 schwarze Exp $ | ||
2 | |||
3 | REGRESS_TARGETS = getopt | ||
4 | PROG = getopt-test | ||
5 | MAN = | ||
6 | |||
7 | getopt: ${PROG} | ||
8 | sh ${.CURDIR}/getopt.sh | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getopt/getopt-test.c b/src/regress/lib/libc/getopt/getopt-test.c deleted file mode 100644 index 40901dcfcf..0000000000 --- a/src/regress/lib/libc/getopt/getopt-test.c +++ /dev/null | |||
@@ -1,59 +0,0 @@ | |||
1 | /* $OpenBSD: getopt-test.c,v 1.1 2020/03/23 03:01:21 schwarze Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | #include <stdio.h> | ||
18 | #include <stdlib.h> | ||
19 | #include <unistd.h> | ||
20 | |||
21 | /* | ||
22 | * Process command line options and arguments according to the | ||
23 | * optstring in the environment variable OPTS. Write: | ||
24 | * OPT(c) for an option "-c" without an option argument | ||
25 | * OPT(carg) for an option "-c" with an option argument "arg" | ||
26 | * ARG(arg) for a non-option argument "arg" | ||
27 | * NONE(arg) for a non-option argument "arg" processed with OPTS =~ ^- | ||
28 | * ERR(?c) for an invalid option "-c", or one lacking an argument | ||
29 | * ERR(:c) for an option "-c" lacking an argument while OPTS =~ ^: | ||
30 | */ | ||
31 | int | ||
32 | main(int argc, char *argv[]) | ||
33 | { | ||
34 | char *optstring; | ||
35 | int ch; | ||
36 | |||
37 | if ((optstring = getenv("OPTS")) == NULL) | ||
38 | optstring = ""; | ||
39 | |||
40 | opterr = 0; | ||
41 | while ((ch = getopt(argc, argv, optstring)) != -1) { | ||
42 | switch (ch) { | ||
43 | case '\1': | ||
44 | printf("NONE(%s)", optarg); | ||
45 | break; | ||
46 | case ':': | ||
47 | case '?': | ||
48 | printf("ERR(%c%c)", ch, optopt); | ||
49 | break; | ||
50 | default: | ||
51 | printf("OPT(%c%s)", ch, optarg == NULL ? "" : optarg); | ||
52 | break; | ||
53 | } | ||
54 | } | ||
55 | while (optind < argc) | ||
56 | printf("ARG(%s)", argv[optind++]); | ||
57 | putchar('\n'); | ||
58 | return 0; | ||
59 | } | ||
diff --git a/src/regress/lib/libc/getopt/getopt.sh b/src/regress/lib/libc/getopt/getopt.sh deleted file mode 100644 index 6e02163d5b..0000000000 --- a/src/regress/lib/libc/getopt/getopt.sh +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # $OpenBSD: getopt.sh,v 1.2 2020/05/27 22:32:22 schwarze Exp $ | ||
4 | # | ||
5 | # Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org> | ||
6 | # | ||
7 | # Permission to use, copy, modify, and distribute this software for any | ||
8 | # purpose with or without fee is hereby granted, provided that the above | ||
9 | # copyright notice and this permission notice appear in all copies. | ||
10 | # | ||
11 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
12 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
13 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
14 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
15 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
16 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
17 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
18 | |||
19 | # Run ./getopt-test once. | ||
20 | # Function arguments: | ||
21 | # 1. optstring argument for getopt(3) | ||
22 | # 2. space-separated command line arguments | ||
23 | # 3. expected output from ./getopt-test | ||
24 | test1_getopt() | ||
25 | { | ||
26 | result=$(OPTS=$1 ./getopt-test $2) | ||
27 | test "$result" == "$3" && return | ||
28 | echo "OPTS=$1 ./getopt-test $2" | ||
29 | echo "expected: $3" | ||
30 | echo "result: $result" | ||
31 | irc=1 | ||
32 | } | ||
33 | |||
34 | # Test both without and with the optstring modifier "+", | ||
35 | # verifying that it makes no difference. | ||
36 | test2_getopt() | ||
37 | { | ||
38 | test1_getopt "$1" "$2" "$3" | ||
39 | test1_getopt "+$1" "$2" "$3" | ||
40 | } | ||
41 | |||
42 | # Also test with the GNU "-" optstring modifier, | ||
43 | # veryfying that it only changes ARG() to NONE(). | ||
44 | # This test function is inadequate in two situations: | ||
45 | # a) options follow non-option arguments that terminate option processing | ||
46 | # b) or any arguments follow explicit "--". | ||
47 | # In these cases, use test2_getopt() plus a separate test1_getopt(-...). | ||
48 | test3_getopt() | ||
49 | { | ||
50 | test2_getopt "$1" "$2" "$3" | ||
51 | test1_getopt "-$1" "$2" $(echo $3 | sed s/ARG/NONE/g) | ||
52 | } | ||
53 | |||
54 | irc=0 | ||
55 | |||
56 | # valid isolated options without arguments | ||
57 | test3_getopt ax '-a -x arg' 'OPT(a)OPT(x)ARG(arg)' | ||
58 | test3_getopt x- '- -x arg' 'OPT(-)OPT(x)ARG(arg)' | ||
59 | |||
60 | # invalid isolated options without arguments | ||
61 | test3_getopt ax '-a -y arg' 'OPT(a)ERR(?y)ARG(arg)' | ||
62 | test1_getopt :ax '-a -y arg' 'OPT(a)ERR(?y)ARG(arg)' | ||
63 | test2_getopt x '- -x arg' 'ARG(-)ARG(-x)ARG(arg)' | ||
64 | test1_getopt -x '- -x arg' 'NONE(-)OPT(x)NONE(arg)' | ||
65 | test3_getopt a- '-a - -x arg' 'OPT(a)OPT(-)ERR(?x)ARG(arg)' | ||
66 | test1_getopt :a- '-a - -x arg' 'OPT(a)OPT(-)ERR(?x)ARG(arg)' | ||
67 | |||
68 | # valid grouped options without arguments | ||
69 | test3_getopt ax '-ax arg' 'OPT(a)OPT(x)ARG(arg)' | ||
70 | test3_getopt ax- '-a- -x arg' 'OPT(a)OPT(-)OPT(x)ARG(arg)' | ||
71 | test3_getopt abx- '-a-b -x arg' 'OPT(a)OPT(-)OPT(b)OPT(x)ARG(arg)' | ||
72 | test3_getopt ax- '--a -x arg' 'OPT(-)OPT(a)OPT(x)ARG(arg)' | ||
73 | |||
74 | # invalid grouped options without arguments | ||
75 | test3_getopt ax '-ay arg' 'OPT(a)ERR(?y)ARG(arg)' | ||
76 | test1_getopt :ax '-ay arg' 'OPT(a)ERR(?y)ARG(arg)' | ||
77 | test3_getopt ax '-a- -x arg' 'OPT(a)ERR(?-)OPT(x)ARG(arg)' | ||
78 | test1_getopt :ax '-a- -x arg' 'OPT(a)ERR(?-)OPT(x)ARG(arg)' | ||
79 | test3_getopt abx '-a-b -x arg' 'OPT(a)ERR(?-)OPT(b)OPT(x)ARG(arg)' | ||
80 | test1_getopt :abx '-a-b -x arg' 'OPT(a)ERR(?-)OPT(b)OPT(x)ARG(arg)' | ||
81 | test3_getopt ax '--a -x arg' 'ERR(?-)OPT(a)OPT(x)ARG(arg)' | ||
82 | test1_getopt :ax '--a -x arg' 'ERR(?-)OPT(a)OPT(x)ARG(arg)' | ||
83 | |||
84 | # non-option arguments terminating option processing | ||
85 | test2_getopt ax '-a arg -x' 'OPT(a)ARG(arg)ARG(-x)' | ||
86 | test1_getopt -ax '-a arg1 -x arg2' 'OPT(a)NONE(arg1)OPT(x)NONE(arg2)' | ||
87 | test2_getopt ax '-a -- -x' 'OPT(a)ARG(-x)' | ||
88 | test1_getopt -ax '-a -- -x' 'OPT(a)ARG(-x)' | ||
89 | test2_getopt ax '-a - -x' 'OPT(a)ARG(-)ARG(-x)' | ||
90 | test1_getopt -ax '-a - -x arg' 'OPT(a)NONE(-)OPT(x)NONE(arg)' | ||
91 | |||
92 | # the ':' option never works | ||
93 | test1_getopt ::a '-:a arg' 'ERR(?:)OPT(a)ARG(arg)' | ||
94 | test1_getopt :::a '-: arg -a' 'ERR(?:)ARG(arg)ARG(-a)' | ||
95 | |||
96 | # isolated options with arguments | ||
97 | test3_getopt o: '-o' 'ERR(?o)' | ||
98 | test1_getopt :o: '-o' 'ERR(:o)' | ||
99 | test3_getopt o-: '-' 'ERR(?-)' | ||
100 | test1_getopt :-: '-' 'ERR(:-)' | ||
101 | test3_getopt o:x '-o arg -x arg' 'OPT(oarg)OPT(x)ARG(arg)' | ||
102 | test3_getopt o:x '-oarg -x arg' 'OPT(oarg)OPT(x)ARG(arg)' | ||
103 | test3_getopt o::x '-oarg -x arg' 'OPT(oarg)OPT(x)ARG(arg)' | ||
104 | test2_getopt o::x '-o arg -x' 'OPT(o)ARG(arg)ARG(-x)' | ||
105 | test1_getopt -o::x '-o arg1 -x arg2' 'OPT(o)NONE(arg1)OPT(x)NONE(arg2)' | ||
106 | test3_getopt o:x '-o -x arg' 'OPT(o-x)ARG(arg)' | ||
107 | test3_getopt o:x '-o -- -x arg' 'OPT(o--)OPT(x)ARG(arg)' | ||
108 | test3_getopt x-: '- arg -x arg' 'OPT(-arg)OPT(x)ARG(arg)' | ||
109 | test3_getopt x-: '--arg -x arg' 'OPT(-arg)OPT(x)ARG(arg)' | ||
110 | test3_getopt x-:: '--arg -x arg' 'OPT(-arg)OPT(x)ARG(arg)' | ||
111 | test2_getopt x-:: '- arg -x' 'OPT(-)ARG(arg)ARG(-x)' | ||
112 | test1_getopt --::x '- arg1 -x arg2' 'OPT(-)NONE(arg1)OPT(x)NONE(arg2)' | ||
113 | test3_getopt x-: '- -x arg' 'OPT(--x)ARG(arg)' | ||
114 | test3_getopt x-: '- -- -x arg' 'OPT(---)OPT(x)ARG(arg)' | ||
115 | |||
116 | # grouped options with arguments | ||
117 | test3_getopt ao: '-ao' 'OPT(a)ERR(?o)' | ||
118 | test1_getopt :ao: '-ao' 'OPT(a)ERR(:o)' | ||
119 | test3_getopt a-: '-a-' 'OPT(a)ERR(?-)' | ||
120 | test1_getopt :a-: '-a-' 'OPT(a)ERR(:-)' | ||
121 | test3_getopt ao:x '-ao arg -x arg' 'OPT(a)OPT(oarg)OPT(x)ARG(arg)' | ||
122 | test3_getopt ao:x '-aoarg -x arg' 'OPT(a)OPT(oarg)OPT(x)ARG(arg)' | ||
123 | test3_getopt ao::x '-aoarg -x arg' 'OPT(a)OPT(oarg)OPT(x)ARG(arg)' | ||
124 | test2_getopt ao::x '-ao arg -x' 'OPT(a)OPT(o)ARG(arg)ARG(-x)' | ||
125 | test1_getopt -ao::x '-ao arg1 -x arg2' 'OPT(a)OPT(o)NONE(arg1)OPT(x)NONE(arg2)' | ||
126 | test3_getopt ao:x '-ao -x arg' 'OPT(a)OPT(o-x)ARG(arg)' | ||
127 | test3_getopt ao:x '-ao -- -x arg' 'OPT(a)OPT(o--)OPT(x)ARG(arg)' | ||
128 | test3_getopt a-:x '-a- arg -x arg' 'OPT(a)OPT(-arg)OPT(x)ARG(arg)' | ||
129 | test3_getopt a-:x '-a-arg -x arg' 'OPT(a)OPT(-arg)OPT(x)ARG(arg)' | ||
130 | test3_getopt a-::x '-a-arg -x arg' 'OPT(a)OPT(-arg)OPT(x)ARG(arg)' | ||
131 | test2_getopt a-::x '-a- arg -x' 'OPT(a)OPT(-)ARG(arg)ARG(-x)' | ||
132 | test1_getopt -a-::x '-a- arg1 -x arg2' 'OPT(a)OPT(-)NONE(arg1)OPT(x)NONE(arg2)' | ||
133 | test3_getopt a-:x '-a- -x arg' 'OPT(a)OPT(--x)ARG(arg)' | ||
134 | test3_getopt a-:x '-a- -- -x arg' 'OPT(a)OPT(---)OPT(x)ARG(arg)' | ||
135 | |||
136 | exit $irc | ||
diff --git a/src/regress/lib/libc/getopt_long/Makefile b/src/regress/lib/libc/getopt_long/Makefile deleted file mode 100644 index 13a187e190..0000000000 --- a/src/regress/lib/libc/getopt_long/Makefile +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.4 2002/12/08 19:25:08 millert Exp $ | ||
2 | |||
3 | NOMAN= | ||
4 | PROG=getopt_long_test | ||
5 | CLEANFILES+=test.out | ||
6 | |||
7 | # test getopt_long and getopt_long_only | ||
8 | run-regress-${PROG}: ${PROG} | ||
9 | @( test -n "$$POSIXLY_CORRECT" && unset POSIXLY_CORRECT; \ | ||
10 | test -n "$$LONG_ONLY" && unset LONG_ONLY; \ | ||
11 | ./${PROG} myfile --force -f infile -9 ; \ | ||
12 | ./${PROG} onefile twofile --best -Williterate -i foo.in threefile ; \ | ||
13 | ./${PROG} -1bfast - ; \ | ||
14 | ./${PROG} --fast --drinking=guiness -i foo.in somefile ; \ | ||
15 | export POSIXLY_CORRECT=1 ; \ | ||
16 | ./${PROG} myfile --force -f infile -9 ; \ | ||
17 | ./${PROG} onefile twofile --best -Williterate -i foo.in threefile ; \ | ||
18 | ./${PROG} -1bfast - ; \ | ||
19 | ./${PROG} --fast --drinking=guiness -i foo.in somefile ; \ | ||
20 | unset POSIXLY_CORRECT ; export LONG_ONLY=1 ; \ | ||
21 | ./${PROG} myfile -force -f infile -9 ; \ | ||
22 | ./${PROG} onefile twofile -best -Williterate -i foo.in threefile ; \ | ||
23 | ./${PROG} -1bfast - ; \ | ||
24 | ./${PROG} --fast -drinking=guiness -i foo.in somefile ; \ | ||
25 | export POSIXLY_CORRECT=1 ; \ | ||
26 | ./${PROG} myfile -force -f infile -9 ; \ | ||
27 | ./${PROG} onefile twofile -best -Williterate -i foo.in threefile ; \ | ||
28 | ./${PROG} -1bfast - ; \ | ||
29 | ./${PROG} --fast -drinking=guiness -i foo.in somefile ) >test.out 2>&1 | ||
30 | cmp -s ${.OBJDIR}/test.out ${.CURDIR}/test.ok | ||
31 | |||
32 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getopt_long/getopt_long_test.c b/src/regress/lib/libc/getopt_long/getopt_long_test.c deleted file mode 100644 index 9e32f94501..0000000000 --- a/src/regress/lib/libc/getopt_long/getopt_long_test.c +++ /dev/null | |||
@@ -1,114 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2002 Todd C. Miller <millert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | * | ||
16 | * Sponsored in part by the Defense Advanced Research Projects | ||
17 | * Agency (DARPA) and Air Force Research Laboratory, Air Force | ||
18 | * Materiel Command, USAF, under agreement number F39502-99-1-0512. | ||
19 | */ | ||
20 | |||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <getopt.h> | ||
24 | |||
25 | /* | ||
26 | * Simple getopt_long() and getopt_long_only() excerciser. | ||
27 | * ENVIRONMENT: | ||
28 | * LONG_ONLY : use getopt_long_only() (default is getopt_long()) | ||
29 | * POSIXLY_CORRECT : don't permute args | ||
30 | */ | ||
31 | |||
32 | int | ||
33 | main(int argc, char **argv) | ||
34 | { | ||
35 | int ch, idx, goggles; | ||
36 | int (*gl)(int, char * const *, const char *, const struct option *, int *); | ||
37 | struct option longopts[] = { | ||
38 | { "force", no_argument, 0, 0 }, | ||
39 | { "fast", no_argument, 0, '1' }, | ||
40 | { "best", no_argument, 0, '9' }, | ||
41 | { "input", required_argument, 0, 'i' }, | ||
42 | { "illiterate", no_argument, 0, 0 }, | ||
43 | { "drinking", required_argument, &goggles, 42 }, | ||
44 | { "help", no_argument, 0, 'h' }, | ||
45 | { 0, 0, 0, 0 }, | ||
46 | }; | ||
47 | |||
48 | if (getenv("LONG_ONLY")) { | ||
49 | gl = getopt_long_only; | ||
50 | printf("getopt_long_only"); | ||
51 | } else { | ||
52 | gl = getopt_long; | ||
53 | printf("getopt_long"); | ||
54 | } | ||
55 | if (getenv("POSIXLY_CORRECT")) | ||
56 | printf(" (POSIXLY_CORRECT)"); | ||
57 | printf(": "); | ||
58 | for (idx = 1; idx < argc; idx++) | ||
59 | printf("%s ", argv[idx]); | ||
60 | printf("\n"); | ||
61 | |||
62 | goggles = 0; | ||
63 | for (;;) { | ||
64 | idx = -1; | ||
65 | ch = gl(argc, argv, "19bf:i:hW;-", longopts, &idx); | ||
66 | if (ch == -1) | ||
67 | break; | ||
68 | switch (ch) { | ||
69 | case 0: | ||
70 | case '1': | ||
71 | case '9': | ||
72 | case 'h': | ||
73 | case 'b': | ||
74 | case '-': | ||
75 | if (idx != -1) { | ||
76 | if (goggles == 42) | ||
77 | printf("option %s, arg %s\n", | ||
78 | longopts[idx].name, optarg); | ||
79 | else | ||
80 | printf("option %s\n", | ||
81 | longopts[idx].name); | ||
82 | } else | ||
83 | printf("option %c\n", ch); | ||
84 | break; | ||
85 | case 'f': | ||
86 | case 'i': | ||
87 | if (idx != -1) | ||
88 | printf("option %s, arg %s\n", | ||
89 | longopts[idx].name, optarg); | ||
90 | else | ||
91 | printf("option %c, arg %s\n", ch, optarg); | ||
92 | break; | ||
93 | |||
94 | case '?': | ||
95 | break; | ||
96 | |||
97 | default: | ||
98 | printf("unexpected return value: %c\n", ch); | ||
99 | break; | ||
100 | } | ||
101 | } | ||
102 | argc -= optind; | ||
103 | argv += optind; | ||
104 | |||
105 | if (argc > 0) { | ||
106 | printf("remaining ARGV: "); | ||
107 | while (argc--) | ||
108 | printf("%s ", *argv++); | ||
109 | printf("\n"); | ||
110 | } | ||
111 | printf("\n"); | ||
112 | |||
113 | exit (0); | ||
114 | } | ||
diff --git a/src/regress/lib/libc/getopt_long/test.ok b/src/regress/lib/libc/getopt_long/test.ok deleted file mode 100644 index 9782087f40..0000000000 --- a/src/regress/lib/libc/getopt_long/test.ok +++ /dev/null | |||
@@ -1,84 +0,0 @@ | |||
1 | getopt_long: myfile --force -f infile -9 | ||
2 | option force | ||
3 | option f, arg infile | ||
4 | option 9 | ||
5 | remaining ARGV: myfile | ||
6 | |||
7 | getopt_long: onefile twofile --best -Williterate -i foo.in threefile | ||
8 | option best | ||
9 | option illiterate | ||
10 | option i, arg foo.in | ||
11 | remaining ARGV: onefile twofile threefile | ||
12 | |||
13 | getopt_long: -1bfast - | ||
14 | option 1 | ||
15 | option b | ||
16 | option f, arg ast | ||
17 | option - | ||
18 | |||
19 | getopt_long: --fast --drinking=guiness -i foo.in somefile | ||
20 | option fast | ||
21 | option drinking, arg guiness | ||
22 | option i, arg foo.in | ||
23 | remaining ARGV: somefile | ||
24 | |||
25 | getopt_long (POSIXLY_CORRECT): myfile --force -f infile -9 | ||
26 | remaining ARGV: myfile --force -f infile -9 | ||
27 | |||
28 | getopt_long (POSIXLY_CORRECT): onefile twofile --best -Williterate -i foo.in threefile | ||
29 | remaining ARGV: onefile twofile --best -Williterate -i foo.in threefile | ||
30 | |||
31 | getopt_long (POSIXLY_CORRECT): -1bfast - | ||
32 | option 1 | ||
33 | option b | ||
34 | option f, arg ast | ||
35 | option - | ||
36 | |||
37 | getopt_long (POSIXLY_CORRECT): --fast --drinking=guiness -i foo.in somefile | ||
38 | option fast | ||
39 | option drinking, arg guiness | ||
40 | option i, arg foo.in | ||
41 | remaining ARGV: somefile | ||
42 | |||
43 | getopt_long_only: myfile -force -f infile -9 | ||
44 | option force | ||
45 | option f, arg infile | ||
46 | option 9 | ||
47 | remaining ARGV: myfile | ||
48 | |||
49 | getopt_long_only: onefile twofile -best -Williterate -i foo.in threefile | ||
50 | option best | ||
51 | option illiterate | ||
52 | option i, arg foo.in | ||
53 | remaining ARGV: onefile twofile threefile | ||
54 | |||
55 | getopt_long_only: -1bfast - | ||
56 | option 1 | ||
57 | option b | ||
58 | option fast | ||
59 | option - | ||
60 | |||
61 | getopt_long_only: --fast -drinking=guiness -i foo.in somefile | ||
62 | option fast | ||
63 | option drinking, arg guiness | ||
64 | option i, arg foo.in | ||
65 | remaining ARGV: somefile | ||
66 | |||
67 | getopt_long_only (POSIXLY_CORRECT): myfile -force -f infile -9 | ||
68 | remaining ARGV: myfile -force -f infile -9 | ||
69 | |||
70 | getopt_long_only (POSIXLY_CORRECT): onefile twofile -best -Williterate -i foo.in threefile | ||
71 | remaining ARGV: onefile twofile -best -Williterate -i foo.in threefile | ||
72 | |||
73 | getopt_long_only (POSIXLY_CORRECT): -1bfast - | ||
74 | option 1 | ||
75 | option b | ||
76 | option fast | ||
77 | option - | ||
78 | |||
79 | getopt_long_only (POSIXLY_CORRECT): --fast -drinking=guiness -i foo.in somefile | ||
80 | option fast | ||
81 | option drinking, arg guiness | ||
82 | option i, arg foo.in | ||
83 | remaining ARGV: somefile | ||
84 | |||
diff --git a/src/regress/lib/libc/glob/Makefile b/src/regress/lib/libc/glob/Makefile deleted file mode 100644 index b3f9567833..0000000000 --- a/src/regress/lib/libc/glob/Makefile +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.4 2011/05/01 04:25:40 guenther Exp $ | ||
2 | |||
3 | PROG= globtest | ||
4 | |||
5 | run-regress-${PROG}: | ||
6 | mkdir -m 755 -p `sed 's@/[^/]*$$@@' ${.CURDIR}/files | sort -u` | ||
7 | umask 022; touch `cat ${.CURDIR}/files` | ||
8 | chmod 0755 `grep '/r[^/]*$$' ${.CURDIR}/files` | ||
9 | chmod 0444 `grep '/s[^/]*$$' ${.CURDIR}/files` | ||
10 | chmod 0711 `grep '/t[^/]*$$' ${.CURDIR}/files` | ||
11 | ./${PROG} ${.CURDIR}/${PROG}.in | ||
12 | |||
13 | clean: | ||
14 | rm -rf fake ${PROG} ${OBJS} *.core | ||
15 | |||
16 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/glob/files b/src/regress/lib/libc/glob/files deleted file mode 100644 index c5e92aacd5..0000000000 --- a/src/regress/lib/libc/glob/files +++ /dev/null | |||
@@ -1,47 +0,0 @@ | |||
1 | fake/bin/[ | ||
2 | fake/bin/cat | ||
3 | fake/bin/chgrp | ||
4 | fake/bin/chio | ||
5 | fake/bin/chmod | ||
6 | fake/bin/cksum | ||
7 | fake/bin/cp | ||
8 | fake/bin/cpio | ||
9 | fake/bin/csh | ||
10 | fake/bin/date | ||
11 | fake/bin/dd | ||
12 | fake/bin/df | ||
13 | fake/bin/domainname | ||
14 | fake/bin/echo | ||
15 | fake/bin/ed | ||
16 | fake/bin/eject | ||
17 | fake/bin/expr | ||
18 | fake/bin/hostname | ||
19 | fake/bin/kill | ||
20 | fake/bin/ksh | ||
21 | fake/bin/ln | ||
22 | fake/bin/ls | ||
23 | fake/bin/md5 | ||
24 | fake/bin/mkdir | ||
25 | fake/bin/mt | ||
26 | fake/bin/mv | ||
27 | fake/bin/pax | ||
28 | fake/bin/ps | ||
29 | fake/bin/pwd | ||
30 | fake/bin/rcp | ||
31 | fake/bin/rksh | ||
32 | fake/bin/rm | ||
33 | fake/bin/rmail | ||
34 | fake/bin/rmd160 | ||
35 | fake/bin/rmdir | ||
36 | fake/bin/sh | ||
37 | fake/bin/sha1 | ||
38 | fake/bin/sha256 | ||
39 | fake/bin/sha384 | ||
40 | fake/bin/sha512 | ||
41 | fake/bin/sleep | ||
42 | fake/bin/stty | ||
43 | fake/bin/sum | ||
44 | fake/bin/sync | ||
45 | fake/bin/systrace | ||
46 | fake/bin/tar | ||
47 | fake/bin/test | ||
diff --git a/src/regress/lib/libc/glob/globtest.c b/src/regress/lib/libc/glob/globtest.c deleted file mode 100644 index 1f6037d5bc..0000000000 --- a/src/regress/lib/libc/glob/globtest.c +++ /dev/null | |||
@@ -1,142 +0,0 @@ | |||
1 | /* $OpenBSD: globtest.c,v 1.4 2019/01/25 00:19:26 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Public domain, 2008, Todd C. Miller <millert@openbsd.org> | ||
5 | */ | ||
6 | |||
7 | #include <err.h> | ||
8 | #include <glob.h> | ||
9 | #include <stdio.h> | ||
10 | #include <stdlib.h> | ||
11 | #include <string.h> | ||
12 | |||
13 | #define MAX_RESULTS 256 | ||
14 | |||
15 | struct gl_entry { | ||
16 | int flags; | ||
17 | int nresults; | ||
18 | char pattern[1024]; | ||
19 | char *results[MAX_RESULTS]; | ||
20 | mode_t modes[MAX_RESULTS]; | ||
21 | }; | ||
22 | |||
23 | int test_glob(struct gl_entry *); | ||
24 | |||
25 | int | ||
26 | main(int argc, char **argv) | ||
27 | { | ||
28 | FILE *fp = stdin; | ||
29 | char *buf, *cp; | ||
30 | int errors = 0, lineno, mode; | ||
31 | struct gl_entry entry; | ||
32 | size_t len; | ||
33 | |||
34 | if (argc > 1) { | ||
35 | if ((fp = fopen(argv[1], "r")) == NULL) | ||
36 | err(1, "%s", argv[1]); | ||
37 | } | ||
38 | |||
39 | /* | ||
40 | * Read in test file, which is formatted thusly: | ||
41 | * | ||
42 | * [pattern] <flags> | ||
43 | * result1 [mode] | ||
44 | * result2 [mode] | ||
45 | * result3 [mode] | ||
46 | * ... | ||
47 | * | ||
48 | */ | ||
49 | lineno = 0; | ||
50 | memset(&entry, 0, sizeof(entry)); | ||
51 | while ((buf = fgetln(fp, &len)) != NULL) { | ||
52 | lineno++; | ||
53 | if (buf[len - 1] != '\n') | ||
54 | errx(1, "missing newline at EOF"); | ||
55 | buf[--len] = '\0'; | ||
56 | if (len == 0) | ||
57 | continue; /* blank line */ | ||
58 | |||
59 | if (buf[0] == '[') { | ||
60 | /* check previous pattern */ | ||
61 | if (entry.pattern[0]) | ||
62 | errors += test_glob(&entry); | ||
63 | |||
64 | /* start new entry */ | ||
65 | if ((cp = strrchr(buf + 1, ']')) == NULL) | ||
66 | errx(1, "invalid entry on line %d", lineno); | ||
67 | len = cp - buf - 1; | ||
68 | if (len >= sizeof(entry.pattern)) | ||
69 | errx(1, "pattern too big on line %d", lineno); | ||
70 | memcpy(entry.pattern, buf + 1, len); | ||
71 | entry.pattern[len] = '\0'; | ||
72 | |||
73 | buf = cp + 2; | ||
74 | if (*buf++ != '<') | ||
75 | errx(1, "invalid entry on line %d", lineno); | ||
76 | if ((cp = strchr(buf, '>')) == NULL) | ||
77 | errx(1, "invalid entry on line %d", lineno); | ||
78 | entry.flags = (int)strtol(buf, &cp, 0); | ||
79 | if (*cp != '>' || entry.flags < 0 || entry.flags > 0x4000) | ||
80 | errx(1, "invalid flags: %s", buf); | ||
81 | entry.nresults = 0; | ||
82 | continue; | ||
83 | } | ||
84 | if (!entry.pattern[0]) | ||
85 | errx(1, "missing entry on line %d", lineno); | ||
86 | |||
87 | if (entry.nresults + 1 > MAX_RESULTS) { | ||
88 | errx(1, "too many results for %s, max %d", | ||
89 | entry.pattern, MAX_RESULTS); | ||
90 | } | ||
91 | if ((cp = strchr(buf, ' ')) != NULL) { | ||
92 | *cp++ = '\0'; | ||
93 | mode = strtol(cp, NULL, 8); | ||
94 | } else | ||
95 | mode = -1; | ||
96 | entry.modes[entry.nresults] = (mode_t)mode; | ||
97 | entry.results[entry.nresults++] = strdup(buf); | ||
98 | } | ||
99 | if (entry.pattern[0]) | ||
100 | errors += test_glob(&entry); /* test last pattern */ | ||
101 | exit(errors); | ||
102 | } | ||
103 | |||
104 | int test_glob(struct gl_entry *entry) | ||
105 | { | ||
106 | glob_t gl; | ||
107 | int i = 0; | ||
108 | |||
109 | if (glob(entry->pattern, entry->flags, NULL, &gl) != 0) | ||
110 | errx(1, "glob failed: %s", entry->pattern); | ||
111 | |||
112 | if (gl.gl_matchc != entry->nresults) | ||
113 | goto mismatch; | ||
114 | |||
115 | for (i = 0; i < gl.gl_matchc; i++) { | ||
116 | if (strcmp(gl.gl_pathv[i], entry->results[i]) != 0) | ||
117 | goto mismatch; | ||
118 | if ((entry->flags & GLOB_KEEPSTAT) != 0) { | ||
119 | if (entry->modes[i] == -1 || | ||
120 | gl.gl_statv[i] == NULL || | ||
121 | entry->modes[i] != gl.gl_statv[i]->st_mode) | ||
122 | goto badmode; | ||
123 | } | ||
124 | free(entry->results[i]); | ||
125 | } | ||
126 | return (0); | ||
127 | badmode: | ||
128 | warnx("mismatch mode for pattern %s, flags 0x%x, file \"%s\" " | ||
129 | "(found %07o, expected %07o)", entry->pattern, entry->flags, | ||
130 | gl.gl_pathv[i], gl.gl_statv[i] ? gl.gl_statv[i]->st_mode : 0, | ||
131 | entry->modes[i]); | ||
132 | goto cleanup; | ||
133 | mismatch: | ||
134 | warnx("mismatch for pattern %s, flags 0x%x " | ||
135 | "(found \"%s\", expected \"%s\")", entry->pattern, entry->flags, | ||
136 | gl.gl_pathv[i], entry->results[i]); | ||
137 | cleanup: | ||
138 | while (i < gl.gl_matchc) { | ||
139 | free(entry->results[i++]); | ||
140 | } | ||
141 | return (1); | ||
142 | } | ||
diff --git a/src/regress/lib/libc/glob/globtest.in b/src/regress/lib/libc/glob/globtest.in deleted file mode 100644 index 2ae3b4dfb2..0000000000 --- a/src/regress/lib/libc/glob/globtest.in +++ /dev/null | |||
@@ -1,116 +0,0 @@ | |||
1 | [fake/bin/[[:alpha:]]*] <0x0> | ||
2 | fake/bin/cat | ||
3 | fake/bin/chgrp | ||
4 | fake/bin/chio | ||
5 | fake/bin/chmod | ||
6 | fake/bin/cksum | ||
7 | fake/bin/cp | ||
8 | fake/bin/cpio | ||
9 | fake/bin/csh | ||
10 | fake/bin/date | ||
11 | fake/bin/dd | ||
12 | fake/bin/df | ||
13 | fake/bin/domainname | ||
14 | fake/bin/echo | ||
15 | fake/bin/ed | ||
16 | fake/bin/eject | ||
17 | fake/bin/expr | ||
18 | fake/bin/hostname | ||
19 | fake/bin/kill | ||
20 | fake/bin/ksh | ||
21 | fake/bin/ln | ||
22 | fake/bin/ls | ||
23 | fake/bin/md5 | ||
24 | fake/bin/mkdir | ||
25 | fake/bin/mt | ||
26 | fake/bin/mv | ||
27 | fake/bin/pax | ||
28 | fake/bin/ps | ||
29 | fake/bin/pwd | ||
30 | fake/bin/rcp | ||
31 | fake/bin/rksh | ||
32 | fake/bin/rm | ||
33 | fake/bin/rmail | ||
34 | fake/bin/rmd160 | ||
35 | fake/bin/rmdir | ||
36 | fake/bin/sh | ||
37 | fake/bin/sha1 | ||
38 | fake/bin/sha256 | ||
39 | fake/bin/sha384 | ||
40 | fake/bin/sha512 | ||
41 | fake/bin/sleep | ||
42 | fake/bin/stty | ||
43 | fake/bin/sum | ||
44 | fake/bin/sync | ||
45 | fake/bin/systrace | ||
46 | fake/bin/tar | ||
47 | fake/bin/test | ||
48 | |||
49 | [fake/bin/[[:alpha:]]*] <0x4000> | ||
50 | fake/bin/cat 0100644 | ||
51 | fake/bin/chgrp 0100644 | ||
52 | fake/bin/chio 0100644 | ||
53 | fake/bin/chmod 0100644 | ||
54 | fake/bin/cksum 0100644 | ||
55 | fake/bin/cp 0100644 | ||
56 | fake/bin/cpio 0100644 | ||
57 | fake/bin/csh 0100644 | ||
58 | fake/bin/date 0100644 | ||
59 | fake/bin/dd 0100644 | ||
60 | fake/bin/df 0100644 | ||
61 | fake/bin/domainname 0100644 | ||
62 | fake/bin/echo 0100644 | ||
63 | fake/bin/ed 0100644 | ||
64 | fake/bin/eject 0100644 | ||
65 | fake/bin/expr 0100644 | ||
66 | fake/bin/hostname 0100644 | ||
67 | fake/bin/kill 0100644 | ||
68 | fake/bin/ksh 0100644 | ||
69 | fake/bin/ln 0100644 | ||
70 | fake/bin/ls 0100644 | ||
71 | fake/bin/md5 0100644 | ||
72 | fake/bin/mkdir 0100644 | ||
73 | fake/bin/mt 0100644 | ||
74 | fake/bin/mv 0100644 | ||
75 | fake/bin/pax 0100644 | ||
76 | fake/bin/ps 0100644 | ||
77 | fake/bin/pwd 0100644 | ||
78 | fake/bin/rcp 0100755 | ||
79 | fake/bin/rksh 0100755 | ||
80 | fake/bin/rm 0100755 | ||
81 | fake/bin/rmail 0100755 | ||
82 | fake/bin/rmd160 0100755 | ||
83 | fake/bin/rmdir 0100755 | ||
84 | fake/bin/sh 0100444 | ||
85 | fake/bin/sha1 0100444 | ||
86 | fake/bin/sha256 0100444 | ||
87 | fake/bin/sha384 0100444 | ||
88 | fake/bin/sha512 0100444 | ||
89 | fake/bin/sleep 0100444 | ||
90 | fake/bin/stty 0100444 | ||
91 | fake/bin/sum 0100444 | ||
92 | fake/bin/sync 0100444 | ||
93 | fake/bin/systrace 0100444 | ||
94 | fake/bin/tar 0100711 | ||
95 | fake/bin/test 0100711 | ||
96 | |||
97 | [fake/bin/rm{,dir,ail}] <0x80> | ||
98 | fake/bin/rm | ||
99 | fake/bin/rmdir | ||
100 | fake/bin/rmail | ||
101 | |||
102 | [fake/bin/sha[[:digit:]]] <0x0> | ||
103 | fake/bin/sha1 | ||
104 | |||
105 | [fake/bin/sha[[:digit:]]*] <0x0> | ||
106 | fake/bin/sha1 | ||
107 | fake/bin/sha256 | ||
108 | fake/bin/sha384 | ||
109 | fake/bin/sha512 | ||
110 | |||
111 | [fake/bin/ca[a-z]] <0x0> | ||
112 | fake/bin/cat | ||
113 | |||
114 | [fake/b[a-z]*] <0x4000> | ||
115 | fake/bin 0040755 | ||
116 | |||
diff --git a/src/regress/lib/libc/hsearch/Makefile b/src/regress/lib/libc/hsearch/Makefile deleted file mode 100644 index cddc8ac0c4..0000000000 --- a/src/regress/lib/libc/hsearch/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2004/06/24 04:33:07 millert Exp $ | ||
2 | |||
3 | PROG= hsearchtest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/hsearch/hsearchtest.c b/src/regress/lib/libc/hsearch/hsearchtest.c deleted file mode 100644 index 8659ef7e77..0000000000 --- a/src/regress/lib/libc/hsearch/hsearchtest.c +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | /* $OpenBSD: hsearchtest.c,v 1.2 2009/10/27 23:59:32 deraadt Exp $ */ | ||
2 | /* $NetBSD: hsearchtest.c,v 1.5 2003/07/26 19:38:46 salo Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (c) 2001 Christopher G. Demetriou | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * 3. All advertising materials mentioning features or use of this software | ||
17 | * must display the following acknowledgement: | ||
18 | * This product includes software developed for the | ||
19 | * NetBSD Project. See http://www.NetBSD.org/ for | ||
20 | * information about NetBSD. | ||
21 | * 4. The name of the author may not be used to endorse or promote products | ||
22 | * derived from this software without specific prior written permission. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
34 | * | ||
35 | * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> | ||
36 | */ | ||
37 | |||
38 | /* | ||
39 | * Test program for hsearch() et al. | ||
40 | */ | ||
41 | |||
42 | #include <search.h> | ||
43 | #include <stdlib.h> | ||
44 | #include <stdio.h> | ||
45 | #include <string.h> | ||
46 | |||
47 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LINE__, #e)) | ||
48 | |||
49 | static void | ||
50 | testfail(const char *file, unsigned long line, const char *expression) | ||
51 | { | ||
52 | |||
53 | fprintf(stderr, "TEST FAILED: %s: file %s, line %ld\n", | ||
54 | expression, file, line); | ||
55 | exit(1); | ||
56 | } | ||
57 | |||
58 | int | ||
59 | main(int argc, char *argv[]) | ||
60 | { | ||
61 | ENTRY e, *ep, *ep2; | ||
62 | int created_ok; | ||
63 | char ch[2]; | ||
64 | int i; | ||
65 | |||
66 | created_ok = hcreate(16); | ||
67 | TEST(created_ok); | ||
68 | |||
69 | /* ch[1] should be constant from here on down. */ | ||
70 | ch[1] = '\0'; | ||
71 | |||
72 | /* Basic insertions. Check enough that there'll be collisions. */ | ||
73 | for (i = 0; i < 26; i++) { | ||
74 | ch[0] = 'a' + i; | ||
75 | e.key = strdup(ch); /* ptr to provided key is kept! */ | ||
76 | TEST(e.key != NULL); | ||
77 | e.data = (void *)(long)i; | ||
78 | ep = hsearch(e, ENTER); | ||
79 | TEST(ep != NULL); | ||
80 | TEST(strcmp(ep->key, ch) == 0); | ||
81 | TEST((long)ep->data == i); | ||
82 | } | ||
83 | |||
84 | /* e.key should be constant from here on down. */ | ||
85 | e.key = ch; | ||
86 | |||
87 | /* Basic lookups. */ | ||
88 | for (i = 0; i < 26; i++) { | ||
89 | ch[0] = 'a' + i; | ||
90 | ep = hsearch(e, FIND); | ||
91 | TEST(ep != NULL); | ||
92 | TEST(strcmp(ep->key, ch) == 0); | ||
93 | TEST((long)ep->data == i); | ||
94 | } | ||
95 | |||
96 | /* Check duplicate entry. Should _not_ overwrite existing data. */ | ||
97 | ch[0] = 'a'; | ||
98 | e.data = (void *)(long)12345; | ||
99 | ep = hsearch(e, FIND); | ||
100 | TEST(ep != NULL); | ||
101 | TEST(strcmp(ep->key, ch) == 0); | ||
102 | TEST((long)ep->data == 0); | ||
103 | |||
104 | /* Check for something that's not there. */ | ||
105 | ch[0] = 'A'; | ||
106 | ep = hsearch(e, FIND); | ||
107 | TEST(ep == NULL); | ||
108 | |||
109 | /* Check two at once. */ | ||
110 | ch[0] = 'a'; | ||
111 | ep = hsearch(e, FIND); | ||
112 | ch[0] = 'b'; | ||
113 | ep2 = hsearch(e, FIND); | ||
114 | TEST(ep != NULL); | ||
115 | TEST(strcmp(ep->key, "a") == 0 && (long)ep->data == 0); | ||
116 | TEST(ep2 != NULL); | ||
117 | TEST(strcmp(ep2->key, "b") == 0 && (long)ep2->data == 1); | ||
118 | |||
119 | hdestroy(); | ||
120 | |||
121 | exit(0); | ||
122 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/Makefile b/src/regress/lib/libc/ieeefp/Makefile deleted file mode 100644 index 89ff51a2e7..0000000000 --- a/src/regress/lib/libc/ieeefp/Makefile +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.6 2004/01/15 18:53:23 miod Exp $ | ||
2 | # $NetBSD: Makefile,v 1.5 1996/04/09 16:54:18 phil Exp $ | ||
3 | |||
4 | SUBDIR+= except inf infinity round | ||
5 | |||
6 | install: | ||
7 | |||
8 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/except/Makefile b/src/regress/lib/libc/ieeefp/except/Makefile deleted file mode 100644 index 0a16eb762e..0000000000 --- a/src/regress/lib/libc/ieeefp/except/Makefile +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.7 2021/06/17 12:55:38 kettenis Exp $ | ||
2 | |||
3 | PROG=except | ||
4 | |||
5 | REGRESS_TARGETS+= fltdiv fltinv fltovf fltund | ||
6 | |||
7 | .if ${MACHINE} == arm64 || ${MACHINE} == armv7 || ${MACHINE} == riscv64 | ||
8 | # Floating-point exceptions are optional and absent on most hardware | ||
9 | REGRESS_EXPECTED_FAILURES+= fltdiv fltinv fltovf fltund | ||
10 | .endif | ||
11 | |||
12 | fltdiv: ${PROG} | ||
13 | ./${PROG} fltdiv | ||
14 | |||
15 | fltinv: ${PROG} | ||
16 | ./${PROG} fltinv | ||
17 | |||
18 | fltovf: ${PROG} | ||
19 | ./${PROG} fltovf | ||
20 | |||
21 | fltund: ${PROG} | ||
22 | ./${PROG} fltund | ||
23 | |||
24 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/except/except.c b/src/regress/lib/libc/ieeefp/except/except.c deleted file mode 100644 index cc3dcf8e44..0000000000 --- a/src/regress/lib/libc/ieeefp/except/except.c +++ /dev/null | |||
@@ -1,110 +0,0 @@ | |||
1 | /* $OpenBSD: except.c,v 1.12 2010/05/08 19:16:33 naddy Exp $ */ | ||
2 | |||
3 | #include <sys/types.h> | ||
4 | #include <unistd.h> | ||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <string.h> | ||
8 | #include <signal.h> | ||
9 | #include <assert.h> | ||
10 | #include <ieeefp.h> | ||
11 | #include <float.h> | ||
12 | #include <err.h> | ||
13 | |||
14 | volatile sig_atomic_t signal_status; | ||
15 | |||
16 | volatile const double one = 1.0; | ||
17 | volatile const double zero = 0.0; | ||
18 | volatile const double huge = DBL_MAX; | ||
19 | volatile const double tiny = DBL_MIN; | ||
20 | |||
21 | void | ||
22 | sigfpe(int sig, siginfo_t *si, void *v) | ||
23 | { | ||
24 | char buf[132]; | ||
25 | |||
26 | if (si) { | ||
27 | snprintf(buf, sizeof(buf), "sigfpe: addr=%p, code=%d\n", | ||
28 | si->si_addr, si->si_code); | ||
29 | write(1, buf, strlen(buf)); | ||
30 | } | ||
31 | _exit(signal_status); | ||
32 | } | ||
33 | |||
34 | |||
35 | int | ||
36 | main(int argc, char *argv[]) | ||
37 | { | ||
38 | struct sigaction sa; | ||
39 | volatile double x; | ||
40 | |||
41 | if (argc != 2) { | ||
42 | fprintf(stderr, "usage: %s condition\n", argv[0]); | ||
43 | exit(1); | ||
44 | } | ||
45 | |||
46 | /* | ||
47 | * check to make sure that all exceptions are masked and | ||
48 | * that the accumulated exception status is clear. | ||
49 | */ | ||
50 | assert(fpgetmask() == 0); | ||
51 | assert(fpgetsticky() == 0); | ||
52 | |||
53 | memset(&sa, 0, sizeof(sa)); | ||
54 | sa.sa_sigaction = sigfpe; | ||
55 | sa.sa_flags = SA_SIGINFO; | ||
56 | sigaction(SIGFPE, &sa, NULL); | ||
57 | signal_status = 1; | ||
58 | |||
59 | if (strcmp(argv[1], "fltdiv") == 0) { | ||
60 | /* trip divide by zero */ | ||
61 | x = one / zero; | ||
62 | assert(fpgetsticky() & FP_X_DZ); | ||
63 | fpsetsticky(0); | ||
64 | |||
65 | /* and now unmask to get a signal */ | ||
66 | signal_status = 0; | ||
67 | fpsetmask(FP_X_DZ); | ||
68 | x = one / zero; | ||
69 | } else if (strcmp(argv[1], "fltinv") == 0) { | ||
70 | /* trip invalid operation */ | ||
71 | x = zero / zero; | ||
72 | assert(fpgetsticky() & FP_X_INV); | ||
73 | fpsetsticky(0); | ||
74 | |||
75 | /* and now unmask to get a signal */ | ||
76 | signal_status = 0; | ||
77 | fpsetmask(FP_X_INV); | ||
78 | x = zero / zero; | ||
79 | } else if (strcmp(argv[1], "fltovf") == 0) { | ||
80 | /* trip overflow */ | ||
81 | x = huge * huge; | ||
82 | assert(fpgetsticky() & FP_X_OFL); | ||
83 | fpsetsticky(0); | ||
84 | |||
85 | /* and now unmask to get a signal */ | ||
86 | signal_status = 0; | ||
87 | fpsetmask(FP_X_OFL); | ||
88 | x = huge * huge; | ||
89 | } else if (strcmp(argv[1], "fltund") == 0) { | ||
90 | /* trip underflow */ | ||
91 | x = tiny * tiny; | ||
92 | assert(fpgetsticky() & FP_X_UFL); | ||
93 | fpsetsticky(0); | ||
94 | |||
95 | /* and now unmask to get a signal */ | ||
96 | signal_status = 0; | ||
97 | fpsetmask(FP_X_UFL); | ||
98 | x = tiny * tiny; | ||
99 | } else { | ||
100 | errx(1, "unrecognized condition %s", argv[1]); | ||
101 | } | ||
102 | |||
103 | /* | ||
104 | * attempt to trigger the exception on machines where | ||
105 | * floating-point exceptions are deferred. | ||
106 | */ | ||
107 | x = one * one; | ||
108 | |||
109 | errx(1, "signal wasn't caught"); | ||
110 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/inf/Makefile b/src/regress/lib/libc/ieeefp/inf/Makefile deleted file mode 100644 index b9a50e0ce6..0000000000 --- a/src/regress/lib/libc/ieeefp/inf/Makefile +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2002/02/16 17:22:16 pvalchev Exp $ | ||
2 | |||
3 | PROG= inf | ||
4 | SRCS= inf.c | ||
5 | |||
6 | LDADD+= -lm | ||
7 | DPADD+= ${LIBM} | ||
8 | |||
9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/inf/inf.c b/src/regress/lib/libc/ieeefp/inf/inf.c deleted file mode 100644 index a1956145a6..0000000000 --- a/src/regress/lib/libc/ieeefp/inf/inf.c +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | /* $OpenBSD: inf.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Peter Valchev <pvalchev@openbsd.org> Public Domain, 2002. | ||
5 | */ | ||
6 | |||
7 | #include <math.h> | ||
8 | |||
9 | int | ||
10 | main(int argc, char *argv[]) | ||
11 | { | ||
12 | if (isinf(HUGE_VAL)) | ||
13 | return 0; | ||
14 | |||
15 | return 1; | ||
16 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/infinity/Makefile b/src/regress/lib/libc/ieeefp/infinity/Makefile deleted file mode 100644 index ac102d8a63..0000000000 --- a/src/regress/lib/libc/ieeefp/infinity/Makefile +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2004/01/16 19:34:37 miod Exp $ | ||
2 | |||
3 | PROG= infinity | ||
4 | |||
5 | DPADD+= ${LIBM} | ||
6 | LDADD+= -lm | ||
7 | |||
8 | REGRESS_TARGETS+= add mult neg pumpkin | ||
9 | |||
10 | add: ${PROG} | ||
11 | ./${PROG} -a | ||
12 | |||
13 | mult: ${PROG} | ||
14 | ./${PROG} -m | ||
15 | |||
16 | neg: ${PROG} | ||
17 | ./${PROG} -n | ||
18 | |||
19 | pumpkin: ${PROG} | ||
20 | ./${PROG} -p | ||
21 | |||
22 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/infinity/infinity.c b/src/regress/lib/libc/ieeefp/infinity/infinity.c deleted file mode 100644 index 3b1b71ec90..0000000000 --- a/src/regress/lib/libc/ieeefp/infinity/infinity.c +++ /dev/null | |||
@@ -1,77 +0,0 @@ | |||
1 | /* $OpenBSD: infinity.c,v 1.2 2004/01/16 19:34:37 miod Exp $ */ | ||
2 | /* | ||
3 | * Written by Miodrag Vallat, 2004 - Public Domain | ||
4 | * Inspired from Perl's t/op/arith test #134 | ||
5 | */ | ||
6 | |||
7 | #include <math.h> | ||
8 | #include <signal.h> | ||
9 | #include <unistd.h> | ||
10 | |||
11 | void | ||
12 | sigfpe(int signum) | ||
13 | { | ||
14 | /* looks like we don't handle fp overflow correctly... */ | ||
15 | _exit(1); | ||
16 | } | ||
17 | |||
18 | int | ||
19 | main(int argc, char *argv[]) | ||
20 | { | ||
21 | int opt; | ||
22 | double d, two; | ||
23 | int i; | ||
24 | char method = 'a'; | ||
25 | |||
26 | while ((opt = getopt(argc, argv, "amnp")) != -1) | ||
27 | method = (char)opt; | ||
28 | |||
29 | signal(SIGFPE, sigfpe); | ||
30 | |||
31 | switch (method) { | ||
32 | case 'a': | ||
33 | /* try to produce +Inf through addition */ | ||
34 | d = 1.0; | ||
35 | for (i = 2000; i != 0; i--) { | ||
36 | d = d + d; | ||
37 | } | ||
38 | /* result should be _positive_ infinity */ | ||
39 | if (!isinf(d) || copysign(1.0, d) < 0.0) | ||
40 | return (1); | ||
41 | break; | ||
42 | case 'm': | ||
43 | /* try to produce +Inf through multiplication */ | ||
44 | d = 1.0; | ||
45 | two = 2.0; | ||
46 | for (i = 2000; i != 0; i--) { | ||
47 | d = d * two; | ||
48 | } | ||
49 | /* result should be _positive_ infinity */ | ||
50 | if (!isinf(d) || copysign(1.0, d) < 0.0) | ||
51 | return (1); | ||
52 | break; | ||
53 | case 'n': | ||
54 | /* try to produce -Inf through subtraction */ | ||
55 | d = -1.0; | ||
56 | for (i = 2000; i != 0; i--) { | ||
57 | d = d + d; | ||
58 | } | ||
59 | /* result should be _negative_ infinity */ | ||
60 | if (!isinf(d) || copysign(1.0, d) > 0.0) | ||
61 | return (1); | ||
62 | break; | ||
63 | case 'p': | ||
64 | /* try to produce -Inf through multiplication */ | ||
65 | d = -1.0; | ||
66 | two = 2.0; | ||
67 | for (i = 2000; i != 0; i--) { | ||
68 | d = d * two; | ||
69 | } | ||
70 | /* result should be _negative_ infinity */ | ||
71 | if (!isinf(d) || copysign(1.0, d) > 0.0) | ||
72 | return (1); | ||
73 | break; | ||
74 | } | ||
75 | |||
76 | return (0); | ||
77 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/round/Makefile b/src/regress/lib/libc/ieeefp/round/Makefile deleted file mode 100644 index 9ea6dd8c39..0000000000 --- a/src/regress/lib/libc/ieeefp/round/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.4 2002/02/18 11:25:34 art Exp $ | ||
2 | |||
3 | PROG= round | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/round/round.c b/src/regress/lib/libc/ieeefp/round/round.c deleted file mode 100644 index 807941ea56..0000000000 --- a/src/regress/lib/libc/ieeefp/round/round.c +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | /* $OpenBSD: round.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $ */ | ||
2 | /* $NetBSD: round.c,v 1.1 1995/04/26 00:27:28 jtc Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Written by J.T. Conklin, Apr 18, 1995 | ||
6 | * Public domain. | ||
7 | */ | ||
8 | |||
9 | #include <assert.h> | ||
10 | #include <stdlib.h> | ||
11 | #include <ieeefp.h> | ||
12 | #include <float.h> | ||
13 | |||
14 | int | ||
15 | main(int argc, char *argv[]) | ||
16 | { | ||
17 | /* | ||
18 | * This test would be better if it actually performed some | ||
19 | * calculations to verify the selected rounding mode. But | ||
20 | * this is probably acceptable since the fp{get,set}round | ||
21 | * functions usually just get or set the processors fpu | ||
22 | * control word. | ||
23 | */ | ||
24 | |||
25 | assert(fpgetround() == FP_RN); | ||
26 | assert(FLT_ROUNDS == 1); | ||
27 | |||
28 | assert(fpsetround(FP_RP) == FP_RN); | ||
29 | assert(fpgetround() == FP_RP); | ||
30 | assert(FLT_ROUNDS == 2); | ||
31 | |||
32 | assert(fpsetround(FP_RM) == FP_RP); | ||
33 | assert(fpgetround() == FP_RM); | ||
34 | assert(FLT_ROUNDS == 3); | ||
35 | |||
36 | assert(fpsetround(FP_RZ) == FP_RM); | ||
37 | assert(fpgetround() == FP_RZ); | ||
38 | assert(FLT_ROUNDS == 0); | ||
39 | |||
40 | assert(fpsetround(FP_RN) == FP_RZ); | ||
41 | assert(fpgetround() == FP_RN); | ||
42 | assert(FLT_ROUNDS == 1); | ||
43 | |||
44 | exit(0); | ||
45 | } | ||
diff --git a/src/regress/lib/libc/ifnameindex/Makefile b/src/regress/lib/libc/ifnameindex/Makefile deleted file mode 100644 index 1f21973a10..0000000000 --- a/src/regress/lib/libc/ifnameindex/Makefile +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2015/10/22 15:47:00 claudio Exp $ | ||
2 | |||
3 | PROG= ifnitest | ||
4 | SRCS= ifnitest.c | ||
5 | NOMAN= # defined | ||
6 | |||
7 | REGRESS_TARGETS=do-test | ||
8 | |||
9 | do-test: ${PROG} | ||
10 | ./${PROG} | ||
11 | |||
12 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ifnameindex/ifnitest.c b/src/regress/lib/libc/ifnameindex/ifnitest.c deleted file mode 100644 index fb7ed3704f..0000000000 --- a/src/regress/lib/libc/ifnameindex/ifnitest.c +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | /* $OpenBSD: ifnitest.c,v 1.3 2017/02/25 07:28:32 jsg Exp $ */ | ||
2 | |||
3 | /* Public domain. 2015, Claudio Jeker */ | ||
4 | |||
5 | #include <sys/types.h> | ||
6 | #include <sys/socket.h> | ||
7 | #include <net/if.h> | ||
8 | #include <err.h> | ||
9 | #include <stdio.h> | ||
10 | #include <string.h> | ||
11 | |||
12 | int | ||
13 | main(int argc, char *argv[]) | ||
14 | { | ||
15 | char name[IF_NAMESIZE], *ifname; | ||
16 | unsigned int lo0index; | ||
17 | |||
18 | lo0index = if_nametoindex("lo0"); | ||
19 | if (lo0index == 0) | ||
20 | err(1, "if_nametoindex(lo0)"); | ||
21 | ifname = if_indextoname(lo0index, name); | ||
22 | if (ifname == NULL || strcmp("lo0", ifname) != 0) | ||
23 | err(1, "if_indextoname(%u)", lo0index); | ||
24 | |||
25 | /* test failures */ | ||
26 | if (if_nametoindex("4kingbula") != 0) | ||
27 | err(1, "if_nametoindex(4kingbula)"); | ||
28 | if (if_indextoname(65536, name) != NULL) | ||
29 | err(1, "if_indextoname(%u)", 65536); | ||
30 | |||
31 | return 0; | ||
32 | } | ||
diff --git a/src/regress/lib/libc/ldexp/Makefile b/src/regress/lib/libc/ldexp/Makefile deleted file mode 100644 index bfe79ac679..0000000000 --- a/src/regress/lib/libc/ldexp/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2017/10/15 12:15:30 visa Exp $ | ||
2 | |||
3 | PROG=ldexp_test | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ldexp/ldexp_test.c b/src/regress/lib/libc/ldexp/ldexp_test.c deleted file mode 100644 index 75031e3083..0000000000 --- a/src/regress/lib/libc/ldexp/ldexp_test.c +++ /dev/null | |||
@@ -1,75 +0,0 @@ | |||
1 | /* $OpenBSD: ldexp_test.c,v 1.1 2017/10/15 12:15:30 visa Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2017 Visa Hankala | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <assert.h> | ||
20 | #include <math.h> | ||
21 | |||
22 | int | ||
23 | main(int argc, char *argv[]) | ||
24 | { | ||
25 | double f; | ||
26 | |||
27 | /* | ||
28 | * Test that the result has the correct sign. | ||
29 | * Assumes IEEE 754 double-precision arithmetics. | ||
30 | */ | ||
31 | |||
32 | assert(ldexp(1.0, -1022) > 0.0); /* IEEE 754 minimum normal positive */ | ||
33 | assert(ldexp(1.0, -1023) > 0.0); /* subnormal positive */ | ||
34 | assert(ldexp(1.0, -1024) > 0.0); /* subnormal positive */ | ||
35 | assert(ldexp(1.0, -1074) > 0.0); /* minimum subnormal positive */ | ||
36 | assert(ldexp(1.0, -1075) >= 0.0); /* zero */ | ||
37 | assert(ldexp(ldexp(1.0, -1022), -53) >= 0.0); /* zero */ | ||
38 | |||
39 | assert(ldexp(1.0, 1023) > 0.0); /* normal positive */ | ||
40 | |||
41 | f = ldexp(1.0, 1024); /* infinite positive */ | ||
42 | assert(isinf(f)); | ||
43 | assert(!signbit(f)); | ||
44 | |||
45 | f = ldexp(ldexp(1.0, 1023), 1); /* infinite positive */ | ||
46 | assert(isinf(f)); | ||
47 | assert(!signbit(f)); | ||
48 | |||
49 | assert(ldexp(-1.0, -1022) < 0.0); /* IEEE 754 maximum normal negative */ | ||
50 | assert(ldexp(-1.0, -1023) < 0.0); /* subnormal negative */ | ||
51 | assert(ldexp(-1.0, -1024) < 0.0); /* subnormal negative */ | ||
52 | assert(ldexp(-1.0, -1074) < 0.0); /* maximum subnormal negative */ | ||
53 | assert(ldexp(-1.0, -1075) <= 0.0); /* zero */ | ||
54 | assert(ldexp(ldexp(-1.0, -1022), -53) <= 0.0); /* zero */ | ||
55 | |||
56 | assert(ldexp(-1.0, 1023) < 0.0); /* normal negative */ | ||
57 | |||
58 | f = ldexp(-1.0, 1024); /* infinite negative */ | ||
59 | assert(isinf(f)); | ||
60 | assert(signbit(f)); | ||
61 | |||
62 | f = ldexp(ldexp(-1.0, 1023), 1); /* infinite negative */ | ||
63 | assert(isinf(f)); | ||
64 | assert(signbit(f)); | ||
65 | |||
66 | f = ldexp(NAN, 0); | ||
67 | assert(isnan(f)); | ||
68 | assert(!signbit(f)); | ||
69 | |||
70 | f = ldexp(-NAN, 0); | ||
71 | assert(isnan(f)); | ||
72 | assert(signbit(f)); | ||
73 | |||
74 | return 0; | ||
75 | } | ||
diff --git a/src/regress/lib/libc/locale/Makefile b/src/regress/lib/libc/locale/Makefile deleted file mode 100644 index 550f176d4c..0000000000 --- a/src/regress/lib/libc/locale/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.7 2020/01/13 15:35:57 bluhm Exp $ | ||
2 | |||
3 | SUBDIR = check_isw mbrtowc setlocale uselocale wcrtomb | ||
4 | |||
5 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/locale/check_isw/Makefile b/src/regress/lib/libc/locale/check_isw/Makefile deleted file mode 100644 index cd79d6cb7f..0000000000 --- a/src/regress/lib/libc/locale/check_isw/Makefile +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ | ||
2 | |||
3 | PROG = check_isw | ||
4 | |||
5 | run-regress-${PROG}: ${PROG} | ||
6 | ./${PROG} >/dev/null | ||
7 | |||
8 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/locale/check_isw/check_isw.c b/src/regress/lib/libc/locale/check_isw/check_isw.c deleted file mode 100644 index 718f387883..0000000000 --- a/src/regress/lib/libc/locale/check_isw/check_isw.c +++ /dev/null | |||
@@ -1,147 +0,0 @@ | |||
1 | /* $OpenBSD: check_isw.c,v 1.2 2017/07/27 15:08:37 bluhm Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2005 Marc Espie <espie@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | /* This checks consistency of the isw* functions with the default <ctype> | ||
19 | * functions. | ||
20 | */ | ||
21 | |||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <ctype.h> | ||
25 | #include <wchar.h> | ||
26 | #include <wctype.h> | ||
27 | |||
28 | int bad = 0; | ||
29 | |||
30 | void | ||
31 | check_bool(int v1, int v2, char msg) | ||
32 | { | ||
33 | if (!v1 != !v2) { | ||
34 | printf("%c", msg); | ||
35 | bad++; | ||
36 | } | ||
37 | } | ||
38 | |||
39 | void | ||
40 | check_value(int v1, int v2, char msg) | ||
41 | { | ||
42 | if (v1 != v2) { | ||
43 | printf("%c", msg); | ||
44 | bad++; | ||
45 | } | ||
46 | } | ||
47 | |||
48 | void | ||
49 | test1() | ||
50 | { | ||
51 | int i; | ||
52 | |||
53 | for (i = 0; i < 256; i++) { | ||
54 | printf(" %02x: ", i); | ||
55 | check_bool(isalnum(i), iswalnum(i), '1'); | ||
56 | check_bool(isalpha(i), iswalpha(i), '2'); | ||
57 | check_bool(isblank(i), iswblank(i), '3'); | ||
58 | check_bool(iscntrl(i), iswcntrl(i), '4'); | ||
59 | check_bool(isdigit(i), iswdigit(i), '5'); | ||
60 | check_bool(isgraph(i), iswgraph(i), '6'); | ||
61 | check_bool(islower(i), iswlower(i), '6'); | ||
62 | check_bool(isprint(i), iswprint(i), '7'); | ||
63 | check_bool(ispunct(i), iswpunct(i), '8'); | ||
64 | check_bool(isspace(i), iswspace(i), '9'); | ||
65 | check_bool(isupper(i), iswupper(i), 'a'); | ||
66 | check_bool(isxdigit(i), iswxdigit(i), 'b'); | ||
67 | check_value(tolower(i), towlower(i), 'c'); | ||
68 | check_value(toupper(i), towupper(i), 'd'); | ||
69 | if (i % 8 == 7) | ||
70 | printf("\n"); | ||
71 | } | ||
72 | printf("\n"); | ||
73 | } | ||
74 | |||
75 | void | ||
76 | test2() | ||
77 | { | ||
78 | unsigned char *s; | ||
79 | unsigned char *buf; | ||
80 | int i, j; | ||
81 | size_t n; | ||
82 | wchar_t c, d; | ||
83 | mbstate_t state; | ||
84 | |||
85 | s = malloc(256); | ||
86 | if (!s) { | ||
87 | bad++; | ||
88 | return; | ||
89 | } | ||
90 | buf = malloc(MB_CUR_MAX); | ||
91 | if (!buf) { | ||
92 | bad++; | ||
93 | free(s); | ||
94 | return; | ||
95 | } | ||
96 | for (i = 0; i < 256; i++) | ||
97 | s[i] = i+1; | ||
98 | |||
99 | j = 0; | ||
100 | mbrtowc(NULL, NULL, 1, &state); | ||
101 | printf(" %02x: ", 0); | ||
102 | |||
103 | while ((n = mbrtowc(&c, s+j, 256-j, &state)) == 1) { | ||
104 | printf(" %02x: ", s[j]); | ||
105 | check_bool(isalnum(s[j]), iswalnum(c), '1'); | ||
106 | check_bool(isalpha(s[j]), iswalpha(c), '2'); | ||
107 | check_bool(isblank(s[j]), iswblank(c), '3'); | ||
108 | check_bool(iscntrl(s[j]), iswcntrl(c), '4'); | ||
109 | check_bool(isdigit(s[j]), iswdigit(c), '5'); | ||
110 | check_bool(isgraph(s[j]), iswgraph(c), '6'); | ||
111 | check_bool(islower(s[j]), iswlower(c), '6'); | ||
112 | check_bool(isprint(s[j]), iswprint(c), '7'); | ||
113 | check_bool(ispunct(s[j]), iswpunct(c), '8'); | ||
114 | check_bool(isspace(s[j]), iswspace(c), '9'); | ||
115 | check_bool(isupper(s[j]), iswupper(c), 'a'); | ||
116 | check_bool(isxdigit(s[j]), iswxdigit(c), 'b'); | ||
117 | d = towlower(c); | ||
118 | if (wctomb(buf, d) == 1) { | ||
119 | check_value(tolower(s[j]), buf[0], 'c'); | ||
120 | } else { | ||
121 | bad++; | ||
122 | } | ||
123 | d = towupper(c); | ||
124 | if (wctomb(buf, d) == 1) { | ||
125 | check_value(toupper(s[j]), buf[0], 'c'); | ||
126 | } else { | ||
127 | bad++; | ||
128 | } | ||
129 | if (s[j] % 8 == 7) | ||
130 | printf("\n"); | ||
131 | j++; | ||
132 | } | ||
133 | if (n != 0 || j != 255) { | ||
134 | bad++; | ||
135 | } | ||
136 | free(s); | ||
137 | free(buf); | ||
138 | } | ||
139 | |||
140 | |||
141 | int | ||
142 | main() | ||
143 | { | ||
144 | test1(); | ||
145 | test2(); | ||
146 | return bad !=0; | ||
147 | } | ||
diff --git a/src/regress/lib/libc/locale/mbrtowc/Makefile b/src/regress/lib/libc/locale/mbrtowc/Makefile deleted file mode 100644 index 5436383911..0000000000 --- a/src/regress/lib/libc/locale/mbrtowc/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ | ||
2 | |||
3 | PROG = test_mbrtowc | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/locale/mbrtowc/test_mbrtowc.c b/src/regress/lib/libc/locale/mbrtowc/test_mbrtowc.c deleted file mode 100644 index 7455f68439..0000000000 --- a/src/regress/lib/libc/locale/mbrtowc/test_mbrtowc.c +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | /* $OpenBSD: test_mbrtowc.c,v 1.3 2020/03/09 09:29:10 dlg Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <sys/types.h> | ||
19 | #include <err.h> | ||
20 | #include <errno.h> | ||
21 | #include <locale.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | #include <wchar.h> | ||
25 | |||
26 | static mbstate_t mbs; | ||
27 | |||
28 | void | ||
29 | onetest(const char *name, const char *in, size_t insz, | ||
30 | int outerr, size_t outsz, wint_t out) | ||
31 | { | ||
32 | wchar_t wc; | ||
33 | size_t sz; | ||
34 | |||
35 | sz = mbrtowc(&wc, in, insz, &mbs); | ||
36 | if (errno != outerr) | ||
37 | err(1, "%zu %s(%zd)", MB_CUR_MAX, name, insz); | ||
38 | if (sz != outsz || (out != WEOF && wc != out)) | ||
39 | errx(1, "%zu %s(%zd) = (%zd, %d) != (%zd, %d)", | ||
40 | MB_CUR_MAX, name, insz, sz, wc, outsz, out); | ||
41 | if (mbsinit(&mbs) == (insz && outsz == (size_t)-2)) | ||
42 | errx(1, "%zu %s(%zd) mbsinit", MB_CUR_MAX, name, insz); | ||
43 | if (errno == 0 && outerr == 0) | ||
44 | return; | ||
45 | errno = 0; | ||
46 | memset(&mbs, 0, sizeof(mbs)); | ||
47 | } | ||
48 | |||
49 | int | ||
50 | main(void) | ||
51 | { | ||
52 | onetest("NUL", "", 0, 0, -2, WEOF); | ||
53 | onetest("NUL", "", 2, 0, 0, L'\0'); | ||
54 | onetest("BEL", "\a", 2, 0, 1, L'\a'); | ||
55 | onetest("A", "A", 2, 0, 1, L'A'); | ||
56 | onetest("DEL", "\177", 2, 0, 1, L'\177'); | ||
57 | onetest("CSI", "\233", 2, 0, 1, L'\233'); | ||
58 | |||
59 | if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) | ||
60 | errx(1, "setlocale(UTF-8) failed"); | ||
61 | |||
62 | onetest("NUL", "", 0, 0, -2, WEOF); | ||
63 | onetest("NUL", "", 8, 0, 0, L'\0'); | ||
64 | onetest("BEL", "\a", 8, 0, 1, L'\a'); | ||
65 | onetest("A", "A", 8, 0, 1, L'A'); | ||
66 | onetest("DEL", "\177", 8, 0, 1, L'\177'); | ||
67 | onetest("0x80", "\200", 8, EILSEQ, -1, WEOF); | ||
68 | onetest("0xc3", "\303", 1, 0, -2, WEOF); | ||
69 | onetest("U+00E9", "\251", 8, 0, 1, 0xe9); | ||
70 | onetest("0xec", "\354", 1, 0, -2, WEOF); | ||
71 | onetest("0xecbf", "\277", 1, 0, -2, WEOF); | ||
72 | onetest("U+CFFF", "\277", 8, 0, 1, 0xcfff); | ||
73 | |||
74 | if (setlocale(LC_CTYPE, "POSIX") == NULL) | ||
75 | errx(1, "setlocale(POSIX) failed"); | ||
76 | |||
77 | onetest("0xff", "\277", 2, 0, 1, L'\277'); | ||
78 | |||
79 | if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) | ||
80 | errx(1, "second setlocale(UTF-8) failed"); | ||
81 | |||
82 | onetest("U+13000", "\360\223\200\200", 8, 0, 4, 0x13000); | ||
83 | |||
84 | return 0; | ||
85 | } | ||
diff --git a/src/regress/lib/libc/locale/setlocale/Makefile b/src/regress/lib/libc/locale/setlocale/Makefile deleted file mode 100644 index 966f7926e5..0000000000 --- a/src/regress/lib/libc/locale/setlocale/Makefile +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ | ||
2 | |||
3 | PROG = setlocale | ||
4 | |||
5 | run-regress-${PROG}: ${PROG} | ||
6 | env -i LC_ALL=fr_FR.UTF-8 ./${PROG} | ||
7 | |||
8 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/locale/setlocale/setlocale.c b/src/regress/lib/libc/locale/setlocale/setlocale.c deleted file mode 100644 index 82245df5c5..0000000000 --- a/src/regress/lib/libc/locale/setlocale/setlocale.c +++ /dev/null | |||
@@ -1,125 +0,0 @@ | |||
1 | /* $OpenBSD: setlocale.c,v 1.4 2018/03/29 16:34:25 schwarze Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2015 Sebastien Marie <semarie@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <err.h> | ||
19 | #include <locale.h> | ||
20 | #include <stdlib.h> | ||
21 | #include <stdio.h> | ||
22 | #include <string.h> | ||
23 | #include <ctype.h> | ||
24 | |||
25 | /* | ||
26 | * test helpers for __LINE__ | ||
27 | */ | ||
28 | #define test_setlocale(_e, _c, _l) _test_setlocale(_e, _c, _l, __LINE__) | ||
29 | #define test_MB_CUR_MAX(_e) _test_MB_CUR_MAX(_e, __LINE__) | ||
30 | #define test_isalpha(_e, _c) _test_isalpha(_e, _c, __LINE__) | ||
31 | |||
32 | |||
33 | static void | ||
34 | _test_setlocale(char *expected, int category, char *locale, int line) | ||
35 | { | ||
36 | char *result = setlocale(category, locale); | ||
37 | |||
38 | if ((expected == NULL) || (result == NULL)) { | ||
39 | if (expected == result) | ||
40 | return; | ||
41 | |||
42 | errx(1, "[%d] setlocale(%d, \"%s\")=\"%s\" [expected: \"%s\"]", | ||
43 | line, category, locale, result, expected); | ||
44 | } | ||
45 | |||
46 | if (strcmp(expected, result) != 0) | ||
47 | errx(1, "[%d] setlocale(%d, \"%s\")=\"%s\" [expected: \"%s\"]", | ||
48 | line, category, locale, result, expected); | ||
49 | } | ||
50 | |||
51 | static void | ||
52 | _test_MB_CUR_MAX(size_t expected, int line) | ||
53 | { | ||
54 | if (MB_CUR_MAX != expected) | ||
55 | errx(1, "[%d] MB_CUR_MAX=%ld [expected %ld]", | ||
56 | line, MB_CUR_MAX, expected); | ||
57 | } | ||
58 | |||
59 | static void | ||
60 | _test_isalpha(int expected, int c, int line) | ||
61 | { | ||
62 | int result = isalpha(c); | ||
63 | if (!!result != expected) | ||
64 | errx(1, "[%d] isalpha(%d)=%d [expected %d]", | ||
65 | line, c, result, expected); | ||
66 | } | ||
67 | |||
68 | int | ||
69 | main(int argc, char *argv[]) | ||
70 | { | ||
71 | /* check initial state (should be "C") */ | ||
72 | test_setlocale("C", LC_ALL, NULL); /* check */ | ||
73 | test_MB_CUR_MAX(1); | ||
74 | test_isalpha(0, 0xe9); /* iso-8859-1 eacute */ | ||
75 | |||
76 | /* load from env */ | ||
77 | /* NOTE: we don't support non-C locales for some categories */ | ||
78 | test_setlocale("fr_FR.UTF-8", LC_CTYPE, ""); /* set */ | ||
79 | test_setlocale("fr_FR.UTF-8", LC_MESSAGES, ""); /* set */ | ||
80 | test_MB_CUR_MAX(4); | ||
81 | test_isalpha(0, 0xe9); /* iso-8859-1 eacute */ | ||
82 | |||
83 | test_setlocale("C", LC_MESSAGES, "C"); /* set */ | ||
84 | test_MB_CUR_MAX(4); | ||
85 | test_setlocale("C/fr_FR.UTF-8/C/C/C/C", LC_ALL, NULL); /* check */ | ||
86 | |||
87 | test_setlocale("C", LC_CTYPE, "C"); /* set */ | ||
88 | test_MB_CUR_MAX(1); | ||
89 | test_setlocale("C", LC_ALL, NULL); /* check */ | ||
90 | |||
91 | /* check for errors on checking */ | ||
92 | test_setlocale("C", LC_ALL, "C"); /* reset */ | ||
93 | test_setlocale(NULL, -1, NULL); | ||
94 | test_setlocale(NULL, _LC_LAST, NULL); | ||
95 | test_setlocale(NULL, _LC_LAST+0xff, NULL); | ||
96 | test_setlocale("C", LC_ALL, NULL); /* check */ | ||
97 | |||
98 | /* check for errors on setting */ | ||
99 | test_setlocale(NULL, -1, ""); | ||
100 | test_setlocale(NULL, _LC_LAST, ""); | ||
101 | test_setlocale(NULL, _LC_LAST+0xff, ""); | ||
102 | test_setlocale("C", LC_ALL, NULL); /* check */ | ||
103 | |||
104 | /* no codeset, fallback to ASCII */ | ||
105 | test_setlocale("C", LC_ALL, "C"); /* reset */ | ||
106 | test_setlocale("invalid", LC_CTYPE, "invalid"); /* set */ | ||
107 | test_setlocale("invalid", LC_CTYPE, NULL); | ||
108 | test_MB_CUR_MAX(1); | ||
109 | test_isalpha(0, 0xe9); /* iso-8859-1 eacute */ | ||
110 | |||
111 | /* with codeset */ | ||
112 | test_setlocale("C", LC_ALL, "C"); /* reset */ | ||
113 | test_setlocale("invalid.UTF-8", LC_CTYPE, "invalid.UTF-8"); /* set */ | ||
114 | test_setlocale("invalid.UTF-8", LC_CTYPE, NULL); | ||
115 | test_setlocale("C/invalid.UTF-8/C/C/C/C", LC_ALL, NULL); | ||
116 | test_MB_CUR_MAX(4); | ||
117 | |||
118 | /* with invalid codeset (is an error) */ | ||
119 | test_setlocale("C", LC_ALL, "C"); /* reset */ | ||
120 | test_setlocale(NULL, LC_CTYPE, "fr_FR.invalid"); /* set */ | ||
121 | test_setlocale("C", LC_CTYPE, NULL); | ||
122 | test_MB_CUR_MAX(1); | ||
123 | |||
124 | return (EXIT_SUCCESS); | ||
125 | } | ||
diff --git a/src/regress/lib/libc/locale/uselocale/Makefile b/src/regress/lib/libc/locale/uselocale/Makefile deleted file mode 100644 index a10471bcf6..0000000000 --- a/src/regress/lib/libc/locale/uselocale/Makefile +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2017/08/16 01:40:30 schwarze Exp $ | ||
2 | |||
3 | PROG = uselocale | ||
4 | CFLAGS += -Wno-macro-redefined -Wno-int-to-pointer-cast | ||
5 | LDFLAGS += -pthread | ||
6 | |||
7 | run-regress-${PROG}: ${PROG} | ||
8 | ./${PROG} | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/locale/uselocale/uselocale.c b/src/regress/lib/libc/locale/uselocale/uselocale.c deleted file mode 100644 index 4759eff46c..0000000000 --- a/src/regress/lib/libc/locale/uselocale/uselocale.c +++ /dev/null | |||
@@ -1,481 +0,0 @@ | |||
1 | /* $OpenBSD: uselocale.c,v 1.9 2024/02/05 06:48:04 anton Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2017, 2022 Ingo Schwarze <schwarze@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <ctype.h> | ||
19 | #include <err.h> | ||
20 | #include <errno.h> | ||
21 | #include <langinfo.h> | ||
22 | #include <locale.h> | ||
23 | #include <pthread.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <string.h> | ||
26 | #include <wchar.h> | ||
27 | #include <wctype.h> | ||
28 | |||
29 | /* Keep in sync with /usr/src/lib/libc/locale/rune.h. */ | ||
30 | #define _LOCALE_NONE (locale_t)0 | ||
31 | #define _LOCALE_C (locale_t)1 | ||
32 | #define _LOCALE_UTF8 (locale_t)2 | ||
33 | #define _LOCALE_BAD (locale_t)3 | ||
34 | |||
35 | /* Options for switch_thread() below. */ | ||
36 | #define SWITCH_SIGNAL 1 /* Call pthread_cond_signal(3). */ | ||
37 | #define SWITCH_WAIT 2 /* Call pthread_cond_timedwait(3). */ | ||
38 | |||
39 | /* Options for TESTFUNC(). */ | ||
40 | #define TOPT_ERR (1 << 0) | ||
41 | |||
42 | /* | ||
43 | * Generate one test function for a specific interface. | ||
44 | * Fn = function name | ||
45 | * Ft = function return type | ||
46 | * FUNCPARA = function parameter list with types and names | ||
47 | * FUNCARGS = function argument list, names only, no types | ||
48 | * Af = format string to print the arguments | ||
49 | * Rf = format string to print the return value | ||
50 | * Op = options for the test function, see above | ||
51 | * line = source code line number in this test file | ||
52 | * ee = expected error number | ||
53 | * er = expected return value | ||
54 | * ar = actual return value | ||
55 | * errno = actual error number (global) | ||
56 | */ | ||
57 | #define TESTFUNC(Fn, Ft, Af, Rf, Op) \ | ||
58 | static void \ | ||
59 | _test_##Fn(int line, int ee, Ft er, FUNCPARA) \ | ||
60 | { \ | ||
61 | Ft ar; \ | ||
62 | errno = 0; \ | ||
63 | ar = Fn(FUNCARGS); \ | ||
64 | if (ar != er) \ | ||
65 | errx(1, "[%d] %s(" Af ")=" Rf " [exp: " Rf "]", \ | ||
66 | line, #Fn, FUNCARGS, ar, er); \ | ||
67 | if (Op & TOPT_ERR && errno != ee) \ | ||
68 | errx(1, "[%d] %s(" Af ") errno=%d [exp: %d]", \ | ||
69 | line, #Fn, FUNCARGS, errno, ee); \ | ||
70 | } | ||
71 | |||
72 | #define STRTESTFUNC(Fn, Af) \ | ||
73 | static void \ | ||
74 | _test_##Fn(int line, int ee, const char *er, FUNCPARA) \ | ||
75 | { \ | ||
76 | const char *ar; \ | ||
77 | errno = 0; \ | ||
78 | ar = Fn(FUNCARGS); \ | ||
79 | if (er == NULL) \ | ||
80 | er = "NULL"; \ | ||
81 | if (ar == NULL) \ | ||
82 | ar = "NULL"; \ | ||
83 | if (strcmp((const char *)er, (const char *)ar) != 0) \ | ||
84 | errx(1, "[%d] %s(" Af ")=%s [exp: %s]", \ | ||
85 | line, #Fn, FUNCARGS, ar, er); \ | ||
86 | } | ||
87 | |||
88 | /* | ||
89 | * Test functions for all tested interfaces. | ||
90 | */ | ||
91 | #define FUNCPARA int mask, const char *locname | ||
92 | #define FUNCARGS mask, locname, _LOCALE_NONE | ||
93 | TESTFUNC(newlocale, locale_t, "%d, %s, %p", "%p", TOPT_ERR) | ||
94 | |||
95 | #define FUNCPARA locale_t locale | ||
96 | #define FUNCARGS locale | ||
97 | TESTFUNC(duplocale, locale_t, "%p", "%p", TOPT_ERR) | ||
98 | TESTFUNC(uselocale, locale_t, "%p", "%p", TOPT_ERR) | ||
99 | |||
100 | #define FUNCPARA int category, char *locname | ||
101 | #define FUNCARGS category, locname | ||
102 | STRTESTFUNC(setlocale, "%d, %s") | ||
103 | |||
104 | #define FUNCPARA nl_item item | ||
105 | #define FUNCARGS item | ||
106 | STRTESTFUNC(nl_langinfo, "%ld") | ||
107 | |||
108 | #define FUNCPARA nl_item item, locale_t locale | ||
109 | #define FUNCARGS item, locale | ||
110 | STRTESTFUNC(nl_langinfo_l, "%ld, %p") | ||
111 | |||
112 | #define FUNCPARA int c | ||
113 | #define FUNCARGS c | ||
114 | TESTFUNC(isalpha, int, "0x%.2x", "%d", 0) | ||
115 | TESTFUNC(tolower, int, "0x%.2x", "0x%.2x", 0) | ||
116 | |||
117 | #define FUNCPARA int c, locale_t locale | ||
118 | #define FUNCARGS c, locale | ||
119 | TESTFUNC(isalpha_l, int, "0x%.2x, %p", "%d", 0) | ||
120 | TESTFUNC(tolower_l, int, "0x%.2x, %p", "0x%.2x", 0) | ||
121 | |||
122 | #define FUNCPARA wint_t wc | ||
123 | #define FUNCARGS wc | ||
124 | TESTFUNC(iswalpha, int, "U+%.4X", "%d", 0) | ||
125 | TESTFUNC(towupper, wint_t, "U+%.4X", "U+%.4X", 0) | ||
126 | |||
127 | #define FUNCPARA wint_t wc, locale_t locale | ||
128 | #define FUNCARGS wc, locale | ||
129 | TESTFUNC(iswalpha_l, int, "U+%.4X, %p", "%d", 0) | ||
130 | TESTFUNC(towupper_l, wint_t, "U+%.4X, %p", "U+%.4X", 0) | ||
131 | |||
132 | #define FUNCPARA wint_t wc, wctype_t charclass | ||
133 | #define FUNCARGS wc, charclass | ||
134 | TESTFUNC(iswctype, int, "U+%.4X, %p", "%d", 0) | ||
135 | |||
136 | #define FUNCPARA wint_t wc, wctype_t charclass, locale_t locale | ||
137 | #define FUNCARGS wc, charclass, locale | ||
138 | TESTFUNC(iswctype_l, int, "U+%.4X, %p, %p", "%d", 0) | ||
139 | |||
140 | #define FUNCPARA wint_t wc, wctrans_t charmap | ||
141 | #define FUNCARGS wc, charmap | ||
142 | TESTFUNC(towctrans, wint_t, "U+%.4X, %p", "U+%.4X", 0) | ||
143 | |||
144 | #define FUNCPARA wint_t wc, wctrans_t charmap, locale_t locale | ||
145 | #define FUNCARGS wc, charmap, locale | ||
146 | TESTFUNC(towctrans_l, wint_t, "U+%.4X, %p, %p", "U+%.4X", 0) | ||
147 | |||
148 | #define FUNCPARA const wchar_t *s1, const wchar_t *s2 | ||
149 | #define FUNCARGS s1, s2 | ||
150 | TESTFUNC(wcscasecmp, int, "%ls, %ls", "%d", 0) | ||
151 | |||
152 | #define FUNCPARA const wchar_t *s1, const wchar_t *s2, locale_t locale | ||
153 | #define FUNCARGS s1, s2, locale | ||
154 | TESTFUNC(wcscasecmp_l, int, "%ls, %ls, %p", "%d", 0) | ||
155 | |||
156 | #define FUNCPARA const wchar_t *s1, const wchar_t *s2, size_t len | ||
157 | #define FUNCARGS s1, s2, len | ||
158 | TESTFUNC(wcsncasecmp, int, "%ls, %ls, %zu", "%d", 0) | ||
159 | |||
160 | #define FUNCPARA const wchar_t *s1, const wchar_t *s2, size_t len, \ | ||
161 | locale_t locale | ||
162 | #define FUNCARGS s1, s2, len, locale | ||
163 | TESTFUNC(wcsncasecmp_l, int, "%ls, %ls, %zu, %p", "%d", 0) | ||
164 | |||
165 | static void | ||
166 | _test_MB_CUR_MAX(int line, int ee, size_t ar) | ||
167 | { | ||
168 | if (MB_CUR_MAX != ar) | ||
169 | errx(1, "[%d] MB_CUR_MAX=%zd [exp: %zd]", | ||
170 | line, MB_CUR_MAX, ar); | ||
171 | } | ||
172 | |||
173 | /* | ||
174 | * Test macros: | ||
175 | * TEST_R(funcname, er, arguments) if you expect errno == 0. | ||
176 | * TEST_ER(funcname, ee, er, arguments) otherwise. | ||
177 | */ | ||
178 | #define TEST_R(Fn, ...) _test_##Fn(__LINE__, 0, __VA_ARGS__) | ||
179 | #define TEST_ER(Fn, ...) _test_##Fn(__LINE__, __VA_ARGS__) | ||
180 | |||
181 | static pthread_mutex_t mtx; | ||
182 | static pthread_mutexattr_t mtxattr; | ||
183 | static pthread_cond_t cond; | ||
184 | |||
185 | /* | ||
186 | * SWITCH_SIGNAL wakes the other thread. | ||
187 | * SWITCH_WAIT goes to sleep. | ||
188 | * Both can be combined. | ||
189 | * The step argument is used for error reporting only. | ||
190 | */ | ||
191 | static void | ||
192 | switch_thread(int step, int flags) | ||
193 | { | ||
194 | struct timespec t; | ||
195 | int irc; | ||
196 | |||
197 | if (flags & SWITCH_SIGNAL) { | ||
198 | if ((irc = pthread_cond_signal(&cond)) != 0) | ||
199 | errc(1, irc, "pthread_cond_signal(%d)", step); | ||
200 | } | ||
201 | if (flags & SWITCH_WAIT) { | ||
202 | if ((irc = pthread_mutex_trylock(&mtx)) != 0) | ||
203 | errc(1, irc, "pthread_mutex_trylock(%d)", step); | ||
204 | t.tv_sec = time(NULL) + 2; | ||
205 | t.tv_nsec = 0; | ||
206 | if ((irc = pthread_cond_timedwait(&cond, &mtx, &t)) != 0) | ||
207 | errc(1, irc, "pthread_cond_timedwait(%d)", step); | ||
208 | if ((irc = pthread_mutex_unlock(&mtx)) != 0) | ||
209 | errc(1, irc, "pthread_mutex_unlock(%d)", step); | ||
210 | } | ||
211 | } | ||
212 | |||
213 | static void * | ||
214 | child_func(void *arg) | ||
215 | { | ||
216 | const wchar_t s1[] = { 0x00C7, 0x00E0, 0x0000 }; | ||
217 | const wchar_t s2[] = { 0x00E7, 0x00C0, 0x0000 }; | ||
218 | const wchar_t s3[] = { 0x00C9, 0x0074, 0x00C9, 0x0000 }; | ||
219 | const wchar_t s4[] = { 0x00E9, 0x0054, 0x00CC, 0x0000 }; | ||
220 | wctype_t wctyg, wctyu, wctyc; | ||
221 | wctrans_t wctrg, wctru, wctrc; | ||
222 | char *sego, *segc, *selo, *selc; | ||
223 | |||
224 | /* Test invalid newlocale(3) arguments. */ | ||
225 | TEST_ER(newlocale, EINVAL, _LOCALE_NONE, LC_CTYPE_MASK, NULL); | ||
226 | TEST_R(MB_CUR_MAX, 1); | ||
227 | TEST_ER(newlocale, EINVAL, _LOCALE_NONE, LC_ALL_MASK + 1, "C.UTF-8"); | ||
228 | TEST_R(MB_CUR_MAX, 1); | ||
229 | TEST_ER(newlocale, ENOENT, _LOCALE_NONE, LC_COLLATE_MASK, "C.INV"); | ||
230 | TEST_R(MB_CUR_MAX, 1); | ||
231 | setenv("LC_TIME", "C.INV", 1); | ||
232 | TEST_ER(newlocale, ENOENT, _LOCALE_NONE, LC_TIME_MASK, ""); | ||
233 | unsetenv("LC_TIME"); | ||
234 | TEST_R(MB_CUR_MAX, 1); | ||
235 | setenv("LC_CTYPE", "C.INV", 1); | ||
236 | TEST_ER(newlocale, ENOENT, _LOCALE_NONE, LC_CTYPE_MASK, ""); | ||
237 | TEST_R(MB_CUR_MAX, 1); | ||
238 | |||
239 | /* Test duplocale(3). */ | ||
240 | TEST_ER(duplocale, EINVAL, _LOCALE_NONE, _LOCALE_UTF8); | ||
241 | TEST_R(duplocale, _LOCALE_C, _LOCALE_C); | ||
242 | TEST_R(duplocale, _LOCALE_C, LC_GLOBAL_LOCALE); | ||
243 | |||
244 | /* Test premature UTF-8 uselocale(3). */ | ||
245 | TEST_ER(uselocale, EINVAL, _LOCALE_NONE, _LOCALE_UTF8); | ||
246 | TEST_R(MB_CUR_MAX, 1); | ||
247 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); | ||
248 | |||
249 | /* Test UTF-8 initialization. */ | ||
250 | setenv("LC_CTYPE", "C.UTF-8", 1); | ||
251 | TEST_R(newlocale, _LOCALE_UTF8, LC_CTYPE_MASK, ""); | ||
252 | unsetenv("LC_CTYPE"); | ||
253 | TEST_R(MB_CUR_MAX, 1); | ||
254 | TEST_R(duplocale, _LOCALE_UTF8, _LOCALE_UTF8); | ||
255 | |||
256 | /* Test invalid uselocale(3) argument. */ | ||
257 | TEST_ER(uselocale, EINVAL, _LOCALE_NONE, _LOCALE_BAD); | ||
258 | TEST_R(MB_CUR_MAX, 1); | ||
259 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); | ||
260 | TEST_R(nl_langinfo, "US-ASCII", CODESET); | ||
261 | TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); | ||
262 | TEST_R(iswalpha, 0, 0x00E9); | ||
263 | TEST_R(iswalpha_l, 1, 0x00E9, _LOCALE_UTF8); | ||
264 | TEST_R(towupper, 0x00E9, 0x00E9); | ||
265 | TEST_R(towupper_l, 0x00C9, 0x00E9, _LOCALE_UTF8); | ||
266 | TEST_R(wcscasecmp, *s1 - *s2, s1, s2); | ||
267 | TEST_R(wcscasecmp_l, 0, s1, s2, _LOCALE_UTF8); | ||
268 | |||
269 | /* Test switching the thread locale. */ | ||
270 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_UTF8); | ||
271 | TEST_R(MB_CUR_MAX, 4); | ||
272 | TEST_R(uselocale, _LOCALE_UTF8, _LOCALE_NONE); | ||
273 | TEST_R(nl_langinfo, "UTF-8", CODESET); | ||
274 | TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); | ||
275 | TEST_R(nl_langinfo_l, "US-ASCII", CODESET, _LOCALE_C); | ||
276 | TEST_R(isalpha, _CTYPE_L, 0x65); /* e */ | ||
277 | TEST_R(isalpha_l, _CTYPE_L, 0x65, _LOCALE_UTF8); | ||
278 | TEST_R(isalpha_l, _CTYPE_L, 0x65, _LOCALE_C); | ||
279 | TEST_R(isalpha_l, _CTYPE_L, 0x65, _LOCALE_C); | ||
280 | TEST_R(isalpha, 0, 0x30); /* 0 */ | ||
281 | TEST_R(isalpha_l, 0, 0x30, _LOCALE_UTF8); | ||
282 | TEST_R(isalpha_l, 0, 0x30, _LOCALE_C); | ||
283 | TEST_R(tolower, 0x61, 0x41); /* A */ | ||
284 | TEST_R(tolower_l, 0x61, 0x41, _LOCALE_UTF8); | ||
285 | TEST_R(tolower_l, 0x61, 0x41, _LOCALE_C); | ||
286 | TEST_R(tolower, 0x40, 0x40); /* @ */ | ||
287 | TEST_R(tolower_l, 0x40, 0x40, _LOCALE_UTF8); | ||
288 | TEST_R(tolower_l, 0x40, 0x40, _LOCALE_C); | ||
289 | TEST_R(iswalpha, 1, 0x00E9); /* e accent aigu */ | ||
290 | TEST_R(iswalpha_l, 1, 0x00E9, _LOCALE_UTF8); | ||
291 | TEST_R(iswalpha_l, 0, 0x00E9, _LOCALE_C); | ||
292 | TEST_R(iswalpha, 1, 0x0153); /* ligature oe */ | ||
293 | TEST_R(iswalpha_l, 1, 0x0153, _LOCALE_UTF8); | ||
294 | TEST_R(iswalpha_l, 0, 0x0153, _LOCALE_C); | ||
295 | TEST_R(iswalpha, 0, 0x2200); /* for all */ | ||
296 | TEST_R(iswalpha_l, 0, 0x2200, _LOCALE_UTF8); | ||
297 | TEST_R(iswalpha_l, 0, 0x2200, _LOCALE_C); | ||
298 | TEST_R(towupper, 0x00C9, 0x00E9); | ||
299 | TEST_R(towupper_l, 0x00C9, 0x00E9, _LOCALE_UTF8); | ||
300 | TEST_R(towupper_l, 0x00E9, 0x00E9, _LOCALE_C); | ||
301 | TEST_R(towupper, 0x0152, 0x0153); | ||
302 | TEST_R(towupper_l, 0x0152, 0x0153, _LOCALE_UTF8); | ||
303 | TEST_R(towupper_l, 0x0153, 0x0153, _LOCALE_C); | ||
304 | TEST_R(towupper, 0x2205, 0x2205); | ||
305 | TEST_R(towupper_l, 0x2205, 0x2205, _LOCALE_UTF8); | ||
306 | TEST_R(towupper_l, 0x2205, 0x2205, _LOCALE_C); | ||
307 | wctyg = wctype("upper"); | ||
308 | if (wctyg == NULL) | ||
309 | errx(1, "wctype(upper) == NULL"); | ||
310 | wctyu = wctype_l("upper", _LOCALE_UTF8); | ||
311 | if (wctyu == NULL) | ||
312 | errx(1, "wctype_l(upper, UTF-8) == NULL"); | ||
313 | if (wctyg != wctyu) | ||
314 | errx(1, "wctype global != UTF-8"); | ||
315 | wctyc = wctype_l("upper", _LOCALE_C); | ||
316 | if (wctyc == NULL) | ||
317 | errx(1, "wctype_l(upper, C) == NULL"); | ||
318 | TEST_R(iswctype, 1, 0x00D0, wctyg); /* Eth */ | ||
319 | TEST_R(iswctype_l, 1, 0x00D0, wctyu, _LOCALE_UTF8); | ||
320 | TEST_R(iswctype_l, 0, 0x00D0, wctyc, _LOCALE_C); | ||
321 | TEST_R(iswctype, 1, 0x0393, wctyg); /* Gamma */ | ||
322 | TEST_R(iswctype_l, 1, 0x0393, wctyu, _LOCALE_UTF8); | ||
323 | TEST_R(iswctype_l, 0, 0x0393, wctyc, _LOCALE_C); | ||
324 | TEST_R(iswctype, 0, 0x2205, wctyg); /* empty set */ | ||
325 | TEST_R(iswctype_l, 0, 0x2205, wctyu, _LOCALE_UTF8); | ||
326 | TEST_R(iswctype_l, 0, 0x2205, wctyc, _LOCALE_C); | ||
327 | wctrg = wctrans("tolower"); | ||
328 | if (wctrg == NULL) | ||
329 | errx(1, "wctrans(tolower) == NULL"); | ||
330 | wctru = wctrans_l("tolower", _LOCALE_UTF8); | ||
331 | if (wctru == NULL) | ||
332 | errx(1, "wctrans(tolower, UTF-8) == NULL"); | ||
333 | if (wctrg != wctru) | ||
334 | errx(1, "wctrans global != UTF-8"); | ||
335 | wctrc = wctrans_l("tolower", _LOCALE_C); | ||
336 | if (wctrc == NULL) | ||
337 | errx(1, "wctrans(tolower, C) == NULL"); | ||
338 | TEST_R(towctrans, 0x00FE, 0x00DE, wctrg); /* Thorn */ | ||
339 | TEST_R(towctrans_l, 0x00FE, 0x00DE, wctru, _LOCALE_UTF8); | ||
340 | TEST_R(towctrans_l, 0x00DE, 0x00DE, wctrc, _LOCALE_C); | ||
341 | TEST_R(towctrans, 0x03C6, 0x03A6, wctrg); /* Phi */ | ||
342 | TEST_R(towctrans_l, 0x03C6, 0x03A6, wctru, _LOCALE_UTF8); | ||
343 | TEST_R(towctrans_l, 0x03A6, 0x03A6, wctrc, _LOCALE_C); | ||
344 | TEST_R(towctrans, 0x2207, 0x2207, wctrg); /* Nabla */ | ||
345 | TEST_R(towctrans_l, 0x2207, 0x2207, wctru, _LOCALE_UTF8); | ||
346 | TEST_R(towctrans_l, 0x2207, 0x2207, wctrc, _LOCALE_C); | ||
347 | TEST_R(wcscasecmp, 0, s1, s2); | ||
348 | TEST_R(wcscasecmp_l, 0, s1, s2, _LOCALE_UTF8); | ||
349 | TEST_R(wcscasecmp_l, *s1 - *s2, s1, s2, _LOCALE_C); | ||
350 | TEST_R(wcsncasecmp, 0, s3, s4, 2); | ||
351 | TEST_R(wcsncasecmp_l, 0, s3, s4, 2, _LOCALE_UTF8); | ||
352 | TEST_R(wcsncasecmp_l, *s3 - *s4, s3, s4, 2, _LOCALE_C); | ||
353 | |||
354 | /* Test non-ctype newlocale(3). */ | ||
355 | TEST_R(newlocale, _LOCALE_C, LC_MESSAGES_MASK, "en_US.UTF-8"); | ||
356 | |||
357 | /* Test strerror(3). */ | ||
358 | sego = strerror(EPERM); | ||
359 | segc = strdup(sego); | ||
360 | selo = strerror_l(ENOENT, _LOCALE_C); | ||
361 | selc = strdup(selo); | ||
362 | if (strcmp(sego, segc) != 0) | ||
363 | errx(1, "child: strerror_l clobbered strerror"); | ||
364 | free(segc); | ||
365 | sego = strerror(ESRCH); | ||
366 | if (strcmp(selo, selc) != 0) | ||
367 | errx(1, "child: strerror clobbered strerror_l"); | ||
368 | |||
369 | /* Temporarily switch to the main thread. */ | ||
370 | switch_thread(2, SWITCH_SIGNAL | SWITCH_WAIT); | ||
371 | if (strcmp(selo, selc) != 0) | ||
372 | errx(1, "child: main clobbered strerror_l"); | ||
373 | free(selc); | ||
374 | |||
375 | /* Check that the C locale works even while all is set to UTF-8. */ | ||
376 | TEST_R(nl_langinfo_l, "US-ASCII", CODESET, _LOCALE_C); | ||
377 | TEST_R(iswalpha_l, 0, 0x00E9, _LOCALE_C); | ||
378 | TEST_R(towupper_l, 0x00E9, 0x00E9, _LOCALE_C); | ||
379 | TEST_R(wcscasecmp_l, *s1 - *s2, s1, s2, _LOCALE_C); | ||
380 | |||
381 | /* Test displaying the global locale while a local one is set. */ | ||
382 | TEST_R(setlocale, "C/C.UTF-8/C/C/C/C", LC_ALL, NULL); | ||
383 | |||
384 | /* Test switching the thread locale back. */ | ||
385 | TEST_R(MB_CUR_MAX, 4); | ||
386 | TEST_R(duplocale, _LOCALE_UTF8, LC_GLOBAL_LOCALE); | ||
387 | TEST_R(uselocale, _LOCALE_UTF8, _LOCALE_C); | ||
388 | TEST_R(MB_CUR_MAX, 1); | ||
389 | TEST_R(uselocale, _LOCALE_C, _LOCALE_NONE); | ||
390 | |||
391 | /* Check that UTF-8 works even with a C thread locale. */ | ||
392 | TEST_R(nl_langinfo, "US-ASCII", CODESET); | ||
393 | TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); | ||
394 | TEST_R(iswalpha, 0, 0x0153); | ||
395 | TEST_R(iswalpha_l, 1, 0x0153, _LOCALE_UTF8); | ||
396 | TEST_R(towupper, 0x0153, 0x0153); | ||
397 | TEST_R(towupper_l, 0x0152, 0x0153, _LOCALE_UTF8); | ||
398 | TEST_R(wcsncasecmp, *s3 - *s4, s3, s4, 2); | ||
399 | TEST_R(wcsncasecmp_l, 0, s3, s4, 2, _LOCALE_UTF8); | ||
400 | |||
401 | /* Test switching back to the global locale. */ | ||
402 | TEST_R(uselocale, _LOCALE_C, LC_GLOBAL_LOCALE); | ||
403 | TEST_R(MB_CUR_MAX, 4); | ||
404 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); | ||
405 | |||
406 | /* Check that the global locale takes effect even in a thread. */ | ||
407 | TEST_R(nl_langinfo, "UTF-8", CODESET); | ||
408 | TEST_R(iswalpha, 1, 0x0153); | ||
409 | TEST_R(towupper, 0x0152, 0x0153); | ||
410 | TEST_R(wcscasecmp, 0, s1, s2); | ||
411 | |||
412 | /* Hand control back to the main thread. */ | ||
413 | switch_thread(4, SWITCH_SIGNAL); | ||
414 | return NULL; | ||
415 | } | ||
416 | |||
417 | int | ||
418 | main(void) | ||
419 | { | ||
420 | pthread_t child_thread; | ||
421 | char *sego, *segc, *selo, *selc; | ||
422 | int irc; | ||
423 | |||
424 | /* Initialize environment. */ | ||
425 | unsetenv("LC_ALL"); | ||
426 | unsetenv("LC_COLLATE"); | ||
427 | unsetenv("LC_CTYPE"); | ||
428 | unsetenv("LC_MONETARY"); | ||
429 | unsetenv("LC_NUMERIC"); | ||
430 | unsetenv("LC_TIME"); | ||
431 | unsetenv("LC_MESSAGES"); | ||
432 | unsetenv("LANG"); | ||
433 | |||
434 | if ((irc = pthread_mutexattr_init(&mtxattr)) != 0) | ||
435 | errc(1, irc, "pthread_mutexattr_init"); | ||
436 | if ((irc = pthread_mutexattr_settype(&mtxattr, | ||
437 | PTHREAD_MUTEX_STRICT_NP)) != 0) | ||
438 | errc(1, irc, "pthread_mutexattr_settype"); | ||
439 | if ((irc = pthread_mutex_init(&mtx, &mtxattr)) != 0) | ||
440 | errc(1, irc, "pthread_mutex_init"); | ||
441 | if ((irc = pthread_cond_init(&cond, NULL)) != 0) | ||
442 | errc(1, irc, "pthread_cond_init"); | ||
443 | |||
444 | /* First let the child do some tests. */ | ||
445 | if ((irc = pthread_create(&child_thread, NULL, child_func, NULL)) != 0) | ||
446 | errc(1, irc, "pthread_create"); | ||
447 | switch_thread(1, SWITCH_WAIT); | ||
448 | |||
449 | /* Check that the global locale is undisturbed. */ | ||
450 | TEST_R(setlocale, "C", LC_ALL, NULL); | ||
451 | TEST_R(MB_CUR_MAX, 1); | ||
452 | |||
453 | /* Check that *_l(3) works without any locale installed. */ | ||
454 | TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); | ||
455 | TEST_R(iswalpha_l, 1, 0x00E9, _LOCALE_UTF8); | ||
456 | TEST_R(towupper_l, 0x00C9, 0x00E9, _LOCALE_UTF8); | ||
457 | |||
458 | /* Test setting the globale locale. */ | ||
459 | TEST_R(setlocale, "C.UTF-8", LC_CTYPE, "C.UTF-8"); | ||
460 | TEST_R(MB_CUR_MAX, 4); | ||
461 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); | ||
462 | |||
463 | /* Test strerror(3). */ | ||
464 | sego = strerror(EINTR); | ||
465 | segc = strdup(sego); | ||
466 | selo = strerror_l(EIO, _LOCALE_C); | ||
467 | selc = strdup(selo); | ||
468 | if (strcmp(sego, segc) != 0) | ||
469 | errx(1, "main: strerror_l clobbered strerror"); | ||
470 | free(segc); | ||
471 | sego = strerror(ENXIO); | ||
472 | if (strcmp(selo, selc) != 0) | ||
473 | errx(1, "main: strerror clobbered strerror_l"); | ||
474 | free(selc); | ||
475 | |||
476 | /* Let the child do some more tests, then clean up. */ | ||
477 | switch_thread(3, SWITCH_SIGNAL); | ||
478 | if ((irc = pthread_join(child_thread, NULL)) != 0) | ||
479 | errc(1, irc, "pthread_join"); | ||
480 | return 0; | ||
481 | } | ||
diff --git a/src/regress/lib/libc/locale/wcrtomb/Makefile b/src/regress/lib/libc/locale/wcrtomb/Makefile deleted file mode 100644 index b09cecc454..0000000000 --- a/src/regress/lib/libc/locale/wcrtomb/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ | ||
2 | |||
3 | PROG = test_wcrtomb | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/locale/wcrtomb/test_wcrtomb.c b/src/regress/lib/libc/locale/wcrtomb/test_wcrtomb.c deleted file mode 100644 index ee0e14b69d..0000000000 --- a/src/regress/lib/libc/locale/wcrtomb/test_wcrtomb.c +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | /* $OpenBSD: test_wcrtomb.c,v 1.3 2021/07/03 12:04:53 schwarze Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <sys/types.h> | ||
19 | #include <err.h> | ||
20 | #include <errno.h> | ||
21 | #include <limits.h> | ||
22 | #include <locale.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <string.h> | ||
25 | #include <wchar.h> | ||
26 | |||
27 | static mbstate_t mbs; | ||
28 | |||
29 | void | ||
30 | onetest(const char *name, const wchar_t wcin, int outerr, const char *out) | ||
31 | { | ||
32 | char buf[MB_LEN_MAX]; | ||
33 | size_t sz, outsz; | ||
34 | |||
35 | memset(buf, 0, MB_LEN_MAX); | ||
36 | outsz = out == NULL ? (size_t)-1 : *out == '\0' ? 1 : strlen(out); | ||
37 | sz = wcrtomb(buf, wcin, &mbs); | ||
38 | if (errno != outerr) | ||
39 | err(1, "%zu %s U+%04X", MB_CUR_MAX, name, wcin); | ||
40 | if (sz != outsz || (out != NULL && strncmp(buf, out, sz))) | ||
41 | errx(1, "%zu %s U+%04X: %4.4s(%zd) != %4.4s(%zd)", | ||
42 | MB_CUR_MAX, name, wcin, buf, sz, | ||
43 | out == NULL ? "(NULL)" : out, outsz); | ||
44 | if (mbsinit(&mbs) == 0) | ||
45 | errx(1, "%zu %s U+%04X mbsinit", MB_CUR_MAX, name, wcin); | ||
46 | if (errno == 0 && outerr == 0) | ||
47 | return; | ||
48 | errno = 0; | ||
49 | memset(&mbs, 0, sizeof(mbs)); | ||
50 | } | ||
51 | |||
52 | int | ||
53 | main(void) | ||
54 | { | ||
55 | onetest("NUL", L'\0', 0, ""); | ||
56 | onetest("BEL", L'\a', 0, "\a"); | ||
57 | onetest("A", L'A', 0, "A"); | ||
58 | onetest("DEL", L'\177', 0, "\177"); | ||
59 | onetest("CSI", L'\233', 0, "\233"); | ||
60 | onetest("0x100", 0x100, EILSEQ, NULL); | ||
61 | |||
62 | if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) | ||
63 | errx(1, "setlocale(UTF-8) failed"); | ||
64 | |||
65 | onetest("NUL", L'\0', 0, ""); | ||
66 | onetest("BEL", L'\a', 0, "\a"); | ||
67 | onetest("A", L'A', 0, "A"); | ||
68 | onetest("DEL", L'\177', 0, "\177"); | ||
69 | onetest("CSI", L'\233', 0, "\302\233"); | ||
70 | onetest("0xe9", 0xe9, 0, "\303\251"); | ||
71 | onetest("0xcfff", 0xcfff, 0, "\354\277\277"); | ||
72 | onetest("0xd800", 0xd800, EILSEQ, NULL); | ||
73 | |||
74 | if (setlocale(LC_CTYPE, "POSIX") == NULL) | ||
75 | errx(1, "setlocale(POSIX) failed"); | ||
76 | |||
77 | onetest("0xff", L'\377', 0, "\377"); | ||
78 | |||
79 | if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) | ||
80 | errx(1, "second setlocale(UTF-8) failed"); | ||
81 | |||
82 | onetest("U+13000", 0x13000, 0, "\360\223\200\200"); | ||
83 | |||
84 | return 0; | ||
85 | } | ||
diff --git a/src/regress/lib/libc/longjmp/Makefile b/src/regress/lib/libc/longjmp/Makefile deleted file mode 100644 index 825e0f86d9..0000000000 --- a/src/regress/lib/libc/longjmp/Makefile +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.4 2002/09/02 20:01:43 avsm Exp $ | ||
2 | PROG= longjmp | ||
3 | |||
4 | do-longjmp: ${PROG} | ||
5 | ./longjmp | ||
6 | |||
7 | do-_longjmp: ${PROG} | ||
8 | ./longjmp -_ | ||
9 | |||
10 | REGRESS_TARGETS=do-longjmp do-_longjmp | ||
11 | .PHONY: ${REGRESS_TARGETS} | ||
12 | |||
13 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/longjmp/longjmp.c b/src/regress/lib/libc/longjmp/longjmp.c deleted file mode 100644 index 7dea5bd97c..0000000000 --- a/src/regress/lib/libc/longjmp/longjmp.c +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /* $OpenBSD: longjmp.c,v 1.4 2002/02/18 11:27:45 art Exp $ */ | ||
2 | /* | ||
3 | * Artur Grabowski <art@openbsd.org>, 2002 Public Domain. | ||
4 | */ | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <unistd.h> | ||
9 | #include <setjmp.h> | ||
10 | #include <err.h> | ||
11 | #include <sys/types.h> | ||
12 | #include <sys/time.h> | ||
13 | #include <sys/resource.h> | ||
14 | |||
15 | |||
16 | jmp_buf buf; | ||
17 | |||
18 | /* | ||
19 | * When longjmp is passed the incorrect arg (0), it should translate it into | ||
20 | * something better. | ||
21 | * | ||
22 | * The rlimit is here in case we start spinning. | ||
23 | */ | ||
24 | int | ||
25 | main(int argc, char **argv) | ||
26 | { | ||
27 | struct rlimit rl; | ||
28 | volatile int i, expect; | ||
29 | int (*sj)(jmp_buf); | ||
30 | void (*lj)(jmp_buf, int); | ||
31 | int ch; | ||
32 | extern char *__progname; | ||
33 | |||
34 | sj = setjmp; | ||
35 | lj = longjmp; | ||
36 | |||
37 | while ((ch = getopt(argc, argv, "_")) != -1) { | ||
38 | switch (ch) { | ||
39 | case '_': | ||
40 | sj = _setjmp; | ||
41 | lj = _longjmp; | ||
42 | break; | ||
43 | default: | ||
44 | fprintf(stderr, "Usage: %s [-_]\n", __progname); | ||
45 | exit(1); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | rl.rlim_cur = 2; | ||
50 | rl.rlim_max = 2; | ||
51 | if (setrlimit(RLIMIT_CPU, &rl) < 0) | ||
52 | err(1, "setrlimit"); | ||
53 | |||
54 | expect = 0; | ||
55 | i = (*sj)(buf); | ||
56 | if (i == 0 && expect != 0) | ||
57 | errx(1, "setjmp returns 0 on longjmp(.., 0)"); | ||
58 | if (expect == 0) { | ||
59 | expect = -1; | ||
60 | (*lj)(buf, 0); | ||
61 | } | ||
62 | |||
63 | expect = 0; | ||
64 | i = (*sj)(buf); | ||
65 | if (i != expect) | ||
66 | errx(1, "bad return from setjmp %d/%d", expect, i); | ||
67 | if (expect < 1000) | ||
68 | (*lj)(buf, expect += 2); | ||
69 | |||
70 | return 0; | ||
71 | } | ||
diff --git a/src/regress/lib/libc/malloc/Makefile b/src/regress/lib/libc/malloc/Makefile deleted file mode 100644 index 546d67f6ca..0000000000 --- a/src/regress/lib/libc/malloc/Makefile +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.8 2023/05/08 11:13:30 otto Exp $ | ||
2 | |||
3 | SUBDIR+= malloc_general malloc0test malloc_errno malloc_ulimit1 malloc_ulimit2 | ||
4 | SUBDIR+= malloc_threaderr malloc_errs | ||
5 | |||
6 | install: | ||
7 | |||
8 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc0test/Makefile b/src/regress/lib/libc/malloc/malloc0test/Makefile deleted file mode 100644 index fc2295c091..0000000000 --- a/src/regress/lib/libc/malloc/malloc0test/Makefile +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2017/07/08 00:08:26 bluhm Exp $ | ||
2 | |||
3 | PROG= malloc0test | ||
4 | |||
5 | .for m in C D F G J j R S U X << >>> | ||
6 | REGRESS_TARGETS += run-regress-${PROG}-${m:S/</-/g:S/>/+/g} | ||
7 | run-regress-${PROG}-${m:S/</-/g:S/>/+/g}: ${PROG} | ||
8 | MALLOC_OPTIONS='${m}' ./${PROG} | ||
9 | .endfor | ||
10 | |||
11 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc0test/malloc0test.c b/src/regress/lib/libc/malloc/malloc0test/malloc0test.c deleted file mode 100644 index 06ff0996ee..0000000000 --- a/src/regress/lib/libc/malloc/malloc0test/malloc0test.c +++ /dev/null | |||
@@ -1,120 +0,0 @@ | |||
1 | /* $OpenBSD: malloc0test.c,v 1.5 2008/04/13 00:22:17 djm Exp $ */ | ||
2 | /* | ||
3 | * Public domain. 2001, Theo de Raadt | ||
4 | */ | ||
5 | #include <sys/types.h> | ||
6 | #include <sys/signal.h> | ||
7 | #include <stdio.h> | ||
8 | #include <unistd.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <setjmp.h> | ||
11 | #include <limits.h> | ||
12 | #include <errno.h> | ||
13 | |||
14 | volatile sig_atomic_t got; | ||
15 | jmp_buf jmp; | ||
16 | |||
17 | static void | ||
18 | catch(int signo) | ||
19 | { | ||
20 | got++; | ||
21 | longjmp(jmp, 1); | ||
22 | } | ||
23 | |||
24 | static int | ||
25 | test(char *p, int size) | ||
26 | { | ||
27 | signal(SIGSEGV, catch); | ||
28 | got = 0; | ||
29 | if (setjmp(jmp) == 0) | ||
30 | *p = 0; | ||
31 | if (setjmp(jmp) == 0) | ||
32 | *(p+size-1) = 0; | ||
33 | return (got); | ||
34 | } | ||
35 | |||
36 | char *prot_table[] = { | ||
37 | "unprotected", | ||
38 | "fuckup", | ||
39 | "protected" | ||
40 | }; | ||
41 | |||
42 | #define SIZE 10 | ||
43 | |||
44 | /* | ||
45 | * Do random memory allocations. | ||
46 | * | ||
47 | * For each one, ensure that it is at least 16 bytes in size (that | ||
48 | * being what our current malloc returns for the minsize of an | ||
49 | * object, alignment wise); | ||
50 | * | ||
51 | * For zero-byte allocations, check that they are still aligned. | ||
52 | * | ||
53 | * For each object, ensure that they are correctly protected or not | ||
54 | * protected. | ||
55 | * | ||
56 | * Does not regress test malloc + free combinations ... it should. | ||
57 | */ | ||
58 | int | ||
59 | main(int argc, char *argv[]) | ||
60 | { | ||
61 | caddr_t blob; | ||
62 | int size, tsize; | ||
63 | int prot; | ||
64 | int rval = 0, fuckup = 0; | ||
65 | long limit = 200000, count; | ||
66 | int ch, silent = 0; | ||
67 | char *ep; | ||
68 | extern char *__progname; | ||
69 | |||
70 | while ((ch = getopt(argc, argv, "sn:")) != -1) { | ||
71 | switch (ch) { | ||
72 | case 's': | ||
73 | silent = 1; | ||
74 | break; | ||
75 | case 'n': | ||
76 | errno = 0; | ||
77 | limit = strtol(optarg, &ep, 10); | ||
78 | if (optarg[0] == '\0' || *ep != '\0' || | ||
79 | (errno == ERANGE && | ||
80 | (limit == LONG_MAX || limit == LONG_MIN))) | ||
81 | goto usage; | ||
82 | break; | ||
83 | default: | ||
84 | usage: | ||
85 | fprintf(stderr, "Usage: %s [-s][-n <count>]\n", | ||
86 | __progname); | ||
87 | exit(1); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | if (limit == 0) | ||
92 | limit = LONG_MAX; | ||
93 | |||
94 | for (count = 0; count < limit; count++) { | ||
95 | size = arc4random_uniform(SIZE); | ||
96 | blob = malloc(size); | ||
97 | if (blob == NULL) { | ||
98 | fprintf(stderr, "success: out of memory\n"); | ||
99 | exit(rval); | ||
100 | } | ||
101 | |||
102 | tsize = size == 0 ? 16 : size; | ||
103 | fuckup = 0; | ||
104 | prot = test(blob, tsize); | ||
105 | |||
106 | if (size == 0 && prot < 2) | ||
107 | fuckup = 1; | ||
108 | |||
109 | if (fuckup) { | ||
110 | printf("%8p %6d %20s %10s\n", blob, size, | ||
111 | prot_table[prot], fuckup ? "fuckup" : ""); | ||
112 | rval = 1; | ||
113 | } | ||
114 | |||
115 | if (!silent && count % 100000 == 0 && count != 0) | ||
116 | fprintf(stderr, "count = %ld\n", count); | ||
117 | } | ||
118 | |||
119 | return rval; | ||
120 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errno/Makefile b/src/regress/lib/libc/malloc/malloc_errno/Makefile deleted file mode 100644 index 73ebe37491..0000000000 --- a/src/regress/lib/libc/malloc/malloc_errno/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2003/07/15 10:06:31 otto Exp $ | ||
2 | |||
3 | PROG= malloc_errno | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c b/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c deleted file mode 100644 index 1759291f38..0000000000 --- a/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | /* $OpenBSD: malloc_errno.c,v 1.5 2019/06/11 22:16:13 bluhm Exp $ */ | ||
2 | /* | ||
3 | * Public domain. 2003, Otto Moerbeek | ||
4 | */ | ||
5 | #include <err.h> | ||
6 | #include <errno.h> | ||
7 | #include <stdio.h> | ||
8 | #include <stdlib.h> | ||
9 | |||
10 | /* On arm64 with 2G of memory this test hangs while junking. */ | ||
11 | char *malloc_options = "jj"; | ||
12 | |||
13 | static void | ||
14 | testerrno(size_t sz) | ||
15 | { | ||
16 | void *p; | ||
17 | |||
18 | errno = -1; | ||
19 | p = malloc(sz); | ||
20 | |||
21 | if (p == NULL && errno != ENOMEM) | ||
22 | errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno); | ||
23 | |||
24 | /* if alloc succeeded, test if errno did not change */ | ||
25 | if (p != NULL && errno != -1) | ||
26 | errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno); | ||
27 | |||
28 | free(p); | ||
29 | } | ||
30 | |||
31 | /* | ||
32 | * Provide some (silly) arguments to malloc(), and check if ERRNO is set | ||
33 | * correctly. | ||
34 | */ | ||
35 | int | ||
36 | main(int argc, char *argv[]) | ||
37 | { | ||
38 | size_t i; | ||
39 | |||
40 | testerrno(1); | ||
41 | testerrno(100000); | ||
42 | testerrno(-1); | ||
43 | testerrno(-1000); | ||
44 | testerrno(-10000); | ||
45 | testerrno(-10000000); | ||
46 | for (i = 0; i < 0x10; i++) | ||
47 | testerrno(i * 0x10000000); | ||
48 | return 0; | ||
49 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errs/Makefile b/src/regress/lib/libc/malloc/malloc_errs/Makefile deleted file mode 100644 index 150f30e671..0000000000 --- a/src/regress/lib/libc/malloc/malloc_errs/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2023/05/08 11:12:44 otto Exp $ | ||
2 | |||
3 | PROG= malloc_errs | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c b/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c deleted file mode 100644 index 486c247f0d..0000000000 --- a/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c +++ /dev/null | |||
@@ -1,325 +0,0 @@ | |||
1 | /* $OpenBSD: malloc_errs.c,v 1.5 2024/04/14 17:47:41 otto Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2023 Otto Moerbeek <otto@drijf.net> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <sys/resource.h> | ||
19 | #include <sys/wait.h> | ||
20 | #include <err.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <stdio.h> | ||
23 | #include <stdint.h> | ||
24 | #include <signal.h> | ||
25 | #include <unistd.h> | ||
26 | |||
27 | /* Test erroneous use of API and heap that malloc should catch */ | ||
28 | |||
29 | void | ||
30 | clearq(void *p) | ||
31 | { | ||
32 | int i; | ||
33 | void *q; | ||
34 | |||
35 | /* Clear delayed free queue */ | ||
36 | for (i = 0; i < 400; i++) { | ||
37 | q = malloc(100); | ||
38 | free(q); | ||
39 | if (p == q) { | ||
40 | fprintf(stderr, "Re-use\n"); | ||
41 | abort(); | ||
42 | } | ||
43 | } | ||
44 | } | ||
45 | |||
46 | /* test the test setup */ | ||
47 | void | ||
48 | t0(void) | ||
49 | { | ||
50 | abort(); | ||
51 | } | ||
52 | |||
53 | /* double free >= page size */ | ||
54 | void | ||
55 | t1(void) | ||
56 | { | ||
57 | void *p = malloc(10000); | ||
58 | free(p); | ||
59 | free(p); | ||
60 | } | ||
61 | |||
62 | /* double free chunks are different, have a delayed free list */ | ||
63 | void | ||
64 | t2(void) | ||
65 | { | ||
66 | void *p, *q; | ||
67 | int i; | ||
68 | |||
69 | p = malloc(100); | ||
70 | free(p); | ||
71 | clearq(p); | ||
72 | free(p); | ||
73 | } | ||
74 | |||
75 | /* double free without clearing delayed free list, needs F */ | ||
76 | void | ||
77 | t3(void) | ||
78 | { | ||
79 | void *p = malloc(100); | ||
80 | free(p); | ||
81 | free(p); | ||
82 | } | ||
83 | |||
84 | /* free without prior allocation */ | ||
85 | void | ||
86 | t4(void) | ||
87 | { | ||
88 | free((void*)1); | ||
89 | } | ||
90 | |||
91 | /* realloc of bogus pointer */ | ||
92 | void | ||
93 | t5(void) | ||
94 | { | ||
95 | realloc((void*)1, 10); | ||
96 | } | ||
97 | |||
98 | /* write after free for chunk */ | ||
99 | void | ||
100 | t6(void) | ||
101 | { | ||
102 | char *p = malloc(32); | ||
103 | free(p); | ||
104 | p[0] = ~p[0]; | ||
105 | clearq(NULL); | ||
106 | } | ||
107 | |||
108 | /* write after free large alloction */ | ||
109 | void | ||
110 | t7(void) | ||
111 | { | ||
112 | char *p, *q; | ||
113 | int i; | ||
114 | |||
115 | p = malloc(10000); | ||
116 | free(p); | ||
117 | p[0] = ~p[0]; | ||
118 | /* force re-use from the cache */ | ||
119 | for (i = 0; i < 100; i++) { | ||
120 | q = malloc(10000); | ||
121 | free(q); | ||
122 | } | ||
123 | } | ||
124 | |||
125 | /* write after free for chunk, no clearing of delayed free queue */ | ||
126 | void | ||
127 | t8(void) | ||
128 | { | ||
129 | char *p, *q; | ||
130 | |||
131 | p = malloc(32); | ||
132 | q = malloc(32); | ||
133 | free(p); | ||
134 | p[0] = ~p[0]; | ||
135 | free(q); | ||
136 | } | ||
137 | |||
138 | /* canary check */ | ||
139 | void | ||
140 | t9(void) | ||
141 | { | ||
142 | char *p = malloc(100); | ||
143 | p[100] = 0; | ||
144 | free(p); | ||
145 | } | ||
146 | |||
147 | /* t10 is the same as t9 with different flags */ | ||
148 | |||
149 | /* modified chunk pointer */ | ||
150 | void | ||
151 | t11(void) | ||
152 | { | ||
153 | char *p = malloc(100); | ||
154 | free(p + 1); | ||
155 | } | ||
156 | |||
157 | /* free chunk pointer */ | ||
158 | void | ||
159 | t12(void) | ||
160 | { | ||
161 | char *p = malloc(16); | ||
162 | free(p + 16); | ||
163 | } | ||
164 | |||
165 | /* freezero with wrong size */ | ||
166 | void | ||
167 | t13(void) | ||
168 | { | ||
169 | char *p = malloc(16); | ||
170 | freezero(p, 17); | ||
171 | } | ||
172 | |||
173 | /* freezero with wrong size 2 */ | ||
174 | void | ||
175 | t14(void) | ||
176 | { | ||
177 | char *p = malloc(15); | ||
178 | freezero(p, 16); | ||
179 | } | ||
180 | |||
181 | /* freezero with wrong size, pages */ | ||
182 | void | ||
183 | t15(void) | ||
184 | { | ||
185 | char *p = malloc(getpagesize()); | ||
186 | freezero(p, getpagesize() + 1); | ||
187 | } | ||
188 | |||
189 | /* recallocarray with wrong size */ | ||
190 | void | ||
191 | t16(void) | ||
192 | { | ||
193 | char *p = recallocarray(NULL, 0, 16, 1); | ||
194 | char *q = recallocarray(p, 2, 3, 16); | ||
195 | } | ||
196 | |||
197 | /* recallocarray with wrong size 2 */ | ||
198 | void | ||
199 | t17(void) | ||
200 | { | ||
201 | char *p = recallocarray(NULL, 0, 15, 1); | ||
202 | char *q = recallocarray(p, 2, 3, 15); | ||
203 | } | ||
204 | |||
205 | /* recallocarray with wrong size, pages */ | ||
206 | void | ||
207 | t18(void) | ||
208 | { | ||
209 | char *p = recallocarray(NULL, 0, 1, getpagesize()); | ||
210 | char *q = recallocarray(p, 2, 3, getpagesize()); | ||
211 | } | ||
212 | |||
213 | /* recallocarray with wrong size, pages */ | ||
214 | void | ||
215 | t19(void) | ||
216 | { | ||
217 | char *p = recallocarray(NULL, 0, 1, 10 * getpagesize()); | ||
218 | char *q = recallocarray(p, 1, 2, 4 * getpagesize()); | ||
219 | } | ||
220 | |||
221 | /* canary check pages */ | ||
222 | void | ||
223 | t20(void) | ||
224 | { | ||
225 | char *p = malloc(2*getpagesize() - 100); | ||
226 | p[2*getpagesize() - 100] = 0; | ||
227 | free(p); | ||
228 | } | ||
229 | |||
230 | /* out-of-bound write preceding chunk */ | ||
231 | void | ||
232 | t22(void) | ||
233 | { | ||
234 | int i, j; | ||
235 | unsigned char *p; | ||
236 | while (1) { | ||
237 | uintptr_t address; | ||
238 | p = malloc(32); | ||
239 | address = (uintptr_t)(void *)p; | ||
240 | /* we don't want to have a chunk on the last slot of a page */ | ||
241 | if (address / getpagesize() == (address + 32) / getpagesize()) | ||
242 | break; | ||
243 | free(p); | ||
244 | } | ||
245 | p[32] = 0; | ||
246 | for (i = 0; i < 10000; i++) | ||
247 | p = malloc(32); | ||
248 | } | ||
249 | |||
250 | struct test { | ||
251 | void (*test)(void); | ||
252 | const char *flags; | ||
253 | }; | ||
254 | |||
255 | struct test tests[] = { | ||
256 | { t0, "" }, | ||
257 | { t1, "" }, | ||
258 | { t2, "" }, | ||
259 | { t3, "F" }, | ||
260 | { t4, "" }, | ||
261 | { t5, "" }, | ||
262 | { t6, "J" }, | ||
263 | { t7, "JJ" }, | ||
264 | { t8, "FJ" }, | ||
265 | { t9, "C" }, | ||
266 | { t9, "JC" }, /* t10 re-uses code from t9 */ | ||
267 | { t11, "" }, | ||
268 | { t12, "" }, | ||
269 | { t13, "" }, | ||
270 | { t14, "C" }, | ||
271 | { t15, "" }, | ||
272 | { t16, "" }, | ||
273 | { t17, "C" }, | ||
274 | { t18, "" }, | ||
275 | { t19, "" }, | ||
276 | { t20, "C" }, | ||
277 | { t8, "FJD" }, /* t21 re-uses code from t8 */ | ||
278 | { t22, "J" }, | ||
279 | { t22, "JD" }, /* t23 re-uses code from t22 */ | ||
280 | }; | ||
281 | |||
282 | int main(int argc, char *argv[]) | ||
283 | { | ||
284 | |||
285 | const struct rlimit lim = {0, 0}; | ||
286 | int i, status; | ||
287 | pid_t pid; | ||
288 | char num[10]; | ||
289 | char options[10]; | ||
290 | extern char* malloc_options; | ||
291 | |||
292 | if (argc == 3) { | ||
293 | malloc_options = argv[2]; | ||
294 | /* prevent coredumps */ | ||
295 | setrlimit(RLIMIT_CORE, &lim); | ||
296 | i = atoi(argv[1]); | ||
297 | fprintf(stderr, "Test %d\n", i); | ||
298 | (*tests[i].test)(); | ||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) { | ||
303 | pid = fork(); | ||
304 | switch (pid) { | ||
305 | case 0: | ||
306 | snprintf(options, sizeof(options), "us%s", tests[i].flags); | ||
307 | snprintf(num, sizeof(num), "%d", i); | ||
308 | execl(argv[0], argv[0], num, options, NULL); | ||
309 | err(1, "exec"); | ||
310 | break; | ||
311 | case -1: | ||
312 | err(1, "fork"); | ||
313 | break; | ||
314 | default: | ||
315 | if (waitpid(pid, &status, 0) == -1) | ||
316 | err(1, "wait"); | ||
317 | if (!WIFSIGNALED(status) || | ||
318 | WTERMSIG(status) != SIGABRT) | ||
319 | errx(1, "Test %d did not abort", i); | ||
320 | break; | ||
321 | } | ||
322 | } | ||
323 | return 0; | ||
324 | } | ||
325 | |||
diff --git a/src/regress/lib/libc/malloc/malloc_general/Makefile b/src/regress/lib/libc/malloc/malloc_general/Makefile deleted file mode 100644 index 367b33b9c5..0000000000 --- a/src/regress/lib/libc/malloc/malloc_general/Makefile +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.7 2023/05/09 19:07:37 otto Exp $ | ||
2 | |||
3 | REGRESS_TARGETS= t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 | ||
4 | PROG= malloc_general | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
7 | |||
8 | t1: malloc_general | ||
9 | MALLOC_OPTIONS=su ${.OBJDIR}/malloc_general | ||
10 | |||
11 | t2: malloc_general | ||
12 | MALLOC_OPTIONS=suC ${.OBJDIR}/malloc_general | ||
13 | |||
14 | t3: malloc_general | ||
15 | MALLOC_OPTIONS=suJ ${.OBJDIR}/malloc_general | ||
16 | |||
17 | t4: malloc_general | ||
18 | MALLOC_OPTIONS=suF ${.OBJDIR}/malloc_general | ||
19 | |||
20 | t5: malloc_general | ||
21 | MALLOC_OPTIONS=suG ${.OBJDIR}/malloc_general | ||
22 | |||
23 | t6: malloc_general | ||
24 | MALLOC_OPTIONS=suS ${.OBJDIR}/malloc_general | ||
25 | |||
26 | t7: malloc_general | ||
27 | MALLOC_OPTIONS=suFGJ ${.OBJDIR}/malloc_general | ||
28 | |||
29 | t8: malloc_general | ||
30 | MALLOC_OPTIONS=suCJ ${.OBJDIR}/malloc_general | ||
31 | |||
32 | t9: malloc_general | ||
33 | MALLOC_OPTIONS=suCJJ ${.OBJDIR}/malloc_general | ||
34 | |||
35 | t10: malloc_general | ||
36 | MALLOC_OPTIONS=suJS ${.OBJDIR}/malloc_general | ||
37 | |||
38 | t11: malloc_general | ||
39 | MALLOC_OPTIONS=suFGJJ ${.OBJDIR}/malloc_general | ||
40 | |||
41 | t12: malloc_general | ||
42 | MALLOC_OPTIONS=suFCJJ ${.OBJDIR}/malloc_general | ||
43 | |||
diff --git a/src/regress/lib/libc/malloc/malloc_general/malloc_general.c b/src/regress/lib/libc/malloc/malloc_general/malloc_general.c deleted file mode 100644 index b243787bcf..0000000000 --- a/src/regress/lib/libc/malloc/malloc_general/malloc_general.c +++ /dev/null | |||
@@ -1,123 +0,0 @@ | |||
1 | /* $OpenBSD: malloc_general.c,v 1.7 2022/01/09 07:18:50 otto Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2017 Otto Moerbeek <otto@drijf.net> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <err.h> | ||
19 | #include <stdio.h> | ||
20 | #include <stdlib.h> | ||
21 | #include <string.h> | ||
22 | |||
23 | /* #define VERBOSE */ | ||
24 | |||
25 | #define N 1000 | ||
26 | |||
27 | size_t | ||
28 | size(void) | ||
29 | { | ||
30 | int p = arc4random_uniform(17) + 3; | ||
31 | return arc4random_uniform(1 << p); | ||
32 | } | ||
33 | |||
34 | struct { void *p; size_t sz; } a[N]; | ||
35 | |||
36 | void | ||
37 | fill(u_char *p, size_t sz) | ||
38 | { | ||
39 | size_t i; | ||
40 | |||
41 | for (i = 0; i < sz; i++) | ||
42 | p[i] = i % 256; | ||
43 | } | ||
44 | |||
45 | void | ||
46 | check(u_char *p, size_t sz) | ||
47 | { | ||
48 | size_t i; | ||
49 | |||
50 | for (i = 0; i < sz; i++) | ||
51 | if (p[i] != i % 256) | ||
52 | errx(1, "check"); | ||
53 | } | ||
54 | |||
55 | int | ||
56 | main(int argc, char *argv[]) | ||
57 | { | ||
58 | int count, p, r, i; | ||
59 | void * q; | ||
60 | size_t sz; | ||
61 | |||
62 | for (count = 0; count < 800000; count++) { | ||
63 | if (count % 10000 == 0) { | ||
64 | printf("."); | ||
65 | fflush(stdout); | ||
66 | } | ||
67 | p = arc4random_uniform(2); | ||
68 | i = arc4random_uniform(N); | ||
69 | switch (p) { | ||
70 | case 0: | ||
71 | if (a[i].p) { | ||
72 | #ifdef VERBOSE | ||
73 | printf("F %p\n", a[i].p); | ||
74 | #endif | ||
75 | if (a[i].p) | ||
76 | check(a[i].p, a[i].sz); | ||
77 | free(a[i].p); | ||
78 | a[i].p = NULL; | ||
79 | } | ||
80 | sz = size(); | ||
81 | #ifdef VERBOSE | ||
82 | printf("M %zu=", sz); | ||
83 | #endif | ||
84 | r = arc4random_uniform(2); | ||
85 | a[i].p = r == 0 ? malloc_conceal(sz) : malloc(sz); | ||
86 | a[i].sz = sz; | ||
87 | #ifdef VERBOSE | ||
88 | printf("%p\n", a[i].p); | ||
89 | #endif | ||
90 | if (a[i].p) | ||
91 | fill(a[i].p, sz); | ||
92 | break; | ||
93 | case 1: | ||
94 | sz = size(); | ||
95 | #ifdef VERBOSE | ||
96 | printf("R %p %zu=", a[i].p, sz); | ||
97 | #endif | ||
98 | q = realloc(a[i].p, sz); | ||
99 | #ifdef VERBOSE | ||
100 | printf("%p\n", q); | ||
101 | #endif | ||
102 | if (a[i].p && q) | ||
103 | check(q, a[i].sz < sz ? a[i].sz : sz); | ||
104 | if (q) { | ||
105 | a[i].p = q; | ||
106 | a[i].sz = sz; | ||
107 | fill(a[i].p, sz); | ||
108 | } | ||
109 | break; | ||
110 | } | ||
111 | } | ||
112 | for (i = 0; i < N; i++) { | ||
113 | if (a[i].p) | ||
114 | check(a[i].p, a[i].sz); | ||
115 | r = arc4random_uniform(2); | ||
116 | if (r) | ||
117 | free(a[i].p); | ||
118 | else | ||
119 | freezero(a[i].p, a[i].sz); | ||
120 | } | ||
121 | printf("\n"); | ||
122 | return 0; | ||
123 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_threaderr/Makefile b/src/regress/lib/libc/malloc/malloc_threaderr/Makefile deleted file mode 100644 index 2d715af58b..0000000000 --- a/src/regress/lib/libc/malloc/malloc_threaderr/Makefile +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2018/01/28 14:55:24 otto Exp $ | ||
2 | |||
3 | # This test is supposed to print a malloc error and create a core dump | ||
4 | |||
5 | REGRESS_TARGETS= t1 | ||
6 | PROG= malloc_threaderr | ||
7 | LDADD+= -pthread | ||
8 | DPADD+= ${LIBPTHREAD} | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
11 | |||
12 | t1: malloc_threaderr | ||
13 | ${.OBJDIR}/malloc_threaderr 2>&1 | fgrep 'in free(): bogus pointer (double free?)' | ||
diff --git a/src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c b/src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c deleted file mode 100644 index 3c38604ede..0000000000 --- a/src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c +++ /dev/null | |||
@@ -1,72 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2018 Otto Moerbeek <otto@drijf.net> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <err.h> | ||
18 | #include <pthread.h> | ||
19 | #include <signal.h> | ||
20 | #include <stdio.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <unistd.h> | ||
23 | #include <sys/resource.h> | ||
24 | |||
25 | pthread_cond_t cond; | ||
26 | pthread_mutex_t mutex; | ||
27 | |||
28 | void *p; | ||
29 | |||
30 | void *m(void *arg) | ||
31 | { | ||
32 | p = malloc(100000); | ||
33 | if (p == NULL) | ||
34 | err(1, NULL); | ||
35 | return NULL; | ||
36 | } | ||
37 | |||
38 | void *f(void *arg) | ||
39 | { | ||
40 | free(p); | ||
41 | free(p); | ||
42 | return NULL; | ||
43 | } | ||
44 | |||
45 | void | ||
46 | catch(int x) | ||
47 | { | ||
48 | _exit(0); | ||
49 | } | ||
50 | |||
51 | int | ||
52 | main(void) | ||
53 | { | ||
54 | const struct rlimit lim = {0, 0}; | ||
55 | pthread_t t1, t2; | ||
56 | |||
57 | /* prevent coredumps */ | ||
58 | setrlimit(RLIMIT_CORE, &lim); | ||
59 | printf("This test is supposed to print a malloc error\n"); | ||
60 | |||
61 | signal(SIGABRT, catch); | ||
62 | |||
63 | if (pthread_create(&t1, NULL, m, NULL)) | ||
64 | err(1, "pthread_create"); | ||
65 | pthread_join(t1, NULL); | ||
66 | |||
67 | if (pthread_create(&t2, NULL, f, NULL)) | ||
68 | err(1, "pthread_create"); | ||
69 | pthread_join(t2, NULL); | ||
70 | |||
71 | return 1; | ||
72 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile b/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile deleted file mode 100644 index 46ced27a98..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2006/04/18 19:03:30 otto Exp $ | ||
2 | |||
3 | PROG= malloc_ulimit1 | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c b/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c deleted file mode 100644 index 799d2b9117..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | /* $OpenBSD: malloc_ulimit1.c,v 1.5 2019/06/12 11:31:36 bluhm Exp $ */ | ||
2 | |||
3 | /* Public Domain, 2006, Otto Moerbeek <otto@drijf.net> */ | ||
4 | |||
5 | #include <sys/types.h> | ||
6 | #include <sys/time.h> | ||
7 | #include <sys/resource.h> | ||
8 | #include <err.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <stdio.h> | ||
11 | |||
12 | /* | ||
13 | * This code tries to trigger the case present in -current as of April | ||
14 | * 2006) where the allocation of the region itself succeeds, but the | ||
15 | * page dir entry pages fails. | ||
16 | * This in turn trips a "hole in directories" error. | ||
17 | * Having a large (512M) ulimit -m helps a lot in triggering the | ||
18 | * problem. Note that you may need to run this test multiple times to | ||
19 | * see the error. | ||
20 | */ | ||
21 | |||
22 | #define STARTI 1300 | ||
23 | #define FACTOR 1024 | ||
24 | |||
25 | /* This test takes forever with junking turned on. */ | ||
26 | char *malloc_options = "jj"; | ||
27 | |||
28 | int | ||
29 | main() | ||
30 | { | ||
31 | struct rlimit lim; | ||
32 | size_t sz; | ||
33 | int i; | ||
34 | void *p; | ||
35 | |||
36 | if (getrlimit(RLIMIT_DATA, &lim) == -1) | ||
37 | err(1, "getrlimit"); | ||
38 | |||
39 | sz = lim.rlim_cur / FACTOR; | ||
40 | |||
41 | for (i = STARTI; i >= 0; i--) { | ||
42 | size_t len = (sz-i) * FACTOR; | ||
43 | p = malloc(len); | ||
44 | free(p); | ||
45 | free(malloc(4096)); | ||
46 | } | ||
47 | return (0); | ||
48 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile b/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile deleted file mode 100644 index bc83666415..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2006/04/18 19:04:03 otto Exp $ | ||
2 | |||
3 | PROG= malloc_ulimit2 | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c b/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c deleted file mode 100644 index 5d9e3774e7..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | /* $OpenBSD: malloc_ulimit2.c,v 1.5 2019/06/12 11:31:36 bluhm Exp $ */ | ||
2 | |||
3 | /* Public Domain, 2006, Otto Moerbeek <otto@drijf.net> */ | ||
4 | |||
5 | #include <sys/types.h> | ||
6 | #include <sys/time.h> | ||
7 | #include <sys/resource.h> | ||
8 | #include <err.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <stdio.h> | ||
11 | |||
12 | #define FACTOR 1024 | ||
13 | |||
14 | /* This test takes forever with junking turned on. */ | ||
15 | char *malloc_options = "jj"; | ||
16 | |||
17 | int | ||
18 | main() | ||
19 | { | ||
20 | struct rlimit lim; | ||
21 | size_t sz; | ||
22 | int i; | ||
23 | void *p; | ||
24 | |||
25 | if (getrlimit(RLIMIT_DATA, &lim) == -1) | ||
26 | err(1, "getrlimit"); | ||
27 | |||
28 | sz = lim.rlim_cur / FACTOR; | ||
29 | |||
30 | for (i = 0; ; i++) { | ||
31 | size_t len = (sz-i) * FACTOR; | ||
32 | p = malloc(len); | ||
33 | if (p != NULL) { | ||
34 | free(p); | ||
35 | break; | ||
36 | } | ||
37 | } | ||
38 | i += 10; | ||
39 | for (; i >= 0; i--) { | ||
40 | size_t len = (sz-i) * FACTOR; | ||
41 | p = malloc(len); | ||
42 | free(p); | ||
43 | free(malloc(4096)); | ||
44 | } | ||
45 | return (0); | ||
46 | } | ||
diff --git a/src/regress/lib/libc/mkstemp/Makefile b/src/regress/lib/libc/mkstemp/Makefile deleted file mode 100644 index dc7eb281a9..0000000000 --- a/src/regress/lib/libc/mkstemp/Makefile +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2010/02/11 07:35:38 guenther Exp $ | ||
2 | |||
3 | PROG=mkstemp_test | ||
4 | CLEANFILES+= ; rm -rf output | ||
5 | |||
6 | O = output | ||
7 | |||
8 | # The ktrace/kdump/perl combo verifies that all open() calls that | ||
9 | # were passed O_CREAT were also passed O_EXCL | ||
10 | run-regress-${PROG}: ${PROG} | ||
11 | mkdir -p $O && cd $O && ktrace ../${PROG} | ||
12 | cd $O && kdump | perl -mFcntl -nl \ | ||
13 | -e '/ open\([^,]*,([^,]+)/ or next;' \ | ||
14 | -e '$$f = oct($$1);' \ | ||
15 | -e 'if ($$f & O_CREAT && !($$f & O_EXCL)) {' \ | ||
16 | -e ' print "FAIL"; exit 1' \ | ||
17 | -e '}' | ||
18 | |||
19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/mkstemp/mkstemp_test.c b/src/regress/lib/libc/mkstemp/mkstemp_test.c deleted file mode 100644 index b92619cd36..0000000000 --- a/src/regress/lib/libc/mkstemp/mkstemp_test.c +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2010 Philip Guenther <guenther@openbsd.org> | ||
3 | * | ||
4 | * Public domain. | ||
5 | * | ||
6 | * Verify that mkstemp() and mkstemps() doesn't overrun or underrun | ||
7 | * the template buffer and that it can generate names that don't | ||
8 | * contain any X's | ||
9 | */ | ||
10 | |||
11 | #include <sys/types.h> | ||
12 | #include <sys/mman.h> | ||
13 | #include <sys/stat.h> | ||
14 | |||
15 | #include <err.h> | ||
16 | #include <errno.h> | ||
17 | #include <stdio.h> | ||
18 | #include <stdlib.h> | ||
19 | #include <string.h> | ||
20 | #include <limits.h> | ||
21 | #include <unistd.h> | ||
22 | |||
23 | #define MAX_TEMPLATE_LEN 10 | ||
24 | #define MAX_TRIES 100 | ||
25 | #define MIN_Xs 6 | ||
26 | |||
27 | #define SUFFIX ".suff" | ||
28 | #define SLEN (sizeof SUFFIX - 1) | ||
29 | |||
30 | long pg; | ||
31 | |||
32 | /* | ||
33 | * verify that a path generated by mkstemp() or mkstemp() looks like a | ||
34 | * reasonable expansion of the template and matches the fd. Returns true | ||
35 | * if all the X's were replaced with non-X's | ||
36 | */ | ||
37 | int | ||
38 | check(int fd, char const *path, char const *prefix, size_t plen, | ||
39 | char const *suffix, size_t slen, int tlen) | ||
40 | { | ||
41 | struct stat sb, fsb; | ||
42 | char const *p; | ||
43 | |||
44 | if (tlen < MIN_Xs) { | ||
45 | if (fd >= 0) | ||
46 | errx(1, "mkstemp(%s) succeed with too few Xs", path); | ||
47 | if (errno != EINVAL) | ||
48 | err(1, "mkstemp(%s) failed with wrong errno", path); | ||
49 | return 1; | ||
50 | } | ||
51 | if (fd < 0) | ||
52 | err(1, "mkstemp(%s)", path); | ||
53 | if (stat(path, &sb)) | ||
54 | err(1, "stat(%s)", path); | ||
55 | if (fstat(fd, &fsb)) | ||
56 | err(1, "fstat(%d==%s)", fd, path); | ||
57 | if (sb.st_dev != fsb.st_dev || sb.st_ino != fsb.st_ino) | ||
58 | errx(1, "stat mismatch"); | ||
59 | close(fd); | ||
60 | if (memcmp(path, prefix, plen) != 0) | ||
61 | errx(1, "prefix changed! %s vs %s", prefix, path); | ||
62 | if (memcmp(path + plen + tlen, suffix, slen + 1) != 0) | ||
63 | errx(1, "suffix changed! %s vs %s", suffix, path); | ||
64 | for (p = path + plen; p < path + plen + tlen; p++) | ||
65 | if (*p == '\0') | ||
66 | errx(1, "unexpected truncation"); | ||
67 | else if (*p == 'X') | ||
68 | return 0; | ||
69 | return 1; | ||
70 | } | ||
71 | |||
72 | |||
73 | void | ||
74 | try_mkstemp(char *p, char const *prefix, int len) | ||
75 | { | ||
76 | char *q; | ||
77 | size_t plen = strlen(prefix); | ||
78 | int tries, fd; | ||
79 | |||
80 | for (tries = 0; tries < MAX_TRIES; tries++) { | ||
81 | memcpy(p, prefix, plen); | ||
82 | memset(p + plen, 'X', len); | ||
83 | p[plen + len] = '\0'; | ||
84 | fd = mkstemp(p); | ||
85 | if (check(fd, p, prefix, plen, "", 0, len)) | ||
86 | return; | ||
87 | } | ||
88 | errx(1, "exceeded MAX_TRIES"); | ||
89 | } | ||
90 | |||
91 | void | ||
92 | try_mkstemps(char *p, char const *prefix, int len, char const *suffix) | ||
93 | { | ||
94 | char *q; | ||
95 | size_t plen = strlen(prefix); | ||
96 | size_t slen = strlen(suffix); | ||
97 | int tries, fd; | ||
98 | |||
99 | for (tries = 0; tries < MAX_TRIES; tries++) { | ||
100 | memcpy(p, prefix, plen); | ||
101 | memset(p + plen, 'X', len); | ||
102 | memcpy(p + plen + len, suffix, slen + 1); | ||
103 | fd = mkstemps(p, slen); | ||
104 | if (check(fd, p, prefix, plen, suffix, slen, len)) | ||
105 | return; | ||
106 | } | ||
107 | errx(1, "exceeded MAX_TRIES"); | ||
108 | } | ||
109 | |||
110 | int | ||
111 | main(void) | ||
112 | { | ||
113 | struct stat sb, fsb; | ||
114 | char cwd[PATH_MAX + 1]; | ||
115 | char *p; | ||
116 | size_t clen; | ||
117 | int i; | ||
118 | |||
119 | pg = sysconf(_SC_PAGESIZE); | ||
120 | if (getcwd(cwd, sizeof cwd - 1) == NULL) | ||
121 | err(1, "getcwd"); | ||
122 | clen = strlen(cwd); | ||
123 | cwd[clen++] = '/'; | ||
124 | cwd[clen] = '\0'; | ||
125 | p = mmap(NULL, pg * 3, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); | ||
126 | if (p == MAP_FAILED) | ||
127 | err(1, "mmap"); | ||
128 | if (mprotect(p, pg, PROT_NONE) || mprotect(p + pg * 2, pg, PROT_NONE)) | ||
129 | err(1, "mprotect"); | ||
130 | p += pg; | ||
131 | |||
132 | i = MAX_TEMPLATE_LEN + 1; | ||
133 | while (i-- > 0) { | ||
134 | /* try first at the start of a page, no prefix */ | ||
135 | try_mkstemp(p, "", i); | ||
136 | /* now at the end of the page, no prefix */ | ||
137 | try_mkstemp(p + pg - i - 1, "", i); | ||
138 | /* start of the page, prefixed with the cwd */ | ||
139 | try_mkstemp(p, cwd, i); | ||
140 | /* how about at the end of the page, prefixed with cwd? */ | ||
141 | try_mkstemp(p + pg - clen - i - 1, cwd, i); | ||
142 | |||
143 | /* again, with mkstemps() and an empty suffix */ | ||
144 | /* try first at the start of a page, no prefix */ | ||
145 | try_mkstemps(p, "", i, ""); | ||
146 | /* now at the end of the page, no prefix */ | ||
147 | try_mkstemps(p + pg - i - 1, "", i, ""); | ||
148 | /* start of the page, prefixed with the cwd */ | ||
149 | try_mkstemps(p, cwd, i, ""); | ||
150 | /* how about at the end of the page, prefixed with cwd? */ | ||
151 | try_mkstemps(p + pg - clen - i - 1, cwd, i, ""); | ||
152 | |||
153 | /* mkstemps() and a non-empty suffix */ | ||
154 | /* try first at the start of a page, no prefix */ | ||
155 | try_mkstemps(p, "", i, SUFFIX); | ||
156 | /* now at the end of the page, no prefix */ | ||
157 | try_mkstemps(p + pg - i - SLEN - 1, "", i, SUFFIX); | ||
158 | /* start of the page, prefixed with the cwd */ | ||
159 | try_mkstemps(p, cwd, i, SUFFIX); | ||
160 | /* how about at the end of the page, prefixed with cwd? */ | ||
161 | try_mkstemps(p + pg - clen - i - SLEN - 1, cwd, i, SUFFIX); | ||
162 | |||
163 | } | ||
164 | |||
165 | return 0; | ||
166 | } | ||
diff --git a/src/regress/lib/libc/modf/Makefile b/src/regress/lib/libc/modf/Makefile deleted file mode 100644 index 587c595f12..0000000000 --- a/src/regress/lib/libc/modf/Makefile +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | PROG=modf_test | ||
2 | |||
3 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/modf/modf_test.c b/src/regress/lib/libc/modf/modf_test.c deleted file mode 100644 index b96618e1f0..0000000000 --- a/src/regress/lib/libc/modf/modf_test.c +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | /* $OpenBSD: modf_test.c,v 1.2 2023/08/13 06:57:04 miod Exp $ */ | ||
2 | |||
3 | #include <assert.h> | ||
4 | #include <math.h> | ||
5 | |||
6 | /* Test for bug introduced in 4.4BSD modf() on sparc */ | ||
7 | /* Public domain, 2014, Tobias Ulmer <tobiasu@tmux.org> */ | ||
8 | |||
9 | #define BIGFLOAT (5e15) /* Number large enough to trigger the "big" case */ | ||
10 | |||
11 | void | ||
12 | modf_sparc(void) | ||
13 | { | ||
14 | double f, i; | ||
15 | |||
16 | f = modf(BIGFLOAT, &i); | ||
17 | assert(i == BIGFLOAT); | ||
18 | assert(f == 0.0); | ||
19 | |||
20 | /* Repeat, maybe we were lucky */ | ||
21 | f = modf(BIGFLOAT, &i); | ||
22 | assert(i == BIGFLOAT); | ||
23 | assert(f == 0.0); | ||
24 | |||
25 | /* With negative number, for good measure */ | ||
26 | f = modf(-BIGFLOAT, &i); | ||
27 | assert(i == -BIGFLOAT); | ||
28 | assert(f == 0.0); | ||
29 | } | ||
30 | |||
31 | /* Test for modf() behaviour on Inf and Nan */ | ||
32 | /* Written by Willemijn Coene. Public domain */ | ||
33 | |||
34 | void | ||
35 | modf_infnan(void) | ||
36 | { | ||
37 | double f, i; | ||
38 | |||
39 | f = modf(__builtin_inf(), &i); | ||
40 | assert(isinf(i)); | ||
41 | assert(signbit(i) == 0); | ||
42 | assert(f == 0.0); | ||
43 | |||
44 | f = modf(-__builtin_inf(), &i); | ||
45 | assert(isinf(i)); | ||
46 | assert(signbit(i) != 0); | ||
47 | assert(f == -0.0); | ||
48 | |||
49 | f = modf(NAN, &i); | ||
50 | assert(isnan(i)); | ||
51 | assert(signbit(i) == 0); | ||
52 | assert(isnan(f)); | ||
53 | assert(signbit(f) == 0); | ||
54 | |||
55 | f = modf(-NAN, &i); | ||
56 | assert(isnan(i)); | ||
57 | assert(signbit(i) != 0); | ||
58 | assert(isnan(f)); | ||
59 | assert(signbit(f) != 0); | ||
60 | } | ||
61 | |||
62 | int | ||
63 | main(void) | ||
64 | { | ||
65 | modf_sparc(); | ||
66 | modf_infnan(); | ||
67 | } | ||
diff --git a/src/regress/lib/libc/netdb/Makefile b/src/regress/lib/libc/netdb/Makefile deleted file mode 100644 index 8254607227..0000000000 --- a/src/regress/lib/libc/netdb/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2004/10/25 15:10:36 otto Exp $ | ||
2 | |||
3 | PROG= netdb | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/netdb/netdb.c b/src/regress/lib/libc/netdb/netdb.c deleted file mode 100644 index fabb3ee4e1..0000000000 --- a/src/regress/lib/libc/netdb/netdb.c +++ /dev/null | |||
@@ -1,183 +0,0 @@ | |||
1 | /* $OpenBSD: netdb.c,v 1.2 2011/05/01 04:27:07 guenther Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Public domain, 2004, Otto Moerbeek <otto@drijf.net> | ||
5 | */ | ||
6 | |||
7 | #include <err.h> | ||
8 | #include <netdb.h> | ||
9 | #include <stdarg.h> | ||
10 | #include <string.h> | ||
11 | |||
12 | int ret = 0; | ||
13 | |||
14 | void | ||
15 | checkp(int n, struct protoent *p, int proto, const char *name, ...) | ||
16 | { | ||
17 | va_list va; | ||
18 | char *a; | ||
19 | int i; | ||
20 | |||
21 | if (p == NULL) { | ||
22 | warnx("%d proto struct is NULL", n); | ||
23 | ret = 1; | ||
24 | return; | ||
25 | } | ||
26 | if (p->p_proto != proto) { | ||
27 | warnx("%d proto num mismatch %d %d", n, p->p_proto, proto); | ||
28 | ret = 1; | ||
29 | } | ||
30 | if (strcmp(p->p_name, name) != 0) { | ||
31 | warnx("%d proto name mismatch %s %s", n, p->p_name, name); | ||
32 | ret = 1; | ||
33 | } | ||
34 | va_start(va, name); | ||
35 | a = va_arg(va, char *); | ||
36 | i = 0; | ||
37 | while (a != NULL) { | ||
38 | if (strcmp(p->p_aliases[i], a) != 0) { | ||
39 | warnx("%d proto alias mismatch %s %s", n, | ||
40 | p->p_aliases[i], a); | ||
41 | ret = 1; | ||
42 | } | ||
43 | i++; | ||
44 | a = va_arg(va, char *); | ||
45 | } | ||
46 | if (p->p_aliases[i] != NULL) { | ||
47 | warnx("%d proto alias list does not end with NULL", n); | ||
48 | ret = 1; | ||
49 | } | ||
50 | va_end(va); | ||
51 | } | ||
52 | |||
53 | |||
54 | void | ||
55 | checks(int n, struct servent *s, int port, const char *proto, | ||
56 | const char *name, ...) | ||
57 | { | ||
58 | va_list va; | ||
59 | char *a; | ||
60 | int i; | ||
61 | |||
62 | if (s == NULL) { | ||
63 | warnx("%d serv struct is NULL", n); | ||
64 | ret = 1; | ||
65 | return; | ||
66 | } | ||
67 | if (s->s_port != ntohs(port)) { | ||
68 | warnx("%d port num mismatch %d %d", n, s->s_port, port); | ||
69 | ret = 1; | ||
70 | } | ||
71 | if (strcmp(s->s_name, name) != 0) { | ||
72 | warnx("%d serv name mismatch %s %s", n, s->s_name, name); | ||
73 | ret = 1; | ||
74 | } | ||
75 | if (strcmp(s->s_proto, proto) != 0) { | ||
76 | warnx("%d serv proto mismatch %s %s", n, s->s_proto, proto); | ||
77 | ret = 1; | ||
78 | } | ||
79 | va_start(va, name); | ||
80 | a = va_arg(va, char *); | ||
81 | i = 0; | ||
82 | while (a != NULL) { | ||
83 | if (strcmp(s->s_aliases[i], a) != 0) { | ||
84 | warnx("%d serv alias mismatch %s %s", n, | ||
85 | s->s_aliases[i], a); | ||
86 | ret = 1; | ||
87 | } | ||
88 | i++; | ||
89 | a = va_arg(va, char *); | ||
90 | } | ||
91 | if (s->s_aliases[i] != NULL) { | ||
92 | warnx("%d serv alias list does not end with NULL", n); | ||
93 | ret = 1; | ||
94 | } | ||
95 | va_end(va); | ||
96 | } | ||
97 | |||
98 | int | ||
99 | main() | ||
100 | { | ||
101 | struct protoent *p; | ||
102 | struct protoent protoent; | ||
103 | struct protoent_data protoent_data; | ||
104 | struct servent *s; | ||
105 | struct servent servent; | ||
106 | struct servent_data servent_data; | ||
107 | int r; | ||
108 | |||
109 | p = getprotobynumber(35); | ||
110 | checkp(1, p, 35, "idpr", "IDPR", (char *)NULL); | ||
111 | |||
112 | p = getprotobyname("igp"); | ||
113 | checkp(2, p, 9, "igp", "IGP", (char *) NULL); | ||
114 | |||
115 | p = getprotobyname("RDP"); | ||
116 | checkp(3, p, 27, "rdp", "RDP", (char *) NULL); | ||
117 | |||
118 | p = getprotobyname("vrrp"); | ||
119 | checkp(4, p, 112, "carp", "CARP", "vrrp", (char *) NULL); | ||
120 | |||
121 | p = getprotobyname("nonexistent"); | ||
122 | if (p != NULL) | ||
123 | err(1, "nonexistent proto found"); | ||
124 | |||
125 | memset(&protoent_data, 0, sizeof(protoent_data)); | ||
126 | r = getprotobynumber_r(35, &protoent, &protoent_data); | ||
127 | if (r != 0) | ||
128 | err(1, "proto not found"); | ||
129 | |||
130 | checkp(5, &protoent, 35, "idpr", "IDPR", (char *)NULL); | ||
131 | |||
132 | r = getprotobyname_r("vrrp", &protoent, &protoent_data); | ||
133 | if (r != 0) | ||
134 | err(1, "proto not found"); | ||
135 | checkp(6, &protoent, 112, "carp", "CARP", "vrrp", (char *) NULL); | ||
136 | |||
137 | r = getprotobyname_r("nonexistent", &protoent, &protoent_data); | ||
138 | if (r != -1) | ||
139 | err(1, "nonexistent proto found"); | ||
140 | |||
141 | r = getprotobyname_r("", &protoent, &protoent_data); | ||
142 | if (r != -1) | ||
143 | err(1, "nonexistent proto found"); | ||
144 | |||
145 | |||
146 | r = getprotobynumber_r(256, &protoent, &protoent_data); | ||
147 | if (r != -1) | ||
148 | err(1, "nonexistent proto found"); | ||
149 | |||
150 | s = getservbyname("zip", NULL); | ||
151 | checks(7, s, 6, "ddp", "zip", (char *)NULL); | ||
152 | |||
153 | s = getservbyname("nicname", "tcp"); | ||
154 | checks(8, s, 43, "tcp", "whois", "nicname", (char *)NULL); | ||
155 | |||
156 | s = getservbyport(htons(42), "tcp"); | ||
157 | checks(9, s, 42, "tcp", "nameserver", "name", (char *)NULL); | ||
158 | |||
159 | memset(&servent_data, 0, sizeof(servent_data)); | ||
160 | r = getservbyname_r("zip", "ddp", &servent, &servent_data); | ||
161 | if (r != 0) | ||
162 | err(1, "servent not found"); | ||
163 | checks(10, &servent, 6, "ddp", "zip", (char *)NULL); | ||
164 | |||
165 | r = getservbyport_r(htons(520), NULL, &servent, &servent_data); | ||
166 | if (r != 0) | ||
167 | err(1, "servent not found"); | ||
168 | checks(11, &servent, 520, "udp", "route", "router", "routed", (char *)NULL); | ||
169 | |||
170 | r = getservbyname_r("nonexistent", NULL, &servent, &servent_data); | ||
171 | if (r != -1) | ||
172 | err(1, "nonexiststent servent found"); | ||
173 | |||
174 | r = getservbyport_r(htons(50000), NULL, &servent, &servent_data); | ||
175 | if (r != -1) | ||
176 | err(1, "nonexistent servent found"); | ||
177 | |||
178 | r = getservbyport_r(htons(520), "tcp", &servent, &servent_data); | ||
179 | if (r != -1) | ||
180 | err(1, "nonexistent servent found"); | ||
181 | |||
182 | return ret; | ||
183 | } | ||
diff --git a/src/regress/lib/libc/open_memstream/Makefile b/src/regress/lib/libc/open_memstream/Makefile deleted file mode 100644 index ab7d194232..0000000000 --- a/src/regress/lib/libc/open_memstream/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2013/06/02 15:33:53 dtucker Exp $ | ||
2 | |||
3 | PROG= open_memstreamtest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/open_memstream/open_memstreamtest.c b/src/regress/lib/libc/open_memstream/open_memstreamtest.c deleted file mode 100644 index e8da0e03b2..0000000000 --- a/src/regress/lib/libc/open_memstream/open_memstreamtest.c +++ /dev/null | |||
@@ -1,186 +0,0 @@ | |||
1 | /* $OpenBSD: open_memstreamtest.c,v 1.6 2019/05/13 02:54:54 bluhm Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <err.h> | ||
20 | #include <stdio.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | #include <unistd.h> | ||
24 | |||
25 | #define OFFSET 16384 | ||
26 | |||
27 | const char start[] = "start"; | ||
28 | const char hello[] = "hello"; | ||
29 | |||
30 | int | ||
31 | main(void) | ||
32 | { | ||
33 | FILE *fp; | ||
34 | char *buf = (char *)0xff; | ||
35 | size_t size = 0; | ||
36 | off_t off; | ||
37 | int i, failures = 0; | ||
38 | |||
39 | if ((fp = open_memstream(&buf, &size)) == NULL) { | ||
40 | warn("open_memstream failed"); | ||
41 | return (1); | ||
42 | } | ||
43 | |||
44 | off = ftello(fp); | ||
45 | if (off != 0) { | ||
46 | warnx("ftello failed. (1)"); | ||
47 | failures++; | ||
48 | } | ||
49 | |||
50 | if (fflush(fp) != 0) { | ||
51 | warnx("fflush failed. (2)"); | ||
52 | failures++; | ||
53 | } | ||
54 | |||
55 | if (size != 0) { | ||
56 | warnx("string should be empty. (3)"); | ||
57 | failures++; | ||
58 | } | ||
59 | |||
60 | if (buf == (char *)0xff) { | ||
61 | warnx("buf not updated. (4)"); | ||
62 | failures++; | ||
63 | } | ||
64 | |||
65 | if (fseek(fp, OFFSET, SEEK_SET) != 0) { | ||
66 | warnx("failed to fseek. (5)"); | ||
67 | failures++; | ||
68 | } | ||
69 | |||
70 | if (fprintf(fp, hello) == EOF) { | ||
71 | warnx("fprintf failed. (6)"); | ||
72 | failures++; | ||
73 | } | ||
74 | |||
75 | if (fflush(fp) == EOF) { | ||
76 | warnx("fflush failed. (7)"); | ||
77 | failures++; | ||
78 | } | ||
79 | |||
80 | if (size != OFFSET + sizeof(hello)-1) { | ||
81 | warnx("failed, size %zu should be %zu. (8)", | ||
82 | size, OFFSET + sizeof(hello)-1); | ||
83 | failures++; | ||
84 | } | ||
85 | |||
86 | if (fseek(fp, 0, SEEK_SET) != 0) { | ||
87 | warnx("failed to fseek. (9)"); | ||
88 | failures++; | ||
89 | } | ||
90 | |||
91 | if (fprintf(fp, start) == EOF) { | ||
92 | warnx("fprintf failed. (10)"); | ||
93 | failures++; | ||
94 | } | ||
95 | |||
96 | if (fflush(fp) == EOF) { | ||
97 | warnx("fflush failed. (11)"); | ||
98 | failures++; | ||
99 | } | ||
100 | |||
101 | if (size != sizeof(start)-1) { | ||
102 | warnx("failed, size %zu should be %zu. (12)", | ||
103 | size, sizeof(start)-1); | ||
104 | failures++; | ||
105 | } | ||
106 | |||
107 | /* Needed for sparse files */ | ||
108 | if (strncmp(buf, start, sizeof(start)-1) != 0) { | ||
109 | warnx("failed, buffer didn't start with '%s'. (13)", start); | ||
110 | failures++; | ||
111 | } | ||
112 | for (i = sizeof(start)-1; i < OFFSET; i++) | ||
113 | if (buf[i] != '\0') { | ||
114 | warnx("failed, buffer non zero (offset %d). (14)", i); | ||
115 | failures++; | ||
116 | break; | ||
117 | } | ||
118 | |||
119 | if (memcmp(buf + OFFSET, hello, sizeof(hello)-1) != 0) { | ||
120 | warnx("written string incorrect. (15)"); | ||
121 | failures++; | ||
122 | } | ||
123 | |||
124 | /* verify that simply seeking past the end doesn't increase the size */ | ||
125 | if (fseek(fp, 100, SEEK_END) != 0) { | ||
126 | warnx("failed to fseek. (16)"); | ||
127 | failures++; | ||
128 | } | ||
129 | |||
130 | if (fflush(fp) == EOF) { | ||
131 | warnx("fflush failed. (17)"); | ||
132 | failures++; | ||
133 | } | ||
134 | |||
135 | if (size != OFFSET + sizeof(hello)-1) { | ||
136 | warnx("failed, size %zu should be %zu. (18)", | ||
137 | size, OFFSET + sizeof(hello)-1); | ||
138 | failures++; | ||
139 | } | ||
140 | |||
141 | if (fseek(fp, -1, SEEK_END) != 0) { | ||
142 | warnx("failed to fseek. (19)"); | ||
143 | failures++; | ||
144 | } | ||
145 | |||
146 | if (fseek(fp, 8, SEEK_SET) != 0) { | ||
147 | warnx("failed to fseek. (20)"); | ||
148 | failures++; | ||
149 | } | ||
150 | |||
151 | if (ftell(fp) != 8) { | ||
152 | warnx("failed seek test. (21)"); | ||
153 | failures++; | ||
154 | } | ||
155 | |||
156 | /* Try to seek backward */ | ||
157 | if (fseek(fp, -1, SEEK_CUR) != 0) { | ||
158 | warnx("failed to fseek. (22)"); | ||
159 | failures++; | ||
160 | } | ||
161 | |||
162 | if (ftell(fp) != 7) { | ||
163 | warnx("failed seeking backward. (23)"); | ||
164 | failures++; | ||
165 | } | ||
166 | |||
167 | if (fseek(fp, 5, SEEK_CUR) != 0) { | ||
168 | warnx("failed to fseek. (24)"); | ||
169 | failures++; | ||
170 | } | ||
171 | |||
172 | if (fclose(fp) == EOF) { | ||
173 | warnx("fclose failed. (25)"); | ||
174 | failures++; | ||
175 | } | ||
176 | |||
177 | if (size != 12) { | ||
178 | warnx("failed, size %zu should be %u. (26)", | ||
179 | size, 12); | ||
180 | failures++; | ||
181 | } | ||
182 | |||
183 | free(buf); | ||
184 | |||
185 | return (failures); | ||
186 | } | ||
diff --git a/src/regress/lib/libc/orientation/Makefile b/src/regress/lib/libc/orientation/Makefile deleted file mode 100644 index 5c73702abe..0000000000 --- a/src/regress/lib/libc/orientation/Makefile +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2010/06/29 16:20:28 guenther Exp $ | ||
2 | |||
3 | NOMAN= | ||
4 | PROG=orientation_test | ||
5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
6 | |||
7 | run-regress-${PROG}: ${PROG} | ||
8 | ./${PROG} | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/orientation/orientation_test.c b/src/regress/lib/libc/orientation/orientation_test.c deleted file mode 100644 index 4d713f80bf..0000000000 --- a/src/regress/lib/libc/orientation/orientation_test.c +++ /dev/null | |||
@@ -1,264 +0,0 @@ | |||
1 | /* $OpenBSD: orientation_test.c,v 1.5 2014/04/22 02:29:52 lteo Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2009 Philip Guenther | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * | ||
11 | * - Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * - Redistributions in binary form must reproduce the above | ||
14 | * copyright notice, this list of conditions and the following | ||
15 | * disclaimer in the documentation and/or other materials provided | ||
16 | * with the distribution. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
29 | * POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | /* | ||
33 | * Test whether the various stdio functions set the stream orientation | ||
34 | * ("width") as they should | ||
35 | */ | ||
36 | |||
37 | #include <sys/types.h> | ||
38 | #include <err.h> | ||
39 | #include <stddef.h> | ||
40 | #include <stdio.h> | ||
41 | #include <stdlib.h> | ||
42 | #include <string.h> | ||
43 | #include <unistd.h> | ||
44 | #include <wchar.h> | ||
45 | |||
46 | char filename[] = "/tmp/fwide.XXXXXXXXXX"; | ||
47 | |||
48 | FILE *dup_stdout = NULL; | ||
49 | int failures = 0; | ||
50 | |||
51 | void | ||
52 | fail(int line, int r, char const *expect, char const *test) | ||
53 | { | ||
54 | failures++; | ||
55 | fprintf(dup_stdout, | ||
56 | "FAIL: %d: fwide returned %d, expected %s 0 after %s\n", | ||
57 | line, r, expect, test); | ||
58 | } | ||
59 | |||
60 | FILE * | ||
61 | setup(int line) | ||
62 | { | ||
63 | FILE *f; | ||
64 | int r; | ||
65 | |||
66 | if ((f = fopen(filename, "r+")) == NULL) | ||
67 | err(2, "fopen"); | ||
68 | if ((r = fwide(f, 0)) != 0) | ||
69 | fail(line, r, "==", "fopen"); | ||
70 | return (f); | ||
71 | } | ||
72 | |||
73 | FILE * | ||
74 | setup_std(FILE *std, int line) | ||
75 | { | ||
76 | int r; | ||
77 | |||
78 | if (freopen(filename, "r+", std) == NULL) | ||
79 | err(2, "freopen"); | ||
80 | if ((r = fwide(std, 0)) != 0) | ||
81 | fail(line, r, "==", "freopen"); | ||
82 | return (std); | ||
83 | } | ||
84 | |||
85 | #define TEST_(x, op) \ | ||
86 | do { \ | ||
87 | f = setup(__LINE__); \ | ||
88 | x; \ | ||
89 | if (!((r = fwide(f, 0)) op 0)) \ | ||
90 | fail(__LINE__, r, #op, #x); \ | ||
91 | fclose(f); \ | ||
92 | } while (0) | ||
93 | |||
94 | #define TEST_STD_(std, x, op) \ | ||
95 | do { \ | ||
96 | f = setup_std(std, __LINE__); \ | ||
97 | x; \ | ||
98 | if (!((r = fwide(f, 0)) op 0)) \ | ||
99 | fail(__LINE__, r, #op, #x); \ | ||
100 | } while (0) | ||
101 | |||
102 | #define TEST_UNCHANGED(x) TEST_(x, ==) | ||
103 | #define TEST_NARROW(x) TEST_(x, <) | ||
104 | #define TEST_WIDE(x) TEST_(x, >) | ||
105 | #define TEST_UNCHANGED_STD(std, x) TEST_STD_(std, x, ==) | ||
106 | #define TEST_NARROW_STD(std, x) TEST_STD_(std, x, <) | ||
107 | #define TEST_WIDE_STD(std, x) TEST_STD_(std, x, >) | ||
108 | |||
109 | int | ||
110 | main(int argc, char *argv[]) | ||
111 | { | ||
112 | char buffer[BUFSIZ]; | ||
113 | wchar_t wbuffer[BUFSIZ]; | ||
114 | char *buf; | ||
115 | wchar_t *wbuf; | ||
116 | FILE *f; | ||
117 | off_t off; | ||
118 | fpos_t pos; | ||
119 | size_t size; | ||
120 | int fd, r; | ||
121 | char c; | ||
122 | wchar_t wc; | ||
123 | |||
124 | if ((fd = dup(1)) == -1) | ||
125 | err(2, "dup"); | ||
126 | if ((dup_stdout = fdopen(fd, "w")) == NULL) | ||
127 | err(2, "fdopen"); | ||
128 | if ((fd = mkstemp(filename)) == -1) | ||
129 | err(2, "mkstemp"); | ||
130 | if (write(fd, "0123456789\n\n", 12) != 12 || close(fd)) | ||
131 | err(2, "write + close"); | ||
132 | |||
133 | /* status */ | ||
134 | TEST_UNCHANGED(fwide(f, 0)); | ||
135 | TEST_NARROW(fwide(f, -1)); | ||
136 | TEST_WIDE(fwide(f, 1)); | ||
137 | TEST_UNCHANGED(feof(f)); | ||
138 | TEST_UNCHANGED(ferror(f)); | ||
139 | TEST_UNCHANGED(fileno(f)); | ||
140 | TEST_UNCHANGED(clearerr(f)); | ||
141 | |||
142 | /* flush and purge */ | ||
143 | TEST_UNCHANGED(fflush(f)); | ||
144 | TEST_UNCHANGED(fpurge(f)); | ||
145 | |||
146 | /* positioning */ | ||
147 | TEST_UNCHANGED(fgetpos(f, &pos)); | ||
148 | TEST_UNCHANGED(fgetpos(f, &pos); fsetpos(f, &pos)); | ||
149 | TEST_UNCHANGED(ftell(f)); | ||
150 | TEST_UNCHANGED(ftello(f)); | ||
151 | TEST_UNCHANGED(fseek(f, 1, SEEK_CUR)); | ||
152 | TEST_UNCHANGED(fseek(f, 1, SEEK_SET)); | ||
153 | TEST_UNCHANGED(fseek(f, 1, SEEK_END)); | ||
154 | TEST_UNCHANGED(fseeko(f, 1, SEEK_CUR)); | ||
155 | TEST_UNCHANGED(fseeko(f, 1, SEEK_SET)); | ||
156 | TEST_UNCHANGED(fseeko(f, 1, SEEK_END)); | ||
157 | TEST_UNCHANGED(rewind(f)); | ||
158 | |||
159 | /* buffering */ | ||
160 | TEST_UNCHANGED(setbuf(f, NULL)); | ||
161 | TEST_UNCHANGED(setbuf(f, buffer)); | ||
162 | TEST_UNCHANGED(setvbuf(f, buffer, _IONBF, BUFSIZ)); | ||
163 | TEST_UNCHANGED(setvbuf(f, buffer, _IOLBF, BUFSIZ)); | ||
164 | TEST_UNCHANGED(setvbuf(f, buffer, _IOFBF, BUFSIZ)); | ||
165 | TEST_UNCHANGED(setvbuf(f, NULL, _IONBF, 0)); | ||
166 | TEST_UNCHANGED(setvbuf(f, NULL, _IOLBF, 0)); | ||
167 | TEST_UNCHANGED(setvbuf(f, NULL, _IOFBF, 0)); | ||
168 | TEST_UNCHANGED(setbuffer(f, NULL, 0)); | ||
169 | TEST_UNCHANGED(setbuffer(f, buffer, BUFSIZ)); | ||
170 | TEST_UNCHANGED(setlinebuf(f)); | ||
171 | |||
172 | /* locking */ | ||
173 | TEST_UNCHANGED(flockfile(f);funlockfile(f)); | ||
174 | TEST_UNCHANGED(ftrylockfile(f);funlockfile(f)); | ||
175 | |||
176 | /* input */ | ||
177 | TEST_NARROW(getc(f)); | ||
178 | TEST_NARROW(getc_unlocked(f)); | ||
179 | TEST_NARROW(fgetc(f)); | ||
180 | TEST_NARROW(c = fgetc(f); ungetc(c, f)); | ||
181 | TEST_NARROW(fgets(buffer, BUFSIZ, f)); | ||
182 | TEST_NARROW(fscanf(f, "%s\n", buffer)); | ||
183 | TEST_NARROW(fgetln(f, &size)); | ||
184 | |||
185 | /* output */ | ||
186 | TEST_NARROW(putc('c', f)); | ||
187 | TEST_NARROW(putc_unlocked('c', f)); | ||
188 | TEST_NARROW(fputc('c', f)); | ||
189 | TEST_NARROW(fputs("foo", f)); | ||
190 | TEST_NARROW(fprintf(f, "%s\n", "foo")); | ||
191 | |||
192 | /* input from stdin */ | ||
193 | TEST_NARROW_STD(stdin, getchar()); | ||
194 | TEST_NARROW_STD(stdin, getchar_unlocked()); | ||
195 | TEST_NARROW_STD(stdin, scanf("%s\n", buffer)); | ||
196 | |||
197 | /* output to stdout */ | ||
198 | TEST_NARROW_STD(stdout, putchar('c')); | ||
199 | TEST_NARROW_STD(stdout, putchar_unlocked('c')); | ||
200 | TEST_NARROW_STD(stdout, puts("foo")); | ||
201 | TEST_NARROW_STD(stdout, printf("foo")); | ||
202 | |||
203 | /* word-size ops */ | ||
204 | /* | ||
205 | * fread and fwrite are specified as being implemented in | ||
206 | * terms of fgetc() and fputc() and therefore must set the | ||
207 | * stream orientation to narrow. | ||
208 | */ | ||
209 | TEST_NARROW(fread(buffer, 4, BUFSIZ / 4, f)); | ||
210 | TEST_NARROW(fwrite(buffer, 4, BUFSIZ / 4, f)); | ||
211 | |||
212 | /* | ||
213 | * getw() and putw() aren't specified anywhere but logically | ||
214 | * should behave the same as fread/fwrite. Not all OSes agree: | ||
215 | * Solaris 10 has them not changing the orientation. | ||
216 | */ | ||
217 | TEST_NARROW(getw(f)); | ||
218 | TEST_NARROW(putw(1234, f)); | ||
219 | |||
220 | |||
221 | /* WIDE CHAR TIME! */ | ||
222 | |||
223 | /* input */ | ||
224 | TEST_WIDE(getwc(f)); | ||
225 | TEST_WIDE(fgetwc(f)); | ||
226 | TEST_WIDE(wc = fgetwc(f); ungetwc(wc, f)); | ||
227 | TEST_WIDE(fgetws(wbuffer, BUFSIZ, f)); | ||
228 | TEST_WIDE(fwscanf(f, L"%s\n", wbuffer)); | ||
229 | |||
230 | /* output */ | ||
231 | TEST_WIDE(putwc(L'c', f)); | ||
232 | TEST_WIDE(fputwc(L'c', f)); | ||
233 | TEST_WIDE(fputws(L"foo", f)); | ||
234 | TEST_WIDE(fwprintf(f, L"%s\n", L"foo")); | ||
235 | |||
236 | /* input from stdin */ | ||
237 | TEST_WIDE_STD(stdin, getwchar()); | ||
238 | TEST_WIDE_STD(stdin, wscanf(L"%s\n", wbuffer)); | ||
239 | |||
240 | /* output to stdout */ | ||
241 | TEST_WIDE_STD(stdout, putwchar(L'c')); | ||
242 | TEST_WIDE_STD(stdout, wprintf(L"foo")); | ||
243 | |||
244 | |||
245 | /* memory streams */ | ||
246 | f = open_memstream(&buf, &size); | ||
247 | if (!((r = fwide(f, 0)) < 0)) | ||
248 | fail(__LINE__, r, "<", "open_memstream()"); | ||
249 | fclose(f); | ||
250 | f = open_wmemstream(&wbuf, &size); | ||
251 | if (!((r = fwide(f, 0)) > 0)) | ||
252 | fail(__LINE__, r, ">", "open_wmemstream()"); | ||
253 | fclose(f); | ||
254 | |||
255 | |||
256 | /* random stuff? */ | ||
257 | TEST_UNCHANGED_STD(stderr, perror("foo")); | ||
258 | |||
259 | remove(filename); | ||
260 | if (failures) | ||
261 | exit(1); | ||
262 | exit(0); | ||
263 | } | ||
264 | |||
diff --git a/src/regress/lib/libc/popen/Makefile b/src/regress/lib/libc/popen/Makefile deleted file mode 100644 index 25b8668a7a..0000000000 --- a/src/regress/lib/libc/popen/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2002/02/16 01:55:09 art Exp $ | ||
2 | |||
3 | PROG=popen | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/popen/popen.c b/src/regress/lib/libc/popen/popen.c deleted file mode 100644 index 2e081de584..0000000000 --- a/src/regress/lib/libc/popen/popen.c +++ /dev/null | |||
@@ -1,98 +0,0 @@ | |||
1 | /* $NetBSD: popen.c,v 1.1 1999/09/30 09:23:23 tron Exp $ */ | ||
2 | |||
3 | /*- | ||
4 | * Copyright (c) 1999 The NetBSD Foundation, Inc. | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * This code is derived from software contributed to The NetBSD Foundation | ||
8 | * by Matthias Scheler. | ||
9 | * | ||
10 | * Redistribution and use in source and binary forms, with or without | ||
11 | * modification, are permitted provided that the following conditions | ||
12 | * are met: | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in the | ||
17 | * documentation and/or other materials provided with the distribution. | ||
18 | * | ||
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
29 | * POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | |||
33 | #include <err.h> | ||
34 | #include <errno.h> | ||
35 | #include <paths.h> | ||
36 | #include <stdio.h> | ||
37 | #include <stdlib.h> | ||
38 | #include <limits.h> | ||
39 | #include <time.h> | ||
40 | #include <unistd.h> | ||
41 | |||
42 | #define _PATH_CAT "/bin/cat" | ||
43 | #define BUFSIZE (640*1024) | ||
44 | /* 640KB ought to be enough for everyone. */ | ||
45 | #define DATAFILE "popen.data" | ||
46 | |||
47 | int | ||
48 | main(int argc, char **argv) | ||
49 | { | ||
50 | char *buffer, command[PATH_MAX]; | ||
51 | int index, in; | ||
52 | FILE *pipe; | ||
53 | |||
54 | if ((buffer = malloc(BUFSIZE*sizeof(char))) == NULL) | ||
55 | err(1, NULL); | ||
56 | |||
57 | for (index=0; index<BUFSIZE; index++) | ||
58 | buffer[index]=arc4random(); | ||
59 | |||
60 | (void)snprintf(command, sizeof(command), "%s >%s", | ||
61 | _PATH_CAT, DATAFILE); | ||
62 | if ((pipe = popen(command, "w")) == NULL) | ||
63 | err(1, "popen write"); | ||
64 | |||
65 | if (fwrite(buffer, sizeof(char), BUFSIZE, pipe) != BUFSIZE) | ||
66 | err(1, "write"); | ||
67 | |||
68 | if (pclose(pipe) == -1) | ||
69 | err(1, "pclose"); | ||
70 | |||
71 | (void)snprintf(command, sizeof(command), "%s %s", | ||
72 | _PATH_CAT, DATAFILE); | ||
73 | if ((pipe = popen(command, "r")) == NULL) | ||
74 | err(1, "popen read"); | ||
75 | |||
76 | index = 0; | ||
77 | while ((in = fgetc(pipe)) != EOF) | ||
78 | if (index == BUFSIZE) { | ||
79 | errno = EFBIG; | ||
80 | err(1, "read"); | ||
81 | } | ||
82 | else | ||
83 | if ((char)in != buffer[index++]) { | ||
84 | errno = EINVAL; | ||
85 | err(1, "read"); | ||
86 | } | ||
87 | |||
88 | if (index < BUFSIZE) { | ||
89 | errno = EIO; | ||
90 | err(1, "read"); | ||
91 | } | ||
92 | |||
93 | if (pclose(pipe) == -1) | ||
94 | err(1, "pclose"); | ||
95 | |||
96 | (void)unlink(DATAFILE); | ||
97 | return 0; | ||
98 | } | ||
diff --git a/src/regress/lib/libc/printf/Makefile b/src/regress/lib/libc/printf/Makefile deleted file mode 100644 index 5125fc64da..0000000000 --- a/src/regress/lib/libc/printf/Makefile +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2020/07/09 01:49:15 schwarze Exp $ | ||
2 | |||
3 | PROGS = fp int string | ||
4 | |||
5 | REGRESS_TARGETS = ${PROGS:S/^/run-regress-/} | ||
6 | |||
7 | .for p in ${PROGS} | ||
8 | run-regress-${p}: ${p} | ||
9 | ./${p} | ||
10 | .PHONY: run-regress-${p} | ||
11 | .endfor | ||
12 | |||
13 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/printf/fp.c b/src/regress/lib/libc/printf/fp.c deleted file mode 100644 index 299d05f55d..0000000000 --- a/src/regress/lib/libc/printf/fp.c +++ /dev/null | |||
@@ -1,225 +0,0 @@ | |||
1 | /* $OpenBSD: fp.c,v 1.2 2020/05/31 12:27:19 mortimer Exp $ */ | ||
2 | /*- | ||
3 | * Copyright (c) 2002, 2005 David Schultz <das@FreeBSD.org> | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * | ||
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
25 | * SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | /* | ||
29 | * Test for printf() floating point formats. | ||
30 | */ | ||
31 | |||
32 | #include <assert.h> | ||
33 | #include <err.h> | ||
34 | #include <float.h> | ||
35 | #include <math.h> | ||
36 | #include <stdio.h> | ||
37 | #include <stdarg.h> | ||
38 | #include <stdint.h> | ||
39 | #include <stdlib.h> | ||
40 | #include <string.h> | ||
41 | |||
42 | #define testfmt(result, fmt, ...) \ | ||
43 | _testfmt((result), __LINE__, #__VA_ARGS__, fmt, __VA_ARGS__) | ||
44 | void _testfmt(const char *, int, const char *, const char *, ...); | ||
45 | void smash_stack(void); | ||
46 | |||
47 | int | ||
48 | main(int argc, char *argv[]) | ||
49 | { | ||
50 | /* | ||
51 | * Basic tests of decimal output functionality. | ||
52 | */ | ||
53 | testfmt(" 1.000000E+00", "%13E", 1.0); | ||
54 | testfmt(" 1.000000", "%13f", 1.0); | ||
55 | testfmt(" 1", "%13G", 1.0); | ||
56 | testfmt(" 1.000000E+00", "%13LE", 1.0L); | ||
57 | testfmt(" 1.000000", "%13Lf", 1.0L); | ||
58 | testfmt(" 1", "%13LG", 1.0L); | ||
59 | |||
60 | testfmt("2.718282", "%.*f", -2, 2.7182818); | ||
61 | |||
62 | testfmt("1.234568e+06", "%e", 1234567.8); | ||
63 | testfmt("1234567.800000", "%f", 1234567.8); | ||
64 | testfmt("1.23457E+06", "%G", 1234567.8); | ||
65 | testfmt("1.234568e+06", "%Le", 1234567.8L); | ||
66 | testfmt("1234567.800000", "%Lf", 1234567.8L); | ||
67 | testfmt("1.23457E+06", "%LG", 1234567.8L); | ||
68 | |||
69 | #if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) | ||
70 | testfmt("123456789.864210", "%Lf", 123456789.8642097531L); | ||
71 | testfmt("-1.23457E+08", "%LG", -123456789.8642097531L); | ||
72 | testfmt("123456789.8642097531", "%.10Lf", 123456789.8642097531L); | ||
73 | testfmt(" 3.141592653589793238e-4000", "%L27.18Le", | ||
74 | 3.14159265358979323846e-4000L); | ||
75 | #endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) */ | ||
76 | |||
77 | /* | ||
78 | * Infinities and NaNs | ||
79 | */ | ||
80 | #ifdef NAN | ||
81 | testfmt("nan", "%e", NAN); | ||
82 | testfmt("NAN", "%F", NAN); | ||
83 | testfmt("nan", "%g", NAN); | ||
84 | testfmt("NAN", "%LE", (long double)NAN); | ||
85 | testfmt(" nan", "%05e", NAN); | ||
86 | #endif /* NAN */ | ||
87 | |||
88 | testfmt("INF", "%E", HUGE_VAL); | ||
89 | testfmt("-inf", "%f", -HUGE_VAL); | ||
90 | testfmt("+inf", "%+g", HUGE_VAL); | ||
91 | testfmt(" inf", "%4.2Le", HUGE_VALL); | ||
92 | testfmt("-inf", "%Lf", -HUGE_VALL); | ||
93 | testfmt(" inf", "%05e", HUGE_VAL); | ||
94 | testfmt(" -inf", "%05e", -HUGE_VAL); | ||
95 | |||
96 | /* | ||
97 | * Padding | ||
98 | */ | ||
99 | testfmt("0.000000e+00", "%e", 0.0); | ||
100 | testfmt("0.000000", "%F", (double)0.0); | ||
101 | testfmt("0", "%G", 0.0); | ||
102 | testfmt(" 0", "%3.0Lg", 0.0L); | ||
103 | testfmt(" 0", "%5.0f", 0.001); | ||
104 | |||
105 | /* | ||
106 | * Precision specifiers | ||
107 | */ | ||
108 | testfmt("1.0123e+00", "%.4e", 1.0123456789); | ||
109 | testfmt("1.0123", "%.4f", 1.0123456789); | ||
110 | testfmt("1.012", "%.4g", 1.0123456789); | ||
111 | testfmt("1.2346e-02", "%.4e", 0.0123456789); | ||
112 | testfmt("0.0123", "%.4f", 0.0123456789); | ||
113 | testfmt("0.01235", "%.4g", 0.0123456789); | ||
114 | |||
115 | /* | ||
116 | * Signed conversions | ||
117 | */ | ||
118 | testfmt("+2.500000e-01", "%+e", 0.25); | ||
119 | testfmt("+0.000000", "%+F", 0.0); | ||
120 | testfmt("-1", "%+g", -1.0); | ||
121 | |||
122 | testfmt("-1.000000e+00", "% e", -1.0); | ||
123 | testfmt("+1.000000", "% +f", 1.0); | ||
124 | testfmt(" 1", "% g", 1.0); | ||
125 | testfmt(" 0", "% g", 0.0); | ||
126 | |||
127 | /* | ||
128 | * ``Alternate form'' | ||
129 | */ | ||
130 | testfmt("1.250e+00", "%#.3e", 1.25); | ||
131 | testfmt("123.000000", "%#f", 123.0); | ||
132 | testfmt(" 12345.", "%#7.5g", 12345.0); | ||
133 | testfmt(" 1.00000", "%#8g", 1.0); | ||
134 | testfmt("0.0", "%#.2g", 0.0); | ||
135 | |||
136 | /* | ||
137 | * Padding and decimal point placement | ||
138 | */ | ||
139 | testfmt("03.2E+00", "%08.1E", 3.25); | ||
140 | testfmt("003.25", "%06.2F", 3.25); | ||
141 | testfmt("0003.25", "%07.4G", 3.25); | ||
142 | |||
143 | testfmt("3.14159e-05", "%g", 3.14159e-5); | ||
144 | testfmt("0.000314159", "%g", 3.14159e-4); | ||
145 | testfmt("3.14159e+06", "%g", 3.14159e6); | ||
146 | testfmt("314159", "%g", 3.14159e5); | ||
147 | testfmt("314159.", "%#g", 3.14159e5); | ||
148 | |||
149 | testfmt(" 9.000000e+03", "%13e", 9000.0); | ||
150 | testfmt(" 9000.000000", "%12f", 9000.0); | ||
151 | testfmt(" 9000", "%5g", 9000.0); | ||
152 | testfmt(" 900000.", "%#8g", 900000.0); | ||
153 | testfmt(" 9e+06", "%6g", 9000000.0); | ||
154 | testfmt(" 9.000000e-04", "%13e", 0.0009); | ||
155 | testfmt(" 0.000900", "%9f", 0.0009); | ||
156 | testfmt(" 0.0009", "%7g", 0.0009); | ||
157 | testfmt(" 9e-05", "%6g", 0.00009); | ||
158 | testfmt(" 9.00000e-05", "%#12g", 0.00009); | ||
159 | testfmt(" 9.e-05", "%#7.1g", 0.00009); | ||
160 | |||
161 | testfmt(" 0.0", "%4.1f", 0.0); | ||
162 | testfmt("90.0", "%4.1f", 90.0); | ||
163 | testfmt(" 100", "%4.0f", 100.0); | ||
164 | testfmt("9.0e+01", "%4.1e", 90.0); | ||
165 | testfmt("1e+02", "%4.0e", 100.0); | ||
166 | |||
167 | /* | ||
168 | * Hexadecimal floating point (%a, %A) tests. Some of these | ||
169 | * are only valid if the implementation converts to hex digits | ||
170 | * on nibble boundaries. | ||
171 | */ | ||
172 | testfmt("0x0p+0", "%a", 0x0.0p0); | ||
173 | testfmt("0X0.P+0", "%#LA", 0x0.0p0L); | ||
174 | #ifdef NAN | ||
175 | testfmt("inf", "%La", (long double)INFINITY); | ||
176 | testfmt("+INF", "%+A", INFINITY); | ||
177 | testfmt("nan", "%La", (long double)NAN); | ||
178 | testfmt("NAN", "%A", NAN); | ||
179 | #endif /* NAN */ | ||
180 | |||
181 | testfmt(" 0x1.23p+0", "%10a", 0x1.23p0); | ||
182 | testfmt(" 0x1.23p-500", "%12a", 0x1.23p-500); | ||
183 | testfmt(" 0x1.2p+40", "%10.1a", 0x1.23p40); | ||
184 | testfmt(" 0X1.230000000000000000000000P-4", "%32.24A", 0x1.23p-4); | ||
185 | testfmt("0x1p-1074", "%a", 0x1p-1074); | ||
186 | testfmt("0x1.2345p-1024", "%a", 0x1.2345p-1024); | ||
187 | |||
188 | #if LDBL_MANT_DIG == 113 | ||
189 | testfmt("-0x1.e7d7c7b7a7978777675747372717p-14344", "%La", | ||
190 | -0x1.e7d7c7b7a7978777675747372717p-14344L); | ||
191 | #elif LDBL_MANT_DIG == 64 | ||
192 | testfmt("-0x8.777675747372717p-16248", "%La", | ||
193 | -0x8.777675747372717p-16248L); | ||
194 | #endif | ||
195 | |||
196 | return (0); | ||
197 | } | ||
198 | |||
199 | void | ||
200 | smash_stack(void) | ||
201 | { | ||
202 | static uint32_t junk = 0xdeadbeef; | ||
203 | uint32_t buf[512]; | ||
204 | int i; | ||
205 | |||
206 | for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++) | ||
207 | buf[i] = junk; | ||
208 | } | ||
209 | |||
210 | void | ||
211 | _testfmt(const char *result, int line, const char *argstr, const char *fmt,...) | ||
212 | { | ||
213 | char s[100]; | ||
214 | va_list ap; | ||
215 | |||
216 | va_start(ap, fmt); | ||
217 | smash_stack(); | ||
218 | vsnprintf(s, sizeof(s), fmt, ap); | ||
219 | if (strcmp(result, s) != 0) { | ||
220 | fprintf(stderr, | ||
221 | "%d: printf(\"%s\", %s) ==> [%s], expected [%s]\n", | ||
222 | line, fmt, argstr, s, result); | ||
223 | abort(); | ||
224 | } | ||
225 | } | ||
diff --git a/src/regress/lib/libc/printf/int.c b/src/regress/lib/libc/printf/int.c deleted file mode 100644 index 5a56c8d50e..0000000000 --- a/src/regress/lib/libc/printf/int.c +++ /dev/null | |||
@@ -1,376 +0,0 @@ | |||
1 | /* $OpenBSD: int.c,v 1.2 2020/07/14 16:40:04 kettenis Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | * | ||
17 | * Test the %c, %lc, %s, and %ls conversion specifiers with all their | ||
18 | * modifiers, in particular with the minus flag, width, and maxbytes. | ||
19 | * Also verify that other flags do nothing useful. | ||
20 | */ | ||
21 | #include <err.h> | ||
22 | #include <stddef.h> | ||
23 | #include <stdint.h> | ||
24 | #include <stdio.h> | ||
25 | #include <string.h> | ||
26 | #include <unistd.h> | ||
27 | |||
28 | enum int_size { | ||
29 | S_CHAR, | ||
30 | S_SHORT, | ||
31 | S_INT, | ||
32 | S_LONG, | ||
33 | S_LL, | ||
34 | S_MAX, | ||
35 | S_PTR, | ||
36 | S_SIZE | ||
37 | }; | ||
38 | |||
39 | void ti(const char *, enum int_size, long long, const char *); | ||
40 | void tu(const char *, enum int_size, unsigned long long, const char *); | ||
41 | |||
42 | static int badret, badlen, badout; /* Error counters. */ | ||
43 | static int verbose; /* For debugging. */ | ||
44 | |||
45 | |||
46 | /* | ||
47 | * Print the signed integer i with the format fmt, | ||
48 | * check that the result matches what we want, | ||
49 | * and report and count the error on failure. | ||
50 | */ | ||
51 | void | ||
52 | ti(const char *fmt, enum int_size sz, long long i, const char *want) | ||
53 | { | ||
54 | char buf[32]; | ||
55 | size_t len; | ||
56 | int irc, happy; | ||
57 | |||
58 | happy = 1; | ||
59 | switch (sz) { | ||
60 | case S_CHAR: | ||
61 | irc = snprintf(buf, sizeof(buf), fmt, (signed char)i); | ||
62 | break; | ||
63 | case S_SHORT: | ||
64 | irc = snprintf(buf, sizeof(buf), fmt, (short)i); | ||
65 | break; | ||
66 | case S_INT: | ||
67 | irc = snprintf(buf, sizeof(buf), fmt, (int)i); | ||
68 | break; | ||
69 | case S_LONG: | ||
70 | irc = snprintf(buf, sizeof(buf), fmt, (long)i); | ||
71 | break; | ||
72 | case S_LL: | ||
73 | irc = snprintf(buf, sizeof(buf), fmt, (long long)i); | ||
74 | break; | ||
75 | case S_MAX: | ||
76 | irc = snprintf(buf, sizeof(buf), fmt, (intmax_t)i); | ||
77 | break; | ||
78 | case S_PTR: | ||
79 | irc = snprintf(buf, sizeof(buf), fmt, (ptrdiff_t)i); | ||
80 | break; | ||
81 | case S_SIZE: | ||
82 | irc = snprintf(buf, sizeof(buf), fmt, (ssize_t)i); | ||
83 | break; | ||
84 | default: | ||
85 | warnx("printf(\"%s\", %lld) unknown size code %d", | ||
86 | fmt, i, sz); | ||
87 | badret++; | ||
88 | return; | ||
89 | } | ||
90 | len = strlen(want); | ||
91 | if (irc < 0) { | ||
92 | warn("printf(\"%s\", %lld) returned %d", fmt, i, irc); | ||
93 | badret++; | ||
94 | return; | ||
95 | } | ||
96 | if ((unsigned long long)irc != len) { | ||
97 | warnx("printf(\"%s\", %lld) returned %d (expected %zu)", | ||
98 | fmt, i, irc, len); | ||
99 | badlen++; | ||
100 | happy = 0; | ||
101 | } | ||
102 | if (strcmp(buf, want) != 0) { | ||
103 | warnx("printf(\"%s\", %lld) wrote \"%s\" (expected \"%s\")", | ||
104 | fmt, i, buf, want); | ||
105 | badout++; | ||
106 | happy = 0; | ||
107 | } | ||
108 | if (verbose && happy) | ||
109 | warnx("printf(\"%s\", %lld) wrote \"%s\" length %d (OK)", | ||
110 | fmt, i, buf, irc); | ||
111 | } | ||
112 | |||
113 | /* | ||
114 | * Print the unsigned integer i with the format fmt, | ||
115 | * check that the result matches what we want, | ||
116 | * and report and count the error on failure. | ||
117 | */ | ||
118 | void | ||
119 | tu(const char *fmt, enum int_size sz, unsigned long long i, const char *want) | ||
120 | { | ||
121 | char buf[32]; | ||
122 | size_t len; | ||
123 | int irc, happy; | ||
124 | |||
125 | happy = 1; | ||
126 | switch (sz) { | ||
127 | case S_CHAR: | ||
128 | irc = snprintf(buf, sizeof(buf), fmt, (unsigned char)i); | ||
129 | break; | ||
130 | case S_SHORT: | ||
131 | irc = snprintf(buf, sizeof(buf), fmt, (unsigned short)i); | ||
132 | break; | ||
133 | case S_INT: | ||
134 | irc = snprintf(buf, sizeof(buf), fmt, (unsigned int)i); | ||
135 | break; | ||
136 | case S_LONG: | ||
137 | irc = snprintf(buf, sizeof(buf), fmt, (unsigned long)i); | ||
138 | break; | ||
139 | case S_LL: | ||
140 | irc = snprintf(buf, sizeof(buf), fmt, (unsigned long long)i); | ||
141 | break; | ||
142 | case S_MAX: | ||
143 | irc = snprintf(buf, sizeof(buf), fmt, (uintmax_t)i); | ||
144 | break; | ||
145 | case S_SIZE: | ||
146 | irc = snprintf(buf, sizeof(buf), fmt, (size_t)i); | ||
147 | break; | ||
148 | default: | ||
149 | warnx("printf(\"%s\", %llu) unknown size code %d", | ||
150 | fmt, i, sz); | ||
151 | badret++; | ||
152 | return; | ||
153 | } | ||
154 | len = strlen(want); | ||
155 | if (irc < 0) { | ||
156 | warn("printf(\"%s\", %llu) returned %d", fmt, i, irc); | ||
157 | badret++; | ||
158 | return; | ||
159 | } | ||
160 | if ((unsigned long long)irc != len) { | ||
161 | warnx("printf(\"%s\", %llu) returned %d (expected %zu)", | ||
162 | fmt, i, irc, len); | ||
163 | badlen++; | ||
164 | happy = 0; | ||
165 | } | ||
166 | if (strcmp(buf, want) != 0) { | ||
167 | warnx("printf(\"%s\", %llu) wrote \"%s\" (expected \"%s\")", | ||
168 | fmt, i, buf, want); | ||
169 | badout++; | ||
170 | happy = 0; | ||
171 | } | ||
172 | if (verbose && happy) | ||
173 | warnx("printf(\"%s\", %llu) wrote \"%s\" length %d (OK)", | ||
174 | fmt, i, buf, irc); | ||
175 | } | ||
176 | |||
177 | int | ||
178 | main(int argc, char *argv[]) | ||
179 | { | ||
180 | int badarg, picky; | ||
181 | int ch; | ||
182 | |||
183 | badarg = picky = 0; | ||
184 | while ((ch = getopt(argc, argv, "pv")) != -1) { | ||
185 | switch (ch) { | ||
186 | case 'p': | ||
187 | picky = 1; | ||
188 | break; | ||
189 | case 'v': | ||
190 | verbose = 1; | ||
191 | break; | ||
192 | default: | ||
193 | badarg = 1; | ||
194 | break; | ||
195 | } | ||
196 | } | ||
197 | argc -= optind; | ||
198 | argv += optind; | ||
199 | if (argc > 0) { | ||
200 | warnx("unexpected argument \"%s\"", *argv); | ||
201 | badarg = 1; | ||
202 | } | ||
203 | if (badarg) { | ||
204 | fputs("usage: int [-pv]\n", stderr); | ||
205 | return 1; | ||
206 | } | ||
207 | |||
208 | /* | ||
209 | * Valid use cases of %d. | ||
210 | */ | ||
211 | |||
212 | ti("<%d>", S_INT, 0, "<0>"); | ||
213 | ti("<%d>", S_INT, 1, "<1>"); | ||
214 | ti("<%d>", S_INT, -1, "<-1>"); | ||
215 | ti("<%d>", S_INT, 42, "<42>"); | ||
216 | ti("<%d>", S_INT, INT32_MAX, "<2147483647>"); | ||
217 | ti("<%d>", S_INT, INT32_MIN, "<-2147483648>"); | ||
218 | ti("<% d>", S_INT, 42, "< 42>"); | ||
219 | ti("<% d>", S_INT, -42, "<-42>"); | ||
220 | ti("<%+d>", S_INT, 42, "<+42>"); | ||
221 | ti("<%+d>", S_INT, -42, "<-42>"); | ||
222 | ti("<% +d>", S_INT, 42, "<+42>"); | ||
223 | ti("<% +d>", S_INT, -42, "<-42>"); | ||
224 | ti("<%-4d>", S_INT, 42, "<42 >"); | ||
225 | ti("<% -4d>", S_INT, 42, "< 42 >"); | ||
226 | ti("<%+-4d>", S_INT, 42, "<+42 >"); | ||
227 | ti("<%04d>", S_INT, 42, "<0042>"); | ||
228 | ti("<%-04d>", S_INT, 42, "<42 >"); | ||
229 | ti("<% 04d>", S_INT, 42, "< 042>"); | ||
230 | ti("<%+04d>", S_INT, 42, "<+042>"); | ||
231 | ti("<%4.3d>", S_INT, 42, "< 042>"); | ||
232 | ti("<% 5.3d>", S_INT, 42, "< 042>"); | ||
233 | ti("<%+5.3d>", S_INT, 42, "< +042>"); | ||
234 | ti("<%-4.3d>", S_INT, 42, "<042 >"); | ||
235 | ti("<%04.3d>", S_INT, 42, "< 042>"); | ||
236 | |||
237 | ti("<%hhd>", S_CHAR, INT8_MIN, "<-128>"); | ||
238 | ti("<%hhd>", S_CHAR, -1, "<-1>"); | ||
239 | ti("<%hhd>", S_CHAR, 0, "<0>"); | ||
240 | ti("<%hhd>", S_CHAR, 1, "<1>"); | ||
241 | ti("<%hhd>", S_CHAR, INT8_MAX, "<127>"); | ||
242 | ti("<%+.4hhd>", S_CHAR, 42, "<+0042>"); | ||
243 | ti("<% 04hhd>", S_CHAR, 42, "< 042>"); | ||
244 | |||
245 | ti("<%hd>", S_SHORT, INT16_MIN, "<-32768>"); | ||
246 | ti("<%hd>", S_SHORT, -1, "<-1>"); | ||
247 | ti("<%hd>", S_SHORT, 0, "<0>"); | ||
248 | ti("<%hd>", S_SHORT, 1, "<1>"); | ||
249 | ti("<%hd>", S_SHORT, INT16_MAX, "<32767>"); | ||
250 | |||
251 | ti("<%hld>", S_LONG, INT32_MIN, "<-2147483648>"); | ||
252 | ti("<%hld>", S_LONG, -1, "<-1>"); | ||
253 | ti("<%hld>", S_LONG, 0, "<0>"); | ||
254 | ti("<%hld>", S_LONG, 1, "<1>"); | ||
255 | ti("<%hld>", S_LONG, INT32_MAX, "<2147483647>"); | ||
256 | |||
257 | ti("<%hlld>", S_LL, INT64_MIN, "<-9223372036854775808>"); | ||
258 | ti("<%hlld>", S_LL, -1, "<-1>"); | ||
259 | ti("<%hlld>", S_LL, 0, "<0>"); | ||
260 | ti("<%hlld>", S_LL, 1, "<1>"); | ||
261 | ti("<%hlld>", S_LL, INT64_MAX, "<9223372036854775807>"); | ||
262 | ti("<%h-19lld>", S_LL, 123456789123456789LL, "<123456789123456789 >"); | ||
263 | |||
264 | ti("<%hjd>", S_MAX, INT64_MIN, "<-9223372036854775808>"); | ||
265 | ti("<%hjd>", S_MAX, -1, "<-1>"); | ||
266 | ti("<%hjd>", S_MAX, 0, "<0>"); | ||
267 | ti("<%hjd>", S_MAX, 1, "<1>"); | ||
268 | ti("<%hjd>", S_MAX, INT64_MAX, "<9223372036854775807>"); | ||
269 | |||
270 | ti("<%htd>", S_PTR, INT32_MIN, "<-2147483648>"); | ||
271 | ti("<%htd>", S_PTR, -1, "<-1>"); | ||
272 | ti("<%htd>", S_PTR, 0, "<0>"); | ||
273 | ti("<%htd>", S_PTR, 1, "<1>"); | ||
274 | ti("<%htd>", S_PTR, INT32_MAX, "<2147483647>"); | ||
275 | |||
276 | ti("<%hzd>", S_SIZE, INT32_MIN, "<-2147483648>"); | ||
277 | ti("<%hzd>", S_SIZE, -1, "<-1>"); | ||
278 | ti("<%hzd>", S_SIZE, 0, "<0>"); | ||
279 | ti("<%hzd>", S_SIZE, 1, "<1>"); | ||
280 | ti("<%hzd>", S_SIZE, INT32_MAX, "<2147483647>"); | ||
281 | |||
282 | /* | ||
283 | * Undefined behaviour of %d. | ||
284 | * Do not test by default to avoid noise. | ||
285 | * But provide the tests anyway to help track down | ||
286 | * unintended changes of behaviour when needed. | ||
287 | */ | ||
288 | |||
289 | if (picky) { | ||
290 | ti("<%#d>", S_INT, 42, "<42>"); | ||
291 | ti("<%Ld>", S_INT, 42, "<42>"); | ||
292 | } | ||
293 | |||
294 | /* | ||
295 | * Valid use cases of %u. | ||
296 | */ | ||
297 | |||
298 | tu("<%u>", S_INT, 0, "<0>"); | ||
299 | tu("<%u>", S_INT, 1, "<1>"); | ||
300 | tu("<%u>", S_INT, 42, "<42>"); | ||
301 | tu("<%u>", S_INT, UINT32_MAX, "<4294967295>"); | ||
302 | tu("<%-4u>", S_INT, 42, "<42 >"); | ||
303 | tu("<%04u>", S_INT, 42, "<0042>"); | ||
304 | tu("<%-04u>", S_INT, 42, "<42 >"); | ||
305 | tu("<%4.3u>", S_INT, 42, "< 042>"); | ||
306 | tu("<%-4.3u>", S_INT, 42, "<042 >"); | ||
307 | tu("<%04.3u>", S_INT, 42, "< 042>"); | ||
308 | |||
309 | tu("<%hhu>", S_CHAR, 0, "<0>"); | ||
310 | tu("<%hhu>", S_CHAR, UINT8_MAX, "<255>"); | ||
311 | tu("<%hhu>", S_CHAR, -1, "<255>"); | ||
312 | tu("<%-4hhu>", S_CHAR, 42, "<42 >"); | ||
313 | tu("<%04hhu>", S_CHAR, 42, "<0042>"); | ||
314 | |||
315 | tu("<%hu>", S_SHORT, 0, "<0>"); | ||
316 | tu("<%hu>", S_SHORT, UINT16_MAX, "<65535>"); | ||
317 | tu("<%hlu>", S_LONG, 0, "<0>"); | ||
318 | tu("<%hlu>", S_LONG, UINT32_MAX, "<4294967295>"); | ||
319 | tu("<%hllu>", S_LL, 0, "<0>"); | ||
320 | tu("<%hllu>", S_LL, UINT64_MAX, "<18446744073709551615>"); | ||
321 | tu("<%h-19llu>", S_LL, 123456789123456789ULL, "<123456789123456789 >"); | ||
322 | tu("<%hju>", S_MAX, 0, "<0>"); | ||
323 | tu("<%hju>", S_MAX, UINT64_MAX, "<18446744073709551615>"); | ||
324 | tu("<%hzu>", S_SIZE, 0, "<0>"); | ||
325 | tu("<%hzu>", S_SIZE, UINT32_MAX, "<4294967295>"); | ||
326 | |||
327 | tu("<%hho>", S_CHAR, 0, "<0>"); | ||
328 | tu("<%#hho>", S_CHAR, 0, "<0>"); | ||
329 | tu("<%hho>", S_CHAR, UINT8_MAX, "<377>"); | ||
330 | tu("<%#hho>", S_CHAR, UINT8_MAX, "<0377>"); | ||
331 | tu("<%hho>", S_CHAR, -1, "<377>"); | ||
332 | tu("<%#hho>", S_CHAR, -1, "<0377>"); | ||
333 | tu("<%-4hho>", S_CHAR, 42, "<52 >"); | ||
334 | tu("<%#-4hho>", S_CHAR, 42, "<052 >"); | ||
335 | tu("<%04hho>", S_CHAR, 42, "<0052>"); | ||
336 | tu("<%#04hho>", S_CHAR, 42, "<0052>"); | ||
337 | |||
338 | tu("<%hx>", S_SHORT, 0, "<0>"); | ||
339 | tu("<%#hx>", S_SHORT, 0, "<0>"); | ||
340 | tu("<%hX>", S_SHORT, 0, "<0>"); | ||
341 | tu("<%#hX>", S_SHORT, 0, "<0>"); | ||
342 | tu("<%hx>", S_SHORT, 1, "<1>"); | ||
343 | tu("<%#hx>", S_SHORT, 1, "<0x1>"); | ||
344 | tu("<%hX>", S_SHORT, 1, "<1>"); | ||
345 | tu("<%#hX>", S_SHORT, 1, "<0X1>"); | ||
346 | tu("<%hx>", S_SHORT, 10, "<a>"); | ||
347 | tu("<%#hx>", S_SHORT, 10, "<0xa>"); | ||
348 | tu("<%hX>", S_SHORT, 10, "<A>"); | ||
349 | tu("<%#hX>", S_SHORT, 10, "<0XA>"); | ||
350 | tu("<%hx>", S_SHORT, UINT16_MAX, "<ffff>"); | ||
351 | tu("<%#hx>", S_SHORT, UINT16_MAX, "<0xffff>"); | ||
352 | tu("<%hX>", S_SHORT, UINT16_MAX, "<FFFF>"); | ||
353 | tu("<%#hX>", S_SHORT, UINT16_MAX, "<0XFFFF>"); | ||
354 | |||
355 | /* | ||
356 | * Undefined behaviour of %u. | ||
357 | */ | ||
358 | |||
359 | if (picky) { | ||
360 | tu("<%#u>", S_INT, 42, "<42>"); | ||
361 | tu("<% u>", S_INT, 42, "<42>"); | ||
362 | tu("<%+u>", S_INT, 42, "<42>"); | ||
363 | tu("<%Lu>", S_INT, 42, "<42>"); | ||
364 | } | ||
365 | |||
366 | /* | ||
367 | * Summarize the results. | ||
368 | */ | ||
369 | |||
370 | if (badret + badlen + badout) | ||
371 | errx(1, "ERRORS: %d fail + %d mismatch (incl. %d bad length)", | ||
372 | badret, badout, badlen); | ||
373 | else if (verbose) | ||
374 | warnx("SUCCESS"); | ||
375 | return 0; | ||
376 | } | ||
diff --git a/src/regress/lib/libc/printf/string.c b/src/regress/lib/libc/printf/string.c deleted file mode 100644 index 6e65a371a4..0000000000 --- a/src/regress/lib/libc/printf/string.c +++ /dev/null | |||
@@ -1,435 +0,0 @@ | |||
1 | /* $OpenBSD: string.c,v 1.2 2020/07/14 16:40:04 kettenis Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | * | ||
17 | * Test the %c, %lc, %s, and %ls conversion specifiers with all their | ||
18 | * modifiers, in particular with the minus flag, width, and maxbytes. | ||
19 | * Also verify that other flags do nothing useful. | ||
20 | */ | ||
21 | #include <err.h> | ||
22 | #include <errno.h> | ||
23 | #include <locale.h> | ||
24 | #include <stdio.h> | ||
25 | #include <stdlib.h> | ||
26 | #include <string.h> | ||
27 | #include <unistd.h> | ||
28 | #include <wchar.h> | ||
29 | |||
30 | void tc(const char *, int, const char *); | ||
31 | void tlc(const char *, wint_t, const char *); | ||
32 | void tlc_expect_fail(const char *, wint_t); | ||
33 | void ts(const char *, const char *, const char *); | ||
34 | void tls(const char *, const wchar_t *, const char *); | ||
35 | void tls_expect_fail(const char *, const wchar_t *); | ||
36 | |||
37 | static int badret, badlen, badout; /* Error counters. */ | ||
38 | static int verbose; /* For debugging. */ | ||
39 | |||
40 | |||
41 | /* | ||
42 | * Print the single-byte character c with the format fmt, | ||
43 | * check that the result matches what we want, | ||
44 | * and report and count the error on failure. | ||
45 | */ | ||
46 | void | ||
47 | tc(const char *fmt, int c, const char *want) | ||
48 | { | ||
49 | char buf[32]; | ||
50 | size_t len; | ||
51 | int irc, happy; | ||
52 | |||
53 | happy = 1; | ||
54 | irc = snprintf(buf, sizeof(buf), fmt, c); | ||
55 | len = strlen(want); | ||
56 | if (irc < 0) { | ||
57 | warn("printf(\"%s\", %d) returned %d", fmt, c, irc); | ||
58 | badret++; | ||
59 | return; | ||
60 | } | ||
61 | if ((unsigned long long)irc != len) { | ||
62 | warnx("printf(\"%s\", %d) returned %d (expected %zu)", | ||
63 | fmt, c, irc, len); | ||
64 | badlen++; | ||
65 | happy = 0; | ||
66 | } | ||
67 | if (strcmp(buf, want) != 0) { | ||
68 | warnx("printf(\"%s\", %d) wrote \"%s\" (expected \"%s\")", | ||
69 | fmt, c, buf, want); | ||
70 | badout++; | ||
71 | happy = 0; | ||
72 | } | ||
73 | if (verbose && happy) | ||
74 | warnx("printf(\"%s\", %d) wrote \"%s\" length %d (OK)", | ||
75 | fmt, c, buf, irc); | ||
76 | } | ||
77 | |||
78 | /* | ||
79 | * Print the wide character wc with the format fmt, | ||
80 | * check that the result matches what we want, | ||
81 | * and report and count the error on failure. | ||
82 | */ | ||
83 | void | ||
84 | tlc(const char *fmt, wint_t wc, const char *want) | ||
85 | { | ||
86 | char buf[32]; | ||
87 | const char *charset; | ||
88 | size_t len; | ||
89 | int irc, happy; | ||
90 | |||
91 | happy = 1; | ||
92 | charset = MB_CUR_MAX > 1 ? "UTF-8" : "ASCII"; | ||
93 | irc = snprintf(buf, sizeof(buf), fmt, wc); | ||
94 | len = strlen(want); | ||
95 | if (irc < 0) { | ||
96 | warn("%s printf(\"%s\", U+%.4X) returned %d", | ||
97 | charset, fmt, (unsigned int)wc, irc); | ||
98 | badret++; | ||
99 | return; | ||
100 | } | ||
101 | if ((unsigned long long)irc != len) { | ||
102 | warnx("%s printf(\"%s\", U+%.4X) returned %d (expected %zu)", | ||
103 | charset, fmt, (unsigned int)wc, irc, len); | ||
104 | badlen++; | ||
105 | happy = 0; | ||
106 | } | ||
107 | if (strcmp(buf, want) != 0) { | ||
108 | warnx("%s printf(\"%s\", U+%.4X) " | ||
109 | "wrote \"%s\" (expected \"%s\")", | ||
110 | charset, fmt, (unsigned int)wc, buf, want); | ||
111 | badout++; | ||
112 | happy = 0; | ||
113 | } | ||
114 | if (verbose && happy) | ||
115 | warnx("%s printf(\"%s\", U+%.4X) wrote \"%s\" length %d (OK)", | ||
116 | charset, fmt, (unsigned int)wc, buf, irc); | ||
117 | } | ||
118 | |||
119 | /* | ||
120 | * Try to print the invalid wide character wc with the format fmt, | ||
121 | * check that it fails as it should, and report and count if it doesn't. | ||
122 | */ | ||
123 | void | ||
124 | tlc_expect_fail(const char *fmt, wint_t wc) | ||
125 | { | ||
126 | char buf[32]; | ||
127 | const char *charset; | ||
128 | int irc; | ||
129 | |||
130 | errno = 0; | ||
131 | charset = MB_CUR_MAX > 1 ? "UTF-8" : "ASCII"; | ||
132 | irc = snprintf(buf, sizeof(buf), fmt, wc); | ||
133 | if (irc != -1) { | ||
134 | warn("%s printf(\"%s\", U+%.4X) returned %d", | ||
135 | charset, fmt, (unsigned int)wc, irc); | ||
136 | badret++; | ||
137 | } else if (errno != EILSEQ) { | ||
138 | warnx("%s printf(\"%s\", U+%.4X) errno %d (expected %d)", | ||
139 | charset, fmt, (unsigned int)wc, errno, EILSEQ); | ||
140 | badret++; | ||
141 | } else if (verbose) | ||
142 | warnx("%s printf(\"%s\", U+%.4X) returned %d errno %d (OK)", | ||
143 | charset, fmt, (unsigned int)wc, irc, errno); | ||
144 | } | ||
145 | |||
146 | /* | ||
147 | * Print the string s with the format fmt, | ||
148 | * check that the result matches what we want, | ||
149 | * and report and count the error on failure. | ||
150 | */ | ||
151 | void | ||
152 | ts(const char *fmt, const char *s, const char *want) | ||
153 | { | ||
154 | char buf[32]; | ||
155 | size_t len; | ||
156 | int irc, happy; | ||
157 | |||
158 | happy = 1; | ||
159 | irc = snprintf(buf, sizeof(buf), fmt, s); | ||
160 | len = strlen(want); | ||
161 | if (irc < 0) { | ||
162 | warn("printf(\"%s\", \"%s\") returned %d", fmt, s, irc); | ||
163 | badret++; | ||
164 | return; | ||
165 | } | ||
166 | if ((unsigned long long)irc != len) { | ||
167 | warnx("printf(\"%s\", \"%s\") returned %d (expected %zu)", | ||
168 | fmt, s, irc, len); | ||
169 | badlen++; | ||
170 | happy = 0; | ||
171 | } | ||
172 | if (strcmp(buf, want) != 0) { | ||
173 | warnx("printf(\"%s\", \"%s\") wrote \"%s\" (expected \"%s\")", | ||
174 | fmt, s, buf, want); | ||
175 | badout++; | ||
176 | happy = 0; | ||
177 | } | ||
178 | if (verbose && happy) | ||
179 | warnx("printf(\"%s\", \"%s\") wrote \"%s\" length %d (OK)", | ||
180 | fmt, s, buf, irc); | ||
181 | } | ||
182 | |||
183 | /* | ||
184 | * Print the wide character string ws with the format fmt, | ||
185 | * check that the result matches what we want, | ||
186 | * and report and count the error on failure. | ||
187 | */ | ||
188 | void | ||
189 | tls(const char *fmt, const wchar_t *ws, const char *want) | ||
190 | { | ||
191 | char buf[32]; | ||
192 | const char *charset; | ||
193 | size_t len; | ||
194 | int irc, happy; | ||
195 | |||
196 | happy = 1; | ||
197 | charset = MB_CUR_MAX > 1 ? "UTF-8" : "ASCII"; | ||
198 | irc = snprintf(buf, sizeof(buf), fmt, ws); | ||
199 | len = strlen(want); | ||
200 | if (irc < 0) { | ||
201 | warn("%s printf(\"%s\", \"%ls\") returned %d", | ||
202 | charset, fmt, ws, irc); | ||
203 | badret++; | ||
204 | return; | ||
205 | } | ||
206 | if ((unsigned long long)irc != len) { | ||
207 | warnx("%s printf(\"%s\", \"%ls\") returned %d (expected %zu)", | ||
208 | charset, fmt, ws, irc, len); | ||
209 | badlen++; | ||
210 | happy = 0; | ||
211 | } | ||
212 | if (strcmp(buf, want) != 0) { | ||
213 | warnx("%s printf(\"%s\", \"%ls\") " | ||
214 | "wrote \"%s\" (expected \"%s\")", | ||
215 | charset, fmt, ws, buf, want); | ||
216 | badout++; | ||
217 | happy = 0; | ||
218 | } | ||
219 | if (verbose && happy) | ||
220 | warnx("%s printf(\"%s\", \"%ls\") wrote \"%s\" length %d (OK)", | ||
221 | charset, fmt, ws, buf, irc); | ||
222 | } | ||
223 | |||
224 | /* | ||
225 | * Try to print the invalid wide character string ws with the format fmt, | ||
226 | * check that it fails as it should, and report and count if it doesn't. | ||
227 | */ | ||
228 | void | ||
229 | tls_expect_fail(const char *fmt, const wchar_t *ws) | ||
230 | { | ||
231 | char buf[32]; | ||
232 | const char *charset; | ||
233 | int irc; | ||
234 | |||
235 | errno = 0; | ||
236 | charset = MB_CUR_MAX > 1 ? "UTF-8" : "ASCII"; | ||
237 | irc = snprintf(buf, sizeof(buf), fmt, ws); | ||
238 | if (irc != -1) { | ||
239 | warn("%s printf(\"%s\", U+%.4X, ...) returned %d", | ||
240 | charset, fmt, (unsigned int)*ws, irc); | ||
241 | badret++; | ||
242 | } else if (errno != EILSEQ) { | ||
243 | warnx("%s printf(\"%s\", U+%.4X, ...) errno %d (expected %d)", | ||
244 | charset, fmt, (unsigned int)*ws, errno, EILSEQ); | ||
245 | badret++; | ||
246 | } else if (verbose) | ||
247 | warnx("%s printf(\"%s\", U+%.4X, ...) " | ||
248 | "returned %d errno %d (OK)", | ||
249 | charset, fmt, (unsigned int)*ws, irc, errno); | ||
250 | } | ||
251 | |||
252 | int | ||
253 | main(int argc, char *argv[]) | ||
254 | { | ||
255 | const wchar_t ws[] = { 0x0421, 0x043e, 0x0444, 0x044f, 0 }; | ||
256 | const wchar_t wsbad[] = { 0x0391, 0xdeef, 0x3c9, 0 }; | ||
257 | int badarg, picky; | ||
258 | int ch; | ||
259 | |||
260 | badarg = picky = 0; | ||
261 | while ((ch = getopt(argc, argv, "pv")) != -1) { | ||
262 | switch (ch) { | ||
263 | case 'p': | ||
264 | picky = 1; | ||
265 | break; | ||
266 | case 'v': | ||
267 | verbose = 1; | ||
268 | break; | ||
269 | default: | ||
270 | badarg = 1; | ||
271 | break; | ||
272 | } | ||
273 | } | ||
274 | argc -= optind; | ||
275 | argv += optind; | ||
276 | if (argc > 0) { | ||
277 | warnx("unexpected argument \"%s\"", *argv); | ||
278 | badarg = 1; | ||
279 | } | ||
280 | if (badarg) { | ||
281 | fputs("usage: string [-pv]\n", stderr); | ||
282 | return 1; | ||
283 | } | ||
284 | |||
285 | /* | ||
286 | * Valid use cases of %c and %s. | ||
287 | */ | ||
288 | |||
289 | tc("<%c>", '=', "<=>"); | ||
290 | tc("<%c>", '\t', "<\t>"); | ||
291 | tc("<%c>", 0xfe, "<\xfe>"); | ||
292 | tc("<%-c>", '=', "<=>"); | ||
293 | tc("<%2c>", '=', "< =>"); | ||
294 | tc("<%-2c>", '=', "<= >"); | ||
295 | |||
296 | ts("<%s>", "text", "<text>"); | ||
297 | ts("<%-s>", "text", "<text>"); | ||
298 | ts("<%6s>", "text", "< text>"); | ||
299 | ts("<%-6s>", "text", "<text >"); | ||
300 | ts("<%.2s>", "text", "<te>"); | ||
301 | ts("<%4.2s>", "text", "< te>"); | ||
302 | ts("<%-4.2s>", "text", "<te >"); | ||
303 | |||
304 | /* | ||
305 | * Undefined behaviour of %c and %s. | ||
306 | * Do not test by default to avoid noise. | ||
307 | * But provide the tests anyway to help track down | ||
308 | * unintended changes of behaviour when needed. | ||
309 | */ | ||
310 | |||
311 | if (picky) { | ||
312 | tc("<%#c>", '=', "<=>"); | ||
313 | tc("<% -3c>", '=', "<= >"); | ||
314 | tc("<%+-3c>", '=', "<= >"); | ||
315 | tc("<%03c>", '=', "<00=>"); | ||
316 | tc("<%-03c>", '=', "<= >"); | ||
317 | tc("<%3.2c>", '=', "< =>"); | ||
318 | tc("<%hc>", '=', "<=>"); | ||
319 | |||
320 | ts("<%#s>", "text", "<text>"); | ||
321 | ts("<% -6s>", "text", "<text >"); | ||
322 | ts("<%+-6s>", "text", "<text >"); | ||
323 | ts("<%06s>", "text", "<00text>"); | ||
324 | ts("<%-06s>", "text", "<text >"); | ||
325 | ts("<%hs>", "text", "<text>"); | ||
326 | } | ||
327 | |||
328 | /* | ||
329 | * Valid use cases of %lc and %ls in the POSIX locale. | ||
330 | */ | ||
331 | |||
332 | tlc("<%lc>", L'=', "<=>"); | ||
333 | tlc("<%lc>", L'\t', "<\t>"); | ||
334 | tlc_expect_fail("<%lc>", 0x03c0); | ||
335 | tlc("<%-lc>", L'=', "<=>"); | ||
336 | tlc("<%2lc>", L'=', "< =>"); | ||
337 | tlc("<%-2lc>", L'=', "<= >"); | ||
338 | |||
339 | tls("<%ls>", L"text", "<text>"); | ||
340 | tls_expect_fail("<%ls>", ws); | ||
341 | tls_expect_fail("<%ls>", wsbad); | ||
342 | tls("<%-ls>", L"text", "<text>"); | ||
343 | tls("<%6ls>", L"text", "< text>"); | ||
344 | tls("<%-6ls>", L"text", "<text >"); | ||
345 | tls("<%.2ls>", L"text", "<te>"); | ||
346 | tls("<%4.2ls>", L"text", "< te>"); | ||
347 | tls("<%-4.2ls>", L"text", "<te >"); | ||
348 | |||
349 | /* | ||
350 | * Undefined behaviour of %lc and %ls in the POSIX locale. | ||
351 | */ | ||
352 | |||
353 | if (picky) { | ||
354 | tlc("<%lc>", 0x00fe, "<\xfe>"); | ||
355 | tlc("<%#lc>", L'=', "<=>"); | ||
356 | tlc("<% -3lc>", L'=', "<= >"); | ||
357 | tlc("<%+-3lc>", L'=', "<= >"); | ||
358 | tlc("<%03lc>", L'=', "<00=>"); | ||
359 | tlc("<%-03lc>", L'=', "<= >"); | ||
360 | tlc("<%3.2lc>", L'=', "< =>"); | ||
361 | tc("<%llc>", '=', "<=>"); | ||
362 | |||
363 | tls("<%#ls>", L"text", "<text>"); | ||
364 | tls("<% -6ls>", L"text", "<text >"); | ||
365 | tls("<%+-6ls>", L"text", "<text >"); | ||
366 | tls("<%06ls>", L"text", "<00text>"); | ||
367 | tls("<%-06ls>", L"text", "<text >"); | ||
368 | ts("<%lls>", "text", "<text>"); | ||
369 | } | ||
370 | |||
371 | /* | ||
372 | * Valid use cases of %lc and %ls in a UTF-8 locale. | ||
373 | */ | ||
374 | |||
375 | if (setlocale(LC_CTYPE, "C.UTF-8") == NULL) | ||
376 | err(1, "setlocale"); | ||
377 | |||
378 | tlc("<%lc>", L'=', "<=>"); | ||
379 | tlc("<%lc>", L'\t', "<\t>"); | ||
380 | tlc("<%lc>", 0x00fe, "<\xc3\xbe>"); | ||
381 | tlc("<%lc>", 0x03c0, "<\xcf\x80>"); | ||
382 | tlc_expect_fail("<%lc>", 0x123456); | ||
383 | tlc("<%-lc>", L'=', "<=>"); | ||
384 | tlc("<%-lc>", 0x03c0, "<\xcf\x80>"); | ||
385 | tlc("<%2lc>", L'=', "< =>"); | ||
386 | tlc("<%3lc>", 0x03c0, "< \xcf\x80>"); | ||
387 | tlc("<%-2lc>", L'=', "<= >"); | ||
388 | tlc("<%-3lc>", 0x03c0, "<\xcf\x80 >"); | ||
389 | |||
390 | tls("<%ls>", ws, "<\xd0\xa1\xd0\xbe\xd1\x84\xd1\x8f>"); | ||
391 | tls_expect_fail("<%ls>", wsbad); | ||
392 | tls("<%-ls>", ws, "<\xd0\xa1\xd0\xbe\xd1\x84\xd1\x8f>"); | ||
393 | tls("<%9ls>", ws, "< \xd0\xa1\xd0\xbe\xd1\x84\xd1\x8f>"); | ||
394 | tls("<%-9ls>", ws, "<\xd0\xa1\xd0\xbe\xd1\x84\xd1\x8f >"); | ||
395 | tls("<%.4ls>", ws, "<\xd0\xa1\xd0\xbe>"); | ||
396 | tls("<%.3ls>", ws, "<\xd0\xa1>"); | ||
397 | tls("<%6.4ls>", ws, "< \xd0\xa1\xd0\xbe>"); | ||
398 | tls("<%3.3ls>", ws, "< \xd0\xa1>"); | ||
399 | tls("<%-6.4ls>", ws, "<\xd0\xa1\xd0\xbe >"); | ||
400 | tls("<%-3.3ls>", ws, "<\xd0\xa1 >"); | ||
401 | |||
402 | /* | ||
403 | * Undefined behaviour of %lc and %ls in a UTF-8 locale. | ||
404 | */ | ||
405 | |||
406 | if (picky) { | ||
407 | tlc("<%#lc>", 0x03c0, "<\xcf\x80>"); | ||
408 | tlc("<% -4lc>", 0x03c0, "<\xcf\x80 >"); | ||
409 | tlc("<%+-4lc>", 0x03c0, "<\xcf\x80 >"); | ||
410 | tlc("<%04lc>", 0x03c0, "<00\xcf\x80>"); | ||
411 | tlc("<%-04lc>", 0x03c0, "<\xcf\x80 >"); | ||
412 | tlc("<%4.5lc>", 0x03c0, "< \xcf\x80>"); | ||
413 | tlc("<%4.3lc>", 0x03c0, "< \xcf\x80>"); | ||
414 | tlc("<%4.1lc>", 0x03c0, "< \xcf\x80>"); | ||
415 | tc("<%llc>", 0xfe, "<\xfe>"); | ||
416 | |||
417 | tls("<%#ls>", ws + 2, "<\xd1\x84\xd1\x8f>"); | ||
418 | tls("<% -6ls>", ws + 2, "<\xd1\x84\xd1\x8f >"); | ||
419 | tls("<%+-6ls>", ws + 2, "<\xd1\x84\xd1\x8f >"); | ||
420 | tls("<%06ls>", ws + 2, "<00\xd1\x84\xd1\x8f>"); | ||
421 | tls("<%-06ls>", ws + 2, "<\xd1\x84\xd1\x8f >"); | ||
422 | ts("<%lls>", "text", "<text>"); | ||
423 | } | ||
424 | |||
425 | /* | ||
426 | * Summarize the results. | ||
427 | */ | ||
428 | |||
429 | if (badret + badlen + badout) | ||
430 | errx(1, "ERRORS: %d fail + %d mismatch (incl. %d bad length)", | ||
431 | badret, badout, badlen); | ||
432 | else if (verbose) | ||
433 | warnx("SUCCESS"); | ||
434 | return 0; | ||
435 | } | ||
diff --git a/src/regress/lib/libc/qsort/Makefile b/src/regress/lib/libc/qsort/Makefile deleted file mode 100644 index 473432f423..0000000000 --- a/src/regress/lib/libc/qsort/Makefile +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2017/05/22 17:16:43 millert Exp $ | ||
2 | |||
3 | PROG= qsort_test | ||
4 | SRCS= qsort_test.c antiqsort.c | ||
5 | CFLAGS+=-Wall | ||
6 | |||
7 | qsort-regress: ${PROG} | ||
8 | ./${PROG} | ||
9 | |||
10 | REGRESS_TARGETS=qsort-regress | ||
11 | .PHONY: ${REGRESS_TARGETS} | ||
12 | |||
13 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/qsort/antiqsort.c b/src/regress/lib/libc/qsort/antiqsort.c deleted file mode 100644 index cb3b7b2525..0000000000 --- a/src/regress/lib/libc/qsort/antiqsort.c +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | /* | ||
2 | * A Killer Adversary for Quicksort | ||
3 | * M. D. MCILROY | ||
4 | * http://www.cs.dartmouth.edu/~doug/mdmspe.pdf | ||
5 | * | ||
6 | * For comparison: | ||
7 | * Bentley & McIlroy: 4096 items, 1645585 compares | ||
8 | * random pivot: 4096 items, 8388649 compares | ||
9 | * introsort: 4096 items, 151580 compares | ||
10 | * heapsort: 4096 items, 48233 compares | ||
11 | */ | ||
12 | |||
13 | #include <stdio.h> | ||
14 | #include <stdlib.h> | ||
15 | |||
16 | static int *val; /* item values */ | ||
17 | static int ncmp; /* number of comparisons */ | ||
18 | static int nsolid; /* number of solid items */ | ||
19 | static int candidate; /* pivot candidate */ | ||
20 | static int gas; /* gas value */ | ||
21 | |||
22 | #define freeze(x) (val[(x)] = nsolid++) | ||
23 | |||
24 | static int | ||
25 | cmp(const void *px, const void *py) | ||
26 | { | ||
27 | const int x = *(const int *)px; | ||
28 | const int y = *(const int *)py; | ||
29 | |||
30 | ncmp++; | ||
31 | if (val[x] == gas && val[y] == gas) { | ||
32 | if (x == candidate) | ||
33 | freeze(x); | ||
34 | else | ||
35 | freeze(y); | ||
36 | } | ||
37 | if (val[x] == gas) | ||
38 | candidate = x; | ||
39 | else if (val[y] == gas) | ||
40 | candidate = y; | ||
41 | return val[x] > val[y] ? 1 : val[x] < val[y] ? -1 : 0; | ||
42 | } | ||
43 | |||
44 | int | ||
45 | antiqsort(int n, int *a, int *ptr) | ||
46 | { | ||
47 | int i; | ||
48 | |||
49 | val = a; | ||
50 | gas = n - 1; | ||
51 | nsolid = ncmp = candidate = 0; | ||
52 | for (i = 0; i < n; i++) { | ||
53 | ptr[i] = i; | ||
54 | val[i] = gas; | ||
55 | } | ||
56 | qsort(ptr, n, sizeof(*ptr), cmp); | ||
57 | return ncmp; | ||
58 | } | ||
diff --git a/src/regress/lib/libc/qsort/qsort_test.c b/src/regress/lib/libc/qsort/qsort_test.c deleted file mode 100644 index 352c707718..0000000000 --- a/src/regress/lib/libc/qsort/qsort_test.c +++ /dev/null | |||
@@ -1,777 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017 Todd C. Miller <millert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <sys/time.h> | ||
18 | |||
19 | #include <stdbool.h> | ||
20 | #include <stdio.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | #include <setjmp.h> | ||
24 | #include <time.h> | ||
25 | #include <unistd.h> | ||
26 | #include <err.h> | ||
27 | |||
28 | /* | ||
29 | * Test program based on Bentley & McIlroy's "Engineering a Sort Function". | ||
30 | * Uses mergesort(3) to check the results. | ||
31 | * | ||
32 | * Additional "killer" input taken from: | ||
33 | * David R. Musser's "Introspective Sorting and Selection Algorithms" | ||
34 | * http://calmerthanyouare.org/2014/06/11/algorithmic-complexity-attacks-and-libc-qsort.html | ||
35 | * M. D. McIlroy's "A Killer Adversary for Quicksort" | ||
36 | */ | ||
37 | |||
38 | /* | ||
39 | * TODO: | ||
40 | * test with unaligned elements (char[]?) | ||
41 | */ | ||
42 | struct test_distribution { | ||
43 | const char *name; | ||
44 | void (*fill)(void *x, int n, int m); | ||
45 | int (*test)(struct test_distribution *d, int n, void *x, void *y, void *z); | ||
46 | int (*cmp)(const void *v1, const void *v2); | ||
47 | int (*cmp_checked)(const void *v1, const void *v2); | ||
48 | }; | ||
49 | |||
50 | #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) | ||
51 | #define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b)) | ||
52 | |||
53 | static size_t compares; | ||
54 | static size_t max_compares; | ||
55 | static size_t abrt_compares; | ||
56 | static sigjmp_buf cmpjmp; | ||
57 | static bool dump_table, timing, verbose; | ||
58 | |||
59 | extern int antiqsort(int n, int *a, int *ptr); | ||
60 | |||
61 | static int | ||
62 | cmp_i(const void *v1, const void *v2) | ||
63 | { | ||
64 | const int a = *(const int *)v1; | ||
65 | const int b = *(const int *)v2; | ||
66 | |||
67 | return a > b ? 1 : a < b ? -1 : 0; | ||
68 | } | ||
69 | |||
70 | static int | ||
71 | cmp_checked_i(const void *v1, const void *v2) | ||
72 | { | ||
73 | const int a = *(const int *)v1; | ||
74 | const int b = *(const int *)v2; | ||
75 | |||
76 | compares++; | ||
77 | if (compares > abrt_compares) | ||
78 | siglongjmp(cmpjmp, 1); | ||
79 | return a > b ? 1 : a < b ? -1 : 0; | ||
80 | } | ||
81 | |||
82 | static int | ||
83 | cmp_ll(const void *v1, const void *v2) | ||
84 | { | ||
85 | const long long a = *(const long long *)v1; | ||
86 | const long long b = *(const long long *)v2; | ||
87 | |||
88 | return a > b ? 1 : a < b ? -1 : 0; | ||
89 | } | ||
90 | |||
91 | static int | ||
92 | cmp_checked_ll(const void *v1, const void *v2) | ||
93 | { | ||
94 | const long long a = *(const long long *)v1; | ||
95 | const long long b = *(const long long *)v2; | ||
96 | |||
97 | compares++; | ||
98 | if (compares > abrt_compares) | ||
99 | siglongjmp(cmpjmp, 1); | ||
100 | return a > b ? 1 : a < b ? -1 : 0; | ||
101 | } | ||
102 | |||
103 | static int | ||
104 | cmp_d(const void *v1, const void *v2) | ||
105 | { | ||
106 | const double a = *(const double *)v1; | ||
107 | const double b = *(const double *)v2; | ||
108 | |||
109 | return a > b ? 1 : a < b ? -1 : 0; | ||
110 | } | ||
111 | |||
112 | static int | ||
113 | cmp_checked_d(const void *v1, const void *v2) | ||
114 | { | ||
115 | const double a = *(const double *)v1; | ||
116 | const double b = *(const double *)v2; | ||
117 | |||
118 | compares++; | ||
119 | if (compares > abrt_compares) | ||
120 | siglongjmp(cmpjmp, 1); | ||
121 | return a > b ? 1 : a < b ? -1 : 0; | ||
122 | } | ||
123 | |||
124 | static int | ||
125 | check_result(char *sub, size_t es, char *got, char *expected, struct test_distribution *d, | ||
126 | int m, int n) | ||
127 | { | ||
128 | int i; | ||
129 | |||
130 | if (verbose || compares > max_compares) { | ||
131 | if (sub != NULL) { | ||
132 | if (m != 0) { | ||
133 | warnx("%s (%s): m: %d, n: %d, %zu compares, " | ||
134 | "max %zu(%zu)", d->name, sub, m, n, | ||
135 | compares, max_compares, abrt_compares); | ||
136 | } else { | ||
137 | warnx("%s (%s): n: %d, %zu compares, " | ||
138 | "max %zu(%zu)", d->name, sub, n, | ||
139 | compares, max_compares, abrt_compares); | ||
140 | } | ||
141 | } else { | ||
142 | if (m != 0) { | ||
143 | warnx("%s: m: %d, n: %d, %zu compares, " | ||
144 | "max %zu(%zu)", d->name, m, n, | ||
145 | compares, max_compares, abrt_compares); | ||
146 | } else { | ||
147 | warnx("%s: n: %d, %zu compares, " | ||
148 | "max %zu(%zu)", d->name, n, | ||
149 | compares, max_compares, abrt_compares); | ||
150 | } | ||
151 | } | ||
152 | } | ||
153 | |||
154 | for (i = 0; i < n; i++) { | ||
155 | if (memcmp(got, expected, es) != 0) | ||
156 | break; | ||
157 | got += es; | ||
158 | expected += es; | ||
159 | } | ||
160 | if (i == n) | ||
161 | return 0; | ||
162 | |||
163 | if (sub != NULL) { | ||
164 | warnx("%s (%s): failure at %d, m: %d, n: %d", | ||
165 | d->name, sub, i, m, n); | ||
166 | } else { | ||
167 | warnx("%s: failure at %d, m: %d, n: %d", | ||
168 | d->name, i, m, n); | ||
169 | } | ||
170 | return 1; | ||
171 | } | ||
172 | |||
173 | #define FILL_SAWTOOTH(x, n, m) do { \ | ||
174 | int i; \ | ||
175 | \ | ||
176 | for (i = 0; i < n; i++) \ | ||
177 | x[i] = i % m; \ | ||
178 | } while (0) | ||
179 | |||
180 | static void | ||
181 | fill_sawtooth_i(void *v, int n, int m) | ||
182 | { | ||
183 | int *x = v; | ||
184 | FILL_SAWTOOTH(x, n, m); | ||
185 | } | ||
186 | |||
187 | static void | ||
188 | fill_sawtooth_ll(void *v, int n, int m) | ||
189 | { | ||
190 | long long *x = v; | ||
191 | FILL_SAWTOOTH(x, n, m); | ||
192 | } | ||
193 | |||
194 | static void | ||
195 | fill_sawtooth_double(void *v, int n, int m) | ||
196 | { | ||
197 | double *x = v; | ||
198 | FILL_SAWTOOTH(x, n, m); | ||
199 | } | ||
200 | |||
201 | #define FILL_RANDOM(x, n, m) do { \ | ||
202 | int i; \ | ||
203 | \ | ||
204 | for (i = 0; i < n; i++) \ | ||
205 | x[i] = arc4random_uniform(m); \ | ||
206 | } while (0) | ||
207 | |||
208 | |||
209 | static void | ||
210 | fill_random_i(void *v, int n, int m) | ||
211 | { | ||
212 | int *x = v; | ||
213 | FILL_RANDOM(x, n, m); | ||
214 | } | ||
215 | |||
216 | static void | ||
217 | fill_random_ll(void *v, int n, int m) | ||
218 | { | ||
219 | long long *x = v; | ||
220 | FILL_RANDOM(x, n, m); | ||
221 | } | ||
222 | |||
223 | static void | ||
224 | fill_random_double(void *v, int n, int m) | ||
225 | { | ||
226 | double *x = v; | ||
227 | FILL_RANDOM(x, n, m); | ||
228 | } | ||
229 | |||
230 | #define FILL_STAGGER(x, n, m) do { \ | ||
231 | int i; \ | ||
232 | \ | ||
233 | for (i = 0; i < n; i++) \ | ||
234 | x[i] = (i * m + i) % n; \ | ||
235 | } while (0) | ||
236 | |||
237 | |||
238 | static void | ||
239 | fill_stagger_i(void *v, int n, int m) | ||
240 | { | ||
241 | int *x = v; | ||
242 | FILL_STAGGER(x, n, m); | ||
243 | } | ||
244 | |||
245 | static void | ||
246 | fill_stagger_ll(void *v, int n, int m) | ||
247 | { | ||
248 | long long *x = v; | ||
249 | FILL_STAGGER(x, n, m); | ||
250 | } | ||
251 | |||
252 | static void | ||
253 | fill_stagger_double(void *v, int n, int m) | ||
254 | { | ||
255 | double *x = v; | ||
256 | FILL_STAGGER(x, n, m); | ||
257 | } | ||
258 | |||
259 | #define FILL_PLATEAU(x, n, m) do { \ | ||
260 | int i; \ | ||
261 | \ | ||
262 | for (i = 0; i < n; i++) \ | ||
263 | x[i] = MINIMUM(i, m); \ | ||
264 | } while (0) | ||
265 | |||
266 | static void | ||
267 | fill_plateau_i(void *v, int n, int m) | ||
268 | { | ||
269 | int *x = v; | ||
270 | FILL_PLATEAU(x, n, m); | ||
271 | } | ||
272 | |||
273 | static void | ||
274 | fill_plateau_ll(void *v, int n, int m) | ||
275 | { | ||
276 | long long *x = v; | ||
277 | FILL_PLATEAU(x, n, m); | ||
278 | } | ||
279 | |||
280 | static void | ||
281 | fill_plateau_double(void *v, int n, int m) | ||
282 | { | ||
283 | double *x = v; | ||
284 | FILL_PLATEAU(x, n, m); | ||
285 | } | ||
286 | |||
287 | #define FILL_SHUFFLE(x, n, m) do { \ | ||
288 | int i, j, k; \ | ||
289 | \ | ||
290 | for (i = 0, j = 0, k = 1; i < n; i++) \ | ||
291 | x[i] = arc4random_uniform(m) ? (j += 2) : (k += 2); \ | ||
292 | } while (0) | ||
293 | |||
294 | static void | ||
295 | fill_shuffle_i(void *v, int n, int m) | ||
296 | { | ||
297 | int *x = v; | ||
298 | FILL_SHUFFLE(x, n, m); | ||
299 | } | ||
300 | |||
301 | static void | ||
302 | fill_shuffle_ll(void *v, int n, int m) | ||
303 | { | ||
304 | long long *x = v; | ||
305 | FILL_SHUFFLE(x, n, m); | ||
306 | } | ||
307 | |||
308 | static void | ||
309 | fill_shuffle_double(void *v, int n, int m) | ||
310 | { | ||
311 | double *x = v; | ||
312 | FILL_SHUFFLE(x, n, m); | ||
313 | } | ||
314 | |||
315 | #define FILL_BSD_KILLER(x, n, m) do { \ | ||
316 | int i, k; \ | ||
317 | \ | ||
318 | /* 4.4BSD insertion sort optimization killer, Mats Linander */ \ | ||
319 | k = n / 2; \ | ||
320 | for (i = 0; i < n; i++) { \ | ||
321 | if (i < k) \ | ||
322 | x[i] = k - i; \ | ||
323 | else if (i > k) \ | ||
324 | x[i] = n + k + 1 - i; \ | ||
325 | else \ | ||
326 | x[i] = k + 1; \ | ||
327 | } \ | ||
328 | } while (0) | ||
329 | |||
330 | static void | ||
331 | fill_bsd_killer_i(void *v, int n, int m) | ||
332 | { | ||
333 | int *x = v; | ||
334 | FILL_BSD_KILLER(x, n, m); | ||
335 | |||
336 | } | ||
337 | |||
338 | static void | ||
339 | fill_bsd_killer_ll(void *v, int n, int m) | ||
340 | { | ||
341 | long long *x = v; | ||
342 | FILL_BSD_KILLER(x, n, m); | ||
343 | |||
344 | } | ||
345 | |||
346 | static void | ||
347 | fill_bsd_killer_double(void *v, int n, int m) | ||
348 | { | ||
349 | double *x = v; | ||
350 | FILL_BSD_KILLER(x, n, m); | ||
351 | |||
352 | } | ||
353 | |||
354 | #define FILL_MED3_KILLER(x, n, m) do { \ | ||
355 | int i, k; \ | ||
356 | \ | ||
357 | /* \ | ||
358 | * Median of 3 killer, as seen in David R Musser's \ | ||
359 | * "Introspective Sorting and Selection Algorithms" \ | ||
360 | */ \ | ||
361 | if (n & 1) { \ | ||
362 | /* odd size, store last at end and make even. */ \ | ||
363 | x[n - 1] = n; \ | ||
364 | n--; \ | ||
365 | } \ | ||
366 | k = n / 2; \ | ||
367 | for (i = 0; i < n; i++) { \ | ||
368 | if (i & 1) { \ | ||
369 | x[i] = k + x[i - 1]; \ | ||
370 | } else { \ | ||
371 | x[i] = i + 1; \ | ||
372 | } \ | ||
373 | } \ | ||
374 | } while (0) | ||
375 | |||
376 | static void | ||
377 | fill_med3_killer_i(void *v, int n, int m) | ||
378 | { | ||
379 | int *x = v; | ||
380 | FILL_MED3_KILLER(x, n, m); | ||
381 | } | ||
382 | |||
383 | static void | ||
384 | fill_med3_killer_ll(void *v, int n, int m) | ||
385 | { | ||
386 | long long *x = v; | ||
387 | FILL_MED3_KILLER(x, n, m); | ||
388 | } | ||
389 | |||
390 | static void | ||
391 | fill_med3_killer_double(void *v, int n, int m) | ||
392 | { | ||
393 | double *x = v; | ||
394 | FILL_MED3_KILLER(x, n, m); | ||
395 | } | ||
396 | |||
397 | static void | ||
398 | print_timing(struct test_distribution *d, char *sub, int m, int n, double elapsed) | ||
399 | { | ||
400 | if (sub != NULL) { | ||
401 | if (m != 0) { | ||
402 | warnx("%s (%s): m: %d, n: %d, %f seconds", | ||
403 | d->name, sub, m, n, elapsed); | ||
404 | } else { | ||
405 | warnx("%s (%s): n: %d, %f seconds", | ||
406 | d->name, sub, n, elapsed); | ||
407 | } | ||
408 | } else { | ||
409 | if (m != 0) { | ||
410 | warnx("%s: m: %d, n: %d, %f seconds", | ||
411 | d->name, m, n, elapsed); | ||
412 | } else { | ||
413 | warnx("%s: n: %d, %f seconds", | ||
414 | d->name, n, elapsed); | ||
415 | } | ||
416 | } | ||
417 | } | ||
418 | |||
419 | static int | ||
420 | do_test(struct test_distribution *d, char *sub, int m, int n, size_t es, void *y, void *z) | ||
421 | { | ||
422 | int ret = 0; | ||
423 | struct timespec before, after; | ||
424 | |||
425 | compares = 0; | ||
426 | if (sigsetjmp(cmpjmp, 1) != 0) { | ||
427 | if (sub != NULL) { | ||
428 | warnx("%s (%s): qsort aborted after %zu compares, m: %d, n: %d", | ||
429 | d->name, sub, compares, m, n); | ||
430 | } else { | ||
431 | warnx("%s: qsort aborted after %zu compares, m: %d, n: %d", | ||
432 | d->name, compares, m, n); | ||
433 | } | ||
434 | ret = 1; | ||
435 | } else { | ||
436 | if (timing) | ||
437 | clock_gettime(CLOCK_MONOTONIC, &before); | ||
438 | qsort(y, n, es, d->cmp_checked); | ||
439 | if (timing) { | ||
440 | double elapsed; | ||
441 | clock_gettime(CLOCK_MONOTONIC, &after); | ||
442 | timespecsub(&after, &before, &after); | ||
443 | elapsed = after.tv_sec + after.tv_nsec / 1000000000.0; | ||
444 | print_timing(d, sub, m, n, elapsed); | ||
445 | } | ||
446 | if (check_result(sub, es, y, z, d, m, n) != 0) | ||
447 | ret = 1; | ||
448 | } | ||
449 | return ret; | ||
450 | } | ||
451 | |||
452 | #define TEST_PERTURBED(d, n, x, y, z) do { \ | ||
453 | int i, j, m; \ | ||
454 | const int es = sizeof(x[0]); \ | ||
455 | \ | ||
456 | for (m = 1; m < 2 * n; m *= 2) { \ | ||
457 | /* Fill in x[n] modified by m */ \ | ||
458 | d->fill(x, n, m); \ | ||
459 | \ | ||
460 | /* Test on copy of x[] */ \ | ||
461 | for (i = 0; i < n; i++) \ | ||
462 | y[i] = z[i] = x[i]; \ | ||
463 | if (mergesort(z, n, es, d->cmp) != 0) \ | ||
464 | err(1, NULL); \ | ||
465 | if (do_test(d, "copy", m, n, es, y, z) != 0) \ | ||
466 | ret = 1; \ | ||
467 | \ | ||
468 | /* Test on reversed copy of x[] */ \ | ||
469 | for (i = 0, j = n - 1; i < n; i++, j--) \ | ||
470 | y[i] = z[i] = x[j]; \ | ||
471 | if (mergesort(z, n, es, d->cmp) != 0) \ | ||
472 | err(1, NULL); \ | ||
473 | if (do_test(d, "reversed", m, n, es, y, z) != 0) \ | ||
474 | ret = 1; \ | ||
475 | \ | ||
476 | /* Test with front half of x[] reversed */ \ | ||
477 | for (i = 0, j = (n / 2) - 1; i < n / 2; i++, j--) \ | ||
478 | y[i] = z[i] = x[j]; \ | ||
479 | for (; i < n; i++) \ | ||
480 | y[i] = z[i] = x[i]; \ | ||
481 | if (mergesort(z, n, es, d->cmp) != 0) \ | ||
482 | err(1, NULL); \ | ||
483 | if (do_test(d, "front reversed", m, n, es, y, z) != 0) \ | ||
484 | ret = 1; \ | ||
485 | \ | ||
486 | /* Test with back half of x[] reversed */ \ | ||
487 | for (i = 0; i < n / 2; i++) \ | ||
488 | y[i] = z[i] = x[i]; \ | ||
489 | for (j = n - 1; i < n; i++, j--) \ | ||
490 | y[i] = z[i] = x[j]; \ | ||
491 | if (mergesort(z, n, es, d->cmp) != 0) \ | ||
492 | err(1, NULL); \ | ||
493 | if (do_test(d, "back reversed", m, n, es, y, z) != 0) \ | ||
494 | ret = 1; \ | ||
495 | \ | ||
496 | /* Test on sorted copy of x[] */ \ | ||
497 | if (mergesort(x, n, es, d->cmp) != 0) \ | ||
498 | err(1, NULL); \ | ||
499 | for (i = 0; i < n; i++) \ | ||
500 | y[i] = x[i]; \ | ||
501 | if (do_test(d, "sorted", m, n, es, y, x) != 0) \ | ||
502 | ret = 1; \ | ||
503 | \ | ||
504 | /* Test with i%5 added to x[i] (dither) */ \ | ||
505 | for (i = 0, j = n - 1; i < n; i++, j--) \ | ||
506 | y[i] = z[i] = x[j] + (i % 5); \ | ||
507 | if (mergesort(z, n, es, d->cmp) != 0) \ | ||
508 | err(1, NULL); \ | ||
509 | if (do_test(d, "dithered", m, n, es, y, z) != 0) \ | ||
510 | ret = 1; \ | ||
511 | } \ | ||
512 | } while (0) | ||
513 | |||
514 | static int | ||
515 | test_perturbed_i(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
516 | { | ||
517 | int *x = vx; | ||
518 | int *y = vx; | ||
519 | int *z = vz; | ||
520 | int ret = 0; | ||
521 | |||
522 | TEST_PERTURBED(d, n, x, y, z); | ||
523 | return ret; | ||
524 | } | ||
525 | |||
526 | static int | ||
527 | test_perturbed_ll(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
528 | { | ||
529 | long long *x = vx; | ||
530 | long long *y = vx; | ||
531 | long long *z = vz; | ||
532 | int ret = 0; | ||
533 | |||
534 | TEST_PERTURBED(d, n, x, y, z); | ||
535 | return ret; | ||
536 | } | ||
537 | |||
538 | static int | ||
539 | test_perturbed_double(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
540 | { | ||
541 | double *x = vx; | ||
542 | double *y = vx; | ||
543 | double *z = vz; | ||
544 | int ret = 0; | ||
545 | |||
546 | TEST_PERTURBED(d, n, x, y, z); | ||
547 | return ret; | ||
548 | } | ||
549 | |||
550 | /* | ||
551 | * Like TEST_PERTURBED but because the input is tailored to cause | ||
552 | * quicksort to go quadratic we don't perturb the input. | ||
553 | */ | ||
554 | #define TEST_SIMPLE(d, n, x, y, z) do { \ | ||
555 | int i, ret = 0; \ | ||
556 | \ | ||
557 | /* Fill in x[n] */ \ | ||
558 | d->fill(x, n, 0); \ | ||
559 | \ | ||
560 | /* Make a copy of x[] */ \ | ||
561 | for (i = 0; i < n; i++) \ | ||
562 | y[i] = z[i] = x[i]; \ | ||
563 | if (mergesort(z, n, sizeof(z[0]), d->cmp) != 0) \ | ||
564 | err(1, NULL); \ | ||
565 | if (do_test(d, NULL, 0, n, sizeof(x[0]), y, z) != 0) \ | ||
566 | ret = 1; \ | ||
567 | } while (0) | ||
568 | |||
569 | static int | ||
570 | test_simple_i(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
571 | { | ||
572 | int *x = vx; | ||
573 | int *y = vx; | ||
574 | int *z = vz; | ||
575 | int ret = 0; | ||
576 | |||
577 | TEST_SIMPLE(d, n, x, y, z); | ||
578 | return ret; | ||
579 | } | ||
580 | |||
581 | static int | ||
582 | test_simple_ll(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
583 | { | ||
584 | long long *x = vx; | ||
585 | long long *y = vx; | ||
586 | long long *z = vz; | ||
587 | int ret = 0; | ||
588 | |||
589 | TEST_SIMPLE(d, n, x, y, z); | ||
590 | return ret; | ||
591 | } | ||
592 | |||
593 | static int | ||
594 | test_simple_double(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
595 | { | ||
596 | double *x = vx; | ||
597 | double *y = vx; | ||
598 | double *z = vz; | ||
599 | int ret = 0; | ||
600 | |||
601 | TEST_SIMPLE(d, n, x, y, z); | ||
602 | return ret; | ||
603 | } | ||
604 | |||
605 | /* | ||
606 | * Use D. McIlroy's "Killer Adversary for Quicksort" | ||
607 | * We don't compare the results in this case. | ||
608 | */ | ||
609 | static int | ||
610 | test_antiqsort(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
611 | { | ||
612 | struct timespec before, after; | ||
613 | int *x = vx; | ||
614 | int *y = vx; | ||
615 | int i, ret = 0; | ||
616 | |||
617 | /* | ||
618 | * We expect antiqsort to generate > 1.5 * nlgn compares. | ||
619 | * If introspection is not used, it will be > 10 * nlgn compares. | ||
620 | */ | ||
621 | if (timing) | ||
622 | clock_gettime(CLOCK_MONOTONIC, &before); | ||
623 | i = antiqsort(n, x, y); | ||
624 | if (timing) | ||
625 | clock_gettime(CLOCK_MONOTONIC, &after); | ||
626 | if (i > abrt_compares) | ||
627 | ret = 1; | ||
628 | if (dump_table) { | ||
629 | printf("/* %d items, %d compares */\n", n, i); | ||
630 | printf("static const int table_%d[] = {", n); | ||
631 | for (i = 0; i < n - 1; i++) { | ||
632 | if ((i % 12) == 0) | ||
633 | printf("\n\t"); | ||
634 | printf("%4d, ", x[i]); | ||
635 | } | ||
636 | printf("%4d\n};\n", x[i]); | ||
637 | } else { | ||
638 | if (timing) { | ||
639 | double elapsed; | ||
640 | timespecsub(&after, &before, &after); | ||
641 | elapsed = after.tv_sec + after.tv_nsec / 1000000000.0; | ||
642 | print_timing(d, NULL, 0, n, elapsed); | ||
643 | } | ||
644 | if (verbose || ret != 0) { | ||
645 | warnx("%s: n: %d, %d compares, max %zu(%zu)", | ||
646 | d->name, n, i, max_compares, abrt_compares); | ||
647 | } | ||
648 | } | ||
649 | |||
650 | return ret; | ||
651 | } | ||
652 | |||
653 | static struct test_distribution distributions[] = { | ||
654 | { "sawtooth_i", fill_sawtooth_i, test_perturbed_i, cmp_i, cmp_checked_i }, | ||
655 | { "sawtooth_ll", fill_sawtooth_ll, test_perturbed_ll, cmp_ll, cmp_checked_ll }, | ||
656 | { "sawtooth_d", fill_sawtooth_double, test_perturbed_double, cmp_d, cmp_checked_d }, | ||
657 | { "random_i", fill_random_i, test_perturbed_i, cmp_i, cmp_checked_i }, | ||
658 | { "random_ll", fill_random_ll, test_perturbed_ll, cmp_ll, cmp_checked_ll }, | ||
659 | { "random_d", fill_random_double, test_perturbed_double, cmp_d, cmp_checked_d }, | ||
660 | { "stagger_i", fill_stagger_i, test_perturbed_i, cmp_i, cmp_checked_i }, | ||
661 | { "stagger_ll", fill_stagger_ll, test_perturbed_ll, cmp_ll, cmp_checked_ll }, | ||
662 | { "stagger_d", fill_stagger_double, test_perturbed_double, cmp_d, cmp_checked_d }, | ||
663 | { "plateau_i", fill_plateau_i, test_perturbed_i, cmp_i, cmp_checked_i }, | ||
664 | { "plateau_ll", fill_plateau_ll, test_perturbed_ll, cmp_ll, cmp_checked_ll }, | ||
665 | { "plateau_d", fill_plateau_double, test_perturbed_double, cmp_d, cmp_checked_d }, | ||
666 | { "shuffle_i", fill_shuffle_i, test_perturbed_i, cmp_i, cmp_checked_i }, | ||
667 | { "shuffle_ll", fill_shuffle_ll, test_perturbed_ll, cmp_ll, cmp_checked_ll }, | ||
668 | { "shuffle_d", fill_shuffle_double, test_perturbed_double, cmp_d, cmp_checked_d }, | ||
669 | { "bsd_killer_i", fill_bsd_killer_i, test_simple_i, cmp_i, cmp_checked_i }, | ||
670 | { "bsd_killer_ll", fill_bsd_killer_ll, test_simple_ll, cmp_ll, cmp_checked_ll }, | ||
671 | { "bsd_killer_d", fill_bsd_killer_double, test_simple_double, cmp_d, cmp_checked_d }, | ||
672 | { "med3_killer_i", fill_med3_killer_i, test_simple_i, cmp_i, cmp_checked_i }, | ||
673 | { "med3_killer_ll", fill_med3_killer_ll, test_simple_ll, cmp_ll, cmp_checked_ll }, | ||
674 | { "med3_killer_d", fill_med3_killer_double, test_simple_double, cmp_d, cmp_checked_d }, | ||
675 | { "antiqsort", NULL, test_antiqsort, cmp_i, cmp_checked_i }, | ||
676 | { NULL } | ||
677 | }; | ||
678 | |||
679 | static int | ||
680 | run_tests(int n, const char *name) | ||
681 | { | ||
682 | void *x, *y, *z; | ||
683 | int i, nlgn = 0; | ||
684 | int ret = 0; | ||
685 | size_t es; | ||
686 | struct test_distribution *d; | ||
687 | |||
688 | /* | ||
689 | * We expect A*n*lg(n) compares where A is between 1 and 2. | ||
690 | * For A > 1.5, print a warning. | ||
691 | * For A > 10 abort the test since qsort has probably gone quadratic. | ||
692 | */ | ||
693 | for (i = n - 1; i > 0; i >>= 1) | ||
694 | nlgn++; | ||
695 | nlgn *= n; | ||
696 | max_compares = nlgn * 1.5; | ||
697 | abrt_compares = nlgn * 10; | ||
698 | |||
699 | /* Allocate enough space to store ints or doubles. */ | ||
700 | es = MAXIMUM(sizeof(int), sizeof(double)); | ||
701 | x = reallocarray(NULL, n, es); | ||
702 | y = reallocarray(NULL, n, es); | ||
703 | z = reallocarray(NULL, n, es); | ||
704 | if (x == NULL || y == NULL || z == NULL) | ||
705 | err(1, NULL); | ||
706 | |||
707 | for (d = distributions; d->name != NULL; d++) { | ||
708 | if (name != NULL && strncmp(name, d->name, strlen(name)) != 0) | ||
709 | continue; | ||
710 | if (d->test(d, n, x, y, z) != 0) | ||
711 | ret = 1; | ||
712 | } | ||
713 | |||
714 | free(x); | ||
715 | free(y); | ||
716 | free(z); | ||
717 | return ret; | ||
718 | } | ||
719 | |||
720 | __dead void | ||
721 | usage(void) | ||
722 | { | ||
723 | fprintf(stderr, "usage: qsort_test [-dvt] [-n test_name] [num ...]\n"); | ||
724 | exit(1); | ||
725 | } | ||
726 | |||
727 | int | ||
728 | main(int argc, char *argv[]) | ||
729 | { | ||
730 | char *nums[] = { "100", "1023", "1024", "1025", "4095", "4096", "4097" }; | ||
731 | struct test_distribution *d; | ||
732 | int ch, n, ret = 0; | ||
733 | char *name = NULL; | ||
734 | |||
735 | while ((ch = getopt(argc, argv, "dn:tv")) != -1) { | ||
736 | switch (ch) { | ||
737 | case 'd': | ||
738 | dump_table = true; | ||
739 | break; | ||
740 | case 'n': | ||
741 | for (d = distributions; d->name != NULL; d++) { | ||
742 | if (strncmp(optarg, d->name, strlen(optarg)) == 0) | ||
743 | break; | ||
744 | } | ||
745 | if (d->name == NULL) | ||
746 | errx(1, "unknown test %s", optarg); | ||
747 | name = optarg; | ||
748 | break; | ||
749 | case 't': | ||
750 | timing = true; | ||
751 | break; | ||
752 | case 'v': | ||
753 | verbose = true; | ||
754 | break; | ||
755 | default: | ||
756 | usage(); | ||
757 | break; | ||
758 | } | ||
759 | } | ||
760 | argc -= optind; | ||
761 | argv += optind; | ||
762 | |||
763 | if (argc == 0) { | ||
764 | argv = nums; | ||
765 | argc = sizeof(nums) / sizeof(nums[0]); | ||
766 | } | ||
767 | |||
768 | while (argc > 0) { | ||
769 | n = atoi(*argv); | ||
770 | if (run_tests(n, name) != 0) | ||
771 | ret = 1; | ||
772 | argc--; | ||
773 | argv++; | ||
774 | } | ||
775 | |||
776 | return ret; | ||
777 | } | ||
diff --git a/src/regress/lib/libc/regex/Makefile b/src/regress/lib/libc/regex/Makefile deleted file mode 100644 index 5b9a080209..0000000000 --- a/src/regress/lib/libc/regex/Makefile +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.11 2017/04/16 16:01:05 kettenis Exp $ | ||
2 | # $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $ | ||
3 | |||
4 | PROG= re | ||
5 | SRCS= main.c split.c debug.c regcomp.c regerror.c regexec.c regfree.c | ||
6 | .PATH: ${.CURDIR}/../../../../lib/libc/regex | ||
7 | CLEANFILES += t_exhaust | ||
8 | |||
9 | CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex -DREDEBUG -DPOSIX_MISTAKE | ||
10 | CFLAGS+= -D'DEF_WEAK(x)=asm("")' | ||
11 | |||
12 | TESTS= ${.CURDIR}/tests | ||
13 | |||
14 | REGRESS_TARGETS = do-reg do-reg-long do-reg-backref | ||
15 | # cannot run with large limits | ||
16 | #REGRESS_TARGETS += do-t_exhaust | ||
17 | |||
18 | do-reg: ${PROG} | ||
19 | ./re < ${TESTS} | ||
20 | do-reg-long: ${PROG} | ||
21 | ./re -el < ${TESTS} | ||
22 | do-reg-backref: ${PROG} | ||
23 | ./re -er < ${TESTS} | ||
24 | #do-t_exhaust: t_exhaust | ||
25 | # ./t_exhaust | ||
26 | |||
27 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/regex/debug.c b/src/regress/lib/libc/regex/debug.c deleted file mode 100644 index 7044a2a185..0000000000 --- a/src/regress/lib/libc/regex/debug.c +++ /dev/null | |||
@@ -1,208 +0,0 @@ | |||
1 | /* $OpenBSD: debug.c,v 1.5 2020/12/31 17:20:19 millert Exp $ */ | ||
2 | /* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */ | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <string.h> | ||
6 | #include <ctype.h> | ||
7 | #include <limits.h> | ||
8 | #include <stdlib.h> | ||
9 | #include <sys/types.h> | ||
10 | #include <regex.h> | ||
11 | |||
12 | #include "utils.h" | ||
13 | #include "regex2.h" | ||
14 | #include "debug.ih" | ||
15 | |||
16 | /* | ||
17 | - regprint - print a regexp for debugging | ||
18 | == void regprint(regex_t *r, FILE *d); | ||
19 | */ | ||
20 | void | ||
21 | regprint(r, d) | ||
22 | regex_t *r; | ||
23 | FILE *d; | ||
24 | { | ||
25 | register struct re_guts *g = r->re_g; | ||
26 | register int i; | ||
27 | register int c; | ||
28 | register int last; | ||
29 | |||
30 | fprintf(d, "%ld states", (long)g->nstates); | ||
31 | fprintf(d, ", first %ld last %ld", (long)g->firststate, | ||
32 | (long)g->laststate); | ||
33 | if (g->iflags&USEBOL) | ||
34 | fprintf(d, ", USEBOL"); | ||
35 | if (g->iflags&USEEOL) | ||
36 | fprintf(d, ", USEEOL"); | ||
37 | if (g->iflags&BAD) | ||
38 | fprintf(d, ", BAD"); | ||
39 | if (g->nsub > 0) | ||
40 | fprintf(d, ", nsub=%ld", (long)g->nsub); | ||
41 | if (g->must != NULL) | ||
42 | fprintf(d, ", must(%ld) `%*s'", (long)g->mlen, (int)g->mlen, | ||
43 | g->must); | ||
44 | if (g->backrefs) | ||
45 | fprintf(d, ", backrefs"); | ||
46 | if (g->nplus > 0) | ||
47 | fprintf(d, ", nplus %ld", (long)g->nplus); | ||
48 | fprintf(d, "\n"); | ||
49 | s_print(g, d); | ||
50 | } | ||
51 | |||
52 | /* | ||
53 | - s_print - print the strip for debugging | ||
54 | == static void s_print(register struct re_guts *g, FILE *d); | ||
55 | */ | ||
56 | static void | ||
57 | s_print(g, d) | ||
58 | register struct re_guts *g; | ||
59 | FILE *d; | ||
60 | { | ||
61 | register sop *s; | ||
62 | register cset *cs; | ||
63 | register int i; | ||
64 | register int done = 0; | ||
65 | register sop opnd; | ||
66 | register int col = 0; | ||
67 | register int last; | ||
68 | register sopno offset = 2; | ||
69 | # define GAP() { if (offset % 5 == 0) { \ | ||
70 | if (col > 40) { \ | ||
71 | fprintf(d, "\n\t"); \ | ||
72 | col = 0; \ | ||
73 | } else { \ | ||
74 | fprintf(d, " "); \ | ||
75 | col++; \ | ||
76 | } \ | ||
77 | } else \ | ||
78 | col++; \ | ||
79 | offset++; \ | ||
80 | } | ||
81 | |||
82 | if (OP(g->strip[0]) != OEND) | ||
83 | fprintf(d, "missing initial OEND!\n"); | ||
84 | for (s = &g->strip[1]; !done; s++) { | ||
85 | opnd = OPND(*s); | ||
86 | switch (OP(*s)) { | ||
87 | case OEND: | ||
88 | fprintf(d, "\n"); | ||
89 | done = 1; | ||
90 | break; | ||
91 | case OCHAR: | ||
92 | if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL) | ||
93 | fprintf(d, "\\%c", (char)opnd); | ||
94 | else | ||
95 | fprintf(d, "%s", regchar((char)opnd)); | ||
96 | break; | ||
97 | case OBOL: | ||
98 | fprintf(d, "^"); | ||
99 | break; | ||
100 | case OEOL: | ||
101 | fprintf(d, "$"); | ||
102 | break; | ||
103 | case OBOW: | ||
104 | fprintf(d, "\\{"); | ||
105 | break; | ||
106 | case OEOW: | ||
107 | fprintf(d, "\\}"); | ||
108 | break; | ||
109 | case OANY: | ||
110 | fprintf(d, "."); | ||
111 | break; | ||
112 | case OANYOF: | ||
113 | fprintf(d, "[(%ld)", (long)opnd); | ||
114 | cs = &g->sets[opnd]; | ||
115 | last = -1; | ||
116 | for (i = 0; i < g->csetsize+1; i++) /* +1 flushes */ | ||
117 | if (CHIN(cs, i) && i < g->csetsize) { | ||
118 | if (last < 0) { | ||
119 | fprintf(d, "%s", regchar(i)); | ||
120 | last = i; | ||
121 | } | ||
122 | } else { | ||
123 | if (last >= 0) { | ||
124 | if (last != i-1) | ||
125 | fprintf(d, "-%s", | ||
126 | regchar(i-1)); | ||
127 | last = -1; | ||
128 | } | ||
129 | } | ||
130 | fprintf(d, "]"); | ||
131 | break; | ||
132 | case OBACK_: | ||
133 | fprintf(d, "(\\<%ld>", (long)opnd); | ||
134 | break; | ||
135 | case O_BACK: | ||
136 | fprintf(d, "<%ld>\\)", (long)opnd); | ||
137 | break; | ||
138 | case OPLUS_: | ||
139 | fprintf(d, "(+"); | ||
140 | if (OP(*(s+opnd)) != O_PLUS) | ||
141 | fprintf(d, "<%ld>", (long)opnd); | ||
142 | break; | ||
143 | case O_PLUS: | ||
144 | if (OP(*(s-opnd)) != OPLUS_) | ||
145 | fprintf(d, "<%ld>", (long)opnd); | ||
146 | fprintf(d, "+)"); | ||
147 | break; | ||
148 | case OQUEST_: | ||
149 | fprintf(d, "(?"); | ||
150 | if (OP(*(s+opnd)) != O_QUEST) | ||
151 | fprintf(d, "<%ld>", (long)opnd); | ||
152 | break; | ||
153 | case O_QUEST: | ||
154 | if (OP(*(s-opnd)) != OQUEST_) | ||
155 | fprintf(d, "<%ld>", (long)opnd); | ||
156 | fprintf(d, "?)"); | ||
157 | break; | ||
158 | case OLPAREN: | ||
159 | fprintf(d, "((<%ld>", (long)opnd); | ||
160 | break; | ||
161 | case ORPAREN: | ||
162 | fprintf(d, "<%ld>))", (long)opnd); | ||
163 | break; | ||
164 | case OCH_: | ||
165 | fprintf(d, "<"); | ||
166 | if (OP(*(s+opnd)) != OOR2) | ||
167 | fprintf(d, "<%ld>", (long)opnd); | ||
168 | break; | ||
169 | case OOR1: | ||
170 | if (OP(*(s-opnd)) != OOR1 && OP(*(s-opnd)) != OCH_) | ||
171 | fprintf(d, "<%ld>", (long)opnd); | ||
172 | fprintf(d, "|"); | ||
173 | break; | ||
174 | case OOR2: | ||
175 | fprintf(d, "|"); | ||
176 | if (OP(*(s+opnd)) != OOR2 && OP(*(s+opnd)) != O_CH) | ||
177 | fprintf(d, "<%ld>", (long)opnd); | ||
178 | break; | ||
179 | case O_CH: | ||
180 | if (OP(*(s-opnd)) != OOR1) | ||
181 | fprintf(d, "<%ld>", (long)opnd); | ||
182 | fprintf(d, ">"); | ||
183 | break; | ||
184 | default: | ||
185 | fprintf(d, "!%ld(%ld)!", (long)OP(*s), (long)opnd); | ||
186 | break; | ||
187 | } | ||
188 | if (!done) | ||
189 | GAP(); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | /* | ||
194 | - regchar - make a character printable | ||
195 | == static char *regchar(int ch); | ||
196 | */ | ||
197 | static char * /* -> representation */ | ||
198 | regchar(ch) | ||
199 | int ch; | ||
200 | { | ||
201 | static char buf[10]; | ||
202 | |||
203 | if (isprint(ch) || ch == ' ') | ||
204 | snprintf(buf, sizeof buf, "%c", ch); | ||
205 | else | ||
206 | snprintf(buf, sizeof buf, "\\%o", ch); | ||
207 | return(buf); | ||
208 | } | ||
diff --git a/src/regress/lib/libc/regex/debug.ih b/src/regress/lib/libc/regex/debug.ih deleted file mode 100644 index 9eb313af23..0000000000 --- a/src/regress/lib/libc/regex/debug.ih +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | /* $OpenBSD: debug.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
2 | /* $NetBSD: debug.ih,v 1.2 1995/04/20 22:39:47 cgd Exp $ */ | ||
3 | |||
4 | /* ========= begin header generated by ./mkh ========= */ | ||
5 | #ifdef __cplusplus | ||
6 | extern "C" { | ||
7 | #endif | ||
8 | |||
9 | /* === debug.c === */ | ||
10 | void regprint(regex_t *r, FILE *d); | ||
11 | static void s_print(register struct re_guts *g, FILE *d); | ||
12 | static char *regchar(int ch); | ||
13 | |||
14 | #ifdef __cplusplus | ||
15 | } | ||
16 | #endif | ||
17 | /* ========= end header generated by ./mkh ========= */ | ||
diff --git a/src/regress/lib/libc/regex/main.c b/src/regress/lib/libc/regex/main.c deleted file mode 100644 index 4501e86b87..0000000000 --- a/src/regress/lib/libc/regex/main.c +++ /dev/null | |||
@@ -1,516 +0,0 @@ | |||
1 | /* $OpenBSD: main.c,v 1.12 2022/12/04 23:50:46 cheloha Exp $ */ | ||
2 | /* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */ | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <stdlib.h> | ||
6 | #include <string.h> | ||
7 | #include <sys/types.h> | ||
8 | #include <regex.h> | ||
9 | #include <assert.h> | ||
10 | #include <unistd.h> | ||
11 | |||
12 | #include "main.ih" | ||
13 | |||
14 | char *progname; | ||
15 | int debug = 0; | ||
16 | int line = 0; | ||
17 | int status = 0; | ||
18 | |||
19 | int copts = REG_EXTENDED; | ||
20 | int eopts = 0; | ||
21 | regoff_t startoff = 0; | ||
22 | regoff_t endoff = 0; | ||
23 | |||
24 | |||
25 | extern int split(char *, char *[], int, char *); | ||
26 | extern void regprint(regex_t *, FILE *); | ||
27 | |||
28 | /* | ||
29 | - main - do the simple case, hand off to regress() for regression | ||
30 | */ | ||
31 | int | ||
32 | main(int argc, char *argv[]) | ||
33 | |||
34 | { | ||
35 | regex_t re; | ||
36 | # define NS 10 | ||
37 | regmatch_t subs[NS]; | ||
38 | char erbuf[100]; | ||
39 | int err; | ||
40 | size_t len; | ||
41 | int c; | ||
42 | int errflg = 0; | ||
43 | register int i; | ||
44 | |||
45 | progname = argv[0]; | ||
46 | |||
47 | while ((c = getopt(argc, argv, "c:E:e:S:x")) != -1) | ||
48 | switch (c) { | ||
49 | case 'c': /* compile options */ | ||
50 | copts = options('c', optarg); | ||
51 | break; | ||
52 | case 'E': /* end offset */ | ||
53 | endoff = (regoff_t)atoi(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 'x': /* Debugging. */ | ||
62 | debug++; | ||
63 | break; | ||
64 | default: | ||
65 | errflg++; | ||
66 | break; | ||
67 | } | ||
68 | if (errflg) { | ||
69 | fprintf(stderr, "usage: %s ", progname); | ||
70 | fprintf(stderr, "[-x] [-c copt] [-E endoff] [-e eopt] [-S startoff] [re]\n"); | ||
71 | exit(2); | ||
72 | } | ||
73 | |||
74 | if (optind >= argc) { | ||
75 | regress(stdin); | ||
76 | exit(status); | ||
77 | } | ||
78 | |||
79 | err = regcomp(&re, argv[optind++], copts); | ||
80 | if (err) { | ||
81 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
82 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", | ||
83 | eprint(err), len, sizeof(erbuf), erbuf); | ||
84 | exit(status); | ||
85 | } | ||
86 | regprint(&re, stdout); | ||
87 | |||
88 | if (optind >= argc) { | ||
89 | regfree(&re); | ||
90 | exit(status); | ||
91 | } | ||
92 | |||
93 | if (eopts®_STARTEND) { | ||
94 | subs[0].rm_so = startoff; | ||
95 | subs[0].rm_eo = strlen(argv[optind]) - endoff; | ||
96 | } | ||
97 | err = regexec(&re, argv[optind], (size_t)NS, subs, eopts); | ||
98 | if (err) { | ||
99 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
100 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", | ||
101 | eprint(err), len, sizeof(erbuf), erbuf); | ||
102 | exit(status); | ||
103 | } | ||
104 | if (!(copts®_NOSUB)) { | ||
105 | len = (size_t)(subs[0].rm_eo - subs[0].rm_so); | ||
106 | if (subs[0].rm_so != -1) { | ||
107 | if (len != 0) | ||
108 | printf("match `%.*s'\n", (int)len, | ||
109 | argv[optind] + subs[0].rm_so); | ||
110 | else | ||
111 | printf("match `'@%.1s\n", | ||
112 | argv[optind] + subs[0].rm_so); | ||
113 | } | ||
114 | for (i = 1; i < NS; i++) | ||
115 | if (subs[i].rm_so != -1) | ||
116 | printf("(%d) `%.*s'\n", i, | ||
117 | (int)(subs[i].rm_eo - subs[i].rm_so), | ||
118 | argv[optind] + subs[i].rm_so); | ||
119 | } | ||
120 | exit(status); | ||
121 | } | ||
122 | |||
123 | /* | ||
124 | - regress - main loop of regression test | ||
125 | == void regress(FILE *in); | ||
126 | */ | ||
127 | void | ||
128 | regress(in) | ||
129 | FILE *in; | ||
130 | { | ||
131 | char inbuf[1000]; | ||
132 | # define MAXF 10 | ||
133 | char *f[MAXF]; | ||
134 | int nf; | ||
135 | int i; | ||
136 | char erbuf[100]; | ||
137 | size_t ne; | ||
138 | char *badpat = "invalid regular expression"; | ||
139 | # define SHORT 10 | ||
140 | char *bpname = "REG_BADPAT"; | ||
141 | regex_t re; | ||
142 | |||
143 | while (fgets(inbuf, sizeof(inbuf), in) != NULL) { | ||
144 | line++; | ||
145 | if (inbuf[0] == '#' || inbuf[0] == '\n') | ||
146 | continue; /* NOTE CONTINUE */ | ||
147 | inbuf[strcspn(inbuf, "\n")] = '\0'; /* get rid of stupid \n */ | ||
148 | if (debug) | ||
149 | fprintf(stdout, "%d:\n", line); | ||
150 | nf = split(inbuf, f, MAXF, "\t\t"); | ||
151 | if (nf < 3) { | ||
152 | fprintf(stderr, "bad input, line %d\n", line); | ||
153 | exit(1); | ||
154 | } | ||
155 | for (i = 0; i < nf; i++) | ||
156 | if (strcmp(f[i], "\"\"") == 0) | ||
157 | f[i] = ""; | ||
158 | if (nf <= 3) | ||
159 | f[3] = NULL; | ||
160 | if (nf <= 4) | ||
161 | f[4] = NULL; | ||
162 | try(f[0], f[1], f[2], f[3], f[4], options('c', f[1])); | ||
163 | if (opt('&', f[1])) /* try with either type of RE */ | ||
164 | try(f[0], f[1], f[2], f[3], f[4], | ||
165 | options('c', f[1]) &~ REG_EXTENDED); | ||
166 | } | ||
167 | |||
168 | ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf)); | ||
169 | if (strcmp(erbuf, badpat) != 0 || ne != strlen(badpat)+1) { | ||
170 | fprintf(stderr, "end: regerror() test gave `%s' not `%s'\n", | ||
171 | erbuf, badpat); | ||
172 | status = 1; | ||
173 | } | ||
174 | ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, (size_t)SHORT); | ||
175 | if (strncmp(erbuf, badpat, SHORT-1) != 0 || erbuf[SHORT-1] != '\0' || | ||
176 | ne != strlen(badpat)+1) { | ||
177 | fprintf(stderr, "end: regerror() short test gave `%s' not `%.*s'\n", | ||
178 | erbuf, SHORT-1, badpat); | ||
179 | status = 1; | ||
180 | } | ||
181 | ne = regerror(REG_ITOA|REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf)); | ||
182 | if (strcmp(erbuf, bpname) != 0 || ne != strlen(bpname)+1) { | ||
183 | fprintf(stderr, "end: regerror() ITOA test gave `%s' not `%s'\n", | ||
184 | erbuf, bpname); | ||
185 | status = 1; | ||
186 | } | ||
187 | re.re_endp = bpname; | ||
188 | ne = regerror(REG_ATOI, &re, erbuf, sizeof(erbuf)); | ||
189 | if (atoi(erbuf) != (int)REG_BADPAT) { | ||
190 | fprintf(stderr, "end: regerror() ATOI test gave `%s' not `%ld'\n", | ||
191 | erbuf, (long)REG_BADPAT); | ||
192 | status = 1; | ||
193 | } else if (ne != strlen(erbuf)+1) { | ||
194 | fprintf(stderr, "end: regerror() ATOI test len(`%s') = %ld\n", | ||
195 | erbuf, (long)REG_BADPAT); | ||
196 | status = 1; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | /* | ||
201 | - try - try it, and report on problems | ||
202 | == void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); | ||
203 | */ | ||
204 | void | ||
205 | try(f0, f1, f2, f3, f4, opts) | ||
206 | char *f0; | ||
207 | char *f1; | ||
208 | char *f2; | ||
209 | char *f3; | ||
210 | char *f4; | ||
211 | int opts; /* may not match f1 */ | ||
212 | { | ||
213 | regex_t re; | ||
214 | # define NSUBS 10 | ||
215 | regmatch_t subs[NSUBS]; | ||
216 | # define NSHOULD 15 | ||
217 | char *should[NSHOULD]; | ||
218 | int nshould; | ||
219 | char erbuf[100]; | ||
220 | int err; | ||
221 | int len; | ||
222 | char *type = (opts & REG_EXTENDED) ? "ERE" : "BRE"; | ||
223 | register int i; | ||
224 | char *grump; | ||
225 | char f0copy[1000]; | ||
226 | char f2copy[1000]; | ||
227 | |||
228 | strlcpy(f0copy, f0, sizeof f0copy); | ||
229 | re.re_endp = (opts®_PEND) ? f0copy + strlen(f0copy) : NULL; | ||
230 | fixstr(f0copy); | ||
231 | err = regcomp(&re, f0copy, opts); | ||
232 | if (err != 0 && (!opt('C', f1) || err != efind(f2))) { | ||
233 | /* unexpected error or wrong error */ | ||
234 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
235 | fprintf(stderr, "%d: %s error %s, %d/%zu `%s'\n", | ||
236 | line, type, eprint(err), len, | ||
237 | sizeof(erbuf), erbuf); | ||
238 | status = 1; | ||
239 | } else if (err == 0 && opt('C', f1)) { | ||
240 | /* unexpected success */ | ||
241 | fprintf(stderr, "%d: %s should have given REG_%s\n", | ||
242 | line, type, f2); | ||
243 | status = 1; | ||
244 | err = 1; /* so we won't try regexec */ | ||
245 | } | ||
246 | |||
247 | if (err != 0) { | ||
248 | regfree(&re); | ||
249 | return; | ||
250 | } | ||
251 | |||
252 | strlcpy(f2copy, f2, sizeof f2copy); | ||
253 | fixstr(f2copy); | ||
254 | |||
255 | if (options('e', f1)®_STARTEND) { | ||
256 | if (strchr(f2, '(') == NULL || strchr(f2, ')') == NULL) | ||
257 | fprintf(stderr, "%d: bad STARTEND syntax\n", line); | ||
258 | subs[0].rm_so = strchr(f2, '(') - f2 + 1; | ||
259 | subs[0].rm_eo = strchr(f2, ')') - f2; | ||
260 | /* the preceding character is relevant with REG_NOTBOL */ | ||
261 | f2copy[subs[0].rm_so - 1] = subs[0].rm_so > 1 ? | ||
262 | f2copy[subs[0].rm_so - 2] : 'X'; | ||
263 | } | ||
264 | err = regexec(&re, f2copy, NSUBS, subs, options('e', f1)); | ||
265 | |||
266 | if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) { | ||
267 | /* unexpected error or wrong error */ | ||
268 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
269 | fprintf(stderr, "%d: %s exec error %s, %d/%zu `%s'\n", | ||
270 | line, type, eprint(err), len, | ||
271 | sizeof(erbuf), erbuf); | ||
272 | status = 1; | ||
273 | } else if (err != 0) { | ||
274 | /* nothing more to check */ | ||
275 | } else if (f3 == NULL) { | ||
276 | /* unexpected success */ | ||
277 | fprintf(stderr, "%d: %s exec should have failed\n", | ||
278 | line, type); | ||
279 | status = 1; | ||
280 | err = 1; /* just on principle */ | ||
281 | } else if (opts®_NOSUB) { | ||
282 | /* nothing more to check */ | ||
283 | } else if ((grump = check(f2, subs[0], f3)) != NULL) { | ||
284 | fprintf(stderr, "%d: %s %s\n", line, type, grump); | ||
285 | status = 1; | ||
286 | err = 1; | ||
287 | } | ||
288 | |||
289 | if (err != 0 || f4 == NULL) { | ||
290 | regfree(&re); | ||
291 | return; | ||
292 | } | ||
293 | |||
294 | for (i = 1; i < NSHOULD; i++) | ||
295 | should[i] = NULL; | ||
296 | nshould = split(f4, should+1, NSHOULD-1, ","); | ||
297 | if (nshould == 0) { | ||
298 | nshould = 1; | ||
299 | should[1] = ""; | ||
300 | } | ||
301 | for (i = 1; i < NSUBS; i++) { | ||
302 | grump = check(f2, subs[i], should[i]); | ||
303 | if (grump != NULL) { | ||
304 | fprintf(stderr, "%d: %s $%d %s\n", line, | ||
305 | type, i, grump); | ||
306 | status = 1; | ||
307 | err = 1; | ||
308 | } | ||
309 | } | ||
310 | |||
311 | regfree(&re); | ||
312 | } | ||
313 | |||
314 | /* | ||
315 | - options - pick options out of a regression-test string | ||
316 | == int options(int type, char *s); | ||
317 | */ | ||
318 | int | ||
319 | options(type, s) | ||
320 | int type; /* 'c' compile, 'e' exec */ | ||
321 | char *s; | ||
322 | { | ||
323 | register char *p; | ||
324 | register int o = (type == 'c') ? copts : eopts; | ||
325 | register char *legal = (type == 'c') ? "bisnmp" : "^$#tl"; | ||
326 | |||
327 | for (p = s; *p != '\0'; p++) | ||
328 | if (strchr(legal, *p) != NULL) | ||
329 | switch (*p) { | ||
330 | case 'b': | ||
331 | o &= ~REG_EXTENDED; | ||
332 | break; | ||
333 | case 'i': | ||
334 | o |= REG_ICASE; | ||
335 | break; | ||
336 | case 's': | ||
337 | o |= REG_NOSUB; | ||
338 | break; | ||
339 | case 'n': | ||
340 | o |= REG_NEWLINE; | ||
341 | break; | ||
342 | case 'm': | ||
343 | o &= ~REG_EXTENDED; | ||
344 | o |= REG_NOSPEC; | ||
345 | break; | ||
346 | case 'p': | ||
347 | o |= REG_PEND; | ||
348 | break; | ||
349 | case '^': | ||
350 | o |= REG_NOTBOL; | ||
351 | break; | ||
352 | case '$': | ||
353 | o |= REG_NOTEOL; | ||
354 | break; | ||
355 | case '#': | ||
356 | o |= REG_STARTEND; | ||
357 | break; | ||
358 | case 't': /* trace */ | ||
359 | o |= REG_TRACE; | ||
360 | break; | ||
361 | case 'l': /* force long representation */ | ||
362 | o |= REG_LARGE; | ||
363 | break; | ||
364 | case 'r': /* force backref use */ | ||
365 | o |= REG_BACKR; | ||
366 | break; | ||
367 | } | ||
368 | return(o); | ||
369 | } | ||
370 | |||
371 | /* | ||
372 | - opt - is a particular option in a regression string? | ||
373 | == int opt(int c, char *s); | ||
374 | */ | ||
375 | int /* predicate */ | ||
376 | opt(c, s) | ||
377 | int c; | ||
378 | char *s; | ||
379 | { | ||
380 | return(strchr(s, c) != NULL); | ||
381 | } | ||
382 | |||
383 | /* | ||
384 | - fixstr - transform magic characters in strings | ||
385 | == void fixstr(register char *p); | ||
386 | */ | ||
387 | void | ||
388 | fixstr(p) | ||
389 | register char *p; | ||
390 | { | ||
391 | if (p == NULL) | ||
392 | return; | ||
393 | |||
394 | for (; *p != '\0'; p++) | ||
395 | if (*p == 'N') | ||
396 | *p = '\n'; | ||
397 | else if (*p == 'T') | ||
398 | *p = '\t'; | ||
399 | else if (*p == 'S') | ||
400 | *p = ' '; | ||
401 | else if (*p == 'Z') | ||
402 | *p = '\0'; | ||
403 | } | ||
404 | |||
405 | /* | ||
406 | - check - check a substring match | ||
407 | == char *check(char *str, regmatch_t sub, char *should); | ||
408 | */ | ||
409 | char * /* NULL or complaint */ | ||
410 | check(str, sub, should) | ||
411 | char *str; | ||
412 | regmatch_t sub; | ||
413 | char *should; | ||
414 | { | ||
415 | register int len; | ||
416 | register int shlen; | ||
417 | register char *p; | ||
418 | static char grump[500]; | ||
419 | register char *at = NULL; | ||
420 | |||
421 | if (should != NULL && strcmp(should, "-") == 0) | ||
422 | should = NULL; | ||
423 | if (should != NULL && should[0] == '@') { | ||
424 | at = should + 1; | ||
425 | should = ""; | ||
426 | } | ||
427 | |||
428 | /* check rm_so and rm_eo for consistency */ | ||
429 | if (sub.rm_so > sub.rm_eo || (sub.rm_so == -1 && sub.rm_eo != -1) || | ||
430 | (sub.rm_so != -1 && sub.rm_eo == -1) || | ||
431 | (sub.rm_so != -1 && sub.rm_so < 0) || | ||
432 | (sub.rm_eo != -1 && sub.rm_eo < 0) ) { | ||
433 | snprintf(grump, sizeof grump, | ||
434 | "start %ld end %ld", (long)sub.rm_so, | ||
435 | (long)sub.rm_eo); | ||
436 | return(grump); | ||
437 | } | ||
438 | |||
439 | /* check for no match */ | ||
440 | if (sub.rm_so == -1 && should == NULL) | ||
441 | return(NULL); | ||
442 | if (sub.rm_so == -1) | ||
443 | return("did not match"); | ||
444 | |||
445 | /* check for in range */ | ||
446 | if (sub.rm_eo > strlen(str)) { | ||
447 | snprintf(grump, sizeof grump, | ||
448 | "start %ld end %ld, past end of string", | ||
449 | (long)sub.rm_so, (long)sub.rm_eo); | ||
450 | return(grump); | ||
451 | } | ||
452 | |||
453 | len = (int)(sub.rm_eo - sub.rm_so); | ||
454 | p = str + sub.rm_so; | ||
455 | |||
456 | /* check for not supposed to match */ | ||
457 | if (should == NULL) { | ||
458 | snprintf(grump, sizeof grump, "matched `%.*s'", len, p); | ||
459 | return(grump); | ||
460 | } | ||
461 | |||
462 | /* check for wrong match */ | ||
463 | shlen = (int)strlen(should); | ||
464 | if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { | ||
465 | snprintf(grump, sizeof grump, "matched `%.*s' instead", len, p); | ||
466 | return(grump); | ||
467 | } | ||
468 | if (shlen > 0) | ||
469 | return(NULL); | ||
470 | |||
471 | /* check null match in right place */ | ||
472 | if (at == NULL) | ||
473 | return(NULL); | ||
474 | shlen = strlen(at); | ||
475 | if (shlen == 0) | ||
476 | shlen = 1; /* force check for end-of-string */ | ||
477 | if (strncmp(p, at, shlen) != 0) { | ||
478 | snprintf(grump, sizeof grump, "matched null at `%.20s'", p); | ||
479 | return(grump); | ||
480 | } | ||
481 | return(NULL); | ||
482 | } | ||
483 | |||
484 | /* | ||
485 | - eprint - convert error number to name | ||
486 | == static char *eprint(int err); | ||
487 | */ | ||
488 | static char * | ||
489 | eprint(err) | ||
490 | int err; | ||
491 | { | ||
492 | static char epbuf[100]; | ||
493 | size_t len; | ||
494 | |||
495 | len = regerror(REG_ITOA|err, (regex_t *)NULL, epbuf, sizeof(epbuf)); | ||
496 | assert(len <= sizeof(epbuf)); | ||
497 | return(epbuf); | ||
498 | } | ||
499 | |||
500 | /* | ||
501 | - efind - convert error name to number | ||
502 | == static int efind(char *name); | ||
503 | */ | ||
504 | static int | ||
505 | efind(name) | ||
506 | char *name; | ||
507 | { | ||
508 | static char efbuf[100]; | ||
509 | regex_t re; | ||
510 | |||
511 | snprintf(efbuf, sizeof efbuf, "REG_%s", name); | ||
512 | assert(strlen(efbuf) < sizeof(efbuf)); | ||
513 | re.re_endp = efbuf; | ||
514 | (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf)); | ||
515 | return(atoi(efbuf)); | ||
516 | } | ||
diff --git a/src/regress/lib/libc/regex/main.ih b/src/regress/lib/libc/regex/main.ih deleted file mode 100644 index 0860e26333..0000000000 --- a/src/regress/lib/libc/regex/main.ih +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | /* $OpenBSD: main.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
2 | /* $NetBSD: main.ih,v 1.2 1995/04/20 22:39:55 cgd Exp $ */ | ||
3 | |||
4 | /* ========= begin header generated by ./mkh ========= */ | ||
5 | #ifdef __cplusplus | ||
6 | extern "C" { | ||
7 | #endif | ||
8 | |||
9 | /* === main.c === */ | ||
10 | void regress(FILE *in); | ||
11 | void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); | ||
12 | int options(int type, char *s); | ||
13 | int opt(int c, char *s); | ||
14 | void fixstr(register char *p); | ||
15 | char *check(char *str, regmatch_t sub, char *should); | ||
16 | static char *eprint(int err); | ||
17 | static int efind(char *name); | ||
18 | |||
19 | #ifdef __cplusplus | ||
20 | } | ||
21 | #endif | ||
22 | /* ========= end header generated by ./mkh ========= */ | ||
diff --git a/src/regress/lib/libc/regex/split.c b/src/regress/lib/libc/regex/split.c deleted file mode 100644 index fcd81a3503..0000000000 --- a/src/regress/lib/libc/regex/split.c +++ /dev/null | |||
@@ -1,317 +0,0 @@ | |||
1 | /* $OpenBSD: split.c,v 1.5 2007/09/09 23:25:12 chl Exp $ */ | ||
2 | /* $NetBSD: split.c,v 1.2 1995/04/20 22:39:57 cgd Exp $ */ | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <string.h> | ||
6 | |||
7 | int split(char *string, char *fields[], int nfields, char *sep); | ||
8 | |||
9 | /* | ||
10 | - split - divide a string into fields, like awk split() | ||
11 | = int split(char *string, char *fields[], int nfields, char *sep); | ||
12 | */ | ||
13 | int /* number of fields, including overflow */ | ||
14 | split(char *string, char *fields[], int nfields, char *sep) | ||
15 | { | ||
16 | register char *p = string; | ||
17 | register char c; /* latest character */ | ||
18 | register char sepc = sep[0]; | ||
19 | register char sepc2; | ||
20 | register int fn; | ||
21 | register char **fp = fields; | ||
22 | register char *sepp; | ||
23 | register int trimtrail; | ||
24 | |||
25 | /* white space */ | ||
26 | if (sepc == '\0') { | ||
27 | while ((c = *p++) == ' ' || c == '\t') | ||
28 | continue; | ||
29 | p--; | ||
30 | trimtrail = 1; | ||
31 | sep = " \t"; /* note, code below knows this is 2 long */ | ||
32 | sepc = ' '; | ||
33 | } else | ||
34 | trimtrail = 0; | ||
35 | sepc2 = sep[1]; /* now we can safely pick this up */ | ||
36 | |||
37 | /* catch empties */ | ||
38 | if (*p == '\0') | ||
39 | return(0); | ||
40 | |||
41 | /* single separator */ | ||
42 | if (sepc2 == '\0') { | ||
43 | fn = nfields; | ||
44 | for (;;) { | ||
45 | *fp++ = p; | ||
46 | fn--; | ||
47 | if (fn == 0) | ||
48 | break; | ||
49 | while ((c = *p++) != sepc) | ||
50 | if (c == '\0') | ||
51 | return(nfields - fn); | ||
52 | *(p-1) = '\0'; | ||
53 | } | ||
54 | /* we have overflowed the fields vector -- just count them */ | ||
55 | fn = nfields; | ||
56 | for (;;) { | ||
57 | while ((c = *p++) != sepc) | ||
58 | if (c == '\0') | ||
59 | return(fn); | ||
60 | fn++; | ||
61 | } | ||
62 | /* not reached */ | ||
63 | } | ||
64 | |||
65 | /* two separators */ | ||
66 | if (sep[2] == '\0') { | ||
67 | fn = nfields; | ||
68 | for (;;) { | ||
69 | *fp++ = p; | ||
70 | fn--; | ||
71 | while ((c = *p++) != sepc && c != sepc2) | ||
72 | if (c == '\0') { | ||
73 | if (trimtrail && **(fp-1) == '\0') | ||
74 | fn++; | ||
75 | return(nfields - fn); | ||
76 | } | ||
77 | if (fn == 0) | ||
78 | break; | ||
79 | *(p-1) = '\0'; | ||
80 | while ((c = *p++) == sepc || c == sepc2) | ||
81 | continue; | ||
82 | p--; | ||
83 | } | ||
84 | /* we have overflowed the fields vector -- just count them */ | ||
85 | fn = nfields; | ||
86 | while (c != '\0') { | ||
87 | while ((c = *p++) == sepc || c == sepc2) | ||
88 | continue; | ||
89 | p--; | ||
90 | fn++; | ||
91 | while ((c = *p++) != '\0' && c != sepc && c != sepc2) | ||
92 | continue; | ||
93 | } | ||
94 | /* might have to trim trailing white space */ | ||
95 | if (trimtrail) { | ||
96 | p--; | ||
97 | while ((c = *--p) == sepc || c == sepc2) | ||
98 | continue; | ||
99 | p++; | ||
100 | if (*p != '\0') { | ||
101 | if (fn == nfields+1) | ||
102 | *p = '\0'; | ||
103 | fn--; | ||
104 | } | ||
105 | } | ||
106 | return(fn); | ||
107 | } | ||
108 | |||
109 | /* n separators */ | ||
110 | fn = 0; | ||
111 | for (;;) { | ||
112 | if (fn < nfields) | ||
113 | *fp++ = p; | ||
114 | fn++; | ||
115 | for (;;) { | ||
116 | c = *p++; | ||
117 | if (c == '\0') | ||
118 | return(fn); | ||
119 | sepp = sep; | ||
120 | while ((sepc = *sepp++) != '\0' && sepc != c) | ||
121 | continue; | ||
122 | if (sepc != '\0') /* it was a separator */ | ||
123 | break; | ||
124 | } | ||
125 | if (fn < nfields) | ||
126 | *(p-1) = '\0'; | ||
127 | for (;;) { | ||
128 | c = *p++; | ||
129 | sepp = sep; | ||
130 | while ((sepc = *sepp++) != '\0' && sepc != c) | ||
131 | continue; | ||
132 | if (sepc == '\0') /* it wasn't a separator */ | ||
133 | break; | ||
134 | } | ||
135 | p--; | ||
136 | } | ||
137 | |||
138 | /* not reached */ | ||
139 | } | ||
140 | |||
141 | #ifdef TEST_SPLIT | ||
142 | |||
143 | |||
144 | /* | ||
145 | * test program | ||
146 | * pgm runs regression | ||
147 | * pgm sep splits stdin lines by sep | ||
148 | * pgm str sep splits str by sep | ||
149 | * pgm str sep n splits str by sep n times | ||
150 | */ | ||
151 | int | ||
152 | main(argc, argv) | ||
153 | int argc; | ||
154 | char *argv[]; | ||
155 | { | ||
156 | char buf[512]; | ||
157 | register int n; | ||
158 | # define MNF 10 | ||
159 | char *fields[MNF]; | ||
160 | |||
161 | if (argc > 4) | ||
162 | for (n = atoi(argv[3]); n > 0; n--) { | ||
163 | (void) strlcpy(buf, argv[1], sizeof buf); | ||
164 | } | ||
165 | else if (argc > 3) | ||
166 | for (n = atoi(argv[3]); n > 0; n--) { | ||
167 | (void) strlcpy(buf, argv[1], sizeof buf); | ||
168 | (void) split(buf, fields, MNF, argv[2]); | ||
169 | } | ||
170 | else if (argc > 2) | ||
171 | dosplit(argv[1], argv[2]); | ||
172 | else if (argc > 1) | ||
173 | while (fgets(buf, sizeof(buf), stdin) != NULL) { | ||
174 | buf[strcspn(buf, "\n")] = '\0'; /* stomp newline */ | ||
175 | dosplit(buf, argv[1]); | ||
176 | } | ||
177 | else | ||
178 | regress(); | ||
179 | |||
180 | exit(0); | ||
181 | } | ||
182 | |||
183 | dosplit(string, seps) | ||
184 | char *string; | ||
185 | char *seps; | ||
186 | { | ||
187 | # define NF 5 | ||
188 | char *fields[NF]; | ||
189 | register int nf; | ||
190 | |||
191 | nf = split(string, fields, NF, seps); | ||
192 | print(nf, NF, fields); | ||
193 | } | ||
194 | |||
195 | print(nf, nfp, fields) | ||
196 | int nf; | ||
197 | int nfp; | ||
198 | char *fields[]; | ||
199 | { | ||
200 | register int fn; | ||
201 | register int bound; | ||
202 | |||
203 | bound = (nf > nfp) ? nfp : nf; | ||
204 | printf("%d:\t", nf); | ||
205 | for (fn = 0; fn < bound; fn++) | ||
206 | printf("\"%s\"%s", fields[fn], (fn+1 < nf) ? ", " : "\n"); | ||
207 | } | ||
208 | |||
209 | #define RNF 5 /* some table entries know this */ | ||
210 | struct { | ||
211 | char *str; | ||
212 | char *seps; | ||
213 | int nf; | ||
214 | char *fi[RNF]; | ||
215 | } tests[] = { | ||
216 | "", " ", 0, { "" }, | ||
217 | " ", " ", 2, { "", "" }, | ||
218 | "x", " ", 1, { "x" }, | ||
219 | "xy", " ", 1, { "xy" }, | ||
220 | "x y", " ", 2, { "x", "y" }, | ||
221 | "abc def g ", " ", 5, { "abc", "def", "", "g", "" }, | ||
222 | " a bcd", " ", 4, { "", "", "a", "bcd" }, | ||
223 | "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" }, | ||
224 | " a b c d ", " ", 6, { "", "a", "b", "c", "d " }, | ||
225 | |||
226 | "", " _", 0, { "" }, | ||
227 | " ", " _", 2, { "", "" }, | ||
228 | "x", " _", 1, { "x" }, | ||
229 | "x y", " _", 2, { "x", "y" }, | ||
230 | "ab _ cd", " _", 2, { "ab", "cd" }, | ||
231 | " a_b c ", " _", 5, { "", "a", "b", "c", "" }, | ||
232 | "a b c_d e f", " _", 6, { "a", "b", "c", "d", "e f" }, | ||
233 | " a b c d ", " _", 6, { "", "a", "b", "c", "d " }, | ||
234 | |||
235 | "", " _~", 0, { "" }, | ||
236 | " ", " _~", 2, { "", "" }, | ||
237 | "x", " _~", 1, { "x" }, | ||
238 | "x y", " _~", 2, { "x", "y" }, | ||
239 | "ab _~ cd", " _~", 2, { "ab", "cd" }, | ||
240 | " a_b c~", " _~", 5, { "", "a", "b", "c", "" }, | ||
241 | "a b_c d~e f", " _~", 6, { "a", "b", "c", "d", "e f" }, | ||
242 | "~a b c d ", " _~", 6, { "", "a", "b", "c", "d " }, | ||
243 | |||
244 | "", " _~-", 0, { "" }, | ||
245 | " ", " _~-", 2, { "", "" }, | ||
246 | "x", " _~-", 1, { "x" }, | ||
247 | "x y", " _~-", 2, { "x", "y" }, | ||
248 | "ab _~- cd", " _~-", 2, { "ab", "cd" }, | ||
249 | " a_b c~", " _~-", 5, { "", "a", "b", "c", "" }, | ||
250 | "a b_c-d~e f", " _~-", 6, { "a", "b", "c", "d", "e f" }, | ||
251 | "~a-b c d ", " _~-", 6, { "", "a", "b", "c", "d " }, | ||
252 | |||
253 | "", " ", 0, { "" }, | ||
254 | " ", " ", 2, { "", "" }, | ||
255 | "x", " ", 1, { "x" }, | ||
256 | "xy", " ", 1, { "xy" }, | ||
257 | "x y", " ", 2, { "x", "y" }, | ||
258 | "abc def g ", " ", 4, { "abc", "def", "g", "" }, | ||
259 | " a bcd", " ", 3, { "", "a", "bcd" }, | ||
260 | "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" }, | ||
261 | " a b c d ", " ", 6, { "", "a", "b", "c", "d " }, | ||
262 | |||
263 | "", "", 0, { "" }, | ||
264 | " ", "", 0, { "" }, | ||
265 | "x", "", 1, { "x" }, | ||
266 | "xy", "", 1, { "xy" }, | ||
267 | "x y", "", 2, { "x", "y" }, | ||
268 | "abc def g ", "", 3, { "abc", "def", "g" }, | ||
269 | "\t a bcd", "", 2, { "a", "bcd" }, | ||
270 | " a \tb\t c ", "", 3, { "a", "b", "c" }, | ||
271 | "a b c d e ", "", 5, { "a", "b", "c", "d", "e" }, | ||
272 | "a b\tc d e f", "", 6, { "a", "b", "c", "d", "e f" }, | ||
273 | " a b c d e f ", "", 6, { "a", "b", "c", "d", "e f " }, | ||
274 | |||
275 | NULL, NULL, 0, { NULL }, | ||
276 | }; | ||
277 | |||
278 | regress() | ||
279 | { | ||
280 | char buf[512]; | ||
281 | register int n; | ||
282 | char *fields[RNF+1]; | ||
283 | register int nf; | ||
284 | register int i; | ||
285 | register int printit; | ||
286 | register char *f; | ||
287 | |||
288 | for (n = 0; tests[n].str != NULL; n++) { | ||
289 | (void) strlcpy(buf, tests[n].str, sizeof buf); | ||
290 | fields[RNF] = NULL; | ||
291 | nf = split(buf, fields, RNF, tests[n].seps); | ||
292 | printit = 0; | ||
293 | if (nf != tests[n].nf) { | ||
294 | printf("split `%s' by `%s' gave %d fields, not %d\n", | ||
295 | tests[n].str, tests[n].seps, nf, tests[n].nf); | ||
296 | printit = 1; | ||
297 | } else if (fields[RNF] != NULL) { | ||
298 | printf("split() went beyond array end\n"); | ||
299 | printit = 1; | ||
300 | } else { | ||
301 | for (i = 0; i < nf && i < RNF; i++) { | ||
302 | f = fields[i]; | ||
303 | if (f == NULL) | ||
304 | f = "(NULL)"; | ||
305 | if (strcmp(f, tests[n].fi[i]) != 0) { | ||
306 | printf("split `%s' by `%s', field %d is `%s', not `%s'\n", | ||
307 | tests[n].str, tests[n].seps, | ||
308 | i, fields[i], tests[n].fi[i]); | ||
309 | printit = 1; | ||
310 | } | ||
311 | } | ||
312 | } | ||
313 | if (printit) | ||
314 | print(nf, RNF, fields); | ||
315 | } | ||
316 | } | ||
317 | #endif | ||
diff --git a/src/regress/lib/libc/regex/t_exhaust.c b/src/regress/lib/libc/regex/t_exhaust.c deleted file mode 100644 index f54bab18da..0000000000 --- a/src/regress/lib/libc/regex/t_exhaust.c +++ /dev/null | |||
@@ -1,183 +0,0 @@ | |||
1 | /* $OpenBSD: t_exhaust.c,v 1.4 2024/07/15 10:11:56 anton Exp $ */ | ||
2 | /* $NetBSD: t_exhaust.c,v 1.2 2011/10/21 00:41:34 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Christos Zoulas. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * 3. All advertising materials mentioning features or use of this software | ||
20 | * must display the following acknowledgement: | ||
21 | * This product includes software developed by the NetBSD | ||
22 | * Foundation, Inc. and its contributors. | ||
23 | * 4. Neither the name of The NetBSD Foundation nor the names of its | ||
24 | * contributors may be used to endorse or promote products derived | ||
25 | * from this software without specific prior written permission. | ||
26 | * | ||
27 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
28 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
29 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
30 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
31 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
37 | * POSSIBILITY OF SUCH DAMAGE. | ||
38 | */ | ||
39 | |||
40 | #include <stdio.h> | ||
41 | #include <regex.h> | ||
42 | #include <string.h> | ||
43 | #include <stdlib.h> | ||
44 | #include <err.h> | ||
45 | //#include <atf-c.h> | ||
46 | |||
47 | |||
48 | static char * | ||
49 | mkstr(const char *str, size_t len) | ||
50 | { | ||
51 | size_t i, slen = strlen(str); | ||
52 | char *p = malloc(slen * len + 1); | ||
53 | if (p == NULL) | ||
54 | err(1, "malloc"); | ||
55 | for (i = 0; i < len; i++) | ||
56 | strlcpy(&p[i * slen], str, slen * len + 1 - (i * slen)); | ||
57 | return p; | ||
58 | } | ||
59 | |||
60 | static char * | ||
61 | concat(const char *d, const char *s) | ||
62 | { | ||
63 | size_t dlen = strlen(d); | ||
64 | size_t slen = strlen(s); | ||
65 | char *p = malloc(dlen + slen + 1); | ||
66 | strlcpy(p, d, dlen + slen + 1); | ||
67 | strlcat(p, s, dlen + slen + 1); | ||
68 | return p; | ||
69 | } | ||
70 | |||
71 | static char * | ||
72 | p0(size_t len) | ||
73 | { | ||
74 | char *d, *s1, *s2; | ||
75 | s1 = mkstr("\\(", len); | ||
76 | s2 = concat(s1, ")"); | ||
77 | free(s1); | ||
78 | d = concat("(", s2); | ||
79 | free(s2); | ||
80 | return d; | ||
81 | } | ||
82 | |||
83 | static char * | ||
84 | p1(size_t len) | ||
85 | { | ||
86 | char *d, *s1, *s2, *s3; | ||
87 | s1 = mkstr("\\(", 60); | ||
88 | s2 = mkstr("(.*)", len); | ||
89 | s3 = concat(s1, s2); | ||
90 | free(s2); | ||
91 | free(s1); | ||
92 | s1 = concat(s3, ")"); | ||
93 | free(s3); | ||
94 | d = concat("(", s1); | ||
95 | free(s1); | ||
96 | return d; | ||
97 | } | ||
98 | |||
99 | static char * | ||
100 | ps(const char *m, const char *s, size_t len) | ||
101 | { | ||
102 | char *d, *s1, *s2, *s3; | ||
103 | s1 = mkstr(m, len); | ||
104 | s2 = mkstr(s, len); | ||
105 | s3 = concat(s1, s2); | ||
106 | free(s2); | ||
107 | free(s1); | ||
108 | d = concat("(.?)", s3); | ||
109 | free(s3); | ||
110 | return d; | ||
111 | } | ||
112 | |||
113 | static char * | ||
114 | p2(size_t len) | ||
115 | { | ||
116 | return ps("((.*){0,255}", ")", len); | ||
117 | } | ||
118 | |||
119 | static char * | ||
120 | p3(size_t len) | ||
121 | { | ||
122 | return ps("(.\\{0,}", ")", len); | ||
123 | } | ||
124 | |||
125 | static char * | ||
126 | p4(size_t len) | ||
127 | { | ||
128 | return ps("((.*){1,255}", ")", len); | ||
129 | } | ||
130 | |||
131 | static char * | ||
132 | p5(size_t len) | ||
133 | { | ||
134 | return ps("(", "){1,100}", len); | ||
135 | } | ||
136 | |||
137 | static char * | ||
138 | p6(size_t len) | ||
139 | { | ||
140 | char *d, *s1, *s2; | ||
141 | s1 = mkstr("(?:(.*)|", len); | ||
142 | s2 = concat(s1, "(.*)"); | ||
143 | free(s1); | ||
144 | s1 = mkstr(")", len); | ||
145 | d = concat(s2, s1); | ||
146 | free(s1); | ||
147 | free(s2); | ||
148 | return d; | ||
149 | } | ||
150 | |||
151 | static char *(*patterns[])(size_t) = { | ||
152 | p0, | ||
153 | p1, | ||
154 | p2, | ||
155 | p3, | ||
156 | p4, | ||
157 | p5, | ||
158 | p6, | ||
159 | }; | ||
160 | |||
161 | int | ||
162 | main(void) | ||
163 | { | ||
164 | regex_t re; | ||
165 | int e, ret = 0; | ||
166 | size_t i; | ||
167 | |||
168 | for (i = 0; i < sizeof(patterns) / sizeof(patterns[0]); i++) { | ||
169 | char *d = (*patterns[i])(9999); | ||
170 | e = regcomp(&re, d, i == 6 ? REG_BASIC : REG_EXTENDED); | ||
171 | free(d); | ||
172 | if (e) { | ||
173 | if (e != REG_ESPACE) { | ||
174 | printf("regcomp returned %d for pattern %zu", e, i); | ||
175 | ret = 1; | ||
176 | } | ||
177 | continue; | ||
178 | } | ||
179 | (void)regexec(&re, "aaaaaaaa", 0, NULL, 0); | ||
180 | regfree(&re); | ||
181 | } | ||
182 | return ret; | ||
183 | } | ||
diff --git a/src/regress/lib/libc/regex/tests b/src/regress/lib/libc/regex/tests deleted file mode 100644 index f3fd9d0e6b..0000000000 --- a/src/regress/lib/libc/regex/tests +++ /dev/null | |||
@@ -1,612 +0,0 @@ | |||
1 | # $OpenBSD: tests,v 1.10 2021/04/02 14:20:57 otto Exp $ | ||
2 | # $NetBSD: tests,v 1.5 1995/04/20 22:40:00 cgd Exp $ | ||
3 | |||
4 | # regular expression test set | ||
5 | # Lines are at least three fields, separated by one or more tabs. "" stands | ||
6 | # for an empty field. First field is an RE. Second field is flags. If | ||
7 | # C flag given, regcomp() is expected to fail, and the third field is the | ||
8 | # error name (minus the leading REG_). | ||
9 | # | ||
10 | # Otherwise it is expected to succeed, and the third field is the string to | ||
11 | # try matching it against. If there is no fourth field, the match is | ||
12 | # expected to fail. If there is a fourth field, it is the substring that | ||
13 | # the RE is expected to match. If there is a fifth field, it is a comma- | ||
14 | # separated list of what the subexpressions should match, with - indicating | ||
15 | # no match for that one. In both the fourth and fifth fields, a (sub)field | ||
16 | # starting with @ indicates that the (sub)expression is expected to match | ||
17 | # a null string followed by the stuff after the @; this provides a way to | ||
18 | # test where null strings match. The character `N' in REs and strings | ||
19 | # is newline, `S' is space, `T' is tab, `Z' is NUL. | ||
20 | # | ||
21 | # The full list of flags: | ||
22 | # - placeholder, does nothing | ||
23 | # b RE is a BRE, not an ERE | ||
24 | # & try it as both an ERE and a BRE | ||
25 | # C regcomp() error expected, third field is error name | ||
26 | # i REG_ICASE | ||
27 | # m ("mundane") REG_NOSPEC | ||
28 | # s REG_NOSUB (not really testable) | ||
29 | # n REG_NEWLINE | ||
30 | # ^ REG_NOTBOL | ||
31 | # $ REG_NOTEOL | ||
32 | # # REG_STARTEND (see below) | ||
33 | # p REG_PEND | ||
34 | # | ||
35 | # For REG_STARTEND, the start/end offsets are those of the substring | ||
36 | # enclosed in (). | ||
37 | |||
38 | # basics | ||
39 | a & a a | ||
40 | abc & abc abc | ||
41 | abc|de - abc abc | ||
42 | a|b|c - abc a | ||
43 | |||
44 | # parentheses and perversions thereof | ||
45 | a(b)c - abc abc | ||
46 | a\(b\)c b abc abc | ||
47 | a( C EPAREN | ||
48 | a( b a( a( | ||
49 | a\( - a( a( | ||
50 | a\( bC EPAREN | ||
51 | a\(b bC EPAREN | ||
52 | a(b C EPAREN | ||
53 | a(b b a(b a(b | ||
54 | # gag me with a right parenthesis -- 1003.2 goofed here (my fault, partly) | ||
55 | a) - a) a) | ||
56 | ) - ) ) | ||
57 | # end gagging (in a just world, those *should* give EPAREN) | ||
58 | a) b a) a) | ||
59 | a\) bC EPAREN | ||
60 | \) bC EPAREN | ||
61 | a()b - ab ab | ||
62 | a\(\)b b ab ab | ||
63 | |||
64 | # anchoring and REG_NEWLINE | ||
65 | ^abc$ & abc abc | ||
66 | ^b & abc | ||
67 | a^b - a^b | ||
68 | a^b b a^b a^b | ||
69 | a$b - a$b | ||
70 | a$b b a$b a$b | ||
71 | ^ & abc @abc | ||
72 | $ & abc @ | ||
73 | ^$ & "" @ | ||
74 | $^ - "" @ | ||
75 | \($\)\(^\) b "" @ | ||
76 | # stop retching, those are legitimate (although disgusting) | ||
77 | ^^ - "" @ | ||
78 | $$ - "" @ | ||
79 | b$ & abNc | ||
80 | b$ &n abNc b | ||
81 | ^b & aNbNc | ||
82 | b$ & aNbNc | ||
83 | ^a &n aNb a | ||
84 | ^b &n abc | ||
85 | ^b$ &n aNbNc b | ||
86 | ^$ &n aNNb @Nb | ||
87 | ^$ n abc | ||
88 | ^$ n abcN @ | ||
89 | $^ n aNNb @Nb | ||
90 | \($\)\(^\) bn aNNb @Nb | ||
91 | ^^ n^ aNNb @Nb | ||
92 | $$ n aNNb @NN | ||
93 | ^a &^ a | ||
94 | a$ &$ a | ||
95 | ^b &^ abc | ||
96 | ^b &^ aNb | ||
97 | ^a &^n aNb | ||
98 | ^b &^n abc | ||
99 | ^b &^n aNb b | ||
100 | a$ &$n bNa | ||
101 | b$ &$n bNa b | ||
102 | a*(^b$)c* - b b | ||
103 | a*\(^b$\)c* b b b | ||
104 | |||
105 | # certain syntax errors and non-errors | ||
106 | | C EMPTY | ||
107 | | b | | | ||
108 | * C BADRPT | ||
109 | * b * * | ||
110 | + C BADRPT | ||
111 | ? C BADRPT | ||
112 | "" &C EMPTY | ||
113 | () - abc @abc | ||
114 | \(\) b abc @abc | ||
115 | a||b C EMPTY | ||
116 | |ab C EMPTY | ||
117 | ab| C EMPTY | ||
118 | (|a)b C EMPTY | ||
119 | (a|)b C EMPTY | ||
120 | (*a) C BADRPT | ||
121 | (+a) C BADRPT | ||
122 | (?a) C BADRPT | ||
123 | ({1}a) C BADRPT | ||
124 | \(\{1\}a\) bC BADRPT | ||
125 | (a|*b) C BADRPT | ||
126 | (a|+b) C BADRPT | ||
127 | (a|?b) C BADRPT | ||
128 | (a|{1}b) C BADRPT | ||
129 | ^* C BADRPT | ||
130 | ^* b * * | ||
131 | ^+ C BADRPT | ||
132 | ^? C BADRPT | ||
133 | ^{1} C BADRPT | ||
134 | ^\{1\} bC BADRPT | ||
135 | |||
136 | # metacharacters, backslashes | ||
137 | a.c & abc abc | ||
138 | a[bc]d & abd abd | ||
139 | a\*c & a*c a*c | ||
140 | a\\b & a\b a\b | ||
141 | a\\\*b & a\*b a\*b | ||
142 | a\bc & abc abc | ||
143 | a\ &C EESCAPE | ||
144 | a\\bc & a\bc a\bc | ||
145 | \{ bC BADRPT | ||
146 | a\[b & a[b a[b | ||
147 | a[b &C EBRACK | ||
148 | # trailing $ is a peculiar special case for the BRE code | ||
149 | a$ & a a | ||
150 | a$ & a$ | ||
151 | a\$ & a | ||
152 | a\$ & a$ a$ | ||
153 | a\\$ & a | ||
154 | a\\$ & a$ | ||
155 | a\\$ & a\$ | ||
156 | a\\$ & a\ a\ | ||
157 | |||
158 | # back references, ugh | ||
159 | a\(b\)\2c bC ESUBREG | ||
160 | a\(b\1\)c bC ESUBREG | ||
161 | a\(b*\)c\1d b abbcbbd abbcbbd bb | ||
162 | a\(b*\)c\1d b abbcbd | ||
163 | a\(b*\)c\1d b abbcbbbd | ||
164 | ^\(.\)\1 b abc | ||
165 | a\([bc]\)\1d b abcdabbd abbd b | ||
166 | a\(\([bc]\)\2\)*d b abbccd abbccd | ||
167 | a\(\([bc]\)\2\)*d b abbcbd | ||
168 | # actually, this next one probably ought to fail, but the spec is unclear | ||
169 | a\(\(b\)*\2\)*d b abbbd abbbd | ||
170 | # here is a case that no NFA implementation does right | ||
171 | \(ab*\)[ab]*\1 b ababaaa ababaaa a | ||
172 | # check out normal matching in the presence of back refs | ||
173 | \(a\)\1bcd b aabcd aabcd | ||
174 | \(a\)\1bc*d b aabcd aabcd | ||
175 | \(a\)\1bc*d b aabd aabd | ||
176 | \(a\)\1bc*d b aabcccd aabcccd | ||
177 | \(a\)\1bc*[ce]d b aabcccd aabcccd | ||
178 | ^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd | ||
179 | \(b*\)\(a*\1\)* b ab a | ||
180 | \([^_]*\)\(_*\1\)* b foo_foo_bar_bar_bar_baz foo_foo foo,_foo | ||
181 | \([^_]*\)\(_*\1\)* b bar_bar_bar_baz bar_bar_bar bar,_bar | ||
182 | \([^_]*\)\(_*\1\)* b foo_bar_baz foo foo | ||
183 | \(.*\)\1 b "" "" | ||
184 | \(.*\)\1 b a "" | ||
185 | \(.*\)\1 b aa aa | ||
186 | \(.*\)\1 b aaa aa | ||
187 | \(.*\)\1 b aaaa aaaa | ||
188 | \([^_]*\)\1 b "" "" | ||
189 | \([^_]*\)\1 b a "" | ||
190 | \([^_]*\)\1 b aa aa | ||
191 | \([^_]*\)\1 b aaa aa | ||
192 | \([^_]*\)\1 b aaaa aaaa | ||
193 | foo\(.*\)bar\1 b foolbarl foolbarl l | ||
194 | foo\(.*\)bar\1 b foobar foobar "" | ||
195 | \(\(.\)b\)*\1 b aba | ||
196 | \(\(.\)b\)*\1 b abba | ||
197 | \(\(.\)b\)*\1 b abbba | ||
198 | \(\(.\)b\)*\1 b abbbba bbbb bb,b | ||
199 | \(\(.\)b\)*\1 b abbbbba abbbbb bb,b | ||
200 | \(\(.\)b\)*\1 b abbbbbba abbbbb bb,b | ||
201 | \(\(.\)b\)*\1 b abbbbbbbbbbbbbba abbbbbbbbbbbbb bb,b | ||
202 | \(\(.\)b\)*\1 b abbbbbbbbbbbbbbba abbbbbbbbbbbbbbb bb,b | ||
203 | # these used to segfault, buffer underflow in engine.c, backref() | ||
204 | \(^a\)*\(b.\)\2 b^ sbxbxe bxbx -,bx | ||
205 | \([[:<:]]a\)*\(b.\)\2 b^ sbxbxe bxbx -,bx | ||
206 | |||
207 | # ordinary repetitions | ||
208 | ab*c & abc abc | ||
209 | ab+c - abc abc | ||
210 | ab?c - abc abc | ||
211 | a\(*\)b b a*b a*b | ||
212 | a\(**\)b b ab ab | ||
213 | a\(***\)b bC BADRPT | ||
214 | *a b *a *a | ||
215 | **a b a a | ||
216 | ***a bC BADRPT | ||
217 | |||
218 | # the dreaded bounded repetitions | ||
219 | { & { { | ||
220 | {abc & {abc {abc | ||
221 | {1 C BADRPT | ||
222 | {1} C BADRPT | ||
223 | a{b & a{b a{b | ||
224 | a{1}b - ab ab | ||
225 | a\{1\}b b ab ab | ||
226 | a{1,}b - ab ab | ||
227 | a\{1,\}b b ab ab | ||
228 | a{1,2}b - aab aab | ||
229 | a\{1,2\}b b aab aab | ||
230 | a{1 C EBRACE | ||
231 | a\{1 bC EBRACE | ||
232 | a{1a C EBRACE | ||
233 | a\{1a bC EBRACE | ||
234 | a{1a} C BADBR | ||
235 | a\{1a\} bC BADBR | ||
236 | a{,2} - a{,2} a{,2} | ||
237 | a\{,2\} bC BADBR | ||
238 | a{,} - a{,} a{,} | ||
239 | a\{,\} bC BADBR | ||
240 | a{1,x} C BADBR | ||
241 | a\{1,x\} bC BADBR | ||
242 | a{1,x C EBRACE | ||
243 | a\{1,x bC EBRACE | ||
244 | a{300} C BADBR | ||
245 | a\{300\} bC BADBR | ||
246 | a{1,0} C BADBR | ||
247 | a\{1,0\} bC BADBR | ||
248 | ab{0,0}c - abcac ac | ||
249 | ab\{0,0\}c b abcac ac | ||
250 | ab{0,1}c - abcac abc | ||
251 | ab\{0,1\}c b abcac abc | ||
252 | ab{0,3}c - abbcac abbc | ||
253 | ab\{0,3\}c b abbcac abbc | ||
254 | ab{1,1}c - acabc abc | ||
255 | ab\{1,1\}c b acabc abc | ||
256 | ab{1,3}c - acabc abc | ||
257 | ab\{1,3\}c b acabc abc | ||
258 | ab{2,2}c - abcabbc abbc | ||
259 | ab\{2,2\}c b abcabbc abbc | ||
260 | ab{2,4}c - abcabbc abbc | ||
261 | ab\{2,4\}c b abcabbc abbc | ||
262 | ((a{1,10}){1,10}){1,10} - a a a,a | ||
263 | |||
264 | # multiple repetitions | ||
265 | a** &C BADRPT | ||
266 | a++ C BADRPT | ||
267 | a?? C BADRPT | ||
268 | a*+ C BADRPT | ||
269 | a*? C BADRPT | ||
270 | a+* C BADRPT | ||
271 | a+? C BADRPT | ||
272 | a?* C BADRPT | ||
273 | a?+ C BADRPT | ||
274 | a{1}{1} C BADRPT | ||
275 | a*{1} C BADRPT | ||
276 | a+{1} C BADRPT | ||
277 | a?{1} C BADRPT | ||
278 | a{1}* C BADRPT | ||
279 | a{1}+ C BADRPT | ||
280 | a{1}? C BADRPT | ||
281 | a*{b} - a{b} a{b} | ||
282 | a\{1\}\{1\} bC BADRPT | ||
283 | a*\{1\} bC BADRPT | ||
284 | a\{1\}* bC BADRPT | ||
285 | |||
286 | # brackets, and numerous perversions thereof | ||
287 | a[b]c & abc abc | ||
288 | a[ab]c & abc abc | ||
289 | a[^ab]c & adc adc | ||
290 | a[]b]c & a]c a]c | ||
291 | a[[b]c & a[c a[c | ||
292 | a[-b]c & a-c a-c | ||
293 | a[^]b]c & adc adc | ||
294 | a[^-b]c & adc adc | ||
295 | a[b-]c & a-c a-c | ||
296 | a[b &C EBRACK | ||
297 | a[] &C EBRACK | ||
298 | a[1-3]c & a2c a2c | ||
299 | a[3-1]c &C ERANGE | ||
300 | a[1-3-5]c &C ERANGE | ||
301 | a[[.-.]--]c & a-c a-c | ||
302 | a[1- &C ERANGE | ||
303 | a[[. &C EBRACK | ||
304 | a[[.x &C EBRACK | ||
305 | a[[.x. &C EBRACK | ||
306 | a[[.x.] &C EBRACK | ||
307 | a[[.x.]] & ax ax | ||
308 | a[[.x,.]] &C ECOLLATE | ||
309 | a[[.one.]]b & a1b a1b | ||
310 | a[[.notdef.]]b &C ECOLLATE | ||
311 | a[[.].]]b & a]b a]b | ||
312 | a[[:alpha:]]c & abc abc | ||
313 | a[[:notdef:]]c &C ECTYPE | ||
314 | a[[: &C EBRACK | ||
315 | a[[:alpha &C EBRACK | ||
316 | a[[:alpha:] &C EBRACK | ||
317 | a[[:alpha,:] &C ECTYPE | ||
318 | a[[:]:]]b &C ECTYPE | ||
319 | a[[:-:]]b &C ECTYPE | ||
320 | a[[:alph:]] &C ECTYPE | ||
321 | a[[:alphabet:]] &C ECTYPE | ||
322 | [[:alnum:]]+ - -%@a0X- a0X | ||
323 | [[:alpha:]]+ - -%@aX0- aX | ||
324 | [[:blank:]]+ - aSSTb SST | ||
325 | [[:cntrl:]]+ - aNTb NT | ||
326 | [[:digit:]]+ - a019b 019 | ||
327 | [[:graph:]]+ - Sa%bS a%b | ||
328 | [[:lower:]]+ - AabC ab | ||
329 | [[:print:]]+ - NaSbN aSb | ||
330 | [[:punct:]]+ - S%-&T %-& | ||
331 | [[:space:]]+ - aSNTb SNT | ||
332 | [[:upper:]]+ - aBCd BC | ||
333 | [[:xdigit:]]+ - p0f3Cq 0f3C | ||
334 | a[[=b=]]c & abc abc | ||
335 | a[[= &C EBRACK | ||
336 | a[[=b &C EBRACK | ||
337 | a[[=b= &C EBRACK | ||
338 | a[[=b=] &C EBRACK | ||
339 | a[[=b,=]] &C ECOLLATE | ||
340 | a[[=one=]]b & a1b a1b | ||
341 | |||
342 | # complexities | ||
343 | a(((b)))c - abc abc | ||
344 | a(b|(c))d - abd abd | ||
345 | a(b*|c)d - abbd abbd | ||
346 | # just gotta have one DFA-buster, of course | ||
347 | a[ab]{20} - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab | ||
348 | # and an inline expansion in case somebody gets tricky | ||
349 | a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab | ||
350 | # and in case somebody just slips in an NFA... | ||
351 | a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night) - aaaaabaaaabaaaabaaaabweeknights aaaaabaaaabaaaabaaaabweeknights | ||
352 | # fish for anomalies as the number of states passes 32 | ||
353 | 12345678901234567890123456789 - a12345678901234567890123456789b 12345678901234567890123456789 | ||
354 | 123456789012345678901234567890 - a123456789012345678901234567890b 123456789012345678901234567890 | ||
355 | 1234567890123456789012345678901 - a1234567890123456789012345678901b 1234567890123456789012345678901 | ||
356 | 12345678901234567890123456789012 - a12345678901234567890123456789012b 12345678901234567890123456789012 | ||
357 | 123456789012345678901234567890123 - a123456789012345678901234567890123b 123456789012345678901234567890123 | ||
358 | # and one really big one, beyond any plausible word width | ||
359 | 1234567890123456789012345678901234567890123456789012345678901234567890 - a1234567890123456789012345678901234567890123456789012345678901234567890b 1234567890123456789012345678901234567890123456789012345678901234567890 | ||
360 | # fish for problems as brackets go past 8 | ||
361 | [ab][cd][ef][gh][ij][kl][mn] - xacegikmoq acegikm | ||
362 | [ab][cd][ef][gh][ij][kl][mn][op] - xacegikmoq acegikmo | ||
363 | [ab][cd][ef][gh][ij][kl][mn][op][qr] - xacegikmoqy acegikmoq | ||
364 | [ab][cd][ef][gh][ij][kl][mn][op][q] - xacegikmoqy acegikmoq | ||
365 | |||
366 | # subtleties of matching | ||
367 | abc & xabcy abc | ||
368 | a\(b\)?c\1d b acd | ||
369 | aBc i Abc Abc | ||
370 | a[Bc]*d i abBCcd abBCcd | ||
371 | 0[[:upper:]]1 &i 0a1 0a1 | ||
372 | 0[[:lower:]]1 &i 0A1 0A1 | ||
373 | a[^b]c &i abc | ||
374 | a[^b]c &i aBc | ||
375 | a[^b]c &i adc adc | ||
376 | [a]b[c] - abc abc | ||
377 | [a]b[a] - aba aba | ||
378 | [abc]b[abc] - abc abc | ||
379 | [abc]b[abd] - abd abd | ||
380 | a(b?c)+d - accd accd | ||
381 | (wee|week)(knights|night) - weeknights weeknights | ||
382 | (we|wee|week|frob)(knights|night|day) - weeknights weeknights | ||
383 | a[bc]d - xyzaaabcaababdacd abd | ||
384 | a[ab]c - aaabc abc | ||
385 | abc s abc abc | ||
386 | a* & b @b | ||
387 | |||
388 | # Let's have some fun -- try to match a C comment. | ||
389 | # first the obvious, which looks okay at first glance... | ||
390 | /\*.*\*/ - /*x*/ /*x*/ | ||
391 | # but... | ||
392 | /\*.*\*/ - /*x*/y/*z*/ /*x*/y/*z*/ | ||
393 | # okay, we must not match */ inside; try to do that... | ||
394 | /\*([^*]|\*[^/])*\*/ - /*x*/ /*x*/ | ||
395 | /\*([^*]|\*[^/])*\*/ - /*x*/y/*z*/ /*x*/ | ||
396 | # but... | ||
397 | /\*([^*]|\*[^/])*\*/ - /*x**/y/*z*/ /*x**/y/*z*/ | ||
398 | # and a still fancier version, which does it right (I think)... | ||
399 | /\*([^*]|\*+[^*/])*\*+/ - /*x*/ /*x*/ | ||
400 | /\*([^*]|\*+[^*/])*\*+/ - /*x*/y/*z*/ /*x*/ | ||
401 | /\*([^*]|\*+[^*/])*\*+/ - /*x**/y/*z*/ /*x**/ | ||
402 | /\*([^*]|\*+[^*/])*\*+/ - /*x****/y/*z*/ /*x****/ | ||
403 | /\*([^*]|\*+[^*/])*\*+/ - /*x**x*/y/*z*/ /*x**x*/ | ||
404 | /\*([^*]|\*+[^*/])*\*+/ - /*x***x/y/*z*/ /*x***x/y/*z*/ | ||
405 | |||
406 | # subexpressions | ||
407 | a(b)(c)d - abcd abcd b,c | ||
408 | a(((b)))c - abc abc b,b,b | ||
409 | a(b|(c))d - abd abd b,- | ||
410 | a(b*|c|e)d - abbd abbd bb | ||
411 | a(b*|c|e)d - acd acd c | ||
412 | a(b*|c|e)d - ad ad @d | ||
413 | a(b?)c - abc abc b | ||
414 | a(b?)c - ac ac @c | ||
415 | a(b+)c - abc abc b | ||
416 | a(b+)c - abbbc abbbc bbb | ||
417 | a(b*)c - ac ac @c | ||
418 | (a|ab)(bc([de]+)f|cde) - abcdef abcdef a,bcdef,de | ||
419 | # the regression tester only asks for 9 subexpressions | ||
420 | a(b)(c)(d)(e)(f)(g)(h)(i)(j)k - abcdefghijk abcdefghijk b,c,d,e,f,g,h,i,j | ||
421 | a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l - abcdefghijkl abcdefghijkl b,c,d,e,f,g,h,i,j,k | ||
422 | a([bc]?)c - abc abc b | ||
423 | a([bc]?)c - ac ac @c | ||
424 | a([bc]+)c - abc abc b | ||
425 | a([bc]+)c - abcc abcc bc | ||
426 | a([bc]+)bc - abcbc abcbc bc | ||
427 | a(bb+|b)b - abb abb b | ||
428 | a(bbb+|bb+|b)b - abb abb b | ||
429 | a(bbb+|bb+|b)b - abbb abbb bb | ||
430 | a(bbb+|bb+|b)bb - abbb abbb b | ||
431 | (.*).* - abcdef abcdef abcdef | ||
432 | (a*)* - bc @b @b | ||
433 | |||
434 | # do we get the right subexpression when it is used more than once? | ||
435 | a(b|c)*d - ad ad - | ||
436 | a(b|c)*d - abcd abcd c | ||
437 | a(b|c)+d - abd abd b | ||
438 | a(b|c)+d - abcd abcd c | ||
439 | a(b|c?)+d - ad ad @d | ||
440 | a(b|c?)+d - abcd abcd @d | ||
441 | a(b|c){0,0}d - ad ad - | ||
442 | a(b|c){0,1}d - ad ad - | ||
443 | a(b|c){0,1}d - abd abd b | ||
444 | a(b|c){0,2}d - ad ad - | ||
445 | a(b|c){0,2}d - abcd abcd c | ||
446 | a(b|c){0,}d - ad ad - | ||
447 | a(b|c){0,}d - abcd abcd c | ||
448 | a(b|c){1,1}d - abd abd b | ||
449 | a(b|c){1,1}d - acd acd c | ||
450 | a(b|c){1,2}d - abd abd b | ||
451 | a(b|c){1,2}d - abcd abcd c | ||
452 | a(b|c){1,}d - abd abd b | ||
453 | a(b|c){1,}d - abcd abcd c | ||
454 | a(b|c){2,2}d - acbd acbd b | ||
455 | a(b|c){2,2}d - abcd abcd c | ||
456 | a(b|c){2,4}d - abcd abcd c | ||
457 | a(b|c){2,4}d - abcbd abcbd b | ||
458 | a(b|c){2,4}d - abcbcd abcbcd c | ||
459 | a(b|c){2,}d - abcd abcd c | ||
460 | a(b|c){2,}d - abcbd abcbd b | ||
461 | a(b+|((c)*))+d - abd abd @d,@d,- | ||
462 | a(b+|((c)*))+d - abcd abcd @d,@d,- | ||
463 | |||
464 | # check out the STARTEND option | ||
465 | ^[abc] &# a(b)c b | ||
466 | ^[abc] &# a(xb)c | ||
467 | ^[abc] &# aN(b)c b | ||
468 | ^[abc] &n# a(b)c b | ||
469 | ^[abc] &n# a(xb)c | ||
470 | ^[abc] &n# aN(b)c b | ||
471 | ^[abc] &^# a(b)c | ||
472 | ^[abc] &^# a(xb)c | ||
473 | ^[abc] &^# aN(b)c | ||
474 | ^[abc] &n^# a(b)c | ||
475 | ^[abc] &n^# a(xb)c | ||
476 | ^[abc] &n^# aN(b)c b | ||
477 | [abc] &# a(d)c | ||
478 | [abc] &# a(bc)d b | ||
479 | [abc] &# a(dc)d c | ||
480 | . &# a()c | ||
481 | b.*c &# b(bc)c bc | ||
482 | b.* &# b(bc)c bc | ||
483 | .*c &# b(bc)c bc | ||
484 | |||
485 | # plain strings, with the NOSPEC flag | ||
486 | abc m abc abc | ||
487 | abc m xabcy abc | ||
488 | abc m xyz | ||
489 | a*b m aba*b a*b | ||
490 | a*b m ab | ||
491 | "" mC EMPTY | ||
492 | |||
493 | # cases involving NULs | ||
494 | aZb & a a | ||
495 | aZb &p a | ||
496 | aZb &p# (aZb) aZb | ||
497 | aZ*b &p# (ab) ab | ||
498 | a.b &# (aZb) aZb | ||
499 | a.* &# (aZb)c aZb | ||
500 | |||
501 | # word boundaries (ick) | ||
502 | [[:<:]]a & a a | ||
503 | \<a & a a | ||
504 | [[:<:]]a & ba | ||
505 | \<a & ba | ||
506 | [[:<:]]a & -a a | ||
507 | \<a & -a a | ||
508 | [[:<:]]a & Na a | ||
509 | \<a & Na a | ||
510 | [[:<:]]a &n a a | ||
511 | \<a &n a a | ||
512 | [[:<:]]a &n ba | ||
513 | \<a &n ba | ||
514 | [[:<:]]a &n -a a | ||
515 | \<a &n -a a | ||
516 | [[:<:]]a &n Na a | ||
517 | \<a &n Na a | ||
518 | [[:<:]]a &^ a | ||
519 | \<a &^ a | ||
520 | [[:<:]]a &^ ba | ||
521 | \<a &^ ba | ||
522 | [[:<:]]a &^ -a a | ||
523 | \<a &^ -a a | ||
524 | [[:<:]]a &^ Na a | ||
525 | \<a &^ Na a | ||
526 | [[:<:]]a &n^ a | ||
527 | \<a &n^ a | ||
528 | [[:<:]]a &n^ ba | ||
529 | \<a &n^ ba | ||
530 | [[:<:]]a &n^ -a a | ||
531 | \<a &n^ -a a | ||
532 | [[:<:]]a &n^ Na a | ||
533 | \<a &n^ Na a | ||
534 | [[:<:]]b &# a(b)c b | ||
535 | \<b &# a(b)c b | ||
536 | [[:<:]]b &# a(xb)c | ||
537 | \<b &# a(xb)c | ||
538 | [[:<:]]b &# -(b)c b | ||
539 | \<b &# -(b)c b | ||
540 | [[:<:]]b &# aN(b)c b | ||
541 | \<b &# aN(b)c b | ||
542 | [[:<:]]b &n# a(b)c b | ||
543 | \<b &n# a(b)c b | ||
544 | [[:<:]]b &n# a(xb)c | ||
545 | \<b &n# a(xb)c | ||
546 | [[:<:]]b &n# -(b)c b | ||
547 | \<b &n# -(b)c b | ||
548 | [[:<:]]b &n# aN(b)c b | ||
549 | \<b &n# aN(b)c b | ||
550 | [[:<:]]b &^# a(b)c | ||
551 | \<b &^# a(b)c | ||
552 | [[:<:]]b &^# a(xb)c | ||
553 | \<b &^# a(xb)c | ||
554 | [[:<:]]b &^# -(b)c b | ||
555 | \<b &^# -(b)c b | ||
556 | [[:<:]]b &^# aN(b)c b | ||
557 | \<b &^# aN(b)c b | ||
558 | [[:<:]]b &n^# a(b)c | ||
559 | \<b &n^# a(b)c | ||
560 | [[:<:]]b &n^# a(xb)c | ||
561 | \<b &n^# a(xb)c | ||
562 | [[:<:]]b &n^# -(b)c b | ||
563 | \<b &n^# -(b)c b | ||
564 | [[:<:]]b &n^# aN(b)c b | ||
565 | \<b &n^# aN(b)c b | ||
566 | a[[:>:]] & a a | ||
567 | a\> & a a | ||
568 | a[[:>:]] & ab | ||
569 | a\> & ab | ||
570 | a[[:>:]] & a- a | ||
571 | a\> & a- a | ||
572 | [[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc abc | ||
573 | \<a.c\> & axcd-dayc-dazce-abc abc | ||
574 | [[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc-q abc | ||
575 | \<a.c\> & axcd-dayc-dazce-abc-q abc | ||
576 | [[:<:]]a.c[[:>:]] & axc-dayc-dazce-abc axc | ||
577 | \<a.c\> & axc-dayc-dazce-abc axc | ||
578 | [[:<:]]b.c[[:>:]] & a_bxc-byc_d-bzc-q bzc | ||
579 | \<b.c\> & a_bxc-byc_d-bzc-q bzc | ||
580 | [[:<:]].x..[[:>:]] & y_xa_-_xb_y-_xc_-axdc _xc_ | ||
581 | \<.x..\> & y_xa_-_xb_y-_xc_-axdc _xc_ | ||
582 | [[:<:]]a_b[[:>:]] & x_a_b | ||
583 | \<a_b\> & x_a_b | ||
584 | |||
585 | # past problems, and suspected problems | ||
586 | (A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A]) - A1 A1 | ||
587 | abcdefghijklmnop i abcdefghijklmnop abcdefghijklmnop | ||
588 | abcdefghijklmnopqrstuv i abcdefghijklmnopqrstuv abcdefghijklmnopqrstuv | ||
589 | (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 | ||
590 | CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11 | ||
591 | Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz | ||
592 | a?b - ab ab | ||
593 | -\{0,1\}[0-9]*$ b -5 -5 | ||
594 | |||
595 | # FreeBSD PR 130504 | ||
596 | (.|())(b) - ab ab | ||
597 | (()|.)(b) - ab ab | ||
598 | |||
599 | # Some BRE cases where \{0,\} makes a backref go wrong, as reported by Michael Paoli | ||
600 | Y*\(x\)\1 b YYxx YYxx | ||
601 | Y\{2,\}\(x\)\1 b YYxx YYxx | ||
602 | # Fails currently | ||
603 | #Y\{0,\}\(x\)\1 b YYxx YYxx | ||
604 | Y\{0,\}\(x\) b YYxx YYx | ||
605 | Y\{2,\}x\{1,\} b YYxx YYxx | ||
606 | Y\{2,\}x\{0,\}z b YYxxz YYxxz | ||
607 | Y\{0,\}x\{0,\}z b YYxxz YYxxz | ||
608 | Y\{2,\}\(xy\)\1 b YYxyxy YYxyxy | ||
609 | # Fails currently | ||
610 | #Y\{0,\}\(xy\)\1 b YYxyxy YYxyxy | ||
611 | Y*\(xy\)\1 b YYxyxy YYxyxy | ||
612 | Y\{0,\}\(xy\)xy b YYxyxy YYxyxy | ||
diff --git a/src/regress/lib/libc/setjmp-fpu/Makefile b/src/regress/lib/libc/setjmp-fpu/Makefile deleted file mode 100644 index 203613931a..0000000000 --- a/src/regress/lib/libc/setjmp-fpu/Makefile +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.6 2021/04/19 15:56:37 kettenis Exp $ | ||
2 | |||
3 | PROGS= fpu _setjmp setjmp sigsetjmp | ||
4 | |||
5 | LDADD= -lm | ||
6 | |||
7 | REGRESS_TARGETS = run-fpu | ||
8 | run-fpu: fpu | ||
9 | # check fpu functions without setjmp/longjmp before testing the latter | ||
10 | ./fpu | ||
11 | |||
12 | .for p in ${PROGS:M*jmp} | ||
13 | REGRESS_TARGETS += run-$p | ||
14 | run-$p: $p | ||
15 | ./$p | ||
16 | .endfor | ||
17 | |||
18 | .if ${MACHINE} == powerpc64 | ||
19 | # The powerpc64 ELFv2 ABI explicitly states that exception enable bits | ||
20 | # and rounding control bits are not restored by longjmp(3) | ||
21 | .for p in ${PROGS:M*jmp} | ||
22 | REGRESS_EXPECTED_FAILURES += run-$p | ||
23 | .endfor | ||
24 | .endif | ||
25 | |||
26 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/setjmp-fpu/_setjmp.c b/src/regress/lib/libc/setjmp-fpu/_setjmp.c deleted file mode 100644 index dba5d7259d..0000000000 --- a/src/regress/lib/libc/setjmp-fpu/_setjmp.c +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | /* $OpenBSD: _setjmp.c,v 1.4 2020/01/13 14:58:38 bluhm Exp $ */ | ||
2 | |||
3 | int test__setjmp(void); | ||
4 | |||
5 | int | ||
6 | main(int argc, char *argv[]) | ||
7 | { | ||
8 | return test__setjmp(); | ||
9 | } | ||
10 | |||
11 | #define SETJMP(env, savemask) _setjmp(env) | ||
12 | #define LONGJMP(env, val) _longjmp(env, val) | ||
13 | #define TEST_SETJMP test__setjmp | ||
14 | #define JMP_BUF jmp_buf | ||
15 | |||
16 | #include "setjmp-fpu.c" | ||
diff --git a/src/regress/lib/libc/setjmp-fpu/fpu.c b/src/regress/lib/libc/setjmp-fpu/fpu.c deleted file mode 100644 index e585702887..0000000000 --- a/src/regress/lib/libc/setjmp-fpu/fpu.c +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | /* $OpenBSD: fpu.c,v 1.3 2021/06/17 12:55:38 kettenis Exp $ */ | ||
2 | |||
3 | #include <err.h> | ||
4 | #include <fenv.h> | ||
5 | #include <stdlib.h> | ||
6 | |||
7 | int | ||
8 | main(int argc, char *argv[]) | ||
9 | { | ||
10 | fexcept_t flag; | ||
11 | int rv; | ||
12 | |||
13 | /* Set up the FPU control word register. */ | ||
14 | rv = fesetround(FE_UPWARD); | ||
15 | if (rv != 0) | ||
16 | errx(2, "fesetround FE_UPWARD returned %d", rv); | ||
17 | fedisableexcept(FE_ALL_EXCEPT); | ||
18 | feenableexcept(FE_DIVBYZERO); | ||
19 | |||
20 | /* Set the FPU exception flags. */ | ||
21 | flag = FE_OVERFLOW; | ||
22 | rv = fesetexceptflag(&flag, FE_ALL_EXCEPT); | ||
23 | if (rv != 0) | ||
24 | errx(2, "fesetexceptflag returned %d", rv); | ||
25 | |||
26 | /* Schedule another process, to check if kernel preserves state. */ | ||
27 | rv = system("true"); | ||
28 | if (rv == -1) | ||
29 | err(2, "system"); | ||
30 | if (rv != 0) | ||
31 | errx(2, "true: %d", rv); | ||
32 | |||
33 | /* Verify that the FPU control word is preserved. */ | ||
34 | rv = fegetround(); | ||
35 | if (rv != FE_UPWARD) | ||
36 | errx(1, "fegetround returned %d, not FE_UPWARD", rv); | ||
37 | #if !defined(__arm__) && !defined(__aarch64__) && !defined(__riscv) | ||
38 | rv = fegetexcept(); | ||
39 | if (rv != FE_DIVBYZERO) | ||
40 | errx(1, "fegetexcept returned %d, not FE_DIVBYZERO", | ||
41 | rv); | ||
42 | #endif | ||
43 | |||
44 | /* Verify that the FPU exception flags weren't clobbered. */ | ||
45 | flag = 0; | ||
46 | rv = fegetexceptflag(&flag, FE_ALL_EXCEPT); | ||
47 | if (rv != 0) | ||
48 | errx(2, "fegetexceptflag returned %d", rv); | ||
49 | if (flag != FE_OVERFLOW) | ||
50 | errx(1, "except flag is %d, no FE_OVERFLOW", rv); | ||
51 | |||
52 | return (0); | ||
53 | } | ||
diff --git a/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c b/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c deleted file mode 100644 index b5ffd8948e..0000000000 --- a/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c +++ /dev/null | |||
@@ -1,65 +0,0 @@ | |||
1 | /* $OpenBSD: setjmp-fpu.c,v 1.7 2021/06/17 12:55:38 kettenis Exp $ */ | ||
2 | |||
3 | #include <err.h> | ||
4 | #include <fenv.h> | ||
5 | #include <setjmp.h> | ||
6 | |||
7 | int | ||
8 | TEST_SETJMP(void) | ||
9 | { | ||
10 | JMP_BUF env; | ||
11 | fexcept_t flag; | ||
12 | int rv; | ||
13 | |||
14 | /* Set up the FPU control word register. */ | ||
15 | rv = fesetround(FE_UPWARD); | ||
16 | if (rv != 0) | ||
17 | errx(2, "fesetround FE_UPWARD returned %d", rv); | ||
18 | fedisableexcept(FE_ALL_EXCEPT); | ||
19 | feenableexcept(FE_DIVBYZERO); | ||
20 | |||
21 | rv = SETJMP(env, 0); | ||
22 | |||
23 | switch(rv) { | ||
24 | case 0: { | ||
25 | /* Mess with the FPU control word. */ | ||
26 | rv = fesetround(FE_DOWNWARD); | ||
27 | if (rv != 0) | ||
28 | errx(2, "fesetround FE_DOWNWARD returned %d", rv); | ||
29 | fedisableexcept(FE_DIVBYZERO); | ||
30 | |||
31 | /* Set the FPU exception flags. */ | ||
32 | flag = FE_OVERFLOW; | ||
33 | rv = fesetexceptflag(&flag, FE_ALL_EXCEPT); | ||
34 | if (rv != 0) | ||
35 | errx(2, "fesetexceptflag returned %d", rv); | ||
36 | |||
37 | LONGJMP(env, 1); | ||
38 | errx(2, "longjmp returned"); | ||
39 | } | ||
40 | case 1: { | ||
41 | /* Verify that the FPU control word is preserved. */ | ||
42 | rv = fegetround(); | ||
43 | if (rv != FE_UPWARD) | ||
44 | errx(1, "fegetround returned %d, not FE_UPWARD", rv); | ||
45 | #if !defined(__arm__) && !defined(__aarch64__) && !defined(__riscv) | ||
46 | rv = fegetexcept(); | ||
47 | if (rv != FE_DIVBYZERO) | ||
48 | errx(1, "fegetexcept returned %d, not FE_DIVBYZERO", | ||
49 | rv); | ||
50 | #endif | ||
51 | |||
52 | /* Verify that the FPU exception flags weren't clobbered. */ | ||
53 | flag = 0; | ||
54 | rv = fegetexceptflag(&flag, FE_ALL_EXCEPT); | ||
55 | if (rv != 0) | ||
56 | errx(2, "fegetexceptflag returned %d", rv); | ||
57 | if (flag != FE_OVERFLOW) | ||
58 | errx(1, "except flag is %d, no FE_OVERFLOW", rv); | ||
59 | |||
60 | return (0); | ||
61 | } | ||
62 | default: | ||
63 | errx(2, "setjmp returned %d", rv); | ||
64 | } | ||
65 | } | ||
diff --git a/src/regress/lib/libc/setjmp-fpu/setjmp.c b/src/regress/lib/libc/setjmp-fpu/setjmp.c deleted file mode 100644 index e12731da37..0000000000 --- a/src/regress/lib/libc/setjmp-fpu/setjmp.c +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | /* $OpenBSD: setjmp.c,v 1.4 2020/01/13 14:58:38 bluhm Exp $ */ | ||
2 | |||
3 | int test_setjmp(void); | ||
4 | |||
5 | int | ||
6 | main(int argc, char *argv[]) | ||
7 | { | ||
8 | return test_setjmp(); | ||
9 | } | ||
10 | |||
11 | #define SETJMP(env, savemask) setjmp(env) | ||
12 | #define LONGJMP(env, val) longjmp(env, val) | ||
13 | #define TEST_SETJMP test_setjmp | ||
14 | #define JMP_BUF jmp_buf | ||
15 | |||
16 | #include "setjmp-fpu.c" | ||
diff --git a/src/regress/lib/libc/setjmp-fpu/sigsetjmp.c b/src/regress/lib/libc/setjmp-fpu/sigsetjmp.c deleted file mode 100644 index 8c7a22a92b..0000000000 --- a/src/regress/lib/libc/setjmp-fpu/sigsetjmp.c +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | /* $OpenBSD: sigsetjmp.c,v 1.4 2020/01/13 14:58:38 bluhm Exp $ */ | ||
2 | |||
3 | int test_sigsetjmp(void); | ||
4 | |||
5 | int | ||
6 | main(int argc, char *argv[]) | ||
7 | { | ||
8 | return test_sigsetjmp(); | ||
9 | } | ||
10 | |||
11 | #define SETJMP(env, savemask) sigsetjmp(env, savemask) | ||
12 | #define LONGJMP(env, val) siglongjmp(env, val) | ||
13 | #define TEST_SETJMP test_sigsetjmp | ||
14 | #define JMP_BUF sigjmp_buf | ||
15 | |||
16 | #include "setjmp-fpu.c" | ||
diff --git a/src/regress/lib/libc/setjmp-signal/Makefile b/src/regress/lib/libc/setjmp-signal/Makefile deleted file mode 100644 index a9649a8abe..0000000000 --- a/src/regress/lib/libc/setjmp-signal/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2002/07/31 05:18:24 art Exp $ | ||
2 | |||
3 | PROG= setjmp-signal | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/setjmp-signal/setjmp-signal.c b/src/regress/lib/libc/setjmp-signal/setjmp-signal.c deleted file mode 100644 index b50f6b27c5..0000000000 --- a/src/regress/lib/libc/setjmp-signal/setjmp-signal.c +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | /* $OpenBSD: setjmp-signal.c,v 1.4 2017/07/27 12:31:09 bluhm Exp $ */ | ||
2 | /* | ||
3 | * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain. | ||
4 | */ | ||
5 | |||
6 | #include <setjmp.h> | ||
7 | #include <signal.h> | ||
8 | |||
9 | jmp_buf jb; | ||
10 | |||
11 | void | ||
12 | segv_handler(int signum) | ||
13 | { | ||
14 | longjmp(jb, 1); | ||
15 | } | ||
16 | |||
17 | int | ||
18 | main() | ||
19 | { | ||
20 | signal(SIGSEGV, segv_handler); | ||
21 | if (setjmp(jb) == 0) { | ||
22 | *((volatile int *)0L) = 0; | ||
23 | return (1); | ||
24 | } | ||
25 | return (0); | ||
26 | } | ||
diff --git a/src/regress/lib/libc/setjmp/Makefile b/src/regress/lib/libc/setjmp/Makefile deleted file mode 100644 index fc68e8d44c..0000000000 --- a/src/regress/lib/libc/setjmp/Makefile +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2002/01/01 23:00:51 art Exp $ | ||
2 | # $NetBSD: Makefile,v 1.2 1995/04/20 22:40:13 cgd Exp $ | ||
3 | |||
4 | PROG= setjmptest | ||
5 | SRCS= jmptest.c | ||
6 | |||
7 | CFLAGS+= -DTEST_SETJMP | ||
8 | |||
9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/setjmp/jmptest.c b/src/regress/lib/libc/setjmp/jmptest.c deleted file mode 100644 index 9512c9ee34..0000000000 --- a/src/regress/lib/libc/setjmp/jmptest.c +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
1 | /* $OpenBSD: jmptest.c,v 1.7 2003/09/02 23:52:16 david Exp $ */ | ||
2 | /* $NetBSD: jmptest.c,v 1.2 1995/01/01 20:55:35 jtc Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (c) 1994 Christopher G. Demetriou | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * 3. All advertising materials mentioning features or use of this software | ||
17 | * must display the following acknowledgement: | ||
18 | * This product includes software developed by Christopher G. Demetriou | ||
19 | * for the NetBSD Project. | ||
20 | * 4. The name of the author may not be used to endorse or promote products | ||
21 | * derived from this software without specific prior written permission | ||
22 | * | ||
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | |||
35 | #include <sys/types.h> | ||
36 | #include <err.h> | ||
37 | #include <setjmp.h> | ||
38 | #include <signal.h> | ||
39 | #include <stdio.h> | ||
40 | #include <stdlib.h> | ||
41 | #include <string.h> | ||
42 | #include <unistd.h> | ||
43 | |||
44 | #if (TEST_SETJMP + TEST_U_SETJMP + TEST_SIGSETJMP) != 1 | ||
45 | #error one of TEST_SETJMP, TEST_U_SETJMP, or TEST_SIGSETJMP must be defined | ||
46 | #endif | ||
47 | |||
48 | #ifdef TEST_SETJMP | ||
49 | #define BUF jmp_buf | ||
50 | #define SET(b, m) setjmp(b) | ||
51 | #define JMP(b, v) longjmp(b, v) | ||
52 | #endif | ||
53 | |||
54 | #ifdef TEST_U_SETJMP | ||
55 | #define BUF jmp_buf | ||
56 | #define SET(b, m) _setjmp(b) | ||
57 | #define JMP(b, v) _longjmp(b, v) | ||
58 | #endif | ||
59 | |||
60 | #ifdef TEST_SIGSETJMP | ||
61 | #define BUF sigjmp_buf | ||
62 | #define SET(b, m) sigsetjmp(b, m) | ||
63 | #define JMP(b, v) siglongjmp(b, v) | ||
64 | #endif | ||
65 | |||
66 | int expectsignal; | ||
67 | |||
68 | static void | ||
69 | aborthandler(int signo) | ||
70 | { | ||
71 | |||
72 | if (expectsignal) | ||
73 | _exit(0); | ||
74 | else { | ||
75 | warnx("kill(SIGABRT) succeeded"); | ||
76 | _exit(1); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | int | ||
81 | main(int argc, char *argv[]) | ||
82 | { | ||
83 | struct sigaction sa; | ||
84 | BUF jb; | ||
85 | sigset_t ss; | ||
86 | int i, x; | ||
87 | |||
88 | i = getpid(); | ||
89 | |||
90 | #ifdef TEST_SETJMP | ||
91 | expectsignal = 0; | ||
92 | #endif | ||
93 | #ifdef TEST_U_SETJMP | ||
94 | expectsignal = 1; | ||
95 | #endif | ||
96 | #ifdef TEST_SIGSETJMP | ||
97 | if (argc != 2 || | ||
98 | (strcmp(argv[1], "save") && strcmp(argv[1], "nosave"))) { | ||
99 | fprintf(stderr, "usage: %s [save|nosave]\n", argv[0]); | ||
100 | exit(1); | ||
101 | } | ||
102 | expectsignal = (strcmp(argv[1], "save") != 0); | ||
103 | #endif | ||
104 | |||
105 | sa.sa_handler = aborthandler; | ||
106 | sigemptyset(&sa.sa_mask); | ||
107 | sa.sa_flags = 0; | ||
108 | if (sigaction(SIGABRT, &sa, NULL) == -1) | ||
109 | err(1, "sigaction failed"); | ||
110 | |||
111 | if (sigemptyset(&ss) == -1) | ||
112 | err(1, "sigemptyset failed"); | ||
113 | if (sigaddset(&ss, SIGABRT) == -1) | ||
114 | err(1, "sigaddset failed"); | ||
115 | if (sigprocmask(SIG_BLOCK, &ss, NULL) == -1) | ||
116 | err(1, "sigprocmask (1) failed"); | ||
117 | |||
118 | x = SET(jb, !expectsignal); | ||
119 | if (x != 0) { | ||
120 | if (x != i) | ||
121 | errx(1, "setjmp returned wrong value"); | ||
122 | |||
123 | kill(i, SIGABRT); | ||
124 | if (expectsignal) | ||
125 | errx(1, "kill(SIGABRT) failed"); | ||
126 | else | ||
127 | exit(0); | ||
128 | } | ||
129 | |||
130 | if (sigprocmask(SIG_UNBLOCK, &ss, NULL) == -1) | ||
131 | err(1, "sigprocmask (2) failed"); | ||
132 | |||
133 | JMP(jb, i); | ||
134 | |||
135 | errx(1, "jmp failed"); | ||
136 | } | ||
diff --git a/src/regress/lib/libc/sigsetjmp/Makefile b/src/regress/lib/libc/sigsetjmp/Makefile deleted file mode 100644 index f88bea3b47..0000000000 --- a/src/regress/lib/libc/sigsetjmp/Makefile +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.5 2002/09/02 20:01:43 avsm Exp $ | ||
2 | |||
3 | PROG= sigsetjmptest | ||
4 | SRCS= jmptest.c | ||
5 | |||
6 | CFLAGS+= -DTEST_SIGSETJMP | ||
7 | |||
8 | .PATH: ${.CURDIR}/../setjmp | ||
9 | |||
10 | REGRESS_TARGETS=sigsetjmp-save sigsetjmp-nosave | ||
11 | |||
12 | sigsetjmp-save: ${PROG} | ||
13 | ./${PROG} save | ||
14 | sigsetjmp-nosave: ${PROG} | ||
15 | ./${PROG} nosave | ||
16 | |||
17 | .PHONY: ${REGRESS_TARGETS} | ||
18 | |||
19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sigthr/Makefile b/src/regress/lib/libc/sigthr/Makefile deleted file mode 100644 index 8ae4643e1e..0000000000 --- a/src/regress/lib/libc/sigthr/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2015/10/22 05:30:18 guenther Exp $ | ||
2 | |||
3 | PROG=sigthr_test | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sigthr/sigthr_test.c b/src/regress/lib/libc/sigthr/sigthr_test.c deleted file mode 100644 index c2eaa1f779..0000000000 --- a/src/regress/lib/libc/sigthr/sigthr_test.c +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> | ||
3 | * | ||
4 | * Public domain. | ||
5 | * | ||
6 | * Verify that SIGTHR can't be blocked or caught by applications. | ||
7 | */ | ||
8 | |||
9 | #include <err.h> | ||
10 | #include <errno.h> | ||
11 | #include <stdio.h> | ||
12 | #include <stdlib.h> | ||
13 | #include <string.h> | ||
14 | #include <signal.h> | ||
15 | |||
16 | void sighandler(int sig) { } | ||
17 | |||
18 | int | ||
19 | main(void) | ||
20 | { | ||
21 | struct sigaction sa; | ||
22 | sigset_t set, oset; | ||
23 | |||
24 | /* | ||
25 | * check sigprocmask | ||
26 | */ | ||
27 | if (sigprocmask(SIG_BLOCK, NULL, &set)) | ||
28 | err(1, "sigprocmask"); | ||
29 | if (sigismember(&set, SIGTHR)) | ||
30 | errx(1, "SIGTHR already blocked"); | ||
31 | sigaddset(&set, SIGTHR); | ||
32 | if (sigprocmask(SIG_BLOCK, &set, NULL)) | ||
33 | err(1, "sigprocmask"); | ||
34 | if (sigprocmask(SIG_SETMASK, &set, &oset)) | ||
35 | err(1, "sigprocmask"); | ||
36 | if (sigismember(&oset, SIGTHR)) | ||
37 | errx(1, "SIGTHR blocked with SIG_BLOCK"); | ||
38 | if (sigprocmask(SIG_BLOCK, NULL, &oset)) | ||
39 | err(1, "sigprocmask"); | ||
40 | if (sigismember(&oset, SIGTHR)) | ||
41 | errx(1, "SIGTHR blocked with SIG_SETMASK"); | ||
42 | |||
43 | /* | ||
44 | * check sigaction | ||
45 | */ | ||
46 | if (sigaction(SIGTHR, NULL, &sa) == 0) | ||
47 | errx(1, "sigaction(SIGTHR) succeeded"); | ||
48 | else if (errno != EINVAL) | ||
49 | err(1, "sigaction(SIGTHR) didn't fail with EINVAL"); | ||
50 | memset(&sa, 0, sizeof sa); | ||
51 | sa.sa_handler = sighandler; | ||
52 | sigfillset(&sa.sa_mask); | ||
53 | sa.sa_flags = 0; | ||
54 | if (sigaction(SIGTHR, &sa, NULL) == 0) | ||
55 | errx(1, "sigaction(SIGTHR) succeeded"); | ||
56 | else if (errno != EINVAL) | ||
57 | err(1, "sigaction(SIGTHR) didn't fail with EINVAL"); | ||
58 | if (sigaction(SIGUSR1, &sa, NULL)) | ||
59 | err(1, "sigaction(SIGUSR1)"); | ||
60 | if (sigaction(SIGUSR1, NULL, &sa)) | ||
61 | err(1, "sigaction(SIGUSR1)"); | ||
62 | if (sigismember(&sa.sa_mask, SIGTHR)) | ||
63 | errx(1, "SIGTHR blocked with sigaction"); | ||
64 | |||
65 | return 0; | ||
66 | } | ||
diff --git a/src/regress/lib/libc/sleep/Makefile b/src/regress/lib/libc/sleep/Makefile deleted file mode 100644 index 3700b1662a..0000000000 --- a/src/regress/lib/libc/sleep/Makefile +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2009/12/14 05:08:19 guenther Exp $ | ||
2 | |||
3 | NOMAN= | ||
4 | PROG=sleep_test | ||
5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
6 | |||
7 | run-regress-${PROG}: ${PROG} | ||
8 | [ x$$(./${PROG} 1) = x0 ] || exit 1 | ||
9 | file=$$(mktemp -t sleep.XXXXXXXXXX); ./${PROG} 4 >$$file & pid=$$!; \ | ||
10 | sleep 1; kill $$pid; sleep 1; v=$$(cat $$file); rm -f $$file; \ | ||
11 | { [ $$v -gt 0 ] && [ $$v -lt 4 ] ; } || exit 2 | ||
12 | |||
13 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sleep/sleep_test.c b/src/regress/lib/libc/sleep/sleep_test.c deleted file mode 100644 index 4c7764375d..0000000000 --- a/src/regress/lib/libc/sleep/sleep_test.c +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | /* $OpenBSD: sleep_test.c,v 1.2 2015/10/18 23:27:43 guenther Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2009 Philip Guenther | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * | ||
11 | * - Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * - Redistributions in binary form must reproduce the above | ||
14 | * copyright notice, this list of conditions and the following | ||
15 | * disclaimer in the documentation and/or other materials provided | ||
16 | * with the distribution. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
29 | * POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | /* | ||
33 | * Test whether sleep returns the correct value | ||
34 | */ | ||
35 | |||
36 | #include <sys/types.h> | ||
37 | #include <err.h> | ||
38 | #include <errno.h> | ||
39 | #include <limits.h> | ||
40 | #include <signal.h> | ||
41 | #include <stddef.h> | ||
42 | #include <stdio.h> | ||
43 | #include <stdlib.h> | ||
44 | #include <string.h> | ||
45 | #include <unistd.h> | ||
46 | |||
47 | static void | ||
48 | handler(int sig) | ||
49 | { | ||
50 | return; | ||
51 | } | ||
52 | |||
53 | static void * | ||
54 | garbage(void) | ||
55 | { | ||
56 | char buf[20]; | ||
57 | strlcpy(buf, "012354678901235467890123546789", sizeof buf); | ||
58 | return buf; | ||
59 | } | ||
60 | |||
61 | int | ||
62 | main(int argc, char *argv[]) | ||
63 | { | ||
64 | struct sigaction sa; | ||
65 | char const *errstr; | ||
66 | int i; | ||
67 | |||
68 | if (argc != 2) | ||
69 | return (1); | ||
70 | errno = 0; | ||
71 | i = strtonum(argv[1], 0, INT_MAX, &errstr); | ||
72 | if (i == 0 && errno != 0) { | ||
73 | fprintf(stderr, "%s\n", errstr); | ||
74 | return (1); | ||
75 | } | ||
76 | |||
77 | memset(&sa, 0, sizeof sa); | ||
78 | sa.sa_handler = &handler; | ||
79 | if (sigaction(SIGTERM, &sa, NULL)) | ||
80 | err(3, "sigaction"); | ||
81 | garbage(); | ||
82 | printf("%d\n", sleep(i)); | ||
83 | return (0); | ||
84 | } | ||
85 | |||
diff --git a/src/regress/lib/libc/sprintf/Makefile b/src/regress/lib/libc/sprintf/Makefile deleted file mode 100644 index 514d795f2f..0000000000 --- a/src/regress/lib/libc/sprintf/Makefile +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ | ||
2 | |||
3 | PROG = sprintf_test | ||
4 | CFLAGS = -Wno-format | ||
5 | CPPFLAGS = -I${.CURDIR}/../../../../lib/libc | ||
6 | |||
7 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sprintf/sprintf_test.c b/src/regress/lib/libc/sprintf/sprintf_test.c deleted file mode 100644 index 0cdd170911..0000000000 --- a/src/regress/lib/libc/sprintf/sprintf_test.c +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | /* $OpenBSD: sprintf_test.c,v 1.5 2021/09/02 09:46:21 deraadt Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2003 Theo de Raadt | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * | ||
11 | * - Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * - Redistributions in binary form must reproduce the above | ||
14 | * copyright notice, this list of conditions and the following | ||
15 | * disclaimer in the documentation and/or other materials provided | ||
16 | * with the distribution. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
29 | * POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | #include <stddef.h> | ||
33 | #include <stdio.h> | ||
34 | #include <stdlib.h> | ||
35 | #include <string.h> | ||
36 | #include <signal.h> | ||
37 | |||
38 | char correct[] = | ||
39 | "|xx 01 02 03 04\n" | ||
40 | "|xx 05 06 07 08\n" | ||
41 | "|xx 09 10 11 12\n" | ||
42 | "|xx 13 14 15 16\n" | ||
43 | "|xx 17 18 19 20\n" | ||
44 | "|xx 21 22 23 24\n" | ||
45 | "|xx 25 26 27 28\n" | ||
46 | "|xx 29 30 31 32\n" | ||
47 | "|xx 33 34 35 36\n" | ||
48 | "|xx 37 38 39 40\n" | ||
49 | "|xx 41 42 43 44\n" | ||
50 | "|xx 45 -1 1 -1 1\n"; | ||
51 | |||
52 | char correct2[] = | ||
53 | "1 0 -1 1 1 2 1 3 -1 4 1 \n" | ||
54 | "1 -1 1 1 -1 1 \n"; | ||
55 | |||
56 | int | ||
57 | main(int argc, char *argv[]) | ||
58 | { | ||
59 | char buf[1024]; | ||
60 | size_t sz1, sz2, sz3, sz4; | ||
61 | ptrdiff_t p1, p2, p3, p4; | ||
62 | |||
63 | /* Test positional arguments */ | ||
64 | snprintf(buf, sizeof buf, | ||
65 | "|xx %1$s %2$s %3$s %4$s\n" | ||
66 | "|xx %5$s %6$s %7$s %8$s\n" | ||
67 | "|xx %9$s %10$s %11$s %12$s\n" | ||
68 | "|xx %13$s %14$s %15$s %16$s\n" | ||
69 | "|xx %17$s %18$s %19$s %20$s\n" | ||
70 | "|xx %21$s %22$s %23$s %24$s\n" | ||
71 | "|xx %25$s %26$s %27$s %28$s\n" | ||
72 | "|xx %29$s %30$s %31$s %32$s\n" | ||
73 | "|xx %33$s %34$s %35$s %36$s\n" | ||
74 | "|xx %37$s %38$s %39$s %40$s\n" | ||
75 | "|xx %41$s %42$s %43$s %44$s\n" | ||
76 | "|xx %45$d %46$ld %47$lld %48$d %49$lld\n", | ||
77 | "01", "02", "03", "04", "05", "06", | ||
78 | "07", "08", "09", "10", "11", "12", | ||
79 | "13", "14", "15", "16", "17", "18", | ||
80 | "19", "20", "21", "22", "23", "24", | ||
81 | "25", "26", "27", "28", "29", "30", | ||
82 | "31", "32", "33", "34", "35", "36", | ||
83 | "37", "38", "39", "40", "41", "42", | ||
84 | "43", "44", 45, -1L, 1LL, -1, 1LL | ||
85 | ); | ||
86 | |||
87 | if (strcmp(buf, correct) != 0) | ||
88 | exit(1); | ||
89 | exit(0); | ||
90 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/Makefile b/src/regress/lib/libc/stdio_threading/Makefile deleted file mode 100644 index e42481afc2..0000000000 --- a/src/regress/lib/libc/stdio_threading/Makefile +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | SUBDIR += fopen fread fwrite fgetln fgets fputs | ||
2 | |||
3 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgetln/Makefile b/src/regress/lib/libc/stdio_threading/fgetln/Makefile deleted file mode 100644 index cad51e2b23..0000000000 --- a/src/regress/lib/libc/stdio_threading/fgetln/Makefile +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | TOPDIR=${.CURDIR} | ||
2 | PROG=fgetln_test | ||
3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
4 | LDFLAGS+=-lpthread | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c b/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c deleted file mode 100755 index 76d154bb2a..0000000000 --- a/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include "local.h" | ||
18 | |||
19 | void | ||
20 | fgetln_thread(void *v) | ||
21 | { | ||
22 | FILE *file = v; | ||
23 | size_t len; | ||
24 | char *buf; | ||
25 | int i; | ||
26 | |||
27 | for (i = 0; i < 4096; i++) { | ||
28 | if ((buf = fgetln(file, &len)) == NULL) { | ||
29 | |||
30 | if (feof(file)) | ||
31 | break; | ||
32 | |||
33 | printf("OMG!!!\n"); | ||
34 | fflush(stdout); | ||
35 | break; | ||
36 | } | ||
37 | if (strncmp(buf, TEXT_N, sizeof(TEXT_N))) | ||
38 | err(1, "fgetln not atomic!!!"); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | int | ||
43 | main(void) | ||
44 | { | ||
45 | char sfn[24]; | ||
46 | FILE *sfp; | ||
47 | int fd, i; | ||
48 | |||
49 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
50 | if ((fd = mkstemp(sfn)) == -1 || | ||
51 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
52 | int saved_errno = errno; | ||
53 | if (fd != -1) { | ||
54 | unlink(sfn); | ||
55 | close(fd); | ||
56 | } | ||
57 | errc(1, saved_errno, "could not open temporary file"); | ||
58 | } | ||
59 | |||
60 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
61 | if (fwrite(TEXT_N, sizeof(char), strlen(TEXT_N), sfp) == 0) | ||
62 | err(1, "Could not populate test file"); | ||
63 | |||
64 | run_threads(fgetln_thread, sfp); | ||
65 | |||
66 | unlink(sfn); | ||
67 | close(fd); | ||
68 | |||
69 | exit(0); | ||
70 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgets/Makefile b/src/regress/lib/libc/stdio_threading/fgets/Makefile deleted file mode 100644 index 52310fd429..0000000000 --- a/src/regress/lib/libc/stdio_threading/fgets/Makefile +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | TOPDIR=${.CURDIR} | ||
2 | PROG=fgets_test | ||
3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
4 | LDFLAGS+=-lpthread | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c b/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c deleted file mode 100755 index 7c5008e2ad..0000000000 --- a/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include "local.h" | ||
18 | |||
19 | void | ||
20 | fgets_thread(void *v) | ||
21 | { | ||
22 | char buf[sizeof(TEXT_N) + 1]; | ||
23 | FILE *file = v; | ||
24 | int i; | ||
25 | |||
26 | for (i = 0; i < 4096; i++) { | ||
27 | if (fgets(buf, sizeof(buf), file) == NULL) { | ||
28 | |||
29 | if (feof(file)) | ||
30 | break; | ||
31 | |||
32 | printf("OMG!!!\n"); | ||
33 | fflush(stdout); | ||
34 | break; | ||
35 | } | ||
36 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
37 | err(1, "Read not atomic!!!"); | ||
38 | } | ||
39 | } | ||
40 | |||
41 | int | ||
42 | main(void) | ||
43 | { | ||
44 | char sfn[24]; | ||
45 | FILE *sfp; | ||
46 | int fd, i; | ||
47 | |||
48 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
49 | if ((fd = mkstemp(sfn)) == -1 || | ||
50 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
51 | int saved_errno = errno; | ||
52 | if (fd != -1) { | ||
53 | unlink(sfn); | ||
54 | close(fd); | ||
55 | } | ||
56 | errc(1, saved_errno, "could not open temporary file"); | ||
57 | } | ||
58 | |||
59 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
60 | if (fwrite(TEXT_N, sizeof(char), strlen(TEXT_N), sfp) == 0) | ||
61 | err(1, "Could not populate test file"); | ||
62 | |||
63 | run_threads(fgets_thread, sfp); | ||
64 | |||
65 | unlink(sfn); | ||
66 | close(fd); | ||
67 | |||
68 | exit(0); | ||
69 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fopen/Makefile b/src/regress/lib/libc/stdio_threading/fopen/Makefile deleted file mode 100644 index e51deeff1d..0000000000 --- a/src/regress/lib/libc/stdio_threading/fopen/Makefile +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | TOPDIR=${.CURDIR} | ||
2 | PROG=fopen_test | ||
3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
4 | LDFLAGS+=-lpthread | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c b/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c deleted file mode 100755 index 89172d9fb7..0000000000 --- a/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | /* $OpenBSD: fopen_test.c,v 1.2 2015/01/20 04:41:01 krw Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <stdio.h> | ||
19 | #include <pthread.h> | ||
20 | #include "local.h" | ||
21 | |||
22 | int | ||
23 | writefn(void *cookie, const char *buf, int size) | ||
24 | { | ||
25 | return 0; | ||
26 | } | ||
27 | |||
28 | void | ||
29 | fopen_thread(void *v) | ||
30 | { | ||
31 | FILE *file; | ||
32 | int i; | ||
33 | |||
34 | for (i = 0; i < 4096; i++) { | ||
35 | file = fwopen(&i, writefn); | ||
36 | if (file != NULL) { | ||
37 | fputc('0', file); | ||
38 | pthread_yield(); | ||
39 | fclose(file); | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | |||
44 | int | ||
45 | main(void) | ||
46 | { | ||
47 | run_threads(fopen_thread, NULL); | ||
48 | exit(0); | ||
49 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fputs/Makefile b/src/regress/lib/libc/stdio_threading/fputs/Makefile deleted file mode 100644 index e561745581..0000000000 --- a/src/regress/lib/libc/stdio_threading/fputs/Makefile +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | TOPDIR=${.CURDIR} | ||
2 | PROG=fputs_test | ||
3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
4 | LDFLAGS+=-lpthread | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c b/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c deleted file mode 100755 index 93d0f0b6c7..0000000000 --- a/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include "local.h" | ||
18 | |||
19 | void | ||
20 | fputs_thread(void *v) | ||
21 | { | ||
22 | FILE *file = v; | ||
23 | int i; | ||
24 | |||
25 | for (i = 0; i < 4096; i++) { | ||
26 | if (fputs(TEXT, file) != 0) { | ||
27 | |||
28 | if (feof(file)) | ||
29 | break; | ||
30 | |||
31 | printf("OMG!!!\n"); | ||
32 | fflush(stdout); | ||
33 | break; | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | |||
38 | int | ||
39 | main(void) | ||
40 | { | ||
41 | char sfn[24]; | ||
42 | char buf[sizeof(TEXT)]; | ||
43 | FILE *sfp; | ||
44 | int fd; | ||
45 | |||
46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
47 | if ((fd = mkstemp(sfn)) == -1 || | ||
48 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
49 | int saved_errno = errno; | ||
50 | if (fd != -1) { | ||
51 | unlink(sfn); | ||
52 | close(fd); | ||
53 | } | ||
54 | errc(1, saved_errno, "could not open temporary file"); | ||
55 | } | ||
56 | |||
57 | run_threads(fputs_thread, sfp); | ||
58 | |||
59 | while (fgets(buf, sizeof(buf), sfp) != NULL) /* verify */ | ||
60 | if (strcmp(buf, TEXT)) | ||
61 | err(1, "Thread writes were not atomic!!!"); | ||
62 | |||
63 | unlink(sfn); | ||
64 | close(fd); | ||
65 | |||
66 | exit(0); | ||
67 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fread/Makefile b/src/regress/lib/libc/stdio_threading/fread/Makefile deleted file mode 100644 index 25196dd7ab..0000000000 --- a/src/regress/lib/libc/stdio_threading/fread/Makefile +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | TOPDIR=${.CURDIR} | ||
2 | PROG=fread_test | ||
3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
4 | LDFLAGS+=-lpthread | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fread/fread_test.c b/src/regress/lib/libc/stdio_threading/fread/fread_test.c deleted file mode 100755 index 6bd734b470..0000000000 --- a/src/regress/lib/libc/stdio_threading/fread/fread_test.c +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <stdio.h> | ||
18 | #include <pthread.h> | ||
19 | #include "local.h" | ||
20 | |||
21 | void | ||
22 | fread_thread(void *v) | ||
23 | { | ||
24 | char buf[sizeof(TEXT)]; | ||
25 | FILE *file = v; | ||
26 | int i; | ||
27 | |||
28 | for (i = 0; i < 4096; i++) { | ||
29 | if (fread(buf, sizeof(char), strlen(TEXT), file) == 0) { | ||
30 | |||
31 | if (feof(file)) | ||
32 | break; | ||
33 | |||
34 | printf("OMG!!!\n"); | ||
35 | fflush(stdout); | ||
36 | break; | ||
37 | } | ||
38 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
39 | err(1, "Read not atomic!!!"); | ||
40 | } | ||
41 | } | ||
42 | |||
43 | int | ||
44 | main(void) | ||
45 | { | ||
46 | char sfn[24]; | ||
47 | FILE *sfp; | ||
48 | int fd, i; | ||
49 | |||
50 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
51 | if ((fd = mkstemp(sfn)) == -1 || | ||
52 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
53 | int saved_errno = errno; | ||
54 | if (fd != -1) { | ||
55 | unlink(sfn); | ||
56 | close(fd); | ||
57 | } | ||
58 | errc(1, saved_errno, "could not open temporary file"); | ||
59 | } | ||
60 | |||
61 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
62 | if (fwrite(TEXT, sizeof(char), strlen(TEXT), sfp) == 0) | ||
63 | err(1, "Could not populate test file"); | ||
64 | |||
65 | run_threads(fread_thread, sfp); | ||
66 | |||
67 | unlink(sfn); | ||
68 | close(fd); | ||
69 | |||
70 | exit(0); | ||
71 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fwrite/Makefile b/src/regress/lib/libc/stdio_threading/fwrite/Makefile deleted file mode 100644 index e79899c475..0000000000 --- a/src/regress/lib/libc/stdio_threading/fwrite/Makefile +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | TOPDIR=${.CURDIR} | ||
2 | PROG=fwrite_test | ||
3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
4 | LDFLAGS+=-lpthread | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c b/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c deleted file mode 100755 index 86c450cbc9..0000000000 --- a/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include "local.h" | ||
18 | |||
19 | void | ||
20 | fwrite_thread(void *v) | ||
21 | { | ||
22 | FILE *file = v; | ||
23 | int i; | ||
24 | |||
25 | for (i = 0; i < 4096; i++) { | ||
26 | if (fwrite(TEXT, sizeof(char), strlen(TEXT), file) == 0) { | ||
27 | |||
28 | if (feof(file)) | ||
29 | break; | ||
30 | |||
31 | printf("OMG!!!\n"); | ||
32 | fflush(stdout); | ||
33 | break; | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | |||
38 | int | ||
39 | main(void) | ||
40 | { | ||
41 | char sfn[24]; | ||
42 | char buf[sizeof(TEXT)]; | ||
43 | FILE *sfp; | ||
44 | int fd; | ||
45 | |||
46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
47 | if ((fd = mkstemp(sfn)) == -1 || | ||
48 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
49 | int saved_errno = errno; | ||
50 | if (fd != -1) { | ||
51 | unlink(sfn); | ||
52 | close(fd); | ||
53 | } | ||
54 | errc(1, saved_errno, "could not open temporary file"); | ||
55 | } | ||
56 | |||
57 | run_threads(fwrite_thread, sfp); | ||
58 | |||
59 | while (fread(buf, sizeof(char), strlen(TEXT), sfp)) /* verify */ | ||
60 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
61 | err(1, "Thread writes were not atomic!!!"); | ||
62 | |||
63 | unlink(sfn); | ||
64 | close(fd); | ||
65 | |||
66 | exit(0); | ||
67 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/include/local.h b/src/regress/lib/libc/stdio_threading/include/local.h deleted file mode 100644 index 7a7822a452..0000000000 --- a/src/regress/lib/libc/stdio_threading/include/local.h +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <err.h> | ||
18 | #include <errno.h> | ||
19 | #include <stdio.h> | ||
20 | #include <stdlib.h> | ||
21 | #include <string.h> | ||
22 | #include <unistd.h> | ||
23 | #include <pthread.h> | ||
24 | |||
25 | #define THREAD_COUNT 64 | ||
26 | |||
27 | #define TEXT "barnacles" | ||
28 | #define TEXT_N "barnacles\n" | ||
29 | |||
30 | void run_threads(void (*)(void *), void *); | ||
31 | |||
32 | static pthread_rwlock_t start; | ||
33 | static void (*real_func)(void *); | ||
34 | |||
35 | static void * | ||
36 | thread(void *arg) | ||
37 | { | ||
38 | int r; | ||
39 | |||
40 | if ((r = pthread_rwlock_rdlock(&start))) | ||
41 | errc(1, r, "could not obtain lock in thread"); | ||
42 | real_func(arg); | ||
43 | if ((r = pthread_rwlock_unlock(&start))) | ||
44 | errc(1, r, "could not release lock in thread"); | ||
45 | return NULL; | ||
46 | } | ||
47 | |||
48 | void | ||
49 | run_threads(void (*func)(void *), void *arg) | ||
50 | { | ||
51 | pthread_t self, pthread[THREAD_COUNT]; | ||
52 | int i, r; | ||
53 | |||
54 | self = pthread_self(); | ||
55 | real_func = func; | ||
56 | if ((r = pthread_rwlock_init(&start, NULL))) | ||
57 | errc(1, r, "could not initialize lock"); | ||
58 | |||
59 | if ((r = pthread_rwlock_wrlock(&start))) /* block */ | ||
60 | errc(1, r, "could not lock lock"); | ||
61 | |||
62 | for (i = 0; i < THREAD_COUNT; i++) | ||
63 | if ((r = pthread_create(&pthread[i], NULL, thread, arg))) { | ||
64 | warnc(r, "could not create thread"); | ||
65 | pthread[i] = self; | ||
66 | } | ||
67 | |||
68 | |||
69 | if ((r = pthread_rwlock_unlock(&start))) /* unleash */ | ||
70 | errc(1, r, "could not release lock"); | ||
71 | |||
72 | sleep(1); | ||
73 | |||
74 | if ((r = pthread_rwlock_wrlock(&start))) /* sync */ | ||
75 | errx(1, "parent could not sync with children: %s", | ||
76 | strerror(r)); | ||
77 | |||
78 | for (i = 0; i < THREAD_COUNT; i++) | ||
79 | if (! pthread_equal(pthread[i], self) && | ||
80 | (r = pthread_join(pthread[i], NULL))) | ||
81 | warnc(r, "could not join thread"); | ||
82 | } | ||
83 | |||
diff --git a/src/regress/lib/libc/stpncpy/Makefile b/src/regress/lib/libc/stpncpy/Makefile deleted file mode 100644 index 9333934da6..0000000000 --- a/src/regress/lib/libc/stpncpy/Makefile +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | PROG=stpncpy_test | ||
2 | |||
3 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stpncpy/stpncpy_test.c b/src/regress/lib/libc/stpncpy/stpncpy_test.c deleted file mode 100644 index 63b7d25e53..0000000000 --- a/src/regress/lib/libc/stpncpy/stpncpy_test.c +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | /* $OpenBSD: stpncpy_test.c,v 1.1 2012/07/11 10:46:23 naddy Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Public domain, 2012, Christian Weisgerber <naddy@openbsd.org> | ||
5 | */ | ||
6 | |||
7 | #include <string.h> | ||
8 | |||
9 | int main(void) | ||
10 | { | ||
11 | char dst[8]; | ||
12 | char *src = "abcdef"; | ||
13 | |||
14 | if (stpncpy(dst, src, 5) != dst + 5) | ||
15 | return 1; | ||
16 | if (stpncpy(dst, src, 6) != dst + 6) | ||
17 | return 1; | ||
18 | if (stpncpy(dst, src, 7) != dst + 6) | ||
19 | return 1; | ||
20 | if (stpncpy(dst, src, 8) != dst + 6) | ||
21 | return 1; | ||
22 | |||
23 | return 0; | ||
24 | } | ||
diff --git a/src/regress/lib/libc/strchr/Makefile b/src/regress/lib/libc/strchr/Makefile deleted file mode 100644 index 355c0d9421..0000000000 --- a/src/regress/lib/libc/strchr/Makefile +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2021/07/24 05:45:49 visa Exp $ | ||
2 | |||
3 | PROG= strchrtest | ||
4 | |||
5 | CFLAGS+= -fno-builtin-strchr | ||
6 | CFLAGS+= -fno-builtin-strrchr | ||
7 | |||
8 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strchr/strchrtest.c b/src/regress/lib/libc/strchr/strchrtest.c deleted file mode 100644 index 0be4c8df63..0000000000 --- a/src/regress/lib/libc/strchr/strchrtest.c +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | /* $OpenBSD: strchrtest.c,v 1.2 2021/09/01 09:26:32 jasper Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2021 Visa Hankala | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <assert.h> | ||
20 | #include <stdio.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | #include <unistd.h> | ||
24 | |||
25 | int | ||
26 | main(void) | ||
27 | { | ||
28 | char *buf; | ||
29 | size_t bufsize; | ||
30 | |||
31 | /* Allocate buffer with guard pages. */ | ||
32 | bufsize = getpagesize(); | ||
33 | buf = malloc(bufsize); | ||
34 | if (buf == NULL) { | ||
35 | fprintf(stderr, "unable to allocate memory\n"); | ||
36 | return 1; | ||
37 | } | ||
38 | |||
39 | memset(buf, 0, bufsize); | ||
40 | assert(strchr(buf, 'a') == NULL); | ||
41 | assert(strchr(buf, '\0') == buf); | ||
42 | assert(strrchr(buf, 'a') == NULL); | ||
43 | assert(strrchr(buf, '\0') == buf); | ||
44 | |||
45 | memcpy(buf, "haystack\xcf\x80", 10); | ||
46 | assert(strchr(buf, 'a') == buf + 1); | ||
47 | assert(strchr(buf, '\x80') == buf + 9); | ||
48 | assert(strchr(buf, 0x180) == buf + 9); | ||
49 | assert(strchr(buf, '\0') == buf + 10); | ||
50 | assert(strrchr(buf, 'a') == buf + 5); | ||
51 | assert(strrchr(buf, '\xcf') == buf + 8); | ||
52 | assert(strrchr(buf, 0x3cf) == buf + 8); | ||
53 | assert(strrchr(buf, '\0') == buf + 10); | ||
54 | |||
55 | memset(buf, 'a', bufsize - 2); | ||
56 | buf[0] = 'b'; | ||
57 | buf[bufsize - 2] = 'b'; | ||
58 | assert(strchr(buf, 'b') == buf); | ||
59 | assert(strchr(buf, 'c') == NULL); | ||
60 | assert(strchr(buf, '\0') == buf + bufsize - 1); | ||
61 | assert(strrchr(buf, 'b') == buf + bufsize - 2); | ||
62 | assert(strrchr(buf, 'c') == NULL); | ||
63 | assert(strrchr(buf, '\0') == buf + bufsize - 1); | ||
64 | |||
65 | return 0; | ||
66 | } | ||
diff --git a/src/regress/lib/libc/strerror/Makefile b/src/regress/lib/libc/strerror/Makefile deleted file mode 100644 index 448b6da903..0000000000 --- a/src/regress/lib/libc/strerror/Makefile +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2004/04/30 17:15:12 espie Exp $ | ||
2 | |||
3 | NOMAN= | ||
4 | PROG=strerror_test | ||
5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
6 | CLEANFILES+= invalid.out valid.out | ||
7 | |||
8 | run-regress-strerror_test: ${PROG} | ||
9 | ./${PROG} >${.OBJDIR}/valid.out | ||
10 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok | ||
11 | |||
12 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strerror/strerror_test.c b/src/regress/lib/libc/strerror/strerror_test.c deleted file mode 100644 index 23b542f1ee..0000000000 --- a/src/regress/lib/libc/strerror/strerror_test.c +++ /dev/null | |||
@@ -1,65 +0,0 @@ | |||
1 | /* $OpenBSD: strerror_test.c,v 1.5 2015/09/14 06:31:25 guenther Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | #include <signal.h> | ||
18 | #include <string.h> | ||
19 | #include <stdio.h> | ||
20 | #include <limits.h> | ||
21 | #include <errno.h> | ||
22 | |||
23 | void | ||
24 | check_strerror_r(int val) | ||
25 | { | ||
26 | char buffer[NL_TEXTMAX + 1]; | ||
27 | int i, r; | ||
28 | |||
29 | memset(buffer, 'X', sizeof(buffer) - 1); | ||
30 | buffer[sizeof(buffer) - 1] = '\0'; | ||
31 | (void)strerror_r(val, NULL, 0); /* XXX */ | ||
32 | for (i = 0; i < 25; i++) { | ||
33 | r = strerror_r(val, buffer, i); | ||
34 | printf("%d %d %zu: %s\n", i, r, strlen(buffer), buffer); | ||
35 | } | ||
36 | } | ||
37 | |||
38 | void | ||
39 | check_strsignal(int val) | ||
40 | { | ||
41 | printf("%s\n", strsignal(val)); | ||
42 | } | ||
43 | |||
44 | int | ||
45 | main() | ||
46 | { | ||
47 | printf("%s\n", strerror(21345)); | ||
48 | printf("%s\n", strerror(-21345)); | ||
49 | printf("%s\n", strerror(0)); | ||
50 | printf("%s\n", strerror(INT_MAX)); | ||
51 | printf("%s\n", strerror(INT_MIN)); | ||
52 | printf("%s\n", strerror(EPERM)); | ||
53 | check_strerror_r(EPERM); | ||
54 | check_strerror_r(21345); | ||
55 | check_strsignal(-1); | ||
56 | check_strsignal(0); | ||
57 | check_strsignal(10); | ||
58 | check_strsignal(NSIG-1); | ||
59 | check_strsignal(NSIG); | ||
60 | check_strsignal(100); | ||
61 | check_strsignal(INT_MAX); | ||
62 | check_strsignal(INT_MIN); | ||
63 | check_strsignal(UINT_MAX); | ||
64 | return 0; | ||
65 | } | ||
diff --git a/src/regress/lib/libc/strerror/valid.ok b/src/regress/lib/libc/strerror/valid.ok deleted file mode 100644 index cbc365c598..0000000000 --- a/src/regress/lib/libc/strerror/valid.ok +++ /dev/null | |||
@@ -1,65 +0,0 @@ | |||
1 | Unknown error: 21345 | ||
2 | Unknown error: -21345 | ||
3 | Undefined error: 0 | ||
4 | Unknown error: 2147483647 | ||
5 | Unknown error: -2147483648 | ||
6 | Operation not permitted | ||
7 | 0 34 255: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
8 | 1 34 0: | ||
9 | 2 34 1: O | ||
10 | 3 34 2: Op | ||
11 | 4 34 3: Ope | ||
12 | 5 34 4: Oper | ||
13 | 6 34 5: Opera | ||
14 | 7 34 6: Operat | ||
15 | 8 34 7: Operati | ||
16 | 9 34 8: Operatio | ||
17 | 10 34 9: Operation | ||
18 | 11 34 10: Operation | ||
19 | 12 34 11: Operation n | ||
20 | 13 34 12: Operation no | ||
21 | 14 34 13: Operation not | ||
22 | 15 34 14: Operation not | ||
23 | 16 34 15: Operation not p | ||
24 | 17 34 16: Operation not pe | ||
25 | 18 34 17: Operation not per | ||
26 | 19 34 18: Operation not perm | ||
27 | 20 34 19: Operation not permi | ||
28 | 21 34 20: Operation not permit | ||
29 | 22 34 21: Operation not permitt | ||
30 | 23 34 22: Operation not permitte | ||
31 | 24 0 23: Operation not permitted | ||
32 | 0 34 255: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
33 | 1 34 0: | ||
34 | 2 34 1: U | ||
35 | 3 34 2: Un | ||
36 | 4 34 3: Unk | ||
37 | 5 34 4: Unkn | ||
38 | 6 34 5: Unkno | ||
39 | 7 34 6: Unknow | ||
40 | 8 34 7: Unknown | ||
41 | 9 34 8: Unknown | ||
42 | 10 34 9: Unknown e | ||
43 | 11 34 10: Unknown er | ||
44 | 12 34 11: Unknown err | ||
45 | 13 34 12: Unknown erro | ||
46 | 14 34 13: Unknown error | ||
47 | 15 34 14: Unknown error: | ||
48 | 16 34 15: Unknown error: | ||
49 | 17 34 15: Unknown error: | ||
50 | 18 34 15: Unknown error: | ||
51 | 19 34 15: Unknown error: | ||
52 | 20 34 15: Unknown error: | ||
53 | 21 22 20: Unknown error: 21345 | ||
54 | 22 22 20: Unknown error: 21345 | ||
55 | 23 22 20: Unknown error: 21345 | ||
56 | 24 22 20: Unknown error: 21345 | ||
57 | Unknown signal: 4294967295 | ||
58 | Signal 0 | ||
59 | Bus error | ||
60 | Thread AST | ||
61 | Unknown signal: 33 | ||
62 | Unknown signal: 100 | ||
63 | Unknown signal: 2147483647 | ||
64 | Unknown signal: 2147483648 | ||
65 | Unknown signal: 4294967295 | ||
diff --git a/src/regress/lib/libc/strlcat/Makefile b/src/regress/lib/libc/strlcat/Makefile deleted file mode 100644 index 858cb22696..0000000000 --- a/src/regress/lib/libc/strlcat/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2014/12/02 17:48:34 millert Exp $ | ||
2 | |||
3 | PROG= strlcattest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strlcat/strlcattest.c b/src/regress/lib/libc/strlcat/strlcattest.c deleted file mode 100644 index a86fbed843..0000000000 --- a/src/regress/lib/libc/strlcat/strlcattest.c +++ /dev/null | |||
@@ -1,171 +0,0 @@ | |||
1 | /* $OpenBSD: strlcattest.c,v 1.5 2021/09/27 19:33:58 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2014 Todd C. Miller <millert@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <sys/types.h> | ||
20 | |||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | #include <setjmp.h> | ||
25 | #include <signal.h> | ||
26 | #include <unistd.h> | ||
27 | |||
28 | volatile sig_atomic_t got_signal; | ||
29 | sigjmp_buf jmpenv; | ||
30 | |||
31 | void | ||
32 | handler(int signo) | ||
33 | { | ||
34 | got_signal = signo; | ||
35 | siglongjmp(jmpenv, 1); | ||
36 | } | ||
37 | |||
38 | int | ||
39 | main(int argc, char *argv[]) | ||
40 | { | ||
41 | char *buf, *cp, *ep; | ||
42 | struct sigaction sa; | ||
43 | size_t len, bufsize; | ||
44 | volatile int failures = 0; | ||
45 | |||
46 | bufsize = getpagesize(); /* trigger guard pages easily */ | ||
47 | buf = malloc(bufsize); | ||
48 | if (buf == NULL) { | ||
49 | fprintf(stderr, "unable to allocate memory\n"); | ||
50 | return 1; | ||
51 | } | ||
52 | memset(buf, 'z', bufsize); | ||
53 | ep = buf + bufsize; | ||
54 | |||
55 | /* Test appending to an unterminated string. */ | ||
56 | len = strlcat(buf, "abcd", bufsize); | ||
57 | if (len != 4 + bufsize) { | ||
58 | fprintf(stderr, | ||
59 | "strlcat: failed unterminated buffer test (1a)\n"); | ||
60 | failures++; | ||
61 | } | ||
62 | /* Make sure we only wrote where expected. */ | ||
63 | for (cp = buf; cp < ep; cp++) { | ||
64 | if (*cp != 'z') { | ||
65 | fprintf(stderr, | ||
66 | "strlcat: failed unterminated buffer test (1b)\n"); | ||
67 | failures++; | ||
68 | break; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | /* Test appending to a full string. */ | ||
73 | ep[-1] = '\0'; | ||
74 | len = strlcat(buf, "abcd", bufsize); | ||
75 | if (len != 4 + bufsize - 1) { | ||
76 | fprintf(stderr, "strlcat: failed full buffer test (2a)\n"); | ||
77 | failures++; | ||
78 | } | ||
79 | /* Make sure we only wrote where expected. */ | ||
80 | for (cp = buf; cp < ep - 1; cp++) { | ||
81 | if (*cp != 'z') { | ||
82 | fprintf(stderr, | ||
83 | "strlcat: failed full buffer test (2b)\n"); | ||
84 | failures++; | ||
85 | break; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | /* Test appending to an empty string. */ | ||
90 | ep[-1] = 'z'; | ||
91 | buf[0] = '\0'; | ||
92 | len = strlcat(buf, "abcd", bufsize); | ||
93 | if (len != 4) { | ||
94 | fprintf(stderr, "strlcat: failed empty buffer test (3a)\n"); | ||
95 | failures++; | ||
96 | } | ||
97 | /* Make sure we only wrote where expected. */ | ||
98 | if (memcmp(buf, "abcd", sizeof("abcd")) != 0) { | ||
99 | fprintf(stderr, "strlcat: failed empty buffer test (3b)\n"); | ||
100 | failures++; | ||
101 | } | ||
102 | for (cp = buf + len + 1; cp < ep; cp++) { | ||
103 | if (*cp != 'z') { | ||
104 | fprintf(stderr, | ||
105 | "strlcat: failed empty buffer test (3c)\n"); | ||
106 | failures++; | ||
107 | break; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | /* Test appending to a NUL-terminated string. */ | ||
112 | memcpy(buf, "abcd", sizeof("abcd")); | ||
113 | len = strlcat(buf, "efgh", bufsize); | ||
114 | if (len != 8) { | ||
115 | fprintf(stderr, "strlcat: failed empty buffer test (4a)\n"); | ||
116 | failures++; | ||
117 | } | ||
118 | /* Make sure we only wrote where expected. */ | ||
119 | if (memcmp(buf, "abcdefgh", sizeof("abcdefgh")) != 0) { | ||
120 | fprintf(stderr, "strlcat: failed empty buffer test (4b)\n"); | ||
121 | failures++; | ||
122 | } | ||
123 | for (cp = buf + len + 1; cp < ep; cp++) { | ||
124 | if (*cp != 'z') { | ||
125 | fprintf(stderr, | ||
126 | "strlcat: failed empty buffer test (4c)\n"); | ||
127 | failures++; | ||
128 | break; | ||
129 | } | ||
130 | } | ||
131 | |||
132 | /* | ||
133 | * The following tests should result in SIGSEGV, however some | ||
134 | * systems may erroneously report SIGBUS. | ||
135 | * These tests assume that strlcat() is signal-safe. | ||
136 | */ | ||
137 | memset(&sa, 0, sizeof(sa)); | ||
138 | sigemptyset(&sa.sa_mask); | ||
139 | sa.sa_handler = handler; | ||
140 | sigaction(SIGSEGV, &sa, NULL); | ||
141 | sigaction(SIGBUS, &sa, NULL); | ||
142 | |||
143 | /* Test copying to a NULL buffer with non-zero size. */ | ||
144 | got_signal = 0; | ||
145 | if (sigsetjmp(jmpenv, 1) == 0) { | ||
146 | len = strlcat(NULL, "abcd", sizeof(buf)); | ||
147 | fprintf(stderr, "strlcat: failed NULL dst test (5a), " | ||
148 | "expected signal %d, got len %zu\n", SIGSEGV, len); | ||
149 | failures++; | ||
150 | } else if (got_signal != SIGSEGV) { | ||
151 | fprintf(stderr, "strlcat: failed NULL dst test (5b), " | ||
152 | "expected signal %d, got %d\n", SIGSEGV, got_signal); | ||
153 | failures++; | ||
154 | } | ||
155 | |||
156 | /* Test copying from a NULL src. */ | ||
157 | memcpy(buf, "abcd", sizeof("abcd")); | ||
158 | got_signal = 0; | ||
159 | if (sigsetjmp(jmpenv, 1) == 0) { | ||
160 | len = strlcat(buf, NULL, sizeof(buf)); | ||
161 | fprintf(stderr, "strlcat: failed NULL src test (6a), " | ||
162 | "expected signal %d, got len %zu\n", SIGSEGV, len); | ||
163 | failures++; | ||
164 | } else if (got_signal != SIGSEGV) { | ||
165 | fprintf(stderr, "strlcat: failed NULL src test (6b), " | ||
166 | "expected signal %d, got %d\n", SIGSEGV, got_signal); | ||
167 | failures++; | ||
168 | } | ||
169 | |||
170 | return failures; | ||
171 | } | ||
diff --git a/src/regress/lib/libc/strlcpy/Makefile b/src/regress/lib/libc/strlcpy/Makefile deleted file mode 100644 index 921354432b..0000000000 --- a/src/regress/lib/libc/strlcpy/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2014/12/02 20:23:05 millert Exp $ | ||
2 | |||
3 | PROG= strlcpytest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strlcpy/strlcpytest.c b/src/regress/lib/libc/strlcpy/strlcpytest.c deleted file mode 100644 index ebc1c56a45..0000000000 --- a/src/regress/lib/libc/strlcpy/strlcpytest.c +++ /dev/null | |||
@@ -1,167 +0,0 @@ | |||
1 | /* $OpenBSD: strlcpytest.c,v 1.5 2021/09/27 19:33:58 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2014 Todd C. Miller <millert@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <sys/types.h> | ||
20 | |||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | #include <signal.h> | ||
25 | #include <setjmp.h> | ||
26 | #include <unistd.h> | ||
27 | |||
28 | volatile sig_atomic_t got_signal; | ||
29 | sigjmp_buf jmpenv; | ||
30 | |||
31 | void | ||
32 | handler(int signo) | ||
33 | { | ||
34 | got_signal = signo; | ||
35 | siglongjmp(jmpenv, 1); | ||
36 | } | ||
37 | |||
38 | int | ||
39 | main(int argc, char *argv[]) | ||
40 | { | ||
41 | char *buf, *buf2, *cp, *ep; | ||
42 | struct sigaction sa; | ||
43 | size_t len, bufsize; | ||
44 | volatile int failures = 0; | ||
45 | |||
46 | bufsize = getpagesize(); /* trigger guard pages easily */ | ||
47 | buf = malloc(bufsize); | ||
48 | buf2 = malloc(bufsize); | ||
49 | if (buf == NULL || buf2 == NULL) { | ||
50 | fprintf(stderr, "unable to allocate memory\n"); | ||
51 | return 1; | ||
52 | } | ||
53 | memset(buf, 'z', bufsize); | ||
54 | ep = buf + bufsize; | ||
55 | |||
56 | /* Test copying to a zero-length NULL buffer. */ | ||
57 | len = strlcpy(NULL, "abcd", 0); | ||
58 | if (len != 4) { | ||
59 | fprintf(stderr, | ||
60 | "strlcpy: failed zero-length buffer test (1a)\n"); | ||
61 | failures++; | ||
62 | } | ||
63 | |||
64 | /* Test copying small string to a large buffer. */ | ||
65 | len = strlcpy(buf, "abcd", bufsize); | ||
66 | if (len != 4) { | ||
67 | fprintf(stderr, "strlcpy: failed large buffer test (2a)\n"); | ||
68 | failures++; | ||
69 | } | ||
70 | /* Make sure we only wrote where expected. */ | ||
71 | if (memcmp(buf, "abcd", sizeof("abcd")) != 0) { | ||
72 | fprintf(stderr, "strlcpy: failed large buffer test (2b)\n"); | ||
73 | failures++; | ||
74 | } | ||
75 | for (cp = buf + len + 1; cp < ep; cp++) { | ||
76 | if (*cp != 'z') { | ||
77 | fprintf(stderr, | ||
78 | "strlcpy: failed large buffer test (2c)\n"); | ||
79 | failures++; | ||
80 | break; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | /* Test copying large string to a small buffer. */ | ||
85 | memset(buf, 'z', bufsize); | ||
86 | memset(buf2, 'x', bufsize - 1); | ||
87 | buf2[bufsize - 1] = '\0'; | ||
88 | len = strlcpy(buf, buf2, bufsize / 2); | ||
89 | if (len != bufsize - 1) { | ||
90 | fprintf(stderr, "strlcpy: failed small buffer test (3a)\n"); | ||
91 | failures++; | ||
92 | } | ||
93 | /* Make sure we only wrote where expected. */ | ||
94 | len = (bufsize / 2) - 1; | ||
95 | if (memcmp(buf, buf2, len) != 0 || buf[len] != '\0') { | ||
96 | fprintf(stderr, "strlcpy: failed small buffer test (3b)\n"); | ||
97 | failures++; | ||
98 | } | ||
99 | for (cp = buf + len + 1; cp < ep; cp++) { | ||
100 | if (*cp != 'z') { | ||
101 | fprintf(stderr, | ||
102 | "strlcpy: failed small buffer test (3c)\n"); | ||
103 | failures++; | ||
104 | break; | ||
105 | } | ||
106 | } | ||
107 | |||
108 | /* Test copying to a 1-byte buffer. */ | ||
109 | memset(buf, 'z', bufsize); | ||
110 | len = strlcpy(buf, "abcd", 1); | ||
111 | if (len != 4) { | ||
112 | fprintf(stderr, "strlcpy: failed 1-byte buffer test (4a)\n"); | ||
113 | failures++; | ||
114 | } | ||
115 | /* Make sure we only wrote where expected. */ | ||
116 | if (buf[0] != '\0') { | ||
117 | fprintf(stderr, "strlcpy: failed 1-byte buffer test (4b)\n"); | ||
118 | failures++; | ||
119 | } | ||
120 | for (cp = buf + 1; cp < ep; cp++) { | ||
121 | if (*cp != 'z') { | ||
122 | fprintf(stderr, | ||
123 | "strlcpy: failed 1-byte buffer test (4c)\n"); | ||
124 | failures++; | ||
125 | break; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | /* | ||
130 | * The following tests should result in SIGSEGV, however some | ||
131 | * systems may erroneously report SIGBUS. | ||
132 | * These tests assume that strlcpy() is signal-safe. | ||
133 | */ | ||
134 | memset(&sa, 0, sizeof(sa)); | ||
135 | sigemptyset(&sa.sa_mask); | ||
136 | sa.sa_handler = handler; | ||
137 | sigaction(SIGSEGV, &sa, NULL); | ||
138 | sigaction(SIGBUS, &sa, NULL); | ||
139 | |||
140 | /* Test copying to a NULL buffer with non-zero size. */ | ||
141 | got_signal = 0; | ||
142 | if (sigsetjmp(jmpenv, 1) == 0) { | ||
143 | len = strlcpy(NULL, "abcd", sizeof(buf)); | ||
144 | fprintf(stderr, "strlcpy: failed NULL dst test (5a), " | ||
145 | "expected signal %d, got len %zu\n", SIGSEGV, len); | ||
146 | failures++; | ||
147 | } else if (got_signal != SIGSEGV) { | ||
148 | fprintf(stderr, "strlcpy: failed NULL dst test (5b), " | ||
149 | "expected signal %d, got %d\n", SIGSEGV, got_signal); | ||
150 | failures++; | ||
151 | } | ||
152 | |||
153 | /* Test copying from a NULL src. */ | ||
154 | got_signal = 0; | ||
155 | if (sigsetjmp(jmpenv, 1) == 0) { | ||
156 | len = strlcpy(buf, NULL, sizeof(buf)); | ||
157 | fprintf(stderr, "strlcpy: failed NULL src test (6a), " | ||
158 | "expected signal %d, got len %zu\n", SIGSEGV, len); | ||
159 | failures++; | ||
160 | } else if (got_signal != SIGSEGV) { | ||
161 | fprintf(stderr, "strlcpy: failed NULL src test (6b), " | ||
162 | "expected signal %d, got %d\n", SIGSEGV, got_signal); | ||
163 | failures++; | ||
164 | } | ||
165 | |||
166 | return failures; | ||
167 | } | ||
diff --git a/src/regress/lib/libc/strnlen/Makefile b/src/regress/lib/libc/strnlen/Makefile deleted file mode 100644 index e7c74972e1..0000000000 --- a/src/regress/lib/libc/strnlen/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2010/06/02 12:20:47 millert Exp $ | ||
2 | |||
3 | PROG= strnlentest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strnlen/strnlentest.c b/src/regress/lib/libc/strnlen/strnlentest.c deleted file mode 100644 index 78f8cfb252..0000000000 --- a/src/regress/lib/libc/strnlen/strnlentest.c +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | /* $OpenBSD: strnlentest.c,v 1.3 2021/09/01 09:26:32 jasper Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2010 Todd C. Miller <millert@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <sys/types.h> | ||
20 | |||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | #include <unistd.h> | ||
25 | |||
26 | int main(int argc, char *argv[]) | ||
27 | { | ||
28 | char *buf; | ||
29 | int failures = 0; | ||
30 | size_t len, bufsize; | ||
31 | |||
32 | bufsize = getpagesize(); /* trigger guard pages easily */ | ||
33 | buf = malloc(bufsize); | ||
34 | if (buf == NULL) { | ||
35 | fprintf(stderr, "unable to allocate memory\n"); | ||
36 | return 1; | ||
37 | } | ||
38 | memset(buf, 'a', bufsize); | ||
39 | |||
40 | len = strnlen(buf, bufsize); | ||
41 | if (len != bufsize) { | ||
42 | fprintf(stderr, "strnlen: failed unterminated buffer test (1)"); | ||
43 | failures++; | ||
44 | } | ||
45 | |||
46 | len = strnlen(buf, bufsize / 2); | ||
47 | if (len != bufsize / 2) { | ||
48 | fprintf(stderr, "strnlen: failed unterminated buffer test (2)"); | ||
49 | failures++; | ||
50 | } | ||
51 | |||
52 | buf[bufsize - 1] = '\0'; | ||
53 | len = strnlen(buf, bufsize); | ||
54 | if (len != bufsize - 1) { | ||
55 | fprintf(stderr, "strnlen: failed NUL-terminated buffer test (1)"); | ||
56 | failures++; | ||
57 | } | ||
58 | |||
59 | len = strnlen(buf, (size_t)-1); | ||
60 | if (len != bufsize - 1) { | ||
61 | fprintf(stderr, "strnlen: failed NUL-terminated buffer test (2)"); | ||
62 | failures++; | ||
63 | } | ||
64 | |||
65 | return failures; | ||
66 | } | ||
diff --git a/src/regress/lib/libc/strtod/Makefile b/src/regress/lib/libc/strtod/Makefile deleted file mode 100644 index 030c0e7f56..0000000000 --- a/src/regress/lib/libc/strtod/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2006/09/29 11:00:24 otto Exp $ | ||
2 | |||
3 | PROG= strtodtest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strtod/strtodtest.c b/src/regress/lib/libc/strtod/strtodtest.c deleted file mode 100644 index 570a002b18..0000000000 --- a/src/regress/lib/libc/strtod/strtodtest.c +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | /* $OpenBSD: strtodtest.c,v 1.2 2017/02/25 07:28:32 jsg Exp $ */ | ||
2 | /* Public domain, Otto Moerbeek <otto@drijf.net>, 2006. */ | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <stdlib.h> | ||
6 | #include <errno.h> | ||
7 | #include <err.h> | ||
8 | |||
9 | /* | ||
10 | * Checks if strtod() reports underflow. | ||
11 | */ | ||
12 | |||
13 | int | ||
14 | main() | ||
15 | { | ||
16 | char *tmp="0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"; | ||
17 | double d; | ||
18 | |||
19 | d = strtod(tmp, NULL); | ||
20 | if (errno != ERANGE) | ||
21 | errx(1, "errno = %d", errno); | ||
22 | return (0); | ||
23 | } | ||
diff --git a/src/regress/lib/libc/strtol/Makefile b/src/regress/lib/libc/strtol/Makefile deleted file mode 100644 index 3e2f4c746d..0000000000 --- a/src/regress/lib/libc/strtol/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2012/11/18 04:11:09 jsing Exp $ | ||
2 | |||
3 | PROG= strtoltest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strtol/strtoltest.c b/src/regress/lib/libc/strtol/strtoltest.c deleted file mode 100644 index 2efd7b3ad1..0000000000 --- a/src/regress/lib/libc/strtol/strtoltest.c +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | /* $OpenBSD: strtoltest.c,v 1.4 2017/07/15 17:08:26 jsing Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2012 Joel Sing <jsing@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <errno.h> | ||
19 | #include <limits.h> | ||
20 | #include <stdlib.h> | ||
21 | #include <stdio.h> | ||
22 | #include <string.h> | ||
23 | |||
24 | struct strtol_test { | ||
25 | char *input; | ||
26 | long output; | ||
27 | char end; | ||
28 | int base; | ||
29 | int err; | ||
30 | }; | ||
31 | |||
32 | struct strtol_test strtol_tests[] = { | ||
33 | {"1234567890", 1234567890L, '\0', 0, 0}, | ||
34 | {"0755", 493L, '\0', 0, 0}, | ||
35 | {"0x7fFFffFf", 2147483647L, '\0', 0, 0}, | ||
36 | {"1234567890", 0L, '1', 1, EINVAL}, | ||
37 | {"10101010", 170L, '\0', 2, 0}, | ||
38 | {"755", 493L, '\0', 8, 0}, | ||
39 | {"1234567890", 1234567890L, '\0', 10, 0}, | ||
40 | {"abc", 0L, 'a', 10, 0}, | ||
41 | {"123xyz", 123L, 'x', 10, 0}, | ||
42 | {"-080000000", -2147483648L, '\0', 16, 0}, | ||
43 | {"deadbeefdeadbeef", LONG_MAX, '\0', 16, ERANGE}, | ||
44 | {"deadzbeef", 57005L, 'z', 16, 0}, | ||
45 | {"0xy", 0L, 'x', 16, 0}, | ||
46 | {"-quitebigmchuge", LONG_MIN, '\0', 32, ERANGE}, | ||
47 | {"zzz", 46655L, '\0', 36, 0}, | ||
48 | {"1234567890", 0L, '1', 37, EINVAL}, | ||
49 | {"1234567890", 0L, '1', 123, EINVAL}, | ||
50 | }; | ||
51 | |||
52 | int | ||
53 | main(int argc, char **argv) | ||
54 | { | ||
55 | struct strtol_test *test; | ||
56 | int failure = 0; | ||
57 | char *end; | ||
58 | u_int i; | ||
59 | long n; | ||
60 | |||
61 | for (i = 0; i < (sizeof(strtol_tests) / sizeof(strtol_tests[0])); i++) { | ||
62 | test = &strtol_tests[i]; | ||
63 | errno = 0; | ||
64 | n = strtol(test->input, &end, test->base); | ||
65 | if (n != test->output) { | ||
66 | fprintf(stderr, "TEST %i FAILED: %s base %i: %li\n", | ||
67 | i, test->input, test->base, n); | ||
68 | failure = 1; | ||
69 | } else if (*end != test->end) { | ||
70 | fprintf(stderr, "TEST %i FAILED: end is not %c: %c\n", | ||
71 | i, test->end, *end); | ||
72 | failure = 1; | ||
73 | } else if (errno != test->err) { | ||
74 | fprintf(stderr, "TEST %i FAILED: errno is not %i: %i\n", | ||
75 | i, test->err, errno); | ||
76 | failure = 1; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | return failure; | ||
81 | } | ||
diff --git a/src/regress/lib/libc/strtonum/Makefile b/src/regress/lib/libc/strtonum/Makefile deleted file mode 100644 index e0e8ecd139..0000000000 --- a/src/regress/lib/libc/strtonum/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2004/08/03 20:38:36 otto Exp $ | ||
2 | |||
3 | PROG= strtonumtest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strtonum/strtonumtest.c b/src/regress/lib/libc/strtonum/strtonumtest.c deleted file mode 100644 index 7e82a007fe..0000000000 --- a/src/regress/lib/libc/strtonum/strtonumtest.c +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | /* $OpenBSD: strtonumtest.c,v 1.1 2004/08/03 20:38:36 otto Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2004 Otto Moerbeek <otto@drijf.net> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <limits.h> | ||
19 | #include <stdio.h> | ||
20 | #include <stdlib.h> | ||
21 | |||
22 | int fail; | ||
23 | |||
24 | void | ||
25 | test(const char *p, long long lb, long long ub, int ok) | ||
26 | { | ||
27 | long long val; | ||
28 | const char *q; | ||
29 | |||
30 | val = strtonum(p, lb, ub, &q); | ||
31 | if (ok && q != NULL) { | ||
32 | fprintf(stderr, "%s [%lld-%lld] ", p, lb, ub); | ||
33 | fprintf(stderr, "NUMBER NOT ACCEPTED %s\n", q); | ||
34 | fail = 1; | ||
35 | } else if (!ok && q == NULL) { | ||
36 | fprintf(stderr, "%s [%lld-%lld] %lld ", p, lb, ub, val); | ||
37 | fprintf(stderr, "NUMBER ACCEPTED\n"); | ||
38 | fail = 1; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | int main(int argc, char *argv[]) | ||
43 | { | ||
44 | test("1", 0, 10, 1); | ||
45 | test("0", -2, 5, 1); | ||
46 | test("0", 2, 5, 0); | ||
47 | test("0", 2, LLONG_MAX, 0); | ||
48 | test("-2", 0, LLONG_MAX, 0); | ||
49 | test("0", -5, LLONG_MAX, 1); | ||
50 | test("-3", -3, LLONG_MAX, 1); | ||
51 | test("-9223372036854775808", LLONG_MIN, LLONG_MAX, 1); | ||
52 | test("9223372036854775807", LLONG_MIN, LLONG_MAX, 1); | ||
53 | test("-9223372036854775809", LLONG_MIN, LLONG_MAX, 0); | ||
54 | test("9223372036854775808", LLONG_MIN, LLONG_MAX, 0); | ||
55 | test("1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0); | ||
56 | test("-1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0); | ||
57 | test("-2", 10, -1, 0); | ||
58 | test("-2", -10, -1, 1); | ||
59 | test("-20", -10, -1, 0); | ||
60 | test("20", -10, -1, 0); | ||
61 | |||
62 | return (fail); | ||
63 | } | ||
64 | |||
diff --git a/src/regress/lib/libc/sys/Makefile b/src/regress/lib/libc/sys/Makefile deleted file mode 100644 index 5ff237d4e7..0000000000 --- a/src/regress/lib/libc/sys/Makefile +++ /dev/null | |||
@@ -1,152 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.18 2023/10/31 08:00:33 claudio Exp $ | ||
2 | |||
3 | # Copyright (c) 2019 Moritz Buhl <openbsd@moritzbuhl.de> | ||
4 | # Copyright (c) 2019 Alexander Bluhm <bluhm@openbsd.org> | ||
5 | # | ||
6 | # Permission to use, copy, modify, and distribute this software for any | ||
7 | # purpose with or without fee is hereby granted, provided that the above | ||
8 | # copyright notice and this permission notice appear in all copies. | ||
9 | # | ||
10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | |||
18 | # Each test program in PROGS may define several numbered subtests. | ||
19 | # In a first step compile all programs and extract their parameters. | ||
20 | # For each PROG define new regression subtests based on the test number. | ||
21 | |||
22 | .if defined(NUMBERS) | ||
23 | REGRESS_TARGETS = ${NUMBERS:C/(.*)/run-${PROG}-\1 cleanup-${PROG}-\1/} | ||
24 | .else | ||
25 | REGRESS_TARGETS = ${PROGS:S/^/run-/} | ||
26 | .endif | ||
27 | |||
28 | PROGS = | ||
29 | PROGS += t_access | ||
30 | PROGS += t_bind | ||
31 | PROGS += t_chroot t_clock_gettime | ||
32 | PROGS += t_connect | ||
33 | PROGS += t_dup | ||
34 | PROGS += t_fork | ||
35 | PROGS += t_fsync | ||
36 | PROGS += t_getgroups t_getitimer t_getlogin t_getpid t_getrusage | ||
37 | PROGS += t_getsid t_getsockname t_gettimeofday | ||
38 | PROGS += t_kevent | ||
39 | PROGS += t_kill | ||
40 | PROGS += t_link t_listen | ||
41 | PROGS += t_minherit | ||
42 | PROGS += t_mkdir | ||
43 | PROGS += t_mkfifo | ||
44 | PROGS += t_mknod | ||
45 | PROGS += t_mlock | ||
46 | PROGS += t_mmap | ||
47 | PROGS += t_msgctl | ||
48 | PROGS += t_msgget | ||
49 | PROGS += t_msgrcv | ||
50 | PROGS += t_msgsnd | ||
51 | PROGS += t_msync | ||
52 | PROGS += t_pipe | ||
53 | PROGS += t_pipe2 | ||
54 | PROGS += t_poll | ||
55 | PROGS += t_ppoll | ||
56 | PROGS += t_ptrace | ||
57 | PROGS += t_recvmmsg | ||
58 | PROGS += t_revoke | ||
59 | PROGS += t_select | ||
60 | PROGS += t_sendmmsg | ||
61 | PROGS += t_sendrecv | ||
62 | PROGS += t_setrlimit | ||
63 | PROGS += t_setuid | ||
64 | PROGS += t_sigaction | ||
65 | PROGS += t_sigaltstack | ||
66 | PROGS += t_socketpair | ||
67 | PROGS += t_stat | ||
68 | #PROGS += t_syscall Deleted: test of gcc1.x syscall pad | ||
69 | PROGS += t_truncate | ||
70 | PROGS += t_umask t_unlink | ||
71 | PROGS += t_vfork | ||
72 | PROGS += t_waitid | ||
73 | PROGS += t_wait_noproc | ||
74 | PROGS += t_wait_noproc_wnohang | ||
75 | PROGS += t_write | ||
76 | |||
77 | # failing tests | ||
78 | REGRESS_EXPECTED_FAILURES = | ||
79 | REGRESS_EXPECTED_FAILURES += run-t_mlock-4 | ||
80 | REGRESS_EXPECTED_FAILURES += run-t_msgrcv-3 | ||
81 | |||
82 | . for t in run-t_fork-{3,4,5} | ||
83 | ${t}: | ||
84 | # Only works with a controlling tty | ||
85 | @echo DISABLED | ||
86 | . endfor | ||
87 | |||
88 | run-t_vfork-2: | ||
89 | # SIGSTOP with vfork is masked before exec(3)/exit(3) | ||
90 | # see NetBSD: kern_sig.c,v 1.345 | ||
91 | @echo DISABLED | ||
92 | |||
93 | . for p in ${PROGS} | ||
94 | SRCS_$p = $p.c atf-c.c | ||
95 | . endfor | ||
96 | |||
97 | CFLAGS += -std=gnu99 | ||
98 | |||
99 | LDADD_t_getpid = -lpthread | ||
100 | |||
101 | run-t_truncate: setup-t_truncate | ||
102 | setup-t_truncate: | ||
103 | ${SUDO} touch truncate_test.root_owned | ||
104 | ${SUDO} chown root:wheel truncate_test.root_owned | ||
105 | |||
106 | run-t_chroot: clean-dir | ||
107 | run-t_ptrace: clean-dir | ||
108 | clean-dir: | ||
109 | ${SUDO} rm -rf dir | ||
110 | |||
111 | CLEANFILES = access dummy mmap truncate_test.root_owned | ||
112 | |||
113 | .for p in ${PROGS} | ||
114 | run-$p: $p | ||
115 | ulimit -c unlimited && \ | ||
116 | ntests="`./$p -n`" && \ | ||
117 | echo "1..$$ntests" && \ | ||
118 | tnumbers="`jot -ns' ' - 1 $$ntests`" && \ | ||
119 | ${.MAKE} -C ${.CURDIR} PROG=$p NUMBERS="$$tnumbers" regress | ||
120 | .endfor | ||
121 | |||
122 | .if defined(NUMBERS) | ||
123 | CUR_USER != id -g | ||
124 | |||
125 | . for n in ${NUMBERS} | ||
126 | DESCR_$n != eval `./${PROG} -i $n` && echo $$DESCR | ||
127 | REQ_USER_$n != eval `./${PROG} -i $n` && echo $$REQ_USER | ||
128 | |||
129 | . if ${REQ_USER_$n} == "root" | ||
130 | REGRESS_ROOT_TARGETS += run-${PROG}-$n | ||
131 | . endif | ||
132 | |||
133 | run-${PROG}-$n: | ||
134 | @echo "$n ${DESCR_$n}" | ||
135 | . if ${REQ_USER_$n} == "root" | ||
136 | ${SUDO} ./${PROG} -r $n | ||
137 | . elif ${REQ_USER_$n} == "unprivileged" && ${CUR_USER} == 0 | ||
138 | ${SUDO} su ${BUILDUSER} -c exec ./${PROG} -r $n | ||
139 | . elif ${REQ_USER_$n} == "unprivileged" || ${REQ_USER_$n} == "" | ||
140 | ./${PROG} -r $n | ||
141 | . else | ||
142 | # bad REQ_USER: ${REQ_USER_$n} | ||
143 | false | ||
144 | . endif | ||
145 | |||
146 | cleanup-${PROG}-$n: | ||
147 | -./${PROG} -c $n | ||
148 | |||
149 | . endfor | ||
150 | .endif | ||
151 | |||
152 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sys/README b/src/regress/lib/libc/sys/README deleted file mode 100644 index 526832e5a7..0000000000 --- a/src/regress/lib/libc/sys/README +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | Regression tests for system calls ported from NetBSD. | ||
2 | |||
3 | Reimplement ATF with many hacks to adjust the tests as little as possible. | ||
4 | |||
5 | Tests passing without source file adjustments: | ||
6 | t_access t_getsockname t_msgctl t_sigaltstack | ||
7 | t_bind t_gettimeofday t_msgsnd t_socketpair | ||
8 | t_conect t_kill t_msync t_truncate | ||
9 | t_getgroups t_link t_pipe t_umask | ||
10 | t_getitimer t_listen t_ppoll t_write | ||
11 | t_getlogin t_minherit t_sendrecv | ||
12 | t_getpid t_mkdir t_setuid | ||
13 | t_getsid t_mkfifo t_sigaction | ||
14 | |||
15 | Tests passing after adjustments: | ||
16 | t_chroot - fchroot is not implemented | ||
17 | t_clock_gettime - requires sysctlbyname | ||
18 | t_dup - OpenBSD dup3 is similar to Linux dup3 | ||
19 | t_fork - add reallocarr function, remove clone(2) tests | ||
20 | t_fsync - replace mkstemp | ||
21 | t_getrusage - no expected fail, PR kern/30115 is NetBSD, work more | ||
22 | t_kevent - no EVFILT_USER, DRVCTLDEV, passing kqueue forbidden | ||
23 | t_mknod - remove tests for unsupported file types | ||
24 | t_msgget - remove msgget_limit test | ||
25 | t_poll - remove pollts_* tests | ||
26 | t_ptrace - change EPERM -> EINVAL for PT_ATTACH of a parent | ||
27 | t_revoke - remove basic tests, revoke only on ttys supported | ||
28 | t_select - remove sigset_t struct as it is int on OpenBSD | ||
29 | t_setrlimit - remove unsupported resource parameters and lwp | ||
30 | t_syscall - add __syscall prototype | ||
31 | t_vfork - SIGSTOP is masked before exec(3)/exit(3) | ||
32 | t_wait_noproc - waitid and wait6 are not implemented | ||
33 | t_wait_noproc_wnohang - waitid and wait6 are not implemented | ||
34 | |||
35 | Failing tests: | ||
36 | t_mlock - wrong errno, succeeds where not expected, POSIX imprecise | ||
37 | t_mmap - ENOTBLK on test NetBSD is skipping, remove mmap_va0 test | ||
38 | t_msgrcv - msgrcv(id, &r, 3 - 1, 0x41, 004000) != -1 | ||
39 | t_pipe2 - closefrom(4) == -1, remove F_GETNOSIGPIPE and nosigpipe test | ||
40 | t_stat - invalid GID with doas | ||
41 | t_unlink - wrong errno according to POSIX | ||
42 | |||
43 | Excluded tests: | ||
44 | t_clock_nanosleep - not available | ||
45 | t_clone - not available | ||
46 | t_futex_ops - no lwp | ||
47 | t_futex_robust - no lwp | ||
48 | t_getcontext - not available, removed in POSIX.1-2008 | ||
49 | t_getrandom - not available | ||
50 | t_issetugid - works as iplemented | ||
51 | t_lwp_create - not available | ||
52 | t_lwp_ctl - not available | ||
53 | t_mincore - removed | ||
54 | t_mprotect - no exec_prot_support and no return_one in libc | ||
55 | t_nanosleep - not available | ||
56 | t_pollts - not available | ||
57 | t_posix_fadvise - optional POSIX Advisory Information | ||
58 | t_posix_fallocate - optional POSIX Advisory Information | ||
59 | t_ptrace_sigchld - | ||
60 | t_ptrace_wait - | ||
61 | t_ptrace_wait3 - | ||
62 | t_ptrace_wait4 - | ||
63 | t_ptrace_wait6 - not implemented | ||
64 | t_ptrace_waitid - | ||
65 | t_ptrace_waitpid - | ||
66 | t_sigqueue - not implemented, added in POSIX.1-2004 | ||
67 | t_sigtimedwait - not implemented, added in POSIX.1-2004 | ||
68 | t_swapcontext - not available, removed in POSIX.1-2008 | ||
69 | t_timer_create - not implemented, added in POSIX.1-2004 | ||
70 | t_ucontext - not available, removed in POSIX.1-2008 | ||
71 | t_wait - wait6 is not available, not POSIX | ||
diff --git a/src/regress/lib/libc/sys/atf-c.c b/src/regress/lib/libc/sys/atf-c.c deleted file mode 100644 index e550a9b753..0000000000 --- a/src/regress/lib/libc/sys/atf-c.c +++ /dev/null | |||
@@ -1,128 +0,0 @@ | |||
1 | /* $OpenBSD: atf-c.c,v 1.2 2019/11/22 15:59:53 bluhm Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2019 Moritz Buhl <openbsd@moritzbuhl.de> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <sys/wait.h> | ||
19 | |||
20 | #include <err.h> | ||
21 | #include <errno.h> | ||
22 | #include <limits.h> | ||
23 | #include <stdarg.h> | ||
24 | #include <stdio.h> | ||
25 | #include <stdlib.h> | ||
26 | #include <pwd.h> | ||
27 | #include <unistd.h> | ||
28 | |||
29 | #include "atf-c.h" | ||
30 | |||
31 | void usage(void); | ||
32 | |||
33 | int cleanup; | ||
34 | int count; | ||
35 | int inspect; | ||
36 | int run; | ||
37 | int test; | ||
38 | |||
39 | int | ||
40 | main(int argc, char *argv[]) | ||
41 | { | ||
42 | int ch, test; | ||
43 | const char *errstr, *num; | ||
44 | |||
45 | while ((ch = getopt(argc, argv, "c:i:nr:")) != -1) { | ||
46 | switch(ch) { | ||
47 | case 'c': | ||
48 | cleanup = 1; | ||
49 | num = optarg; | ||
50 | break; | ||
51 | case 'i': | ||
52 | inspect = 1; | ||
53 | num = optarg; | ||
54 | break; | ||
55 | case 'n': | ||
56 | count = 1; | ||
57 | break; | ||
58 | case 'r': | ||
59 | run = 1; | ||
60 | num = optarg; | ||
61 | break; | ||
62 | default: | ||
63 | usage(); | ||
64 | } | ||
65 | } | ||
66 | argc -= optind; | ||
67 | argv += optind; | ||
68 | |||
69 | if (cleanup + count + inspect + run > 1) | ||
70 | usage(); | ||
71 | |||
72 | if (cleanup || inspect || run) { | ||
73 | test = strtonum(num, 1, INT_MAX, &errstr); | ||
74 | if (errstr != NULL) | ||
75 | errx(1, "test # is %s: %s", errstr, argv[1]); | ||
76 | } | ||
77 | if (count) | ||
78 | printf("%d\n", atf_test(0, 0)); | ||
79 | else if (cleanup) | ||
80 | ATF_CLEANUP(test); | ||
81 | else if (run) | ||
82 | ATF_RUN(test); | ||
83 | else if (inspect) | ||
84 | ATF_INSPECT(test); | ||
85 | else | ||
86 | usage(); | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | void | ||
92 | usage(void) | ||
93 | { | ||
94 | fprintf(stderr, "usage: %s [-n] [-c|i|r test#]\n", getprogname()); | ||
95 | exit(1); | ||
96 | } | ||
97 | |||
98 | void | ||
99 | atf_require(int exp, int expected_errno, const char *expstr, const char *src, | ||
100 | const int lineno, char *fmt, ...) | ||
101 | { | ||
102 | va_list args; | ||
103 | if (!(exp)) { | ||
104 | fprintf(stderr, "\n%s:%d: ", src, lineno); | ||
105 | if (fmt != NULL) { | ||
106 | va_start(args, fmt); | ||
107 | vfprintf(stderr, fmt, args); | ||
108 | va_end(args); | ||
109 | } else { | ||
110 | fprintf(stderr, "'%s' evaluated to false\n", expstr); | ||
111 | } | ||
112 | exit(1); | ||
113 | } else if (expected_errno >= 0 && errno != expected_errno) { | ||
114 | fprintf(stderr, "\n%s:%d: ", src, lineno); | ||
115 | fprintf(stderr, "expected errno %d but got %d instead\n", | ||
116 | expected_errno, errno); | ||
117 | exit(1); | ||
118 | } | ||
119 | return; | ||
120 | } | ||
121 | |||
122 | void | ||
123 | atf_tc_fail(char *fmt, ...) | ||
124 | { | ||
125 | va_list args; | ||
126 | va_start(args, fmt); | ||
127 | verrx(1, fmt, args); | ||
128 | } | ||
diff --git a/src/regress/lib/libc/sys/atf-c.h b/src/regress/lib/libc/sys/atf-c.h deleted file mode 100644 index 6670abac0a..0000000000 --- a/src/regress/lib/libc/sys/atf-c.h +++ /dev/null | |||
@@ -1,105 +0,0 @@ | |||
1 | /* $OpenBSD: atf-c.h,v 1.5 2022/09/11 20:51:44 mbuhl Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2019 Moritz Buhl <openbsd@moritzbuhl.de> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #if !defined(ATF_C_H) | ||
19 | #define ATF_C_H | ||
20 | |||
21 | #include <pwd.h> | ||
22 | #include <stdio.h> | ||
23 | #include <string.h> | ||
24 | #include <unistd.h> | ||
25 | |||
26 | |||
27 | int atf_test(int, int); | ||
28 | void atf_require(int, int, const char *, const char *, const int, char *, ...); | ||
29 | void atf_tc_fail(char *, ...) | ||
30 | __attribute__((__noreturn__, __format__ (printf, 1, 2))); | ||
31 | |||
32 | #define ATF_INSPECT_TEST 1 | ||
33 | #define ATF_RUN_TEST 2 | ||
34 | #define ATF_CLEANUP_TEST 3 | ||
35 | |||
36 | #define ATF_TC_FUNCTIONS(fn) \ | ||
37 | void atf_head_##fn(void); \ | ||
38 | void atf_body_##fn(void); \ | ||
39 | void atf_cleanup_##fn(void); | ||
40 | |||
41 | #define ATF_TC(fn) \ | ||
42 | ATF_TC_FUNCTIONS(fn) \ | ||
43 | void atf_cleanup_##fn(void) { return; } | ||
44 | |||
45 | #define ATF_TC_WITH_CLEANUP(fn) \ | ||
46 | ATF_TC_FUNCTIONS(fn) | ||
47 | |||
48 | #define ATF_TC_HEAD(fn, tc) void atf_head_##fn(void) | ||
49 | #define ATF_TC_BODY(fn, tc) void atf_body_##fn(void) | ||
50 | #define ATF_TC_CLEANUP(fn, tc) void atf_cleanup_##fn(void) | ||
51 | |||
52 | #define ATF_TP_ADD_TCS(tp) int atf_test(int tst, int what) | ||
53 | #define ATF_TP_ADD_TC(tp, fn) tst--; \ | ||
54 | if (tst == 0) { \ | ||
55 | if (what == ATF_INSPECT_TEST) \ | ||
56 | atf_head_##fn(); \ | ||
57 | else if (what == ATF_RUN_TEST) \ | ||
58 | atf_body_##fn(); \ | ||
59 | else if (what == ATF_CLEANUP_TEST) \ | ||
60 | atf_cleanup_##fn(); \ | ||
61 | return 0; \ | ||
62 | } | ||
63 | |||
64 | #define atf_no_error() (-tst) | ||
65 | |||
66 | #define ATF_INSPECT(i) atf_test(i, ATF_INSPECT_TEST) | ||
67 | #define ATF_RUN(i) atf_test(i, ATF_RUN_TEST) | ||
68 | #define ATF_CLEANUP(i) atf_test(i, ATF_CLEANUP_TEST) | ||
69 | |||
70 | #define atf_tc_set_md_var(tc, attr, fmt, ...) \ | ||
71 | if (strcmp(attr, "descr") == 0) \ | ||
72 | printf("DESCR=\"" fmt "\"\n", ##__VA_ARGS__); \ | ||
73 | else if (strcmp(attr, "require.user") == 0) \ | ||
74 | printf("REQ_USER=" fmt "\n", ##__VA_ARGS__); | ||
75 | |||
76 | #define ATF_CHECK ATF_REQUIRE | ||
77 | #define ATF_CHECK_MSG ATF_REQUIRE_MSG | ||
78 | #define ATF_CHECK_EQ ATF_REQUIRE_EQ | ||
79 | #define ATF_CHECK_EQ_MSG ATF_REQUIRE_EQ_MSG | ||
80 | #define ATF_CHECK_ERRNO ATF_REQUIRE_ERRNO | ||
81 | #define ATF_CHECK_STREQ ATF_REQUIRE_STREQ | ||
82 | |||
83 | #define atf_req(exp, err, msg, ...) \ | ||
84 | atf_require(exp, err, #exp, __FILE__, __LINE__, msg, ##__VA_ARGS__) | ||
85 | #define ATF_REQUIRE(exp) atf_req(exp, -1, NULL) | ||
86 | #define ATF_REQUIRE_ERRNO(no, exp) atf_req(exp, no, NULL) | ||
87 | #define ATF_REQUIRE_MSG(exp, fmt, ...) atf_req(exp, -1, fmt, ##__VA_ARGS__) | ||
88 | #define ATF_REQUIRE_EQ(a, b) atf_req((a) == (b), -1, NULL) | ||
89 | #define ATF_REQUIRE_EQ_MSG(a, b, fmt, ...) \ | ||
90 | atf_req((a) == (b), -1, fmt, ##__VA_ARGS__) | ||
91 | #define ATF_REQUIRE_STREQ(x, y) \ | ||
92 | ATF_REQUIRE_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s)", #x, #y, x, y) | ||
93 | |||
94 | #define atf_tc_fail_nonfatal(fmt, ...) atf_tc_fail(fmt, ##__VA_ARGS__) | ||
95 | #define atf_tc_expect_fail(fmt, ...) \ | ||
96 | atf_tc_fail(fmt "\nEXPECTED_FAIL", ##__VA_ARGS__) | ||
97 | #define atf_tc_skip(fmt, ...) \ | ||
98 | atf_tc_fail(fmt "\nSKIPPING", ##__VA_ARGS__) | ||
99 | #define atf_tc_pass() exit(0) | ||
100 | |||
101 | #define atf_tc_get_config_var(a, b) "." | ||
102 | |||
103 | #define atf_utils_fork() fork() | ||
104 | |||
105 | #endif /* !defined(ATF_C_H) */ | ||
diff --git a/src/regress/lib/libc/sys/h_macros.h b/src/regress/lib/libc/sys/h_macros.h deleted file mode 100644 index 22f7ed83f4..0000000000 --- a/src/regress/lib/libc/sys/h_macros.h +++ /dev/null | |||
@@ -1,88 +0,0 @@ | |||
1 | /* $OpenBSD: h_macros.h,v 1.2 2021/09/02 12:40:44 mbuhl Exp $ */ | ||
2 | /* $NetBSD: h_macros.h,v 1.13 2016/08/20 15:49:08 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
27 | * POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #ifndef SRC_TESTS_H_MACROS_H_ | ||
31 | #define SRC_TESTS_H_MACROS_H_ | ||
32 | |||
33 | #include <sys/types.h> | ||
34 | #include <errno.h> | ||
35 | #include <stdarg.h> | ||
36 | #include <stdio.h> | ||
37 | #include <stdlib.h> | ||
38 | #include <string.h> | ||
39 | |||
40 | #include "atf-c.h" | ||
41 | |||
42 | #define REQUIRE_LIBC(x, v) \ | ||
43 | ATF_REQUIRE_MSG((x) != (v), "%s: %s", #x, strerror(errno)) | ||
44 | |||
45 | #define CHECK_LIBC(x, v) \ | ||
46 | ATF_CHECK_MSG((x) != (v), "%s: %s", #x, strerror(errno)) | ||
47 | |||
48 | #define RL(x) REQUIRE_LIBC(x, -1) | ||
49 | #define RLF(x, fmt, arg) \ | ||
50 | ATF_CHECK_MSG((x) != -1, "%s [" fmt "]: %s", #x, arg, strerror(errno)) | ||
51 | #define RZ(x) \ | ||
52 | do { \ | ||
53 | int RZ_rv = x; \ | ||
54 | ATF_REQUIRE_MSG(RZ_rv == 0, "%s: %s", #x, strerror(RZ_rv)); \ | ||
55 | } while (/*CONSTCOND*/0) | ||
56 | |||
57 | __dead static __inline __attribute__((__format__(__printf__,1,2))) void | ||
58 | atf_tc_fail_errno(const char *fmt, ...) | ||
59 | { | ||
60 | va_list ap; | ||
61 | char buf[1024]; | ||
62 | int sverrno = errno; | ||
63 | |||
64 | va_start(ap, fmt); | ||
65 | vsnprintf(buf, sizeof(buf), fmt, ap); | ||
66 | va_end(ap); | ||
67 | |||
68 | strlcat(buf, ": ", sizeof(buf)); | ||
69 | strlcat(buf, strerror(sverrno), sizeof(buf)); | ||
70 | |||
71 | atf_tc_fail("%s", buf); | ||
72 | } | ||
73 | |||
74 | static __inline void | ||
75 | tests_makegarbage(void *space, size_t len) | ||
76 | { | ||
77 | uint16_t *sb = space; | ||
78 | uint16_t randval; | ||
79 | |||
80 | while (len >= sizeof(randval)) { | ||
81 | *sb++ = (uint16_t)random(); | ||
82 | len -= sizeof(*sb); | ||
83 | } | ||
84 | randval = (uint16_t)random(); | ||
85 | memcpy(sb, &randval, len); | ||
86 | } | ||
87 | |||
88 | #endif | ||
diff --git a/src/regress/lib/libc/sys/macros.h b/src/regress/lib/libc/sys/macros.h deleted file mode 100644 index cb0789eb71..0000000000 --- a/src/regress/lib/libc/sys/macros.h +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | /* $OpenBSD: macros.h,v 1.5 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* Public domain - Moritz Buhl */ | ||
3 | |||
4 | #include <sys/socket.h> | ||
5 | #include <sys/stdint.h> | ||
6 | #include <sys/sysctl.h> | ||
7 | #include <sys/types.h> | ||
8 | |||
9 | #include <stdbool.h> | ||
10 | #include <string.h> | ||
11 | #include <stdio.h> | ||
12 | |||
13 | #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) | ||
14 | |||
15 | #define __arraycount(_a) nitems(_a) | ||
16 | #define __unreachable() atf_tc_fail("unreachable") | ||
17 | #define __UNCONST(a) (a) | ||
18 | |||
19 | /* t_chroot.c */ | ||
20 | #define fchroot(fd) 0 | ||
21 | |||
22 | /* t_clock_gettime.c */ | ||
23 | int sysctlbyname(char *, void *, size_t *, void *, size_t); | ||
24 | |||
25 | int | ||
26 | sysctlbyname(char* s, void *oldp, size_t *oldlenp, void *newp, size_t newlen) | ||
27 | { | ||
28 | int mib[3], miblen; | ||
29 | |||
30 | mib[0] = CTL_KERN; | ||
31 | if (strcmp(s, "kern.timecounter.hardware") == 0) { | ||
32 | mib[1] = KERN_TIMECOUNTER; | ||
33 | mib[2] = KERN_TIMECOUNTER_HARDWARE; | ||
34 | miblen = 3; | ||
35 | } else if (strcmp(s, "kern.timecounter.choice") == 0) { | ||
36 | mib[1] = KERN_TIMECOUNTER; | ||
37 | mib[2] = KERN_TIMECOUNTER_CHOICE; | ||
38 | miblen = 3; | ||
39 | } else if (strcmp(s, "kern.securelevel") == 0) { | ||
40 | mib[1] = KERN_SECURELVL; | ||
41 | miblen = 2; | ||
42 | } else { | ||
43 | fprintf(stderr, "%s(): mib '%s' not supported\n", __func__, s); | ||
44 | return -42; | ||
45 | } | ||
46 | |||
47 | return sysctl(mib, miblen, oldp, oldlenp, newp, newlen); | ||
48 | } | ||
49 | |||
50 | /* t_connect.c */ | ||
51 | #define IPPORT_RESERVEDMAX 1023 | ||
52 | |||
53 | /* t_fork.c */ | ||
54 | #define kinfo_proc2 kinfo_proc | ||
55 | #define KERN_PROC2 KERN_PROC | ||
56 | #define reallocarr(pp, n, s) ((*pp = reallocarray(*pp, n, s)), *pp == NULL) | ||
57 | #define LSSTOP SSTOP | ||
58 | |||
59 | /* t_mlock.c */ | ||
60 | #define MAP_WIRED __MAP_NOREPLACE | ||
61 | |||
62 | /* t_pipe2.c */ | ||
63 | #define O_NOSIGPIPE 0 | ||
64 | |||
65 | /* t_poll.c */ | ||
66 | #define pollts(a, b, c, e) 0 | ||
67 | |||
68 | /* t_sendrecv.c */ | ||
69 | #define SO_RERROR SO_DEBUG | ||
70 | |||
71 | /* t_write.c */ | ||
72 | #define _PATH_DEVZERO "/dev/zero" | ||
73 | |||
74 | /* t_wait_noproc.c */ | ||
75 | #define ___STRING(x) #x | ||
76 | #define __BIT(n) (1 << (n)) | ||
diff --git a/src/regress/lib/libc/sys/t_access.c b/src/regress/lib/libc/sys/t_access.c deleted file mode 100644 index 531b17c46e..0000000000 --- a/src/regress/lib/libc/sys/t_access.c +++ /dev/null | |||
@@ -1,213 +0,0 @@ | |||
1 | /* $OpenBSD: t_access.c,v 1.3 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_access.c,v 1.3 2019/07/16 17:29:18 martin Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include "atf-c.h" | ||
36 | |||
37 | #include <sys/stat.h> | ||
38 | |||
39 | #include <errno.h> | ||
40 | #include <fcntl.h> | ||
41 | #include <limits.h> | ||
42 | #include <stdint.h> | ||
43 | #include <stdlib.h> | ||
44 | #include <unistd.h> | ||
45 | |||
46 | static const char path[] = "access"; | ||
47 | static const int mode[4] = { R_OK, W_OK, X_OK, F_OK }; | ||
48 | |||
49 | ATF_TC_WITH_CLEANUP(access_access); | ||
50 | ATF_TC_HEAD(access_access, tc) | ||
51 | { | ||
52 | atf_tc_set_md_var(tc, "descr", "Test access(2) for EACCES"); | ||
53 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
54 | } | ||
55 | |||
56 | ATF_TC_BODY(access_access, tc) | ||
57 | { | ||
58 | const int perm[3] = { 0200, 0400, 0000 }; | ||
59 | size_t i; | ||
60 | int fd; | ||
61 | |||
62 | fd = open(path, O_RDONLY | O_CREAT, 0600); | ||
63 | |||
64 | if (fd < 0) | ||
65 | return; | ||
66 | |||
67 | for (i = 0; i < __arraycount(mode) - 1; i++) { | ||
68 | |||
69 | ATF_REQUIRE(fchmod(fd, perm[i]) == 0); | ||
70 | |||
71 | errno = 0; | ||
72 | |||
73 | ATF_REQUIRE(access(path, mode[i]) != 0); | ||
74 | ATF_REQUIRE(errno == EACCES); | ||
75 | } | ||
76 | |||
77 | ATF_REQUIRE(close(fd) == 0); | ||
78 | } | ||
79 | |||
80 | ATF_TC_CLEANUP(access_access, tc) | ||
81 | { | ||
82 | (void)unlink(path); | ||
83 | } | ||
84 | |||
85 | ATF_TC(access_fault); | ||
86 | ATF_TC_HEAD(access_fault, tc) | ||
87 | { | ||
88 | atf_tc_set_md_var(tc, "descr", "Test access(2) for EFAULT"); | ||
89 | } | ||
90 | |||
91 | ATF_TC_BODY(access_fault, tc) | ||
92 | { | ||
93 | size_t i; | ||
94 | |||
95 | for (i = 0; i < __arraycount(mode); i++) { | ||
96 | |||
97 | errno = 0; | ||
98 | |||
99 | ATF_REQUIRE(access(NULL, mode[i]) != 0); | ||
100 | ATF_REQUIRE(errno == EFAULT); | ||
101 | |||
102 | errno = 0; | ||
103 | |||
104 | ATF_REQUIRE(access((char *)-1, mode[i]) != 0); | ||
105 | ATF_REQUIRE(errno == EFAULT); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | ATF_TC(access_inval); | ||
110 | ATF_TC_HEAD(access_inval, tc) | ||
111 | { | ||
112 | atf_tc_set_md_var(tc, "descr", "Test access(2) for EINVAL"); | ||
113 | } | ||
114 | |||
115 | ATF_TC_BODY(access_inval, tc) | ||
116 | { | ||
117 | |||
118 | errno = 0; | ||
119 | |||
120 | ATF_REQUIRE(access("/usr", -1) != 0); | ||
121 | ATF_REQUIRE(errno == EINVAL); | ||
122 | } | ||
123 | |||
124 | ATF_TC(access_notdir); | ||
125 | ATF_TC_HEAD(access_notdir, tc) | ||
126 | { | ||
127 | atf_tc_set_md_var(tc, "descr", "Test access(2) for ENOTDIR"); | ||
128 | } | ||
129 | |||
130 | ATF_TC_BODY(access_notdir, tc) | ||
131 | { | ||
132 | size_t i; | ||
133 | |||
134 | for (i = 0; i < __arraycount(mode); i++) { | ||
135 | |||
136 | errno = 0; | ||
137 | |||
138 | /* | ||
139 | * IEEE Std 1003.1-2008 about ENOTDIR: | ||
140 | * | ||
141 | * "A component of the path prefix is not a directory, | ||
142 | * or the path argument contains at least one non-<slash> | ||
143 | * character and ends with one or more trailing <slash> | ||
144 | * characters and the last pathname component names an | ||
145 | * existing file that is neither a directory nor a symbolic | ||
146 | * link to a directory." | ||
147 | */ | ||
148 | ATF_REQUIRE(access("/etc/passwd//", mode[i]) != 0); | ||
149 | ATF_REQUIRE(errno == ENOTDIR); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | ATF_TC(access_notexist); | ||
154 | ATF_TC_HEAD(access_notexist, tc) | ||
155 | { | ||
156 | atf_tc_set_md_var(tc, "descr", "Test access(2) for ENOENT"); | ||
157 | } | ||
158 | |||
159 | ATF_TC_BODY(access_notexist, tc) | ||
160 | { | ||
161 | size_t i; | ||
162 | |||
163 | for (i = 0; i < __arraycount(mode); i++) { | ||
164 | |||
165 | errno = 0; | ||
166 | |||
167 | ATF_REQUIRE(access("", mode[i]) != 0); | ||
168 | ATF_REQUIRE(errno == ENOENT); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | ATF_TC(access_toolong); | ||
173 | ATF_TC_HEAD(access_toolong, tc) | ||
174 | { | ||
175 | atf_tc_set_md_var(tc, "descr", "Test access(2) for ENAMETOOLONG"); | ||
176 | } | ||
177 | |||
178 | ATF_TC_BODY(access_toolong, tc) | ||
179 | { | ||
180 | char *buf; | ||
181 | size_t i; | ||
182 | |||
183 | buf = malloc(PATH_MAX); | ||
184 | |||
185 | if (buf == NULL) | ||
186 | return; | ||
187 | |||
188 | for (i = 0; i < PATH_MAX; i++) | ||
189 | buf[i] = 'x'; | ||
190 | |||
191 | for (i = 0; i < __arraycount(mode); i++) { | ||
192 | |||
193 | errno = 0; | ||
194 | |||
195 | ATF_REQUIRE(access(buf, mode[i]) != 0); | ||
196 | ATF_REQUIRE(errno == ENAMETOOLONG); | ||
197 | } | ||
198 | |||
199 | free(buf); | ||
200 | } | ||
201 | |||
202 | ATF_TP_ADD_TCS(tp) | ||
203 | { | ||
204 | |||
205 | ATF_TP_ADD_TC(tp, access_access); | ||
206 | ATF_TP_ADD_TC(tp, access_fault); | ||
207 | ATF_TP_ADD_TC(tp, access_inval); | ||
208 | ATF_TP_ADD_TC(tp, access_notdir); | ||
209 | ATF_TP_ADD_TC(tp, access_notexist); | ||
210 | ATF_TP_ADD_TC(tp, access_toolong); | ||
211 | |||
212 | return atf_no_error(); | ||
213 | } | ||
diff --git a/src/regress/lib/libc/sys/t_bind.c b/src/regress/lib/libc/sys/t_bind.c deleted file mode 100644 index 7989c7c229..0000000000 --- a/src/regress/lib/libc/sys/t_bind.c +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | /* $OpenBSD: t_bind.c,v 1.1.1.1 2019/11/19 19:57:03 bluhm Exp $ */ | ||
2 | /* $NetBSD: t_bind.c,v 1.3 2015/04/05 23:28:10 rtr Exp $ */ | ||
3 | /* | ||
4 | * Copyright (c) 2015 The NetBSD Foundation, Inc. | ||
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 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND | ||
17 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
18 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
20 | * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY | ||
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
23 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
25 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #include "macros.h" | ||
31 | |||
32 | #include <errno.h> | ||
33 | #include <stdlib.h> | ||
34 | #include <string.h> | ||
35 | |||
36 | #include <unistd.h> | ||
37 | |||
38 | #include <sys/socket.h> | ||
39 | #include <arpa/inet.h> | ||
40 | #include <netinet/in.h> | ||
41 | |||
42 | #include "atf-c.h" | ||
43 | |||
44 | ATF_TC(bind_foreign_family); | ||
45 | |||
46 | ATF_TC_HEAD(bind_foreign_family, tc) | ||
47 | { | ||
48 | atf_tc_set_md_var(tc, "descr", "Checks that binding a socket " | ||
49 | "with a different address family fails"); | ||
50 | } | ||
51 | |||
52 | ATF_TC_BODY(bind_foreign_family, tc) | ||
53 | { | ||
54 | struct sockaddr_in addr; | ||
55 | |||
56 | /* addr.sin_family = AF_UNSPEC = 0 */ | ||
57 | memset(&addr, 0, sizeof(addr)); | ||
58 | |||
59 | /* | ||
60 | * it is not necessary to initialize sin_{addr,port} since | ||
61 | * those structure members shall not be accessed if bind | ||
62 | * fails correctly. | ||
63 | */ | ||
64 | |||
65 | int sock = socket(AF_LOCAL, SOCK_STREAM, 0); | ||
66 | ATF_REQUIRE(sock != -1); | ||
67 | |||
68 | /* should fail but currently doesn't */ | ||
69 | ATF_REQUIRE(-1 == bind(sock, (struct sockaddr *)&addr, sizeof(addr))); | ||
70 | ATF_REQUIRE(EAFNOSUPPORT == errno); | ||
71 | |||
72 | close(sock); | ||
73 | } | ||
74 | |||
75 | ATF_TP_ADD_TCS(tp) | ||
76 | { | ||
77 | |||
78 | ATF_TP_ADD_TC(tp, bind_foreign_family); | ||
79 | |||
80 | return atf_no_error(); | ||
81 | } | ||
diff --git a/src/regress/lib/libc/sys/t_chroot.c b/src/regress/lib/libc/sys/t_chroot.c deleted file mode 100644 index fb65bacebd..0000000000 --- a/src/regress/lib/libc/sys/t_chroot.c +++ /dev/null | |||
@@ -1,318 +0,0 @@ | |||
1 | /* $OpenBSD: t_chroot.c,v 1.3 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_chroot.c,v 1.2 2017/01/10 22:36:29 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/wait.h> | ||
36 | #include <sys/stat.h> | ||
37 | |||
38 | #include "atf-c.h" | ||
39 | #include <errno.h> | ||
40 | #include <fcntl.h> | ||
41 | #include <limits.h> | ||
42 | #include <pwd.h> | ||
43 | #include <stdlib.h> | ||
44 | #include <string.h> | ||
45 | #include <unistd.h> | ||
46 | |||
47 | ATF_TC(chroot_basic); | ||
48 | ATF_TC_HEAD(chroot_basic, tc) | ||
49 | { | ||
50 | atf_tc_set_md_var(tc, "descr", "A basic test of chroot(2)"); | ||
51 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
52 | } | ||
53 | |||
54 | ATF_TC_BODY(chroot_basic, tc) | ||
55 | { | ||
56 | char buf[PATH_MAX]; | ||
57 | int fd, sta; | ||
58 | pid_t pid; | ||
59 | |||
60 | (void)memset(buf, '\0', sizeof(buf)); | ||
61 | (void)getcwd(buf, sizeof(buf)); | ||
62 | (void)strlcat(buf, "/dir", sizeof(buf)); | ||
63 | |||
64 | ATF_REQUIRE(mkdir(buf, 0500) == 0); | ||
65 | ATF_REQUIRE(chdir(buf) == 0); | ||
66 | |||
67 | pid = fork(); | ||
68 | ATF_REQUIRE(pid >= 0); | ||
69 | |||
70 | if (pid == 0) { | ||
71 | |||
72 | if (chroot(buf) != 0) | ||
73 | _exit(EXIT_FAILURE); | ||
74 | |||
75 | errno = 0; | ||
76 | |||
77 | if (chroot("/root") != -1) | ||
78 | _exit(EXIT_FAILURE); | ||
79 | |||
80 | if (errno != ENOENT) | ||
81 | _exit(EXIT_FAILURE); | ||
82 | |||
83 | fd = open("file", O_RDONLY | O_CREAT, 0600); | ||
84 | |||
85 | if (fd < 0) | ||
86 | _exit(EXIT_FAILURE); | ||
87 | |||
88 | if (close(fd) != 0) | ||
89 | _exit(EXIT_FAILURE); | ||
90 | |||
91 | _exit(EXIT_SUCCESS); | ||
92 | } | ||
93 | |||
94 | (void)wait(&sta); | ||
95 | |||
96 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
97 | atf_tc_fail("chroot(2) failed"); | ||
98 | |||
99 | (void)chdir("/"); | ||
100 | (void)strlcat(buf, "/file", sizeof(buf)); | ||
101 | |||
102 | fd = open(buf, O_RDONLY); | ||
103 | |||
104 | if (fd < 0) | ||
105 | atf_tc_fail("chroot(2) did not change the root directory"); | ||
106 | |||
107 | ATF_REQUIRE(close(fd) == 0); | ||
108 | ATF_REQUIRE(unlink(buf) == 0); | ||
109 | } | ||
110 | |||
111 | ATF_TC(chroot_err); | ||
112 | ATF_TC_HEAD(chroot_err, tc) | ||
113 | { | ||
114 | atf_tc_set_md_var(tc, "descr", "Test error conditions of chroot(2)"); | ||
115 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
116 | } | ||
117 | |||
118 | ATF_TC_BODY(chroot_err, tc) | ||
119 | { | ||
120 | char buf[PATH_MAX + 1]; | ||
121 | |||
122 | (void)memset(buf, 'x', sizeof(buf)); | ||
123 | |||
124 | errno = 0; | ||
125 | ATF_REQUIRE_ERRNO(ENAMETOOLONG, chroot(buf) == -1); | ||
126 | |||
127 | errno = 0; | ||
128 | ATF_REQUIRE_ERRNO(EFAULT, chroot((void *)-1) == -1); | ||
129 | |||
130 | errno = 0; | ||
131 | ATF_REQUIRE_ERRNO(ENOENT, chroot("/a/b/c/d/e/f/g/h/i/j") == -1); | ||
132 | } | ||
133 | |||
134 | ATF_TC(chroot_perm); | ||
135 | ATF_TC_HEAD(chroot_perm, tc) | ||
136 | { | ||
137 | atf_tc_set_md_var(tc, "descr", "Test permissions with chroot(2)"); | ||
138 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
139 | } | ||
140 | |||
141 | ATF_TC_BODY(chroot_perm, tc) | ||
142 | { | ||
143 | static char buf[LINE_MAX]; | ||
144 | pid_t pid; | ||
145 | int sta; | ||
146 | |||
147 | (void)memset(buf, '\0', sizeof(buf)); | ||
148 | ATF_REQUIRE(getcwd(buf, sizeof(buf)) != NULL); | ||
149 | |||
150 | pid = fork(); | ||
151 | ATF_REQUIRE(pid >= 0); | ||
152 | |||
153 | if (pid == 0) { | ||
154 | |||
155 | errno = 0; | ||
156 | |||
157 | if (chroot(buf) != -1) | ||
158 | _exit(EXIT_FAILURE); | ||
159 | |||
160 | if (errno != EPERM) | ||
161 | _exit(EXIT_FAILURE); | ||
162 | |||
163 | _exit(EXIT_SUCCESS); | ||
164 | } | ||
165 | |||
166 | (void)wait(&sta); | ||
167 | |||
168 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
169 | atf_tc_fail("chroot(2) succeeded as unprivileged user"); | ||
170 | } | ||
171 | |||
172 | ATF_TC(fchroot_basic); | ||
173 | ATF_TC_HEAD(fchroot_basic, tc) | ||
174 | { | ||
175 | atf_tc_set_md_var(tc, "descr", "A basic test of fchroot(2)"); | ||
176 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
177 | } | ||
178 | |||
179 | ATF_TC_BODY(fchroot_basic, tc) | ||
180 | { | ||
181 | char buf[PATH_MAX]; | ||
182 | int fd, sta; | ||
183 | pid_t pid; | ||
184 | |||
185 | (void)memset(buf, '\0', sizeof(buf)); | ||
186 | (void)getcwd(buf, sizeof(buf)); | ||
187 | (void)strlcat(buf, "/dir", sizeof(buf)); | ||
188 | |||
189 | ATF_REQUIRE(mkdir(buf, 0500) == 0); | ||
190 | ATF_REQUIRE(chdir(buf) == 0); | ||
191 | |||
192 | fd = open(buf, O_RDONLY); | ||
193 | ATF_REQUIRE(fd >= 0); | ||
194 | |||
195 | pid = fork(); | ||
196 | ATF_REQUIRE(pid >= 0); | ||
197 | |||
198 | if (pid == 0) { | ||
199 | |||
200 | if (fchroot(fd) != 0) | ||
201 | _exit(EXIT_FAILURE); | ||
202 | |||
203 | if (close(fd) != 0) | ||
204 | _exit(EXIT_FAILURE); | ||
205 | |||
206 | fd = open("file", O_RDONLY | O_CREAT, 0600); | ||
207 | |||
208 | if (fd < 0) | ||
209 | _exit(EXIT_FAILURE); | ||
210 | |||
211 | if (close(fd) != 0) | ||
212 | _exit(EXIT_FAILURE); | ||
213 | |||
214 | _exit(EXIT_SUCCESS); | ||
215 | } | ||
216 | |||
217 | (void)wait(&sta); | ||
218 | |||
219 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
220 | atf_tc_fail("fchroot(2) failed"); | ||
221 | |||
222 | (void)chdir("/"); | ||
223 | (void)strlcat(buf, "/file", sizeof(buf)); | ||
224 | |||
225 | fd = open(buf, O_RDONLY); | ||
226 | |||
227 | if (fd < 0) | ||
228 | atf_tc_fail("fchroot(2) did not change the root directory"); | ||
229 | |||
230 | ATF_REQUIRE(close(fd) == 0); | ||
231 | ATF_REQUIRE(unlink(buf) == 0); | ||
232 | } | ||
233 | |||
234 | ATF_TC(fchroot_err); | ||
235 | ATF_TC_HEAD(fchroot_err, tc) | ||
236 | { | ||
237 | atf_tc_set_md_var(tc, "descr", "Test error conditions of fchroot(2)"); | ||
238 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
239 | } | ||
240 | |||
241 | ATF_TC_BODY(fchroot_err, tc) | ||
242 | { | ||
243 | int fd; | ||
244 | |||
245 | fd = open("/etc/passwd", O_RDONLY); | ||
246 | ATF_REQUIRE(fd >= 0); | ||
247 | |||
248 | errno = 0; | ||
249 | ATF_REQUIRE_ERRNO(EBADF, fchroot(-1) == -1); | ||
250 | |||
251 | errno = 0; | ||
252 | ATF_REQUIRE_ERRNO(ENOTDIR, fchroot(fd) == -1); | ||
253 | |||
254 | ATF_REQUIRE(close(fd) == 0); | ||
255 | } | ||
256 | |||
257 | ATF_TC(fchroot_perm); | ||
258 | ATF_TC_HEAD(fchroot_perm, tc) | ||
259 | { | ||
260 | atf_tc_set_md_var(tc, "descr", "Test permissions with fchroot(2)"); | ||
261 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
262 | } | ||
263 | |||
264 | ATF_TC_BODY(fchroot_perm, tc) | ||
265 | { | ||
266 | static char buf[LINE_MAX]; | ||
267 | struct passwd *pw; | ||
268 | int fd, sta; | ||
269 | pid_t pid; | ||
270 | |||
271 | (void)memset(buf, '\0', sizeof(buf)); | ||
272 | ATF_REQUIRE(getcwd(buf, sizeof(buf)) != NULL); | ||
273 | |||
274 | pw = getpwnam("nobody"); | ||
275 | fd = open(buf, O_RDONLY); | ||
276 | |||
277 | ATF_REQUIRE(fd >= 0); | ||
278 | ATF_REQUIRE(pw != NULL); | ||
279 | |||
280 | pid = fork(); | ||
281 | ATF_REQUIRE(pid >= 0); | ||
282 | |||
283 | if (pid == 0) { | ||
284 | |||
285 | (void)setuid(pw->pw_uid); | ||
286 | |||
287 | errno = 0; | ||
288 | |||
289 | if (fchroot(fd) != -1) | ||
290 | _exit(EXIT_FAILURE); | ||
291 | |||
292 | if (errno != EPERM) | ||
293 | _exit(EXIT_FAILURE); | ||
294 | |||
295 | _exit(EXIT_SUCCESS); | ||
296 | } | ||
297 | |||
298 | (void)wait(&sta); | ||
299 | |||
300 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
301 | atf_tc_fail("fchroot(2) succeeded as unprivileged user"); | ||
302 | } | ||
303 | |||
304 | ATF_TP_ADD_TCS(tp) | ||
305 | { | ||
306 | |||
307 | ATF_TP_ADD_TC(tp, chroot_basic); | ||
308 | ATF_TP_ADD_TC(tp, chroot_err); | ||
309 | ATF_TP_ADD_TC(tp, chroot_perm); | ||
310 | #ifndef __OpenBSD__ | ||
311 | /* fchroot(2) not available */ | ||
312 | ATF_TP_ADD_TC(tp, fchroot_basic); | ||
313 | ATF_TP_ADD_TC(tp, fchroot_err); | ||
314 | ATF_TP_ADD_TC(tp, fchroot_perm); | ||
315 | #endif | ||
316 | |||
317 | return atf_no_error(); | ||
318 | } | ||
diff --git a/src/regress/lib/libc/sys/t_clock_gettime.c b/src/regress/lib/libc/sys/t_clock_gettime.c deleted file mode 100644 index 11105d2240..0000000000 --- a/src/regress/lib/libc/sys/t_clock_gettime.c +++ /dev/null | |||
@@ -1,210 +0,0 @@ | |||
1 | /* $OpenBSD: t_clock_gettime.c,v 1.3 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_clock_gettime.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Frank Kardel. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | /*- | ||
34 | * Copyright (c) 2006 Frank Kardel | ||
35 | * All rights reserved. | ||
36 | * | ||
37 | * Redistribution and use in source and binary forms, with or without | ||
38 | * modification, are permitted provided that the following conditions | ||
39 | * are met: | ||
40 | * 1. Redistributions of source code must retain the above copyright | ||
41 | * notice, this list of conditions and the following disclaimer. | ||
42 | * 2. Redistributions in binary form must reproduce the above copyright | ||
43 | * notice, this list of conditions and the following disclaimer in the | ||
44 | * documentation and/or other materials provided with the distribution. | ||
45 | * | ||
46 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
47 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
48 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
49 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
50 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
51 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
52 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
53 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
54 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
55 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
56 | * POSSIBILITY OF SUCH DAMAGE. | ||
57 | */ | ||
58 | |||
59 | #include "macros.h" | ||
60 | |||
61 | #include <sys/sysctl.h> | ||
62 | |||
63 | |||
64 | #include "atf-c.h" | ||
65 | #include <errno.h> | ||
66 | #include <limits.h> | ||
67 | #include <stdio.h> | ||
68 | #include <stdint.h> | ||
69 | #include <stdlib.h> | ||
70 | #include <string.h> | ||
71 | #include <time.h> | ||
72 | #include <unistd.h> | ||
73 | |||
74 | #include "h_macros.h" | ||
75 | |||
76 | #define MINPOSDIFF 15000000 /* 15 ms for now */ | ||
77 | #define TIMEOUT 5 | ||
78 | |||
79 | #define TC_HARDWARE "kern.timecounter.hardware" | ||
80 | #define TC_CHOICE "kern.timecounter.choice" | ||
81 | |||
82 | static void | ||
83 | check_timecounter(void) | ||
84 | { | ||
85 | struct timespec tsa, tsb, tsl, res; | ||
86 | long long mindiff = INTMAX_MAX; | ||
87 | time_t endlimit; | ||
88 | |||
89 | #define CL(x) \ | ||
90 | do { \ | ||
91 | if ((x) != -1) \ | ||
92 | break; \ | ||
93 | atf_tc_fail_nonfatal("%s: %s", #x, strerror(errno)); \ | ||
94 | return; \ | ||
95 | } while (0) | ||
96 | |||
97 | CL(clock_gettime(CLOCK_REALTIME, &tsa)); | ||
98 | tsl = tsa; | ||
99 | |||
100 | CL(time(&endlimit)); | ||
101 | endlimit += TIMEOUT + 1; | ||
102 | |||
103 | while ((time_t)tsa.tv_sec < endlimit) { | ||
104 | long long diff; | ||
105 | |||
106 | CL(clock_gettime(CLOCK_REALTIME, &tsb)); | ||
107 | diff = 1000000000LL * (tsb.tv_sec - tsa.tv_sec) | ||
108 | + tsb.tv_nsec - tsa.tv_nsec; | ||
109 | |||
110 | if (diff > 0 && mindiff > diff) | ||
111 | mindiff = diff; | ||
112 | |||
113 | if (diff < 0 || diff > MINPOSDIFF) { | ||
114 | long long elapsed; | ||
115 | (void)printf("%stime TSA: 0x%jx.%08jx, TSB: 0x%jx.%08jx, " | ||
116 | "diff = %lld nsec, ", (diff < 0) ? "BAD " : "", | ||
117 | (uintmax_t)tsa.tv_sec, (uintmax_t)tsa.tv_nsec, | ||
118 | (uintmax_t)tsb.tv_sec, (uintmax_t)tsb.tv_nsec, diff); | ||
119 | |||
120 | elapsed = 1000000000LL * (tsb.tv_sec - tsl.tv_sec) | ||
121 | + tsb.tv_nsec - tsl.tv_nsec; | ||
122 | |||
123 | |||
124 | (void)printf("%lld nsec\n", elapsed); | ||
125 | tsl = tsb; | ||
126 | |||
127 | ATF_CHECK(diff >= 0); | ||
128 | if (diff < 0) | ||
129 | return; | ||
130 | } | ||
131 | |||
132 | tsa.tv_sec = tsb.tv_sec; | ||
133 | tsa.tv_nsec = tsb.tv_nsec; | ||
134 | } | ||
135 | |||
136 | if (clock_getres(CLOCK_REALTIME, &res) == 0) { | ||
137 | long long r = res.tv_sec * 1000000000 + res.tv_nsec; | ||
138 | |||
139 | (void)printf("Claimed resolution: %lld nsec (%f Hz) or " | ||
140 | "better\n", r, 1.0 / r * 1e9); | ||
141 | (void)printf("Observed minimum non zero delta: %lld " | ||
142 | "nsec\n", mindiff); | ||
143 | } | ||
144 | |||
145 | #undef CL | ||
146 | } | ||
147 | |||
148 | ATF_TC(clock_gettime_real); | ||
149 | ATF_TC_HEAD(clock_gettime_real, tc) | ||
150 | { | ||
151 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
152 | atf_tc_set_md_var(tc, "descr", | ||
153 | "Checks the monotonicity of the CLOCK_REALTIME implementation"); | ||
154 | atf_tc_set_md_var(tc, "timeout", "300"); | ||
155 | } | ||
156 | |||
157 | ATF_TC_BODY(clock_gettime_real, tc) | ||
158 | { | ||
159 | char name[128], cbuf[512], ctrbuf[10240]; | ||
160 | size_t cbufsiz = sizeof(cbuf); | ||
161 | size_t ctrbufsiz = sizeof(ctrbuf); | ||
162 | const char *p; | ||
163 | char *save; | ||
164 | int quality, n; | ||
165 | |||
166 | if (sysctlbyname(TC_HARDWARE, cbuf, &cbufsiz, NULL, 0) != 0) { | ||
167 | (void)printf("\nChecking legacy time implementation " | ||
168 | "for %d seconds\n", TIMEOUT); | ||
169 | check_timecounter(); | ||
170 | return; | ||
171 | /* NOTREACHED */ | ||
172 | } | ||
173 | (void)printf("%s = %s\n", TC_HARDWARE, cbuf); | ||
174 | REQUIRE_LIBC(save = strdup(cbuf), NULL); | ||
175 | |||
176 | RL(sysctlbyname(TC_CHOICE, ctrbuf, &ctrbufsiz, NULL, 0)); | ||
177 | (void)printf("%s = %s\n", TC_CHOICE, ctrbuf); | ||
178 | |||
179 | for (p = ctrbuf, n = 0; sscanf(p, "%127[^(](q=%d, f=%*u Hz)%*[ ]%n", | ||
180 | name, &quality, &n) == 2; p += n) { | ||
181 | struct timespec ts; | ||
182 | int ret; | ||
183 | |||
184 | if (quality < 0) | ||
185 | continue; | ||
186 | |||
187 | (void)printf("\nChecking %s for %d seconds\n", name, TIMEOUT); | ||
188 | CHECK_LIBC(ret = sysctlbyname(TC_HARDWARE, NULL, 0, | ||
189 | name, strlen(name)), -1); | ||
190 | if (ret == -1) | ||
191 | continue; | ||
192 | |||
193 | /* wait a bit to select new counter in clockinterrupt */ | ||
194 | ts.tv_sec = 0; | ||
195 | ts.tv_nsec = 100000000; | ||
196 | (void)nanosleep(&ts, NULL); | ||
197 | |||
198 | check_timecounter(); | ||
199 | } | ||
200 | |||
201 | RL(sysctlbyname(TC_HARDWARE, NULL, 0, save, strlen(save))); | ||
202 | } | ||
203 | |||
204 | ATF_TP_ADD_TCS(tp) | ||
205 | { | ||
206 | |||
207 | ATF_TP_ADD_TC(tp, clock_gettime_real); | ||
208 | |||
209 | return atf_no_error(); | ||
210 | } | ||
diff --git a/src/regress/lib/libc/sys/t_connect.c b/src/regress/lib/libc/sys/t_connect.c deleted file mode 100644 index c1730a40c7..0000000000 --- a/src/regress/lib/libc/sys/t_connect.c +++ /dev/null | |||
@@ -1,135 +0,0 @@ | |||
1 | /* $OpenBSD: t_connect.c,v 1.1 2021/09/02 12:40:44 mbuhl Exp $ */ | ||
2 | /* $NetBSD: t_connect.c,v 1.3 2017/01/13 20:09:48 christos Exp $ */ | ||
3 | /* | ||
4 | * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. | ||
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 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND | ||
17 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
18 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
20 | * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY | ||
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
23 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
25 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | #include "macros.h" | ||
30 | |||
31 | #include <sys/socket.h> | ||
32 | #include <err.h> | ||
33 | #include <errno.h> | ||
34 | #include <string.h> | ||
35 | #include <unistd.h> | ||
36 | |||
37 | #include <arpa/inet.h> | ||
38 | #include <netinet/in.h> | ||
39 | |||
40 | #include "atf-c.h" | ||
41 | |||
42 | ATF_TC(connect_low_port); | ||
43 | ATF_TC_HEAD(connect_low_port, tc) | ||
44 | { | ||
45 | atf_tc_set_md_var(tc, "descr", "Checks that low-port allocation " | ||
46 | "works"); | ||
47 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
48 | } | ||
49 | ATF_TC_BODY(connect_low_port, tc) | ||
50 | { | ||
51 | struct sockaddr_in sin, sinlist; | ||
52 | int sd, val, slist; | ||
53 | socklen_t slen; | ||
54 | |||
55 | slist = socket(AF_INET, SOCK_STREAM, 0); | ||
56 | sd = socket(AF_INET, SOCK_STREAM, 0); | ||
57 | |||
58 | ATF_REQUIRE(sd > 0); | ||
59 | ATF_REQUIRE(slist > 0); | ||
60 | |||
61 | /* bind listening socket */ | ||
62 | memset(&sinlist, 0, sizeof(sinlist)); | ||
63 | sinlist.sin_family = AF_INET; | ||
64 | sinlist.sin_port = htons(31522); | ||
65 | sinlist.sin_addr.s_addr = inet_addr("127.0.0.1"); | ||
66 | |||
67 | ATF_REQUIRE_EQ(bind(slist, | ||
68 | (struct sockaddr *)&sinlist, sizeof(sinlist)), 0); | ||
69 | ATF_REQUIRE_EQ(listen(slist, 1), 0); | ||
70 | |||
71 | val = IP_PORTRANGE_LOW; | ||
72 | if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val, | ||
73 | sizeof(val)) == -1) | ||
74 | atf_tc_fail("setsockopt failed: %s", strerror(errno)); | ||
75 | |||
76 | memset(&sin, 0, sizeof(sin)); | ||
77 | |||
78 | sin.sin_port = htons(31522); | ||
79 | sin.sin_addr.s_addr = inet_addr("127.0.0.1"); | ||
80 | sin.sin_family = AF_INET; | ||
81 | |||
82 | if (connect(sd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { | ||
83 | int serrno = errno; | ||
84 | atf_tc_fail("connect failed: %s%s", | ||
85 | strerror(serrno), | ||
86 | serrno != EACCES ? "" : | ||
87 | " (see http://mail-index.netbsd.org/" | ||
88 | "source-changes/2007/12/16/0011.html)"); | ||
89 | } | ||
90 | |||
91 | slen = sizeof(sin); | ||
92 | ATF_REQUIRE_EQ(getsockname(sd, (struct sockaddr *)&sin, &slen), 0); | ||
93 | ATF_REQUIRE_EQ(slen, sizeof(sin)); | ||
94 | ATF_REQUIRE(ntohs(sin.sin_port) <= IPPORT_RESERVEDMAX); | ||
95 | |||
96 | close(sd); | ||
97 | close(slist); | ||
98 | } | ||
99 | |||
100 | ATF_TC(connect_foreign_family); | ||
101 | ATF_TC_HEAD(connect_foreign_family, tc) | ||
102 | { | ||
103 | atf_tc_set_md_var(tc, "descr", "Checks that connecting a socket " | ||
104 | "with a different address family fails"); | ||
105 | } | ||
106 | ATF_TC_BODY(connect_foreign_family, tc) | ||
107 | { | ||
108 | struct sockaddr_in addr; | ||
109 | |||
110 | /* addr.sin_family = AF_UNSPEC = 0 */ | ||
111 | memset(&addr, 0, sizeof(addr)); | ||
112 | |||
113 | /* | ||
114 | * it is not necessary to initialize sin_{addr,port} since | ||
115 | * those structure members shall not be accessed if connect | ||
116 | * fails correctly. | ||
117 | */ | ||
118 | |||
119 | int sock = socket(AF_LOCAL, SOCK_STREAM, 0); | ||
120 | ATF_REQUIRE(sock != -1); | ||
121 | |||
122 | ATF_REQUIRE(-1 == connect(sock, (struct sockaddr *)&addr, sizeof(addr))); | ||
123 | ATF_REQUIRE(EAFNOSUPPORT == errno); | ||
124 | |||
125 | close(sock); | ||
126 | } | ||
127 | |||
128 | ATF_TP_ADD_TCS(tp) | ||
129 | { | ||
130 | |||
131 | ATF_TP_ADD_TC(tp, connect_low_port); | ||
132 | ATF_TP_ADD_TC(tp, connect_foreign_family); | ||
133 | |||
134 | return atf_no_error(); | ||
135 | } | ||
diff --git a/src/regress/lib/libc/sys/t_dup.c b/src/regress/lib/libc/sys/t_dup.c deleted file mode 100644 index b461a5f7c8..0000000000 --- a/src/regress/lib/libc/sys/t_dup.c +++ /dev/null | |||
@@ -1,407 +0,0 @@ | |||
1 | /* $OpenBSD: t_dup.c,v 1.3 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_dup.c,v 1.9 2017/01/13 20:31:53 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/resource.h> | ||
36 | #include <sys/stat.h> | ||
37 | #include <sys/wait.h> | ||
38 | |||
39 | #include "atf-c.h" | ||
40 | #include <errno.h> | ||
41 | #include <fcntl.h> | ||
42 | #include <limits.h> | ||
43 | #include <stdbool.h> | ||
44 | #include <stdio.h> | ||
45 | #include <stdlib.h> | ||
46 | #include <string.h> | ||
47 | #include <unistd.h> | ||
48 | #include <sysexits.h> | ||
49 | |||
50 | static char path[] = "dup"; | ||
51 | static void check_mode(bool, bool, bool); | ||
52 | |||
53 | static void | ||
54 | check_mode(bool _dup, bool _dup2, bool _dup3) | ||
55 | { | ||
56 | int mode[3] = { O_RDONLY, O_WRONLY, O_RDWR }; | ||
57 | int perm[5] = { 0700, 0400, 0600, 0444, 0666 }; | ||
58 | struct stat st, st1; | ||
59 | int fd, fd1, fd2; | ||
60 | size_t i, j; | ||
61 | |||
62 | /* | ||
63 | * Check that a duplicated descriptor | ||
64 | * retains the mode of the original file. | ||
65 | */ | ||
66 | for (i = 0; i < __arraycount(mode); i++) { | ||
67 | |||
68 | for (j = 0; j < __arraycount(perm); j++) { | ||
69 | |||
70 | fd1 = open(path, mode[i] | O_CREAT, perm[j]); | ||
71 | fd2 = open("/etc/passwd", O_RDONLY); | ||
72 | |||
73 | ATF_REQUIRE(fd1 >= 0); | ||
74 | ATF_REQUIRE(fd2 >= 0); | ||
75 | |||
76 | if (_dup != false) | ||
77 | fd = dup(fd1); | ||
78 | else if (_dup2 != false) | ||
79 | fd = dup2(fd1, fd2); | ||
80 | else if (_dup3 != false) | ||
81 | fd = dup3(fd1, fd2, O_CLOEXEC); | ||
82 | else { | ||
83 | fd = -1; | ||
84 | } | ||
85 | |||
86 | ATF_REQUIRE(fd >= 0); | ||
87 | |||
88 | (void)memset(&st, 0, sizeof(struct stat)); | ||
89 | (void)memset(&st1, 0, sizeof(struct stat)); | ||
90 | |||
91 | ATF_REQUIRE(fstat(fd, &st) == 0); | ||
92 | ATF_REQUIRE(fstat(fd1, &st1) == 0); | ||
93 | |||
94 | if (st.st_mode != st1.st_mode) | ||
95 | atf_tc_fail("invalid mode"); | ||
96 | |||
97 | (void)close(fd); | ||
98 | (void)close(fd1); | ||
99 | (void)close(fd2); | ||
100 | (void)unlink(path); | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | |||
105 | ATF_TC(dup2_basic); | ||
106 | ATF_TC_HEAD(dup2_basic, tc) | ||
107 | { | ||
108 | atf_tc_set_md_var(tc, "descr", "A basic test of dup2(2)"); | ||
109 | } | ||
110 | |||
111 | ATF_TC_BODY(dup2_basic, tc) | ||
112 | { | ||
113 | int fd, fd1, fd2; | ||
114 | |||
115 | fd1 = open("/etc/passwd", O_RDONLY); | ||
116 | fd2 = open("/etc/passwd", O_RDONLY); | ||
117 | |||
118 | ATF_REQUIRE(fd1 >= 0); | ||
119 | ATF_REQUIRE(fd2 >= 0); | ||
120 | |||
121 | fd = dup2(fd1, fd2); | ||
122 | ATF_REQUIRE(fd >= 0); | ||
123 | |||
124 | if (fd != fd2) | ||
125 | atf_tc_fail("invalid descriptor"); | ||
126 | |||
127 | (void)close(fd); | ||
128 | (void)close(fd1); | ||
129 | |||
130 | ATF_REQUIRE(close(fd2) != 0); | ||
131 | } | ||
132 | |||
133 | ATF_TC(dup2_err); | ||
134 | ATF_TC_HEAD(dup2_err, tc) | ||
135 | { | ||
136 | atf_tc_set_md_var(tc, "descr", "Test error conditions of dup2(2)"); | ||
137 | } | ||
138 | |||
139 | ATF_TC_BODY(dup2_err, tc) | ||
140 | { | ||
141 | int fd; | ||
142 | |||
143 | fd = open("/etc/passwd", O_RDONLY); | ||
144 | ATF_REQUIRE(fd >= 0); | ||
145 | |||
146 | errno = 0; | ||
147 | ATF_REQUIRE_ERRNO(EBADF, dup2(-1, -1) == -1); | ||
148 | |||
149 | errno = 0; | ||
150 | ATF_REQUIRE_ERRNO(EBADF, dup2(fd, -1) == -1); | ||
151 | |||
152 | errno = 0; | ||
153 | ATF_REQUIRE_ERRNO(EBADF, dup2(-1, fd) == -1); | ||
154 | |||
155 | /* | ||
156 | * Note that this should not fail with EINVAL. | ||
157 | */ | ||
158 | ATF_REQUIRE(dup2(fd, fd) != -1); | ||
159 | |||
160 | (void)close(fd); | ||
161 | } | ||
162 | |||
163 | ATF_TC(dup2_max); | ||
164 | ATF_TC_HEAD(dup2_max, tc) | ||
165 | { | ||
166 | atf_tc_set_md_var(tc, "descr", "Test dup2(2) against limits"); | ||
167 | } | ||
168 | |||
169 | ATF_TC_BODY(dup2_max, tc) | ||
170 | { | ||
171 | struct rlimit res; | ||
172 | |||
173 | (void)memset(&res, 0, sizeof(struct rlimit)); | ||
174 | (void)getrlimit(RLIMIT_NOFILE, &res); | ||
175 | |||
176 | errno = 0; | ||
177 | ATF_REQUIRE_ERRNO(EBADF, dup2(STDERR_FILENO, res.rlim_cur + 1) == -1); | ||
178 | } | ||
179 | |||
180 | ATF_TC_WITH_CLEANUP(dup2_mode); | ||
181 | ATF_TC_HEAD(dup2_mode, tc) | ||
182 | { | ||
183 | atf_tc_set_md_var(tc, "descr", "A basic test of dup2(2)"); | ||
184 | } | ||
185 | |||
186 | ATF_TC_BODY(dup2_mode, tc) | ||
187 | { | ||
188 | check_mode(false, true, false); | ||
189 | } | ||
190 | |||
191 | ATF_TC_CLEANUP(dup2_mode, tc) | ||
192 | { | ||
193 | (void)unlink(path); | ||
194 | } | ||
195 | |||
196 | |||
197 | ATF_TC(dup3_err); | ||
198 | ATF_TC_HEAD(dup3_err, tc) | ||
199 | { | ||
200 | atf_tc_set_md_var(tc, "descr", | ||
201 | "Test error conditions of dup3(2) (PR lib/45148)"); | ||
202 | } | ||
203 | |||
204 | ATF_TC_BODY(dup3_err, tc) | ||
205 | { | ||
206 | int fd; | ||
207 | |||
208 | fd = open("/etc/passwd", O_RDONLY); | ||
209 | ATF_REQUIRE(fd >= 0); | ||
210 | |||
211 | errno = 0; | ||
212 | #ifdef __OpenBSD__ | ||
213 | ATF_REQUIRE(dup3(fd, fd, O_CLOEXEC) == -1); | ||
214 | #else | ||
215 | ATF_REQUIRE(dup3(fd, fd, O_CLOEXEC) != -1); | ||
216 | #endif | ||
217 | |||
218 | errno = 0; | ||
219 | #ifdef __OpenBSD__ | ||
220 | ATF_REQUIRE_ERRNO(EINVAL, dup3(-1, -1, O_CLOEXEC) == -1); | ||
221 | #else | ||
222 | ATF_REQUIRE_ERRNO(EBADF, dup3(-1, -1, O_CLOEXEC) == -1); | ||
223 | #endif | ||
224 | |||
225 | errno = 0; | ||
226 | ATF_REQUIRE_ERRNO(EBADF, dup3(fd, -1, O_CLOEXEC) == -1); | ||
227 | |||
228 | errno = 0; | ||
229 | ATF_REQUIRE_ERRNO(EBADF, dup3(-1, fd, O_CLOEXEC) == -1); | ||
230 | |||
231 | errno = 0; | ||
232 | ATF_REQUIRE_ERRNO(EINVAL, dup3(fd, 1, O_NOFOLLOW) == -1); | ||
233 | |||
234 | (void)close(fd); | ||
235 | } | ||
236 | |||
237 | ATF_TC(dup3_max); | ||
238 | ATF_TC_HEAD(dup3_max, tc) | ||
239 | { | ||
240 | atf_tc_set_md_var(tc, "descr", "Test dup3(2) against limits"); | ||
241 | } | ||
242 | |||
243 | ATF_TC_BODY(dup3_max, tc) | ||
244 | { | ||
245 | struct rlimit res; | ||
246 | |||
247 | (void)memset(&res, 0, sizeof(struct rlimit)); | ||
248 | (void)getrlimit(RLIMIT_NOFILE, &res); | ||
249 | |||
250 | errno = 0; | ||
251 | ATF_REQUIRE_ERRNO(EBADF, dup3(STDERR_FILENO, | ||
252 | res.rlim_cur + 1, O_CLOEXEC) == -1); | ||
253 | } | ||
254 | |||
255 | ATF_TC_WITH_CLEANUP(dup3_mode); | ||
256 | ATF_TC_HEAD(dup3_mode, tc) | ||
257 | { | ||
258 | atf_tc_set_md_var(tc, "descr", "A basic test of dup3(2)"); | ||
259 | } | ||
260 | |||
261 | ATF_TC_BODY(dup3_mode, tc) | ||
262 | { | ||
263 | check_mode(false, false, true); | ||
264 | } | ||
265 | |||
266 | ATF_TC_CLEANUP(dup3_mode, tc) | ||
267 | { | ||
268 | (void)unlink(path); | ||
269 | } | ||
270 | |||
271 | ATF_TC(dup_err); | ||
272 | ATF_TC_HEAD(dup_err, tc) | ||
273 | { | ||
274 | atf_tc_set_md_var(tc, "descr", "Test error conditions of dup(2)"); | ||
275 | } | ||
276 | |||
277 | ATF_TC_BODY(dup_err, tc) | ||
278 | { | ||
279 | |||
280 | errno = 0; | ||
281 | ATF_REQUIRE_ERRNO(EBADF, dup(-1) == -1); | ||
282 | } | ||
283 | |||
284 | ATF_TC_WITH_CLEANUP(dup_max); | ||
285 | ATF_TC_HEAD(dup_max, tc) | ||
286 | { | ||
287 | atf_tc_set_md_var(tc, "descr", "Test dup(2) against limits"); | ||
288 | } | ||
289 | |||
290 | ATF_TC_BODY(dup_max, tc) | ||
291 | { | ||
292 | struct rlimit res; | ||
293 | int *buf, fd, sta; | ||
294 | size_t i, n; | ||
295 | pid_t pid; | ||
296 | |||
297 | pid = fork(); | ||
298 | ATF_REQUIRE(pid >= 0); | ||
299 | |||
300 | if (pid == 0) { | ||
301 | |||
302 | /* | ||
303 | * Open a temporary file until the | ||
304 | * maximum number of open files is | ||
305 | * reached. Ater that dup(2) family | ||
306 | * should fail with EMFILE. | ||
307 | */ | ||
308 | #ifdef __OpenBSD__ | ||
309 | (void)closefrom(STDERR_FILENO + 1); | ||
310 | #else | ||
311 | (void)closefrom(0); | ||
312 | #endif | ||
313 | (void)memset(&res, 0, sizeof(struct rlimit)); | ||
314 | |||
315 | n = 10; | ||
316 | res.rlim_cur = res.rlim_max = n; | ||
317 | if (setrlimit(RLIMIT_NOFILE, &res) != 0) | ||
318 | _exit(EX_OSERR); | ||
319 | |||
320 | buf = calloc(n, sizeof(int)); | ||
321 | |||
322 | if (buf == NULL) | ||
323 | _exit(EX_OSERR); | ||
324 | |||
325 | #ifdef __OpenBSD__ | ||
326 | buf[0] = open(path, O_CREAT|O_EXCL|O_RDWR, S_IRUSR|S_IWUSR); | ||
327 | #else | ||
328 | buf[0] = mkstemp(path); | ||
329 | #endif | ||
330 | |||
331 | if (buf[0] < 0) | ||
332 | _exit(EX_OSERR); | ||
333 | |||
334 | #ifdef __OpenBSD__ | ||
335 | for (i = 1; i < n - (STDERR_FILENO + 1); i++) { | ||
336 | #else | ||
337 | for (i = 1; i < n; i++) { | ||
338 | #endif | ||
339 | |||
340 | buf[i] = open(path, O_RDONLY); | ||
341 | |||
342 | if (buf[i] < 0) | ||
343 | _exit(EX_OSERR); | ||
344 | } | ||
345 | |||
346 | errno = 0; | ||
347 | fd = dup(buf[0]); | ||
348 | |||
349 | if (fd != -1 || errno != EMFILE) | ||
350 | _exit(EX_DATAERR); | ||
351 | |||
352 | _exit(EXIT_SUCCESS); | ||
353 | } | ||
354 | |||
355 | (void)wait(&sta); | ||
356 | |||
357 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) { | ||
358 | |||
359 | if (WEXITSTATUS(sta) == EX_OSERR) | ||
360 | atf_tc_fail("system call error"); | ||
361 | |||
362 | if (WEXITSTATUS(sta) == EX_DATAERR) | ||
363 | atf_tc_fail("dup(2) dupped more than RLIMIT_NOFILE"); | ||
364 | |||
365 | atf_tc_fail("unknown error"); | ||
366 | } | ||
367 | |||
368 | (void)unlink(path); | ||
369 | } | ||
370 | |||
371 | ATF_TC_CLEANUP(dup_max, tc) | ||
372 | { | ||
373 | (void)unlink(path); | ||
374 | } | ||
375 | |||
376 | ATF_TC_WITH_CLEANUP(dup_mode); | ||
377 | ATF_TC_HEAD(dup_mode, tc) | ||
378 | { | ||
379 | atf_tc_set_md_var(tc, "descr", "A basic test of dup(2)"); | ||
380 | } | ||
381 | |||
382 | ATF_TC_BODY(dup_mode, tc) | ||
383 | { | ||
384 | check_mode(true, false, false); | ||
385 | } | ||
386 | |||
387 | ATF_TC_CLEANUP(dup_mode, tc) | ||
388 | { | ||
389 | (void)unlink(path); | ||
390 | } | ||
391 | |||
392 | ATF_TP_ADD_TCS(tp) | ||
393 | { | ||
394 | |||
395 | ATF_TP_ADD_TC(tp, dup2_basic); | ||
396 | ATF_TP_ADD_TC(tp, dup2_err); | ||
397 | ATF_TP_ADD_TC(tp, dup2_max); | ||
398 | ATF_TP_ADD_TC(tp, dup2_mode); | ||
399 | ATF_TP_ADD_TC(tp, dup3_err); | ||
400 | ATF_TP_ADD_TC(tp, dup3_max); | ||
401 | ATF_TP_ADD_TC(tp, dup3_mode); | ||
402 | ATF_TP_ADD_TC(tp, dup_err); | ||
403 | ATF_TP_ADD_TC(tp, dup_max); | ||
404 | ATF_TP_ADD_TC(tp, dup_mode); | ||
405 | |||
406 | return atf_no_error(); | ||
407 | } | ||
diff --git a/src/regress/lib/libc/sys/t_fork.c b/src/regress/lib/libc/sys/t_fork.c deleted file mode 100644 index b55b557824..0000000000 --- a/src/regress/lib/libc/sys/t_fork.c +++ /dev/null | |||
@@ -1,383 +0,0 @@ | |||
1 | /* $OpenBSD: t_fork.c,v 1.5 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_fork.c,v 1.4 2019/04/06 15:41:54 kamil Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2018, 2019 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
27 | * POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | #include "macros.h" | ||
30 | |||
31 | #include <sys/types.h> | ||
32 | #include <sys/signal.h> | ||
33 | #ifdef __OpenBSD__ | ||
34 | #include <sys/proc.h> | ||
35 | #endif | ||
36 | #include <sys/sysctl.h> | ||
37 | #include <sys/wait.h> | ||
38 | #include <sched.h> | ||
39 | #include <signal.h> | ||
40 | #include <stdbool.h> | ||
41 | #include <stdlib.h> | ||
42 | #include <unistd.h> | ||
43 | #include <err.h> | ||
44 | #include <errno.h> | ||
45 | |||
46 | #include "atf-c.h" | ||
47 | |||
48 | #ifdef VFORK | ||
49 | #define FORK vfork | ||
50 | #else | ||
51 | #define FORK fork | ||
52 | #endif | ||
53 | |||
54 | /* | ||
55 | * A child process cannot call atf functions and expect them to magically | ||
56 | * work like in the parent. | ||
57 | * The printf(3) messaging from a child will not work out of the box as well | ||
58 | * without estabilishing a communication protocol with its parent. To not | ||
59 | * overcomplicate the tests - do not log from a child and use err(3)/errx(3) | ||
60 | * wrapped with ASSERT_EQ()/ASSERT_NEQ() as that is guaranteed to work. | ||
61 | */ | ||
62 | #define ASSERT_EQ(x, y) \ | ||
63 | do { \ | ||
64 | uintmax_t vx = (x); \ | ||
65 | uintmax_t vy = (y); \ | ||
66 | int ret = vx == vy; \ | ||
67 | if (!ret) \ | ||
68 | errx(EXIT_FAILURE, "%s:%d %s(): Assertion failed for: " \ | ||
69 | "%s(%ju) == %s(%ju)", __FILE__, __LINE__, __func__, \ | ||
70 | #x, vx, #y, vy); \ | ||
71 | } while (/*CONSTCOND*/0) | ||
72 | |||
73 | #define ASSERT_NEQ(x, y) \ | ||
74 | do { \ | ||
75 | uintmax_t vx = (x); \ | ||
76 | uintmax_t vy = (y); \ | ||
77 | int ret = vx != vy; \ | ||
78 | if (!ret) \ | ||
79 | errx(EXIT_FAILURE, "%s:%d %s(): Assertion failed for: " \ | ||
80 | "%s(%ju) != %s(%ju)", __FILE__, __LINE__, __func__, \ | ||
81 | #x, vx, #y, vy); \ | ||
82 | } while (/*CONSTCOND*/0) | ||
83 | |||
84 | static pid_t | ||
85 | await_stopped_child(pid_t process) | ||
86 | { | ||
87 | struct kinfo_proc2 *p = NULL; | ||
88 | size_t i, len; | ||
89 | pid_t child = -1; | ||
90 | |||
91 | int name[] = { | ||
92 | [0] = CTL_KERN, | ||
93 | [1] = KERN_PROC2, | ||
94 | [2] = KERN_PROC_ALL, | ||
95 | [3] = 0, | ||
96 | [4] = sizeof(struct kinfo_proc2), | ||
97 | [5] = 0 | ||
98 | }; | ||
99 | |||
100 | const size_t namelen = __arraycount(name); | ||
101 | |||
102 | /* Await the process becoming a zombie */ | ||
103 | while(1) { | ||
104 | name[5] = 0; | ||
105 | |||
106 | ASSERT_EQ(sysctl(name, namelen, 0, &len, NULL, 0), 0); | ||
107 | |||
108 | ASSERT_EQ(reallocarr(&p, len, sizeof(struct kinfo_proc2)), 0); | ||
109 | |||
110 | name[5] = len; | ||
111 | |||
112 | ASSERT_EQ(sysctl(name, namelen, p, &len, NULL, 0), 0); | ||
113 | |||
114 | for (i = 0; i < len/sizeof(struct kinfo_proc2); i++) { | ||
115 | if (p[i].p_pid == getpid()) | ||
116 | continue; | ||
117 | if (p[i].p_ppid != process) | ||
118 | continue; | ||
119 | if (p[i].p_stat != LSSTOP) | ||
120 | continue; | ||
121 | child = p[i].p_pid; | ||
122 | break; | ||
123 | } | ||
124 | |||
125 | if (child != -1) | ||
126 | break; | ||
127 | |||
128 | ASSERT_EQ(usleep(1000), 0); | ||
129 | } | ||
130 | |||
131 | /* Free the buffer */ | ||
132 | ASSERT_EQ(reallocarr(&p, 0, sizeof(struct kinfo_proc2)), 0); | ||
133 | |||
134 | return child; | ||
135 | } | ||
136 | |||
137 | static void | ||
138 | raise_raw(int sig) | ||
139 | { | ||
140 | int rv, status; | ||
141 | pid_t child, parent, watcher, wpid; | ||
142 | int expect_core = (sig == SIGABRT) ? 1 : 0; | ||
143 | |||
144 | /* | ||
145 | * Spawn a dedicated thread to watch for a stopped child and emit | ||
146 | * the SIGKILL signal to it. | ||
147 | * | ||
148 | * This is required in vfork(2)ing parent and optional in fork(2). | ||
149 | * | ||
150 | * vfork(2) might clobber watcher, this means that it's safer and | ||
151 | * simpler to reparent this process to initproc and forget about it. | ||
152 | */ | ||
153 | if (sig == SIGSTOP | ||
154 | #ifndef VFORK | ||
155 | || (sig == SIGTSTP || sig == SIGTTIN || sig == SIGTTOU) | ||
156 | #endif | ||
157 | ) { | ||
158 | |||
159 | parent = getpid(); | ||
160 | |||
161 | watcher = fork(); | ||
162 | ATF_REQUIRE(watcher != 1); | ||
163 | if (watcher == 0) { | ||
164 | /* Double fork(2) trick to reparent to initproc */ | ||
165 | watcher = fork(); | ||
166 | ASSERT_NEQ(watcher, -1); | ||
167 | if (watcher != 0) | ||
168 | _exit(0); | ||
169 | |||
170 | child = await_stopped_child(parent); | ||
171 | |||
172 | errno = 0; | ||
173 | rv = kill(child, SIGKILL); | ||
174 | ASSERT_EQ(rv, 0); | ||
175 | ASSERT_EQ(errno, 0); | ||
176 | |||
177 | /* This exit value will be collected by initproc */ | ||
178 | _exit(0); | ||
179 | } | ||
180 | |||
181 | wpid = waitpid(watcher, &status, 0); | ||
182 | |||
183 | ATF_REQUIRE_EQ(wpid, watcher); | ||
184 | |||
185 | ATF_REQUIRE(WIFEXITED(status)); | ||
186 | ATF_REQUIRE(!WIFCONTINUED(status)); | ||
187 | ATF_REQUIRE(!WIFSIGNALED(status)); | ||
188 | ATF_REQUIRE(!WIFSTOPPED(status)); | ||
189 | ATF_REQUIRE_EQ(WEXITSTATUS(status), 0); | ||
190 | } | ||
191 | |||
192 | child = FORK(); | ||
193 | ATF_REQUIRE(child != 1); | ||
194 | if (child == 0) { | ||
195 | rv = raise(sig); | ||
196 | ASSERT_EQ(rv, 0); | ||
197 | _exit(0); | ||
198 | } | ||
199 | wpid = waitpid(child, &status, 0); | ||
200 | |||
201 | ATF_REQUIRE_EQ(wpid, child); | ||
202 | |||
203 | switch (sig) { | ||
204 | case SIGKILL: | ||
205 | case SIGABRT: | ||
206 | case SIGHUP: | ||
207 | ATF_REQUIRE(!WIFEXITED(status)); | ||
208 | ATF_REQUIRE(!WIFCONTINUED(status)); | ||
209 | ATF_REQUIRE(WIFSIGNALED(status)); | ||
210 | ATF_REQUIRE(!WIFSTOPPED(status)); | ||
211 | ATF_REQUIRE_EQ(WTERMSIG(status), sig); | ||
212 | ATF_REQUIRE_EQ(!!WCOREDUMP(status), expect_core); | ||
213 | break; | ||
214 | #ifdef VFORK | ||
215 | case SIGTSTP: | ||
216 | case SIGTTIN: | ||
217 | case SIGTTOU: | ||
218 | #endif | ||
219 | case SIGCONT: | ||
220 | ATF_REQUIRE(WIFEXITED(status)); | ||
221 | ATF_REQUIRE(!WIFCONTINUED(status)); | ||
222 | ATF_REQUIRE(!WIFSIGNALED(status)); | ||
223 | ATF_REQUIRE(!WIFSTOPPED(status)); | ||
224 | ATF_REQUIRE_EQ(WEXITSTATUS(status), 0); | ||
225 | break; | ||
226 | #ifndef VFORK | ||
227 | case SIGTSTP: | ||
228 | case SIGTTIN: | ||
229 | case SIGTTOU: | ||
230 | #endif | ||
231 | case SIGSTOP: | ||
232 | ATF_REQUIRE(!WIFEXITED(status)); | ||
233 | ATF_REQUIRE(!WIFCONTINUED(status)); | ||
234 | ATF_REQUIRE(WIFSIGNALED(status)); | ||
235 | ATF_REQUIRE(!WIFSTOPPED(status)); | ||
236 | ATF_REQUIRE_EQ(WTERMSIG(status), SIGKILL); | ||
237 | ATF_REQUIRE_EQ(!!WCOREDUMP(status), 0); | ||
238 | } | ||
239 | } | ||
240 | |||
241 | #define RAISE(test, sig) \ | ||
242 | ATF_TC(test); \ | ||
243 | ATF_TC_HEAD(test, tc) \ | ||
244 | { \ | ||
245 | \ | ||
246 | atf_tc_set_md_var(tc, "descr", \ | ||
247 | "raise " #sig " in a child"); \ | ||
248 | } \ | ||
249 | \ | ||
250 | ATF_TC_BODY(test, tc) \ | ||
251 | { \ | ||
252 | \ | ||
253 | raise_raw(sig); \ | ||
254 | } | ||
255 | |||
256 | RAISE(raise1, SIGKILL) /* non-maskable */ | ||
257 | RAISE(raise2, SIGSTOP) /* non-maskable */ | ||
258 | RAISE(raise3, SIGTSTP) /* ignored in vfork(2) */ | ||
259 | RAISE(raise4, SIGTTIN) /* ignored in vfork(2) */ | ||
260 | RAISE(raise5, SIGTTOU) /* ignored in vfork(2) */ | ||
261 | RAISE(raise6, SIGABRT) /* regular abort trap */ | ||
262 | RAISE(raise7, SIGHUP) /* hangup */ | ||
263 | RAISE(raise8, SIGCONT) /* continued? */ | ||
264 | |||
265 | /// ---------------------------------------------------------------------------- | ||
266 | |||
267 | static int | ||
268 | clone_func(void *arg __unused) | ||
269 | { | ||
270 | |||
271 | return 0; | ||
272 | } | ||
273 | |||
274 | static void | ||
275 | nested_raw(const char *fn, volatile int flags) | ||
276 | { | ||
277 | int status; | ||
278 | pid_t child, child2, wpid; | ||
279 | const size_t stack_size = 1024 * 1024; | ||
280 | void *stack, *stack_base; | ||
281 | |||
282 | stack = malloc(stack_size); | ||
283 | ATF_REQUIRE(stack != NULL); | ||
284 | |||
285 | #ifdef __MACHINE_STACK_GROWS_UP | ||
286 | stack_base = stack; | ||
287 | #else | ||
288 | stack_base = (char *)stack + stack_size; | ||
289 | #endif | ||
290 | |||
291 | flags |= SIGCHLD; | ||
292 | |||
293 | child = FORK(); | ||
294 | ATF_REQUIRE(child != 1); | ||
295 | if (child == 0) { | ||
296 | if (strcmp(fn, "fork") == 0) | ||
297 | child2 = fork(); | ||
298 | else if (strcmp(fn, "vfork") == 0) | ||
299 | child2 = vfork(); | ||
300 | #ifndef __OpenBSD__ | ||
301 | else if (strcmp(fn, "clone") == 0) | ||
302 | child2 = __clone(clone_func, stack_base, flags, NULL); | ||
303 | #endif | ||
304 | else | ||
305 | __unreachable(); | ||
306 | |||
307 | ASSERT_NEQ(child2, -1); | ||
308 | |||
309 | if ((strcmp(fn, "fork") == 0) || (strcmp(fn, "vfork") == 0)) { | ||
310 | if (child2 == 0) | ||
311 | _exit(0); | ||
312 | } | ||
313 | |||
314 | wpid = waitpid(child2, &status, 0); | ||
315 | ASSERT_EQ(child2, wpid); | ||
316 | ASSERT_EQ(!!WIFEXITED(status), true); | ||
317 | ASSERT_EQ(!!WIFCONTINUED(status), false); | ||
318 | ASSERT_EQ(!!WIFSIGNALED(status), false); | ||
319 | ASSERT_EQ(!!WIFSTOPPED(status), false); | ||
320 | ASSERT_EQ(WEXITSTATUS(status), 0); | ||
321 | |||
322 | _exit(0); | ||
323 | } | ||
324 | wpid = waitpid(child, &status, 0); | ||
325 | |||
326 | ATF_REQUIRE_EQ(wpid, child); | ||
327 | ATF_REQUIRE_EQ(!!WIFEXITED(status), true); | ||
328 | ATF_REQUIRE_EQ(!!WIFCONTINUED(status), false); | ||
329 | ATF_REQUIRE_EQ(!!WIFSIGNALED(status), false); | ||
330 | ATF_REQUIRE_EQ(!!WIFSTOPPED(status), false); | ||
331 | ATF_REQUIRE_EQ(WEXITSTATUS(status), 0); | ||
332 | } | ||
333 | |||
334 | #define NESTED(test, fn, flags) \ | ||
335 | ATF_TC(test); \ | ||
336 | ATF_TC_HEAD(test, tc) \ | ||
337 | { \ | ||
338 | \ | ||
339 | atf_tc_set_md_var(tc, "descr", \ | ||
340 | "Test nested " #fn " in a child"); \ | ||
341 | } \ | ||
342 | \ | ||
343 | ATF_TC_BODY(test, tc) \ | ||
344 | { \ | ||
345 | \ | ||
346 | nested_raw(#fn, flags); \ | ||
347 | } | ||
348 | |||
349 | NESTED(nested_fork, fork, 0) | ||
350 | NESTED(nested_vfork, vfork, 0) | ||
351 | #ifndef __OpenBSD__ | ||
352 | NESTED(nested_clone, clone, 0) | ||
353 | NESTED(nested_clone_vm, clone, CLONE_VM) | ||
354 | NESTED(nested_clone_fs, clone, CLONE_FS) | ||
355 | NESTED(nested_clone_files, clone, CLONE_FILES) | ||
356 | //NESTED(nested_clone_sighand, clone, CLONE_SIGHAND) // XXX | ||
357 | NESTED(nested_clone_vfork, clone, CLONE_VFORK) | ||
358 | #endif | ||
359 | |||
360 | ATF_TP_ADD_TCS(tp) | ||
361 | { | ||
362 | ATF_TP_ADD_TC(tp, raise1); | ||
363 | ATF_TP_ADD_TC(tp, raise2); | ||
364 | ATF_TP_ADD_TC(tp, raise3); | ||
365 | ATF_TP_ADD_TC(tp, raise4); | ||
366 | ATF_TP_ADD_TC(tp, raise5); | ||
367 | ATF_TP_ADD_TC(tp, raise6); | ||
368 | ATF_TP_ADD_TC(tp, raise7); | ||
369 | ATF_TP_ADD_TC(tp, raise8); | ||
370 | |||
371 | ATF_TP_ADD_TC(tp, nested_fork); | ||
372 | ATF_TP_ADD_TC(tp, nested_vfork); | ||
373 | #ifndef __OpenBSD__ | ||
374 | ATF_TP_ADD_TC(tp, nested_clone); | ||
375 | ATF_TP_ADD_TC(tp, nested_clone_vm); | ||
376 | ATF_TP_ADD_TC(tp, nested_clone_fs); | ||
377 | ATF_TP_ADD_TC(tp, nested_clone_files); | ||
378 | // ATF_TP_ADD_TC(tp, nested_clone_sighand); // XXX | ||
379 | ATF_TP_ADD_TC(tp, nested_clone_vfork); | ||
380 | #endif | ||
381 | |||
382 | return atf_no_error(); | ||
383 | } | ||
diff --git a/src/regress/lib/libc/sys/t_fsync.c b/src/regress/lib/libc/sys/t_fsync.c deleted file mode 100644 index 66653df633..0000000000 --- a/src/regress/lib/libc/sys/t_fsync.c +++ /dev/null | |||
@@ -1,125 +0,0 @@ | |||
1 | /* $OpenBSD: t_fsync.c,v 1.3 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_fsync.c,v 1.2 2012/03/18 07:00:52 jruoho Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <errno.h> | ||
36 | #include <fcntl.h> | ||
37 | #include <stdio.h> | ||
38 | #include <stdlib.h> | ||
39 | #include <string.h> | ||
40 | #include <unistd.h> | ||
41 | |||
42 | #include "atf-c.h" | ||
43 | |||
44 | ATF_TC(fsync_err); | ||
45 | ATF_TC_HEAD(fsync_err, tc) | ||
46 | { | ||
47 | atf_tc_set_md_var(tc, "descr", | ||
48 | "Test error conditions of fsync(2) (PR kern/30)"); | ||
49 | } | ||
50 | |||
51 | ATF_TC_BODY(fsync_err, tc) | ||
52 | { | ||
53 | int i, fd[2]; | ||
54 | |||
55 | /* | ||
56 | * The fsync(2) call should fail with EBADF | ||
57 | * when the 'fd' is not a valid descriptor. | ||
58 | */ | ||
59 | for (i = 1; i < 1024; i = i + 128) { | ||
60 | |||
61 | errno = 0; | ||
62 | |||
63 | ATF_REQUIRE(fsync(-i) == -1); | ||
64 | ATF_REQUIRE(errno == EBADF); | ||
65 | } | ||
66 | |||
67 | /* | ||
68 | * On the other hand, EINVAL should follow | ||
69 | * if the operation is not possible with | ||
70 | * the file descriptor. | ||
71 | */ | ||
72 | ATF_REQUIRE(pipe(fd) == 0); | ||
73 | |||
74 | errno = 0; | ||
75 | |||
76 | ATF_REQUIRE(fsync(fd[0]) == -1); | ||
77 | ATF_REQUIRE(errno == EINVAL); | ||
78 | |||
79 | errno = 0; | ||
80 | |||
81 | ATF_REQUIRE(fsync(fd[1]) == -1); | ||
82 | ATF_REQUIRE(errno == EINVAL); | ||
83 | |||
84 | ATF_REQUIRE(close(fd[0]) == 0); | ||
85 | ATF_REQUIRE(close(fd[1]) == 0); | ||
86 | } | ||
87 | |||
88 | ATF_TC(fsync_sync); | ||
89 | ATF_TC_HEAD(fsync_sync, tc) | ||
90 | { | ||
91 | atf_tc_set_md_var(tc, "descr", "A basic test of fsync(2)"); | ||
92 | } | ||
93 | |||
94 | ATF_TC_BODY(fsync_sync, tc) | ||
95 | { | ||
96 | char buf[128]; | ||
97 | int fd, i; | ||
98 | |||
99 | for (i = 0; i < 10; i++) { | ||
100 | |||
101 | (void)snprintf(buf, sizeof(buf), "t_fsync-%d", i); | ||
102 | |||
103 | #ifdef __OpenBSD__ | ||
104 | fd = open(buf, O_CREAT|O_EXCL|O_RDWR, 0600); | ||
105 | #else | ||
106 | fd = mkstemp(buf); | ||
107 | #endif | ||
108 | |||
109 | ATF_REQUIRE(fd != -1); | ||
110 | ATF_REQUIRE(write(fd, "0", 1) == 1); | ||
111 | ATF_REQUIRE(fsync(fd) == 0); | ||
112 | |||
113 | ATF_REQUIRE(unlink(buf) == 0); | ||
114 | ATF_REQUIRE(close(fd) == 0); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | ATF_TP_ADD_TCS(tp) | ||
119 | { | ||
120 | |||
121 | ATF_TP_ADD_TC(tp, fsync_err); | ||
122 | ATF_TP_ADD_TC(tp, fsync_sync); | ||
123 | |||
124 | return atf_no_error(); | ||
125 | } | ||
diff --git a/src/regress/lib/libc/sys/t_getgroups.c b/src/regress/lib/libc/sys/t_getgroups.c deleted file mode 100644 index a17c9c6778..0000000000 --- a/src/regress/lib/libc/sys/t_getgroups.c +++ /dev/null | |||
@@ -1,176 +0,0 @@ | |||
1 | /* $OpenBSD: t_getgroups.c,v 1.3 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_getgroups.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/wait.h> | ||
36 | |||
37 | #include "atf-c.h" | ||
38 | #include <errno.h> | ||
39 | #include <limits.h> | ||
40 | #include <stdlib.h> | ||
41 | #include <string.h> | ||
42 | #include <unistd.h> | ||
43 | |||
44 | ATF_TC(getgroups_err); | ||
45 | ATF_TC_HEAD(getgroups_err, tc) | ||
46 | { | ||
47 | atf_tc_set_md_var(tc, "descr", "Test errors in getgroups(2)"); | ||
48 | } | ||
49 | |||
50 | ATF_TC_BODY(getgroups_err, tc) | ||
51 | { | ||
52 | gid_t gidset[NGROUPS_MAX]; | ||
53 | |||
54 | errno = 0; | ||
55 | |||
56 | #if __OpenBSD__ | ||
57 | ATF_REQUIRE(getgroups(NGROUPS_MAX, (gid_t *)-1) == -1); | ||
58 | #else | ||
59 | ATF_REQUIRE(getgroups(10, (gid_t *)-1) == -1); | ||
60 | #endif | ||
61 | ATF_REQUIRE(errno == EFAULT); | ||
62 | |||
63 | errno = 0; | ||
64 | |||
65 | ATF_REQUIRE(getgroups(-1, gidset) == -1); | ||
66 | ATF_REQUIRE(errno == EINVAL); | ||
67 | } | ||
68 | |||
69 | ATF_TC(getgroups_getgid); | ||
70 | ATF_TC_HEAD(getgroups_getgid, tc) | ||
71 | { | ||
72 | atf_tc_set_md_var(tc, "descr", "Test getgid(2) from getgroups(2)"); | ||
73 | } | ||
74 | |||
75 | ATF_TC_BODY(getgroups_getgid, tc) | ||
76 | { | ||
77 | gid_t gidset[NGROUPS_MAX]; | ||
78 | gid_t gid = getgid(); | ||
79 | int i, n; | ||
80 | |||
81 | /* | ||
82 | * Check that getgid(2) is found from | ||
83 | * the GIDs returned by getgroups(2). | ||
84 | */ | ||
85 | n = getgroups(NGROUPS_MAX, gidset); | ||
86 | |||
87 | for (i = 0; i < n; i++) { | ||
88 | |||
89 | if (gidset[i] == gid) | ||
90 | return; | ||
91 | } | ||
92 | |||
93 | atf_tc_fail("getgid(2) not found from getgroups(2)"); | ||
94 | } | ||
95 | |||
96 | ATF_TC(getgroups_setgid); | ||
97 | ATF_TC_HEAD(getgroups_setgid, tc) | ||
98 | { | ||
99 | atf_tc_set_md_var(tc, "descr", "Test setgid(2) from getgroups(2)"); | ||
100 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
101 | } | ||
102 | |||
103 | ATF_TC_BODY(getgroups_setgid, tc) | ||
104 | { | ||
105 | gid_t gidset[NGROUPS_MAX]; | ||
106 | int i, n, rv, sta; | ||
107 | pid_t pid; | ||
108 | |||
109 | /* | ||
110 | * Check that we can setgid(2) | ||
111 | * to the returned group IDs. | ||
112 | */ | ||
113 | n = getgroups(NGROUPS_MAX, gidset); | ||
114 | ATF_REQUIRE(n >= 0); | ||
115 | |||
116 | for (i = 0; i < n; i++) { | ||
117 | |||
118 | pid = fork(); | ||
119 | ATF_REQUIRE(pid >= 0); | ||
120 | |||
121 | if (pid == 0) { | ||
122 | |||
123 | rv = setgid(gidset[i]); | ||
124 | |||
125 | if (rv != 0) | ||
126 | _exit(EXIT_FAILURE); | ||
127 | |||
128 | _exit(EXIT_SUCCESS); | ||
129 | } | ||
130 | |||
131 | (void)wait(&sta); | ||
132 | |||
133 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
134 | atf_tc_fail("getgroups(2) is inconsistent"); | ||
135 | } | ||
136 | } | ||
137 | |||
138 | ATF_TC(getgroups_zero); | ||
139 | ATF_TC_HEAD(getgroups_zero, tc) | ||
140 | { | ||
141 | atf_tc_set_md_var(tc, "descr", "Test getgroups(2) with zero param"); | ||
142 | } | ||
143 | |||
144 | ATF_TC_BODY(getgroups_zero, tc) | ||
145 | { | ||
146 | const gid_t val = 123456789; | ||
147 | gid_t gidset[NGROUPS_MAX]; | ||
148 | size_t i; | ||
149 | |||
150 | /* | ||
151 | * If the first parameter is zero, the number | ||
152 | * of groups should be returned but the supplied | ||
153 | * buffer should remain intact. | ||
154 | */ | ||
155 | for (i = 0; i < __arraycount(gidset); i++) | ||
156 | gidset[i] = val; | ||
157 | |||
158 | ATF_REQUIRE(getgroups(0, gidset) >= 0); | ||
159 | |||
160 | for (i = 0; i < __arraycount(gidset); i++) { | ||
161 | |||
162 | if (gidset[i] != val) | ||
163 | atf_tc_fail("getgroups(2) modified the buffer"); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | ATF_TP_ADD_TCS(tp) | ||
168 | { | ||
169 | |||
170 | ATF_TP_ADD_TC(tp, getgroups_err); | ||
171 | ATF_TP_ADD_TC(tp, getgroups_getgid); | ||
172 | ATF_TP_ADD_TC(tp, getgroups_setgid); | ||
173 | ATF_TP_ADD_TC(tp, getgroups_zero); | ||
174 | |||
175 | return atf_no_error(); | ||
176 | } | ||
diff --git a/src/regress/lib/libc/sys/t_getitimer.c b/src/regress/lib/libc/sys/t_getitimer.c deleted file mode 100644 index b18bc75cd0..0000000000 --- a/src/regress/lib/libc/sys/t_getitimer.c +++ /dev/null | |||
@@ -1,215 +0,0 @@ | |||
1 | /* $OpenBSD: t_getitimer.c,v 1.4 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_getitimer.c,v 1.3 2019/07/13 12:44:02 gson Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/time.h> | ||
36 | |||
37 | #include "atf-c.h" | ||
38 | #include <errno.h> | ||
39 | #include <limits.h> | ||
40 | #include <signal.h> | ||
41 | #include <string.h> | ||
42 | #include <unistd.h> | ||
43 | |||
44 | static bool fail; | ||
45 | static void sighandler(int); | ||
46 | |||
47 | static void | ||
48 | sighandler(int signo) | ||
49 | { | ||
50 | |||
51 | if (signo == SIGALRM || signo == SIGVTALRM) | ||
52 | fail = false; | ||
53 | } | ||
54 | |||
55 | ATF_TC(getitimer_empty); | ||
56 | ATF_TC_HEAD(getitimer_empty, tc) | ||
57 | { | ||
58 | atf_tc_set_md_var(tc, "descr", "getitimer(2) before setitimer(2)"); | ||
59 | } | ||
60 | |||
61 | ATF_TC_BODY(getitimer_empty, tc) | ||
62 | { | ||
63 | struct itimerval it; | ||
64 | |||
65 | /* | ||
66 | * Verify that the passed structure remains | ||
67 | * empty after calling getitimer(2) but before | ||
68 | * actually arming the timer with setitimer(2). | ||
69 | */ | ||
70 | (void)memset(&it, 0, sizeof(struct itimerval)); | ||
71 | |||
72 | ATF_REQUIRE(getitimer(ITIMER_REAL, &it) == 0); | ||
73 | |||
74 | if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0) | ||
75 | goto fail; | ||
76 | |||
77 | ATF_REQUIRE(getitimer(ITIMER_VIRTUAL, &it) == 0); | ||
78 | |||
79 | if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0) | ||
80 | goto fail; | ||
81 | |||
82 | ATF_REQUIRE(getitimer(ITIMER_PROF, &it) == 0); | ||
83 | |||
84 | if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0) | ||
85 | goto fail; | ||
86 | |||
87 | return; | ||
88 | |||
89 | fail: | ||
90 | atf_tc_fail("getitimer(2) modfied the timer before it was armed"); | ||
91 | } | ||
92 | |||
93 | ATF_TC(getitimer_err); | ||
94 | ATF_TC_HEAD(getitimer_err, tc) | ||
95 | { | ||
96 | atf_tc_set_md_var(tc, "descr", "Test errors from getitimer(2)"); | ||
97 | } | ||
98 | |||
99 | ATF_TC_BODY(getitimer_err, tc) | ||
100 | { | ||
101 | struct itimerval it; | ||
102 | |||
103 | errno = 0; | ||
104 | ATF_REQUIRE_ERRNO(EINVAL, getitimer(-1, &it) == -1); | ||
105 | |||
106 | errno = 0; | ||
107 | ATF_REQUIRE_ERRNO(EINVAL, getitimer(INT_MAX, &it) == -1); | ||
108 | |||
109 | errno = 0; | ||
110 | ATF_REQUIRE_ERRNO(EFAULT, getitimer(ITIMER_REAL, (void *)-1) == -1); | ||
111 | } | ||
112 | |||
113 | ATF_TC(setitimer_basic); | ||
114 | ATF_TC_HEAD(setitimer_basic, tc) | ||
115 | { | ||
116 | atf_tc_set_md_var(tc, "descr", "A basic test of setitimer(2)"); | ||
117 | } | ||
118 | |||
119 | ATF_TC_BODY(setitimer_basic, tc) | ||
120 | { | ||
121 | struct itimerval it; | ||
122 | |||
123 | it.it_value.tv_sec = 0; | ||
124 | it.it_value.tv_usec = 100; | ||
125 | |||
126 | it.it_interval.tv_sec = 0; | ||
127 | it.it_interval.tv_usec = 0; | ||
128 | |||
129 | fail = true; | ||
130 | |||
131 | ATF_REQUIRE(signal(SIGALRM, sighandler) != SIG_ERR); | ||
132 | ATF_REQUIRE(setitimer(ITIMER_REAL, &it, NULL) == 0); | ||
133 | |||
134 | /* | ||
135 | * Although the interaction between | ||
136 | * setitimer(2) and sleep(3) can be | ||
137 | * unspecified, it is assumed that one | ||
138 | * second suspension will be enough for | ||
139 | * the timer to fire. | ||
140 | */ | ||
141 | (void)sleep(1); | ||
142 | |||
143 | if (fail != false) | ||
144 | atf_tc_fail("timer did not fire"); | ||
145 | } | ||
146 | |||
147 | ATF_TC(setitimer_err); | ||
148 | ATF_TC_HEAD(setitimer_err, tc) | ||
149 | { | ||
150 | atf_tc_set_md_var(tc, "descr", "Test errors from setitimer(2)" | ||
151 | " (PR standards/44927)"); | ||
152 | } | ||
153 | |||
154 | ATF_TC_BODY(setitimer_err, tc) | ||
155 | { | ||
156 | struct itimerval it, ot; | ||
157 | |||
158 | errno = 0; | ||
159 | ATF_REQUIRE_ERRNO(EINVAL, setitimer(-1, &it, &ot) == -1); | ||
160 | |||
161 | errno = 0; | ||
162 | ATF_REQUIRE_ERRNO(EINVAL, setitimer(INT_MAX, &it, &ot) == -1); | ||
163 | |||
164 | errno = 0; | ||
165 | ATF_REQUIRE_ERRNO(EFAULT, setitimer(ITIMER_REAL,(void*)-1, &ot) == -1); | ||
166 | } | ||
167 | |||
168 | ATF_TC(setitimer_old); | ||
169 | ATF_TC_HEAD(setitimer_old, tc) | ||
170 | { | ||
171 | atf_tc_set_md_var(tc, "descr", "Test old values from setitimer(2)"); | ||
172 | } | ||
173 | |||
174 | ATF_TC_BODY(setitimer_old, tc) | ||
175 | { | ||
176 | struct itimerval it, ot; | ||
177 | |||
178 | /* | ||
179 | * Make two calls; the second one should store the old | ||
180 | * timer value which should be the same as that set in | ||
181 | * the first call, or slightly less due to time passing | ||
182 | * between the two calls. | ||
183 | */ | ||
184 | it.it_value.tv_sec = 4; | ||
185 | it.it_value.tv_usec = 999999; | ||
186 | |||
187 | it.it_interval.tv_sec = 0; | ||
188 | it.it_interval.tv_usec = 0; | ||
189 | |||
190 | ATF_REQUIRE(setitimer(ITIMER_REAL, &it, &ot) == 0); | ||
191 | |||
192 | it.it_value.tv_sec = 2; | ||
193 | it.it_value.tv_usec = 1; | ||
194 | |||
195 | it.it_interval.tv_sec = 0; | ||
196 | it.it_interval.tv_usec = 0; | ||
197 | |||
198 | ATF_REQUIRE(setitimer(ITIMER_REAL, &it, &ot) == 0); | ||
199 | |||
200 | /* Check seconds only as microseconds may have decremented */ | ||
201 | if (ot.it_value.tv_sec != 4) | ||
202 | atf_tc_fail("setitimer(2) did not store old values"); | ||
203 | } | ||
204 | |||
205 | ATF_TP_ADD_TCS(tp) | ||
206 | { | ||
207 | |||
208 | ATF_TP_ADD_TC(tp, getitimer_empty); | ||
209 | ATF_TP_ADD_TC(tp, getitimer_err); | ||
210 | ATF_TP_ADD_TC(tp, setitimer_basic); | ||
211 | ATF_TP_ADD_TC(tp, setitimer_err); | ||
212 | ATF_TP_ADD_TC(tp, setitimer_old); | ||
213 | |||
214 | return atf_no_error(); | ||
215 | } | ||
diff --git a/src/regress/lib/libc/sys/t_getlogin.c b/src/regress/lib/libc/sys/t_getlogin.c deleted file mode 100644 index b4f06fdee6..0000000000 --- a/src/regress/lib/libc/sys/t_getlogin.c +++ /dev/null | |||
@@ -1,238 +0,0 @@ | |||
1 | /* $OpenBSD: t_getlogin.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_getlogin.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/wait.h> | ||
36 | |||
37 | #include "atf-c.h" | ||
38 | #include <errno.h> | ||
39 | #include <stdlib.h> | ||
40 | #include <string.h> | ||
41 | #include <limits.h> | ||
42 | #include <unistd.h> | ||
43 | |||
44 | ATF_TC(getlogin_r_err); | ||
45 | ATF_TC_HEAD(getlogin_r_err, tc) | ||
46 | { | ||
47 | atf_tc_set_md_var(tc, "descr", "Test errors from getlogin_r(2)"); | ||
48 | } | ||
49 | |||
50 | ATF_TC_BODY(getlogin_r_err, tc) | ||
51 | { | ||
52 | char small[0]; | ||
53 | |||
54 | ATF_REQUIRE(getlogin_r(small, sizeof(small)) == ERANGE); | ||
55 | } | ||
56 | |||
57 | ATF_TC(getlogin_same); | ||
58 | ATF_TC_HEAD(getlogin_same, tc) | ||
59 | { | ||
60 | atf_tc_set_md_var(tc, "descr", "getlogin(2) vs. getlogin_r(2)"); | ||
61 | } | ||
62 | |||
63 | ATF_TC_BODY(getlogin_same, tc) | ||
64 | { | ||
65 | char buf[LOGIN_NAME_MAX]; | ||
66 | char *str; | ||
67 | |||
68 | str = getlogin(); | ||
69 | |||
70 | if (str == NULL) | ||
71 | return; | ||
72 | |||
73 | ATF_REQUIRE(getlogin_r(buf, sizeof(buf)) == 0); | ||
74 | |||
75 | if (strcmp(str, buf) != 0) | ||
76 | atf_tc_fail("getlogin(2) and getlogin_r(2) differ"); | ||
77 | } | ||
78 | |||
79 | ATF_TC(setlogin_basic); | ||
80 | ATF_TC_HEAD(setlogin_basic, tc) | ||
81 | { | ||
82 | atf_tc_set_md_var(tc, "descr", "Test that setlogin(2) works"); | ||
83 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
84 | } | ||
85 | |||
86 | ATF_TC_BODY(setlogin_basic, tc) | ||
87 | { | ||
88 | char *name; | ||
89 | pid_t pid; | ||
90 | int sta; | ||
91 | |||
92 | pid = fork(); | ||
93 | ATF_REQUIRE(pid >= 0); | ||
94 | |||
95 | if (pid == 0) { | ||
96 | |||
97 | (void)setsid(); | ||
98 | |||
99 | if (setlogin("foobar") != 0) | ||
100 | _exit(EXIT_FAILURE); | ||
101 | |||
102 | name = getlogin(); | ||
103 | |||
104 | if (name == NULL) | ||
105 | _exit(EXIT_FAILURE); | ||
106 | |||
107 | if (strcmp(name, "foobar") != 0) | ||
108 | _exit(EXIT_FAILURE); | ||
109 | |||
110 | _exit(EXIT_SUCCESS); | ||
111 | } | ||
112 | |||
113 | (void)wait(&sta); | ||
114 | |||
115 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
116 | atf_tc_fail("setlogin(2) failed to set login name"); | ||
117 | } | ||
118 | |||
119 | ATF_TC(setlogin_err); | ||
120 | ATF_TC_HEAD(setlogin_err, tc) | ||
121 | { | ||
122 | atf_tc_set_md_var(tc, "descr", "Test errors from setlogin(2)"); | ||
123 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
124 | } | ||
125 | |||
126 | ATF_TC_BODY(setlogin_err, tc) | ||
127 | { | ||
128 | char buf[LOGIN_NAME_MAX + 1]; | ||
129 | char *name; | ||
130 | pid_t pid; | ||
131 | int sta; | ||
132 | |||
133 | pid = fork(); | ||
134 | ATF_REQUIRE(pid >= 0); | ||
135 | |||
136 | (void)memset(buf, 'x', sizeof(buf)); | ||
137 | |||
138 | if (pid == 0) { | ||
139 | |||
140 | (void)setsid(); | ||
141 | |||
142 | errno = 0; | ||
143 | |||
144 | if (setlogin(buf) != -1) | ||
145 | _exit(EINVAL); | ||
146 | |||
147 | if (errno != EINVAL) | ||
148 | _exit(EINVAL); | ||
149 | |||
150 | errno = 0; | ||
151 | |||
152 | if (setlogin((void *)-1) != -1) | ||
153 | _exit(EFAULT); | ||
154 | |||
155 | if (errno != EFAULT) | ||
156 | _exit(EFAULT); | ||
157 | |||
158 | name = getlogin(); | ||
159 | |||
160 | if (name == NULL) | ||
161 | _exit(EXIT_FAILURE); | ||
162 | |||
163 | if (strcmp(name, "foobar") == 0) | ||
164 | _exit(EXIT_FAILURE); | ||
165 | |||
166 | _exit(EXIT_SUCCESS); | ||
167 | } | ||
168 | |||
169 | (void)wait(&sta); | ||
170 | |||
171 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) { | ||
172 | |||
173 | if (WEXITSTATUS(sta) == EFAULT) | ||
174 | atf_tc_fail("expected EFAULT, but the call succeeded"); | ||
175 | |||
176 | if (WEXITSTATUS(sta) == EINVAL) | ||
177 | atf_tc_fail("expected EINVAL, but the call succeeded"); | ||
178 | |||
179 | atf_tc_fail("setlogin(2) failed, but login name was set"); | ||
180 | } | ||
181 | } | ||
182 | |||
183 | ATF_TC(setlogin_perm); | ||
184 | ATF_TC_HEAD(setlogin_perm, tc) | ||
185 | { | ||
186 | atf_tc_set_md_var(tc, "descr", "Test setlogin(2) as normal user"); | ||
187 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
188 | } | ||
189 | |||
190 | ATF_TC_BODY(setlogin_perm, tc) | ||
191 | { | ||
192 | char *name; | ||
193 | pid_t pid; | ||
194 | int sta; | ||
195 | |||
196 | pid = fork(); | ||
197 | ATF_REQUIRE(pid >= 0); | ||
198 | |||
199 | if (pid == 0) { | ||
200 | |||
201 | (void)setsid(); | ||
202 | |||
203 | errno = 0; | ||
204 | |||
205 | if (setlogin("foobar") != -1) | ||
206 | _exit(EXIT_FAILURE); | ||
207 | |||
208 | if (errno != EPERM) | ||
209 | _exit(EXIT_FAILURE); | ||
210 | |||
211 | name = getlogin(); | ||
212 | |||
213 | if (name == NULL) | ||
214 | _exit(EXIT_FAILURE); | ||
215 | |||
216 | if (strcmp(name, "foobar") == 0) | ||
217 | _exit(EXIT_FAILURE); | ||
218 | |||
219 | _exit(EXIT_SUCCESS); | ||
220 | } | ||
221 | |||
222 | (void)wait(&sta); | ||
223 | |||
224 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
225 | atf_tc_fail("login name was set as an unprivileged user"); | ||
226 | } | ||
227 | |||
228 | ATF_TP_ADD_TCS(tp) | ||
229 | { | ||
230 | |||
231 | ATF_TP_ADD_TC(tp, getlogin_r_err); | ||
232 | ATF_TP_ADD_TC(tp, getlogin_same); | ||
233 | ATF_TP_ADD_TC(tp, setlogin_basic); | ||
234 | ATF_TP_ADD_TC(tp, setlogin_err); | ||
235 | ATF_TP_ADD_TC(tp, setlogin_perm); | ||
236 | |||
237 | return atf_no_error(); | ||
238 | } | ||
diff --git a/src/regress/lib/libc/sys/t_getpid.c b/src/regress/lib/libc/sys/t_getpid.c deleted file mode 100644 index db9f8c8746..0000000000 --- a/src/regress/lib/libc/sys/t_getpid.c +++ /dev/null | |||
@@ -1,135 +0,0 @@ | |||
1 | /* $OpenBSD: t_getpid.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_getpid.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/wait.h> | ||
36 | |||
37 | #include <stdlib.h> | ||
38 | #include <pthread.h> | ||
39 | #include <unistd.h> | ||
40 | |||
41 | #include "atf-c.h" | ||
42 | |||
43 | static int maxiter = 10; | ||
44 | static void *threadfunc(void *); | ||
45 | |||
46 | static void * | ||
47 | threadfunc(void *arg) | ||
48 | { | ||
49 | *(pid_t *)arg = getpid(); | ||
50 | |||
51 | return NULL; | ||
52 | } | ||
53 | |||
54 | ATF_TC(getpid_process); | ||
55 | ATF_TC_HEAD(getpid_process, tc) | ||
56 | { | ||
57 | atf_tc_set_md_var(tc, "descr", "Test getpid(2) with processes"); | ||
58 | } | ||
59 | |||
60 | ATF_TC_BODY(getpid_process, tc) | ||
61 | { | ||
62 | pid_t ppid, fpid, cpid, tpid, wpid; | ||
63 | int i, sta; | ||
64 | |||
65 | for (i = 0; i < maxiter; i++) { | ||
66 | |||
67 | tpid = getpid(); | ||
68 | fpid = fork(); | ||
69 | |||
70 | ATF_REQUIRE(fpid >= 0); | ||
71 | |||
72 | if (fpid == 0) { | ||
73 | |||
74 | cpid = getpid(); | ||
75 | ppid = getppid(); | ||
76 | |||
77 | if (tpid != ppid) | ||
78 | _exit(EXIT_FAILURE); | ||
79 | |||
80 | if (cpid == ppid) | ||
81 | _exit(EXIT_FAILURE); | ||
82 | |||
83 | if (tpid == fpid) | ||
84 | _exit(EXIT_FAILURE); | ||
85 | |||
86 | _exit(EXIT_SUCCESS); | ||
87 | } | ||
88 | |||
89 | wpid = wait(&sta); | ||
90 | |||
91 | if (wpid != fpid) | ||
92 | atf_tc_fail("PID mismatch"); | ||
93 | |||
94 | ATF_REQUIRE(WIFEXITED(sta) != 0); | ||
95 | |||
96 | if (WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
97 | atf_tc_fail("PID mismatch"); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | ATF_TC(getpid_thread); | ||
102 | ATF_TC_HEAD(getpid_thread, tc) | ||
103 | { | ||
104 | atf_tc_set_md_var(tc, "descr", "Test getpid(2) with threads"); | ||
105 | } | ||
106 | |||
107 | ATF_TC_BODY(getpid_thread, tc) | ||
108 | { | ||
109 | pid_t pid, tpid; | ||
110 | pthread_t tid; | ||
111 | int i, rv; | ||
112 | |||
113 | for (i = 0; i < maxiter; i++) { | ||
114 | |||
115 | pid = getpid(); | ||
116 | |||
117 | rv = pthread_create(&tid, NULL, threadfunc, &tpid); | ||
118 | ATF_REQUIRE(rv == 0); | ||
119 | |||
120 | rv = pthread_join(tid, NULL); | ||
121 | ATF_REQUIRE(rv == 0); | ||
122 | |||
123 | if (pid != tpid) | ||
124 | atf_tc_fail("Unequal PIDs"); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | ATF_TP_ADD_TCS(tp) | ||
129 | { | ||
130 | |||
131 | ATF_TP_ADD_TC(tp, getpid_process); | ||
132 | ATF_TP_ADD_TC(tp, getpid_thread); | ||
133 | |||
134 | return atf_no_error(); | ||
135 | } | ||
diff --git a/src/regress/lib/libc/sys/t_getrusage.c b/src/regress/lib/libc/sys/t_getrusage.c deleted file mode 100644 index 1a9e3d139c..0000000000 --- a/src/regress/lib/libc/sys/t_getrusage.c +++ /dev/null | |||
@@ -1,286 +0,0 @@ | |||
1 | /* $OpenBSD: t_getrusage.c,v 1.3 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_getrusage.c,v 1.8 2018/05/09 08:45:03 mrg Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/resource.h> | ||
36 | #include <sys/time.h> | ||
37 | |||
38 | #include "atf-c.h" | ||
39 | #include <stdio.h> | ||
40 | #include <errno.h> | ||
41 | #include <limits.h> | ||
42 | #include <signal.h> | ||
43 | #include <stdint.h> | ||
44 | #include <stdlib.h> | ||
45 | #include <string.h> | ||
46 | #include <fcntl.h> | ||
47 | #include <sys/socket.h> | ||
48 | #include <netinet/in.h> | ||
49 | |||
50 | static void work(void); | ||
51 | static void sighandler(int); | ||
52 | |||
53 | static const size_t maxiter = 2000; | ||
54 | |||
55 | static void | ||
56 | sighandler(int signo __unused) | ||
57 | { | ||
58 | /* Nothing. */ | ||
59 | } | ||
60 | |||
61 | static void | ||
62 | work(void) | ||
63 | { | ||
64 | size_t n = UINT16_MAX * 10; | ||
65 | |||
66 | while (n > 0) { | ||
67 | #ifdef __or1k__ | ||
68 | asm volatile("l.nop"); /* Do something. */ | ||
69 | #elif defined(__ia64__) | ||
70 | asm volatile("nop 0"); /* Do something. */ | ||
71 | #else | ||
72 | asm volatile("nop"); /* Do something. */ | ||
73 | #endif | ||
74 | n--; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | ATF_TC(getrusage_err); | ||
79 | ATF_TC_HEAD(getrusage_err, tc) | ||
80 | { | ||
81 | atf_tc_set_md_var(tc, "descr", "Test error conditions"); | ||
82 | } | ||
83 | |||
84 | ATF_TC_BODY(getrusage_err, tc) | ||
85 | { | ||
86 | struct rusage ru; | ||
87 | |||
88 | errno = 0; | ||
89 | |||
90 | ATF_REQUIRE(getrusage(INT_MAX, &ru) != 0); | ||
91 | ATF_REQUIRE(errno == EINVAL); | ||
92 | |||
93 | errno = 0; | ||
94 | |||
95 | ATF_REQUIRE(getrusage(RUSAGE_SELF, (void *)0) != 0); | ||
96 | ATF_REQUIRE(errno == EFAULT); | ||
97 | } | ||
98 | |||
99 | ATF_TC(getrusage_sig); | ||
100 | ATF_TC_HEAD(getrusage_sig, tc) | ||
101 | { | ||
102 | atf_tc_set_md_var(tc, "descr", "Test signal count with getrusage(2)"); | ||
103 | } | ||
104 | |||
105 | ATF_TC_BODY(getrusage_sig, tc) | ||
106 | { | ||
107 | struct rusage ru; | ||
108 | const long n = 5; | ||
109 | int i; | ||
110 | |||
111 | /* | ||
112 | * Test that signals are recorded. | ||
113 | */ | ||
114 | ATF_REQUIRE(signal(SIGUSR1, sighandler) != SIG_ERR); | ||
115 | |||
116 | for (i = 0; i < n; i++) | ||
117 | ATF_REQUIRE(raise(SIGUSR1) == 0); | ||
118 | |||
119 | (void)memset(&ru, 0, sizeof(struct rusage)); | ||
120 | ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0); | ||
121 | |||
122 | if (n != ru.ru_nsignals) | ||
123 | atf_tc_fail("getrusage(2) did not record signals"); | ||
124 | } | ||
125 | |||
126 | ATF_TC(getrusage_maxrss); | ||
127 | ATF_TC_HEAD(getrusage_maxrss, tc) | ||
128 | { | ||
129 | atf_tc_set_md_var(tc, "descr", "Test maxrss growing with getrusage(2)"); | ||
130 | } | ||
131 | |||
132 | ATF_TC_BODY(getrusage_maxrss, tc) | ||
133 | { | ||
134 | struct rusage ru; | ||
135 | long maxrss; | ||
136 | int i, fd; | ||
137 | |||
138 | #define DUMP_FILE "dump" | ||
139 | |||
140 | fd = open(DUMP_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0222); | ||
141 | ATF_REQUIRE(fd != -1); | ||
142 | |||
143 | (void)memset(&ru, 0, sizeof(struct rusage)); | ||
144 | ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0); | ||
145 | maxrss = ru.ru_maxrss; | ||
146 | |||
147 | #define CHUNK (1024 * 1024) | ||
148 | for (i = 0; i < 40; i++) { | ||
149 | void *p = malloc(CHUNK); | ||
150 | memset(p, 0, CHUNK); | ||
151 | write(fd, p, CHUNK); | ||
152 | } | ||
153 | close(fd); | ||
154 | unlink(DUMP_FILE); | ||
155 | |||
156 | ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0); | ||
157 | ATF_REQUIRE_MSG(maxrss < ru.ru_maxrss, | ||
158 | "maxrss: %ld, ru.ru_maxrss: %ld", maxrss, ru.ru_maxrss); | ||
159 | } | ||
160 | |||
161 | ATF_TC(getrusage_msgsnd); | ||
162 | ATF_TC_HEAD(getrusage_msgsnd, tc) | ||
163 | { | ||
164 | atf_tc_set_md_var(tc, "descr", "Test send growing with getrusage(2)"); | ||
165 | } | ||
166 | |||
167 | ATF_TC_BODY(getrusage_msgsnd, tc) | ||
168 | { | ||
169 | struct rusage ru; | ||
170 | long msgsnd; | ||
171 | int s, i; | ||
172 | struct sockaddr_in sin; | ||
173 | |||
174 | ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0); | ||
175 | msgsnd = ru.ru_msgsnd; | ||
176 | |||
177 | s = socket(AF_INET, SOCK_DGRAM, 0); | ||
178 | ATF_REQUIRE(s >= 0); | ||
179 | memset(&sin, 0, sizeof(sin)); | ||
180 | sin.sin_family = AF_INET; | ||
181 | sin.sin_len = sizeof(sin); | ||
182 | sin.sin_addr.s_addr = ntohl(INADDR_LOOPBACK); | ||
183 | sin.sin_port = htons(3333); | ||
184 | |||
185 | for (i = 0; i < 10; i++) | ||
186 | ATF_REQUIRE(sendto(s, &sin, sizeof(sin), 0, (void *)&sin, | ||
187 | (socklen_t)sizeof(sin)) != -1); | ||
188 | |||
189 | ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0); | ||
190 | ATF_REQUIRE(msgsnd + 10 == ru.ru_msgsnd); | ||
191 | close(s); | ||
192 | } | ||
193 | |||
194 | ATF_TC(getrusage_utime_back); | ||
195 | ATF_TC_HEAD(getrusage_utime_back, tc) | ||
196 | { | ||
197 | atf_tc_set_md_var(tc, "descr", "Test bogus values from getrusage(2)"); | ||
198 | } | ||
199 | |||
200 | ATF_TC_BODY(getrusage_utime_back, tc) | ||
201 | { | ||
202 | struct rusage ru1, ru2; | ||
203 | size_t i; | ||
204 | |||
205 | /* | ||
206 | * Test that two consecutive calls are sane. | ||
207 | */ | ||
208 | #ifndef __OpenBSD__ | ||
209 | atf_tc_expect_fail("PR kern/30115"); | ||
210 | #endif | ||
211 | |||
212 | for (i = 0; i < maxiter; i++) { | ||
213 | |||
214 | (void)memset(&ru1, 0, sizeof(struct rusage)); | ||
215 | (void)memset(&ru2, 0, sizeof(struct rusage)); | ||
216 | |||
217 | work(); | ||
218 | |||
219 | ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru1) == 0); | ||
220 | |||
221 | work(); | ||
222 | |||
223 | ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru2) == 0); | ||
224 | |||
225 | if (timercmp(&ru2.ru_utime, &ru1.ru_utime, <) != 0) | ||
226 | atf_tc_fail("user time went backwards"); | ||
227 | } | ||
228 | |||
229 | #ifndef __OpenBSD__ | ||
230 | atf_tc_fail("anticipated error did not occur"); | ||
231 | #endif | ||
232 | } | ||
233 | |||
234 | ATF_TC(getrusage_utime_zero); | ||
235 | ATF_TC_HEAD(getrusage_utime_zero, tc) | ||
236 | { | ||
237 | atf_tc_set_md_var(tc, "descr", "Test zero utime from getrusage(2)"); | ||
238 | } | ||
239 | |||
240 | ATF_TC_BODY(getrusage_utime_zero, tc) | ||
241 | { | ||
242 | struct rusage ru; | ||
243 | size_t i; | ||
244 | |||
245 | /* | ||
246 | * Test that getrusage(2) does not return | ||
247 | * zero user time for the calling process. | ||
248 | * | ||
249 | * See also (duplicate) PR port-amd64/41734. | ||
250 | */ | ||
251 | #ifndef __OpenBSD__ | ||
252 | atf_tc_expect_fail("PR kern/30115"); | ||
253 | #endif | ||
254 | |||
255 | for (i = 0; i < maxiter; i++) { | ||
256 | |||
257 | work(); | ||
258 | #ifdef __OpenBSD__ | ||
259 | } | ||
260 | #endif | ||
261 | |||
262 | (void)memset(&ru, 0, sizeof(struct rusage)); | ||
263 | |||
264 | ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0); | ||
265 | |||
266 | if (ru.ru_utime.tv_sec == 0 && ru.ru_utime.tv_usec == 0) | ||
267 | atf_tc_fail("zero user time from getrusage(2)"); | ||
268 | #ifndef __OpenBSD__ | ||
269 | } | ||
270 | |||
271 | atf_tc_fail("anticipated error did not occur"); | ||
272 | #endif | ||
273 | } | ||
274 | |||
275 | ATF_TP_ADD_TCS(tp) | ||
276 | { | ||
277 | |||
278 | ATF_TP_ADD_TC(tp, getrusage_err); | ||
279 | ATF_TP_ADD_TC(tp, getrusage_sig); | ||
280 | ATF_TP_ADD_TC(tp, getrusage_maxrss); | ||
281 | ATF_TP_ADD_TC(tp, getrusage_msgsnd); | ||
282 | ATF_TP_ADD_TC(tp, getrusage_utime_back); | ||
283 | ATF_TP_ADD_TC(tp, getrusage_utime_zero); | ||
284 | |||
285 | return atf_no_error(); | ||
286 | } | ||
diff --git a/src/regress/lib/libc/sys/t_getsid.c b/src/regress/lib/libc/sys/t_getsid.c deleted file mode 100644 index 9bd82cd2ba..0000000000 --- a/src/regress/lib/libc/sys/t_getsid.c +++ /dev/null | |||
@@ -1,120 +0,0 @@ | |||
1 | /* $OpenBSD: t_getsid.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_getsid.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/wait.h> | ||
36 | |||
37 | #include <errno.h> | ||
38 | #include <stdlib.h> | ||
39 | #include <unistd.h> | ||
40 | |||
41 | #include "atf-c.h" | ||
42 | |||
43 | ATF_TC(getsid_current); | ||
44 | ATF_TC_HEAD(getsid_current, tc) | ||
45 | { | ||
46 | atf_tc_set_md_var(tc, "descr", "Test getsid(0)"); | ||
47 | } | ||
48 | |||
49 | ATF_TC_BODY(getsid_current, tc) | ||
50 | { | ||
51 | pid_t sid; | ||
52 | |||
53 | sid = getsid(0); | ||
54 | ATF_REQUIRE(sid != -1); | ||
55 | |||
56 | if (sid != getsid(getpid())) | ||
57 | atf_tc_fail("getsid(0) did not match the calling process"); | ||
58 | } | ||
59 | |||
60 | ATF_TC(getsid_err); | ||
61 | ATF_TC_HEAD(getsid_err, tc) | ||
62 | { | ||
63 | atf_tc_set_md_var(tc, "descr", "Test error conditions in getsid(2)"); | ||
64 | } | ||
65 | |||
66 | ATF_TC_BODY(getsid_err, tc) | ||
67 | { | ||
68 | |||
69 | errno = 0; | ||
70 | |||
71 | ATF_REQUIRE(getsid(-1) == -1); | ||
72 | ATF_REQUIRE(errno == ESRCH); | ||
73 | } | ||
74 | |||
75 | ATF_TC(getsid_process); | ||
76 | ATF_TC_HEAD(getsid_process, tc) | ||
77 | { | ||
78 | atf_tc_set_md_var(tc, "descr", "Test getsid(2) with processes"); | ||
79 | } | ||
80 | |||
81 | ATF_TC_BODY(getsid_process, tc) | ||
82 | { | ||
83 | pid_t csid, pid, ppid, sid; | ||
84 | int sta; | ||
85 | |||
86 | sid = getsid(0); | ||
87 | pid = fork(); | ||
88 | |||
89 | ATF_REQUIRE(pid >= 0); | ||
90 | ATF_REQUIRE(sid != -1); | ||
91 | |||
92 | if (pid == 0) { | ||
93 | |||
94 | csid = getsid(0); | ||
95 | ppid = getppid(); | ||
96 | |||
97 | if (sid != csid) | ||
98 | _exit(EXIT_FAILURE); | ||
99 | |||
100 | if (getsid(ppid) != csid) | ||
101 | _exit(EXIT_FAILURE); | ||
102 | |||
103 | _exit(EXIT_SUCCESS); | ||
104 | } | ||
105 | |||
106 | (void)wait(&sta); | ||
107 | |||
108 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
109 | atf_tc_fail("invalid session ID"); | ||
110 | } | ||
111 | |||
112 | ATF_TP_ADD_TCS(tp) | ||
113 | { | ||
114 | |||
115 | ATF_TP_ADD_TC(tp, getsid_current); | ||
116 | ATF_TP_ADD_TC(tp, getsid_err); | ||
117 | ATF_TP_ADD_TC(tp, getsid_process); | ||
118 | |||
119 | return atf_no_error(); | ||
120 | } | ||
diff --git a/src/regress/lib/libc/sys/t_getsockname.c b/src/regress/lib/libc/sys/t_getsockname.c deleted file mode 100644 index 8b0accd7a0..0000000000 --- a/src/regress/lib/libc/sys/t_getsockname.c +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | /* $OpenBSD: t_getsockname.c,v 1.1.1.1 2019/11/19 19:57:03 bluhm Exp $ */ | ||
2 | /* $NetBSD: t_getsockname.c,v 1.1 2016/07/30 11:03:54 njoly Exp $ */ | ||
3 | /* | ||
4 | * Copyright (c) 2016 The NetBSD Foundation, Inc. | ||
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 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND | ||
17 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
18 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
20 | * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY | ||
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
23 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
25 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #include "macros.h" | ||
31 | |||
32 | #include <sys/socket.h> | ||
33 | #include <sys/un.h> | ||
34 | |||
35 | #include <string.h> | ||
36 | #include <unistd.h> | ||
37 | |||
38 | #include "atf-c.h" | ||
39 | |||
40 | ATF_TC(getsockname_unix); | ||
41 | |||
42 | ATF_TC_HEAD(getsockname_unix, tc) | ||
43 | { | ||
44 | atf_tc_set_md_var(tc, "descr", "Checks getsockname with UNIX domain"); | ||
45 | } | ||
46 | |||
47 | ATF_TC_BODY(getsockname_unix, tc) | ||
48 | { | ||
49 | const char *path = "sock.unix"; | ||
50 | int sd; | ||
51 | socklen_t len; | ||
52 | struct sockaddr_un sun; | ||
53 | |||
54 | sd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
55 | ATF_REQUIRE(sd != -1); | ||
56 | |||
57 | len = sizeof(sun); | ||
58 | memset(&sun, 0, sizeof(sun)); | ||
59 | ATF_REQUIRE(getsockname(sd, (struct sockaddr *)&sun, &len) != -1); | ||
60 | ATF_CHECK(sun.sun_family == AF_UNIX); | ||
61 | ATF_CHECK(strcmp(sun.sun_path, "") == 0); | ||
62 | |||
63 | len = sizeof(sun); | ||
64 | memset(&sun, 0, sizeof(sun)); | ||
65 | sun.sun_family = AF_UNIX; | ||
66 | strcpy(sun.sun_path, path); | ||
67 | ATF_REQUIRE(bind(sd, (struct sockaddr *)&sun, len) != -1); | ||
68 | |||
69 | len = sizeof(sun); | ||
70 | memset(&sun, 0, sizeof(sun)); | ||
71 | ATF_REQUIRE(getsockname(sd, (struct sockaddr *)&sun, &len) != -1); | ||
72 | ATF_CHECK(sun.sun_family == AF_UNIX); | ||
73 | ATF_CHECK(strcmp(sun.sun_path, path) == 0); | ||
74 | |||
75 | ATF_REQUIRE(close(sd) != -1); | ||
76 | ATF_REQUIRE(unlink(path) != -1); | ||
77 | } | ||
78 | |||
79 | ATF_TP_ADD_TCS(tp) | ||
80 | { | ||
81 | |||
82 | ATF_TP_ADD_TC(tp, getsockname_unix); | ||
83 | |||
84 | return atf_no_error(); | ||
85 | } | ||
diff --git a/src/regress/lib/libc/sys/t_gettimeofday.c b/src/regress/lib/libc/sys/t_gettimeofday.c deleted file mode 100644 index 7a7d319be1..0000000000 --- a/src/regress/lib/libc/sys/t_gettimeofday.c +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | /* $OpenBSD: t_gettimeofday.c,v 1.5 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_gettimeofday.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/time.h> | ||
36 | |||
37 | #include "atf-c.h" | ||
38 | #include <errno.h> | ||
39 | #include <signal.h> | ||
40 | #include <string.h> | ||
41 | |||
42 | #ifdef __OpenBSD__ | ||
43 | static void sighandler(int); | ||
44 | |||
45 | static void | ||
46 | sighandler(int signo) | ||
47 | { | ||
48 | _exit(0); | ||
49 | } | ||
50 | #endif | ||
51 | |||
52 | ATF_TC(gettimeofday_err); | ||
53 | ATF_TC_HEAD(gettimeofday_err, tc) | ||
54 | { | ||
55 | atf_tc_set_md_var(tc, "descr", "Test errors from gettimeofday(2)"); | ||
56 | } | ||
57 | |||
58 | ATF_TC_BODY(gettimeofday_err, tc) | ||
59 | { | ||
60 | |||
61 | #ifdef __OpenBSD__ | ||
62 | /* | ||
63 | * With userland timecounters we will generate SIGSEGV instead | ||
64 | * of failing with errno set to EFAULT. POSIX explicitly | ||
65 | * allows this behaviour. | ||
66 | */ | ||
67 | ATF_REQUIRE(signal(SIGSEGV, sighandler) != SIG_ERR); | ||
68 | /* On sparc64 dereferencing -1 causes SIGBUS */ | ||
69 | ATF_REQUIRE(signal(SIGBUS, sighandler) != SIG_ERR); | ||
70 | #endif | ||
71 | errno = 0; | ||
72 | |||
73 | ATF_REQUIRE_ERRNO(EFAULT, gettimeofday((void *)-1, NULL) != 0); | ||
74 | } | ||
75 | |||
76 | ATF_TC(gettimeofday_mono); | ||
77 | ATF_TC_HEAD(gettimeofday_mono, tc) | ||
78 | { | ||
79 | atf_tc_set_md_var(tc, "descr", "Test monotonicity of gettimeofday(2)"); | ||
80 | } | ||
81 | |||
82 | ATF_TC_BODY(gettimeofday_mono, tc) | ||
83 | { | ||
84 | static const size_t maxiter = 100; | ||
85 | struct timeval tv1, tv2; | ||
86 | size_t i; | ||
87 | |||
88 | for (i = 0; i < maxiter; i++) { | ||
89 | |||
90 | (void)memset(&tv1, 0, sizeof(struct timeval)); | ||
91 | (void)memset(&tv2, 0, sizeof(struct timeval)); | ||
92 | |||
93 | ATF_REQUIRE(gettimeofday(&tv1, NULL) == 0); | ||
94 | ATF_REQUIRE(gettimeofday(&tv2, NULL) == 0); | ||
95 | |||
96 | if (timercmp(&tv2, &tv1, <) != 0) | ||
97 | atf_tc_fail("time went backwards"); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | ATF_TP_ADD_TCS(tp) | ||
102 | { | ||
103 | |||
104 | ATF_TP_ADD_TC(tp, gettimeofday_err); | ||
105 | ATF_TP_ADD_TC(tp, gettimeofday_mono); | ||
106 | |||
107 | return atf_no_error(); | ||
108 | } | ||
diff --git a/src/regress/lib/libc/sys/t_kevent.c b/src/regress/lib/libc/sys/t_kevent.c deleted file mode 100644 index 003d7b8a5d..0000000000 --- a/src/regress/lib/libc/sys/t_kevent.c +++ /dev/null | |||
@@ -1,232 +0,0 @@ | |||
1 | /* $OpenBSD: t_kevent.c,v 1.3 2023/04/19 12:58:15 jsg Exp $ */ | ||
2 | /* $NetBSD: t_kevent.c,v 1.9 2020/10/31 01:08:32 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundatiom | ||
9 | * by Christos Zoulas. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | #include "macros.h" | ||
33 | |||
34 | #include <sys/types.h> | ||
35 | #include <sys/event.h> | ||
36 | |||
37 | #include "atf-c.h" | ||
38 | #include <errno.h> | ||
39 | #include <time.h> | ||
40 | #include <stdio.h> | ||
41 | #include <stdlib.h> | ||
42 | #include <string.h> | ||
43 | #include <unistd.h> | ||
44 | #include <fcntl.h> | ||
45 | #include <err.h> | ||
46 | #ifndef __OpenBSD__ | ||
47 | #include <sys/drvctlio.h> | ||
48 | #endif | ||
49 | #include <sys/time.h> | ||
50 | #include <sys/socket.h> | ||
51 | #include <sys/wait.h> | ||
52 | |||
53 | ATF_TC(kevent_zerotimer); | ||
54 | ATF_TC_HEAD(kevent_zerotimer, tc) | ||
55 | { | ||
56 | atf_tc_set_md_var(tc, "descr", "Checks that kevent with a 0 timer " | ||
57 | "does not crash the system (PR lib/45618)"); | ||
58 | } | ||
59 | |||
60 | ATF_TC_BODY(kevent_zerotimer, tc) | ||
61 | { | ||
62 | struct kevent ev; | ||
63 | int kq; | ||
64 | |||
65 | ATF_REQUIRE((kq = kqueue()) != -1); | ||
66 | EV_SET(&ev, 1, EVFILT_TIMER, EV_ADD|EV_ENABLE, 0, 1, 0); | ||
67 | ATF_REQUIRE(kevent(kq, &ev, 1, NULL, 0, NULL) != -1); | ||
68 | ATF_REQUIRE(kevent(kq, NULL, 0, &ev, 1, NULL) == 1); | ||
69 | } | ||
70 | |||
71 | ATF_TC(kqueue_desc_passing); | ||
72 | ATF_TC_HEAD(kqueue_desc_passing, tc) | ||
73 | { | ||
74 | atf_tc_set_md_var(tc, "descr", "Checks that passing a kqueue to " | ||
75 | "another process does not crash the kernel (PR 46463)"); | ||
76 | } | ||
77 | |||
78 | ATF_TC_BODY(kqueue_desc_passing, tc) | ||
79 | { | ||
80 | pid_t child; | ||
81 | int s[2], storage, status, kq; | ||
82 | struct cmsghdr *msg; | ||
83 | struct iovec iov; | ||
84 | struct msghdr m; | ||
85 | struct kevent ev; | ||
86 | |||
87 | ATF_REQUIRE((kq = kqueue()) != -1); | ||
88 | |||
89 | // atf_tc_skip("crashes kernel (PR kern/46463)"); | ||
90 | |||
91 | ATF_REQUIRE(socketpair(AF_LOCAL, SOCK_STREAM, 0, s) != -1); | ||
92 | msg = malloc(CMSG_SPACE(sizeof(int))); | ||
93 | m.msg_iov = &iov; | ||
94 | m.msg_iovlen = 1; | ||
95 | m.msg_name = NULL; | ||
96 | m.msg_namelen = 0; | ||
97 | m.msg_control = msg; | ||
98 | m.msg_controllen = CMSG_SPACE(sizeof(int)); | ||
99 | |||
100 | child = fork(); | ||
101 | if (child == 0) { | ||
102 | #ifdef __OpenBSD__ | ||
103 | sleep(1); | ||
104 | exit(0); | ||
105 | #endif | ||
106 | close(s[0]); | ||
107 | |||
108 | iov.iov_base = &storage; | ||
109 | iov.iov_len = sizeof(int); | ||
110 | m.msg_iov = &iov; | ||
111 | m.msg_iovlen = 1; | ||
112 | |||
113 | if (recvmsg(s[1], &m, 0) == -1) | ||
114 | err(1, "child: could not recvmsg"); | ||
115 | |||
116 | kq = *(int *)CMSG_DATA(msg); | ||
117 | printf("child (pid %d): received kq fd %d\n", getpid(), kq); | ||
118 | exit(0); | ||
119 | } | ||
120 | |||
121 | close(s[1]); | ||
122 | |||
123 | iov.iov_base = &storage; | ||
124 | iov.iov_len = sizeof(int); | ||
125 | |||
126 | msg->cmsg_level = SOL_SOCKET; | ||
127 | msg->cmsg_type = SCM_RIGHTS; | ||
128 | msg->cmsg_len = CMSG_LEN(sizeof(int)); | ||
129 | |||
130 | *(int *)CMSG_DATA(msg) = kq; | ||
131 | |||
132 | EV_SET(&ev, 1, EVFILT_TIMER, EV_ADD|EV_ENABLE, 0, 1, 0); | ||
133 | ATF_CHECK(kevent(kq, &ev, 1, NULL, 0, NULL) != -1); | ||
134 | |||
135 | printf("parent (pid %d): sending kq fd %d\n", getpid(), kq); | ||
136 | if (sendmsg(s[0], &m, 0) == -1) { | ||
137 | #ifdef __OpenBSD__ | ||
138 | ATF_REQUIRE_EQ_MSG(errno, EINVAL, "errno is %d", errno); | ||
139 | #else | ||
140 | ATF_REQUIRE_EQ_MSG(errno, EBADF, "errno is %d", errno); | ||
141 | atf_tc_skip("PR kern/46523"); | ||
142 | #endif | ||
143 | } | ||
144 | |||
145 | close(kq); | ||
146 | |||
147 | waitpid(child, &status, 0); | ||
148 | ATF_CHECK(WIFEXITED(status) && WEXITSTATUS(status)==0); | ||
149 | } | ||
150 | |||
151 | #ifndef __OpenBSD__ | ||
152 | ATF_TC(kqueue_unsupported_fd); | ||
153 | ATF_TC_HEAD(kqueue_unsupported_fd, tc) | ||
154 | { | ||
155 | atf_tc_set_md_var(tc, "descr", "Checks that watching an fd whose" | ||
156 | " type is not supported does not crash the kernel"); | ||
157 | } | ||
158 | |||
159 | ATF_TC_BODY(kqueue_unsupported_fd, tc) | ||
160 | { | ||
161 | /* mqueue and semaphore use fnullop_kqueue also */ | ||
162 | int fd, kq; | ||
163 | struct kevent ev; | ||
164 | |||
165 | fd = open(DRVCTLDEV, O_RDONLY); | ||
166 | if (fd == -1) { | ||
167 | switch (errno) { | ||
168 | case ENOENT: | ||
169 | case ENXIO: | ||
170 | atf_tc_skip("no " DRVCTLDEV " available for testing"); | ||
171 | break; | ||
172 | } | ||
173 | } | ||
174 | ATF_REQUIRE(fd != -1); | ||
175 | ATF_REQUIRE((kq = kqueue()) != -1); | ||
176 | |||
177 | EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, | ||
178 | NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK| | ||
179 | NOTE_RENAME|NOTE_REVOKE, 0, 0); | ||
180 | |||
181 | ATF_REQUIRE(kevent(kq, &ev, 1, NULL, 0, NULL) == -1); | ||
182 | ATF_REQUIRE_ERRNO(EOPNOTSUPP, true); | ||
183 | |||
184 | (void)close(fd); | ||
185 | (void)close(kq); | ||
186 | } | ||
187 | |||
188 | ATF_TC(kqueue_EVFILT_USER); | ||
189 | ATF_TC_HEAD(kqueue_EVFILT_USER, tc) | ||
190 | { | ||
191 | atf_tc_set_md_var(tc, "descr", "Checks usability of EVFILT_USER"); | ||
192 | } | ||
193 | |||
194 | ATF_TC_BODY(kqueue_EVFILT_USER, tc) | ||
195 | { | ||
196 | /* mqueue and semaphore use fnullop_kqueue also */ | ||
197 | int kq; | ||
198 | struct kevent ev, rev; | ||
199 | |||
200 | ATF_REQUIRE((kq = kqueue()) != -1); | ||
201 | |||
202 | EV_SET(&ev, 666, EVFILT_USER, EV_ADD | EV_ENABLE, 0, 0, 0); | ||
203 | ATF_REQUIRE(kevent(kq, &ev, 1, NULL, 0, NULL) == 0); | ||
204 | EV_SET(&ev, 666, EVFILT_USER, 0, NOTE_FFCOPY | NOTE_TRIGGER | 8, 0, 0); | ||
205 | ATF_REQUIRE(kevent(kq, &ev, 1, NULL, 0, NULL) == 0); | ||
206 | const struct timespec timeout = { | ||
207 | .tv_sec = 1, | ||
208 | .tv_nsec = 0, | ||
209 | }; | ||
210 | |||
211 | ATF_REQUIRE(kevent(kq, NULL, 0, &rev, 1, &timeout) == 1); | ||
212 | ATF_REQUIRE(rev.ident == 666); | ||
213 | ATF_REQUIRE(rev.filter == EVFILT_USER); | ||
214 | ATF_REQUIRE(rev.fflags == 8); | ||
215 | (void)close(kq); | ||
216 | } | ||
217 | #endif | ||
218 | |||
219 | |||
220 | |||
221 | ATF_TP_ADD_TCS(tp) | ||
222 | { | ||
223 | |||
224 | ATF_TP_ADD_TC(tp, kevent_zerotimer); | ||
225 | ATF_TP_ADD_TC(tp, kqueue_desc_passing); | ||
226 | #ifndef __OpenBSD__ | ||
227 | ATF_TP_ADD_TC(tp, kqueue_unsupported_fd); | ||
228 | ATF_TP_ADD_TC(tp, kqueue_EVFILT_USER); | ||
229 | #endif | ||
230 | |||
231 | return atf_no_error(); | ||
232 | } | ||
diff --git a/src/regress/lib/libc/sys/t_kill.c b/src/regress/lib/libc/sys/t_kill.c deleted file mode 100644 index 0c55dfa41b..0000000000 --- a/src/regress/lib/libc/sys/t_kill.c +++ /dev/null | |||
@@ -1,313 +0,0 @@ | |||
1 | /* $OpenBSD: t_kill.c,v 1.4 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_kill.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/wait.h> | ||
36 | |||
37 | #include <errno.h> | ||
38 | #include <limits.h> | ||
39 | #include <pwd.h> | ||
40 | #include <signal.h> | ||
41 | #include <stdlib.h> | ||
42 | #include <unistd.h> | ||
43 | |||
44 | #include "atf-c.h" | ||
45 | |||
46 | ATF_TC(kill_basic); | ||
47 | ATF_TC_HEAD(kill_basic, tc) | ||
48 | { | ||
49 | atf_tc_set_md_var(tc, "descr", "Test that kill(2) works"); | ||
50 | } | ||
51 | |||
52 | ATF_TC_BODY(kill_basic, tc) | ||
53 | { | ||
54 | const int sig[] = { SIGHUP, SIGINT, SIGKILL, SIGTERM }; | ||
55 | pid_t pid; | ||
56 | size_t i; | ||
57 | int sta; | ||
58 | |||
59 | for (i = 0; i < __arraycount(sig); i++) { | ||
60 | |||
61 | pid = fork(); | ||
62 | ATF_REQUIRE(pid >= 0); | ||
63 | |||
64 | switch (pid) { | ||
65 | |||
66 | case 0: | ||
67 | pause(); | ||
68 | break; | ||
69 | |||
70 | default: | ||
71 | ATF_REQUIRE(kill(pid, sig[i]) == 0); | ||
72 | } | ||
73 | |||
74 | (void)wait(&sta); | ||
75 | |||
76 | if (WIFSIGNALED(sta) == 0 || WTERMSIG(sta) != sig[i]) | ||
77 | atf_tc_fail("kill(2) failed to kill child"); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | ATF_TC(kill_err); | ||
82 | ATF_TC_HEAD(kill_err, tc) | ||
83 | { | ||
84 | atf_tc_set_md_var(tc, "descr", "Test error conditions of kill(2)"); | ||
85 | } | ||
86 | |||
87 | ATF_TC_BODY(kill_err, tc) | ||
88 | { | ||
89 | int rv, sta; | ||
90 | pid_t pid; | ||
91 | |||
92 | pid = fork(); | ||
93 | ATF_REQUIRE(pid >= 0); | ||
94 | |||
95 | if (pid == 0) { | ||
96 | |||
97 | errno = 0; | ||
98 | rv = kill(getpid(), -1); | ||
99 | |||
100 | if (rv == 0 || errno != EINVAL) | ||
101 | _exit(EINVAL); | ||
102 | |||
103 | errno = 0; | ||
104 | rv = kill(INT_MAX, SIGUSR1); | ||
105 | |||
106 | if (rv == 0 || errno != ESRCH) | ||
107 | _exit(ESRCH); | ||
108 | |||
109 | _exit(EXIT_SUCCESS); | ||
110 | } | ||
111 | |||
112 | (void)wait(&sta); | ||
113 | |||
114 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) { | ||
115 | |||
116 | if (WEXITSTATUS(sta) == EINVAL) | ||
117 | atf_tc_fail("expected EINVAL, but kill(2) succeeded"); | ||
118 | |||
119 | if (WEXITSTATUS(sta) == ESRCH) | ||
120 | atf_tc_fail("expected ESRCH, but kill(2) succeeded"); | ||
121 | |||
122 | atf_tc_fail("unknown error from kill(2)"); | ||
123 | } | ||
124 | } | ||
125 | |||
126 | ATF_TC(kill_perm); | ||
127 | ATF_TC_HEAD(kill_perm, tc) | ||
128 | { | ||
129 | atf_tc_set_md_var(tc, "descr", "Test kill(2) permissions"); | ||
130 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
131 | } | ||
132 | |||
133 | ATF_TC_BODY(kill_perm, tc) | ||
134 | { | ||
135 | struct passwd *pw; | ||
136 | pid_t cpid, ppid; | ||
137 | uid_t cuid = 0; | ||
138 | uid_t puid = 0; | ||
139 | int sta; | ||
140 | |||
141 | /* | ||
142 | * Test that kill(2) fails when called | ||
143 | * for a PID owned by another user. | ||
144 | */ | ||
145 | pw = getpwnam("operator"); | ||
146 | |||
147 | if (pw != NULL) | ||
148 | cuid = pw->pw_uid; | ||
149 | |||
150 | pw = getpwnam("nobody"); | ||
151 | |||
152 | if (pw != NULL) | ||
153 | puid = pw->pw_uid; | ||
154 | |||
155 | if (cuid == 0 || puid == 0 || cuid == puid) | ||
156 | atf_tc_fail("getpwnam(3) failed"); | ||
157 | |||
158 | ppid = fork(); | ||
159 | |||
160 | if (ppid < 0) | ||
161 | _exit(EXIT_FAILURE); | ||
162 | |||
163 | if (ppid == 0) { | ||
164 | |||
165 | cpid = fork(); | ||
166 | |||
167 | if (cpid < 0) | ||
168 | _exit(EXIT_FAILURE); | ||
169 | |||
170 | if (cpid == 0) { | ||
171 | |||
172 | if (setuid(cuid) < 0) | ||
173 | _exit(EXIT_FAILURE); | ||
174 | else { | ||
175 | (void)sleep(1); | ||
176 | } | ||
177 | |||
178 | _exit(EXIT_SUCCESS); | ||
179 | } | ||
180 | |||
181 | /* | ||
182 | * Try to kill the child after having | ||
183 | * set the real and effective UID. | ||
184 | */ | ||
185 | if (setuid(puid) != 0) | ||
186 | _exit(EXIT_FAILURE); | ||
187 | |||
188 | errno = 0; | ||
189 | |||
190 | if (kill(cpid, SIGKILL) == 0) | ||
191 | _exit(EPERM); | ||
192 | |||
193 | if (errno != EPERM) | ||
194 | _exit(EPERM); | ||
195 | |||
196 | (void)waitpid(cpid, &sta, 0); | ||
197 | |||
198 | _exit(EXIT_SUCCESS); | ||
199 | } | ||
200 | |||
201 | (void)waitpid(ppid, &sta, 0); | ||
202 | |||
203 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) == EPERM) | ||
204 | atf_tc_fail("killed a process of another user"); | ||
205 | |||
206 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
207 | atf_tc_fail("unknown error from kill(2)"); | ||
208 | } | ||
209 | |||
210 | ATF_TC(kill_pgrp_neg); | ||
211 | ATF_TC_HEAD(kill_pgrp_neg, tc) | ||
212 | { | ||
213 | atf_tc_set_md_var(tc, "descr", "Test kill(2) with process group, #2"); | ||
214 | } | ||
215 | |||
216 | ATF_TC_BODY(kill_pgrp_neg, tc) | ||
217 | { | ||
218 | const int maxiter = 3; | ||
219 | pid_t cpid, ppid; | ||
220 | int i, sta; | ||
221 | |||
222 | ppid = fork(); | ||
223 | ATF_REQUIRE(ppid >= 0); | ||
224 | |||
225 | if (ppid == 0) { | ||
226 | |||
227 | ATF_REQUIRE(setpgid(0, 0) == 0); | ||
228 | |||
229 | for (i = 0; i < maxiter; i++) { | ||
230 | |||
231 | cpid = fork(); | ||
232 | ATF_REQUIRE(cpid >= 0); | ||
233 | |||
234 | if (cpid == 0) | ||
235 | pause(); | ||
236 | } | ||
237 | |||
238 | /* | ||
239 | * Test the variant of killpg(3); if the process number | ||
240 | * is negative but not -1, the signal should be sent to | ||
241 | * all processes whose process group ID is equal to the | ||
242 | * absolute value of the process number. | ||
243 | */ | ||
244 | ATF_REQUIRE(kill(-getpgrp(), SIGKILL) == 0); | ||
245 | |||
246 | (void)sleep(1); | ||
247 | |||
248 | _exit(EXIT_SUCCESS); | ||
249 | } | ||
250 | |||
251 | (void)waitpid(ppid, &sta, 0); | ||
252 | |||
253 | if (WIFSIGNALED(sta) == 0 || WTERMSIG(sta) != SIGKILL) | ||
254 | atf_tc_fail("failed to kill(2) a process group"); | ||
255 | } | ||
256 | |||
257 | ATF_TC(kill_pgrp_zero); | ||
258 | ATF_TC_HEAD(kill_pgrp_zero, tc) | ||
259 | { | ||
260 | atf_tc_set_md_var(tc, "descr", "Test kill(2) with process group, #1"); | ||
261 | } | ||
262 | |||
263 | ATF_TC_BODY(kill_pgrp_zero, tc) | ||
264 | { | ||
265 | const int maxiter = 3; | ||
266 | pid_t cpid, ppid; | ||
267 | int i, sta; | ||
268 | |||
269 | ppid = fork(); | ||
270 | ATF_REQUIRE(ppid >= 0); | ||
271 | |||
272 | if (ppid == 0) { | ||
273 | |||
274 | ATF_REQUIRE(setpgid(0, 0) == 0); | ||
275 | |||
276 | for (i = 0; i < maxiter; i++) { | ||
277 | |||
278 | cpid = fork(); | ||
279 | ATF_REQUIRE(cpid >= 0); | ||
280 | |||
281 | if (cpid == 0) | ||
282 | pause(); | ||
283 | } | ||
284 | |||
285 | /* | ||
286 | * If the supplied process number is zero, | ||
287 | * the signal should be sent to all processes | ||
288 | * under the current process group. | ||
289 | */ | ||
290 | ATF_REQUIRE(kill(0, SIGKILL) == 0); | ||
291 | |||
292 | (void)sleep(1); | ||
293 | |||
294 | _exit(EXIT_SUCCESS); | ||
295 | } | ||
296 | |||
297 | (void)waitpid(ppid, &sta, 0); | ||
298 | |||
299 | if (WIFSIGNALED(sta) == 0 || WTERMSIG(sta) != SIGKILL) | ||
300 | atf_tc_fail("failed to kill(2) a process group"); | ||
301 | } | ||
302 | |||
303 | ATF_TP_ADD_TCS(tp) | ||
304 | { | ||
305 | |||
306 | ATF_TP_ADD_TC(tp, kill_basic); | ||
307 | ATF_TP_ADD_TC(tp, kill_err); | ||
308 | ATF_TP_ADD_TC(tp, kill_perm); | ||
309 | ATF_TP_ADD_TC(tp, kill_pgrp_neg); | ||
310 | ATF_TP_ADD_TC(tp, kill_pgrp_zero); | ||
311 | |||
312 | return atf_no_error(); | ||
313 | } | ||
diff --git a/src/regress/lib/libc/sys/t_link.c b/src/regress/lib/libc/sys/t_link.c deleted file mode 100644 index 12dbd8b595..0000000000 --- a/src/regress/lib/libc/sys/t_link.c +++ /dev/null | |||
@@ -1,230 +0,0 @@ | |||
1 | /* $OpenBSD: t_link.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_link.c,v 1.3 2017/01/13 20:42:36 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/stat.h> | ||
36 | |||
37 | #include "atf-c.h" | ||
38 | #include <errno.h> | ||
39 | #include <fcntl.h> | ||
40 | #include <limits.h> | ||
41 | #include <stdio.h> | ||
42 | #include <string.h> | ||
43 | #include <unistd.h> | ||
44 | |||
45 | static const char *getpath(void); | ||
46 | static char path[] = "link"; | ||
47 | static const char *pathl; | ||
48 | |||
49 | static const char * | ||
50 | getpath(void) | ||
51 | { | ||
52 | static char buf[LINE_MAX]; | ||
53 | |||
54 | (void)memset(buf, '\0', sizeof(buf)); | ||
55 | |||
56 | if (getcwd(buf, sizeof(buf)) == NULL) | ||
57 | return NULL; | ||
58 | |||
59 | (void)strlcat(buf, path, sizeof(buf)); | ||
60 | (void)strlcat(buf, ".link", sizeof(buf)); | ||
61 | |||
62 | return buf; | ||
63 | } | ||
64 | |||
65 | ATF_TC_WITH_CLEANUP(link_count); | ||
66 | ATF_TC_HEAD(link_count, tc) | ||
67 | { | ||
68 | atf_tc_set_md_var(tc, "descr", "link(2) counts are incremented?"); | ||
69 | } | ||
70 | |||
71 | ATF_TC_BODY(link_count, tc) | ||
72 | { | ||
73 | struct stat sa, sb; | ||
74 | int fd; | ||
75 | |||
76 | (void)memset(&sa, 0, sizeof(struct stat)); | ||
77 | (void)memset(&sb, 0, sizeof(struct stat)); | ||
78 | |||
79 | pathl = getpath(); | ||
80 | fd = open(path, O_RDWR | O_CREAT, 0600); | ||
81 | |||
82 | ATF_REQUIRE(fd >= 0); | ||
83 | ATF_REQUIRE(pathl != NULL); | ||
84 | |||
85 | ATF_REQUIRE(stat(path, &sa) == 0); | ||
86 | ATF_REQUIRE(link(path, pathl) == 0); | ||
87 | ATF_REQUIRE(stat(path, &sb) == 0); | ||
88 | |||
89 | if (sa.st_nlink != sb.st_nlink - 1) | ||
90 | atf_tc_fail("incorrect link(2) count"); | ||
91 | |||
92 | ATF_REQUIRE(close(fd) == 0); | ||
93 | ATF_REQUIRE(unlink(path) == 0); | ||
94 | ATF_REQUIRE(unlink(pathl) == 0); | ||
95 | } | ||
96 | |||
97 | ATF_TC_CLEANUP(link_count, tc) | ||
98 | { | ||
99 | (void)unlink(path); | ||
100 | (void)unlink(pathl); | ||
101 | } | ||
102 | |||
103 | ATF_TC_WITH_CLEANUP(link_err); | ||
104 | ATF_TC_HEAD(link_err, tc) | ||
105 | { | ||
106 | atf_tc_set_md_var(tc, "descr", "Test error conditions of link(2)"); | ||
107 | } | ||
108 | |||
109 | ATF_TC_BODY(link_err, tc) | ||
110 | { | ||
111 | char buf[PATH_MAX + 1]; | ||
112 | int fd; | ||
113 | |||
114 | (void)memset(buf, 'x', sizeof(buf)); | ||
115 | |||
116 | pathl = getpath(); | ||
117 | fd = open(path, O_RDWR | O_CREAT, 0600); | ||
118 | |||
119 | ATF_REQUIRE(fd >= 0); | ||
120 | ATF_REQUIRE(pathl != NULL); | ||
121 | |||
122 | errno = 0; | ||
123 | ATF_REQUIRE(link(path, pathl) == 0); | ||
124 | ATF_REQUIRE_ERRNO(EEXIST, link(path, pathl) == -1); | ||
125 | |||
126 | errno = 0; | ||
127 | ATF_REQUIRE_ERRNO(ENAMETOOLONG, link(buf, "xxx") == -1); | ||
128 | |||
129 | errno = 0; | ||
130 | ATF_REQUIRE_ERRNO(ENOENT, link(path, "/d/c/b/a") == -1); | ||
131 | |||
132 | errno = 0; | ||
133 | ATF_REQUIRE_ERRNO(ENOENT, link("/a/b/c/d", path) == -1); | ||
134 | |||
135 | errno = 0; | ||
136 | ATF_REQUIRE_ERRNO(ENOENT, link("/a/b/c/d", "/d/c/b/a") == -1); | ||
137 | |||
138 | errno = 0; | ||
139 | ATF_REQUIRE_ERRNO(EFAULT, link(path, (const char *)-1) == -1); | ||
140 | |||
141 | errno = 0; | ||
142 | ATF_REQUIRE_ERRNO(EFAULT, link((const char *)-1, "xxx") == -1); | ||
143 | |||
144 | ATF_REQUIRE(close(fd) == 0); | ||
145 | ATF_REQUIRE(unlink(path) == 0); | ||
146 | ATF_REQUIRE(unlink(pathl) == 0); | ||
147 | } | ||
148 | |||
149 | ATF_TC_CLEANUP(link_err, tc) | ||
150 | { | ||
151 | (void)unlink(path); | ||
152 | (void)unlink(pathl); | ||
153 | } | ||
154 | |||
155 | ATF_TC(link_perm); | ||
156 | ATF_TC_HEAD(link_perm, tc) | ||
157 | { | ||
158 | atf_tc_set_md_var(tc, "descr", "Test permissions with link(2)"); | ||
159 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
160 | } | ||
161 | |||
162 | ATF_TC_BODY(link_perm, tc) | ||
163 | { | ||
164 | int rv; | ||
165 | |||
166 | errno = 0; | ||
167 | rv = link("/root", "/root.link"); | ||
168 | ATF_REQUIRE_MSG(rv == -1 && (errno == EACCES || errno == EPERM), | ||
169 | "link to a directory did not fail with EPERM or EACCESS; link() " | ||
170 | "returned %d, errno %d", rv, errno); | ||
171 | |||
172 | errno = 0; | ||
173 | ATF_REQUIRE_ERRNO(EACCES, | ||
174 | link("/root/.profile", "/root/.profile.link") == -1); | ||
175 | } | ||
176 | |||
177 | ATF_TC_WITH_CLEANUP(link_stat); | ||
178 | ATF_TC_HEAD(link_stat, tc) | ||
179 | { | ||
180 | atf_tc_set_md_var(tc, "descr", "Check stat(2) of a linked file"); | ||
181 | } | ||
182 | |||
183 | ATF_TC_BODY(link_stat, tc) | ||
184 | { | ||
185 | struct stat sa, sb; | ||
186 | int fd; | ||
187 | |||
188 | (void)memset(&sa, 0, sizeof(struct stat)); | ||
189 | (void)memset(&sb, 0, sizeof(struct stat)); | ||
190 | |||
191 | pathl = getpath(); | ||
192 | fd = open(path, O_RDWR | O_CREAT, 0600); | ||
193 | |||
194 | ATF_REQUIRE(fd >= 0); | ||
195 | ATF_REQUIRE(pathl != NULL); | ||
196 | |||
197 | ATF_REQUIRE(link(path, pathl) == 0); | ||
198 | ATF_REQUIRE(stat(path, &sa) == 0); | ||
199 | ATF_REQUIRE(lstat(pathl, &sb) == 0); | ||
200 | |||
201 | if (sa.st_uid != sb.st_uid) | ||
202 | atf_tc_fail("unequal UIDs"); | ||
203 | |||
204 | if (sa.st_mode != sb.st_mode) | ||
205 | atf_tc_fail("unequal modes"); | ||
206 | |||
207 | if (sa.st_ino != sb.st_ino) | ||
208 | atf_tc_fail("unequal inodes"); | ||
209 | |||
210 | ATF_REQUIRE(close(fd) == 0); | ||
211 | ATF_REQUIRE(unlink(path) == 0); | ||
212 | ATF_REQUIRE(unlink(pathl) == 0); | ||
213 | } | ||
214 | |||
215 | ATF_TC_CLEANUP(link_stat, tc) | ||
216 | { | ||
217 | (void)unlink(path); | ||
218 | (void)unlink(pathl); | ||
219 | } | ||
220 | |||
221 | ATF_TP_ADD_TCS(tp) | ||
222 | { | ||
223 | |||
224 | ATF_TP_ADD_TC(tp, link_count); | ||
225 | ATF_TP_ADD_TC(tp, link_err); | ||
226 | ATF_TP_ADD_TC(tp, link_perm); | ||
227 | ATF_TP_ADD_TC(tp, link_stat); | ||
228 | |||
229 | return atf_no_error(); | ||
230 | } | ||
diff --git a/src/regress/lib/libc/sys/t_listen.c b/src/regress/lib/libc/sys/t_listen.c deleted file mode 100644 index da5b287cdf..0000000000 --- a/src/regress/lib/libc/sys/t_listen.c +++ /dev/null | |||
@@ -1,139 +0,0 @@ | |||
1 | /* $OpenBSD: t_listen.c,v 1.1.1.1 2019/11/19 19:57:03 bluhm Exp $ */ | ||
2 | /* $NetBSD: t_listen.c,v 1.6 2019/07/09 16:24:01 maya Exp $ */ | ||
3 | /* | ||
4 | * Copyright (c) 2007 The NetBSD Foundation, Inc. | ||
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 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND | ||
17 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
18 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
20 | * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY | ||
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
23 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
25 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #include "macros.h" | ||
31 | |||
32 | #include <sys/socket.h> | ||
33 | #include "atf-c.h" | ||
34 | #include <err.h> | ||
35 | #include <errno.h> | ||
36 | #include <fcntl.h> | ||
37 | #include <string.h> | ||
38 | #include <unistd.h> | ||
39 | |||
40 | #include <arpa/inet.h> | ||
41 | #include <netinet/in.h> | ||
42 | |||
43 | static const char *path = "listen"; | ||
44 | |||
45 | ATF_TC_WITH_CLEANUP(listen_err); | ||
46 | ATF_TC_HEAD(listen_err, tc) | ||
47 | { | ||
48 | atf_tc_set_md_var(tc, "descr", | ||
49 | "Checks errors from listen(2) (PR standards/46150)"); | ||
50 | } | ||
51 | |||
52 | ATF_TC_BODY(listen_err, tc) | ||
53 | { | ||
54 | static const size_t siz = sizeof(struct sockaddr_in); | ||
55 | struct sockaddr_in sina, sinb; | ||
56 | int fda, fdb, fdc; | ||
57 | |||
58 | (void)memset(&sina, 0, sizeof(struct sockaddr_in)); | ||
59 | (void)memset(&sinb, 0, sizeof(struct sockaddr_in)); | ||
60 | |||
61 | sina.sin_family = AF_INET; | ||
62 | sina.sin_port = htons(31522); | ||
63 | sina.sin_addr.s_addr = inet_addr("127.0.0.1"); | ||
64 | |||
65 | sinb.sin_family = AF_INET; | ||
66 | sinb.sin_port = htons(31522); | ||
67 | sinb.sin_addr.s_addr = inet_addr("127.0.0.1"); | ||
68 | |||
69 | fda = socket(AF_INET, SOCK_STREAM, 0); | ||
70 | fdb = socket(AF_INET, SOCK_STREAM, 0); | ||
71 | fdc = open("listen", O_RDWR | O_CREAT, 0600); | ||
72 | |||
73 | ATF_REQUIRE(fda >= 0 && fdb >= 0 && fdc >= 0); | ||
74 | ATF_REQUIRE_ERRNO(ENOTSOCK, listen(fdc, 1) == -1); | ||
75 | |||
76 | (void)close(fdc); | ||
77 | (void)unlink(path); | ||
78 | |||
79 | ATF_REQUIRE(bind(fda, (struct sockaddr *)&sina, siz) == 0); | ||
80 | ATF_REQUIRE(listen(fda, 1) == 0); | ||
81 | |||
82 | /* | ||
83 | * According to IEEE Std 1003.1-2008: if the socket is | ||
84 | * already connected, the call should fail with EINVAL. | ||
85 | */ | ||
86 | ATF_REQUIRE(connect(fdb, (struct sockaddr *)&sinb, siz) == 0); | ||
87 | ATF_REQUIRE_ERRNO(EINVAL, listen(fdb, 1) == -1); | ||
88 | |||
89 | (void)close(fda); | ||
90 | (void)close(fdb); | ||
91 | |||
92 | ATF_REQUIRE_ERRNO(EBADF, connect(fdb, | ||
93 | (struct sockaddr *)&sinb, siz) == -1); | ||
94 | } | ||
95 | |||
96 | ATF_TC_CLEANUP(listen_err, tc) | ||
97 | { | ||
98 | (void)unlink(path); | ||
99 | } | ||
100 | |||
101 | ATF_TC(listen_low_port); | ||
102 | ATF_TC_HEAD(listen_low_port, tc) | ||
103 | { | ||
104 | atf_tc_set_md_var(tc, "descr", "Does low-port allocation work?"); | ||
105 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
106 | } | ||
107 | |||
108 | ATF_TC_BODY(listen_low_port, tc) | ||
109 | { | ||
110 | int sd, val; | ||
111 | |||
112 | sd = socket(AF_INET, SOCK_STREAM, 0); | ||
113 | ATF_REQUIRE_MSG(sd != -1, "socket failed: %s", strerror(errno)); | ||
114 | |||
115 | val = IP_PORTRANGE_LOW; | ||
116 | if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val, | ||
117 | sizeof(val)) == -1) | ||
118 | atf_tc_fail("setsockopt failed: %s", strerror(errno)); | ||
119 | |||
120 | if (listen(sd, 5) == -1) { | ||
121 | int serrno = errno; | ||
122 | atf_tc_fail("listen failed: %s%s", | ||
123 | strerror(serrno), | ||
124 | serrno != EACCES ? "" : | ||
125 | " (see http://mail-index.netbsd.org/" | ||
126 | "source-changes/2007/12/16/0011.html)"); | ||
127 | } | ||
128 | |||
129 | close(sd); | ||
130 | } | ||
131 | |||
132 | ATF_TP_ADD_TCS(tp) | ||
133 | { | ||
134 | |||
135 | ATF_TP_ADD_TC(tp, listen_err); | ||
136 | ATF_TP_ADD_TC(tp, listen_low_port); | ||
137 | |||
138 | return atf_no_error(); | ||
139 | } | ||
diff --git a/src/regress/lib/libc/sys/t_minherit.c b/src/regress/lib/libc/sys/t_minherit.c deleted file mode 100644 index 578092352c..0000000000 --- a/src/regress/lib/libc/sys/t_minherit.c +++ /dev/null | |||
@@ -1,200 +0,0 @@ | |||
1 | /* $OpenBSD: t_minherit.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_minherit.c,v 1.1 2014/07/18 12:34:52 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2014 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Christos Zoulas | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | #include "macros.h" | ||
33 | |||
34 | #include <sys/mman.h> | ||
35 | #include <sys/sysctl.h> | ||
36 | #include <sys/wait.h> | ||
37 | |||
38 | #include <errno.h> | ||
39 | #include <fcntl.h> | ||
40 | #include <stdlib.h> | ||
41 | #include <string.h> | ||
42 | #include <signal.h> | ||
43 | #include <unistd.h> | ||
44 | |||
45 | #include "atf-c.h" | ||
46 | |||
47 | static long page; | ||
48 | |||
49 | static void * | ||
50 | makemap(int v, int f) { | ||
51 | void *map = mmap(NULL, page, PROT_READ|PROT_WRITE, | ||
52 | MAP_SHARED|MAP_ANON, -1, 0); | ||
53 | ATF_REQUIRE(map != MAP_FAILED); | ||
54 | memset(map, v, page); | ||
55 | if (f != 666) | ||
56 | ATF_REQUIRE(minherit(map, page, f) == 0); | ||
57 | else | ||
58 | ATF_REQUIRE(minherit(map, page, f) == -1); | ||
59 | return map; | ||
60 | } | ||
61 | |||
62 | ATF_TC(minherit_copy); | ||
63 | ATF_TC_HEAD(minherit_copy, tc) | ||
64 | { | ||
65 | atf_tc_set_md_var(tc, "descr", | ||
66 | "Test for MAP_INHERIT_COPY from minherit(2)"); | ||
67 | } | ||
68 | |||
69 | ATF_TC_BODY(minherit_copy, tc) | ||
70 | { | ||
71 | void *map1 = makemap(1, MAP_INHERIT_COPY); | ||
72 | void *map2 = makemap(1, MAP_INHERIT_COPY); | ||
73 | switch (fork()) { | ||
74 | default: | ||
75 | ATF_REQUIRE(wait(NULL) != -1); | ||
76 | ATF_REQUIRE(memcmp(map1, map2, page) == 0); | ||
77 | break; | ||
78 | case -1: | ||
79 | ATF_REQUIRE(0); | ||
80 | break; | ||
81 | case 0: | ||
82 | ATF_REQUIRE(memcmp(map1, map2, page) == 0); | ||
83 | memset(map1, 0, page); | ||
84 | exit(0); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | ATF_TC(minherit_share); | ||
89 | ATF_TC_HEAD(minherit_share, tc) | ||
90 | { | ||
91 | atf_tc_set_md_var(tc, "descr", | ||
92 | "Test for MAP_INHERIT_SHARE from minherit(2)"); | ||
93 | } | ||
94 | |||
95 | ATF_TC_BODY(minherit_share, tc) | ||
96 | { | ||
97 | void *map1 = makemap(1, MAP_INHERIT_SHARE); | ||
98 | void *map2 = makemap(1, MAP_INHERIT_SHARE); | ||
99 | |||
100 | switch (fork()) { | ||
101 | default: | ||
102 | ATF_REQUIRE(wait(NULL) != -1); | ||
103 | memset(map2, 0, page); | ||
104 | ATF_REQUIRE(memcmp(map1, map2, page) == 0); | ||
105 | break; | ||
106 | case -1: | ||
107 | ATF_REQUIRE(0); | ||
108 | break; | ||
109 | case 0: | ||
110 | ATF_REQUIRE(memcmp(map1, map2, page) == 0); | ||
111 | memset(map1, 0, page); | ||
112 | exit(0); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | static void | ||
117 | segv(int n) { | ||
118 | _exit(n); | ||
119 | } | ||
120 | |||
121 | ATF_TC(minherit_none); | ||
122 | ATF_TC_HEAD(minherit_none, tc) | ||
123 | { | ||
124 | atf_tc_set_md_var(tc, "descr", | ||
125 | "Test for MAP_INHERIT_NONE from minherit(2)"); | ||
126 | } | ||
127 | |||
128 | ATF_TC_BODY(minherit_none, tc) | ||
129 | { | ||
130 | void *map1 = makemap(0, MAP_INHERIT_NONE); | ||
131 | int status; | ||
132 | |||
133 | switch (fork()) { | ||
134 | default: | ||
135 | ATF_REQUIRE(wait(&status) != -1); | ||
136 | ATF_REQUIRE(WEXITSTATUS(status) == SIGSEGV); | ||
137 | break; | ||
138 | case -1: | ||
139 | ATF_REQUIRE(0); | ||
140 | break; | ||
141 | case 0: | ||
142 | ATF_REQUIRE(signal(SIGSEGV, segv) != SIG_ERR); | ||
143 | memset(map1, 0, page); | ||
144 | exit(0); | ||
145 | } | ||
146 | } | ||
147 | |||
148 | ATF_TC(minherit_zero); | ||
149 | ATF_TC_HEAD(minherit_zero, tc) | ||
150 | { | ||
151 | atf_tc_set_md_var(tc, "descr", | ||
152 | "Test for MAP_INHERIT_ZERO from minherit(2)"); | ||
153 | } | ||
154 | |||
155 | ATF_TC_BODY(minherit_zero, tc) | ||
156 | { | ||
157 | void *map1 = makemap(1, MAP_INHERIT_ZERO); | ||
158 | void *map2 = makemap(0, MAP_INHERIT_SHARE); | ||
159 | |||
160 | switch (fork()) { | ||
161 | default: | ||
162 | ATF_REQUIRE(wait(NULL) != -1); | ||
163 | memset(map2, 1, page); | ||
164 | ATF_REQUIRE(memcmp(map1, map2, page) == 0); | ||
165 | break; | ||
166 | case -1: | ||
167 | ATF_REQUIRE(0); | ||
168 | break; | ||
169 | case 0: | ||
170 | ATF_REQUIRE(memcmp(map1, map2, page) == 0); | ||
171 | memset(map1, 2, page); | ||
172 | exit(0); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | ATF_TC(minherit_bad); | ||
177 | ATF_TC_HEAD(minherit_bad, tc) | ||
178 | { | ||
179 | atf_tc_set_md_var(tc, "descr", | ||
180 | "Test for bad minherit(2)"); | ||
181 | } | ||
182 | |||
183 | ATF_TC_BODY(minherit_bad, tc) | ||
184 | { | ||
185 | (void)makemap(0, 666); | ||
186 | } | ||
187 | |||
188 | ATF_TP_ADD_TCS(tp) | ||
189 | { | ||
190 | page = sysconf(_SC_PAGESIZE); | ||
191 | ATF_REQUIRE(page >= 0); | ||
192 | |||
193 | ATF_TP_ADD_TC(tp, minherit_copy); | ||
194 | ATF_TP_ADD_TC(tp, minherit_share); | ||
195 | ATF_TP_ADD_TC(tp, minherit_none); | ||
196 | ATF_TP_ADD_TC(tp, minherit_zero); | ||
197 | ATF_TP_ADD_TC(tp, minherit_bad); | ||
198 | |||
199 | return atf_no_error(); | ||
200 | } | ||
diff --git a/src/regress/lib/libc/sys/t_mkdir.c b/src/regress/lib/libc/sys/t_mkdir.c deleted file mode 100644 index 5052bd3988..0000000000 --- a/src/regress/lib/libc/sys/t_mkdir.c +++ /dev/null | |||
@@ -1,208 +0,0 @@ | |||
1 | /* $OpenBSD: t_mkdir.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_mkdir.c,v 1.2 2011/10/15 07:38:31 jruoho Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2008, 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jason R. Thorpe and Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/stat.h> | ||
36 | #include <sys/wait.h> | ||
37 | |||
38 | #include "atf-c.h" | ||
39 | #include <errno.h> | ||
40 | #include <fcntl.h> | ||
41 | #include <limits.h> | ||
42 | #include <pwd.h> | ||
43 | #include <stdio.h> | ||
44 | #include <stdlib.h> | ||
45 | #include <string.h> | ||
46 | #include <unistd.h> | ||
47 | |||
48 | ATF_TC(mkdir_err); | ||
49 | ATF_TC_HEAD(mkdir_err, tc) | ||
50 | { | ||
51 | atf_tc_set_md_var(tc, "descr", "Checks errors from mkdir(2)"); | ||
52 | } | ||
53 | |||
54 | ATF_TC_BODY(mkdir_err, tc) | ||
55 | { | ||
56 | char buf[PATH_MAX + 1]; | ||
57 | int fd; | ||
58 | |||
59 | (void)memset(buf, 'x', sizeof(buf)); | ||
60 | |||
61 | fd = open("/etc", O_RDONLY); | ||
62 | |||
63 | if (fd >= 0) { | ||
64 | |||
65 | (void)close(fd); | ||
66 | |||
67 | errno = 0; | ||
68 | ATF_REQUIRE_ERRNO(EEXIST, mkdir("/etc", 0500) == -1); | ||
69 | } | ||
70 | |||
71 | errno = 0; | ||
72 | ATF_REQUIRE_ERRNO(EFAULT, mkdir((void *)-1, 0500) == -1); | ||
73 | |||
74 | errno = 0; | ||
75 | ATF_REQUIRE_ERRNO(ENAMETOOLONG, mkdir(buf, 0500) == -1); | ||
76 | |||
77 | errno = 0; | ||
78 | ATF_REQUIRE_ERRNO(ENOENT, mkdir("/a/b/c/d/e/f/g/h/i/j/k", 0500) == -1); | ||
79 | } | ||
80 | |||
81 | ATF_TC_WITH_CLEANUP(mkdir_perm); | ||
82 | ATF_TC_HEAD(mkdir_perm, tc) | ||
83 | { | ||
84 | atf_tc_set_md_var(tc, "descr", "Checks permissions with mkdir(2)"); | ||
85 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
86 | } | ||
87 | |||
88 | ATF_TC_BODY(mkdir_perm, tc) | ||
89 | { | ||
90 | errno = 0; | ||
91 | ATF_REQUIRE_ERRNO(EACCES, mkdir("/usr/__nonexistent__", 0500) == -1); | ||
92 | } | ||
93 | |||
94 | ATF_TC_CLEANUP(mkdir_perm, tc) | ||
95 | { | ||
96 | (void)rmdir("/usr/__nonexistent__"); | ||
97 | } | ||
98 | |||
99 | ATF_TC_WITH_CLEANUP(mkdir_mode); | ||
100 | ATF_TC_HEAD(mkdir_mode, tc) | ||
101 | { | ||
102 | atf_tc_set_md_var(tc, "descr", "Test that UIDs and GIDs are right " | ||
103 | "for a directory created with mkdir(2)"); | ||
104 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
105 | } | ||
106 | |||
107 | ATF_TC_BODY(mkdir_mode, tc) | ||
108 | { | ||
109 | static const char *path = "/tmp/mkdir"; | ||
110 | struct stat st_a, st_b; | ||
111 | struct passwd *pw; | ||
112 | pid_t pid; | ||
113 | int sta; | ||
114 | |||
115 | (void)memset(&st_a, 0, sizeof(struct stat)); | ||
116 | (void)memset(&st_b, 0, sizeof(struct stat)); | ||
117 | |||
118 | pw = getpwnam("nobody"); | ||
119 | |||
120 | ATF_REQUIRE(pw != NULL); | ||
121 | ATF_REQUIRE(stat("/tmp", &st_a) == 0); | ||
122 | |||
123 | pid = fork(); | ||
124 | ATF_REQUIRE(pid >= 0); | ||
125 | |||
126 | if (pid == 0) { | ||
127 | |||
128 | if (setuid(pw->pw_uid) != 0) | ||
129 | _exit(EXIT_FAILURE); | ||
130 | |||
131 | if (mkdir(path, 0500) != 0) | ||
132 | _exit(EXIT_FAILURE); | ||
133 | |||
134 | _exit(EXIT_SUCCESS); | ||
135 | } | ||
136 | |||
137 | (void)sleep(1); | ||
138 | (void)wait(&sta); | ||
139 | |||
140 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
141 | atf_tc_fail("failed to create '%s'", path); | ||
142 | |||
143 | ATF_REQUIRE(stat(path, &st_b) == 0); | ||
144 | ATF_REQUIRE(rmdir(path) == 0); | ||
145 | |||
146 | /* | ||
147 | * The directory's owner ID should be set to the | ||
148 | * effective UID, whereas the group ID should be | ||
149 | * set to that of the parent directory. | ||
150 | */ | ||
151 | if (st_b.st_uid != pw->pw_uid) | ||
152 | atf_tc_fail("invalid UID for '%s'", path); | ||
153 | |||
154 | if (st_b.st_gid != st_a.st_gid) | ||
155 | atf_tc_fail("GID did not follow the parent directory"); | ||
156 | } | ||
157 | |||
158 | ATF_TC_CLEANUP(mkdir_mode, tc) | ||
159 | { | ||
160 | (void)rmdir("/tmp/mkdir"); | ||
161 | } | ||
162 | |||
163 | ATF_TC(mkdir_trail); | ||
164 | ATF_TC_HEAD(mkdir_trail, tc) | ||
165 | { | ||
166 | atf_tc_set_md_var(tc, "descr", "Checks mkdir(2) for trailing slashes"); | ||
167 | } | ||
168 | |||
169 | ATF_TC_BODY(mkdir_trail, tc) | ||
170 | { | ||
171 | const char *tests[] = { | ||
172 | /* | ||
173 | * IEEE 1003.1 second ed. 2.2.2.78: | ||
174 | * | ||
175 | * If the pathname refers to a directory, it may also have | ||
176 | * one or more trailing slashes. Multiple successive slashes | ||
177 | * are considered to be the same as one slash. | ||
178 | */ | ||
179 | "dir1/", | ||
180 | "dir2//", | ||
181 | |||
182 | NULL, | ||
183 | }; | ||
184 | |||
185 | const char **test; | ||
186 | |||
187 | for (test = &tests[0]; *test != NULL; ++test) { | ||
188 | |||
189 | (void)printf("Checking \"%s\"\n", *test); | ||
190 | (void)rmdir(*test); | ||
191 | |||
192 | ATF_REQUIRE(mkdir(*test, 0777) == 0); | ||
193 | ATF_REQUIRE(rename(*test, "foo") == 0); | ||
194 | ATF_REQUIRE(rename("foo/", *test) == 0); | ||
195 | ATF_REQUIRE(rmdir(*test) == 0); | ||
196 | } | ||
197 | } | ||
198 | |||
199 | ATF_TP_ADD_TCS(tp) | ||
200 | { | ||
201 | |||
202 | ATF_TP_ADD_TC(tp, mkdir_err); | ||
203 | ATF_TP_ADD_TC(tp, mkdir_perm); | ||
204 | ATF_TP_ADD_TC(tp, mkdir_mode); | ||
205 | ATF_TP_ADD_TC(tp, mkdir_trail); | ||
206 | |||
207 | return atf_no_error(); | ||
208 | } | ||
diff --git a/src/regress/lib/libc/sys/t_mkfifo.c b/src/regress/lib/libc/sys/t_mkfifo.c deleted file mode 100644 index 13cd2d1922..0000000000 --- a/src/regress/lib/libc/sys/t_mkfifo.c +++ /dev/null | |||
@@ -1,306 +0,0 @@ | |||
1 | /* $OpenBSD: t_mkfifo.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_mkfifo.c,v 1.3 2019/06/20 03:31:54 kamil Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/stat.h> | ||
36 | #include <sys/wait.h> | ||
37 | |||
38 | #include "atf-c.h" | ||
39 | #include <errno.h> | ||
40 | #include <fcntl.h> | ||
41 | #include <limits.h> | ||
42 | #include <stdlib.h> | ||
43 | #include <signal.h> | ||
44 | #include <string.h> | ||
45 | #include <unistd.h> | ||
46 | |||
47 | static const char path[] = "fifo"; | ||
48 | static void support(void); | ||
49 | |||
50 | static void | ||
51 | support(void) | ||
52 | { | ||
53 | |||
54 | errno = 0; | ||
55 | |||
56 | if (mkfifo(path, 0600) == 0) { | ||
57 | ATF_REQUIRE(unlink(path) == 0); | ||
58 | return; | ||
59 | } | ||
60 | |||
61 | if (errno == EOPNOTSUPP) | ||
62 | atf_tc_skip("the kernel does not support FIFOs"); | ||
63 | else { | ||
64 | atf_tc_fail("mkfifo(2) failed"); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | ATF_TC_WITH_CLEANUP(mkfifo_block); | ||
69 | ATF_TC_HEAD(mkfifo_block, tc) | ||
70 | { | ||
71 | atf_tc_set_md_var(tc, "descr", "Test that FIFOs block"); | ||
72 | } | ||
73 | |||
74 | ATF_TC_BODY(mkfifo_block, tc) | ||
75 | { | ||
76 | int sta, fd = -1; | ||
77 | pid_t pid; | ||
78 | |||
79 | support(); | ||
80 | |||
81 | ATF_REQUIRE(mkfifo(path, 0600) == 0); | ||
82 | |||
83 | pid = fork(); | ||
84 | ATF_REQUIRE(pid >= 0); | ||
85 | |||
86 | if (pid == 0) { | ||
87 | |||
88 | /* | ||
89 | * If we open the FIFO as read-only (write-only), | ||
90 | * the call should block until another process | ||
91 | * opens the FIFO for writing (reading). | ||
92 | */ | ||
93 | fd = open(path, O_RDONLY); | ||
94 | |||
95 | _exit(EXIT_FAILURE); /* NOTREACHED */ | ||
96 | } | ||
97 | |||
98 | (void)sleep(1); | ||
99 | |||
100 | ATF_REQUIRE(kill(pid, SIGKILL) == 0); | ||
101 | |||
102 | (void)wait(&sta); | ||
103 | |||
104 | if (WIFSIGNALED(sta) == 0 || WTERMSIG(sta) != SIGKILL) | ||
105 | atf_tc_fail("FIFO did not block"); | ||
106 | |||
107 | (void)close(fd); | ||
108 | (void)unlink(path); | ||
109 | } | ||
110 | |||
111 | ATF_TC_CLEANUP(mkfifo_block, tc) | ||
112 | { | ||
113 | (void)unlink(path); | ||
114 | } | ||
115 | |||
116 | ATF_TC_WITH_CLEANUP(mkfifo_err); | ||
117 | ATF_TC_HEAD(mkfifo_err, tc) | ||
118 | { | ||
119 | atf_tc_set_md_var(tc, "descr", "Test erros from mkfifo(2)"); | ||
120 | } | ||
121 | |||
122 | ATF_TC_BODY(mkfifo_err, tc) | ||
123 | { | ||
124 | char buf[PATH_MAX + 1]; | ||
125 | |||
126 | support(); | ||
127 | |||
128 | (void)memset(buf, 'x', sizeof(buf)); | ||
129 | ATF_REQUIRE(mkfifo(path, 0600) == 0); | ||
130 | |||
131 | errno = 0; | ||
132 | ATF_REQUIRE_ERRNO(EFAULT, mkfifo((char *)-1, 0600) == -1); | ||
133 | |||
134 | errno = 0; | ||
135 | ATF_REQUIRE_ERRNO(EEXIST, mkfifo("/etc/passwd", 0600) == -1); | ||
136 | |||
137 | errno = 0; | ||
138 | ATF_REQUIRE_ERRNO(EEXIST, mkfifo(path, 0600) == -1); | ||
139 | |||
140 | errno = 0; | ||
141 | ATF_REQUIRE_ERRNO(ENAMETOOLONG, mkfifo(buf, 0600) == -1); | ||
142 | |||
143 | errno = 0; | ||
144 | ATF_REQUIRE_ERRNO(ENOENT, mkfifo("/a/b/c/d/e/f/g", 0600) == -1); | ||
145 | |||
146 | ATF_REQUIRE(unlink(path) == 0); | ||
147 | } | ||
148 | |||
149 | ATF_TC_CLEANUP(mkfifo_err, tc) | ||
150 | { | ||
151 | (void)unlink(path); | ||
152 | } | ||
153 | |||
154 | ATF_TC_WITH_CLEANUP(mkfifo_nonblock); | ||
155 | ATF_TC_HEAD(mkfifo_nonblock, tc) | ||
156 | { | ||
157 | atf_tc_set_md_var(tc, "descr", "Test O_NONBLOCK with FIFOs"); | ||
158 | } | ||
159 | |||
160 | ATF_TC_BODY(mkfifo_nonblock, tc) | ||
161 | { | ||
162 | int fd, sta; | ||
163 | pid_t pid; | ||
164 | |||
165 | support(); | ||
166 | |||
167 | fd = -1; | ||
168 | ATF_REQUIRE(mkfifo(path, 0600) == 0); | ||
169 | |||
170 | pid = fork(); | ||
171 | ATF_REQUIRE(pid >= 0); | ||
172 | |||
173 | if (pid == 0) { | ||
174 | |||
175 | /* | ||
176 | * If we open the FIFO as O_NONBLOCK, the O_RDONLY | ||
177 | * call should return immediately, whereas the call | ||
178 | * for write-only should fail with ENXIO. | ||
179 | */ | ||
180 | fd = open(path, O_RDONLY | O_NONBLOCK); | ||
181 | |||
182 | if (fd >= 0) | ||
183 | _exit(EXIT_SUCCESS); | ||
184 | |||
185 | (void)pause(); /* NOTREACHED */ | ||
186 | } | ||
187 | |||
188 | (void)sleep(1); | ||
189 | |||
190 | errno = 0; | ||
191 | ATF_REQUIRE_ERRNO(ENXIO, open(path, O_WRONLY | O_NONBLOCK) == -1); | ||
192 | |||
193 | (void)kill(pid, SIGKILL); | ||
194 | (void)wait(&sta); | ||
195 | |||
196 | if (WIFSIGNALED(sta) != 0 || WTERMSIG(sta) == SIGKILL) | ||
197 | atf_tc_fail("FIFO blocked for O_NONBLOCK open(2)"); | ||
198 | |||
199 | (void)close(fd); | ||
200 | (void)unlink(path); | ||
201 | } | ||
202 | |||
203 | ATF_TC_CLEANUP(mkfifo_nonblock, tc) | ||
204 | { | ||
205 | (void)unlink(path); | ||
206 | } | ||
207 | |||
208 | ATF_TC_WITH_CLEANUP(mkfifo_perm); | ||
209 | ATF_TC_HEAD(mkfifo_perm, tc) | ||
210 | { | ||
211 | atf_tc_set_md_var(tc, "descr", "Test permissions with mkfifo(2)"); | ||
212 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
213 | } | ||
214 | |||
215 | ATF_TC_BODY(mkfifo_perm, tc) | ||
216 | { | ||
217 | |||
218 | support(); | ||
219 | |||
220 | errno = 0; | ||
221 | ATF_REQUIRE_ERRNO(EACCES, mkfifo("/root/fifo", 0600) == -1); | ||
222 | |||
223 | ATF_REQUIRE(mkfifo(path, 0600) == 0); | ||
224 | |||
225 | /* | ||
226 | * For some reason this fails with EFTYPE... | ||
227 | */ | ||
228 | errno = 0; | ||
229 | ATF_REQUIRE_ERRNO(EFTYPE, chmod(path, 1777) == -1); | ||
230 | |||
231 | ATF_REQUIRE(unlink(path) == 0); | ||
232 | } | ||
233 | |||
234 | ATF_TC_CLEANUP(mkfifo_perm, tc) | ||
235 | { | ||
236 | (void)unlink(path); | ||
237 | } | ||
238 | |||
239 | ATF_TC_WITH_CLEANUP(mkfifo_stat); | ||
240 | ATF_TC_HEAD(mkfifo_stat, tc) | ||
241 | { | ||
242 | atf_tc_set_md_var(tc, "descr", "Test mkfifo(2) with stat"); | ||
243 | } | ||
244 | |||
245 | ATF_TC_BODY(mkfifo_stat, tc) | ||
246 | { | ||
247 | struct stat st; | ||
248 | |||
249 | support(); | ||
250 | |||
251 | (void)memset(&st, 0, sizeof(struct stat)); | ||
252 | |||
253 | ATF_REQUIRE(mkfifo(path, 0600) == 0); | ||
254 | ATF_REQUIRE(stat(path, &st) == 0); | ||
255 | |||
256 | if (S_ISFIFO(st.st_mode) == 0) | ||
257 | atf_tc_fail("invalid mode from mkfifo(2)"); | ||
258 | |||
259 | ATF_REQUIRE(unlink(path) == 0); | ||
260 | } | ||
261 | |||
262 | ATF_TC_CLEANUP(mkfifo_stat, tc) | ||
263 | { | ||
264 | (void)unlink(path); | ||
265 | } | ||
266 | |||
267 | ATF_TC_WITH_CLEANUP(mknod_s_ififo); | ||
268 | ATF_TC_HEAD(mknod_s_ififo, tc) | ||
269 | { | ||
270 | atf_tc_set_md_var(tc, "descr", "Test mknod(2) with S_IFIFO"); | ||
271 | } | ||
272 | |||
273 | ATF_TC_BODY(mknod_s_ififo, tc) | ||
274 | { | ||
275 | struct stat st; | ||
276 | |||
277 | support(); | ||
278 | |||
279 | (void)memset(&st, 0, sizeof(struct stat)); | ||
280 | |||
281 | ATF_REQUIRE(mknod(path, S_IFIFO | 0600, 0) == 0); | ||
282 | ATF_REQUIRE(stat(path, &st) == 0); | ||
283 | |||
284 | if (S_ISFIFO(st.st_mode) == 0) | ||
285 | atf_tc_fail("invalid mode from mknod(2) with S_IFIFO"); | ||
286 | |||
287 | ATF_REQUIRE(unlink(path) == 0); | ||
288 | } | ||
289 | |||
290 | ATF_TC_CLEANUP(mknod_s_ififo, tc) | ||
291 | { | ||
292 | (void)unlink(path); | ||
293 | } | ||
294 | |||
295 | ATF_TP_ADD_TCS(tp) | ||
296 | { | ||
297 | |||
298 | ATF_TP_ADD_TC(tp, mkfifo_block); | ||
299 | ATF_TP_ADD_TC(tp, mkfifo_err); | ||
300 | ATF_TP_ADD_TC(tp, mkfifo_nonblock); | ||
301 | ATF_TP_ADD_TC(tp, mkfifo_perm); | ||
302 | ATF_TP_ADD_TC(tp, mkfifo_stat); | ||
303 | ATF_TP_ADD_TC(tp, mknod_s_ififo); | ||
304 | |||
305 | return atf_no_error(); | ||
306 | } | ||
diff --git a/src/regress/lib/libc/sys/t_mknod.c b/src/regress/lib/libc/sys/t_mknod.c deleted file mode 100644 index 0c8b54f85f..0000000000 --- a/src/regress/lib/libc/sys/t_mknod.c +++ /dev/null | |||
@@ -1,196 +0,0 @@ | |||
1 | /* $OpenBSD: t_mknod.c,v 1.3 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_mknod.c,v 1.2 2012/03/18 07:00:52 jruoho Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/stat.h> | ||
36 | |||
37 | #include "atf-c.h" | ||
38 | #include <errno.h> | ||
39 | #include <fcntl.h> | ||
40 | #include <limits.h> | ||
41 | #include <paths.h> | ||
42 | #include <stdio.h> | ||
43 | #include <string.h> | ||
44 | #include <unistd.h> | ||
45 | |||
46 | static char path[] = "node"; | ||
47 | |||
48 | ATF_TC_WITH_CLEANUP(mknod_err); | ||
49 | ATF_TC_HEAD(mknod_err, tc) | ||
50 | { | ||
51 | atf_tc_set_md_var(tc, "descr", | ||
52 | "Test error conditions of mknod(2) (PR kern/45111)"); | ||
53 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
54 | } | ||
55 | |||
56 | ATF_TC_BODY(mknod_err, tc) | ||
57 | { | ||
58 | char buf[PATH_MAX + 1]; | ||
59 | |||
60 | (void)memset(buf, 'x', sizeof(buf)); | ||
61 | |||
62 | errno = 0; | ||
63 | ATF_REQUIRE_ERRNO(EINVAL, mknod(path, S_IFCHR, -1) == -1); | ||
64 | |||
65 | errno = 0; | ||
66 | ATF_REQUIRE_ERRNO(ENAMETOOLONG, mknod(buf, S_IFCHR, 0) == -1); | ||
67 | |||
68 | errno = 0; | ||
69 | ATF_REQUIRE_ERRNO(EFAULT, mknod((char *)-1, S_IFCHR, 0) == -1); | ||
70 | |||
71 | errno = 0; | ||
72 | ATF_REQUIRE_ERRNO(ENOENT, mknod("/a/b/c/d/e/f/g", S_IFCHR, 0) == -1); | ||
73 | } | ||
74 | |||
75 | ATF_TC_CLEANUP(mknod_err, tc) | ||
76 | { | ||
77 | (void)unlink(path); | ||
78 | } | ||
79 | |||
80 | ATF_TC_WITH_CLEANUP(mknod_exist); | ||
81 | ATF_TC_HEAD(mknod_exist, tc) | ||
82 | { | ||
83 | atf_tc_set_md_var(tc, "descr", "Test EEXIST from mknod(2)"); | ||
84 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
85 | } | ||
86 | |||
87 | ATF_TC_BODY(mknod_exist, tc) | ||
88 | { | ||
89 | int fd; | ||
90 | |||
91 | fd = open("/etc/passwd", O_RDONLY); | ||
92 | |||
93 | if (fd >= 0) { | ||
94 | |||
95 | (void)close(fd); | ||
96 | |||
97 | errno = 0; | ||
98 | ATF_REQUIRE_ERRNO(EEXIST, | ||
99 | mknod("/etc/passwd", S_IFCHR, 0) == -1); | ||
100 | } | ||
101 | |||
102 | ATF_REQUIRE(mknod(path, S_IFCHR, 0) == 0); | ||
103 | |||
104 | errno = 0; | ||
105 | ATF_REQUIRE_ERRNO(EEXIST, mknod(path, S_IFCHR, 0) == -1); | ||
106 | |||
107 | ATF_REQUIRE(unlink(path) == 0); | ||
108 | } | ||
109 | |||
110 | ATF_TC_CLEANUP(mknod_exist, tc) | ||
111 | { | ||
112 | (void)unlink(path); | ||
113 | } | ||
114 | |||
115 | ATF_TC_WITH_CLEANUP(mknod_perm); | ||
116 | ATF_TC_HEAD(mknod_perm, tc) | ||
117 | { | ||
118 | atf_tc_set_md_var(tc, "descr", "Test permissions of mknod(2)"); | ||
119 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
120 | } | ||
121 | |||
122 | ATF_TC_BODY(mknod_perm, tc) | ||
123 | { | ||
124 | |||
125 | errno = 0; | ||
126 | ATF_REQUIRE_ERRNO(EPERM, mknod(path, S_IFCHR, 0) == -1); | ||
127 | |||
128 | errno = 0; | ||
129 | ATF_REQUIRE_ERRNO(EPERM, mknod(path, S_IFBLK, 0) == -1); | ||
130 | } | ||
131 | |||
132 | ATF_TC_CLEANUP(mknod_perm, tc) | ||
133 | { | ||
134 | (void)unlink(path); | ||
135 | } | ||
136 | |||
137 | ATF_TC_WITH_CLEANUP(mknod_stat); | ||
138 | ATF_TC_HEAD(mknod_stat, tc) | ||
139 | { | ||
140 | atf_tc_set_md_var(tc, "descr", "A basic test of mknod(2)"); | ||
141 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
142 | } | ||
143 | |||
144 | ATF_TC_BODY(mknod_stat, tc) | ||
145 | { | ||
146 | struct stat st; | ||
147 | |||
148 | (void)memset(&st, 0, sizeof(struct stat)); | ||
149 | |||
150 | ATF_REQUIRE(mknod(path, S_IFCHR, 0) == 0); | ||
151 | ATF_REQUIRE(stat(path, &st) == 0); | ||
152 | |||
153 | if (S_ISCHR(st.st_mode) == 0) | ||
154 | atf_tc_fail_nonfatal("invalid mode from mknod(2) (S_IFCHR)"); | ||
155 | |||
156 | ATF_REQUIRE(unlink(path) == 0); | ||
157 | |||
158 | (void)memset(&st, 0, sizeof(struct stat)); | ||
159 | |||
160 | ATF_REQUIRE(mknod(path, S_IFBLK, 0) == 0); | ||
161 | ATF_REQUIRE(stat(path, &st) == 0); | ||
162 | |||
163 | if (S_ISBLK(st.st_mode) == 0) | ||
164 | atf_tc_fail_nonfatal("invalid mode from mknod(2) (S_IFBLK)"); | ||
165 | |||
166 | ATF_REQUIRE(unlink(path) == 0); | ||
167 | |||
168 | (void)memset(&st, 0, sizeof(struct stat)); | ||
169 | |||
170 | #ifndef __OpenBSD__ | ||
171 | /* OpenBSD only supports FIFO and device special files */ | ||
172 | ATF_REQUIRE(mknod(path, S_IFREG, 0) == 0); | ||
173 | ATF_REQUIRE(stat(path, &st) == 0); | ||
174 | |||
175 | if (S_ISREG(st.st_mode) == 0) | ||
176 | atf_tc_fail_nonfatal("invalid mode from mknod(2) (S_IFREG)"); | ||
177 | |||
178 | ATF_REQUIRE(unlink(path) == 0); | ||
179 | #endif | ||
180 | } | ||
181 | |||
182 | ATF_TC_CLEANUP(mknod_stat, tc) | ||
183 | { | ||
184 | (void)unlink(path); | ||
185 | } | ||
186 | |||
187 | ATF_TP_ADD_TCS(tp) | ||
188 | { | ||
189 | |||
190 | ATF_TP_ADD_TC(tp, mknod_err); | ||
191 | ATF_TP_ADD_TC(tp, mknod_exist); | ||
192 | ATF_TP_ADD_TC(tp, mknod_perm); | ||
193 | ATF_TP_ADD_TC(tp, mknod_stat); | ||
194 | |||
195 | return atf_no_error(); | ||
196 | } | ||
diff --git a/src/regress/lib/libc/sys/t_mlock.c b/src/regress/lib/libc/sys/t_mlock.c deleted file mode 100644 index 865bd9e36b..0000000000 --- a/src/regress/lib/libc/sys/t_mlock.c +++ /dev/null | |||
@@ -1,329 +0,0 @@ | |||
1 | /* $OpenBSD: t_mlock.c,v 1.3 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_mlock.c,v 1.8 2020/01/24 08:45:16 skrll Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2012 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/mman.h> | ||
36 | #include <sys/resource.h> | ||
37 | #include <sys/sysctl.h> | ||
38 | #include <sys/wait.h> | ||
39 | |||
40 | #include <errno.h> | ||
41 | #include "atf-c.h" | ||
42 | #include <stdint.h> | ||
43 | #include <stdio.h> | ||
44 | #include <stdlib.h> | ||
45 | #include <string.h> | ||
46 | #include <unistd.h> | ||
47 | |||
48 | static long page = 0; | ||
49 | |||
50 | ATF_TC(mlock_clip); | ||
51 | ATF_TC_HEAD(mlock_clip, tc) | ||
52 | { | ||
53 | atf_tc_set_md_var(tc, "descr", "Test with mlock(2) that UVM only " | ||
54 | "clips if the clip address is within the entry (PR kern/44788)"); | ||
55 | } | ||
56 | |||
57 | ATF_TC_BODY(mlock_clip, tc) | ||
58 | { | ||
59 | void *buf; | ||
60 | int err1, err2; | ||
61 | |||
62 | buf = malloc(page); | ||
63 | ATF_REQUIRE(buf != NULL); | ||
64 | fprintf(stderr, "mlock_clip: buf = %p (page=%ld)\n", buf, page); | ||
65 | |||
66 | if (page < 1024) | ||
67 | atf_tc_skip("page size too small"); | ||
68 | |||
69 | for (size_t i = page; i >= 1; i = i - 1024) { | ||
70 | err1 = mlock(buf, page - i); | ||
71 | if (err1 != 0) | ||
72 | fprintf(stderr, "mlock_clip: page=%ld i=%zu," | ||
73 | " mlock(%p, %ld): %s\n", page, i, buf, page - i, | ||
74 | strerror(errno)); | ||
75 | err2 = munlock(buf, page - i); | ||
76 | if (err2 != 0) | ||
77 | fprintf(stderr, "mlock_clip: page=%ld i=%zu," | ||
78 | " munlock(%p, %ld): %s (mlock %s)\n", page, i, | ||
79 | buf, page - i, strerror(errno), err1?"failed":"ok"); | ||
80 | } | ||
81 | |||
82 | free(buf); | ||
83 | } | ||
84 | |||
85 | ATF_TC(mlock_err); | ||
86 | ATF_TC_HEAD(mlock_err, tc) | ||
87 | { | ||
88 | atf_tc_set_md_var(tc, "descr", | ||
89 | "Test error conditions in mlock(2) and munlock(2)"); | ||
90 | } | ||
91 | |||
92 | ATF_TC_BODY(mlock_err, tc) | ||
93 | { | ||
94 | void *invalid_ptr; | ||
95 | void *buf; | ||
96 | int mlock_err, munlock_err; | ||
97 | |||
98 | /* | ||
99 | * Any bad address must return ENOMEM (for lock & unlock) | ||
100 | */ | ||
101 | errno = 0; | ||
102 | ATF_REQUIRE_ERRNO(ENOMEM, mlock(NULL, page) == -1); | ||
103 | |||
104 | errno = 0; | ||
105 | ATF_REQUIRE_ERRNO(ENOMEM, mlock((char *)0, page) == -1); | ||
106 | |||
107 | errno = 0; | ||
108 | #ifdef __OpenBSD__ | ||
109 | ATF_REQUIRE_ERRNO(EINVAL, mlock((char *)-1, page) == -1); | ||
110 | #else | ||
111 | ATF_REQUIRE_ERRNO(ENOMEM, mlock((char *)-1, page) == -1); | ||
112 | #endif | ||
113 | |||
114 | errno = 0; | ||
115 | ATF_REQUIRE_ERRNO(ENOMEM, munlock(NULL, page) == -1); | ||
116 | |||
117 | errno = 0; | ||
118 | ATF_REQUIRE_ERRNO(ENOMEM, munlock((char *)0, page) == -1); | ||
119 | |||
120 | errno = 0; | ||
121 | #ifdef __OpenBSD__ | ||
122 | ATF_REQUIRE_ERRNO(EINVAL, munlock((char *)-1, page) == -1); | ||
123 | #else | ||
124 | ATF_REQUIRE_ERRNO(ENOMEM, munlock((char *)-1, page) == -1); | ||
125 | #endif | ||
126 | |||
127 | buf = malloc(page); | ||
128 | ATF_REQUIRE(buf != NULL); | ||
129 | fprintf(stderr, "mlock_err: buf = %p (page=%ld)\n", buf, page); | ||
130 | |||
131 | /* | ||
132 | * unlocking memory that is not locked is an error... | ||
133 | */ | ||
134 | |||
135 | #ifndef __OpenBSD__ | ||
136 | errno = 0; | ||
137 | ATF_REQUIRE_ERRNO(ENOMEM, munlock(buf, page) == -1); | ||
138 | #endif | ||
139 | |||
140 | /* | ||
141 | * These are permitted to fail (EINVAL) but do not on NetBSD | ||
142 | */ | ||
143 | mlock_err = mlock((void *)(((uintptr_t)buf) + page/3), page/5); | ||
144 | if (mlock_err != 0) | ||
145 | fprintf(stderr, "mlock_err: mlock(%p, %ld): %d [%d] %s\n", | ||
146 | (void *)(((uintptr_t)buf) + page/3), page/5, mlock_err, | ||
147 | errno, strerror(errno)); | ||
148 | ATF_REQUIRE(mlock_err == 0); | ||
149 | munlock_err= munlock((void *)(((uintptr_t)buf) + page/3), page/5); | ||
150 | if (munlock_err != 0) | ||
151 | fprintf(stderr, "mlock_err: munlock(%p, %ld): %d [%d] %s\n", | ||
152 | (void *)(((uintptr_t)buf) + page/3), page/5, munlock_err, | ||
153 | errno, strerror(errno)); | ||
154 | ATF_REQUIRE(munlock_err == 0); | ||
155 | |||
156 | (void)free(buf); | ||
157 | |||
158 | /* | ||
159 | * Try to create a pointer to an unmapped page - first after current | ||
160 | * brk will likely do. | ||
161 | */ | ||
162 | invalid_ptr = (void*)(((uintptr_t)sbrk(0)+page) & ~(page-1)); | ||
163 | printf("testing with (hopefully) invalid pointer %p\n", invalid_ptr); | ||
164 | |||
165 | errno = 0; | ||
166 | ATF_REQUIRE_ERRNO(ENOMEM, mlock(invalid_ptr, page) == -1); | ||
167 | |||
168 | errno = 0; | ||
169 | ATF_REQUIRE_ERRNO(ENOMEM, munlock(invalid_ptr, page) == -1); | ||
170 | } | ||
171 | |||
172 | ATF_TC(mlock_limits); | ||
173 | ATF_TC_HEAD(mlock_limits, tc) | ||
174 | { | ||
175 | atf_tc_set_md_var(tc, "descr", "Test system limits with mlock(2)"); | ||
176 | } | ||
177 | |||
178 | ATF_TC_BODY(mlock_limits, tc) | ||
179 | { | ||
180 | struct rlimit res; | ||
181 | void *buf; | ||
182 | pid_t pid; | ||
183 | int sta; | ||
184 | |||
185 | buf = malloc(page); | ||
186 | ATF_REQUIRE(buf != NULL); | ||
187 | fprintf(stderr, "mlock_limits: buf = %p (page=%ld)\n", buf, page); | ||
188 | |||
189 | pid = fork(); | ||
190 | ATF_REQUIRE(pid >= 0); | ||
191 | |||
192 | if (pid == 0) { | ||
193 | |||
194 | for (ssize_t i = page; i >= 2; i -= 100) { | ||
195 | |||
196 | res.rlim_cur = i - 1; | ||
197 | res.rlim_max = i - 1; | ||
198 | |||
199 | (void)fprintf(stderr, "trying to lock %zu bytes " | ||
200 | "with %zu byte limit\n", i, (size_t)res.rlim_cur); | ||
201 | |||
202 | if (setrlimit(RLIMIT_MEMLOCK, &res) != 0) | ||
203 | _exit(EXIT_FAILURE); | ||
204 | |||
205 | errno = 0; | ||
206 | |||
207 | if ((sta = mlock(buf, i)) != -1 || errno != EAGAIN) { | ||
208 | fprintf(stderr, "mlock(%p, %zu): %d [%d] %s\n", | ||
209 | buf, i, sta, errno, strerror(errno)); | ||
210 | (void)munlock(buf, i); | ||
211 | _exit(EXIT_FAILURE); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | _exit(EXIT_SUCCESS); | ||
216 | } | ||
217 | |||
218 | (void)wait(&sta); | ||
219 | |||
220 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
221 | atf_tc_fail("mlock(2) locked beyond system limits"); | ||
222 | |||
223 | free(buf); | ||
224 | } | ||
225 | |||
226 | ATF_TC(mlock_mmap); | ||
227 | ATF_TC_HEAD(mlock_mmap, tc) | ||
228 | { | ||
229 | atf_tc_set_md_var(tc, "descr", "Test mlock(2)-mmap(2) interaction"); | ||
230 | } | ||
231 | |||
232 | ATF_TC_BODY(mlock_mmap, tc) | ||
233 | { | ||
234 | #ifdef __OpenBSD__ | ||
235 | static const int flags = MAP_ANON | MAP_PRIVATE; | ||
236 | #else | ||
237 | static const int flags = MAP_ANON | MAP_PRIVATE | MAP_WIRED; | ||
238 | #endif | ||
239 | void *buf; | ||
240 | |||
241 | /* | ||
242 | * Make a wired RW mapping and check that mlock(2) | ||
243 | * does not fail for the (already locked) mapping. | ||
244 | */ | ||
245 | buf = mmap(NULL, page, PROT_READ | PROT_WRITE, flags, -1, 0); | ||
246 | |||
247 | if (buf == MAP_FAILED) | ||
248 | fprintf(stderr, | ||
249 | "mlock_mmap: mmap(NULL, %ld, %#x, %#x, -1, 0): MAP_FAILED" | ||
250 | " [%d] %s\n", page, PROT_READ | PROT_WRITE, flags, errno, | ||
251 | strerror(errno)); | ||
252 | |||
253 | ATF_REQUIRE(buf != MAP_FAILED); | ||
254 | |||
255 | fprintf(stderr, "mlock_mmap: buf=%p, page=%ld\n", buf, page); | ||
256 | |||
257 | ATF_REQUIRE(mlock(buf, page) == 0); | ||
258 | ATF_REQUIRE(munlock(buf, page) == 0); | ||
259 | ATF_REQUIRE(munmap(buf, page) == 0); | ||
260 | ATF_REQUIRE(munlock(buf, page) != 0); | ||
261 | |||
262 | fprintf(stderr, "mlock_mmap: first test succeeded\n"); | ||
263 | |||
264 | /* | ||
265 | * But it should be impossible to mlock(2) a PROT_NONE mapping. | ||
266 | */ | ||
267 | buf = mmap(NULL, page, PROT_NONE, flags, -1, 0); | ||
268 | |||
269 | if (buf == MAP_FAILED) | ||
270 | fprintf(stderr, | ||
271 | "mlock_mmap: mmap(NULL, %ld, %#x, %#x, -1, 0): MAP_FAILED" | ||
272 | " [%d] %s\n", page, PROT_NONE, flags, errno, | ||
273 | strerror(errno)); | ||
274 | |||
275 | ATF_REQUIRE(buf != MAP_FAILED); | ||
276 | ATF_REQUIRE(mlock(buf, page) != 0); | ||
277 | ATF_REQUIRE(munmap(buf, page) == 0); | ||
278 | |||
279 | fprintf(stderr, "mlock_mmap: second test succeeded\n"); | ||
280 | } | ||
281 | |||
282 | ATF_TC(mlock_nested); | ||
283 | ATF_TC_HEAD(mlock_nested, tc) | ||
284 | { | ||
285 | atf_tc_set_md_var(tc, "descr", | ||
286 | "Test that consecutive mlock(2) calls succeed"); | ||
287 | } | ||
288 | |||
289 | ATF_TC_BODY(mlock_nested, tc) | ||
290 | { | ||
291 | const size_t maxiter = 100; | ||
292 | void *buf; | ||
293 | int err; | ||
294 | |||
295 | buf = malloc(page); | ||
296 | ATF_REQUIRE(buf != NULL); | ||
297 | fprintf(stderr, "mlock_nested: buf = %p (page=%ld)\n", buf, page); | ||
298 | |||
299 | for (size_t i = 0; i < maxiter; i++) { | ||
300 | err = mlock(buf, page); | ||
301 | if (err != 0) | ||
302 | fprintf(stderr, | ||
303 | "mlock_nested: i=%zu (of %zu) mlock(%p, %ld): %d [%d] %s\n", | ||
304 | i, maxiter, buf, page, err, errno, strerror(errno)); | ||
305 | ATF_REQUIRE(err == 0); | ||
306 | } | ||
307 | |||
308 | err = munlock(buf, page); | ||
309 | if (err != 0) | ||
310 | fprintf(stderr, "mlock_nested: munlock(%p, %ld): %d [%d] %s\n", | ||
311 | buf, page, err, errno, strerror(errno)); | ||
312 | ATF_REQUIRE(err == 0); | ||
313 | free(buf); | ||
314 | } | ||
315 | |||
316 | ATF_TP_ADD_TCS(tp) | ||
317 | { | ||
318 | |||
319 | page = sysconf(_SC_PAGESIZE); | ||
320 | ATF_REQUIRE(page >= 0); | ||
321 | |||
322 | ATF_TP_ADD_TC(tp, mlock_clip); | ||
323 | ATF_TP_ADD_TC(tp, mlock_err); | ||
324 | ATF_TP_ADD_TC(tp, mlock_limits); | ||
325 | ATF_TP_ADD_TC(tp, mlock_mmap); | ||
326 | ATF_TP_ADD_TC(tp, mlock_nested); | ||
327 | |||
328 | return atf_no_error(); | ||
329 | } | ||
diff --git a/src/regress/lib/libc/sys/t_mmap.c b/src/regress/lib/libc/sys/t_mmap.c deleted file mode 100644 index 59c74296e3..0000000000 --- a/src/regress/lib/libc/sys/t_mmap.c +++ /dev/null | |||
@@ -1,590 +0,0 @@ | |||
1 | /* $OpenBSD: t_mmap.c,v 1.4 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_mmap.c,v 1.14 2020/06/26 07:50:11 jruoho Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | /*- | ||
34 | * Copyright (c)2004 YAMAMOTO Takashi, | ||
35 | * All rights reserved. | ||
36 | * | ||
37 | * Redistribution and use in source and binary forms, with or without | ||
38 | * modification, are permitted provided that the following conditions | ||
39 | * are met: | ||
40 | * 1. Redistributions of source code must retain the above copyright | ||
41 | * notice, this list of conditions and the following disclaimer. | ||
42 | * 2. Redistributions in binary form must reproduce the above copyright | ||
43 | * notice, this list of conditions and the following disclaimer in the | ||
44 | * documentation and/or other materials provided with the distribution. | ||
45 | * | ||
46 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
47 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
48 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
49 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
50 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
51 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
52 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
53 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
54 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
55 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
56 | * SUCH DAMAGE. | ||
57 | */ | ||
58 | |||
59 | #include "macros.h" | ||
60 | |||
61 | #include <sys/disklabel.h> | ||
62 | #include <sys/mman.h> | ||
63 | #include <sys/stat.h> | ||
64 | #include <sys/socket.h> | ||
65 | #include <sys/sysctl.h> | ||
66 | #include <sys/wait.h> | ||
67 | |||
68 | #include "atf-c.h" | ||
69 | #include <errno.h> | ||
70 | #include <fcntl.h> | ||
71 | #include <signal.h> | ||
72 | #include <stdio.h> | ||
73 | #include <stdlib.h> | ||
74 | #include <limits.h> | ||
75 | #include <string.h> | ||
76 | #include <unistd.h> | ||
77 | #include <paths.h> | ||
78 | |||
79 | static long page = 0; | ||
80 | static char path[] = "mmap"; | ||
81 | static void map_check(void *, int); | ||
82 | static void map_sighandler(int); | ||
83 | static void testloan(void *, void *, char, int); | ||
84 | |||
85 | #define BUFSIZE (32 * 1024) /* enough size to trigger sosend_loan */ | ||
86 | |||
87 | static void | ||
88 | map_check(void *map, int flag) | ||
89 | { | ||
90 | |||
91 | if (flag != 0) { | ||
92 | ATF_REQUIRE(map == MAP_FAILED); | ||
93 | return; | ||
94 | } | ||
95 | |||
96 | ATF_REQUIRE(map != MAP_FAILED); | ||
97 | ATF_REQUIRE(munmap(map, page) == 0); | ||
98 | } | ||
99 | |||
100 | void | ||
101 | testloan(void *vp, void *vp2, char pat, int docheck) | ||
102 | { | ||
103 | char buf[BUFSIZE]; | ||
104 | char backup[BUFSIZE]; | ||
105 | ssize_t nwritten; | ||
106 | ssize_t nread; | ||
107 | int fds[2]; | ||
108 | int val; | ||
109 | |||
110 | val = BUFSIZE; | ||
111 | |||
112 | if (docheck != 0) | ||
113 | (void)memcpy(backup, vp, BUFSIZE); | ||
114 | |||
115 | if (socketpair(AF_LOCAL, SOCK_STREAM, PF_UNSPEC, fds) != 0) | ||
116 | atf_tc_fail("socketpair() failed"); | ||
117 | |||
118 | val = BUFSIZE; | ||
119 | |||
120 | if (setsockopt(fds[1], SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)) != 0) | ||
121 | atf_tc_fail("setsockopt() failed, SO_RCVBUF"); | ||
122 | |||
123 | val = BUFSIZE; | ||
124 | |||
125 | if (setsockopt(fds[0], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)) != 0) | ||
126 | atf_tc_fail("setsockopt() failed, SO_SNDBUF"); | ||
127 | |||
128 | if (fcntl(fds[0], F_SETFL, O_NONBLOCK) != 0) | ||
129 | atf_tc_fail("fcntl() failed"); | ||
130 | |||
131 | nwritten = write(fds[0], (char *)vp + page, BUFSIZE - page); | ||
132 | |||
133 | if (nwritten == -1) | ||
134 | atf_tc_fail("write() failed"); | ||
135 | |||
136 | /* Break loan. */ | ||
137 | (void)memset(vp2, pat, BUFSIZE); | ||
138 | |||
139 | nread = read(fds[1], buf + page, BUFSIZE - page); | ||
140 | |||
141 | if (nread == -1) | ||
142 | atf_tc_fail("read() failed"); | ||
143 | |||
144 | if (nread != nwritten) | ||
145 | atf_tc_fail("too short read"); | ||
146 | |||
147 | if (docheck != 0 && memcmp(backup, buf + page, nread) != 0) | ||
148 | atf_tc_fail("data mismatch"); | ||
149 | |||
150 | ATF_REQUIRE(close(fds[0]) == 0); | ||
151 | ATF_REQUIRE(close(fds[1]) == 0); | ||
152 | } | ||
153 | |||
154 | static void | ||
155 | map_sighandler(int signo) | ||
156 | { | ||
157 | _exit(signo); | ||
158 | } | ||
159 | |||
160 | ATF_TC(mmap_block); | ||
161 | ATF_TC_HEAD(mmap_block, tc) | ||
162 | { | ||
163 | atf_tc_set_md_var(tc, "descr", "Test mmap(2) with a block device"); | ||
164 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
165 | } | ||
166 | |||
167 | ATF_TC_BODY(mmap_block, tc) | ||
168 | { | ||
169 | static const int mib[] = { CTL_HW, HW_DISKNAMES }; | ||
170 | static const unsigned int miblen = __arraycount(mib); | ||
171 | char *map, *dk, *drives, dev[PATH_MAX]; | ||
172 | size_t len; | ||
173 | int fd = -1; | ||
174 | |||
175 | #ifndef __OpenBSD__ | ||
176 | /* works for us */ | ||
177 | atf_tc_skip("The test case causes a panic " \ | ||
178 | "(PR kern/38889, PR kern/46592)"); | ||
179 | #endif | ||
180 | |||
181 | ATF_REQUIRE(sysctl(mib, miblen, NULL, &len, NULL, 0) == 0); | ||
182 | drives = malloc(len); | ||
183 | ATF_REQUIRE(drives != NULL); | ||
184 | ATF_REQUIRE(sysctl(mib, miblen, drives, &len, NULL, 0) == 0); | ||
185 | #ifdef __OpenBSD__ | ||
186 | /* devices separated by comma, disk uid by colon */ | ||
187 | for (dk = strtok(drives, ",:"); dk != NULL; dk = strtok(NULL, ",:")) { | ||
188 | #else | ||
189 | for (dk = strtok(drives, " "); dk != NULL; dk = strtok(NULL, " ")) { | ||
190 | #endif | ||
191 | if (strncmp(dk, "dk", 2) == 0) | ||
192 | snprintf(dev, sizeof(dev), _PATH_DEV "%s", dk); | ||
193 | else | ||
194 | snprintf(dev, sizeof(dev), _PATH_DEV "%s%c", dk, | ||
195 | 'a' + RAW_PART); | ||
196 | fprintf(stderr, "trying: %s\n", dev); | ||
197 | |||
198 | if ((fd = open(dev, O_RDONLY)) >= 0) { | ||
199 | (void)fprintf(stderr, "using %s\n", dev); | ||
200 | break; | ||
201 | } else | ||
202 | (void)fprintf(stderr, "%s: %s\n", dev, strerror(errno)); | ||
203 | } | ||
204 | free(drives); | ||
205 | |||
206 | if (fd < 0) | ||
207 | atf_tc_skip("failed to find suitable block device"); | ||
208 | |||
209 | map = mmap(NULL, 4096, PROT_READ, MAP_FILE, fd, 0); | ||
210 | ATF_REQUIRE_MSG(map != MAP_FAILED, "mmap: %s", strerror(errno)); | ||
211 | |||
212 | (void)fprintf(stderr, "first byte %x\n", *map); | ||
213 | ATF_REQUIRE(close(fd) == 0); | ||
214 | (void)fprintf(stderr, "first byte %x\n", *map); | ||
215 | |||
216 | ATF_REQUIRE(munmap(map, 4096) == 0); | ||
217 | } | ||
218 | |||
219 | ATF_TC(mmap_err); | ||
220 | ATF_TC_HEAD(mmap_err, tc) | ||
221 | { | ||
222 | atf_tc_set_md_var(tc, "descr", "Test error conditions of mmap(2)"); | ||
223 | } | ||
224 | |||
225 | ATF_TC_BODY(mmap_err, tc) | ||
226 | { | ||
227 | size_t addr = SIZE_MAX; | ||
228 | void *map; | ||
229 | |||
230 | errno = 0; | ||
231 | map = mmap(NULL, 3, PROT_READ, MAP_FILE|MAP_PRIVATE, -1, 0); | ||
232 | |||
233 | ATF_REQUIRE(map == MAP_FAILED); | ||
234 | ATF_REQUIRE(errno == EBADF); | ||
235 | |||
236 | errno = 0; | ||
237 | map = mmap(&addr, page, PROT_READ, MAP_FIXED|MAP_PRIVATE, -1, 0); | ||
238 | |||
239 | ATF_REQUIRE(map == MAP_FAILED); | ||
240 | ATF_REQUIRE(errno == EINVAL); | ||
241 | |||
242 | errno = 0; | ||
243 | map = mmap(NULL, page, PROT_READ, MAP_ANON|MAP_PRIVATE, INT_MAX, 0); | ||
244 | |||
245 | ATF_REQUIRE(map == MAP_FAILED); | ||
246 | ATF_REQUIRE(errno == EINVAL); | ||
247 | } | ||
248 | |||
249 | ATF_TC_WITH_CLEANUP(mmap_loan); | ||
250 | ATF_TC_HEAD(mmap_loan, tc) | ||
251 | { | ||
252 | atf_tc_set_md_var(tc, "descr", "Test uvm page loanout with mmap(2)"); | ||
253 | } | ||
254 | |||
255 | ATF_TC_BODY(mmap_loan, tc) | ||
256 | { | ||
257 | char buf[BUFSIZE]; | ||
258 | char *vp, *vp2; | ||
259 | int fd; | ||
260 | |||
261 | fd = open(path, O_RDWR | O_CREAT, 0600); | ||
262 | ATF_REQUIRE(fd >= 0); | ||
263 | |||
264 | (void)memset(buf, 'x', sizeof(buf)); | ||
265 | (void)write(fd, buf, sizeof(buf)); | ||
266 | |||
267 | vp = mmap(NULL, BUFSIZE, PROT_READ | PROT_WRITE, | ||
268 | MAP_FILE | MAP_PRIVATE, fd, 0); | ||
269 | |||
270 | ATF_REQUIRE(vp != MAP_FAILED); | ||
271 | |||
272 | vp2 = vp; | ||
273 | |||
274 | testloan(vp, vp2, 'A', 0); | ||
275 | testloan(vp, vp2, 'B', 1); | ||
276 | |||
277 | ATF_REQUIRE(munmap(vp, BUFSIZE) == 0); | ||
278 | |||
279 | vp = mmap(NULL, BUFSIZE, PROT_READ | PROT_WRITE, | ||
280 | MAP_FILE | MAP_SHARED, fd, 0); | ||
281 | |||
282 | vp2 = mmap(NULL, BUFSIZE, PROT_READ | PROT_WRITE, | ||
283 | MAP_FILE | MAP_SHARED, fd, 0); | ||
284 | |||
285 | ATF_REQUIRE(vp != MAP_FAILED); | ||
286 | ATF_REQUIRE(vp2 != MAP_FAILED); | ||
287 | |||
288 | testloan(vp, vp2, 'E', 1); | ||
289 | |||
290 | ATF_REQUIRE(munmap(vp, BUFSIZE) == 0); | ||
291 | ATF_REQUIRE(munmap(vp2, BUFSIZE) == 0); | ||
292 | } | ||
293 | |||
294 | ATF_TC_CLEANUP(mmap_loan, tc) | ||
295 | { | ||
296 | (void)unlink(path); | ||
297 | } | ||
298 | |||
299 | ATF_TC_WITH_CLEANUP(mmap_prot_1); | ||
300 | ATF_TC_HEAD(mmap_prot_1, tc) | ||
301 | { | ||
302 | atf_tc_set_md_var(tc, "descr", "Test mmap(2) protections, #1"); | ||
303 | } | ||
304 | |||
305 | ATF_TC_BODY(mmap_prot_1, tc) | ||
306 | { | ||
307 | void *map; | ||
308 | int fd; | ||
309 | |||
310 | /* | ||
311 | * Open a file write-only and try to | ||
312 | * map it read-only. This should fail. | ||
313 | */ | ||
314 | fd = open(path, O_WRONLY | O_CREAT, 0700); | ||
315 | |||
316 | if (fd < 0) | ||
317 | return; | ||
318 | |||
319 | ATF_REQUIRE(write(fd, "XXX", 3) == 3); | ||
320 | |||
321 | map = mmap(NULL, 3, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); | ||
322 | map_check(map, 1); | ||
323 | |||
324 | map = mmap(NULL, 3, PROT_WRITE, MAP_FILE|MAP_PRIVATE, fd, 0); | ||
325 | map_check(map, 0); | ||
326 | |||
327 | ATF_REQUIRE(close(fd) == 0); | ||
328 | } | ||
329 | |||
330 | ATF_TC_CLEANUP(mmap_prot_1, tc) | ||
331 | { | ||
332 | (void)unlink(path); | ||
333 | } | ||
334 | |||
335 | ATF_TC(mmap_prot_2); | ||
336 | ATF_TC_HEAD(mmap_prot_2, tc) | ||
337 | { | ||
338 | atf_tc_set_md_var(tc, "descr", "Test mmap(2) protections, #2"); | ||
339 | } | ||
340 | |||
341 | ATF_TC_BODY(mmap_prot_2, tc) | ||
342 | { | ||
343 | char buf[2]; | ||
344 | void *map; | ||
345 | pid_t pid; | ||
346 | int sta; | ||
347 | |||
348 | /* | ||
349 | * Make a PROT_NONE mapping and try to access it. | ||
350 | * If we catch a SIGSEGV, all works as expected. | ||
351 | */ | ||
352 | map = mmap(NULL, page, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0); | ||
353 | ATF_REQUIRE(map != MAP_FAILED); | ||
354 | |||
355 | pid = fork(); | ||
356 | ATF_REQUIRE(pid >= 0); | ||
357 | |||
358 | if (pid == 0) { | ||
359 | ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR); | ||
360 | ATF_REQUIRE(strlcpy(buf, map, sizeof(buf)) != 0); | ||
361 | } | ||
362 | |||
363 | (void)wait(&sta); | ||
364 | |||
365 | ATF_REQUIRE(WIFEXITED(sta) != 0); | ||
366 | ATF_REQUIRE(WEXITSTATUS(sta) == SIGSEGV); | ||
367 | ATF_REQUIRE(munmap(map, page) == 0); | ||
368 | } | ||
369 | |||
370 | ATF_TC_WITH_CLEANUP(mmap_prot_3); | ||
371 | ATF_TC_HEAD(mmap_prot_3, tc) | ||
372 | { | ||
373 | atf_tc_set_md_var(tc, "descr", "Test mmap(2) protections, #3"); | ||
374 | } | ||
375 | |||
376 | ATF_TC_BODY(mmap_prot_3, tc) | ||
377 | { | ||
378 | char buf[2]; | ||
379 | int fd, sta; | ||
380 | void *map; | ||
381 | pid_t pid; | ||
382 | |||
383 | /* | ||
384 | * Open a file, change the permissions | ||
385 | * to read-only, and try to map it as | ||
386 | * PROT_NONE. This should succeed, but | ||
387 | * the access should generate SIGSEGV. | ||
388 | */ | ||
389 | fd = open(path, O_RDWR | O_CREAT, 0700); | ||
390 | |||
391 | if (fd < 0) | ||
392 | return; | ||
393 | |||
394 | ATF_REQUIRE(write(fd, "XXX", 3) == 3); | ||
395 | ATF_REQUIRE(close(fd) == 0); | ||
396 | ATF_REQUIRE(chmod(path, 0444) == 0); | ||
397 | |||
398 | fd = open(path, O_RDONLY); | ||
399 | ATF_REQUIRE(fd != -1); | ||
400 | |||
401 | map = mmap(NULL, 3, PROT_NONE, MAP_FILE | MAP_SHARED, fd, 0); | ||
402 | ATF_REQUIRE(map != MAP_FAILED); | ||
403 | |||
404 | pid = fork(); | ||
405 | |||
406 | ATF_REQUIRE(pid >= 0); | ||
407 | |||
408 | if (pid == 0) { | ||
409 | ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR); | ||
410 | ATF_REQUIRE(strlcpy(buf, map, sizeof(buf)) != 0); | ||
411 | } | ||
412 | |||
413 | (void)wait(&sta); | ||
414 | |||
415 | ATF_REQUIRE(WIFEXITED(sta) != 0); | ||
416 | ATF_REQUIRE(WEXITSTATUS(sta) == SIGSEGV); | ||
417 | ATF_REQUIRE(munmap(map, 3) == 0); | ||
418 | } | ||
419 | |||
420 | ATF_TC_CLEANUP(mmap_prot_3, tc) | ||
421 | { | ||
422 | (void)unlink(path); | ||
423 | } | ||
424 | |||
425 | ATF_TC_WITH_CLEANUP(mmap_truncate); | ||
426 | ATF_TC_HEAD(mmap_truncate, tc) | ||
427 | { | ||
428 | atf_tc_set_md_var(tc, "descr", "Test mmap(2) and ftruncate(2)"); | ||
429 | } | ||
430 | |||
431 | ATF_TC_BODY(mmap_truncate, tc) | ||
432 | { | ||
433 | char *map; | ||
434 | long i; | ||
435 | int fd; | ||
436 | |||
437 | fd = open(path, O_RDWR | O_CREAT, 0700); | ||
438 | |||
439 | if (fd < 0) | ||
440 | return; | ||
441 | |||
442 | /* | ||
443 | * See that ftruncate(2) works | ||
444 | * while the file is mapped. | ||
445 | */ | ||
446 | ATF_REQUIRE(ftruncate(fd, page) == 0); | ||
447 | |||
448 | map = mmap(NULL, page, PROT_READ | PROT_WRITE, MAP_FILE|MAP_PRIVATE, | ||
449 | fd, 0); | ||
450 | ATF_REQUIRE(map != MAP_FAILED); | ||
451 | |||
452 | for (i = 0; i < page; i++) | ||
453 | map[i] = 'x'; | ||
454 | |||
455 | ATF_REQUIRE(ftruncate(fd, 0) == 0); | ||
456 | ATF_REQUIRE(ftruncate(fd, page / 8) == 0); | ||
457 | ATF_REQUIRE(ftruncate(fd, page / 4) == 0); | ||
458 | ATF_REQUIRE(ftruncate(fd, page / 2) == 0); | ||
459 | ATF_REQUIRE(ftruncate(fd, page / 12) == 0); | ||
460 | ATF_REQUIRE(ftruncate(fd, page / 64) == 0); | ||
461 | |||
462 | (void)munmap(map, page); | ||
463 | ATF_REQUIRE(close(fd) == 0); | ||
464 | } | ||
465 | |||
466 | ATF_TC_CLEANUP(mmap_truncate, tc) | ||
467 | { | ||
468 | (void)unlink(path); | ||
469 | } | ||
470 | |||
471 | ATF_TC_WITH_CLEANUP(mmap_truncate_signal); | ||
472 | ATF_TC_HEAD(mmap_truncate_signal, tc) | ||
473 | { | ||
474 | atf_tc_set_md_var(tc, "descr", | ||
475 | "Test mmap(2) ftruncate(2) causing signal"); | ||
476 | } | ||
477 | |||
478 | ATF_TC_BODY(mmap_truncate_signal, tc) | ||
479 | { | ||
480 | char *map; | ||
481 | long i; | ||
482 | int fd, sta; | ||
483 | pid_t pid; | ||
484 | |||
485 | fd = open(path, O_RDWR | O_CREAT, 0700); | ||
486 | |||
487 | if (fd < 0) | ||
488 | return; | ||
489 | |||
490 | ATF_REQUIRE(write(fd, "foo\n", 5) == 5); | ||
491 | |||
492 | map = mmap(NULL, page, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); | ||
493 | ATF_REQUIRE(map != MAP_FAILED); | ||
494 | |||
495 | sta = 0; | ||
496 | for (i = 0; i < 5; i++) | ||
497 | sta += map[i]; | ||
498 | ATF_REQUIRE(sta == 334); | ||
499 | |||
500 | ATF_REQUIRE(ftruncate(fd, 0) == 0); | ||
501 | pid = fork(); | ||
502 | ATF_REQUIRE(pid >= 0); | ||
503 | |||
504 | if (pid == 0) { | ||
505 | ATF_REQUIRE(signal(SIGBUS, map_sighandler) != SIG_ERR); | ||
506 | ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR); | ||
507 | sta = 0; | ||
508 | for (i = 0; i < page; i++) | ||
509 | sta += map[i]; | ||
510 | /* child never will get this far, but the compiler will | ||
511 | not know, so better use the values calculated to | ||
512 | prevent the access to be optimized out */ | ||
513 | ATF_REQUIRE(i == 0); | ||
514 | ATF_REQUIRE(sta == 0); | ||
515 | (void)munmap(map, page); | ||
516 | (void)close(fd); | ||
517 | return; | ||
518 | } | ||
519 | |||
520 | (void)wait(&sta); | ||
521 | |||
522 | ATF_REQUIRE(WIFEXITED(sta) != 0); | ||
523 | if (WEXITSTATUS(sta) == SIGSEGV) | ||
524 | atf_tc_fail("child process got SIGSEGV instead of SIGBUS"); | ||
525 | ATF_REQUIRE(WEXITSTATUS(sta) == SIGBUS); | ||
526 | ATF_REQUIRE(munmap(map, page) == 0); | ||
527 | ATF_REQUIRE(close(fd) == 0); | ||
528 | } | ||
529 | |||
530 | ATF_TC_CLEANUP(mmap_truncate_signal, tc) | ||
531 | { | ||
532 | (void)unlink(path); | ||
533 | } | ||
534 | |||
535 | ATF_TC(mmap_va0); | ||
536 | ATF_TC_HEAD(mmap_va0, tc) | ||
537 | { | ||
538 | atf_tc_set_md_var(tc, "descr", "Test mmap(2) and vm.user_va0_disable"); | ||
539 | } | ||
540 | |||
541 | ATF_TC_BODY(mmap_va0, tc) | ||
542 | { | ||
543 | int flags = MAP_ANON | MAP_FIXED | MAP_PRIVATE; | ||
544 | size_t len = sizeof(int); | ||
545 | void *map; | ||
546 | int val; | ||
547 | |||
548 | /* | ||
549 | * Make an anonymous fixed mapping at zero address. If the address | ||
550 | * is restricted as noted in security(7), the syscall should fail. | ||
551 | */ | ||
552 | if (sysctlbyname("vm.user_va0_disable", &val, &len, NULL, 0) != 0) | ||
553 | atf_tc_fail("failed to read vm.user_va0_disable"); | ||
554 | |||
555 | map = mmap(NULL, page, PROT_EXEC, flags, -1, 0); | ||
556 | map_check(map, val); | ||
557 | |||
558 | map = mmap(NULL, page, PROT_READ, flags, -1, 0); | ||
559 | map_check(map, val); | ||
560 | |||
561 | map = mmap(NULL, page, PROT_WRITE, flags, -1, 0); | ||
562 | map_check(map, val); | ||
563 | |||
564 | map = mmap(NULL, page, PROT_READ|PROT_WRITE, flags, -1, 0); | ||
565 | map_check(map, val); | ||
566 | |||
567 | map = mmap(NULL, page, PROT_EXEC|PROT_READ|PROT_WRITE, flags, -1, 0); | ||
568 | map_check(map, val); | ||
569 | } | ||
570 | |||
571 | ATF_TP_ADD_TCS(tp) | ||
572 | { | ||
573 | page = sysconf(_SC_PAGESIZE); | ||
574 | ATF_REQUIRE(page >= 0); | ||
575 | |||
576 | ATF_TP_ADD_TC(tp, mmap_block); | ||
577 | ATF_TP_ADD_TC(tp, mmap_err); | ||
578 | ATF_TP_ADD_TC(tp, mmap_loan); | ||
579 | ATF_TP_ADD_TC(tp, mmap_prot_1); | ||
580 | ATF_TP_ADD_TC(tp, mmap_prot_2); | ||
581 | ATF_TP_ADD_TC(tp, mmap_prot_3); | ||
582 | ATF_TP_ADD_TC(tp, mmap_truncate); | ||
583 | ATF_TP_ADD_TC(tp, mmap_truncate_signal); | ||
584 | #ifndef __OpenBSD__ | ||
585 | /* sysctl vm.user_va0_disable not available */ | ||
586 | ATF_TP_ADD_TC(tp, mmap_va0); | ||
587 | #endif | ||
588 | |||
589 | return atf_no_error(); | ||
590 | } | ||
diff --git a/src/regress/lib/libc/sys/t_msgctl.c b/src/regress/lib/libc/sys/t_msgctl.c deleted file mode 100644 index 91c0eaaeaf..0000000000 --- a/src/regress/lib/libc/sys/t_msgctl.c +++ /dev/null | |||
@@ -1,402 +0,0 @@ | |||
1 | /* $OpenBSD: t_msgctl.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_msgctl.c,v 1.7 2017/10/07 17:15:44 kre Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/msg.h> | ||
36 | #include <sys/stat.h> | ||
37 | #include <sys/sysctl.h> | ||
38 | #include <sys/wait.h> | ||
39 | |||
40 | #include "atf-c.h" | ||
41 | #include <errno.h> | ||
42 | #include <limits.h> | ||
43 | #include <pwd.h> | ||
44 | #include <signal.h> | ||
45 | #include <stdio.h> | ||
46 | #include <stdlib.h> | ||
47 | #include <string.h> | ||
48 | #include <sysexits.h> | ||
49 | #include <time.h> | ||
50 | #include <unistd.h> | ||
51 | |||
52 | #define MSG_KEY 12345689 | ||
53 | #define MSG_MTYPE_1 0x41 | ||
54 | |||
55 | struct msg { | ||
56 | long mtype; | ||
57 | char buf[3]; | ||
58 | }; | ||
59 | |||
60 | static void clean(void); | ||
61 | |||
62 | static void | ||
63 | clean(void) | ||
64 | { | ||
65 | int id; | ||
66 | |||
67 | if ((id = msgget(MSG_KEY, 0)) != -1) | ||
68 | (void)msgctl(id, IPC_RMID, 0); | ||
69 | } | ||
70 | |||
71 | ATF_TC_WITH_CLEANUP(msgctl_err); | ||
72 | ATF_TC_HEAD(msgctl_err, tc) | ||
73 | { | ||
74 | atf_tc_set_md_var(tc, "descr", "Test errors from msgctl(2)"); | ||
75 | } | ||
76 | |||
77 | ATF_TC_BODY(msgctl_err, tc) | ||
78 | { | ||
79 | const int cmd[] = { IPC_STAT, IPC_SET, IPC_RMID }; | ||
80 | struct msqid_ds msgds; | ||
81 | size_t i; | ||
82 | int id; | ||
83 | |||
84 | (void)memset(&msgds, 0, sizeof(struct msqid_ds)); | ||
85 | |||
86 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
87 | ATF_REQUIRE(id != -1); | ||
88 | |||
89 | errno = 0; | ||
90 | ATF_REQUIRE_ERRNO(EINVAL, msgctl(id, INT_MAX, &msgds) == -1); | ||
91 | |||
92 | errno = 0; | ||
93 | ATF_REQUIRE_ERRNO(EFAULT, msgctl(id, IPC_STAT, (void *)-1) == -1); | ||
94 | |||
95 | for (i = 0; i < __arraycount(cmd); i++) { | ||
96 | errno = 0; | ||
97 | ATF_REQUIRE_ERRNO(EINVAL, msgctl(-1, cmd[i], &msgds) == -1); | ||
98 | } | ||
99 | |||
100 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
101 | } | ||
102 | |||
103 | ATF_TC_CLEANUP(msgctl_err, tc) | ||
104 | { | ||
105 | clean(); | ||
106 | } | ||
107 | |||
108 | ATF_TC_WITH_CLEANUP(msgctl_perm); | ||
109 | ATF_TC_HEAD(msgctl_perm, tc) | ||
110 | { | ||
111 | atf_tc_set_md_var(tc, "descr", "Test permissions with msgctl(2)"); | ||
112 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
113 | } | ||
114 | |||
115 | ATF_TC_BODY(msgctl_perm, tc) | ||
116 | { | ||
117 | struct msqid_ds msgds; | ||
118 | struct passwd *pw; | ||
119 | pid_t pid; | ||
120 | int sta; | ||
121 | int id; | ||
122 | |||
123 | (void)memset(&msgds, 0, sizeof(struct msqid_ds)); | ||
124 | |||
125 | pw = getpwnam("nobody"); | ||
126 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
127 | |||
128 | ATF_REQUIRE(id != -1); | ||
129 | ATF_REQUIRE(pw != NULL); | ||
130 | ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0); | ||
131 | |||
132 | pid = fork(); | ||
133 | ATF_REQUIRE(pid >= 0); | ||
134 | |||
135 | if (pid == 0) { | ||
136 | |||
137 | if (setuid(pw->pw_uid) != 0) | ||
138 | _exit(EX_OSERR); | ||
139 | |||
140 | msgds.msg_perm.uid = getuid(); | ||
141 | msgds.msg_perm.gid = getgid(); | ||
142 | |||
143 | errno = 0; | ||
144 | |||
145 | if (msgctl(id, IPC_SET, &msgds) == 0) | ||
146 | _exit(EXIT_FAILURE); | ||
147 | |||
148 | if (errno != EPERM) | ||
149 | _exit(EXIT_FAILURE); | ||
150 | |||
151 | (void)memset(&msgds, 0, sizeof(struct msqid_ds)); | ||
152 | |||
153 | if (msgctl(id, IPC_STAT, &msgds) != 0) | ||
154 | _exit(EX_OSERR); | ||
155 | |||
156 | msgds.msg_qbytes = 1; | ||
157 | |||
158 | if (msgctl(id, IPC_SET, &msgds) == 0) | ||
159 | _exit(EXIT_FAILURE); | ||
160 | |||
161 | if (errno != EPERM) | ||
162 | _exit(EXIT_FAILURE); | ||
163 | |||
164 | _exit(EXIT_SUCCESS); | ||
165 | } | ||
166 | |||
167 | (void)wait(&sta); | ||
168 | |||
169 | if (WIFEXITED(sta) == 0) { | ||
170 | |||
171 | if (WEXITSTATUS(sta) == EX_OSERR) | ||
172 | atf_tc_fail("system call failed"); | ||
173 | |||
174 | if (WEXITSTATUS(sta) == EXIT_FAILURE) | ||
175 | atf_tc_fail("UID %u manipulated root's " | ||
176 | "message queue", pw->pw_uid); | ||
177 | } | ||
178 | |||
179 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
180 | } | ||
181 | |||
182 | ATF_TC_CLEANUP(msgctl_perm, tc) | ||
183 | { | ||
184 | clean(); | ||
185 | } | ||
186 | |||
187 | ATF_TC_WITH_CLEANUP(msgctl_pid); | ||
188 | ATF_TC_HEAD(msgctl_pid, tc) | ||
189 | { | ||
190 | atf_tc_set_md_var(tc, "descr", "Test that PIDs are updated"); | ||
191 | } | ||
192 | |||
193 | ATF_TC_BODY(msgctl_pid, tc) | ||
194 | { | ||
195 | struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; | ||
196 | struct msqid_ds msgds; | ||
197 | int id, sta; | ||
198 | pid_t pid; | ||
199 | |||
200 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
201 | ATF_REQUIRE(id != -1); | ||
202 | |||
203 | pid = fork(); | ||
204 | ATF_REQUIRE(pid >= 0); | ||
205 | |||
206 | if (pid == 0) { | ||
207 | |||
208 | (void)msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT); | ||
209 | |||
210 | _exit(EXIT_SUCCESS); | ||
211 | } | ||
212 | |||
213 | (void)sleep(1); | ||
214 | (void)wait(&sta); | ||
215 | (void)memset(&msgds, 0, sizeof(struct msqid_ds)); | ||
216 | |||
217 | ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0); | ||
218 | |||
219 | if (pid != msgds.msg_lspid) | ||
220 | atf_tc_fail("the PID of last msgsnd(2) was not updated"); | ||
221 | |||
222 | pid = fork(); | ||
223 | ATF_REQUIRE(pid >= 0); | ||
224 | |||
225 | if (pid == 0) { | ||
226 | |||
227 | (void)msgrcv(id, &msg, | ||
228 | sizeof(struct msg), MSG_MTYPE_1, IPC_NOWAIT); | ||
229 | |||
230 | _exit(EXIT_SUCCESS); | ||
231 | } | ||
232 | |||
233 | (void)sleep(1); | ||
234 | (void)wait(&sta); | ||
235 | (void)memset(&msgds, 0, sizeof(struct msqid_ds)); | ||
236 | |||
237 | ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0); | ||
238 | |||
239 | if (pid != msgds.msg_lrpid) | ||
240 | atf_tc_fail("the PID of last msgrcv(2) was not updated"); | ||
241 | |||
242 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
243 | } | ||
244 | |||
245 | ATF_TC_CLEANUP(msgctl_pid, tc) | ||
246 | { | ||
247 | clean(); | ||
248 | } | ||
249 | |||
250 | ATF_TC_WITH_CLEANUP(msgctl_set); | ||
251 | ATF_TC_HEAD(msgctl_set, tc) | ||
252 | { | ||
253 | atf_tc_set_md_var(tc, "descr", "Test msgctl(2) with IPC_SET"); | ||
254 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
255 | } | ||
256 | |||
257 | ATF_TC_BODY(msgctl_set, tc) | ||
258 | { | ||
259 | struct msqid_ds msgds; | ||
260 | struct passwd *pw; | ||
261 | int id; | ||
262 | |||
263 | (void)memset(&msgds, 0, sizeof(struct msqid_ds)); | ||
264 | |||
265 | pw = getpwnam("nobody"); | ||
266 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
267 | |||
268 | ATF_REQUIRE(id != -1); | ||
269 | ATF_REQUIRE(pw != NULL); | ||
270 | ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0); | ||
271 | |||
272 | msgds.msg_perm.uid = pw->pw_uid; | ||
273 | |||
274 | if (msgctl(id, IPC_SET, &msgds) != 0) | ||
275 | atf_tc_fail("root failed to change the UID of message queue"); | ||
276 | |||
277 | msgds.msg_perm.uid = getuid(); | ||
278 | msgds.msg_perm.gid = pw->pw_gid; | ||
279 | |||
280 | if (msgctl(id, IPC_SET, &msgds) != 0) | ||
281 | atf_tc_fail("root failed to change the GID of message queue"); | ||
282 | |||
283 | /* | ||
284 | * Note: setting the qbytes to zero fails even as root. | ||
285 | */ | ||
286 | msgds.msg_qbytes = 1; | ||
287 | msgds.msg_perm.gid = getgid(); | ||
288 | |||
289 | if (msgctl(id, IPC_SET, &msgds) != 0) | ||
290 | atf_tc_fail("root failed to change qbytes of message queue"); | ||
291 | |||
292 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
293 | } | ||
294 | |||
295 | ATF_TC_CLEANUP(msgctl_set, tc) | ||
296 | { | ||
297 | clean(); | ||
298 | } | ||
299 | |||
300 | ATF_TC_WITH_CLEANUP(msgctl_time); | ||
301 | ATF_TC_HEAD(msgctl_time, tc) | ||
302 | { | ||
303 | atf_tc_set_md_var(tc, "descr", "Test that access times are updated"); | ||
304 | } | ||
305 | |||
306 | ATF_TC_BODY(msgctl_time, tc) | ||
307 | { | ||
308 | struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; | ||
309 | struct msqid_ds msgds; | ||
310 | time_t t; | ||
311 | int id; | ||
312 | |||
313 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
314 | ATF_REQUIRE(id != -1); | ||
315 | |||
316 | t = time(NULL); | ||
317 | |||
318 | (void)memset(&msgds, 0, sizeof(struct msqid_ds)); | ||
319 | (void)msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT); | ||
320 | (void)msgctl(id, IPC_STAT, &msgds); | ||
321 | |||
322 | if (llabs(t - msgds.msg_stime) > 1) | ||
323 | atf_tc_fail("time of last msgsnd(2) was not updated"); | ||
324 | |||
325 | if (msgds.msg_rtime != 0) | ||
326 | atf_tc_fail("time of last msgrcv(2) was updated incorrectly"); | ||
327 | |||
328 | t = time(NULL); | ||
329 | |||
330 | (void)memset(&msgds, 0, sizeof(struct msqid_ds)); | ||
331 | (void)msgrcv(id, &msg, sizeof(struct msg), MSG_MTYPE_1, IPC_NOWAIT); | ||
332 | (void)msgctl(id, IPC_STAT, &msgds); | ||
333 | |||
334 | if (llabs(t - msgds.msg_rtime) > 1) | ||
335 | atf_tc_fail("time of last msgrcv(2) was not updated"); | ||
336 | |||
337 | /* | ||
338 | * Note: this is non-zero even after the memset(3). | ||
339 | */ | ||
340 | if (msgds.msg_stime == 0) | ||
341 | atf_tc_fail("time of last msgsnd(2) was updated incorrectly"); | ||
342 | |||
343 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
344 | } | ||
345 | |||
346 | ATF_TC_CLEANUP(msgctl_time, tc) | ||
347 | { | ||
348 | clean(); | ||
349 | } | ||
350 | |||
351 | static volatile int sig_caught; | ||
352 | |||
353 | static void | ||
354 | sigsys_handler(int signum) | ||
355 | { | ||
356 | |||
357 | sig_caught = signum; | ||
358 | } | ||
359 | |||
360 | static int | ||
361 | no_kernel_sysvmsg(void) | ||
362 | { | ||
363 | int id; | ||
364 | void (*osig)(int); | ||
365 | |||
366 | sig_caught = 0; | ||
367 | osig = signal(SIGSYS, sigsys_handler); | ||
368 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
369 | if (sig_caught || id == -1) | ||
370 | return 1; | ||
371 | |||
372 | (void)msgctl(id, IPC_RMID, 0); | ||
373 | (void)signal(SIGSYS, osig); | ||
374 | |||
375 | return 0; | ||
376 | } | ||
377 | |||
378 | ATF_TC(msgctl_query); | ||
379 | ATF_TC_HEAD(msgctl_query, tc) | ||
380 | { | ||
381 | atf_tc_set_md_var(tc, "descr", "Skip msgctl_* tests - no SYSVMSG"); | ||
382 | } | ||
383 | ATF_TC_BODY(msgctl_query, tc) | ||
384 | { | ||
385 | atf_tc_skip("No SYSVMSG in kernel"); | ||
386 | } | ||
387 | |||
388 | ATF_TP_ADD_TCS(tp) | ||
389 | { | ||
390 | |||
391 | if (no_kernel_sysvmsg()) { | ||
392 | ATF_TP_ADD_TC(tp, msgctl_query); | ||
393 | } else { | ||
394 | ATF_TP_ADD_TC(tp, msgctl_err); | ||
395 | ATF_TP_ADD_TC(tp, msgctl_perm); | ||
396 | ATF_TP_ADD_TC(tp, msgctl_pid); | ||
397 | ATF_TP_ADD_TC(tp, msgctl_set); | ||
398 | ATF_TP_ADD_TC(tp, msgctl_time); | ||
399 | } | ||
400 | |||
401 | return atf_no_error(); | ||
402 | } | ||
diff --git a/src/regress/lib/libc/sys/t_msgget.c b/src/regress/lib/libc/sys/t_msgget.c deleted file mode 100644 index f4d3013b6f..0000000000 --- a/src/regress/lib/libc/sys/t_msgget.c +++ /dev/null | |||
@@ -1,337 +0,0 @@ | |||
1 | /* $OpenBSD: t_msgget.c,v 1.3 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_msgget.c,v 1.3 2017/10/08 08:31:05 kre Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/msg.h> | ||
36 | #include <sys/stat.h> | ||
37 | #include <sys/sysctl.h> | ||
38 | #include <sys/wait.h> | ||
39 | |||
40 | #include "atf-c.h" | ||
41 | #include <errno.h> | ||
42 | #include <pwd.h> | ||
43 | #include <stdio.h> | ||
44 | #include <stdlib.h> | ||
45 | #include <signal.h> | ||
46 | #include <string.h> | ||
47 | #include <sysexits.h> | ||
48 | #include <time.h> | ||
49 | #include <unistd.h> | ||
50 | |||
51 | #define MSG_KEY 12345689 | ||
52 | |||
53 | static void clean(void); | ||
54 | |||
55 | static void | ||
56 | clean(void) | ||
57 | { | ||
58 | int id; | ||
59 | |||
60 | if ((id = msgget(MSG_KEY, 0)) != -1) | ||
61 | (void)msgctl(id, IPC_RMID, 0); | ||
62 | } | ||
63 | |||
64 | ATF_TC_WITH_CLEANUP(msgget_excl); | ||
65 | ATF_TC_HEAD(msgget_excl, tc) | ||
66 | { | ||
67 | atf_tc_set_md_var(tc, "descr", "Test msgget(2) with IPC_EXCL"); | ||
68 | } | ||
69 | |||
70 | ATF_TC_BODY(msgget_excl, tc) | ||
71 | { | ||
72 | int id; | ||
73 | |||
74 | /* | ||
75 | * Create a message queue and re-open it with | ||
76 | * O_CREAT and IPC_EXCL set. This should fail. | ||
77 | */ | ||
78 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
79 | |||
80 | if (id < 0) | ||
81 | atf_tc_fail("failed to create message queue"); | ||
82 | |||
83 | errno = 0; | ||
84 | |||
85 | if (msgget(MSG_KEY, IPC_CREAT | IPC_EXCL | 0600) != -1) | ||
86 | atf_tc_fail("msgget(2) failed for IPC_EXCL"); | ||
87 | |||
88 | ATF_REQUIRE(errno == EEXIST); | ||
89 | |||
90 | /* | ||
91 | * However, the same call should succeed | ||
92 | * when IPC_EXCL is not set in the flags. | ||
93 | */ | ||
94 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
95 | |||
96 | if (id < 0) | ||
97 | atf_tc_fail("msgget(2) failed to re-open"); | ||
98 | |||
99 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
100 | } | ||
101 | |||
102 | ATF_TC_CLEANUP(msgget_excl, tc) | ||
103 | { | ||
104 | clean(); | ||
105 | } | ||
106 | |||
107 | ATF_TC_WITH_CLEANUP(msgget_exit); | ||
108 | ATF_TC_HEAD(msgget_exit, tc) | ||
109 | { | ||
110 | atf_tc_set_md_var(tc, "descr", | ||
111 | "Test that XSI message queues are " | ||
112 | "not removed when the process exits"); | ||
113 | } | ||
114 | |||
115 | ATF_TC_BODY(msgget_exit, tc) | ||
116 | { | ||
117 | int id, sta; | ||
118 | pid_t pid; | ||
119 | |||
120 | pid = fork(); | ||
121 | ATF_REQUIRE(pid >= 0); | ||
122 | |||
123 | if (pid == 0) { | ||
124 | |||
125 | if (msgget(MSG_KEY, IPC_CREAT | IPC_EXCL | 0600) == -1) | ||
126 | _exit(EXIT_FAILURE); | ||
127 | |||
128 | _exit(EXIT_SUCCESS); | ||
129 | } | ||
130 | |||
131 | (void)wait(&sta); | ||
132 | |||
133 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
134 | atf_tc_fail("failed to create message queue"); | ||
135 | |||
136 | id = msgget(MSG_KEY, 0); | ||
137 | |||
138 | if (id == -1) | ||
139 | atf_tc_fail("message queue was removed on process exit"); | ||
140 | |||
141 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
142 | } | ||
143 | |||
144 | ATF_TC_CLEANUP(msgget_exit, tc) | ||
145 | { | ||
146 | clean(); | ||
147 | } | ||
148 | |||
149 | ATF_TC_WITH_CLEANUP(msgget_init); | ||
150 | ATF_TC_HEAD(msgget_init, tc) | ||
151 | { | ||
152 | atf_tc_set_md_var(tc, "descr", | ||
153 | "Test that msgget(2) initializes data structures properly"); | ||
154 | } | ||
155 | |||
156 | ATF_TC_BODY(msgget_init, tc) | ||
157 | { | ||
158 | const uid_t uid = geteuid(); | ||
159 | const gid_t gid = getegid(); | ||
160 | struct msqid_ds msgds; | ||
161 | time_t t; | ||
162 | int id; | ||
163 | |||
164 | (void)memset(&msgds, 0x9, sizeof(struct msqid_ds)); | ||
165 | |||
166 | t = time(NULL); | ||
167 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
168 | |||
169 | ATF_REQUIRE(id !=-1); | ||
170 | ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0); | ||
171 | |||
172 | ATF_CHECK(msgds.msg_qnum == 0); | ||
173 | ATF_CHECK(msgds.msg_lspid == 0); | ||
174 | ATF_CHECK(msgds.msg_lrpid == 0); | ||
175 | ATF_CHECK(msgds.msg_rtime == 0); | ||
176 | ATF_CHECK(msgds.msg_stime == 0); | ||
177 | ATF_CHECK(msgds.msg_perm.uid == uid); | ||
178 | ATF_CHECK(msgds.msg_perm.gid == gid); | ||
179 | ATF_CHECK(msgds.msg_perm.cuid == uid); | ||
180 | ATF_CHECK(msgds.msg_perm.cgid == gid); | ||
181 | ATF_CHECK(msgds.msg_perm.mode == 0600); | ||
182 | |||
183 | if (llabs(t - msgds.msg_ctime) > 5) | ||
184 | atf_tc_fail("msgget(2) initialized current time incorrectly"); | ||
185 | |||
186 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
187 | } | ||
188 | |||
189 | ATF_TC_CLEANUP(msgget_init, tc) | ||
190 | { | ||
191 | clean(); | ||
192 | } | ||
193 | |||
194 | ATF_TC(msgget_limit); | ||
195 | ATF_TC_HEAD(msgget_limit, tc) | ||
196 | { | ||
197 | atf_tc_set_md_var(tc, "descr", "Test msgget(2) against system limits"); | ||
198 | } | ||
199 | |||
200 | ATF_TC_BODY(msgget_limit, tc) | ||
201 | { | ||
202 | size_t len = sizeof(int); | ||
203 | bool fail = false; | ||
204 | int i, lim = 0; | ||
205 | int *buf; | ||
206 | |||
207 | if (sysctlbyname("kern.ipc.msgmni", &lim, &len, NULL, 0) != 0) | ||
208 | atf_tc_skip("failed to read kern.ipc.msgmni sysctl"); | ||
209 | |||
210 | buf = calloc(lim + 1, sizeof(*buf)); | ||
211 | ATF_REQUIRE(buf != NULL); | ||
212 | |||
213 | for (i = 0; i < lim; i++) { | ||
214 | |||
215 | buf[i] = msgget(MSG_KEY + i, IPC_CREAT | IPC_EXCL | 0600); | ||
216 | |||
217 | (void)fprintf(stderr, "key[%d] = %d\n", i, buf[i]); | ||
218 | |||
219 | /* | ||
220 | * This test only works when there are zero existing | ||
221 | * message queues. Thus, bypass the unit test when | ||
222 | * this precondition is not met, for reason or another. | ||
223 | */ | ||
224 | if (buf[i] == -1) | ||
225 | goto out; | ||
226 | } | ||
227 | |||
228 | i++; | ||
229 | errno = 0; | ||
230 | |||
231 | buf[i] = msgget(MSG_KEY + i, IPC_CREAT | IPC_EXCL | 0600); | ||
232 | |||
233 | if (buf[i] != -1 || errno != ENOSPC) | ||
234 | fail = true; | ||
235 | |||
236 | out: /* Remember to clean-up. */ | ||
237 | for (i = 0; i < lim; i++) | ||
238 | (void)msgctl(buf[i], IPC_RMID, 0); | ||
239 | |||
240 | free(buf); | ||
241 | |||
242 | if (fail != false) | ||
243 | atf_tc_fail("msgget(2) opened more than %d queues", lim); | ||
244 | } | ||
245 | |||
246 | ATF_TC_WITH_CLEANUP(msgget_mode); | ||
247 | ATF_TC_HEAD(msgget_mode, tc) | ||
248 | { | ||
249 | atf_tc_set_md_var(tc, "descr", "Test different modes with msgget(2)"); | ||
250 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
251 | } | ||
252 | |||
253 | ATF_TC_BODY(msgget_mode, tc) | ||
254 | { | ||
255 | static const mode_t mode[] = { | ||
256 | S_IRWXU, S_IRUSR, S_IWUSR, S_IXUSR, S_IRWXG, S_IRGRP, | ||
257 | S_IWGRP, S_IXGRP, S_IRWXO, S_IROTH, S_IWOTH, S_IXOTH | ||
258 | }; | ||
259 | |||
260 | struct msqid_ds msgds; | ||
261 | size_t i; | ||
262 | int id; | ||
263 | |||
264 | for (i = 0; i < __arraycount(mode); i++) { | ||
265 | |||
266 | (void)fprintf(stderr, "testing mode %d\n", mode[i]); | ||
267 | (void)memset(&msgds, 0, sizeof(struct msqid_ds)); | ||
268 | |||
269 | id = msgget(MSG_KEY, IPC_CREAT | IPC_EXCL | (int)mode[i]); | ||
270 | |||
271 | ATF_REQUIRE(id != -1); | ||
272 | ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0); | ||
273 | ATF_REQUIRE(msgds.msg_perm.mode == mode[i]); | ||
274 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | ATF_TC_CLEANUP(msgget_mode, tc) | ||
279 | { | ||
280 | clean(); | ||
281 | } | ||
282 | |||
283 | static volatile int sig_caught; | ||
284 | |||
285 | static void | ||
286 | sigsys_handler(int signum) | ||
287 | { | ||
288 | |||
289 | sig_caught = signum; | ||
290 | } | ||
291 | |||
292 | static int | ||
293 | no_kernel_sysvmsg(void) | ||
294 | { | ||
295 | int id; | ||
296 | void (*osig)(int); | ||
297 | |||
298 | sig_caught = 0; | ||
299 | osig = signal(SIGSYS, sigsys_handler); | ||
300 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
301 | if (sig_caught || id == -1) | ||
302 | return 1; | ||
303 | |||
304 | (void)msgctl(id, IPC_RMID, 0); | ||
305 | (void)signal(SIGSYS, osig); | ||
306 | |||
307 | return 0; | ||
308 | } | ||
309 | |||
310 | ATF_TC(msgget_query); | ||
311 | ATF_TC_HEAD(msgget_query, tc) | ||
312 | { | ||
313 | atf_tc_set_md_var(tc, "descr", "Skip msgget_* tests - no SYSVMSG"); | ||
314 | } | ||
315 | ATF_TC_BODY(msgget_query, tc) | ||
316 | { | ||
317 | atf_tc_skip("No SYSVMSG in kernel"); | ||
318 | } | ||
319 | |||
320 | ATF_TP_ADD_TCS(tp) | ||
321 | { | ||
322 | |||
323 | if (no_kernel_sysvmsg()) { | ||
324 | ATF_TP_ADD_TC(tp, msgget_query); | ||
325 | } else { | ||
326 | ATF_TP_ADD_TC(tp, msgget_excl); | ||
327 | ATF_TP_ADD_TC(tp, msgget_exit); | ||
328 | ATF_TP_ADD_TC(tp, msgget_init); | ||
329 | #ifndef __OpenBSD__ | ||
330 | /* sysctl kern.ipc.msgmni not available */ | ||
331 | ATF_TP_ADD_TC(tp, msgget_limit); | ||
332 | #endif | ||
333 | ATF_TP_ADD_TC(tp, msgget_mode); | ||
334 | } | ||
335 | |||
336 | return atf_no_error(); | ||
337 | } | ||
diff --git a/src/regress/lib/libc/sys/t_msgrcv.c b/src/regress/lib/libc/sys/t_msgrcv.c deleted file mode 100644 index 2e73b3d5ba..0000000000 --- a/src/regress/lib/libc/sys/t_msgrcv.c +++ /dev/null | |||
@@ -1,385 +0,0 @@ | |||
1 | /* $OpenBSD: t_msgrcv.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_msgrcv.c,v 1.5 2017/10/08 08:31:05 kre Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/msg.h> | ||
36 | #include <sys/stat.h> | ||
37 | #include <sys/sysctl.h> | ||
38 | #include <sys/wait.h> | ||
39 | |||
40 | #include "atf-c.h" | ||
41 | #include <errno.h> | ||
42 | #include <limits.h> | ||
43 | #include <pwd.h> | ||
44 | #include <signal.h> | ||
45 | #include <stdio.h> | ||
46 | #include <stdlib.h> | ||
47 | #include <string.h> | ||
48 | #include <sysexits.h> | ||
49 | #include <time.h> | ||
50 | #include <unistd.h> | ||
51 | |||
52 | #define MSG_KEY 1234 | ||
53 | #define MSG_MTYPE_1 0x41 | ||
54 | #define MSG_MTYPE_2 0x42 | ||
55 | #define MSG_MTYPE_3 0x43 | ||
56 | #define MSG_LEN 3 | ||
57 | |||
58 | struct msg { | ||
59 | long mtype; | ||
60 | char buf[MSG_LEN]; | ||
61 | }; | ||
62 | |||
63 | static void clean(void); | ||
64 | |||
65 | static void | ||
66 | clean(void) | ||
67 | { | ||
68 | int id; | ||
69 | |||
70 | if ((id = msgget(MSG_KEY, 0)) != -1) | ||
71 | (void)msgctl(id, IPC_RMID, 0); | ||
72 | } | ||
73 | |||
74 | ATF_TC_WITH_CLEANUP(msgrcv_basic); | ||
75 | ATF_TC_HEAD(msgrcv_basic, tc) | ||
76 | { | ||
77 | atf_tc_set_md_var(tc, "descr", "A basic test of msgrcv(2)"); | ||
78 | } | ||
79 | |||
80 | ATF_TC_BODY(msgrcv_basic, tc) | ||
81 | { | ||
82 | struct msg msg1 = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; | ||
83 | struct msg msg2 = { MSG_MTYPE_1, { 'x', 'y', 'z' } }; | ||
84 | int id; | ||
85 | |||
86 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
87 | ATF_REQUIRE(id != -1); | ||
88 | |||
89 | (void)msgsnd(id, &msg1, MSG_LEN, IPC_NOWAIT); | ||
90 | (void)msgrcv(id, &msg2, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT); | ||
91 | |||
92 | ATF_CHECK(msg1.buf[0] == msg2.buf[0]); | ||
93 | ATF_CHECK(msg1.buf[1] == msg2.buf[1]); | ||
94 | ATF_CHECK(msg1.buf[2] == msg2.buf[2]); | ||
95 | |||
96 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
97 | } | ||
98 | |||
99 | ATF_TC_CLEANUP(msgrcv_basic, tc) | ||
100 | { | ||
101 | clean(); | ||
102 | } | ||
103 | |||
104 | ATF_TC_WITH_CLEANUP(msgrcv_block); | ||
105 | ATF_TC_HEAD(msgrcv_block, tc) | ||
106 | { | ||
107 | atf_tc_set_md_var(tc, "descr", "Test that msgrcv(2) blocks"); | ||
108 | } | ||
109 | |||
110 | ATF_TC_BODY(msgrcv_block, tc) | ||
111 | { | ||
112 | struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; | ||
113 | int id, sta; | ||
114 | pid_t pid; | ||
115 | |||
116 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
117 | ATF_REQUIRE(id != -1); | ||
118 | |||
119 | pid = fork(); | ||
120 | ATF_REQUIRE(pid >= 0); | ||
121 | |||
122 | if (pid == 0) { | ||
123 | |||
124 | if (msgrcv(id, &msg, MSG_LEN, MSG_MTYPE_1, 0) < 0) | ||
125 | _exit(EXIT_FAILURE); | ||
126 | |||
127 | _exit(EXIT_SUCCESS); | ||
128 | } | ||
129 | |||
130 | /* | ||
131 | * Below msgsnd(2) should unblock the child, | ||
132 | * and hence kill(2) should fail with ESRCH. | ||
133 | */ | ||
134 | (void)sleep(1); | ||
135 | (void)msgsnd(id, &msg, MSG_LEN, IPC_NOWAIT); | ||
136 | (void)sleep(1); | ||
137 | (void)kill(pid, SIGKILL); | ||
138 | (void)wait(&sta); | ||
139 | |||
140 | if (WIFEXITED(sta) == 0 || WIFSIGNALED(sta) != 0) | ||
141 | atf_tc_fail("msgrcv(2) did not block"); | ||
142 | |||
143 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
144 | } | ||
145 | |||
146 | ATF_TC_CLEANUP(msgrcv_block, tc) | ||
147 | { | ||
148 | clean(); | ||
149 | } | ||
150 | |||
151 | ATF_TC_WITH_CLEANUP(msgrcv_err); | ||
152 | ATF_TC_HEAD(msgrcv_err, tc) | ||
153 | { | ||
154 | atf_tc_set_md_var(tc, "descr", "Test errors from msgrcv(2)"); | ||
155 | } | ||
156 | |||
157 | ATF_TC_BODY(msgrcv_err, tc) | ||
158 | { | ||
159 | struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; | ||
160 | int id, r = 0; | ||
161 | |||
162 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
163 | ATF_REQUIRE(id != -1); | ||
164 | |||
165 | errno = 0; | ||
166 | |||
167 | ATF_REQUIRE_ERRNO(ENOMSG, msgrcv(id, &msg, | ||
168 | MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT) == -1); | ||
169 | |||
170 | ATF_REQUIRE(msgsnd(id, &msg, MSG_LEN, IPC_NOWAIT) == 0); | ||
171 | |||
172 | errno = 0; | ||
173 | |||
174 | ATF_REQUIRE_ERRNO(EFAULT, msgrcv(id, (void *)-1, | ||
175 | MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT) == -1); | ||
176 | |||
177 | errno = 0; | ||
178 | |||
179 | ATF_REQUIRE_ERRNO(EINVAL, msgrcv(-1, &msg, | ||
180 | MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT) == -1); | ||
181 | |||
182 | errno = 0; | ||
183 | |||
184 | ATF_REQUIRE_ERRNO(EINVAL, msgrcv(-1, &msg, | ||
185 | SSIZE_MAX, MSG_MTYPE_1, IPC_NOWAIT) == -1); | ||
186 | |||
187 | ATF_REQUIRE(msgsnd(id, &msg, MSG_LEN, IPC_NOWAIT) == 0); | ||
188 | |||
189 | errno = 0; | ||
190 | |||
191 | ATF_REQUIRE_ERRNO(E2BIG, msgrcv(id, &r, | ||
192 | MSG_LEN - 1, MSG_MTYPE_1, IPC_NOWAIT) == -1); | ||
193 | |||
194 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
195 | } | ||
196 | |||
197 | ATF_TC_CLEANUP(msgrcv_err, tc) | ||
198 | { | ||
199 | clean(); | ||
200 | } | ||
201 | |||
202 | |||
203 | ATF_TC_WITH_CLEANUP(msgrcv_mtype); | ||
204 | ATF_TC_HEAD(msgrcv_mtype, tc) | ||
205 | { | ||
206 | atf_tc_set_md_var(tc, "descr", "Test message types with msgrcv(2)"); | ||
207 | } | ||
208 | |||
209 | ATF_TC_BODY(msgrcv_mtype, tc) | ||
210 | { | ||
211 | struct msg msg1 = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; | ||
212 | struct msg msg2 = { MSG_MTYPE_3, { 'x', 'y', 'z' } }; | ||
213 | int id; | ||
214 | |||
215 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
216 | ATF_REQUIRE(id != -1); | ||
217 | |||
218 | (void)msgsnd(id, &msg1, MSG_LEN, IPC_NOWAIT); | ||
219 | (void)msgrcv(id, &msg2, MSG_LEN, MSG_MTYPE_2, IPC_NOWAIT); | ||
220 | |||
221 | ATF_CHECK(msg1.buf[0] != msg2.buf[0]); /* Different mtype. */ | ||
222 | ATF_CHECK(msg1.buf[1] != msg2.buf[1]); | ||
223 | ATF_CHECK(msg1.buf[2] != msg2.buf[2]); | ||
224 | |||
225 | (void)msgrcv(id, &msg2, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT); | ||
226 | |||
227 | ATF_CHECK(msg1.buf[0] == msg2.buf[0]); /* Same mtype. */ | ||
228 | ATF_CHECK(msg1.buf[1] == msg2.buf[1]); | ||
229 | ATF_CHECK(msg1.buf[2] == msg2.buf[2]); | ||
230 | |||
231 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
232 | } | ||
233 | |||
234 | ATF_TC_CLEANUP(msgrcv_mtype, tc) | ||
235 | { | ||
236 | clean(); | ||
237 | } | ||
238 | |||
239 | ATF_TC_WITH_CLEANUP(msgrcv_nonblock); | ||
240 | ATF_TC_HEAD(msgrcv_nonblock, tc) | ||
241 | { | ||
242 | atf_tc_set_md_var(tc, "descr", "Test msgrcv(2) with IPC_NOWAIT"); | ||
243 | atf_tc_set_md_var(tc, "timeout", "10"); | ||
244 | } | ||
245 | |||
246 | ATF_TC_BODY(msgrcv_nonblock, tc) | ||
247 | { | ||
248 | struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; | ||
249 | const ssize_t n = 10; | ||
250 | int id, sta; | ||
251 | ssize_t i; | ||
252 | pid_t pid; | ||
253 | |||
254 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
255 | ATF_REQUIRE(id != -1); | ||
256 | |||
257 | for (i = 0; i < n; i++) { | ||
258 | |||
259 | ATF_REQUIRE(msgsnd(id, &msg, MSG_LEN, IPC_NOWAIT) == 0); | ||
260 | } | ||
261 | |||
262 | pid = fork(); | ||
263 | ATF_REQUIRE(pid >= 0); | ||
264 | |||
265 | if (pid == 0) { | ||
266 | |||
267 | while (i != 0) { | ||
268 | |||
269 | if (msgrcv(id, &msg, MSG_LEN, MSG_MTYPE_1, | ||
270 | IPC_NOWAIT) == -1) | ||
271 | _exit(EXIT_FAILURE); | ||
272 | |||
273 | i--; | ||
274 | } | ||
275 | |||
276 | _exit(EXIT_SUCCESS); | ||
277 | } | ||
278 | |||
279 | (void)sleep(2); | ||
280 | (void)kill(pid, SIGKILL); | ||
281 | (void)wait(&sta); | ||
282 | |||
283 | if (WIFSIGNALED(sta) != 0 || WTERMSIG(sta) == SIGKILL) | ||
284 | atf_tc_fail("msgrcv(2) blocked with IPC_NOWAIT"); | ||
285 | |||
286 | if (WIFEXITED(sta) == 0 && WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
287 | atf_tc_fail("msgrcv(2) failed"); | ||
288 | |||
289 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
290 | } | ||
291 | |||
292 | ATF_TC_CLEANUP(msgrcv_nonblock, tc) | ||
293 | { | ||
294 | clean(); | ||
295 | } | ||
296 | |||
297 | ATF_TC_WITH_CLEANUP(msgrcv_truncate); | ||
298 | ATF_TC_HEAD(msgrcv_truncate, tc) | ||
299 | { | ||
300 | atf_tc_set_md_var(tc, "descr", "Test msgrcv(2) with MSG_NOERROR"); | ||
301 | } | ||
302 | |||
303 | ATF_TC_BODY(msgrcv_truncate, tc) | ||
304 | { | ||
305 | #define MSG_SMALLLEN 2 | ||
306 | struct msgsmall { | ||
307 | long mtype; | ||
308 | char buf[MSG_SMALLLEN]; | ||
309 | }; | ||
310 | |||
311 | struct msg msg1 = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; | ||
312 | struct msgsmall msg2 = { MSG_MTYPE_1, { 'x', 'y' } }; | ||
313 | int id; | ||
314 | |||
315 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
316 | ATF_REQUIRE(id != -1); | ||
317 | |||
318 | (void)msgsnd(id, &msg1, MSG_LEN, IPC_NOWAIT); | ||
319 | (void)msgrcv(id, &msg2, MSG_SMALLLEN, | ||
320 | MSG_MTYPE_1, IPC_NOWAIT | MSG_NOERROR); | ||
321 | |||
322 | ATF_CHECK(msg1.buf[0] == msg2.buf[0]); | ||
323 | ATF_CHECK(msg1.buf[1] == msg2.buf[1]); | ||
324 | |||
325 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
326 | } | ||
327 | |||
328 | ATF_TC_CLEANUP(msgrcv_truncate, tc) | ||
329 | { | ||
330 | clean(); | ||
331 | } | ||
332 | |||
333 | static volatile int sig_caught; | ||
334 | |||
335 | static void | ||
336 | sigsys_handler(int signum) | ||
337 | { | ||
338 | |||
339 | sig_caught = signum; | ||
340 | } | ||
341 | |||
342 | static int | ||
343 | no_kernel_sysvmsg(void) | ||
344 | { | ||
345 | int id; | ||
346 | void (*osig)(int); | ||
347 | |||
348 | sig_caught = 0; | ||
349 | osig = signal(SIGSYS, sigsys_handler); | ||
350 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
351 | if (sig_caught || id == -1) | ||
352 | return 1; | ||
353 | |||
354 | (void)msgctl(id, IPC_RMID, 0); | ||
355 | (void)signal(SIGSYS, osig); | ||
356 | |||
357 | return 0; | ||
358 | } | ||
359 | |||
360 | ATF_TC(msgrcv_query); | ||
361 | ATF_TC_HEAD(msgrcv_query, tc) | ||
362 | { | ||
363 | atf_tc_set_md_var(tc, "descr", "Skip msgrcv_* tests - no SYSVMSG"); | ||
364 | } | ||
365 | ATF_TC_BODY(msgrcv_query, tc) | ||
366 | { | ||
367 | atf_tc_skip("No SYSVMSG in kernel"); | ||
368 | } | ||
369 | |||
370 | ATF_TP_ADD_TCS(tp) | ||
371 | { | ||
372 | |||
373 | if (no_kernel_sysvmsg()) { | ||
374 | ATF_TP_ADD_TC(tp, msgrcv_query); | ||
375 | } else { | ||
376 | ATF_TP_ADD_TC(tp, msgrcv_basic); | ||
377 | ATF_TP_ADD_TC(tp, msgrcv_block); | ||
378 | ATF_TP_ADD_TC(tp, msgrcv_err); | ||
379 | ATF_TP_ADD_TC(tp, msgrcv_mtype); | ||
380 | ATF_TP_ADD_TC(tp, msgrcv_nonblock); | ||
381 | ATF_TP_ADD_TC(tp, msgrcv_truncate); | ||
382 | } | ||
383 | |||
384 | return atf_no_error(); | ||
385 | } | ||
diff --git a/src/regress/lib/libc/sys/t_msgsnd.c b/src/regress/lib/libc/sys/t_msgsnd.c deleted file mode 100644 index 4ea2aa485e..0000000000 --- a/src/regress/lib/libc/sys/t_msgsnd.c +++ /dev/null | |||
@@ -1,381 +0,0 @@ | |||
1 | /* $OpenBSD: t_msgsnd.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_msgsnd.c,v 1.4 2017/10/08 08:31:05 kre Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/msg.h> | ||
36 | #include <sys/stat.h> | ||
37 | #include <sys/sysctl.h> | ||
38 | #include <sys/wait.h> | ||
39 | |||
40 | #include "atf-c.h" | ||
41 | #include <errno.h> | ||
42 | #include <limits.h> | ||
43 | #include <pwd.h> | ||
44 | #include <signal.h> | ||
45 | #include <stdio.h> | ||
46 | #include <stdlib.h> | ||
47 | #include <string.h> | ||
48 | #include <sysexits.h> | ||
49 | #include <time.h> | ||
50 | #include <unistd.h> | ||
51 | |||
52 | #define MSG_KEY 1234 | ||
53 | #define MSG_MTYPE_1 0x41 | ||
54 | #define MSG_MTYPE_2 0x42 | ||
55 | #define MSG_MTYPE_3 0x43 | ||
56 | |||
57 | struct msg { | ||
58 | long mtype; | ||
59 | char buf[3]; | ||
60 | }; | ||
61 | |||
62 | static void clean(void); | ||
63 | |||
64 | static void | ||
65 | clean(void) | ||
66 | { | ||
67 | int id; | ||
68 | |||
69 | if ((id = msgget(MSG_KEY, 0)) != -1) | ||
70 | (void)msgctl(id, IPC_RMID, 0); | ||
71 | } | ||
72 | |||
73 | ATF_TC_WITH_CLEANUP(msgsnd_block); | ||
74 | ATF_TC_HEAD(msgsnd_block, tc) | ||
75 | { | ||
76 | atf_tc_set_md_var(tc, "descr", "Test that msgsnd(2) blocks"); | ||
77 | atf_tc_set_md_var(tc, "timeout", "10"); | ||
78 | } | ||
79 | |||
80 | ATF_TC_BODY(msgsnd_block, tc) | ||
81 | { | ||
82 | struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; | ||
83 | int id, sta; | ||
84 | pid_t pid; | ||
85 | |||
86 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
87 | ATF_REQUIRE(id != -1); | ||
88 | |||
89 | pid = fork(); | ||
90 | ATF_REQUIRE(pid >= 0); | ||
91 | |||
92 | if (pid == 0) { | ||
93 | |||
94 | /* | ||
95 | * Enqueue messages until some limit (e.g. the maximum | ||
96 | * number of messages in the queue or the maximum number | ||
97 | * of bytes in the queue) is reached. After this the call | ||
98 | * should block when the IPC_NOWAIT is not set. | ||
99 | */ | ||
100 | for (;;) { | ||
101 | |||
102 | if (msgsnd(id, &msg, sizeof(struct msg), 0) < 0) | ||
103 | _exit(EXIT_FAILURE); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | (void)sleep(2); | ||
108 | (void)kill(pid, SIGKILL); | ||
109 | (void)wait(&sta); | ||
110 | |||
111 | if (WIFEXITED(sta) != 0 || WIFSIGNALED(sta) == 0) | ||
112 | atf_tc_fail("msgsnd(2) did not block"); | ||
113 | |||
114 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
115 | } | ||
116 | |||
117 | ATF_TC_CLEANUP(msgsnd_block, tc) | ||
118 | { | ||
119 | clean(); | ||
120 | } | ||
121 | |||
122 | ATF_TC_WITH_CLEANUP(msgsnd_count); | ||
123 | ATF_TC_HEAD(msgsnd_count, tc) | ||
124 | { | ||
125 | atf_tc_set_md_var(tc, "descr", | ||
126 | "Test that msgsnd(2) increments the amount of " | ||
127 | "message in the queue, as given by msgctl(2)"); | ||
128 | atf_tc_set_md_var(tc, "timeout", "10"); | ||
129 | } | ||
130 | |||
131 | ATF_TC_BODY(msgsnd_count, tc) | ||
132 | { | ||
133 | struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; | ||
134 | struct msqid_ds ds; | ||
135 | size_t i = 0; | ||
136 | int id, rv; | ||
137 | |||
138 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
139 | ATF_REQUIRE(id != -1); | ||
140 | |||
141 | for (;;) { | ||
142 | |||
143 | errno = 0; | ||
144 | rv = msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT); | ||
145 | |||
146 | if (rv == 0) { | ||
147 | i++; | ||
148 | continue; | ||
149 | } | ||
150 | |||
151 | if (rv == -1 && errno == EAGAIN) | ||
152 | break; | ||
153 | |||
154 | atf_tc_fail("failed to enqueue a message"); | ||
155 | } | ||
156 | |||
157 | (void)memset(&ds, 0, sizeof(struct msqid_ds)); | ||
158 | (void)msgctl(id, IPC_STAT, &ds); | ||
159 | |||
160 | if (ds.msg_qnum != i) | ||
161 | atf_tc_fail("incorrect message count"); | ||
162 | |||
163 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
164 | } | ||
165 | |||
166 | ATF_TC_CLEANUP(msgsnd_count, tc) | ||
167 | { | ||
168 | clean(); | ||
169 | } | ||
170 | |||
171 | ATF_TC_WITH_CLEANUP(msgsnd_err); | ||
172 | ATF_TC_HEAD(msgsnd_err, tc) | ||
173 | { | ||
174 | atf_tc_set_md_var(tc, "descr", "Test errors from msgsnd(2)"); | ||
175 | } | ||
176 | |||
177 | ATF_TC_BODY(msgsnd_err, tc) | ||
178 | { | ||
179 | struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; | ||
180 | int id; | ||
181 | |||
182 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
183 | ATF_REQUIRE(id != -1); | ||
184 | |||
185 | errno = 0; | ||
186 | |||
187 | ATF_REQUIRE_ERRNO(EFAULT, msgsnd(id, (void *)-1, | ||
188 | sizeof(struct msg), IPC_NOWAIT) == -1); | ||
189 | |||
190 | errno = 0; | ||
191 | |||
192 | ATF_REQUIRE_ERRNO(EINVAL, msgsnd(-1, &msg, | ||
193 | sizeof(struct msg), IPC_NOWAIT) == -1); | ||
194 | |||
195 | errno = 0; | ||
196 | |||
197 | ATF_REQUIRE_ERRNO(EINVAL, msgsnd(-1, &msg, | ||
198 | SSIZE_MAX, IPC_NOWAIT) == -1); | ||
199 | |||
200 | errno = 0; | ||
201 | msg.mtype = 0; | ||
202 | |||
203 | ATF_REQUIRE_ERRNO(EINVAL, msgsnd(id, &msg, | ||
204 | sizeof(struct msg), IPC_NOWAIT) == -1); | ||
205 | |||
206 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
207 | } | ||
208 | |||
209 | ATF_TC_CLEANUP(msgsnd_err, tc) | ||
210 | { | ||
211 | clean(); | ||
212 | } | ||
213 | |||
214 | ATF_TC_WITH_CLEANUP(msgsnd_nonblock); | ||
215 | ATF_TC_HEAD(msgsnd_nonblock, tc) | ||
216 | { | ||
217 | atf_tc_set_md_var(tc, "descr", "Test msgsnd(2) with IPC_NOWAIT"); | ||
218 | atf_tc_set_md_var(tc, "timeout", "10"); | ||
219 | } | ||
220 | |||
221 | ATF_TC_BODY(msgsnd_nonblock, tc) | ||
222 | { | ||
223 | struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; | ||
224 | int id, rv, sta; | ||
225 | pid_t pid; | ||
226 | |||
227 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
228 | ATF_REQUIRE(id != -1); | ||
229 | |||
230 | pid = fork(); | ||
231 | ATF_REQUIRE(pid >= 0); | ||
232 | |||
233 | if (pid == 0) { | ||
234 | |||
235 | for (;;) { | ||
236 | |||
237 | errno = 0; | ||
238 | rv = msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT); | ||
239 | |||
240 | if (rv == -1 && errno == EAGAIN) | ||
241 | _exit(EXIT_SUCCESS); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | (void)sleep(2); | ||
246 | (void)kill(pid, SIGKILL); | ||
247 | (void)wait(&sta); | ||
248 | |||
249 | if (WIFEXITED(sta) == 0 || WIFSIGNALED(sta) != 0) | ||
250 | atf_tc_fail("msgsnd(2) blocked with IPC_NOWAIT"); | ||
251 | |||
252 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
253 | } | ||
254 | |||
255 | ATF_TC_CLEANUP(msgsnd_nonblock, tc) | ||
256 | { | ||
257 | clean(); | ||
258 | } | ||
259 | |||
260 | ATF_TC_WITH_CLEANUP(msgsnd_perm); | ||
261 | ATF_TC_HEAD(msgsnd_perm, tc) | ||
262 | { | ||
263 | atf_tc_set_md_var(tc, "descr", "Test permissions with msgsnd(2)"); | ||
264 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
265 | } | ||
266 | |||
267 | ATF_TC_BODY(msgsnd_perm, tc) | ||
268 | { | ||
269 | struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; | ||
270 | struct passwd *pw; | ||
271 | int id, sta; | ||
272 | pid_t pid; | ||
273 | uid_t uid; | ||
274 | |||
275 | pw = getpwnam("nobody"); | ||
276 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
277 | |||
278 | ATF_REQUIRE(id != -1); | ||
279 | ATF_REQUIRE(pw != NULL); | ||
280 | |||
281 | uid = pw->pw_uid; | ||
282 | ATF_REQUIRE(uid != 0); | ||
283 | |||
284 | pid = fork(); | ||
285 | ATF_REQUIRE(pid >= 0); | ||
286 | |||
287 | if (pid == 0) { | ||
288 | |||
289 | /* | ||
290 | * Try to enqueue a message to the queue | ||
291 | * created by root as RW for owner only. | ||
292 | */ | ||
293 | if (setuid(uid) != 0) | ||
294 | _exit(EX_OSERR); | ||
295 | |||
296 | id = msgget(MSG_KEY, 0); | ||
297 | |||
298 | if (id == -1) | ||
299 | _exit(EX_OSERR); | ||
300 | |||
301 | errno = 0; | ||
302 | |||
303 | if (msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT) == 0) | ||
304 | _exit(EXIT_FAILURE); | ||
305 | |||
306 | if (errno != EACCES) | ||
307 | _exit(EXIT_FAILURE); | ||
308 | |||
309 | _exit(EXIT_SUCCESS); | ||
310 | } | ||
311 | |||
312 | (void)wait(&sta); | ||
313 | |||
314 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) { | ||
315 | |||
316 | if (errno == EX_OSERR) | ||
317 | atf_tc_fail("system call failed"); | ||
318 | |||
319 | atf_tc_fail("UID %u enqueued message to root's queue", uid); | ||
320 | } | ||
321 | |||
322 | ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); | ||
323 | } | ||
324 | |||
325 | ATF_TC_CLEANUP(msgsnd_perm, tc) | ||
326 | { | ||
327 | clean(); | ||
328 | } | ||
329 | |||
330 | static volatile int sig_caught; | ||
331 | |||
332 | static void | ||
333 | sigsys_handler(int signum) | ||
334 | { | ||
335 | |||
336 | sig_caught = signum; | ||
337 | } | ||
338 | |||
339 | static int | ||
340 | no_kernel_sysvmsg(void) | ||
341 | { | ||
342 | int id; | ||
343 | void (*osig)(int); | ||
344 | |||
345 | sig_caught = 0; | ||
346 | osig = signal(SIGSYS, sigsys_handler); | ||
347 | id = msgget(MSG_KEY, IPC_CREAT | 0600); | ||
348 | if (sig_caught || id == -1) | ||
349 | return 1; | ||
350 | |||
351 | (void)msgctl(id, IPC_RMID, 0); | ||
352 | (void)signal(SIGSYS, osig); | ||
353 | |||
354 | return 0; | ||
355 | } | ||
356 | |||
357 | ATF_TC(msgsnd_query); | ||
358 | ATF_TC_HEAD(msgsnd_query, tc) | ||
359 | { | ||
360 | atf_tc_set_md_var(tc, "descr", "Skip msgsnd_* tests - no SYSVMSG"); | ||
361 | } | ||
362 | ATF_TC_BODY(msgsnd_query, tc) | ||
363 | { | ||
364 | atf_tc_skip("No SYSVMSG in kernel"); | ||
365 | } | ||
366 | |||
367 | ATF_TP_ADD_TCS(tp) | ||
368 | { | ||
369 | |||
370 | if (no_kernel_sysvmsg()) { | ||
371 | ATF_TP_ADD_TC(tp, msgsnd_query); | ||
372 | } else { | ||
373 | ATF_TP_ADD_TC(tp, msgsnd_block); | ||
374 | ATF_TP_ADD_TC(tp, msgsnd_count); | ||
375 | ATF_TP_ADD_TC(tp, msgsnd_err); | ||
376 | ATF_TP_ADD_TC(tp, msgsnd_nonblock); | ||
377 | ATF_TP_ADD_TC(tp, msgsnd_perm); | ||
378 | } | ||
379 | |||
380 | return atf_no_error(); | ||
381 | } | ||
diff --git a/src/regress/lib/libc/sys/t_msync.c b/src/regress/lib/libc/sys/t_msync.c deleted file mode 100644 index acce0f664e..0000000000 --- a/src/regress/lib/libc/sys/t_msync.c +++ /dev/null | |||
@@ -1,225 +0,0 @@ | |||
1 | /* $OpenBSD: t_msync.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_msync.c,v 1.3 2017/01/14 20:52:42 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/mman.h> | ||
36 | |||
37 | #include "atf-c.h" | ||
38 | #include <errno.h> | ||
39 | #include <fcntl.h> | ||
40 | #include <limits.h> | ||
41 | #include <stdlib.h> | ||
42 | #include <string.h> | ||
43 | #include <unistd.h> | ||
44 | |||
45 | static long page = 0; | ||
46 | static const off_t off = 512; | ||
47 | static const char path[] = "msync"; | ||
48 | |||
49 | static const char *msync_sync(const char *, int); | ||
50 | |||
51 | static const char * | ||
52 | msync_sync(const char *garbage, int flags) | ||
53 | { | ||
54 | char *buf, *map = MAP_FAILED; | ||
55 | const char *str = NULL; | ||
56 | size_t len; | ||
57 | int fd, rv; | ||
58 | |||
59 | /* | ||
60 | * Create a temporary file, write | ||
61 | * one page to it, and map the file. | ||
62 | */ | ||
63 | buf = malloc(page); | ||
64 | |||
65 | if (buf == NULL) | ||
66 | return NULL; | ||
67 | |||
68 | memset(buf, 'x', page); | ||
69 | |||
70 | fd = open(path, O_RDWR | O_CREAT, 0700); | ||
71 | |||
72 | if (fd < 0) { | ||
73 | free(buf); | ||
74 | return "failed to open"; | ||
75 | } | ||
76 | |||
77 | ATF_REQUIRE_MSG(write(fd, buf, page) != -1, "write(2) failed: %s", | ||
78 | strerror(errno)); | ||
79 | |||
80 | map = mmap(NULL, page, PROT_READ | PROT_WRITE, MAP_FILE|MAP_PRIVATE, | ||
81 | fd, 0); | ||
82 | |||
83 | if (map == MAP_FAILED) { | ||
84 | str = "failed to map"; | ||
85 | goto out; | ||
86 | } | ||
87 | |||
88 | /* | ||
89 | * Seek to an arbitrary offset and | ||
90 | * write garbage to this position. | ||
91 | */ | ||
92 | if (lseek(fd, off, SEEK_SET) != off) { | ||
93 | str = "failed to seek"; | ||
94 | goto out; | ||
95 | } | ||
96 | |||
97 | len = strlen(garbage); | ||
98 | rv = write(fd, garbage, len); | ||
99 | |||
100 | if (rv != (ssize_t)len) { | ||
101 | str = "failed to write garbage"; | ||
102 | goto out; | ||
103 | } | ||
104 | |||
105 | /* | ||
106 | * Synchronize the mapping and verify | ||
107 | * that garbage is at the given offset. | ||
108 | */ | ||
109 | if (msync(map, page, flags) != 0) { | ||
110 | str = "failed to msync"; | ||
111 | goto out; | ||
112 | } | ||
113 | |||
114 | if (memcmp(map + off, garbage, len) != 0) { | ||
115 | str = "msync did not synchronize"; | ||
116 | goto out; | ||
117 | } | ||
118 | |||
119 | out: | ||
120 | free(buf); | ||
121 | |||
122 | (void)close(fd); | ||
123 | (void)unlink(path); | ||
124 | |||
125 | if (map != MAP_FAILED) | ||
126 | (void)munmap(map, page); | ||
127 | |||
128 | return str; | ||
129 | } | ||
130 | |||
131 | ATF_TC(msync_async); | ||
132 | ATF_TC_HEAD(msync_async, tc) | ||
133 | { | ||
134 | atf_tc_set_md_var(tc, "descr", "Test of msync(2), MS_ASYNC"); | ||
135 | } | ||
136 | |||
137 | ATF_TC_BODY(msync_async, tc) | ||
138 | { | ||
139 | const char *str; | ||
140 | |||
141 | str = msync_sync("garbage", MS_ASYNC); | ||
142 | |||
143 | if (str != NULL) | ||
144 | atf_tc_fail("%s", str); | ||
145 | } | ||
146 | |||
147 | ATF_TC(msync_err); | ||
148 | ATF_TC_HEAD(msync_err, tc) | ||
149 | { | ||
150 | atf_tc_set_md_var(tc, "descr", "Test error conditions in msync(2)"); | ||
151 | } | ||
152 | |||
153 | ATF_TC_BODY(msync_err, tc) | ||
154 | { | ||
155 | |||
156 | char *map = MAP_FAILED; | ||
157 | |||
158 | /* | ||
159 | * Test that invalid flags error out. | ||
160 | */ | ||
161 | ATF_REQUIRE(msync_sync("error", -1) != NULL); | ||
162 | ATF_REQUIRE(msync_sync("error", INT_MAX) != NULL); | ||
163 | |||
164 | errno = 0; | ||
165 | |||
166 | /* | ||
167 | * Map a page and then unmap to get an unmapped address. | ||
168 | */ | ||
169 | map = mmap(NULL, page, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, | ||
170 | -1, 0); | ||
171 | ATF_REQUIRE(map != MAP_FAILED); | ||
172 | |||
173 | (void)munmap(map, page); | ||
174 | |||
175 | ATF_REQUIRE(msync(map, page, MS_SYNC) != 0); | ||
176 | ATF_REQUIRE(errno == EFAULT); | ||
177 | } | ||
178 | |||
179 | ATF_TC(msync_invalidate); | ||
180 | ATF_TC_HEAD(msync_invalidate, tc) | ||
181 | { | ||
182 | atf_tc_set_md_var(tc, "descr", "Test of msync(2), MS_INVALIDATE"); | ||
183 | } | ||
184 | |||
185 | ATF_TC_BODY(msync_invalidate, tc) | ||
186 | { | ||
187 | const char *str; | ||
188 | |||
189 | str = msync_sync("garbage", MS_INVALIDATE); | ||
190 | |||
191 | if (str != NULL) | ||
192 | atf_tc_fail("%s", str); | ||
193 | } | ||
194 | |||
195 | ATF_TC(msync_sync); | ||
196 | ATF_TC_HEAD(msync_sync, tc) | ||
197 | { | ||
198 | atf_tc_set_md_var(tc, "descr", "Test of msync(2), MS_SYNC"); | ||
199 | } | ||
200 | |||
201 | ATF_TC_BODY(msync_sync, tc) | ||
202 | { | ||
203 | const char *str; | ||
204 | |||
205 | str = msync_sync("garbage", MS_SYNC); | ||
206 | |||
207 | if (str != NULL) | ||
208 | atf_tc_fail("%s", str); | ||
209 | } | ||
210 | |||
211 | ATF_TP_ADD_TCS(tp) | ||
212 | { | ||
213 | |||
214 | page = sysconf(_SC_PAGESIZE); | ||
215 | |||
216 | ATF_REQUIRE(page >= 0); | ||
217 | ATF_REQUIRE(page > off); | ||
218 | |||
219 | ATF_TP_ADD_TC(tp, msync_async); | ||
220 | ATF_TP_ADD_TC(tp, msync_err); | ||
221 | ATF_TP_ADD_TC(tp, msync_invalidate); | ||
222 | ATF_TP_ADD_TC(tp, msync_sync); | ||
223 | |||
224 | return atf_no_error(); | ||
225 | } | ||
diff --git a/src/regress/lib/libc/sys/t_pipe.c b/src/regress/lib/libc/sys/t_pipe.c deleted file mode 100644 index 7640cc2944..0000000000 --- a/src/regress/lib/libc/sys/t_pipe.c +++ /dev/null | |||
@@ -1,162 +0,0 @@ | |||
1 | /* $OpenBSD: t_pipe.c,v 1.3 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_pipe.c,v 1.7 2020/06/26 07:50:11 jruoho Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
27 | * POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #include "macros.h" | ||
31 | |||
32 | #include <sys/types.h> | ||
33 | #include <sys/wait.h> | ||
34 | |||
35 | #include <errno.h> | ||
36 | #include <fcntl.h> | ||
37 | #include <poll.h> | ||
38 | #include <sched.h> | ||
39 | #include <signal.h> | ||
40 | #include <stdio.h> | ||
41 | #include <stdlib.h> | ||
42 | #include <unistd.h> | ||
43 | |||
44 | #include "atf-c.h" | ||
45 | |||
46 | #include "h_macros.h" | ||
47 | |||
48 | static pid_t pid; | ||
49 | static int nsiginfo = 0; | ||
50 | |||
51 | /* | ||
52 | * This is used for both parent and child. Handle parent's SIGALRM, | ||
53 | * the childs SIGINFO doesn't need anything. | ||
54 | */ | ||
55 | static void | ||
56 | sighand(int sig) | ||
57 | { | ||
58 | if (sig == SIGALRM) { | ||
59 | kill(pid, SIGINFO); | ||
60 | } | ||
61 | if (sig == SIGINFO) { | ||
62 | nsiginfo++; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | ATF_TC(pipe_restart); | ||
67 | ATF_TC_HEAD(pipe_restart, tc) | ||
68 | { | ||
69 | atf_tc_set_md_var(tc, "descr", "Checks that writing to pipe " | ||
70 | "works correctly after being interrupted and restarted " | ||
71 | "(PR kern/14087)"); | ||
72 | } | ||
73 | |||
74 | ATF_TC_BODY(pipe_restart, tc) | ||
75 | { | ||
76 | int pp[2], st; | ||
77 | ssize_t sz, todo, done; | ||
78 | char *f; | ||
79 | sigset_t asigset, osigset, emptysigset; | ||
80 | |||
81 | /* Initialise signal masks */ | ||
82 | RL(sigemptyset(&emptysigset)); | ||
83 | RL(sigemptyset(&asigset)); | ||
84 | RL(sigaddset(&asigset, SIGINFO)); | ||
85 | |||
86 | /* Register signal handlers for both read and writer */ | ||
87 | REQUIRE_LIBC(signal(SIGINFO, sighand), SIG_ERR); | ||
88 | REQUIRE_LIBC(signal(SIGALRM, sighand), SIG_ERR); | ||
89 | |||
90 | todo = 2 * 1024 * 1024; | ||
91 | REQUIRE_LIBC(f = malloc(todo), NULL); | ||
92 | |||
93 | RL(pipe(pp)); | ||
94 | |||
95 | RL(pid = fork()); | ||
96 | if (pid == 0) { | ||
97 | /* child */ | ||
98 | RL(close(pp[1])); | ||
99 | |||
100 | /* Do initial write. This should succeed, make | ||
101 | * the other side do partial write and wait for us to pick | ||
102 | * rest up. | ||
103 | */ | ||
104 | RL(done = read(pp[0], f, 128 * 1024)); | ||
105 | |||
106 | /* Wait until parent is alarmed and awakens us */ | ||
107 | RL(sigprocmask(SIG_BLOCK, &asigset, &osigset)); | ||
108 | while (nsiginfo == 0) { | ||
109 | if (sigsuspend(&emptysigset) != -1 || errno != EINTR) | ||
110 | atf_tc_fail("sigsuspend(&emptysigset): %s", | ||
111 | strerror(errno)); | ||
112 | } | ||
113 | RL(sigprocmask(SIG_SETMASK, &osigset, NULL)); | ||
114 | |||
115 | /* Read all what parent wants to give us */ | ||
116 | while((sz = read(pp[0], f, 1024 * 1024)) > 0) | ||
117 | done += sz; | ||
118 | |||
119 | /* | ||
120 | * Exit with 1 if number of bytes read doesn't match | ||
121 | * number of expected bytes | ||
122 | */ | ||
123 | printf("Read: %#zx\n", (size_t)done); | ||
124 | printf("Expected: %#zx\n", (size_t)todo); | ||
125 | |||
126 | exit(done != todo); | ||
127 | |||
128 | /* NOTREACHED */ | ||
129 | } else { | ||
130 | RL(close(pp[0])); | ||
131 | |||
132 | /* | ||
133 | * Arrange for alarm after two seconds. Since we have | ||
134 | * handler setup for SIGARLM, the write(2) call should | ||
135 | * be restarted internally by kernel. | ||
136 | */ | ||
137 | (void)alarm(2); | ||
138 | |||
139 | /* We write exactly 'todo' bytes. The very first write(2) | ||
140 | * should partially succeed, block and eventually | ||
141 | * be restarted by kernel | ||
142 | */ | ||
143 | while(todo > 0 && ((sz = write(pp[1], f, todo)) > 0)) | ||
144 | todo -= sz; | ||
145 | |||
146 | /* Close the pipe, so that child would stop reading */ | ||
147 | RL(close(pp[1])); | ||
148 | |||
149 | /* And pickup child's exit status */ | ||
150 | RL(waitpid(pid, &st, 0)); | ||
151 | |||
152 | ATF_REQUIRE_EQ(WEXITSTATUS(st), 0); | ||
153 | } | ||
154 | free(f); | ||
155 | } | ||
156 | |||
157 | ATF_TP_ADD_TCS(tp) | ||
158 | { | ||
159 | ATF_TP_ADD_TC(tp, pipe_restart); | ||
160 | |||
161 | return atf_no_error(); | ||
162 | } | ||
diff --git a/src/regress/lib/libc/sys/t_pipe2.c b/src/regress/lib/libc/sys/t_pipe2.c deleted file mode 100644 index b88d933c9a..0000000000 --- a/src/regress/lib/libc/sys/t_pipe2.c +++ /dev/null | |||
@@ -1,199 +0,0 @@ | |||
1 | /* $OpenBSD: t_pipe2.c,v 1.4 2023/10/31 07:56:44 claudio Exp $ */ | ||
2 | /* $NetBSD: t_pipe2.c,v 1.9 2017/01/13 21:19:45 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Christos Zoulas. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * 3. All advertising materials mentioning features or use of this software | ||
20 | * must display the following acknowledgement: | ||
21 | * This product includes software developed by the NetBSD | ||
22 | * Foundation, Inc. and its contributors. | ||
23 | * 4. Neither the name of The NetBSD Foundation nor the names of its | ||
24 | * contributors may be used to endorse or promote products derived | ||
25 | * from this software without specific prior written permission. | ||
26 | * | ||
27 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
28 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
29 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
30 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
31 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
37 | * POSSIBILITY OF SUCH DAMAGE. | ||
38 | */ | ||
39 | |||
40 | #include "macros.h" | ||
41 | |||
42 | #include "atf-c.h" | ||
43 | #include <fcntl.h> | ||
44 | #include <unistd.h> | ||
45 | #include <stdlib.h> | ||
46 | #include <errno.h> | ||
47 | #include <sys/resource.h> | ||
48 | |||
49 | static void | ||
50 | run(int flags) | ||
51 | { | ||
52 | int fd[2], i; | ||
53 | |||
54 | while ((i = open("/", O_RDONLY)) < 3) | ||
55 | ATF_REQUIRE(i != -1); | ||
56 | |||
57 | ATF_REQUIRE_MSG(closefrom(3) != -1, "closefrom failed: %s", | ||
58 | strerror(errno)); | ||
59 | |||
60 | ATF_REQUIRE(pipe2(fd, flags) == 0); | ||
61 | |||
62 | ATF_REQUIRE(fd[0] == 3); | ||
63 | ATF_REQUIRE(fd[1] == 4); | ||
64 | |||
65 | if (flags & O_CLOEXEC) { | ||
66 | ATF_REQUIRE((fcntl(fd[0], F_GETFD) & FD_CLOEXEC) != 0); | ||
67 | ATF_REQUIRE((fcntl(fd[1], F_GETFD) & FD_CLOEXEC) != 0); | ||
68 | } else { | ||
69 | ATF_REQUIRE((fcntl(fd[0], F_GETFD) & FD_CLOEXEC) == 0); | ||
70 | ATF_REQUIRE((fcntl(fd[1], F_GETFD) & FD_CLOEXEC) == 0); | ||
71 | } | ||
72 | |||
73 | if (flags & O_NONBLOCK) { | ||
74 | ATF_REQUIRE((fcntl(fd[0], F_GETFL) & O_NONBLOCK) != 0); | ||
75 | ATF_REQUIRE((fcntl(fd[1], F_GETFL) & O_NONBLOCK) != 0); | ||
76 | } else { | ||
77 | ATF_REQUIRE((fcntl(fd[0], F_GETFL) & O_NONBLOCK) == 0); | ||
78 | ATF_REQUIRE((fcntl(fd[1], F_GETFL) & O_NONBLOCK) == 0); | ||
79 | } | ||
80 | |||
81 | #ifndef __OpenBSD__ | ||
82 | /* F_GETNOSIGPIPE not available */ | ||
83 | if (flags & O_NOSIGPIPE) { | ||
84 | ATF_REQUIRE(fcntl(fd[0], F_GETNOSIGPIPE) != 0); | ||
85 | ATF_REQUIRE(fcntl(fd[1], F_GETNOSIGPIPE) != 0); | ||
86 | } else { | ||
87 | ATF_REQUIRE(fcntl(fd[0], F_GETNOSIGPIPE) == 0); | ||
88 | ATF_REQUIRE(fcntl(fd[1], F_GETNOSIGPIPE) == 0); | ||
89 | } | ||
90 | #endif | ||
91 | |||
92 | ATF_REQUIRE(close(fd[0]) != -1); | ||
93 | ATF_REQUIRE(close(fd[1]) != -1); | ||
94 | } | ||
95 | |||
96 | ATF_TC(pipe2_basic); | ||
97 | ATF_TC_HEAD(pipe2_basic, tc) | ||
98 | { | ||
99 | atf_tc_set_md_var(tc, "descr", "A basic test of pipe2(2)"); | ||
100 | } | ||
101 | |||
102 | ATF_TC_BODY(pipe2_basic, tc) | ||
103 | { | ||
104 | run(0); | ||
105 | } | ||
106 | |||
107 | ATF_TC(pipe2_consume); | ||
108 | ATF_TC_HEAD(pipe2_consume, tc) | ||
109 | { | ||
110 | atf_tc_set_md_var(tc, "descr", "Test that consuming file descriptors " | ||
111 | "with pipe2(2) does not crash the system (PR kern/46457)"); | ||
112 | } | ||
113 | |||
114 | ATF_TC_BODY(pipe2_consume, tc) | ||
115 | { | ||
116 | struct rlimit rl; | ||
117 | int err, filedes[2]; | ||
118 | int old; | ||
119 | |||
120 | (void)closefrom(4); | ||
121 | |||
122 | err = getrlimit(RLIMIT_NOFILE, &rl); | ||
123 | ATF_REQUIRE(err == 0); | ||
124 | /* | ||
125 | * The heart of this test is to run against the number of open | ||
126 | * file descriptor limit in the middle of a pipe2() call - i.e. | ||
127 | * before the call only a single descriptor may be openend. | ||
128 | */ | ||
129 | old = rl.rlim_cur; | ||
130 | rl.rlim_cur = 4; | ||
131 | err = setrlimit(RLIMIT_NOFILE, &rl); | ||
132 | ATF_REQUIRE(err == 0); | ||
133 | |||
134 | err = pipe2(filedes, O_CLOEXEC); | ||
135 | ATF_REQUIRE(err == -1); | ||
136 | rl.rlim_cur = old; | ||
137 | err = setrlimit(RLIMIT_NOFILE, &rl); | ||
138 | } | ||
139 | |||
140 | ATF_TC(pipe2_nonblock); | ||
141 | ATF_TC_HEAD(pipe2_nonblock, tc) | ||
142 | { | ||
143 | atf_tc_set_md_var(tc, "descr", "A non-blocking test of pipe2(2)"); | ||
144 | } | ||
145 | |||
146 | ATF_TC_BODY(pipe2_nonblock, tc) | ||
147 | { | ||
148 | run(O_NONBLOCK); | ||
149 | } | ||
150 | |||
151 | ATF_TC(pipe2_cloexec); | ||
152 | ATF_TC_HEAD(pipe2_cloexec, tc) | ||
153 | { | ||
154 | atf_tc_set_md_var(tc, "descr", "A close-on-exec test of pipe2(2)"); | ||
155 | } | ||
156 | |||
157 | ATF_TC_BODY(pipe2_cloexec, tc) | ||
158 | { | ||
159 | run(O_CLOEXEC); | ||
160 | } | ||
161 | |||
162 | ATF_TC(pipe2_nosigpipe); | ||
163 | ATF_TC_HEAD(pipe2_nosigpipe, tc) | ||
164 | { | ||
165 | atf_tc_set_md_var(tc, "descr", "A no sigpipe test of pipe2(2)"); | ||
166 | } | ||
167 | |||
168 | ATF_TC_BODY(pipe2_nosigpipe, tc) | ||
169 | { | ||
170 | run(O_NOSIGPIPE); | ||
171 | } | ||
172 | |||
173 | ATF_TC(pipe2_einval); | ||
174 | ATF_TC_HEAD(pipe2_einval, tc) | ||
175 | { | ||
176 | atf_tc_set_md_var(tc, "descr", "A error check of pipe2(2)"); | ||
177 | } | ||
178 | |||
179 | ATF_TC_BODY(pipe2_einval, tc) | ||
180 | { | ||
181 | int fd[2]; | ||
182 | ATF_REQUIRE_ERRNO(EINVAL, pipe2(fd, O_ASYNC) == -1); | ||
183 | } | ||
184 | |||
185 | ATF_TP_ADD_TCS(tp) | ||
186 | { | ||
187 | |||
188 | ATF_TP_ADD_TC(tp, pipe2_basic); | ||
189 | ATF_TP_ADD_TC(tp, pipe2_consume); | ||
190 | ATF_TP_ADD_TC(tp, pipe2_nonblock); | ||
191 | ATF_TP_ADD_TC(tp, pipe2_cloexec); | ||
192 | #ifndef __OpenBSD__ | ||
193 | /* O_NOSIGPIPE not available */ | ||
194 | ATF_TP_ADD_TC(tp, pipe2_nosigpipe); | ||
195 | #endif | ||
196 | ATF_TP_ADD_TC(tp, pipe2_einval); | ||
197 | |||
198 | return atf_no_error(); | ||
199 | } | ||
diff --git a/src/regress/lib/libc/sys/t_poll.c b/src/regress/lib/libc/sys/t_poll.c deleted file mode 100644 index 345b6c7ad0..0000000000 --- a/src/regress/lib/libc/sys/t_poll.c +++ /dev/null | |||
@@ -1,247 +0,0 @@ | |||
1 | /* $OpenBSD: t_poll.c,v 1.3 2022/05/28 18:39:39 mbuhl Exp $ */ | ||
2 | /* $NetBSD: t_poll.c,v 1.4 2020/07/17 15:34:16 kamil Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Matthias Scheler. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/time.h> | ||
36 | #include <sys/wait.h> | ||
37 | |||
38 | #include "atf-c.h" | ||
39 | #include <errno.h> | ||
40 | #include <fcntl.h> | ||
41 | #include <paths.h> | ||
42 | #include <poll.h> | ||
43 | #include <stdio.h> | ||
44 | #include <signal.h> | ||
45 | #include <unistd.h> | ||
46 | |||
47 | static int desc; | ||
48 | |||
49 | static void | ||
50 | child1(void) | ||
51 | { | ||
52 | struct pollfd pfd; | ||
53 | |||
54 | pfd.fd = desc; | ||
55 | pfd.events = POLLIN | POLLHUP | POLLOUT; | ||
56 | |||
57 | (void)poll(&pfd, 1, 2000); | ||
58 | (void)printf("child1 exit\n"); | ||
59 | } | ||
60 | |||
61 | static void | ||
62 | child2(void) | ||
63 | { | ||
64 | struct pollfd pfd; | ||
65 | |||
66 | pfd.fd = desc; | ||
67 | pfd.events = POLLIN | POLLHUP | POLLOUT; | ||
68 | |||
69 | (void)sleep(1); | ||
70 | (void)poll(&pfd, 1, INFTIM); | ||
71 | (void)printf("child2 exit\n"); | ||
72 | } | ||
73 | |||
74 | static void | ||
75 | child3(void) | ||
76 | { | ||
77 | struct pollfd pfd; | ||
78 | |||
79 | (void)sleep(5); | ||
80 | |||
81 | pfd.fd = desc; | ||
82 | pfd.events = POLLIN | POLLHUP | POLLOUT; | ||
83 | |||
84 | (void)poll(&pfd, 1, INFTIM); | ||
85 | (void)printf("child3 exit\n"); | ||
86 | } | ||
87 | |||
88 | ATF_TC(3way); | ||
89 | ATF_TC_HEAD(3way, tc) | ||
90 | { | ||
91 | atf_tc_set_md_var(tc, "timeout", "15"); | ||
92 | atf_tc_set_md_var(tc, "descr", | ||
93 | "Check for 3-way collision for descriptor. First child comes " | ||
94 | "and polls on descriptor, second child comes and polls, first " | ||
95 | "child times out and exits, third child comes and polls. When " | ||
96 | "the wakeup event happens, the two remaining children should " | ||
97 | "both be awaken. (kern/17517)"); | ||
98 | } | ||
99 | |||
100 | ATF_TC_BODY(3way, tc) | ||
101 | { | ||
102 | int pf[2]; | ||
103 | int status, i; | ||
104 | pid_t pid; | ||
105 | |||
106 | pipe(pf); | ||
107 | desc = pf[0]; | ||
108 | |||
109 | pid = fork(); | ||
110 | ATF_REQUIRE(pid >= 0); | ||
111 | |||
112 | if (pid == 0) { | ||
113 | (void)close(pf[1]); | ||
114 | child1(); | ||
115 | _exit(0); | ||
116 | /* NOTREACHED */ | ||
117 | } | ||
118 | |||
119 | pid = fork(); | ||
120 | ATF_REQUIRE(pid >= 0); | ||
121 | |||
122 | if (pid == 0) { | ||
123 | (void)close(pf[1]); | ||
124 | child2(); | ||
125 | _exit(0); | ||
126 | /* NOTREACHED */ | ||
127 | } | ||
128 | |||
129 | pid = fork(); | ||
130 | ATF_REQUIRE( pid >= 0); | ||
131 | |||
132 | if (pid == 0) { | ||
133 | (void)close(pf[1]); | ||
134 | child3(); | ||
135 | _exit(0); | ||
136 | /* NOTREACHED */ | ||
137 | } | ||
138 | |||
139 | (void)sleep(10); | ||
140 | |||
141 | (void)printf("parent write\n"); | ||
142 | |||
143 | ATF_REQUIRE(write(pf[1], "konec\n", 6) == 6); | ||
144 | |||
145 | for(i = 0; i < 3; ++i) | ||
146 | (void)wait(&status); | ||
147 | |||
148 | (void)printf("parent terminated\n"); | ||
149 | } | ||
150 | |||
151 | ATF_TC(basic); | ||
152 | ATF_TC_HEAD(basic, tc) | ||
153 | { | ||
154 | atf_tc_set_md_var(tc, "timeout", "10"); | ||
155 | atf_tc_set_md_var(tc, "descr", | ||
156 | "Basis functionality test for poll(2)"); | ||
157 | } | ||
158 | |||
159 | ATF_TC_BODY(basic, tc) | ||
160 | { | ||
161 | int fds[2]; | ||
162 | struct pollfd pfds[2]; | ||
163 | int ret; | ||
164 | |||
165 | ATF_REQUIRE_EQ(pipe(fds), 0); | ||
166 | |||
167 | pfds[0].fd = fds[0]; | ||
168 | pfds[0].events = POLLIN; | ||
169 | pfds[1].fd = fds[1]; | ||
170 | pfds[1].events = POLLOUT; | ||
171 | |||
172 | /* | ||
173 | * Check that we get a timeout waiting for data on the read end | ||
174 | * of our pipe. | ||
175 | */ | ||
176 | pfds[0].revents = -1; | ||
177 | pfds[1].revents = -1; | ||
178 | ret = poll(&pfds[0], 1, 1); | ||
179 | ATF_REQUIRE_EQ_MSG(ret, 0, "got: %d", ret); | ||
180 | ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents); | ||
181 | ATF_REQUIRE_EQ_MSG(pfds[1].revents, -1, "got: %d", pfds[1].revents); | ||
182 | |||
183 | /* Check that the write end of the pipe as reported as ready. */ | ||
184 | pfds[0].revents = -1; | ||
185 | pfds[1].revents = -1; | ||
186 | ret = poll(&pfds[1], 1, 1); | ||
187 | ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret); | ||
188 | ATF_REQUIRE_EQ_MSG(pfds[0].revents, -1, "got: %d", pfds[0].revents); | ||
189 | ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",\ | ||
190 | pfds[1].revents); | ||
191 | |||
192 | /* Check that only the write end of the pipe as reported as ready. */ | ||
193 | pfds[0].revents = -1; | ||
194 | pfds[1].revents = -1; | ||
195 | ret = poll(pfds, 2, 1); | ||
196 | ATF_REQUIRE_EQ_MSG(ret, 1, "got: %d", ret); | ||
197 | ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents); | ||
198 | ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d", | ||
199 | pfds[1].revents); | ||
200 | |||
201 | /* Write data to our pipe. */ | ||
202 | ATF_REQUIRE_EQ(write(fds[1], "", 1), 1); | ||
203 | |||
204 | /* Check that both ends of our pipe are reported as ready. */ | ||
205 | pfds[0].revents = -1; | ||
206 | pfds[1].revents = -1; | ||
207 | ret = poll(pfds, 2, 1); | ||
208 | ATF_REQUIRE_EQ_MSG(ret, 2, "got: %d", ret); | ||
209 | ATF_REQUIRE_EQ_MSG(pfds[0].revents, POLLIN, "got: %d", | ||
210 | pfds[0].revents); | ||
211 | ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d", | ||
212 | pfds[1].revents); | ||
213 | |||
214 | ATF_REQUIRE_EQ(close(fds[0]), 0); | ||
215 | ATF_REQUIRE_EQ(close(fds[1]), 0); | ||
216 | } | ||
217 | |||
218 | ATF_TC(err); | ||
219 | ATF_TC_HEAD(err, tc) | ||
220 | { | ||
221 | atf_tc_set_md_var(tc, "descr", "Check errors from poll(2)"); | ||
222 | } | ||
223 | |||
224 | ATF_TC_BODY(err, tc) | ||
225 | { | ||
226 | struct pollfd pfd; | ||
227 | int fd = 0; | ||
228 | |||
229 | pfd.fd = fd; | ||
230 | pfd.events = POLLIN; | ||
231 | |||
232 | errno = 0; | ||
233 | ATF_REQUIRE_ERRNO(EFAULT, poll((struct pollfd *)-1, 1, -1) == -1); | ||
234 | |||
235 | errno = 0; | ||
236 | ATF_REQUIRE_ERRNO(EINVAL, poll(&pfd, 1, -2) == -1); | ||
237 | } | ||
238 | |||
239 | ATF_TP_ADD_TCS(tp) | ||
240 | { | ||
241 | |||
242 | ATF_TP_ADD_TC(tp, 3way); | ||
243 | ATF_TP_ADD_TC(tp, basic); | ||
244 | ATF_TP_ADD_TC(tp, err); | ||
245 | |||
246 | return atf_no_error(); | ||
247 | } | ||
diff --git a/src/regress/lib/libc/sys/t_pollts.c b/src/regress/lib/libc/sys/t_pollts.c deleted file mode 100644 index 966b8c7721..0000000000 --- a/src/regress/lib/libc/sys/t_pollts.c +++ /dev/null | |||
@@ -1,203 +0,0 @@ | |||
1 | /* $OpenBSD: t_pollts.c,v 1.1 2021/09/02 12:40:44 mbuhl Exp $ */ | ||
2 | /* $NetBSD: t_pollts.c,v 1.1 2020/07/17 15:34:17 kamil Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011, 2020 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Matthias Scheler. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | #include "macros.h" | ||
33 | |||
34 | #include <sys/time.h> | ||
35 | #include <sys/wait.h> | ||
36 | |||
37 | #include "atf-c.h" | ||
38 | #include <errno.h> | ||
39 | #include <fcntl.h> | ||
40 | #include <paths.h> | ||
41 | #include <poll.h> | ||
42 | #include <stdio.h> | ||
43 | #include <signal.h> | ||
44 | #include <unistd.h> | ||
45 | |||
46 | #ifndef POLLTS | ||
47 | #define POLLTS pollts | ||
48 | #endif | ||
49 | |||
50 | ATF_TC(basic); | ||
51 | ATF_TC_HEAD(basic, tc) | ||
52 | { | ||
53 | atf_tc_set_md_var(tc, "timeout", "10"); | ||
54 | atf_tc_set_md_var(tc, "descr", | ||
55 | "Basis functionality test for ppoll(2)/pollts(2)"); | ||
56 | } | ||
57 | |||
58 | ATF_TC_BODY(basic, tc) | ||
59 | { | ||
60 | int fds[2]; | ||
61 | struct pollfd pfds[2]; | ||
62 | struct timespec timeout; | ||
63 | int ret; | ||
64 | |||
65 | ATF_REQUIRE_EQ(pipe(fds), 0); | ||
66 | |||
67 | pfds[0].fd = fds[0]; | ||
68 | pfds[0].events = POLLIN; | ||
69 | pfds[1].fd = fds[1]; | ||
70 | pfds[1].events = POLLOUT; | ||
71 | |||
72 | /* Use a timeout of 1 second. */ | ||
73 | timeout.tv_sec = 1; | ||
74 | timeout.tv_nsec = 0; | ||
75 | |||
76 | /* | ||
77 | * Check that we get a timeout waiting for data on the read end | ||
78 | * of our pipe. | ||
79 | */ | ||
80 | pfds[0].revents = -1; | ||
81 | pfds[1].revents = -1; | ||
82 | ATF_REQUIRE_EQ_MSG(ret = POLLTS(&pfds[0], 1, &timeout, NULL), 0, | ||
83 | "got: %d", ret); | ||
84 | ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents); | ||
85 | ATF_REQUIRE_EQ_MSG(pfds[1].revents, -1, "got: %d", pfds[1].revents); | ||
86 | |||
87 | /* Check that the write end of the pipe as reported as ready. */ | ||
88 | pfds[0].revents = -1; | ||
89 | pfds[1].revents = -1; | ||
90 | ATF_REQUIRE_EQ_MSG(ret = POLLTS(&pfds[1], 1, &timeout, NULL), 1, | ||
91 | "got: %d", ret); | ||
92 | ATF_REQUIRE_EQ_MSG(pfds[0].revents, -1, "got: %d", pfds[0].revents); | ||
93 | ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",\ | ||
94 | pfds[1].revents); | ||
95 | |||
96 | /* Check that only the write end of the pipe as reported as ready. */ | ||
97 | pfds[0].revents = -1; | ||
98 | pfds[1].revents = -1; | ||
99 | ATF_REQUIRE_EQ_MSG(ret = POLLTS(pfds, 2, &timeout, NULL), 1, | ||
100 | "got: %d", ret); | ||
101 | ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents); | ||
102 | ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d", | ||
103 | pfds[1].revents); | ||
104 | |||
105 | /* Write data to our pipe. */ | ||
106 | ATF_REQUIRE_EQ(write(fds[1], "", 1), 1); | ||
107 | |||
108 | /* Check that both ends of our pipe are reported as ready. */ | ||
109 | pfds[0].revents = -1; | ||
110 | pfds[1].revents = -1; | ||
111 | ATF_REQUIRE_EQ_MSG(ret = POLLTS(pfds, 2, &timeout, NULL), 2, | ||
112 | "got: %d", ret); | ||
113 | ATF_REQUIRE_EQ_MSG(pfds[0].revents, POLLIN, "got: %d", | ||
114 | pfds[0].revents); | ||
115 | ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d", | ||
116 | pfds[1].revents); | ||
117 | |||
118 | ATF_REQUIRE_EQ(close(fds[0]), 0); | ||
119 | ATF_REQUIRE_EQ(close(fds[1]), 0); | ||
120 | } | ||
121 | |||
122 | ATF_TC(err); | ||
123 | ATF_TC_HEAD(err, tc) | ||
124 | { | ||
125 | atf_tc_set_md_var(tc, "descr", "Check errors from ppoll(2)/pollts(2)"); | ||
126 | } | ||
127 | |||
128 | ATF_TC_BODY(err, tc) | ||
129 | { | ||
130 | struct timespec timeout; | ||
131 | struct pollfd pfd; | ||
132 | int fd = 0; | ||
133 | |||
134 | pfd.fd = fd; | ||
135 | pfd.events = POLLIN; | ||
136 | |||
137 | timeout.tv_sec = 1; | ||
138 | timeout.tv_nsec = 0; | ||
139 | |||
140 | errno = 0; | ||
141 | ATF_REQUIRE_ERRNO(EFAULT, POLLTS((void *)-1, 1, &timeout, NULL) == -1); | ||
142 | |||
143 | timeout.tv_sec = -1; | ||
144 | timeout.tv_nsec = -1; | ||
145 | |||
146 | errno = 0; | ||
147 | ATF_REQUIRE_ERRNO(EINVAL, POLLTS(&pfd, 1, &timeout, NULL) == -1); | ||
148 | } | ||
149 | |||
150 | ATF_TC(sigmask); | ||
151 | ATF_TC_HEAD(sigmask, tc) | ||
152 | { | ||
153 | atf_tc_set_md_var(tc, "timeout", "10"); | ||
154 | atf_tc_set_md_var(tc, "descr", | ||
155 | "Check that ppoll(2)/pollts(2) restores the signal mask (PR kern/44986)"); | ||
156 | } | ||
157 | |||
158 | ATF_TC_BODY(sigmask, tc) | ||
159 | { | ||
160 | int fd; | ||
161 | struct pollfd pfd; | ||
162 | struct timespec timeout; | ||
163 | sigset_t mask; | ||
164 | int ret; | ||
165 | |||
166 | fd = open(_PATH_DEVNULL, O_RDONLY); | ||
167 | ATF_REQUIRE(fd >= 0); | ||
168 | |||
169 | pfd.fd = fd; | ||
170 | pfd.events = POLLIN; | ||
171 | |||
172 | /* Use a timeout of 1 second. */ | ||
173 | timeout.tv_sec = 1; | ||
174 | timeout.tv_nsec = 0; | ||
175 | |||
176 | /* Unblock all signals. */ | ||
177 | ATF_REQUIRE_EQ(sigfillset(&mask), 0); | ||
178 | ATF_REQUIRE_EQ(sigprocmask(SIG_UNBLOCK, &mask, NULL), 0); | ||
179 | |||
180 | /* | ||
181 | * Check that ppoll(2)/pollts(2) immediately returns. We block *all* | ||
182 | * signals during ppoll(2)/pollts(2). | ||
183 | */ | ||
184 | ATF_REQUIRE_EQ_MSG(ret = POLLTS(&pfd, 1, &timeout, &mask), 1, | ||
185 | "got: %d", ret); | ||
186 | |||
187 | /* Check that signals are now longer blocked. */ | ||
188 | ATF_REQUIRE_EQ(sigprocmask(SIG_SETMASK, NULL, &mask), 0); | ||
189 | ATF_REQUIRE_EQ_MSG(sigismember(&mask, SIGUSR1), 0, | ||
190 | "signal mask was changed."); | ||
191 | |||
192 | ATF_REQUIRE_EQ(close(fd), 0); | ||
193 | } | ||
194 | |||
195 | ATF_TP_ADD_TCS(tp) | ||
196 | { | ||
197 | |||
198 | ATF_TP_ADD_TC(tp, basic); | ||
199 | ATF_TP_ADD_TC(tp, err); | ||
200 | ATF_TP_ADD_TC(tp, sigmask); | ||
201 | |||
202 | return atf_no_error(); | ||
203 | } | ||
diff --git a/src/regress/lib/libc/sys/t_ppoll.c b/src/regress/lib/libc/sys/t_ppoll.c deleted file mode 100644 index c5daef1f5f..0000000000 --- a/src/regress/lib/libc/sys/t_ppoll.c +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | /* $OpenBSD: t_ppoll.c,v 1.1 2021/09/02 12:40:44 mbuhl Exp $ */ | ||
2 | /* $NetBSD: t_ppoll.c,v 1.1 2020/07/17 15:34:17 kamil Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011, 2020 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Matthias Scheler. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #define POLLTS ppoll | ||
34 | #include "t_pollts.c" | ||
diff --git a/src/regress/lib/libc/sys/t_ptrace.c b/src/regress/lib/libc/sys/t_ptrace.c deleted file mode 100644 index 4b87acfdd2..0000000000 --- a/src/regress/lib/libc/sys/t_ptrace.c +++ /dev/null | |||
@@ -1,232 +0,0 @@ | |||
1 | /* $OpenBSD: t_ptrace.c,v 1.5 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_ptrace.c,v 1.4 2018/05/14 12:44:40 kamil Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2016 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
27 | * POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #include "macros.h" | ||
31 | |||
32 | #include <sys/types.h> | ||
33 | #include <sys/ptrace.h> | ||
34 | #include <sys/stat.h> | ||
35 | #include <sys/sysctl.h> | ||
36 | #include <err.h> | ||
37 | #include <errno.h> | ||
38 | #include <limits.h> | ||
39 | #include <unistd.h> | ||
40 | |||
41 | #include "atf-c.h" | ||
42 | |||
43 | #include "h_macros.h" | ||
44 | |||
45 | /* | ||
46 | * A child process cannot call atf functions and expect them to magically | ||
47 | * work like in the parent. | ||
48 | * The printf(3) messaging from a child will not work out of the box as well | ||
49 | * without estabilishing a communication protocol with its parent. To not | ||
50 | * overcomplicate the tests - do not log from a child and use err(3)/errx(3) | ||
51 | * wrapped with FORKEE_ASSERT()/FORKEE_ASSERTX() as that is guaranteed to work. | ||
52 | */ | ||
53 | #define FORKEE_ASSERTX(x) \ | ||
54 | do { \ | ||
55 | int ret = (x); \ | ||
56 | if (!ret) \ | ||
57 | errx(EXIT_FAILURE, "%s:%d %s(): Assertion failed for: %s", \ | ||
58 | __FILE__, __LINE__, __func__, #x); \ | ||
59 | } while (0) | ||
60 | |||
61 | #define FORKEE_ASSERT(x) \ | ||
62 | do { \ | ||
63 | int ret = (x); \ | ||
64 | if (!ret) \ | ||
65 | err(EXIT_FAILURE, "%s:%d %s(): Assertion failed for: %s", \ | ||
66 | __FILE__, __LINE__, __func__, #x); \ | ||
67 | } while (0) | ||
68 | |||
69 | ATF_TC(attach_pid0); | ||
70 | ATF_TC_HEAD(attach_pid0, tc) | ||
71 | { | ||
72 | atf_tc_set_md_var(tc, "descr", | ||
73 | "Assert that a debugger cannot attach to PID 0"); | ||
74 | } | ||
75 | |||
76 | ATF_TC_BODY(attach_pid0, tc) | ||
77 | { | ||
78 | errno = 0; | ||
79 | ATF_REQUIRE_ERRNO(EPERM, ptrace(PT_ATTACH, 0, NULL, 0) == -1); | ||
80 | } | ||
81 | |||
82 | ATF_TC(attach_pid1); | ||
83 | ATF_TC_HEAD(attach_pid1, tc) | ||
84 | { | ||
85 | atf_tc_set_md_var(tc, "descr", | ||
86 | "Assert that a debugger cannot attach to PID 1 (as non-root)"); | ||
87 | |||
88 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
89 | } | ||
90 | |||
91 | ATF_TC_BODY(attach_pid1, tc) | ||
92 | { | ||
93 | ATF_REQUIRE_ERRNO(EPERM, ptrace(PT_ATTACH, 1, NULL, 0) == -1); | ||
94 | } | ||
95 | |||
96 | ATF_TC(attach_pid1_securelevel); | ||
97 | ATF_TC_HEAD(attach_pid1_securelevel, tc) | ||
98 | { | ||
99 | atf_tc_set_md_var(tc, "descr", | ||
100 | "Assert that a debugger cannot attach to PID 1 with " | ||
101 | "securelevel >= 0 (as root)"); | ||
102 | |||
103 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
104 | } | ||
105 | |||
106 | ATF_TC_BODY(attach_pid1_securelevel, tc) | ||
107 | { | ||
108 | int level; | ||
109 | size_t len = sizeof(level); | ||
110 | |||
111 | ATF_REQUIRE(sysctlbyname("kern.securelevel", &level, &len, NULL, 0) | ||
112 | != -1); | ||
113 | |||
114 | if (level < 0) { | ||
115 | atf_tc_skip("Test must be run with securelevel >= 0"); | ||
116 | } | ||
117 | |||
118 | ATF_REQUIRE_ERRNO(EPERM, ptrace(PT_ATTACH, 1, NULL, 0) == -1); | ||
119 | } | ||
120 | |||
121 | ATF_TC(attach_self); | ||
122 | ATF_TC_HEAD(attach_self, tc) | ||
123 | { | ||
124 | atf_tc_set_md_var(tc, "descr", | ||
125 | "Assert that a debugger cannot attach to self (as it's nonsense)"); | ||
126 | } | ||
127 | |||
128 | ATF_TC_BODY(attach_self, tc) | ||
129 | { | ||
130 | ATF_REQUIRE_ERRNO(EINVAL, ptrace(PT_ATTACH, getpid(), NULL, 0) == -1); | ||
131 | } | ||
132 | |||
133 | ATF_TC(attach_chroot); | ||
134 | ATF_TC_HEAD(attach_chroot, tc) | ||
135 | { | ||
136 | atf_tc_set_md_var(tc, "descr", | ||
137 | "Assert that a debugger cannot trace another process unless the " | ||
138 | "process's root directory is at or below the tracing process's " | ||
139 | "root"); | ||
140 | |||
141 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
142 | } | ||
143 | |||
144 | ATF_TC_BODY(attach_chroot, tc) | ||
145 | { | ||
146 | char buf[PATH_MAX]; | ||
147 | pid_t child; | ||
148 | int fds_toparent[2], fds_fromparent[2]; | ||
149 | int rv; | ||
150 | uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ | ||
151 | |||
152 | (void)memset(buf, '\0', sizeof(buf)); | ||
153 | ATF_REQUIRE(getcwd(buf, sizeof(buf)) != NULL); | ||
154 | (void)strlcat(buf, "/dir", sizeof(buf)); | ||
155 | |||
156 | ATF_REQUIRE(mkdir(buf, 0500) == 0); | ||
157 | ATF_REQUIRE(chdir(buf) == 0); | ||
158 | |||
159 | ATF_REQUIRE(pipe(fds_toparent) == 0); | ||
160 | ATF_REQUIRE(pipe(fds_fromparent) == 0); | ||
161 | child = atf_utils_fork(); | ||
162 | if (child == 0) { | ||
163 | FORKEE_ASSERT(close(fds_toparent[0]) == 0); | ||
164 | FORKEE_ASSERT(close(fds_fromparent[1]) == 0); | ||
165 | |||
166 | FORKEE_ASSERT(chroot(buf) == 0); | ||
167 | |||
168 | rv = write(fds_toparent[1], &msg, sizeof(msg)); | ||
169 | FORKEE_ASSERTX(rv == sizeof(msg)); | ||
170 | |||
171 | #ifdef __OpenBSD__ | ||
172 | ATF_REQUIRE_ERRNO(EINVAL, | ||
173 | #else | ||
174 | ATF_REQUIRE_ERRNO(EPERM, | ||
175 | #endif | ||
176 | ptrace(PT_ATTACH, getppid(), NULL, 0) == -1); | ||
177 | |||
178 | rv = read(fds_fromparent[0], &msg, sizeof(msg)); | ||
179 | FORKEE_ASSERTX(rv == sizeof(msg)); | ||
180 | |||
181 | _exit(0); | ||
182 | } | ||
183 | ATF_REQUIRE(close(fds_toparent[1]) == 0); | ||
184 | ATF_REQUIRE(close(fds_fromparent[0]) == 0); | ||
185 | |||
186 | printf("Waiting for chrooting of the child PID %d\n", child); | ||
187 | rv = read(fds_toparent[0], &msg, sizeof(msg)); | ||
188 | ATF_REQUIRE(rv == sizeof(msg)); | ||
189 | |||
190 | printf("Child is ready, it will try to PT_ATTACH to parent\n"); | ||
191 | rv = write(fds_fromparent[1], &msg, sizeof(msg)); | ||
192 | ATF_REQUIRE(rv == sizeof(msg)); | ||
193 | |||
194 | printf("fds_fromparent is no longer needed - close it\n"); | ||
195 | ATF_REQUIRE(close(fds_fromparent[1]) == 0); | ||
196 | |||
197 | printf("fds_toparent is no longer needed - close it\n"); | ||
198 | ATF_REQUIRE(close(fds_toparent[0]) == 0); | ||
199 | } | ||
200 | |||
201 | ATF_TC(traceme_twice); | ||
202 | ATF_TC_HEAD(traceme_twice, tc) | ||
203 | { | ||
204 | atf_tc_set_md_var(tc, "descr", | ||
205 | "Assert that a process cannot mark its parent a debugger twice"); | ||
206 | } | ||
207 | |||
208 | ATF_TC_BODY(traceme_twice, tc) | ||
209 | { | ||
210 | |||
211 | printf("Mark the parent process (PID %d) a debugger of PID %d\n", | ||
212 | getppid(), getpid()); | ||
213 | ATF_REQUIRE(ptrace(PT_TRACE_ME, 0, NULL, 0) == 0); | ||
214 | |||
215 | printf("Mark the parent process (PID %d) a debugger of PID %d again\n", | ||
216 | getppid(), getpid()); | ||
217 | ATF_REQUIRE_ERRNO(EBUSY, ptrace(PT_TRACE_ME, 0, NULL, 0) == -1); | ||
218 | } | ||
219 | |||
220 | ATF_TP_ADD_TCS(tp) | ||
221 | { | ||
222 | setvbuf(stdout, NULL, _IONBF, 0); | ||
223 | setvbuf(stderr, NULL, _IONBF, 0); | ||
224 | ATF_TP_ADD_TC(tp, attach_pid0); | ||
225 | ATF_TP_ADD_TC(tp, attach_pid1); | ||
226 | ATF_TP_ADD_TC(tp, attach_pid1_securelevel); | ||
227 | ATF_TP_ADD_TC(tp, attach_self); | ||
228 | ATF_TP_ADD_TC(tp, attach_chroot); | ||
229 | ATF_TP_ADD_TC(tp, traceme_twice); | ||
230 | |||
231 | return atf_no_error(); | ||
232 | } | ||
diff --git a/src/regress/lib/libc/sys/t_recvmmsg.c b/src/regress/lib/libc/sys/t_recvmmsg.c deleted file mode 100644 index 793692dac1..0000000000 --- a/src/regress/lib/libc/sys/t_recvmmsg.c +++ /dev/null | |||
@@ -1,189 +0,0 @@ | |||
1 | /* $OpenBSD: t_recvmmsg.c,v 1.2 2022/09/11 20:51:44 mbuhl Exp $ */ | ||
2 | /* $NetBSD: t_recvmmsg.c,v 1.4 2018/08/21 10:39:21 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2012 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jared McNeill and Christos Zoulas. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * 3. All advertising materials mentioning features or use of this software | ||
20 | * must display the following acknowledgement: | ||
21 | * This product includes software developed by the NetBSD | ||
22 | * Foundation, Inc. and its contributors. | ||
23 | * 4. Neither the name of The NetBSD Foundation nor the names of its | ||
24 | * contributors may be used to endorse or promote products derived | ||
25 | * from this software without specific prior written permission. | ||
26 | * | ||
27 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
28 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
29 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
30 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
31 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
37 | * POSSIBILITY OF SUCH DAMAGE. | ||
38 | */ | ||
39 | #include <sys/cdefs.h> | ||
40 | |||
41 | #include "atf-c.h" | ||
42 | #include <sys/types.h> | ||
43 | #include <sys/socket.h> | ||
44 | #include <sys/wait.h> | ||
45 | |||
46 | #include <string.h> | ||
47 | #include <time.h> | ||
48 | #include <stdint.h> | ||
49 | #include <errno.h> | ||
50 | #include <signal.h> | ||
51 | #include <stdio.h> | ||
52 | #include <stdlib.h> | ||
53 | #include <unistd.h> | ||
54 | #include <sched.h> | ||
55 | |||
56 | #define BUFSIZE 65536 | ||
57 | #define NPKTS 50 | ||
58 | |||
59 | #define min(a, b) ((a) < (b) ? (a) : (b)) | ||
60 | static int debug; | ||
61 | static volatile sig_atomic_t rdied; | ||
62 | |||
63 | static void | ||
64 | handle_sigchld(__unused int pid) | ||
65 | { | ||
66 | |||
67 | rdied = 1; | ||
68 | } | ||
69 | |||
70 | ATF_TC(recvmmsg_basic); | ||
71 | ATF_TC_HEAD(recvmmsg_basic, tc) | ||
72 | { | ||
73 | atf_tc_set_md_var(tc, "descr", "A basic test of recvmmsg(2)"); | ||
74 | } | ||
75 | |||
76 | ATF_TC_BODY(recvmmsg_basic, tc) | ||
77 | { | ||
78 | int fd[2], error, i, cnt; | ||
79 | uint8_t *buf; | ||
80 | struct mmsghdr *mmsghdr; | ||
81 | struct iovec *iov; | ||
82 | unsigned int mmsgcnt, n; | ||
83 | int status; | ||
84 | off_t off; | ||
85 | uint8_t DGRAM[1316] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, }; | ||
86 | struct sigaction sa; | ||
87 | ssize_t overf = 0; | ||
88 | |||
89 | error = socketpair(AF_UNIX, SOCK_DGRAM, 0, fd); | ||
90 | ATF_REQUIRE_MSG(error != -1, "socketpair failed (%s)", strerror(errno)); | ||
91 | |||
92 | buf = malloc(BUFSIZE); | ||
93 | ATF_REQUIRE_MSG(buf != NULL, "malloc failed (%s)", strerror(errno)); | ||
94 | |||
95 | mmsgcnt = BUFSIZE / sizeof(DGRAM); | ||
96 | mmsghdr = malloc(sizeof(*mmsghdr) * mmsgcnt); | ||
97 | ATF_REQUIRE_MSG(mmsghdr != NULL, "malloc failed (%s)", strerror(errno)); | ||
98 | iov = malloc(sizeof(*iov) * mmsgcnt); | ||
99 | ATF_REQUIRE_MSG(iov != NULL, "malloc failed (%s)", strerror(errno)); | ||
100 | |||
101 | for (off = 0, n = 0; n < mmsgcnt; n++) { | ||
102 | iov[n].iov_base = buf + off; | ||
103 | iov[n].iov_len = sizeof(DGRAM); | ||
104 | off += iov[n].iov_len; | ||
105 | mmsghdr[n].msg_hdr.msg_iov = &iov[n]; | ||
106 | mmsghdr[n].msg_hdr.msg_iovlen = 1; | ||
107 | mmsghdr[n].msg_hdr.msg_name = NULL; | ||
108 | mmsghdr[n].msg_hdr.msg_namelen = 0; | ||
109 | } | ||
110 | |||
111 | memset(&sa, 0, sizeof(sa)); | ||
112 | sa.sa_flags = SA_RESTART; | ||
113 | sa.sa_handler = &handle_sigchld; | ||
114 | sigemptyset(&sa.sa_mask); | ||
115 | error = sigaction(SIGCHLD, &sa, 0); | ||
116 | ATF_REQUIRE_MSG(error != -1, "sigaction failed (%s)", | ||
117 | strerror(errno)); | ||
118 | |||
119 | switch (fork()) { | ||
120 | case -1: | ||
121 | ATF_REQUIRE_MSG(0, "fork failed (%s)", strerror(errno)); | ||
122 | break; | ||
123 | |||
124 | case 0: | ||
125 | n = NPKTS; | ||
126 | if (debug) | ||
127 | printf("waiting for %u messages (max %u per syscall)\n", n, | ||
128 | mmsgcnt); | ||
129 | while (n > 0) { | ||
130 | struct timespec ts = { 1, 0 }; | ||
131 | cnt = recvmmsg(fd[1], mmsghdr, min(mmsgcnt, n), | ||
132 | MSG_WAITALL, &ts); | ||
133 | if (cnt == -1 && errno == ENOBUFS) { | ||
134 | overf++; | ||
135 | if (debug) | ||
136 | printf("receive buffer overflowed" | ||
137 | " (%zu)\n",overf); | ||
138 | continue; | ||
139 | } | ||
140 | ATF_REQUIRE_MSG(cnt != -1, "recvmmsg failed (%s)", | ||
141 | strerror(errno)); | ||
142 | ATF_REQUIRE_MSG(cnt != 0, "recvmmsg timeout"); | ||
143 | if (debug) | ||
144 | printf("recvmmsg: got %u messages\n", cnt); | ||
145 | for (i = 0; i < cnt; i++) { | ||
146 | ATF_CHECK_EQ_MSG(mmsghdr[i].msg_len, | ||
147 | sizeof(DGRAM), "packet length"); | ||
148 | ATF_CHECK_EQ_MSG( | ||
149 | ((uint8_t *)iov[i].iov_base)[0], | ||
150 | NPKTS - n + i, "packet contents"); | ||
151 | } | ||
152 | n -= cnt; | ||
153 | } | ||
154 | if (debug) | ||
155 | printf("done!\n"); | ||
156 | exit(0); | ||
157 | /*NOTREACHED*/ | ||
158 | default: | ||
159 | sched_yield(); | ||
160 | |||
161 | for (n = 0; n < NPKTS; n++) { | ||
162 | if (debug) | ||
163 | printf("sending packet %u/%u...\n", (n+1), | ||
164 | NPKTS); | ||
165 | do { | ||
166 | if (rdied) | ||
167 | break; | ||
168 | DGRAM[0] = n; | ||
169 | error = send(fd[0], DGRAM, sizeof(DGRAM), 0); | ||
170 | } while (error == -1 && errno == ENOBUFS); | ||
171 | ATF_REQUIRE_MSG(error != -1, "send failed (%s)", | ||
172 | strerror(errno)); | ||
173 | } | ||
174 | error = wait(&status); | ||
175 | ATF_REQUIRE_MSG(error != -1, "wait failed (%s)", | ||
176 | strerror(errno)); | ||
177 | ATF_REQUIRE_MSG(WIFEXITED(status) && WEXITSTATUS(status) == 0, | ||
178 | "receiver died"); | ||
179 | break; | ||
180 | } | ||
181 | } | ||
182 | |||
183 | ATF_TP_ADD_TCS(tp) | ||
184 | { | ||
185 | |||
186 | ATF_TP_ADD_TC(tp, recvmmsg_basic); | ||
187 | |||
188 | return atf_no_error(); | ||
189 | } | ||
diff --git a/src/regress/lib/libc/sys/t_revoke.c b/src/regress/lib/libc/sys/t_revoke.c deleted file mode 100644 index d330b8832a..0000000000 --- a/src/regress/lib/libc/sys/t_revoke.c +++ /dev/null | |||
@@ -1,198 +0,0 @@ | |||
1 | /* $OpenBSD: t_revoke.c,v 1.3 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_revoke.c,v 1.2 2017/01/13 21:15:57 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/resource.h> | ||
36 | #include <sys/wait.h> | ||
37 | |||
38 | #include "atf-c.h" | ||
39 | #include <fcntl.h> | ||
40 | #include <errno.h> | ||
41 | #include <pwd.h> | ||
42 | #include <stdio.h> | ||
43 | #include <stdlib.h> | ||
44 | #include <string.h> | ||
45 | #include <unistd.h> | ||
46 | |||
47 | static const char path[] = "revoke"; | ||
48 | |||
49 | ATF_TC_WITH_CLEANUP(revoke_basic); | ||
50 | ATF_TC_HEAD(revoke_basic, tc) | ||
51 | { | ||
52 | atf_tc_set_md_var(tc, "descr", "A basic test of revoke(2)"); | ||
53 | } | ||
54 | |||
55 | ATF_TC_BODY(revoke_basic, tc) | ||
56 | { | ||
57 | struct rlimit res; | ||
58 | char tmp[10]; | ||
59 | size_t i, n; | ||
60 | int *buf; | ||
61 | |||
62 | (void)memset(&res, 0, sizeof(struct rlimit)); | ||
63 | (void)getrlimit(RLIMIT_NOFILE, &res); | ||
64 | |||
65 | if ((n = res.rlim_cur / 10) == 0) | ||
66 | n = 10; | ||
67 | |||
68 | buf = calloc(n, sizeof(int)); | ||
69 | ATF_REQUIRE(buf != NULL); | ||
70 | |||
71 | buf[0] = open(path, O_RDWR | O_CREAT, 0600); | ||
72 | ATF_REQUIRE(buf[0] >= 0); | ||
73 | |||
74 | for (i = 1; i < n; i++) { | ||
75 | buf[i] = open(path, O_RDWR); | ||
76 | ATF_REQUIRE(buf[i] >= 0); | ||
77 | } | ||
78 | |||
79 | ATF_REQUIRE(revoke(path) == 0); | ||
80 | |||
81 | for (i = 0; i < n; i++) { | ||
82 | |||
83 | ATF_REQUIRE(read(buf[i], tmp, sizeof(tmp)) == -1); | ||
84 | |||
85 | (void)close(buf[i]); | ||
86 | } | ||
87 | |||
88 | free(buf); | ||
89 | |||
90 | (void)unlink(path); | ||
91 | } | ||
92 | |||
93 | ATF_TC_CLEANUP(revoke_basic, tc) | ||
94 | { | ||
95 | (void)unlink(path); | ||
96 | } | ||
97 | |||
98 | ATF_TC(revoke_err); | ||
99 | ATF_TC_HEAD(revoke_err, tc) | ||
100 | { | ||
101 | atf_tc_set_md_var(tc, "descr", "Test errors from revoke(2)"); | ||
102 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
103 | } | ||
104 | |||
105 | ATF_TC_BODY(revoke_err, tc) | ||
106 | { | ||
107 | char buf[1024 + 1]; /* XXX: From the manual page... */ | ||
108 | |||
109 | (void)memset(buf, 'x', sizeof(buf)); | ||
110 | |||
111 | errno = 0; | ||
112 | ATF_REQUIRE_ERRNO(EFAULT, revoke((char *)-1) == -1); | ||
113 | |||
114 | errno = 0; | ||
115 | ATF_REQUIRE_ERRNO(ENAMETOOLONG, revoke(buf) == -1); | ||
116 | |||
117 | errno = 0; | ||
118 | #ifdef __OpenBSD__ | ||
119 | ATF_REQUIRE_ERRNO(ENOTTY, revoke("/etc/passwd") == -1); | ||
120 | #else | ||
121 | ATF_REQUIRE_ERRNO(EPERM, revoke("/etc/passwd") == -1); | ||
122 | #endif | ||
123 | |||
124 | errno = 0; | ||
125 | ATF_REQUIRE_ERRNO(ENOENT, revoke("/etc/xxx/yyy") == -1); | ||
126 | } | ||
127 | |||
128 | ATF_TC_WITH_CLEANUP(revoke_perm); | ||
129 | ATF_TC_HEAD(revoke_perm, tc) | ||
130 | { | ||
131 | atf_tc_set_md_var(tc, "descr", "Test permissions revoke(2)"); | ||
132 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
133 | } | ||
134 | |||
135 | ATF_TC_BODY(revoke_perm, tc) | ||
136 | { | ||
137 | struct passwd *pw; | ||
138 | int fd, sta; | ||
139 | pid_t pid; | ||
140 | |||
141 | pw = getpwnam("nobody"); | ||
142 | fd = open(path, O_RDWR | O_CREAT, 0600); | ||
143 | |||
144 | ATF_REQUIRE(fd >= 0); | ||
145 | ATF_REQUIRE(pw != NULL); | ||
146 | ATF_REQUIRE(revoke(path) == 0); | ||
147 | |||
148 | pid = fork(); | ||
149 | ATF_REQUIRE(pid >= 0); | ||
150 | |||
151 | if (pid == 0) { | ||
152 | |||
153 | if (setuid(pw->pw_uid) != 0) | ||
154 | _exit(EXIT_FAILURE); | ||
155 | |||
156 | errno = 0; | ||
157 | |||
158 | if (revoke(path) == 0) | ||
159 | _exit(EXIT_FAILURE); | ||
160 | |||
161 | if (errno != EACCES) | ||
162 | _exit(EXIT_FAILURE); | ||
163 | |||
164 | if (close(fd) != 0) | ||
165 | _exit(EXIT_FAILURE); | ||
166 | |||
167 | _exit(EXIT_SUCCESS); | ||
168 | } | ||
169 | |||
170 | (void)wait(&sta); | ||
171 | |||
172 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
173 | atf_tc_fail("revoke(2) did not obey permissions"); | ||
174 | |||
175 | (void)close(fd); | ||
176 | ATF_REQUIRE(unlink(path) == 0); | ||
177 | } | ||
178 | |||
179 | ATF_TC_CLEANUP(revoke_perm, tc) | ||
180 | { | ||
181 | (void)unlink(path); | ||
182 | } | ||
183 | |||
184 | ATF_TP_ADD_TCS(tp) | ||
185 | { | ||
186 | |||
187 | #ifndef __OpenBSD__ | ||
188 | /* OpenBSD supports revoke only on ttys */ | ||
189 | ATF_TP_ADD_TC(tp, revoke_basic); | ||
190 | #endif | ||
191 | ATF_TP_ADD_TC(tp, revoke_err); | ||
192 | #ifndef __OpenBSD__ | ||
193 | /* OpenBSD supports revoke only on ttys */ | ||
194 | ATF_TP_ADD_TC(tp, revoke_perm); | ||
195 | #endif | ||
196 | |||
197 | return atf_no_error(); | ||
198 | } | ||
diff --git a/src/regress/lib/libc/sys/t_select.c b/src/regress/lib/libc/sys/t_select.c deleted file mode 100644 index b10fe87495..0000000000 --- a/src/regress/lib/libc/sys/t_select.c +++ /dev/null | |||
@@ -1,227 +0,0 @@ | |||
1 | /* $OpenBSD: t_select.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ | ||
2 | /* $NetBSD: t_select.c,v 1.4 2017/01/13 21:18:33 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundatiom | ||
9 | * by Christos Zoulas. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <assert.h> | ||
36 | #include <sys/types.h> | ||
37 | #include <sys/select.h> | ||
38 | #include <sys/wait.h> | ||
39 | #include <err.h> | ||
40 | #include <stdio.h> | ||
41 | #include <string.h> | ||
42 | #include <signal.h> | ||
43 | #include <stdlib.h> | ||
44 | #include <unistd.h> | ||
45 | #include <errno.h> | ||
46 | #include <fcntl.h> | ||
47 | |||
48 | #include "atf-c.h" | ||
49 | |||
50 | static sig_atomic_t keep_going = 1; | ||
51 | |||
52 | static void | ||
53 | sig_handler(int signum __unused) | ||
54 | { | ||
55 | keep_going = 0; | ||
56 | } | ||
57 | |||
58 | static void | ||
59 | sigchld(int signum __unused) | ||
60 | { | ||
61 | } | ||
62 | |||
63 | static char | ||
64 | xtoa(uint8_t n) | ||
65 | { | ||
66 | static const char xarray[] = "0123456789abcdef"; | ||
67 | assert(n < sizeof(xarray)); | ||
68 | return xarray[n]; | ||
69 | } | ||
70 | |||
71 | static const char * | ||
72 | prmask(const sigset_t *m, char *buf, size_t len) | ||
73 | { | ||
74 | size_t j = 2; | ||
75 | assert(len >= 3 + sizeof(*m)); | ||
76 | buf[0] = '0'; | ||
77 | buf[1] = 'x'; | ||
78 | #define N(p, a) (((p) >> ((a) * 4)) & 0xf) | ||
79 | #ifdef __OpenBSD__ | ||
80 | /* On NetBSD sigset_t is a struct */ | ||
81 | uint32_t p = (*m); | ||
82 | for (size_t k = sizeof(p); k > 0; k--) | ||
83 | buf[j++] = xtoa(N(p, k - 1)); | ||
84 | #else | ||
85 | for (size_t i = __arraycount(m->__bits); i > 0; i--) { | ||
86 | uint32_t p = m->__bits[i - 1]; | ||
87 | for (size_t k = sizeof(p); k > 0; k--) | ||
88 | buf[j++] = xtoa(N(p, k - 1)); | ||
89 | } | ||
90 | #endif | ||
91 | buf[j] = '\0'; | ||
92 | return buf; | ||
93 | } | ||
94 | |||
95 | static __dead void | ||
96 | child(const struct timespec *ts) | ||
97 | { | ||
98 | struct sigaction sa; | ||
99 | sigset_t set, oset, nset; | ||
100 | char obuf[sizeof(oset) + 3], nbuf[sizeof(nset) + 3]; | ||
101 | int fd; | ||
102 | |||
103 | memset(&sa, 0, sizeof(sa)); | ||
104 | sa.sa_handler = sig_handler; | ||
105 | if ((fd = open("/dev/null", O_RDONLY)) == -1) | ||
106 | err(1, "open"); | ||
107 | |||
108 | if (sigaction(SIGTERM, &sa, NULL) == -1) | ||
109 | err(1, "sigaction"); | ||
110 | |||
111 | sigfillset(&set); | ||
112 | if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) | ||
113 | err(1, "sigprocmask"); | ||
114 | |||
115 | if (sigprocmask(SIG_BLOCK, NULL, &oset) == -1) | ||
116 | err(1, "sigprocmask"); | ||
117 | |||
118 | sigemptyset(&set); | ||
119 | |||
120 | for (;;) { | ||
121 | fd_set rset; | ||
122 | FD_ZERO(&rset); | ||
123 | FD_SET(fd, &rset); | ||
124 | if (pselect(1, &rset, NULL, NULL, ts, &set) == -1) { | ||
125 | if(errno == EINTR) { | ||
126 | if (!keep_going) | ||
127 | break; | ||
128 | } | ||
129 | } | ||
130 | if (ts) | ||
131 | break; | ||
132 | } | ||
133 | if (sigprocmask(SIG_BLOCK, NULL, &nset) == -1) | ||
134 | err(1, "sigprocmask"); | ||
135 | if (memcmp(&oset, &nset, sizeof(oset)) != 0) | ||
136 | atf_tc_fail("pselect() masks don't match " | ||
137 | "after timeout %s != %s", | ||
138 | prmask(&nset, nbuf, sizeof(nbuf)), | ||
139 | prmask(&oset, obuf, sizeof(obuf))); | ||
140 | _exit(0); | ||
141 | } | ||
142 | |||
143 | ATF_TC(pselect_sigmask); | ||
144 | ATF_TC_HEAD(pselect_sigmask, tc) | ||
145 | { | ||
146 | atf_tc_set_md_var(tc, "descr", "Checks pselect's temporary mask " | ||
147 | "setting when a signal is received (PR lib/43625)"); | ||
148 | } | ||
149 | |||
150 | ATF_TC_BODY(pselect_sigmask, tc) | ||
151 | { | ||
152 | pid_t pid; | ||
153 | int status; | ||
154 | |||
155 | signal(SIGCHLD, sigchld); | ||
156 | |||
157 | switch (pid = fork()) { | ||
158 | case 0: | ||
159 | child(NULL); | ||
160 | /*NOTREACHED*/ | ||
161 | case -1: | ||
162 | err(1, "fork"); | ||
163 | default: | ||
164 | sleep(1); | ||
165 | if (kill(pid, SIGTERM) == -1) | ||
166 | err(1, "kill"); | ||
167 | sleep(1); | ||
168 | switch (waitpid(pid, &status, WNOHANG)) { | ||
169 | case -1: | ||
170 | err(1, "wait"); | ||
171 | case 0: | ||
172 | if (kill(pid, SIGKILL) == -1) | ||
173 | err(1, "kill"); | ||
174 | atf_tc_fail("pselect() did not receive signal"); | ||
175 | break; | ||
176 | default: | ||
177 | break; | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | |||
182 | ATF_TC(pselect_timeout); | ||
183 | ATF_TC_HEAD(pselect_timeout, tc) | ||
184 | { | ||
185 | |||
186 | atf_tc_set_md_var(tc, "descr", "Checks pselect's temporary mask " | ||
187 | "setting when a timeout occurs"); | ||
188 | } | ||
189 | |||
190 | ATF_TC_BODY(pselect_timeout, tc) | ||
191 | { | ||
192 | pid_t pid; | ||
193 | int status; | ||
194 | static const struct timespec zero = { 0, 0 }; | ||
195 | |||
196 | signal(SIGCHLD, sigchld); | ||
197 | |||
198 | switch (pid = fork()) { | ||
199 | case 0: | ||
200 | child(&zero); | ||
201 | break; | ||
202 | case -1: | ||
203 | err(1, "fork"); | ||
204 | default: | ||
205 | sleep(1); | ||
206 | switch (waitpid(pid, &status, WNOHANG)) { | ||
207 | case -1: | ||
208 | err(1, "wait"); | ||
209 | case 0: | ||
210 | if (kill(pid, SIGKILL) == -1) | ||
211 | err(1, "kill"); | ||
212 | atf_tc_fail("pselect() did not receive signal"); | ||
213 | break; | ||
214 | default: | ||
215 | break; | ||
216 | } | ||
217 | } | ||
218 | } | ||
219 | |||
220 | ATF_TP_ADD_TCS(tp) | ||
221 | { | ||
222 | |||
223 | ATF_TP_ADD_TC(tp, pselect_sigmask); | ||
224 | ATF_TP_ADD_TC(tp, pselect_timeout); | ||
225 | |||
226 | return atf_no_error(); | ||
227 | } | ||
diff --git a/src/regress/lib/libc/sys/t_sendmmsg.c b/src/regress/lib/libc/sys/t_sendmmsg.c deleted file mode 100644 index 46a2e9bf5c..0000000000 --- a/src/regress/lib/libc/sys/t_sendmmsg.c +++ /dev/null | |||
@@ -1,216 +0,0 @@ | |||
1 | /* $OpenBSD: t_sendmmsg.c,v 1.3 2023/10/27 07:33:06 anton Exp $ */ | ||
2 | /* $NetBSD: t_sendmmsg.c,v 1.3 2019/03/16 21:46:43 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Christos Zoulas. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | #include <sys/cdefs.h> | ||
33 | |||
34 | #include "atf-c.h" | ||
35 | #include <sys/types.h> | ||
36 | #include <sys/socket.h> | ||
37 | #include <sys/ioctl.h> | ||
38 | #include <sys/wait.h> | ||
39 | |||
40 | #include <string.h> | ||
41 | #include <time.h> | ||
42 | #include <stdint.h> | ||
43 | #include <errno.h> | ||
44 | #include <signal.h> | ||
45 | #include <stdio.h> | ||
46 | #include <stdlib.h> | ||
47 | #include <unistd.h> | ||
48 | #include <sched.h> | ||
49 | |||
50 | #define BUFSIZE 65536 | ||
51 | |||
52 | #define min(a, b) ((a) < (b) ? (a) : (b)) | ||
53 | static int debug; | ||
54 | static volatile sig_atomic_t rdied; | ||
55 | |||
56 | static void | ||
57 | handle_sigchld(__unused int pid) | ||
58 | { | ||
59 | |||
60 | rdied = 1; | ||
61 | } | ||
62 | |||
63 | ATF_TC(sendmmsg_basic); | ||
64 | ATF_TC_HEAD(sendmmsg_basic, tc) | ||
65 | { | ||
66 | atf_tc_set_md_var(tc, "descr", "A basic test of sendmmsg(2)"); | ||
67 | } | ||
68 | |||
69 | static void | ||
70 | setsock(int fd, int type) | ||
71 | { | ||
72 | int buflen = BUFSIZE; | ||
73 | socklen_t socklen = sizeof(buflen); | ||
74 | |||
75 | ATF_REQUIRE_MSG(setsockopt(fd, SOL_SOCKET, type, | ||
76 | &buflen, socklen) != -1, "%s (%s)", | ||
77 | type == SO_RCVBUF ? "rcv" : "snd", strerror(errno)); | ||
78 | } | ||
79 | |||
80 | ATF_TC_BODY(sendmmsg_basic, tc) | ||
81 | { | ||
82 | int fd[2], error, cnt; | ||
83 | uint8_t *buf; | ||
84 | struct mmsghdr *mmsghdr; | ||
85 | struct iovec *iov; | ||
86 | unsigned int mmsgcnt, n; | ||
87 | int status; | ||
88 | off_t off; | ||
89 | uint8_t DGRAM[1316] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, }; | ||
90 | uint8_t rgram[sizeof(DGRAM)]; | ||
91 | struct sigaction sa; | ||
92 | ssize_t overf = 0; | ||
93 | |||
94 | error = socketpair(AF_UNIX, SOCK_DGRAM, 0, fd); | ||
95 | ATF_REQUIRE_MSG(error != -1, "socketpair failed (%s)", strerror(errno)); | ||
96 | |||
97 | buf = malloc(BUFSIZE); | ||
98 | ATF_REQUIRE_MSG(buf != NULL, "malloc failed (%s)", strerror(errno)); | ||
99 | |||
100 | setsock(fd[1], SO_SNDBUF); | ||
101 | // setsock(fd[0], SO_RCVBUF); | ||
102 | |||
103 | mmsgcnt = BUFSIZE / sizeof(DGRAM); | ||
104 | mmsghdr = calloc(mmsgcnt, sizeof(*mmsghdr)); | ||
105 | ATF_REQUIRE_MSG(mmsghdr != NULL, "malloc failed (%s)", strerror(errno)); | ||
106 | iov = malloc(sizeof(*iov) * mmsgcnt); | ||
107 | ATF_REQUIRE_MSG(iov != NULL, "malloc failed (%s)", strerror(errno)); | ||
108 | |||
109 | for (off = 0, n = 0; n < mmsgcnt; n++) { | ||
110 | iov[n].iov_base = buf + off; | ||
111 | memcpy(iov[n].iov_base, DGRAM, sizeof(DGRAM)); | ||
112 | *(buf + off) = n; | ||
113 | iov[n].iov_len = sizeof(DGRAM); | ||
114 | off += iov[n].iov_len; | ||
115 | mmsghdr[n].msg_hdr.msg_iov = &iov[n]; | ||
116 | mmsghdr[n].msg_hdr.msg_iovlen = 1; | ||
117 | mmsghdr[n].msg_hdr.msg_name = NULL; | ||
118 | mmsghdr[n].msg_hdr.msg_namelen = 0; | ||
119 | } | ||
120 | |||
121 | memset(&sa, 0, sizeof(sa)); | ||
122 | sa.sa_flags = SA_RESTART; | ||
123 | sa.sa_handler = &handle_sigchld; | ||
124 | sigemptyset(&sa.sa_mask); | ||
125 | error = sigaction(SIGCHLD, &sa, 0); | ||
126 | ATF_REQUIRE_MSG(error != -1, "sigaction failed (%s)", | ||
127 | strerror(errno)); | ||
128 | |||
129 | switch (fork()) { | ||
130 | case -1: | ||
131 | ATF_REQUIRE_MSG(0, "fork failed (%s)", strerror(errno)); | ||
132 | break; | ||
133 | case 0: | ||
134 | sched_yield(); | ||
135 | if (debug) | ||
136 | printf("sending %u messages (max %u per syscall)\n", n, | ||
137 | mmsgcnt); | ||
138 | for (n = 0; n < mmsgcnt;) { | ||
139 | if (debug) | ||
140 | printf("sending packet %u/%u...\n", n, | ||
141 | mmsgcnt); | ||
142 | #ifdef __OpenBSD__ | ||
143 | int npkt = min(1024, mmsgcnt - n); | ||
144 | #else | ||
145 | // XXX: ENOBUFS bug, on the receive side!!! | ||
146 | // in npkt = min(mmsgsize, mmsgcnt - n); | ||
147 | int npkt = min(3, mmsgcnt - n), a; | ||
148 | do { | ||
149 | a = 0; | ||
150 | ATF_REQUIRE(ioctl(fd[1], FIONSPACE, &a) != -1); | ||
151 | printf("1 %d\n", a); | ||
152 | ATF_REQUIRE(ioctl(fd[0], FIONSPACE, &a) != -1); | ||
153 | printf("0 %d\n", a); | ||
154 | } while ((size_t)a < sizeof(DGRAM)); | ||
155 | #endif | ||
156 | cnt = sendmmsg(fd[1], mmsghdr + n, npkt, 0); | ||
157 | if (cnt == -1 && errno == ENOBUFS) { | ||
158 | overf++; | ||
159 | if (debug) | ||
160 | printf("send buffer overflowed" | ||
161 | " (%zu)\n",overf); | ||
162 | if (overf > 100) | ||
163 | exit(1); | ||
164 | sched_yield(); | ||
165 | sched_yield(); | ||
166 | sched_yield(); | ||
167 | continue; | ||
168 | } | ||
169 | ATF_REQUIRE_MSG(cnt != -1, "sendmmsg %u failed (%s)", | ||
170 | n, strerror(errno)); | ||
171 | if (debug) | ||
172 | printf("sendmmsg: sent %u messages\n", cnt); | ||
173 | n += cnt; | ||
174 | sched_yield(); | ||
175 | sched_yield(); | ||
176 | sched_yield(); | ||
177 | } | ||
178 | if (debug) | ||
179 | printf("done!\n"); | ||
180 | exit(0); | ||
181 | /*NOTREACHED*/ | ||
182 | default: | ||
183 | for (n = 0; n < mmsgcnt; n++) { | ||
184 | if (debug) | ||
185 | printf("receiving packet %u/%u...\n", n, | ||
186 | mmsgcnt); | ||
187 | do { | ||
188 | if (rdied) | ||
189 | break; | ||
190 | cnt = recv(fd[0], rgram, sizeof(rgram), 0); | ||
191 | ATF_REQUIRE_MSG(cnt != -1 || errno != ENOBUFS, | ||
192 | "recv failed (%s)", strerror(errno)); | ||
193 | ATF_CHECK_EQ_MSG(cnt, sizeof(rgram), | ||
194 | "packet length"); | ||
195 | ATF_CHECK_EQ_MSG(rgram[0], n, | ||
196 | "number %u != %u", rgram[0], n); | ||
197 | ATF_REQUIRE_MSG(memcmp(rgram + 1, DGRAM + 1, | ||
198 | sizeof(rgram) - 1) == 0, "bad data"); | ||
199 | } while (cnt == -1 && errno == ENOBUFS); | ||
200 | } | ||
201 | error = wait(&status); | ||
202 | ATF_REQUIRE_MSG(error != -1, "wait failed (%s)", | ||
203 | strerror(errno)); | ||
204 | ATF_REQUIRE_MSG(WIFEXITED(status) && WEXITSTATUS(status) == 0, | ||
205 | "receiver died, status %d", status); | ||
206 | break; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | ATF_TP_ADD_TCS(tp) | ||
211 | { | ||
212 | |||
213 | ATF_TP_ADD_TC(tp, sendmmsg_basic); | ||
214 | |||
215 | return atf_no_error(); | ||
216 | } | ||
diff --git a/src/regress/lib/libc/sys/t_sendrecv.c b/src/regress/lib/libc/sys/t_sendrecv.c deleted file mode 100644 index 178d9338b8..0000000000 --- a/src/regress/lib/libc/sys/t_sendrecv.c +++ /dev/null | |||
@@ -1,189 +0,0 @@ | |||
1 | /* $OpenBSD: t_sendrecv.c,v 1.4 2024/07/30 13:28:27 claudio Exp $ */ | ||
2 | /* $NetBSD: t_sendrecv.c,v 1.8 2021/03/28 17:30:01 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Christos Zoulas. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include "atf-c.h" | ||
36 | #include <sys/types.h> | ||
37 | #include <sys/socket.h> | ||
38 | |||
39 | #include <string.h> | ||
40 | #include <stdint.h> | ||
41 | #include <errno.h> | ||
42 | #include <stdio.h> | ||
43 | #include <stdlib.h> | ||
44 | #include <sched.h> | ||
45 | #include <unistd.h> | ||
46 | #include <signal.h> | ||
47 | |||
48 | |||
49 | #define COUNT 100 | ||
50 | |||
51 | union packet { | ||
52 | uint8_t buf[1316]; | ||
53 | uintmax_t seq; | ||
54 | }; | ||
55 | |||
56 | static volatile sig_atomic_t rdied; | ||
57 | |||
58 | static void | ||
59 | handle_sigchld(__unused int pid) | ||
60 | { | ||
61 | |||
62 | rdied = 1; | ||
63 | } | ||
64 | |||
65 | static void | ||
66 | sender(int sd) | ||
67 | { | ||
68 | union packet p; | ||
69 | ssize_t n; | ||
70 | p.seq = 0; | ||
71 | for (size_t i = 0; i < COUNT; i++) { | ||
72 | for (; (n = send(sd, &p, sizeof(p), 0)) == sizeof(p); | ||
73 | p.seq++) | ||
74 | continue; | ||
75 | // printf(">>%zd %d %ju\n", n, errno, p.seq); | ||
76 | ATF_REQUIRE_MSG(errno == ENOBUFS, "send %s", strerror(errno)); | ||
77 | } | ||
78 | close(sd); | ||
79 | // printf("sender done\n"); | ||
80 | } | ||
81 | |||
82 | static void | ||
83 | receiver(int sd) | ||
84 | { | ||
85 | union packet p; | ||
86 | ssize_t n; | ||
87 | uintmax_t seq = 0; | ||
88 | |||
89 | for (size_t i = 0; i < COUNT; i++) { | ||
90 | if (rdied) | ||
91 | return; | ||
92 | while ((n = recv(sd, &p, sizeof(p), 0), sizeof(p)) | ||
93 | == sizeof(p)) | ||
94 | { | ||
95 | if (rdied) | ||
96 | return; | ||
97 | if (p.seq != seq) | ||
98 | printf("%ju != %ju\n", p.seq, seq); | ||
99 | if (seq % 10 == 0) | ||
100 | usleep(100); | ||
101 | seq = p.seq + 1; | ||
102 | } | ||
103 | // printf("<<%zd %d %ju\n", n, errno, seq); | ||
104 | if (n == 0) | ||
105 | return; | ||
106 | ATF_REQUIRE_EQ(n, -1); | ||
107 | ATF_REQUIRE_MSG(errno == ENOBUFS, "recv %s", strerror(errno)); | ||
108 | } | ||
109 | close(sd); | ||
110 | } | ||
111 | |||
112 | static void | ||
113 | sendrecv(int rerror) | ||
114 | { | ||
115 | int fd[2], sd[2], error; | ||
116 | char c = 0; | ||
117 | struct sigaction sa; | ||
118 | |||
119 | error = socketpair(AF_UNIX, SOCK_DGRAM, 0, sd); | ||
120 | ATF_REQUIRE_MSG(error != -1, "socketpair failed (%s)", strerror(errno)); | ||
121 | error = pipe(fd); | ||
122 | ATF_REQUIRE_MSG(error != -1, "pipe failed (%s)", strerror(errno)); | ||
123 | |||
124 | for (size_t i = 0; i < __arraycount(sd); i++) { | ||
125 | error = setsockopt(sd[i], SOL_SOCKET, SO_RERROR, &rerror, | ||
126 | sizeof(rerror)); | ||
127 | ATF_REQUIRE_MSG(error != -1, | ||
128 | "setsockopt(SO_RERROR) failed (%s)", strerror(errno)); | ||
129 | } | ||
130 | |||
131 | memset(&sa, 0, sizeof(sa)); | ||
132 | sa.sa_flags = 0; | ||
133 | sa.sa_handler = &handle_sigchld; | ||
134 | sigemptyset(&sa.sa_mask); | ||
135 | error = sigaction(SIGCHLD, &sa, 0); | ||
136 | ATF_REQUIRE_MSG(error != -1, "sigaction failed (%s)", | ||
137 | strerror(errno)); | ||
138 | |||
139 | switch (fork()) { | ||
140 | case -1: | ||
141 | ATF_REQUIRE_MSG(errno == 0, | ||
142 | "fork failed (%s)", strerror(errno)); | ||
143 | __unreachable(); | ||
144 | /*NOTREACHED*/ | ||
145 | case 0: | ||
146 | read(fd[1], &c, sizeof(c)); | ||
147 | sender(sd[0]); | ||
148 | close(sd[0]); | ||
149 | exit(EXIT_SUCCESS); | ||
150 | /*NOTREACHED*/ | ||
151 | default: | ||
152 | write(fd[0], &c, sizeof(c)); | ||
153 | receiver(sd[1]); | ||
154 | return; | ||
155 | } | ||
156 | } | ||
157 | |||
158 | ATF_TC(sendrecv_basic); | ||
159 | |||
160 | ATF_TC_HEAD(sendrecv_basic, tc) | ||
161 | { | ||
162 | atf_tc_set_md_var(tc, "descr", "A basic test of send/recv(2)"); | ||
163 | } | ||
164 | |||
165 | ATF_TC_BODY(sendrecv_basic, tc) | ||
166 | { | ||
167 | sendrecv(0); | ||
168 | } | ||
169 | |||
170 | ATF_TC(sendrecv_rerror); | ||
171 | |||
172 | ATF_TC_HEAD(sendrecv_rerror, tc) | ||
173 | { | ||
174 | atf_tc_set_md_var(tc, "descr", "Test send/recv(2) with receiver error"); | ||
175 | } | ||
176 | |||
177 | ATF_TC_BODY(sendrecv_rerror, tc) | ||
178 | { | ||
179 | sendrecv(1); | ||
180 | } | ||
181 | |||
182 | ATF_TP_ADD_TCS(tp) | ||
183 | { | ||
184 | |||
185 | ATF_TP_ADD_TC(tp, sendrecv_basic); | ||
186 | ATF_TP_ADD_TC(tp, sendrecv_rerror); | ||
187 | |||
188 | return atf_no_error(); | ||
189 | } | ||
diff --git a/src/regress/lib/libc/sys/t_setrlimit.c b/src/regress/lib/libc/sys/t_setrlimit.c deleted file mode 100644 index c9c64d42f0..0000000000 --- a/src/regress/lib/libc/sys/t_setrlimit.c +++ /dev/null | |||
@@ -1,556 +0,0 @@ | |||
1 | /* $OpenBSD: t_setrlimit.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_setrlimit.c,v 1.7 2020/10/13 06:58:57 rin Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | #include "macros.h" | ||
33 | |||
34 | #include <sys/resource.h> | ||
35 | #include <sys/mman.h> | ||
36 | #include <sys/wait.h> | ||
37 | |||
38 | #include "atf-c.h" | ||
39 | #include <errno.h> | ||
40 | #include <fcntl.h> | ||
41 | #include <limits.h> | ||
42 | #ifndef __OpenBSD__ | ||
43 | #include <lwp.h> | ||
44 | #endif | ||
45 | #include <signal.h> | ||
46 | #include <stdint.h> | ||
47 | #include <stdio.h> | ||
48 | #include <stdlib.h> | ||
49 | #include <string.h> | ||
50 | #ifndef __OpenBSD__ | ||
51 | #include <ucontext.h> | ||
52 | #endif | ||
53 | #include <unistd.h> | ||
54 | |||
55 | static void sighandler(int); | ||
56 | static const char path[] = "setrlimit"; | ||
57 | |||
58 | static const int rlimit[] = { | ||
59 | #ifndef __OpenBSD__ | ||
60 | RLIMIT_AS, | ||
61 | #endif | ||
62 | RLIMIT_CORE, | ||
63 | RLIMIT_CPU, | ||
64 | RLIMIT_DATA, | ||
65 | RLIMIT_FSIZE, | ||
66 | RLIMIT_MEMLOCK, | ||
67 | RLIMIT_NOFILE, | ||
68 | RLIMIT_NPROC, | ||
69 | RLIMIT_RSS, | ||
70 | #ifndef __OpenBSD__ | ||
71 | RLIMIT_SBSIZE, | ||
72 | #endif | ||
73 | RLIMIT_STACK | ||
74 | }; | ||
75 | |||
76 | ATF_TC(setrlimit_basic); | ||
77 | ATF_TC_HEAD(setrlimit_basic, tc) | ||
78 | { | ||
79 | atf_tc_set_md_var(tc, "descr", "A basic soft limit test"); | ||
80 | } | ||
81 | |||
82 | ATF_TC_BODY(setrlimit_basic, tc) | ||
83 | { | ||
84 | struct rlimit res; | ||
85 | int *buf, lim; | ||
86 | size_t i; | ||
87 | |||
88 | buf = calloc(__arraycount(rlimit), sizeof(int)); | ||
89 | |||
90 | if (buf == NULL) | ||
91 | atf_tc_fail("initialization failed"); | ||
92 | |||
93 | for (i = lim = 0; i < __arraycount(rlimit); i++) { | ||
94 | |||
95 | (void)memset(&res, 0, sizeof(struct rlimit)); | ||
96 | |||
97 | if (getrlimit(rlimit[i], &res) != 0) | ||
98 | continue; | ||
99 | |||
100 | if (res.rlim_cur == RLIM_INFINITY || res.rlim_cur == 0) | ||
101 | continue; | ||
102 | |||
103 | if (res.rlim_cur == res.rlim_max) /* An unprivileged run. */ | ||
104 | continue; | ||
105 | |||
106 | buf[i] = res.rlim_cur; | ||
107 | res.rlim_cur = res.rlim_cur - 1; | ||
108 | |||
109 | if (setrlimit(rlimit[i], &res) != 0) { | ||
110 | lim = rlimit[i]; | ||
111 | goto out; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | out: | ||
116 | for (i = 0; i < __arraycount(rlimit); i++) { | ||
117 | |||
118 | (void)memset(&res, 0, sizeof(struct rlimit)); | ||
119 | |||
120 | if (buf[i] == 0) | ||
121 | continue; | ||
122 | |||
123 | if (getrlimit(rlimit[i], &res) != 0) | ||
124 | continue; | ||
125 | |||
126 | res.rlim_cur = buf[i]; | ||
127 | |||
128 | (void)setrlimit(rlimit[i], &res); | ||
129 | } | ||
130 | |||
131 | if (lim != 0) | ||
132 | atf_tc_fail("failed to set limit (%d)", lim); | ||
133 | free(buf); | ||
134 | } | ||
135 | |||
136 | ATF_TC(setrlimit_current); | ||
137 | ATF_TC_HEAD(setrlimit_current, tc) | ||
138 | { | ||
139 | atf_tc_set_md_var(tc, "descr", "setrlimit(3) with current limits"); | ||
140 | } | ||
141 | |||
142 | ATF_TC_BODY(setrlimit_current, tc) | ||
143 | { | ||
144 | struct rlimit res; | ||
145 | size_t i; | ||
146 | |||
147 | for (i = 0; i < __arraycount(rlimit); i++) { | ||
148 | |||
149 | (void)memset(&res, 0, sizeof(struct rlimit)); | ||
150 | |||
151 | ATF_REQUIRE(getrlimit(rlimit[i], &res) == 0); | ||
152 | ATF_REQUIRE(setrlimit(rlimit[i], &res) == 0); | ||
153 | } | ||
154 | } | ||
155 | |||
156 | ATF_TC(setrlimit_err); | ||
157 | ATF_TC_HEAD(setrlimit_err, tc) | ||
158 | { | ||
159 | atf_tc_set_md_var(tc, "descr", "Test error conditions"); | ||
160 | } | ||
161 | |||
162 | ATF_TC_BODY(setrlimit_err, tc) | ||
163 | { | ||
164 | struct rlimit res; | ||
165 | size_t i; | ||
166 | |||
167 | for (i = 0; i < __arraycount(rlimit); i++) { | ||
168 | |||
169 | errno = 0; | ||
170 | |||
171 | ATF_REQUIRE(getrlimit(rlimit[i], (void *)0) != 0); | ||
172 | ATF_REQUIRE(errno == EFAULT); | ||
173 | } | ||
174 | |||
175 | errno = 0; | ||
176 | |||
177 | ATF_REQUIRE(getrlimit(INT_MAX, &res) != 0); | ||
178 | ATF_REQUIRE(errno == EINVAL); | ||
179 | } | ||
180 | |||
181 | ATF_TC_WITH_CLEANUP(setrlimit_fsize); | ||
182 | ATF_TC_HEAD(setrlimit_fsize, tc) | ||
183 | { | ||
184 | atf_tc_set_md_var(tc, "descr", "Test setrlimit(2), RLIMIT_FSIZE"); | ||
185 | } | ||
186 | |||
187 | ATF_TC_BODY(setrlimit_fsize, tc) | ||
188 | { | ||
189 | struct rlimit res; | ||
190 | int fd, sta; | ||
191 | pid_t pid; | ||
192 | |||
193 | fd = open(path, O_RDWR | O_CREAT, 0700); | ||
194 | |||
195 | if (fd < 0) | ||
196 | atf_tc_fail("initialization failed"); | ||
197 | |||
198 | pid = fork(); | ||
199 | ATF_REQUIRE(pid >= 0); | ||
200 | |||
201 | if (pid == 0) { | ||
202 | |||
203 | res.rlim_cur = 2; | ||
204 | res.rlim_max = 2; | ||
205 | |||
206 | if (setrlimit(RLIMIT_FSIZE, &res) != 0) | ||
207 | _exit(EXIT_FAILURE); | ||
208 | |||
209 | if (signal(SIGXFSZ, sighandler) == SIG_ERR) | ||
210 | _exit(EXIT_FAILURE); | ||
211 | |||
212 | /* | ||
213 | * The third call should generate a SIGXFSZ. | ||
214 | */ | ||
215 | (void)write(fd, "X", 1); | ||
216 | (void)write(fd, "X", 1); | ||
217 | (void)write(fd, "X", 1); | ||
218 | |||
219 | _exit(EXIT_FAILURE); | ||
220 | } | ||
221 | |||
222 | (void)close(fd); | ||
223 | (void)wait(&sta); | ||
224 | (void)unlink(path); | ||
225 | |||
226 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
227 | atf_tc_fail("RLIMIT_FSIZE not enforced"); | ||
228 | } | ||
229 | |||
230 | ATF_TC_CLEANUP(setrlimit_fsize, tc) | ||
231 | { | ||
232 | (void)unlink(path); | ||
233 | } | ||
234 | |||
235 | static void | ||
236 | sighandler(int signo) | ||
237 | { | ||
238 | |||
239 | if (signo != SIGXFSZ) | ||
240 | _exit(EXIT_FAILURE); | ||
241 | |||
242 | _exit(EXIT_SUCCESS); | ||
243 | } | ||
244 | |||
245 | ATF_TC(setrlimit_memlock); | ||
246 | ATF_TC_HEAD(setrlimit_memlock, tc) | ||
247 | { | ||
248 | atf_tc_set_md_var(tc, "descr", "Test setrlimit(2), RLIMIT_MEMLOCK"); | ||
249 | } | ||
250 | |||
251 | ATF_TC_BODY(setrlimit_memlock, tc) | ||
252 | { | ||
253 | struct rlimit res; | ||
254 | void *buf; | ||
255 | long page; | ||
256 | pid_t pid; | ||
257 | int sta; | ||
258 | |||
259 | page = sysconf(_SC_PAGESIZE); | ||
260 | ATF_REQUIRE(page >= 0); | ||
261 | |||
262 | buf = malloc(page); | ||
263 | pid = fork(); | ||
264 | |||
265 | if (buf == NULL || pid < 0) | ||
266 | atf_tc_fail("initialization failed"); | ||
267 | |||
268 | if (pid == 0) { | ||
269 | |||
270 | /* | ||
271 | * Try to lock a page while | ||
272 | * RLIMIT_MEMLOCK is zero. | ||
273 | */ | ||
274 | if (mlock(buf, page) != 0) | ||
275 | _exit(EXIT_FAILURE); | ||
276 | |||
277 | if (munlock(buf, page) != 0) | ||
278 | _exit(EXIT_FAILURE); | ||
279 | |||
280 | res.rlim_cur = 0; | ||
281 | res.rlim_max = 0; | ||
282 | |||
283 | if (setrlimit(RLIMIT_MEMLOCK, &res) != 0) | ||
284 | _exit(EXIT_FAILURE); | ||
285 | |||
286 | if (mlock(buf, page) != 0) | ||
287 | _exit(EXIT_SUCCESS); | ||
288 | |||
289 | (void)munlock(buf, page); | ||
290 | |||
291 | _exit(EXIT_FAILURE); | ||
292 | } | ||
293 | |||
294 | free(buf); | ||
295 | |||
296 | (void)wait(&sta); | ||
297 | |||
298 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
299 | atf_tc_fail("RLIMIT_MEMLOCK not enforced"); | ||
300 | } | ||
301 | |||
302 | ATF_TC(setrlimit_nofile_1); | ||
303 | ATF_TC_HEAD(setrlimit_nofile_1, tc) | ||
304 | { | ||
305 | atf_tc_set_md_var(tc, "descr", "Test setrlimit(2), RLIMIT_NOFILE, #1"); | ||
306 | } | ||
307 | |||
308 | ATF_TC_BODY(setrlimit_nofile_1, tc) | ||
309 | { | ||
310 | struct rlimit res; | ||
311 | int fd, i, rv, sta; | ||
312 | pid_t pid; | ||
313 | |||
314 | res.rlim_cur = 0; | ||
315 | res.rlim_max = 0; | ||
316 | |||
317 | pid = fork(); | ||
318 | ATF_REQUIRE(pid >= 0); | ||
319 | |||
320 | if (pid == 0) { | ||
321 | |||
322 | /* | ||
323 | * Close all descriptors, set RLIMIT_NOFILE | ||
324 | * to zero, and try to open a random file. | ||
325 | * This should fail with EMFILE. | ||
326 | */ | ||
327 | for (i = 0; i < 1024; i++) | ||
328 | (void)close(i); | ||
329 | |||
330 | rv = setrlimit(RLIMIT_NOFILE, &res); | ||
331 | |||
332 | if (rv != 0) | ||
333 | _exit(EXIT_FAILURE); | ||
334 | |||
335 | errno = 0; | ||
336 | fd = open("/etc/passwd", O_RDONLY); | ||
337 | |||
338 | if (fd >= 0 || errno != EMFILE) | ||
339 | _exit(EXIT_FAILURE); | ||
340 | |||
341 | _exit(EXIT_SUCCESS); | ||
342 | } | ||
343 | |||
344 | (void)wait(&sta); | ||
345 | |||
346 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
347 | atf_tc_fail("RLIMIT_NOFILE not enforced"); | ||
348 | } | ||
349 | |||
350 | ATF_TC(setrlimit_nofile_2); | ||
351 | ATF_TC_HEAD(setrlimit_nofile_2, tc) | ||
352 | { | ||
353 | atf_tc_set_md_var(tc, "descr", "Test setrlimit(2), RLIMIT_NOFILE, #2"); | ||
354 | } | ||
355 | |||
356 | ATF_TC_BODY(setrlimit_nofile_2, tc) | ||
357 | { | ||
358 | static const rlim_t lim = 12; | ||
359 | struct rlimit res; | ||
360 | int fd, i, rv, sta; | ||
361 | pid_t pid; | ||
362 | |||
363 | /* | ||
364 | * See that an arbitrary limit on | ||
365 | * open files is being enforced. | ||
366 | */ | ||
367 | res.rlim_cur = lim; | ||
368 | res.rlim_max = lim; | ||
369 | |||
370 | pid = fork(); | ||
371 | ATF_REQUIRE(pid >= 0); | ||
372 | |||
373 | if (pid == 0) { | ||
374 | |||
375 | for (i = 0; i < 1024; i++) | ||
376 | (void)close(i); | ||
377 | |||
378 | rv = setrlimit(RLIMIT_NOFILE, &res); | ||
379 | |||
380 | if (rv != 0) | ||
381 | _exit(EXIT_FAILURE); | ||
382 | |||
383 | for (i = 0; i < (int)lim; i++) { | ||
384 | |||
385 | fd = open("/etc/passwd", O_RDONLY); | ||
386 | |||
387 | if (fd < 0) | ||
388 | _exit(EXIT_FAILURE); | ||
389 | } | ||
390 | |||
391 | /* | ||
392 | * After the limit has been reached, | ||
393 | * EMFILE should again follow. | ||
394 | */ | ||
395 | fd = open("/etc/passwd", O_RDONLY); | ||
396 | |||
397 | if (fd >= 0 || errno != EMFILE) | ||
398 | _exit(EXIT_FAILURE); | ||
399 | |||
400 | _exit(EXIT_SUCCESS); | ||
401 | } | ||
402 | |||
403 | (void)wait(&sta); | ||
404 | |||
405 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
406 | atf_tc_fail("RLIMIT_NOFILE not enforced"); | ||
407 | } | ||
408 | |||
409 | ATF_TC(setrlimit_nproc); | ||
410 | ATF_TC_HEAD(setrlimit_nproc, tc) | ||
411 | { | ||
412 | atf_tc_set_md_var(tc, "descr", "Test setrlimit(2), RLIMIT_NPROC"); | ||
413 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
414 | } | ||
415 | |||
416 | ATF_TC_BODY(setrlimit_nproc, tc) | ||
417 | { | ||
418 | struct rlimit res; | ||
419 | pid_t pid, cpid; | ||
420 | int sta; | ||
421 | |||
422 | pid = fork(); | ||
423 | ATF_REQUIRE(pid >= 0); | ||
424 | |||
425 | if (pid == 0) { | ||
426 | |||
427 | /* | ||
428 | * Set RLIMIT_NPROC to zero and try to fork. | ||
429 | */ | ||
430 | res.rlim_cur = 0; | ||
431 | res.rlim_max = 0; | ||
432 | |||
433 | if (setrlimit(RLIMIT_NPROC, &res) != 0) | ||
434 | _exit(EXIT_FAILURE); | ||
435 | |||
436 | cpid = fork(); | ||
437 | |||
438 | if (cpid < 0) | ||
439 | _exit(EXIT_SUCCESS); | ||
440 | |||
441 | _exit(EXIT_FAILURE); | ||
442 | } | ||
443 | |||
444 | (void)waitpid(pid, &sta, 0); | ||
445 | |||
446 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
447 | atf_tc_fail("RLIMIT_NPROC not enforced"); | ||
448 | } | ||
449 | |||
450 | #ifndef __OpenBSD__ | ||
451 | |||
452 | ATF_TC(setrlimit_nthr); | ||
453 | ATF_TC_HEAD(setrlimit_nthr, tc) | ||
454 | { | ||
455 | atf_tc_set_md_var(tc, "descr", "Test setrlimit(2), RLIMIT_NTHR"); | ||
456 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
457 | } | ||
458 | |||
459 | static void | ||
460 | func(lwpid_t *id) | ||
461 | { | ||
462 | printf("thread %d\n", *id); | ||
463 | fflush(stdout); | ||
464 | _lwp_exit(); | ||
465 | } | ||
466 | |||
467 | ATF_TC_BODY(setrlimit_nthr, tc) | ||
468 | { | ||
469 | struct rlimit res; | ||
470 | lwpid_t lwpid; | ||
471 | ucontext_t c; | ||
472 | |||
473 | /* | ||
474 | * Set RLIMIT_NTHR to zero and try to create a thread. | ||
475 | */ | ||
476 | res.rlim_cur = 0; | ||
477 | res.rlim_max = 0; | ||
478 | ATF_REQUIRE(setrlimit(RLIMIT_NTHR, &res) == 0); | ||
479 | ATF_REQUIRE(getcontext(&c) == 0); | ||
480 | c.uc_link = NULL; | ||
481 | sigemptyset(&c.uc_sigmask); | ||
482 | c.uc_stack.ss_flags = 0; | ||
483 | c.uc_stack.ss_size = 4096; | ||
484 | ATF_REQUIRE((c.uc_stack.ss_sp = malloc(c.uc_stack.ss_size)) != NULL); | ||
485 | makecontext(&c, func, 1, &lwpid); | ||
486 | ATF_CHECK_ERRNO(EAGAIN, _lwp_create(&c, 0, &lwpid) == -1); | ||
487 | } | ||
488 | #endif | ||
489 | |||
490 | ATF_TC(setrlimit_perm); | ||
491 | ATF_TC_HEAD(setrlimit_perm, tc) | ||
492 | { | ||
493 | atf_tc_set_md_var(tc, "descr", "Test setrlimit(2) for EPERM"); | ||
494 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
495 | } | ||
496 | |||
497 | ATF_TC_BODY(setrlimit_perm, tc) | ||
498 | { | ||
499 | struct rlimit res; | ||
500 | size_t i; | ||
501 | |||
502 | /* | ||
503 | * Try to raise the maximum limits as an user. | ||
504 | */ | ||
505 | for (i = 0; i < __arraycount(rlimit); i++) { | ||
506 | |||
507 | ATF_REQUIRE(getrlimit(rlimit[i], &res) == 0); | ||
508 | |||
509 | if (res.rlim_max == UINT64_MAX) /* Overflow. */ | ||
510 | continue; | ||
511 | |||
512 | errno = 0; | ||
513 | res.rlim_max = res.rlim_max + 1; | ||
514 | |||
515 | ATF_CHECK_ERRNO(EPERM, setrlimit(rlimit[i], &res) != 0); | ||
516 | } | ||
517 | } | ||
518 | |||
519 | ATF_TC(setrlimit_stack); | ||
520 | ATF_TC_HEAD(setrlimit_stack, tc) | ||
521 | { | ||
522 | atf_tc_set_md_var(tc, "descr", "Test setrlimit(2), RLIMIT_STACK"); | ||
523 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
524 | } | ||
525 | |||
526 | ATF_TC_BODY(setrlimit_stack, tc) | ||
527 | { | ||
528 | struct rlimit res; | ||
529 | |||
530 | /* Ensure soft limit is not bigger than hard limit */ | ||
531 | res.rlim_cur = res.rlim_max = 6 * 1024 * 1024; | ||
532 | ATF_REQUIRE(setrlimit(RLIMIT_STACK, &res) == 0); | ||
533 | ATF_REQUIRE(getrlimit(RLIMIT_STACK, &res) == 0); | ||
534 | ATF_CHECK(res.rlim_cur <= res.rlim_max); | ||
535 | |||
536 | } | ||
537 | |||
538 | ATF_TP_ADD_TCS(tp) | ||
539 | { | ||
540 | |||
541 | ATF_TP_ADD_TC(tp, setrlimit_basic); | ||
542 | ATF_TP_ADD_TC(tp, setrlimit_current); | ||
543 | ATF_TP_ADD_TC(tp, setrlimit_err); | ||
544 | ATF_TP_ADD_TC(tp, setrlimit_fsize); | ||
545 | ATF_TP_ADD_TC(tp, setrlimit_memlock); | ||
546 | ATF_TP_ADD_TC(tp, setrlimit_nofile_1); | ||
547 | ATF_TP_ADD_TC(tp, setrlimit_nofile_2); | ||
548 | ATF_TP_ADD_TC(tp, setrlimit_nproc); | ||
549 | ATF_TP_ADD_TC(tp, setrlimit_perm); | ||
550 | #ifndef __OpenBSD__ | ||
551 | ATF_TP_ADD_TC(tp, setrlimit_nthr); | ||
552 | #endif | ||
553 | ATF_TP_ADD_TC(tp, setrlimit_stack); | ||
554 | |||
555 | return atf_no_error(); | ||
556 | } | ||
diff --git a/src/regress/lib/libc/sys/t_setuid.c b/src/regress/lib/libc/sys/t_setuid.c deleted file mode 100644 index 6924041390..0000000000 --- a/src/regress/lib/libc/sys/t_setuid.c +++ /dev/null | |||
@@ -1,123 +0,0 @@ | |||
1 | /* $OpenBSD: t_setuid.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_setuid.c,v 1.1 2011/07/07 06:57:54 jruoho Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/wait.h> | ||
36 | |||
37 | #include "atf-c.h" | ||
38 | #include <errno.h> | ||
39 | #include <pwd.h> | ||
40 | #include <stdlib.h> | ||
41 | #include <unistd.h> | ||
42 | |||
43 | ATF_TC(setuid_perm); | ||
44 | ATF_TC_HEAD(setuid_perm, tc) | ||
45 | { | ||
46 | atf_tc_set_md_var(tc, "descr", "Test setuid(0) as normal user"); | ||
47 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
48 | } | ||
49 | |||
50 | ATF_TC_BODY(setuid_perm, tc) | ||
51 | { | ||
52 | errno = 0; | ||
53 | |||
54 | ATF_REQUIRE(setuid(0) == -1); | ||
55 | ATF_REQUIRE(errno == EPERM); | ||
56 | } | ||
57 | |||
58 | ATF_TC(setuid_real); | ||
59 | ATF_TC_HEAD(setuid_real, tc) | ||
60 | { | ||
61 | atf_tc_set_md_var(tc, "descr", "Test setuid(2) with real UID"); | ||
62 | } | ||
63 | |||
64 | ATF_TC_BODY(setuid_real, tc) | ||
65 | { | ||
66 | uid_t uid = getuid(); | ||
67 | |||
68 | ATF_REQUIRE(setuid(uid) == 0); | ||
69 | |||
70 | ATF_REQUIRE(getuid() == uid); | ||
71 | ATF_REQUIRE(geteuid() == uid); | ||
72 | } | ||
73 | |||
74 | ATF_TC(setuid_root); | ||
75 | ATF_TC_HEAD(setuid_root, tc) | ||
76 | { | ||
77 | atf_tc_set_md_var(tc, "descr", "A basic test of setuid(2)"); | ||
78 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
79 | } | ||
80 | |||
81 | ATF_TC_BODY(setuid_root, tc) | ||
82 | { | ||
83 | struct passwd *pw; | ||
84 | int rv, sta; | ||
85 | pid_t pid; | ||
86 | uid_t uid; | ||
87 | |||
88 | while ((pw = getpwent()) != NULL) { | ||
89 | |||
90 | pid = fork(); | ||
91 | ATF_REQUIRE(pid >= 0); | ||
92 | |||
93 | if (pid == 0) { | ||
94 | |||
95 | rv = setuid(pw->pw_uid); | ||
96 | |||
97 | if (rv != 0) | ||
98 | _exit(EXIT_FAILURE); | ||
99 | |||
100 | uid = getuid(); | ||
101 | |||
102 | if (uid != pw->pw_uid) | ||
103 | _exit(EXIT_FAILURE); | ||
104 | |||
105 | _exit(EXIT_SUCCESS); | ||
106 | } | ||
107 | |||
108 | (void)wait(&sta); | ||
109 | |||
110 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
111 | atf_tc_fail("failed to change UID to %u", pw->pw_uid); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | ATF_TP_ADD_TCS(tp) | ||
116 | { | ||
117 | |||
118 | ATF_TP_ADD_TC(tp, setuid_perm); | ||
119 | ATF_TP_ADD_TC(tp, setuid_real); | ||
120 | ATF_TP_ADD_TC(tp, setuid_root); | ||
121 | |||
122 | return atf_no_error(); | ||
123 | } | ||
diff --git a/src/regress/lib/libc/sys/t_sigaction.c b/src/regress/lib/libc/sys/t_sigaction.c deleted file mode 100644 index 4254e1fece..0000000000 --- a/src/regress/lib/libc/sys/t_sigaction.c +++ /dev/null | |||
@@ -1,151 +0,0 @@ | |||
1 | /* $OpenBSD: t_sigaction.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_sigaction.c,v 1.5 2017/01/13 21:30:41 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2010 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
27 | * POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #include "macros.h" | ||
31 | |||
32 | #include <sys/wait.h> | ||
33 | |||
34 | #include <signal.h> | ||
35 | #include <stdbool.h> | ||
36 | #include <stdlib.h> | ||
37 | #include <string.h> | ||
38 | #include <unistd.h> | ||
39 | |||
40 | #include "atf-c.h" | ||
41 | |||
42 | #include "h_macros.h" | ||
43 | |||
44 | static bool handler_called = false; | ||
45 | |||
46 | static void | ||
47 | handler(int signo __unused) | ||
48 | { | ||
49 | handler_called = true; | ||
50 | } | ||
51 | |||
52 | static void | ||
53 | sa_resethand_child(const int flags) | ||
54 | { | ||
55 | struct sigaction sa; | ||
56 | |||
57 | sa.sa_flags = flags; | ||
58 | sa.sa_handler = &handler; | ||
59 | sigemptyset(&sa.sa_mask); | ||
60 | |||
61 | sigaction(SIGUSR1, &sa, NULL); | ||
62 | kill(getpid(), SIGUSR1); | ||
63 | exit(handler_called ? EXIT_SUCCESS : EXIT_FAILURE); | ||
64 | } | ||
65 | |||
66 | static void | ||
67 | wait_and_check_child(const pid_t pid, const char *fail_message) | ||
68 | { | ||
69 | int status; | ||
70 | |||
71 | (void)waitpid(pid, &status, 0); | ||
72 | |||
73 | if (WIFEXITED(status)) | ||
74 | ATF_CHECK_EQ(EXIT_SUCCESS, WEXITSTATUS(status)); | ||
75 | else | ||
76 | atf_tc_fail("%s; raw exit status was %d", fail_message, status); | ||
77 | } | ||
78 | |||
79 | static void | ||
80 | catch(int sig __unused) | ||
81 | { | ||
82 | return; | ||
83 | } | ||
84 | |||
85 | ATF_TC(sigaction_basic); | ||
86 | ATF_TC_HEAD(sigaction_basic, tc) | ||
87 | { | ||
88 | |||
89 | atf_tc_set_md_var(tc, "descr", "Checks for correct I&D cache" | ||
90 | "synchronization after copying out the trampoline code."); | ||
91 | } | ||
92 | |||
93 | ATF_TC_BODY(sigaction_basic, tc) | ||
94 | { | ||
95 | static struct sigaction sa; | ||
96 | |||
97 | sa.sa_handler = catch; | ||
98 | |||
99 | sigaction(SIGUSR1, &sa, 0); | ||
100 | kill(getpid(), SIGUSR1); | ||
101 | atf_tc_pass(); | ||
102 | } | ||
103 | |||
104 | ATF_TC(sigaction_noflags); | ||
105 | ATF_TC_HEAD(sigaction_noflags, tc) | ||
106 | { | ||
107 | atf_tc_set_md_var(tc, "descr", "Checks programming a signal with " | ||
108 | "sigaction(2) but without any flags"); | ||
109 | } | ||
110 | |||
111 | ATF_TC_BODY(sigaction_noflags, tc) | ||
112 | { | ||
113 | const pid_t pid = fork(); | ||
114 | if (pid == -1) | ||
115 | atf_tc_fail_errno("fork(2) failed"); | ||
116 | else if (pid == 0) | ||
117 | sa_resethand_child(0); | ||
118 | else | ||
119 | wait_and_check_child(pid, "Child process did not exit cleanly;" | ||
120 | " it failed to process the signal"); | ||
121 | } | ||
122 | |||
123 | ATF_TC(sigaction_resethand); | ||
124 | ATF_TC_HEAD(sigaction_resethand, tc) | ||
125 | { | ||
126 | atf_tc_set_md_var(tc, "descr", "Checks that SA_RESETHAND works"); | ||
127 | } | ||
128 | |||
129 | ATF_TC_BODY(sigaction_resethand, tc) | ||
130 | { | ||
131 | const pid_t pid = fork(); | ||
132 | if (pid == -1) | ||
133 | atf_tc_fail_errno("fork(2) failed"); | ||
134 | else if (pid == 0) | ||
135 | sa_resethand_child(SA_RESETHAND); | ||
136 | else { | ||
137 | wait_and_check_child(pid, "Child process did not exit cleanly;" | ||
138 | " it either failed to process the signal or SA_RESETHAND" | ||
139 | " is broken"); | ||
140 | } | ||
141 | } | ||
142 | |||
143 | ATF_TP_ADD_TCS(tp) | ||
144 | { | ||
145 | |||
146 | ATF_TP_ADD_TC(tp, sigaction_basic); | ||
147 | ATF_TP_ADD_TC(tp, sigaction_noflags); | ||
148 | ATF_TP_ADD_TC(tp, sigaction_resethand); | ||
149 | |||
150 | return atf_no_error(); | ||
151 | } | ||
diff --git a/src/regress/lib/libc/sys/t_sigaltstack.c b/src/regress/lib/libc/sys/t_sigaltstack.c deleted file mode 100644 index b02063bf2d..0000000000 --- a/src/regress/lib/libc/sys/t_sigaltstack.c +++ /dev/null | |||
@@ -1,99 +0,0 @@ | |||
1 | /* $OpenBSD: t_sigaltstack.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_sigaltstack.c,v 1.2 2020/05/01 21:35:30 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2020 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
27 | * POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | #include "macros.h" | ||
30 | |||
31 | #include <signal.h> | ||
32 | #include <stdbool.h> | ||
33 | |||
34 | #include "atf-c.h" | ||
35 | |||
36 | #include "h_macros.h" | ||
37 | |||
38 | static stack_t sigstk; | ||
39 | static bool handler_called; | ||
40 | static bool handler_use_altstack; | ||
41 | |||
42 | static void | ||
43 | handler(int signo __unused) | ||
44 | { | ||
45 | char sp[128]; | ||
46 | |||
47 | handler_called = true; | ||
48 | |||
49 | /* checking if the stack pointer is within the range of altstack */ | ||
50 | if ((char *)sigstk.ss_sp <= sp && | ||
51 | ((char *)sigstk.ss_sp + sigstk.ss_size) > sp) | ||
52 | handler_use_altstack = true; | ||
53 | else | ||
54 | handler_use_altstack = false; | ||
55 | } | ||
56 | |||
57 | ATF_TC(sigaltstack_onstack); | ||
58 | ATF_TC_HEAD(sigaltstack_onstack, tc) | ||
59 | { | ||
60 | atf_tc_set_md_var(tc, "descr", | ||
61 | "Checks for using signal stack with SA_ONSTACK"); | ||
62 | } | ||
63 | |||
64 | ATF_TC_BODY(sigaltstack_onstack, tc) | ||
65 | { | ||
66 | struct sigaction sa; | ||
67 | int i; | ||
68 | |||
69 | /* set a signal handler use alternative stack */ | ||
70 | memset(&sigstk, 0, sizeof(sigstk)); | ||
71 | sigstk.ss_sp = malloc(SIGSTKSZ); | ||
72 | ATF_REQUIRE(sigstk.ss_sp != NULL); | ||
73 | sigstk.ss_size = SIGSTKSZ; | ||
74 | sigstk.ss_flags = 0; | ||
75 | ATF_REQUIRE(sigaltstack(&sigstk, 0) == 0); | ||
76 | |||
77 | sigemptyset(&sa.sa_mask); | ||
78 | sa.sa_handler = handler; | ||
79 | sa.sa_flags = SA_ONSTACK; | ||
80 | sigaction(SIGUSR1, &sa, NULL); | ||
81 | |||
82 | /* test several times */ | ||
83 | for (i = 1; i <= 5; i++) { | ||
84 | handler_called = false; | ||
85 | kill(getpid(), SIGUSR1); | ||
86 | |||
87 | if (!handler_called) | ||
88 | atf_tc_fail("signal handler wasn't called (count=%d)", i); | ||
89 | if (!handler_use_altstack) | ||
90 | atf_tc_fail("alternative stack wasn't used (count=%d)", i); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | ATF_TP_ADD_TCS(tp) | ||
95 | { | ||
96 | ATF_TP_ADD_TC(tp, sigaltstack_onstack); | ||
97 | |||
98 | return atf_no_error(); | ||
99 | } | ||
diff --git a/src/regress/lib/libc/sys/t_socketpair.c b/src/regress/lib/libc/sys/t_socketpair.c deleted file mode 100644 index e24a166161..0000000000 --- a/src/regress/lib/libc/sys/t_socketpair.c +++ /dev/null | |||
@@ -1,138 +0,0 @@ | |||
1 | /* $OpenBSD: t_socketpair.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_socketpair.c,v 1.2 2017/01/13 20:04:52 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Christos Zoulas. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * 3. All advertising materials mentioning features or use of this software | ||
20 | * must display the following acknowledgement: | ||
21 | * This product includes software developed by the NetBSD | ||
22 | * Foundation, Inc. and its contributors. | ||
23 | * 4. Neither the name of The NetBSD Foundation nor the names of its | ||
24 | * contributors may be used to endorse or promote products derived | ||
25 | * from this software without specific prior written permission. | ||
26 | * | ||
27 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
28 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
29 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
30 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
31 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
37 | * POSSIBILITY OF SUCH DAMAGE. | ||
38 | */ | ||
39 | |||
40 | #include "macros.h" | ||
41 | |||
42 | #include "atf-c.h" | ||
43 | #include <fcntl.h> | ||
44 | #include <unistd.h> | ||
45 | #include <stdlib.h> | ||
46 | #include <sys/socket.h> | ||
47 | #include <sys/un.h> | ||
48 | #include <errno.h> | ||
49 | |||
50 | static void | ||
51 | connected(int fd) | ||
52 | { | ||
53 | struct sockaddr_un addr; | ||
54 | socklen_t len = (socklen_t)sizeof(addr); | ||
55 | ATF_REQUIRE(getpeername(fd, (struct sockaddr*)(void *)&addr, | ||
56 | &len) == 0); | ||
57 | } | ||
58 | |||
59 | static void | ||
60 | run(int flags) | ||
61 | { | ||
62 | int fd[2], i; | ||
63 | |||
64 | while ((i = open("/", O_RDONLY)) < 3) | ||
65 | ATF_REQUIRE(i != -1); | ||
66 | |||
67 | ATF_REQUIRE(closefrom(3) != -1); | ||
68 | |||
69 | ATF_REQUIRE(socketpair(AF_UNIX, SOCK_DGRAM | flags, 0, fd) == 0); | ||
70 | |||
71 | ATF_REQUIRE(fd[0] == 3); | ||
72 | ATF_REQUIRE(fd[1] == 4); | ||
73 | |||
74 | connected(fd[0]); | ||
75 | connected(fd[1]); | ||
76 | |||
77 | if (flags & SOCK_CLOEXEC) { | ||
78 | ATF_REQUIRE((fcntl(fd[0], F_GETFD) & FD_CLOEXEC) != 0); | ||
79 | ATF_REQUIRE((fcntl(fd[1], F_GETFD) & FD_CLOEXEC) != 0); | ||
80 | } else { | ||
81 | ATF_REQUIRE((fcntl(fd[0], F_GETFD) & FD_CLOEXEC) == 0); | ||
82 | ATF_REQUIRE((fcntl(fd[1], F_GETFD) & FD_CLOEXEC) == 0); | ||
83 | } | ||
84 | |||
85 | if (flags & SOCK_NONBLOCK) { | ||
86 | ATF_REQUIRE((fcntl(fd[0], F_GETFL) & O_NONBLOCK) != 0); | ||
87 | ATF_REQUIRE((fcntl(fd[1], F_GETFL) & O_NONBLOCK) != 0); | ||
88 | } else { | ||
89 | ATF_REQUIRE((fcntl(fd[0], F_GETFL) & O_NONBLOCK) == 0); | ||
90 | ATF_REQUIRE((fcntl(fd[1], F_GETFL) & O_NONBLOCK) == 0); | ||
91 | } | ||
92 | |||
93 | ATF_REQUIRE(close(fd[0]) != -1); | ||
94 | ATF_REQUIRE(close(fd[1]) != -1); | ||
95 | } | ||
96 | |||
97 | ATF_TC(socketpair_basic); | ||
98 | ATF_TC_HEAD(socketpair_basic, tc) | ||
99 | { | ||
100 | atf_tc_set_md_var(tc, "descr", "A basic test of socketpair(2)"); | ||
101 | } | ||
102 | |||
103 | ATF_TC_BODY(socketpair_basic, tc) | ||
104 | { | ||
105 | run(0); | ||
106 | } | ||
107 | |||
108 | ATF_TC(socketpair_nonblock); | ||
109 | ATF_TC_HEAD(socketpair_nonblock, tc) | ||
110 | { | ||
111 | atf_tc_set_md_var(tc, "descr", "A non-blocking test of socketpair(2)"); | ||
112 | } | ||
113 | |||
114 | ATF_TC_BODY(socketpair_nonblock, tc) | ||
115 | { | ||
116 | run(SOCK_NONBLOCK); | ||
117 | } | ||
118 | |||
119 | ATF_TC(socketpair_cloexec); | ||
120 | ATF_TC_HEAD(socketpair_cloexec, tc) | ||
121 | { | ||
122 | atf_tc_set_md_var(tc, "descr", "A close-on-exec of socketpair(2)"); | ||
123 | } | ||
124 | |||
125 | ATF_TC_BODY(socketpair_cloexec, tc) | ||
126 | { | ||
127 | run(SOCK_CLOEXEC); | ||
128 | } | ||
129 | |||
130 | ATF_TP_ADD_TCS(tp) | ||
131 | { | ||
132 | |||
133 | ATF_TP_ADD_TC(tp, socketpair_basic); | ||
134 | ATF_TP_ADD_TC(tp, socketpair_nonblock); | ||
135 | ATF_TP_ADD_TC(tp, socketpair_cloexec); | ||
136 | |||
137 | return atf_no_error(); | ||
138 | } | ||
diff --git a/src/regress/lib/libc/sys/t_stat.c b/src/regress/lib/libc/sys/t_stat.c deleted file mode 100644 index ae88e1559a..0000000000 --- a/src/regress/lib/libc/sys/t_stat.c +++ /dev/null | |||
@@ -1,420 +0,0 @@ | |||
1 | /* $OpenBSD: t_stat.c,v 1.5 2023/10/31 07:57:59 claudio Exp $ */ | ||
2 | /* $NetBSD: t_stat.c,v 1.6 2019/07/16 17:29:18 martin Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/stat.h> | ||
36 | #include <sys/socket.h> | ||
37 | #include <sys/types.h> | ||
38 | |||
39 | #include <arpa/inet.h> | ||
40 | #include <netinet/in.h> | ||
41 | |||
42 | #include "atf-c.h" | ||
43 | #include <errno.h> | ||
44 | #include <fcntl.h> | ||
45 | #include <fts.h> | ||
46 | #include <limits.h> | ||
47 | #include <string.h> | ||
48 | #include <unistd.h> | ||
49 | |||
50 | #include <stdio.h> | ||
51 | |||
52 | static const char *path = "stat"; | ||
53 | |||
54 | ATF_TC_WITH_CLEANUP(stat_chflags); | ||
55 | ATF_TC_HEAD(stat_chflags, tc) | ||
56 | { | ||
57 | atf_tc_set_md_var(tc, "descr", "Test chflags(2) with stat(2)"); | ||
58 | } | ||
59 | |||
60 | ATF_TC_BODY(stat_chflags, tc) | ||
61 | { | ||
62 | struct stat sa, sb; | ||
63 | int fd; | ||
64 | |||
65 | (void)memset(&sa, 0, sizeof(struct stat)); | ||
66 | (void)memset(&sb, 0, sizeof(struct stat)); | ||
67 | |||
68 | fd = open(path, O_RDONLY | O_CREAT, 0600); | ||
69 | |||
70 | ATF_REQUIRE(fd != -1); | ||
71 | ATF_REQUIRE(stat(path, &sa) == 0); | ||
72 | ATF_REQUIRE(chflags(path, UF_NODUMP) == 0); | ||
73 | ATF_REQUIRE(stat(path, &sb) == 0); | ||
74 | |||
75 | if (sa.st_flags == sb.st_flags) | ||
76 | atf_tc_fail("stat(2) did not detect chflags(2)"); | ||
77 | |||
78 | ATF_REQUIRE(close(fd) == 0); | ||
79 | ATF_REQUIRE(unlink(path) == 0); | ||
80 | } | ||
81 | |||
82 | ATF_TC_CLEANUP(stat_chflags, tc) | ||
83 | { | ||
84 | (void)unlink(path); | ||
85 | } | ||
86 | |||
87 | ATF_TC(stat_dir); | ||
88 | ATF_TC_HEAD(stat_dir, tc) | ||
89 | { | ||
90 | atf_tc_set_md_var(tc, "descr", "Test stat(2) with directories"); | ||
91 | } | ||
92 | |||
93 | ATF_TC_BODY(stat_dir, tc) | ||
94 | { | ||
95 | const short depth = 2; | ||
96 | struct stat sa, sb; | ||
97 | char *argv[2]; | ||
98 | FTSENT *ftse; | ||
99 | FTS *fts; | ||
100 | int ops; | ||
101 | |||
102 | argv[1] = NULL; | ||
103 | argv[0] = __UNCONST("/"); | ||
104 | |||
105 | ops = FTS_NOCHDIR; | ||
106 | ops |= FTS_PHYSICAL; | ||
107 | |||
108 | fts = fts_open(argv, ops, NULL); | ||
109 | ATF_REQUIRE(fts != NULL); | ||
110 | |||
111 | while ((ftse = fts_read(fts)) != NULL) { | ||
112 | |||
113 | if (ftse->fts_level < 1) | ||
114 | continue; | ||
115 | |||
116 | if (ftse->fts_level > depth) { | ||
117 | (void)fts_set(fts, ftse, FTS_SKIP); | ||
118 | continue; | ||
119 | } | ||
120 | |||
121 | switch(ftse->fts_info) { | ||
122 | |||
123 | case FTS_DP: | ||
124 | |||
125 | (void)memset(&sa, 0, sizeof(struct stat)); | ||
126 | (void)memset(&sb, 0, sizeof(struct stat)); | ||
127 | |||
128 | ATF_REQUIRE(stat(ftse->fts_parent->fts_path,&sa) == 0); | ||
129 | ATF_REQUIRE(chdir(ftse->fts_path) == 0); | ||
130 | ATF_REQUIRE(stat(".", &sb) == 0); | ||
131 | |||
132 | /* | ||
133 | * The previous two stat(2) calls | ||
134 | * should be for the same directory. | ||
135 | */ | ||
136 | if (sa.st_dev != sb.st_dev || sa.st_ino != sb.st_ino) | ||
137 | atf_tc_fail("inconsistent stat(2)"); | ||
138 | |||
139 | /* | ||
140 | * Check that fts(3)'s stat(2) | ||
141 | * call equals the manual one. | ||
142 | */ | ||
143 | if (sb.st_ino != ftse->fts_statp->st_ino) | ||
144 | atf_tc_fail("stat(2) and fts(3) differ"); | ||
145 | |||
146 | break; | ||
147 | |||
148 | default: | ||
149 | break; | ||
150 | } | ||
151 | } | ||
152 | |||
153 | (void)fts_close(fts); | ||
154 | } | ||
155 | |||
156 | ATF_TC(stat_err); | ||
157 | ATF_TC_HEAD(stat_err, tc) | ||
158 | { | ||
159 | atf_tc_set_md_var(tc, "descr", "Test errors from the stat(2) family"); | ||
160 | } | ||
161 | |||
162 | ATF_TC_BODY(stat_err, tc) | ||
163 | { | ||
164 | char buf[NAME_MAX + 1]; | ||
165 | struct stat st; | ||
166 | |||
167 | (void)memset(buf, 'x', sizeof(buf)); | ||
168 | |||
169 | errno = 0; | ||
170 | ATF_REQUIRE_ERRNO(EBADF, fstat(-1, &st) == -1); | ||
171 | |||
172 | errno = 0; | ||
173 | ATF_REQUIRE_ERRNO(ENAMETOOLONG, stat(buf, &st) == -1); | ||
174 | |||
175 | errno = 0; | ||
176 | ATF_REQUIRE_ERRNO(ENAMETOOLONG, lstat(buf, &st) == -1); | ||
177 | |||
178 | errno = 0; | ||
179 | ATF_REQUIRE_ERRNO(EFAULT, stat((void *)-1, &st) == -1); | ||
180 | |||
181 | errno = 0; | ||
182 | ATF_REQUIRE_ERRNO(EFAULT, lstat((void *)-1, &st) == -1); | ||
183 | |||
184 | errno = 0; | ||
185 | ATF_REQUIRE_ERRNO(EFAULT, stat("/etc/passwd", (void *)-1) == -1); | ||
186 | |||
187 | errno = 0; | ||
188 | ATF_REQUIRE_ERRNO(EFAULT, lstat("/etc/passwd", (void *)-1) == -1); | ||
189 | |||
190 | errno = 0; | ||
191 | ATF_REQUIRE_ERRNO(ENOENT, stat("/a/b/c/d/e/f/g/h/i/j/k", &st) == -1); | ||
192 | |||
193 | errno = 0; | ||
194 | ATF_REQUIRE_ERRNO(ENOENT, lstat("/a/b/c/d/e/f/g/h/i/j/k", &st) == -1); | ||
195 | } | ||
196 | |||
197 | ATF_TC_WITH_CLEANUP(stat_mtime); | ||
198 | ATF_TC_HEAD(stat_mtime, tc) | ||
199 | { | ||
200 | atf_tc_set_md_var(tc, "descr", "Test modification times with stat(2)"); | ||
201 | } | ||
202 | |||
203 | ATF_TC_BODY(stat_mtime, tc) | ||
204 | { | ||
205 | struct stat sa, sb; | ||
206 | int fd[3]; | ||
207 | size_t i; | ||
208 | |||
209 | for (i = 0; i < __arraycount(fd); i++) { | ||
210 | |||
211 | (void)memset(&sa, 0, sizeof(struct stat)); | ||
212 | (void)memset(&sb, 0, sizeof(struct stat)); | ||
213 | |||
214 | fd[i] = open(path, O_WRONLY | O_CREAT, 0600); | ||
215 | |||
216 | ATF_REQUIRE(fd[i] != -1); | ||
217 | ATF_REQUIRE(write(fd[i], "X", 1) == 1); | ||
218 | ATF_REQUIRE(stat(path, &sa) == 0); | ||
219 | |||
220 | (void)sleep(1); | ||
221 | |||
222 | ATF_REQUIRE(write(fd[i], "X", 1) == 1); | ||
223 | ATF_REQUIRE(stat(path, &sb) == 0); | ||
224 | |||
225 | ATF_REQUIRE(close(fd[i]) == 0); | ||
226 | ATF_REQUIRE(unlink(path) == 0); | ||
227 | |||
228 | if (sa.st_mtime == sb.st_mtime) | ||
229 | atf_tc_fail("mtimes did not change"); | ||
230 | } | ||
231 | } | ||
232 | |||
233 | ATF_TC_CLEANUP(stat_mtime, tc) | ||
234 | { | ||
235 | (void)unlink(path); | ||
236 | } | ||
237 | |||
238 | ATF_TC_WITH_CLEANUP(stat_perm); | ||
239 | ATF_TC_HEAD(stat_perm, tc) | ||
240 | { | ||
241 | atf_tc_set_md_var(tc, "descr", "Test permissions with stat(2)"); | ||
242 | atf_tc_set_md_var(tc, "require.user", "root"); | ||
243 | } | ||
244 | |||
245 | ATF_TC_BODY(stat_perm, tc) | ||
246 | { | ||
247 | struct stat sa, sb; | ||
248 | gid_t gid; | ||
249 | uid_t uid; | ||
250 | int fd; | ||
251 | |||
252 | (void)memset(&sa, 0, sizeof(struct stat)); | ||
253 | (void)memset(&sb, 0, sizeof(struct stat)); | ||
254 | |||
255 | uid = getuid(); | ||
256 | gid = getgid(); | ||
257 | |||
258 | fd = open(path, O_RDONLY | O_CREAT, 0600); | ||
259 | |||
260 | ATF_REQUIRE(fd != -1); | ||
261 | ATF_REQUIRE(fstat(fd, &sa) == 0); | ||
262 | ATF_REQUIRE(stat(path, &sb) == 0); | ||
263 | |||
264 | if (sa.st_gid != sb.st_gid) | ||
265 | atf_tc_fail("invalid GID"); | ||
266 | |||
267 | if (uid != sa.st_uid || sa.st_uid != sb.st_uid) | ||
268 | atf_tc_fail("invalid UID"); | ||
269 | |||
270 | ATF_REQUIRE(close(fd) == 0); | ||
271 | ATF_REQUIRE(unlink(path) == 0); | ||
272 | } | ||
273 | |||
274 | ATF_TC_CLEANUP(stat_perm, tc) | ||
275 | { | ||
276 | (void)unlink(path); | ||
277 | } | ||
278 | |||
279 | ATF_TC_WITH_CLEANUP(stat_size); | ||
280 | ATF_TC_HEAD(stat_size, tc) | ||
281 | { | ||
282 | atf_tc_set_md_var(tc, "descr", "Test file sizes with stat(2)"); | ||
283 | } | ||
284 | |||
285 | ATF_TC_BODY(stat_size, tc) | ||
286 | { | ||
287 | struct stat sa, sb, sc; | ||
288 | const size_t n = 10; | ||
289 | size_t i; | ||
290 | int fd; | ||
291 | |||
292 | fd = open(path, O_WRONLY | O_CREAT, 0600); | ||
293 | ATF_REQUIRE(fd >= 0); | ||
294 | |||
295 | for (i = 0; i < n; i++) { | ||
296 | |||
297 | (void)memset(&sa, 0, sizeof(struct stat)); | ||
298 | (void)memset(&sb, 0, sizeof(struct stat)); | ||
299 | (void)memset(&sc, 0, sizeof(struct stat)); | ||
300 | |||
301 | ATF_REQUIRE(fstat(fd, &sa) == 0); | ||
302 | ATF_REQUIRE(write(fd, "X", 1) == 1); | ||
303 | ATF_REQUIRE(fstat(fd, &sb) == 0); | ||
304 | ATF_REQUIRE(stat(path, &sc) == 0); | ||
305 | |||
306 | if (sa.st_size + 1 != sb.st_size) | ||
307 | atf_tc_fail("invalid file size"); | ||
308 | |||
309 | if (sb.st_size != sc.st_size) | ||
310 | atf_tc_fail("stat(2) and fstat(2) mismatch"); | ||
311 | } | ||
312 | |||
313 | ATF_REQUIRE(close(fd) == 0); | ||
314 | ATF_REQUIRE(unlink(path) == 0); | ||
315 | } | ||
316 | |||
317 | ATF_TC_CLEANUP(stat_size, tc) | ||
318 | { | ||
319 | (void)unlink(path); | ||
320 | } | ||
321 | |||
322 | ATF_TC(stat_socket); | ||
323 | ATF_TC_HEAD(stat_socket, tc) | ||
324 | { | ||
325 | atf_tc_set_md_var(tc, "descr", "Test fstat(2) with " | ||
326 | "a socket (PR kern/46077)"); | ||
327 | } | ||
328 | |||
329 | ATF_TC_BODY(stat_socket, tc) | ||
330 | { | ||
331 | struct sockaddr_in addr; | ||
332 | struct stat st; | ||
333 | uint32_t iaddr; | ||
334 | int fd, flags; | ||
335 | |||
336 | (void)memset(&st, 0, sizeof(struct stat)); | ||
337 | (void)memset(&addr, 0, sizeof(struct sockaddr_in)); | ||
338 | |||
339 | fd = socket(AF_INET, SOCK_STREAM, 0); | ||
340 | ATF_REQUIRE(fd >= 0); | ||
341 | |||
342 | flags = fcntl(fd, F_GETFL); | ||
343 | |||
344 | ATF_REQUIRE(flags != -1); | ||
345 | ATF_REQUIRE(fcntl(fd, F_SETFL, flags | O_NONBLOCK) != -1); | ||
346 | ATF_REQUIRE(inet_pton(AF_INET, "127.0.0.1", &iaddr) == 1); | ||
347 | |||
348 | addr.sin_port = htons(42); | ||
349 | addr.sin_family = AF_INET; | ||
350 | addr.sin_addr.s_addr = iaddr; | ||
351 | |||
352 | errno = 0; | ||
353 | |||
354 | ATF_REQUIRE_ERRNO(EINPROGRESS, | ||
355 | connect(fd, (struct sockaddr *)&addr, | ||
356 | sizeof(struct sockaddr_in)) == -1); | ||
357 | |||
358 | errno = 0; | ||
359 | |||
360 | if (fstat(fd, &st) != 0 || errno != 0) | ||
361 | atf_tc_fail("fstat(2) failed for a EINPROGRESS socket"); | ||
362 | |||
363 | (void)close(fd); | ||
364 | } | ||
365 | |||
366 | ATF_TC_WITH_CLEANUP(stat_symlink); | ||
367 | ATF_TC_HEAD(stat_symlink, tc) | ||
368 | { | ||
369 | atf_tc_set_md_var(tc, "descr", "Test symbolic links with stat(2)"); | ||
370 | } | ||
371 | |||
372 | ATF_TC_BODY(stat_symlink, tc) | ||
373 | { | ||
374 | const char *pathlink = "pathlink"; | ||
375 | struct stat sa, sb; | ||
376 | int fd; | ||
377 | |||
378 | (void)memset(&sa, 0, sizeof(struct stat)); | ||
379 | (void)memset(&sb, 0, sizeof(struct stat)); | ||
380 | |||
381 | fd = open(path, O_WRONLY | O_CREAT, 0600); | ||
382 | |||
383 | ATF_REQUIRE(fd >= 0); | ||
384 | ATF_REQUIRE(symlink(path, pathlink) == 0); | ||
385 | ATF_REQUIRE(stat(pathlink, &sa) == 0); | ||
386 | ATF_REQUIRE(lstat(pathlink, &sb) == 0); | ||
387 | |||
388 | if (S_ISLNK(sa.st_mode) != 0) | ||
389 | atf_tc_fail("stat(2) detected symbolic link"); | ||
390 | |||
391 | if (S_ISLNK(sb.st_mode) == 0) | ||
392 | atf_tc_fail("lstat(2) did not detect symbolic link"); | ||
393 | |||
394 | if (sa.st_mode == sb.st_mode) | ||
395 | atf_tc_fail("inconsistencies between stat(2) and lstat(2)"); | ||
396 | |||
397 | (void)close(fd); | ||
398 | ATF_REQUIRE(unlink(path) == 0); | ||
399 | ATF_REQUIRE(unlink(pathlink) == 0); | ||
400 | } | ||
401 | |||
402 | ATF_TC_CLEANUP(stat_symlink, tc) | ||
403 | { | ||
404 | (void)unlink(path); | ||
405 | } | ||
406 | |||
407 | ATF_TP_ADD_TCS(tp) | ||
408 | { | ||
409 | |||
410 | ATF_TP_ADD_TC(tp, stat_chflags); | ||
411 | ATF_TP_ADD_TC(tp, stat_dir); | ||
412 | ATF_TP_ADD_TC(tp, stat_err); | ||
413 | ATF_TP_ADD_TC(tp, stat_mtime); | ||
414 | ATF_TP_ADD_TC(tp, stat_perm); | ||
415 | ATF_TP_ADD_TC(tp, stat_size); | ||
416 | ATF_TP_ADD_TC(tp, stat_socket); | ||
417 | ATF_TP_ADD_TC(tp, stat_symlink); | ||
418 | |||
419 | return atf_no_error(); | ||
420 | } | ||
diff --git a/src/regress/lib/libc/sys/t_truncate.c b/src/regress/lib/libc/sys/t_truncate.c deleted file mode 100644 index f42494f8db..0000000000 --- a/src/regress/lib/libc/sys/t_truncate.c +++ /dev/null | |||
@@ -1,180 +0,0 @@ | |||
1 | /* $OpenBSD: t_truncate.c,v 1.4 2022/05/24 05:14:30 anton Exp $ */ | ||
2 | /* $NetBSD: t_truncate.c,v 1.3 2017/01/13 20:03:51 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/stat.h> | ||
36 | |||
37 | #include "atf-c.h" | ||
38 | #include <errno.h> | ||
39 | #include <fcntl.h> | ||
40 | #include <limits.h> | ||
41 | #include <stdio.h> | ||
42 | #include <string.h> | ||
43 | #include <unistd.h> | ||
44 | |||
45 | static const char path[] = "truncate"; | ||
46 | static const size_t sizes[] = { 8, 16, 512, 1024, 2048, 4094, 3000, 30 }; | ||
47 | |||
48 | ATF_TC_WITH_CLEANUP(ftruncate_basic); | ||
49 | ATF_TC_HEAD(ftruncate_basic, tc) | ||
50 | { | ||
51 | atf_tc_set_md_var(tc, "descr", "A basic test of ftruncate(2)"); | ||
52 | } | ||
53 | |||
54 | ATF_TC_BODY(ftruncate_basic, tc) | ||
55 | { | ||
56 | struct stat st; | ||
57 | size_t i; | ||
58 | int fd; | ||
59 | |||
60 | fd = open(path, O_RDWR | O_CREAT, 0600); | ||
61 | ATF_REQUIRE(fd >= 0); | ||
62 | |||
63 | for (i = 0; i < __arraycount(sizes); i++) { | ||
64 | |||
65 | (void)memset(&st, 0, sizeof(struct stat)); | ||
66 | |||
67 | ATF_REQUIRE(ftruncate(fd, sizes[i]) == 0); | ||
68 | ATF_REQUIRE(fstat(fd, &st) == 0); | ||
69 | |||
70 | (void)fprintf(stderr, "truncating to %zu bytes\n", sizes[i]); | ||
71 | |||
72 | if (sizes[i] != (size_t)st.st_size) | ||
73 | atf_tc_fail("ftruncate(2) did not truncate"); | ||
74 | } | ||
75 | |||
76 | (void)close(fd); | ||
77 | (void)unlink(path); | ||
78 | } | ||
79 | |||
80 | ATF_TC_CLEANUP(ftruncate_basic, tc) | ||
81 | { | ||
82 | (void)unlink(path); | ||
83 | } | ||
84 | |||
85 | ATF_TC(ftruncate_err); | ||
86 | ATF_TC_HEAD(ftruncate_err, tc) | ||
87 | { | ||
88 | atf_tc_set_md_var(tc, "descr", "Test errors from ftruncate(2)"); | ||
89 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
90 | } | ||
91 | |||
92 | ATF_TC_BODY(ftruncate_err, tc) | ||
93 | { | ||
94 | int fd; | ||
95 | |||
96 | fd = open("/etc/passwd", O_RDONLY); | ||
97 | ATF_REQUIRE(fd >= 0); | ||
98 | |||
99 | errno = 0; | ||
100 | ATF_REQUIRE_ERRNO(EBADF, ftruncate(-1, 999) == -1); | ||
101 | |||
102 | errno = 0; | ||
103 | ATF_REQUIRE_ERRNO(EINVAL, ftruncate(fd, 999) == -1); | ||
104 | |||
105 | (void)close(fd); | ||
106 | } | ||
107 | |||
108 | ATF_TC_WITH_CLEANUP(truncate_basic); | ||
109 | ATF_TC_HEAD(truncate_basic, tc) | ||
110 | { | ||
111 | atf_tc_set_md_var(tc, "descr", "A basic test of truncate(2)"); | ||
112 | } | ||
113 | |||
114 | ATF_TC_BODY(truncate_basic, tc) | ||
115 | { | ||
116 | struct stat st; | ||
117 | size_t i; | ||
118 | int fd; | ||
119 | |||
120 | fd = open(path, O_RDWR | O_CREAT, 0600); | ||
121 | ATF_REQUIRE(fd >= 0); | ||
122 | |||
123 | for (i = 0; i < __arraycount(sizes); i++) { | ||
124 | |||
125 | (void)memset(&st, 0, sizeof(struct stat)); | ||
126 | |||
127 | ATF_REQUIRE(truncate(path, sizes[i]) == 0); | ||
128 | ATF_REQUIRE(fstat(fd, &st) == 0); | ||
129 | |||
130 | (void)fprintf(stderr, "truncating to %zu bytes\n", sizes[i]); | ||
131 | |||
132 | if (sizes[i] != (size_t)st.st_size) | ||
133 | atf_tc_fail("truncate(2) did not truncate"); | ||
134 | } | ||
135 | |||
136 | (void)close(fd); | ||
137 | (void)unlink(path); | ||
138 | } | ||
139 | |||
140 | ATF_TC_CLEANUP(truncate_basic, tc) | ||
141 | { | ||
142 | (void)unlink(path); | ||
143 | } | ||
144 | |||
145 | ATF_TC(truncate_err); | ||
146 | ATF_TC_HEAD(truncate_err, tc) | ||
147 | { | ||
148 | atf_tc_set_md_var(tc, "descr", "Test errors from truncate(2)"); | ||
149 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
150 | } | ||
151 | |||
152 | ATF_TC_BODY(truncate_err, tc) | ||
153 | { | ||
154 | char buf[PATH_MAX]; | ||
155 | |||
156 | errno = 0; | ||
157 | ATF_REQUIRE_ERRNO(EFAULT, truncate((void *)-1, 999) == -1); | ||
158 | |||
159 | errno = 0; | ||
160 | ATF_REQUIRE_ERRNO(EISDIR, truncate("/tmp", 999) == -1); | ||
161 | |||
162 | errno = 0; | ||
163 | ATF_REQUIRE_ERRNO(ENOENT, truncate("/a/b/c/d/e/f/g", 999) == -1); | ||
164 | |||
165 | errno = 0; | ||
166 | snprintf(buf, sizeof(buf), "%s/truncate_test.root_owned", | ||
167 | atf_tc_get_config_var(tc, "srcdir")); | ||
168 | ATF_REQUIRE_ERRNO(EACCES, truncate(buf, 999) == -1); | ||
169 | } | ||
170 | |||
171 | ATF_TP_ADD_TCS(tp) | ||
172 | { | ||
173 | |||
174 | ATF_TP_ADD_TC(tp, ftruncate_basic); | ||
175 | ATF_TP_ADD_TC(tp, ftruncate_err); | ||
176 | ATF_TP_ADD_TC(tp, truncate_basic); | ||
177 | ATF_TP_ADD_TC(tp, truncate_err); | ||
178 | |||
179 | return atf_no_error(); | ||
180 | } | ||
diff --git a/src/regress/lib/libc/sys/t_umask.c b/src/regress/lib/libc/sys/t_umask.c deleted file mode 100644 index 53837b654e..0000000000 --- a/src/regress/lib/libc/sys/t_umask.c +++ /dev/null | |||
@@ -1,207 +0,0 @@ | |||
1 | /* $OpenBSD: t_umask.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_umask.c,v 1.2 2017/01/13 19:34:19 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/stat.h> | ||
36 | #include <sys/wait.h> | ||
37 | |||
38 | #include "atf-c.h" | ||
39 | #include <fcntl.h> | ||
40 | #include <stdlib.h> | ||
41 | #include <string.h> | ||
42 | #include <unistd.h> | ||
43 | |||
44 | static const char path[] = "umask"; | ||
45 | static const mode_t mask[] = { | ||
46 | S_IRWXU, | ||
47 | S_IRUSR, | ||
48 | S_IWUSR, | ||
49 | S_IXUSR, | ||
50 | S_IRWXG, | ||
51 | S_IRGRP, | ||
52 | S_IWGRP, | ||
53 | S_IXGRP, | ||
54 | S_IRWXO, | ||
55 | S_IROTH, | ||
56 | S_IWOTH, | ||
57 | S_IXOTH | ||
58 | }; | ||
59 | |||
60 | ATF_TC_WITH_CLEANUP(umask_fork); | ||
61 | ATF_TC_HEAD(umask_fork, tc) | ||
62 | { | ||
63 | atf_tc_set_md_var(tc, "descr", "Check that umask(2) is inherited"); | ||
64 | } | ||
65 | |||
66 | ATF_TC_BODY(umask_fork, tc) | ||
67 | { | ||
68 | mode_t mode; | ||
69 | pid_t pid; | ||
70 | size_t i; | ||
71 | int sta; | ||
72 | |||
73 | for (i = 0; i < __arraycount(mask) - 1; i++) { | ||
74 | |||
75 | (void)umask(mask[i] | mask[i + 1]); | ||
76 | |||
77 | pid = fork(); | ||
78 | |||
79 | if (pid < 0) | ||
80 | continue; | ||
81 | |||
82 | if (pid == 0) { | ||
83 | |||
84 | mode = umask(mask[i]); | ||
85 | |||
86 | if (mode != (mask[i] | mask[i + 1])) | ||
87 | _exit(EXIT_FAILURE); | ||
88 | |||
89 | _exit(EXIT_SUCCESS); | ||
90 | } | ||
91 | |||
92 | (void)wait(&sta); | ||
93 | |||
94 | if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) | ||
95 | goto fail; | ||
96 | } | ||
97 | |||
98 | return; | ||
99 | |||
100 | fail: | ||
101 | (void)umask(S_IWGRP | S_IWOTH); | ||
102 | |||
103 | atf_tc_fail("umask(2) was not inherited"); | ||
104 | } | ||
105 | |||
106 | ATF_TC_CLEANUP(umask_fork, tc) | ||
107 | { | ||
108 | (void)umask(S_IWGRP | S_IWOTH); | ||
109 | } | ||
110 | |||
111 | ATF_TC_WITH_CLEANUP(umask_open); | ||
112 | ATF_TC_HEAD(umask_open, tc) | ||
113 | { | ||
114 | atf_tc_set_md_var(tc, "descr", "A basic test of open(2) and umask(2)"); | ||
115 | } | ||
116 | |||
117 | ATF_TC_BODY(umask_open, tc) | ||
118 | { | ||
119 | const char *str = NULL; | ||
120 | struct stat st; | ||
121 | size_t i; | ||
122 | int fd; | ||
123 | |||
124 | for (i = 0; i < __arraycount(mask); i++) { | ||
125 | |||
126 | (void)umask(mask[i]); | ||
127 | |||
128 | fd = open(path, O_RDWR | O_CREAT, 0777); | ||
129 | |||
130 | if (fd < 0) | ||
131 | continue; | ||
132 | |||
133 | (void)close(fd); | ||
134 | (void)memset(&st, 0, sizeof(struct stat)); | ||
135 | |||
136 | if (stat(path, &st) != 0) { | ||
137 | str = "failed to stat(2)"; | ||
138 | goto out; | ||
139 | } | ||
140 | |||
141 | if ((st.st_mode & mask[i]) != 0) { | ||
142 | str = "invalid umask(2)"; | ||
143 | goto out; | ||
144 | } | ||
145 | |||
146 | if (unlink(path) != 0) { | ||
147 | str = "failed to unlink(2)"; | ||
148 | goto out; | ||
149 | } | ||
150 | |||
151 | } | ||
152 | |||
153 | out: | ||
154 | (void)umask(S_IWGRP | S_IWOTH); | ||
155 | |||
156 | if (str != NULL) | ||
157 | atf_tc_fail("%s", str); | ||
158 | } | ||
159 | |||
160 | ATF_TC_CLEANUP(umask_open, tc) | ||
161 | { | ||
162 | (void)umask(S_IWGRP | S_IWOTH); | ||
163 | (void)unlink(path); | ||
164 | } | ||
165 | |||
166 | ATF_TC_WITH_CLEANUP(umask_previous); | ||
167 | ATF_TC_HEAD(umask_previous, tc) | ||
168 | { | ||
169 | atf_tc_set_md_var(tc, "descr", "Test the return value from umask(2)"); | ||
170 | } | ||
171 | |||
172 | ATF_TC_BODY(umask_previous, tc) | ||
173 | { | ||
174 | mode_t mode; | ||
175 | size_t i; | ||
176 | |||
177 | for (i = 0; i < __arraycount(mask); i++) { | ||
178 | |||
179 | mode = umask(mask[i]); | ||
180 | mode = umask(mask[i]); | ||
181 | |||
182 | if (mode != mask[i]) | ||
183 | goto fail; | ||
184 | } | ||
185 | |||
186 | return; | ||
187 | |||
188 | fail: | ||
189 | (void)umask(S_IWGRP | S_IWOTH); | ||
190 | |||
191 | atf_tc_fail("umask(2) did not return the previous mask"); | ||
192 | } | ||
193 | |||
194 | ATF_TC_CLEANUP(umask_previous, tc) | ||
195 | { | ||
196 | (void)umask(S_IWGRP | S_IWOTH); | ||
197 | } | ||
198 | |||
199 | ATF_TP_ADD_TCS(tp) | ||
200 | { | ||
201 | |||
202 | ATF_TP_ADD_TC(tp, umask_fork); | ||
203 | ATF_TP_ADD_TC(tp, umask_open); | ||
204 | ATF_TP_ADD_TC(tp, umask_previous); | ||
205 | |||
206 | return atf_no_error(); | ||
207 | } | ||
diff --git a/src/regress/lib/libc/sys/t_unlink.c b/src/regress/lib/libc/sys/t_unlink.c deleted file mode 100644 index be1529b6ad..0000000000 --- a/src/regress/lib/libc/sys/t_unlink.c +++ /dev/null | |||
@@ -1,159 +0,0 @@ | |||
1 | /* $OpenBSD: t_unlink.c,v 1.3 2023/10/31 07:59:52 claudio Exp $ */ | ||
2 | /* $NetBSD: t_unlink.c,v 1.4 2017/01/14 20:55:26 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jukka Ruohonen. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/stat.h> | ||
36 | |||
37 | #include "atf-c.h" | ||
38 | #include <errno.h> | ||
39 | #include <fcntl.h> | ||
40 | #include <limits.h> | ||
41 | #include <string.h> | ||
42 | #include <unistd.h> | ||
43 | |||
44 | static char path[] = "unlink"; | ||
45 | |||
46 | ATF_TC_WITH_CLEANUP(unlink_basic); | ||
47 | ATF_TC_HEAD(unlink_basic, tc) | ||
48 | { | ||
49 | atf_tc_set_md_var(tc, "descr", "A basic test of unlink(2)"); | ||
50 | } | ||
51 | |||
52 | ATF_TC_BODY(unlink_basic, tc) | ||
53 | { | ||
54 | const size_t n = 512; | ||
55 | size_t i; | ||
56 | int fd; | ||
57 | |||
58 | for (i = 0; i < n; i++) { | ||
59 | |||
60 | fd = open(path, O_RDWR | O_CREAT, 0666); | ||
61 | |||
62 | ATF_REQUIRE(fd != -1); | ||
63 | ATF_REQUIRE(close(fd) == 0); | ||
64 | ATF_REQUIRE(unlink(path) == 0); | ||
65 | |||
66 | errno = 0; | ||
67 | ATF_REQUIRE_ERRNO(ENOENT, open(path, O_RDONLY) == -1); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | ATF_TC_CLEANUP(unlink_basic, tc) | ||
72 | { | ||
73 | (void)unlink(path); | ||
74 | } | ||
75 | |||
76 | ATF_TC_WITH_CLEANUP(unlink_err); | ||
77 | ATF_TC_HEAD(unlink_err, tc) | ||
78 | { | ||
79 | atf_tc_set_md_var(tc, "descr", "Test error conditions of unlink(2)"); | ||
80 | } | ||
81 | |||
82 | ATF_TC_BODY(unlink_err, tc) | ||
83 | { | ||
84 | char buf[PATH_MAX + 1]; | ||
85 | |||
86 | (void)memset(buf, 'x', sizeof(buf)); | ||
87 | |||
88 | errno = 0; | ||
89 | ATF_REQUIRE(unlink("/") == -1); | ||
90 | |||
91 | errno = 0; | ||
92 | ATF_REQUIRE_ERRNO(ENAMETOOLONG, unlink(buf) == -1); | ||
93 | |||
94 | errno = 0; | ||
95 | ATF_REQUIRE_ERRNO(ENOENT, unlink("/a/b/c/d/e/f/g/h/i/j/k/l/m") == -1); | ||
96 | } | ||
97 | |||
98 | ATF_TC_CLEANUP(unlink_err, tc) | ||
99 | { | ||
100 | (void)unlink(path); | ||
101 | } | ||
102 | |||
103 | ATF_TC_WITH_CLEANUP(unlink_fifo); | ||
104 | ATF_TC_HEAD(unlink_fifo, tc) | ||
105 | { | ||
106 | atf_tc_set_md_var(tc, "descr", "Test unlink(2) for a FIFO"); | ||
107 | } | ||
108 | |||
109 | ATF_TC_BODY(unlink_fifo, tc) | ||
110 | { | ||
111 | |||
112 | ATF_REQUIRE(mkfifo(path, 0666) == 0); | ||
113 | ATF_REQUIRE(unlink(path) == 0); | ||
114 | |||
115 | errno = 0; | ||
116 | ATF_REQUIRE_ERRNO(ENOENT, open(path, O_RDONLY) == -1); | ||
117 | } | ||
118 | |||
119 | ATF_TC_CLEANUP(unlink_fifo, tc) | ||
120 | { | ||
121 | (void)unlink(path); | ||
122 | } | ||
123 | |||
124 | ATF_TC_WITH_CLEANUP(unlink_perm); | ||
125 | ATF_TC_HEAD(unlink_perm, tc) | ||
126 | { | ||
127 | atf_tc_set_md_var(tc, "descr", "Test permissions with unlink(2)"); | ||
128 | atf_tc_set_md_var(tc, "require.user", "unprivileged"); | ||
129 | } | ||
130 | |||
131 | ATF_TC_BODY(unlink_perm, tc) | ||
132 | { | ||
133 | int rv; | ||
134 | |||
135 | errno = 0; | ||
136 | rv = unlink("/etc"); | ||
137 | ATF_REQUIRE_MSG(rv == -1 && (errno == EACCES || errno == EPERM), | ||
138 | "unlinking a directory did not fail with EPERM or EACCESS; " | ||
139 | "unlink() returned %d, errno %d", rv, errno); | ||
140 | |||
141 | errno = 0; | ||
142 | ATF_REQUIRE_ERRNO(EACCES, unlink("/root/.profile") == -1); | ||
143 | } | ||
144 | |||
145 | ATF_TC_CLEANUP(unlink_perm, tc) | ||
146 | { | ||
147 | (void)unlink(path); | ||
148 | } | ||
149 | |||
150 | ATF_TP_ADD_TCS(tp) | ||
151 | { | ||
152 | |||
153 | ATF_TP_ADD_TC(tp, unlink_basic); | ||
154 | ATF_TP_ADD_TC(tp, unlink_err); | ||
155 | ATF_TP_ADD_TC(tp, unlink_fifo); | ||
156 | ATF_TP_ADD_TC(tp, unlink_perm); | ||
157 | |||
158 | return atf_no_error(); | ||
159 | } | ||
diff --git a/src/regress/lib/libc/sys/t_vfork.c b/src/regress/lib/libc/sys/t_vfork.c deleted file mode 100644 index a7c6f82e8a..0000000000 --- a/src/regress/lib/libc/sys/t_vfork.c +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | /* $OpenBSD: t_vfork.c,v 1.1 2021/09/02 15:28:41 mbuhl Exp $ */ | ||
2 | /* $NetBSD: t_vfork.c,v 1.1 2018/05/18 06:39:58 kamil Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
27 | * POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #define VFORK | ||
31 | #include "t_fork.c" | ||
diff --git a/src/regress/lib/libc/sys/t_wait_noproc.c b/src/regress/lib/libc/sys/t_wait_noproc.c deleted file mode 100644 index 8d408041c5..0000000000 --- a/src/regress/lib/libc/sys/t_wait_noproc.c +++ /dev/null | |||
@@ -1,355 +0,0 @@ | |||
1 | /* $OpenBSD: t_wait_noproc.c,v 1.4 2022/12/19 22:44:54 guenther Exp $ */ | ||
2 | /* $NetBSD: t_wait_noproc.c,v 1.5 2016/11/09 17:50:19 kamil Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2016 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
27 | * POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #include "macros.h" | ||
31 | |||
32 | #include <sys/wait.h> | ||
33 | #include <sys/resource.h> | ||
34 | |||
35 | #include <errno.h> | ||
36 | #include <stdio.h> | ||
37 | |||
38 | #include "atf-c.h" | ||
39 | |||
40 | #ifndef TWAIT_OPTION | ||
41 | #define TWAIT_OPTION 0 | ||
42 | #endif | ||
43 | |||
44 | #if TWAIT_OPTION == 0 | ||
45 | ATF_TC(wait); | ||
46 | ATF_TC_HEAD(wait, tc) | ||
47 | { | ||
48 | atf_tc_set_md_var(tc, "descr", | ||
49 | "Test that wait(2) returns ECHILD for no child"); | ||
50 | } | ||
51 | |||
52 | ATF_TC_BODY(wait, tc) | ||
53 | { | ||
54 | ATF_REQUIRE_ERRNO(ECHILD, wait(NULL) == -1); | ||
55 | } | ||
56 | #endif | ||
57 | |||
58 | ATF_TC(waitpid); | ||
59 | ATF_TC_HEAD(waitpid, tc) | ||
60 | { | ||
61 | atf_tc_set_md_var(tc, "descr", | ||
62 | "Test that waitpid(2) returns ECHILD for WAIT_ANY and option %s", | ||
63 | ___STRING(TWAIT_OPTION)); | ||
64 | } | ||
65 | |||
66 | ATF_TC_BODY(waitpid, tc) | ||
67 | { | ||
68 | ATF_REQUIRE_ERRNO(ECHILD, waitpid(WAIT_ANY, NULL, TWAIT_OPTION) == -1); | ||
69 | } | ||
70 | |||
71 | ATF_TC(waitid); | ||
72 | ATF_TC_HEAD(waitid, tc) | ||
73 | { | ||
74 | atf_tc_set_md_var(tc, "descr", | ||
75 | "Test that waitid(2) returns ECHILD for P_ALL and option %s", | ||
76 | ___STRING(TWAIT_OPTION)); | ||
77 | } | ||
78 | |||
79 | ATF_TC_BODY(waitid, tc) | ||
80 | { | ||
81 | ATF_REQUIRE_ERRNO(ECHILD, | ||
82 | waitid(P_ALL, 0, NULL, | ||
83 | WEXITED | TWAIT_OPTION) == -1); | ||
84 | } | ||
85 | |||
86 | ATF_TC(wait3); | ||
87 | ATF_TC_HEAD(wait3, tc) | ||
88 | { | ||
89 | atf_tc_set_md_var(tc, "descr", | ||
90 | "Test that wait3(2) returns ECHILD for no child"); | ||
91 | } | ||
92 | |||
93 | ATF_TC_BODY(wait3, tc) | ||
94 | { | ||
95 | ATF_REQUIRE_ERRNO(ECHILD, wait3(NULL, TWAIT_OPTION, NULL) == -1); | ||
96 | } | ||
97 | |||
98 | ATF_TC(wait4); | ||
99 | ATF_TC_HEAD(wait4, tc) | ||
100 | { | ||
101 | atf_tc_set_md_var(tc, "descr", | ||
102 | "Test that wait4(2) returns ECHILD for WAIT_ANY and option %s", | ||
103 | ___STRING(TWAIT_OPTION)); | ||
104 | } | ||
105 | |||
106 | ATF_TC_BODY(wait4, tc) | ||
107 | { | ||
108 | ATF_REQUIRE_ERRNO(ECHILD, | ||
109 | wait4(WAIT_ANY, NULL, TWAIT_OPTION, NULL) == -1); | ||
110 | } | ||
111 | |||
112 | #ifndef __OpenBSD__ | ||
113 | * Adjusted for OpenBSD, not available | ||
114 | * ATF_TC(wait6); | ||
115 | * ATF_TC_HEAD(wait6, tc) | ||
116 | * { | ||
117 | * atf_tc_set_md_var(tc, "descr", | ||
118 | * "Test that wait6(2) returns ECHILD for P_ALL and option %s", | ||
119 | * ___STRING(TWAIT_OPTION)); | ||
120 | * } | ||
121 | * | ||
122 | * ATF_TC_BODY(wait6, tc) | ||
123 | * { | ||
124 | * ATF_REQUIRE_ERRNO(ECHILD, | ||
125 | * wait6(P_ALL, 0, NULL, | ||
126 | * WTRAPPED | WEXITED | TWAIT_OPTION, NULL, NULL) == -1); | ||
127 | * } | ||
128 | */ | ||
129 | #endif | ||
130 | |||
131 | /* | ||
132 | * Generator of valid combinations of options | ||
133 | * Usage: i = 0; while ((o = get_options_wait6(i++)) != -1) {} | ||
134 | */ | ||
135 | static int | ||
136 | get_options6(size_t pos) | ||
137 | { | ||
138 | int rv = 0; | ||
139 | size_t n; | ||
140 | /* | ||
141 | * waitid(2) must specify at least one of WEXITED, WUNTRACED, | ||
142 | * WSTOPPED, WTRAPPED or WCONTINUED. Single option WNOWAIT | ||
143 | * isn't valid. | ||
144 | */ | ||
145 | const int matrix[] = { | ||
146 | WNOWAIT, // First in order to blacklist it easily | ||
147 | WEXITED, | ||
148 | #ifndef __OpenBSD__ | ||
149 | WUNTRACED, | ||
150 | #endif | ||
151 | WSTOPPED, // SUS compatibility, equal to WUNTRACED | ||
152 | WTRAPPED, | ||
153 | WCONTINUED | ||
154 | }; | ||
155 | |||
156 | const size_t M = (1 << __arraycount(matrix)) - 1; | ||
157 | /* Skip empty and sole WNOWAIT option */ | ||
158 | pos+=2; | ||
159 | |||
160 | if (pos > M) | ||
161 | return -1; | ||
162 | |||
163 | for (n = 0; n < __arraycount(matrix); n++) { | ||
164 | if (pos & __BIT(n)) | ||
165 | rv |= matrix[n]; | ||
166 | } | ||
167 | |||
168 | return rv; | ||
169 | } | ||
170 | |||
171 | /* | ||
172 | * Generator of valid combinations of options | ||
173 | * Usage: i = 0; while ((o = get_options_wait4(i++)) != -1) {} | ||
174 | */ | ||
175 | static int | ||
176 | get_options4(size_t pos) | ||
177 | { | ||
178 | int rv = 0; | ||
179 | size_t n; | ||
180 | |||
181 | const int special[] = { | ||
182 | 0, | ||
183 | #ifndef __OpenBSD__ | ||
184 | WALLSIG, | ||
185 | WALTSIG, | ||
186 | __WALL, // Linux compatibility, equal to WALLSIG | ||
187 | __WCLONE // Linux compatibility, equal to WALTSIG | ||
188 | #endif | ||
189 | }; | ||
190 | |||
191 | const int matrix[] = { | ||
192 | #ifndef __OpenBSD__ | ||
193 | WNOWAIT, | ||
194 | WEXITED, | ||
195 | #endif | ||
196 | WUNTRACED, | ||
197 | #ifndef __OpenBSD__ | ||
198 | WSTOPPED, // SUS compatibility, equal to WUNTRACED | ||
199 | WTRAPPED, | ||
200 | #endif | ||
201 | WCONTINUED | ||
202 | }; | ||
203 | |||
204 | const size_t M = (1 << __arraycount(special)) - 1; | ||
205 | |||
206 | if (pos < __arraycount(special)) | ||
207 | return special[pos]; | ||
208 | |||
209 | pos -= __arraycount(special); | ||
210 | |||
211 | ++pos; /* Don't start with empty mask */ | ||
212 | |||
213 | if (pos > M) | ||
214 | return -1; | ||
215 | |||
216 | for (n = 0; n < __arraycount(special); n++) { | ||
217 | if (pos & __BIT(n)) | ||
218 | rv |= matrix[n]; | ||
219 | } | ||
220 | |||
221 | return rv; | ||
222 | } | ||
223 | |||
224 | ATF_TC(waitpid_options); | ||
225 | ATF_TC_HEAD(waitpid_options, tc) | ||
226 | { | ||
227 | atf_tc_set_md_var(tc, "descr", | ||
228 | "Test that waitpid(2) returns ECHILD for WAIT_ANY and valid " | ||
229 | "combination of options with%s WNOHANG", | ||
230 | TWAIT_OPTION == 0 ? "out" : ""); | ||
231 | } | ||
232 | |||
233 | ATF_TC_BODY(waitpid_options, tc) | ||
234 | { | ||
235 | size_t i = 0; | ||
236 | int o; | ||
237 | |||
238 | while((o = get_options4(i++)) != -1) { | ||
239 | printf("Testing waitpid(2) with options %x\n", o); | ||
240 | |||
241 | ATF_REQUIRE_ERRNO(ECHILD, | ||
242 | waitpid(WAIT_ANY, NULL, o | TWAIT_OPTION) == -1); | ||
243 | } | ||
244 | } | ||
245 | |||
246 | ATF_TC(waitid_options); | ||
247 | ATF_TC_HEAD(waitid_options, tc) | ||
248 | { | ||
249 | atf_tc_set_md_var(tc, "descr", | ||
250 | "Test that waitid(2) returns ECHILD for P_ALL and valid " | ||
251 | "combination of options with%s WNOHANG", | ||
252 | TWAIT_OPTION == 0 ? "out" : ""); | ||
253 | } | ||
254 | |||
255 | ATF_TC_BODY(waitid_options, tc) | ||
256 | { | ||
257 | size_t i = 0; | ||
258 | int o; | ||
259 | |||
260 | while((o = get_options6(i++)) != -1) { | ||
261 | printf("Testing waitid(2) with options %x\n", o); | ||
262 | |||
263 | ATF_REQUIRE_ERRNO(ECHILD, | ||
264 | waitid(P_ALL, 0, NULL, o | TWAIT_OPTION) == -1); | ||
265 | } | ||
266 | } | ||
267 | |||
268 | ATF_TC(wait3_options); | ||
269 | ATF_TC_HEAD(wait3_options, tc) | ||
270 | { | ||
271 | atf_tc_set_md_var(tc, "descr", | ||
272 | "Test that wait3(2) returns ECHILD for no child"); | ||
273 | } | ||
274 | |||
275 | ATF_TC_BODY(wait3_options, tc) | ||
276 | { | ||
277 | size_t i = 0; | ||
278 | int o; | ||
279 | |||
280 | while((o = get_options4(i++)) != -1) { | ||
281 | printf("Testing wait3(2) with options %x\n", o); | ||
282 | |||
283 | ATF_REQUIRE_ERRNO(ECHILD, | ||
284 | wait3(NULL, o | TWAIT_OPTION, NULL) == -1); | ||
285 | } | ||
286 | } | ||
287 | |||
288 | ATF_TC(wait4_options); | ||
289 | ATF_TC_HEAD(wait4_options, tc) | ||
290 | { | ||
291 | atf_tc_set_md_var(tc, "descr", | ||
292 | "Test that wait4(2) returns ECHILD for WAIT_ANY and option %s", | ||
293 | ___STRING(TWAIT_OPTION)); | ||
294 | } | ||
295 | |||
296 | ATF_TC_BODY(wait4_options, tc) | ||
297 | { | ||
298 | size_t i = 0; | ||
299 | int o; | ||
300 | |||
301 | while((o = get_options4(i++)) != -1) { | ||
302 | printf("Testing wait4(2) with options %x\n", o); | ||
303 | |||
304 | ATF_REQUIRE_ERRNO(ECHILD, | ||
305 | wait4(WAIT_ANY, NULL, o | TWAIT_OPTION, NULL) == -1); | ||
306 | } | ||
307 | } | ||
308 | |||
309 | #ifndef __OpenBSD__ | ||
310 | ATF_TC(wait6_options); | ||
311 | ATF_TC_HEAD(wait6_options, tc) | ||
312 | { | ||
313 | atf_tc_set_md_var(tc, "descr", | ||
314 | "Test that wait6(2) returns ECHILD for P_ALL and option %s", | ||
315 | ___STRING(TWAIT_OPTION)); | ||
316 | } | ||
317 | |||
318 | ATF_TC_BODY(wait6_options, tc) | ||
319 | { | ||
320 | size_t i = 0; | ||
321 | int o; | ||
322 | |||
323 | while((o = get_options6(i++)) != -1) { | ||
324 | printf("Testing wait6(2) with options %x\n", o); | ||
325 | |||
326 | ATF_REQUIRE_ERRNO(ECHILD, | ||
327 | wait6(P_ALL, 0, NULL, o | TWAIT_OPTION, NULL, NULL) == -1); | ||
328 | } | ||
329 | } | ||
330 | #endif | ||
331 | |||
332 | ATF_TP_ADD_TCS(tp) | ||
333 | { | ||
334 | |||
335 | #if TWAIT_OPTION == 0 | ||
336 | ATF_TP_ADD_TC(tp, wait); | ||
337 | #endif | ||
338 | ATF_TP_ADD_TC(tp, waitpid); | ||
339 | ATF_TP_ADD_TC(tp, waitid); | ||
340 | ATF_TP_ADD_TC(tp, wait3); | ||
341 | ATF_TP_ADD_TC(tp, wait4); | ||
342 | #ifndef __OpenBSD__ | ||
343 | ATF_TP_ADD_TC(tp, wait6); | ||
344 | #endif | ||
345 | |||
346 | ATF_TP_ADD_TC(tp, waitpid_options); | ||
347 | ATF_TP_ADD_TC(tp, waitid_options); | ||
348 | ATF_TP_ADD_TC(tp, wait3_options); | ||
349 | ATF_TP_ADD_TC(tp, wait4_options); | ||
350 | #ifndef __OpenBSD__ | ||
351 | ATF_TP_ADD_TC(tp, wait6_options); | ||
352 | #endif | ||
353 | |||
354 | return atf_no_error(); | ||
355 | } | ||
diff --git a/src/regress/lib/libc/sys/t_wait_noproc_wnohang.c b/src/regress/lib/libc/sys/t_wait_noproc_wnohang.c deleted file mode 100644 index d1dcb98164..0000000000 --- a/src/regress/lib/libc/sys/t_wait_noproc_wnohang.c +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | /* $OpenBSD: t_wait_noproc_wnohang.c,v 1.1 2021/09/02 12:40:44 mbuhl Exp $ */ | ||
2 | /* $NetBSD: t_wait_noproc_wnohang.c,v 1.1 2016/11/06 15:03:30 kamil Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2016 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
27 | * POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #define TWAIT_OPTION WNOHANG | ||
31 | #include "t_wait_noproc.c" | ||
diff --git a/src/regress/lib/libc/sys/t_waitid.c b/src/regress/lib/libc/sys/t_waitid.c deleted file mode 100644 index ecb16fabad..0000000000 --- a/src/regress/lib/libc/sys/t_waitid.c +++ /dev/null | |||
@@ -1,272 +0,0 @@ | |||
1 | /* $OpenBSD: t_waitid.c,v 1.1 2022/10/26 23:18:02 kettenis Exp $ */ | ||
2 | /* $NetBSD: t_wait.c,v 1.10 2021/07/17 14:03:35 martin Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2016 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Christos Zoulas. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | #include "macros.h" | ||
34 | |||
35 | #include <sys/wait.h> | ||
36 | #include <sys/resource.h> | ||
37 | |||
38 | #include <errno.h> | ||
39 | #include <inttypes.h> | ||
40 | #include <limits.h> | ||
41 | #include <pwd.h> | ||
42 | #include <signal.h> | ||
43 | #include <stdio.h> | ||
44 | #include <stdlib.h> | ||
45 | #include <unistd.h> | ||
46 | |||
47 | #include "atf-c.h" | ||
48 | |||
49 | ATF_TC(waitid_invalid); | ||
50 | ATF_TC_HEAD(waitid_invalid, tc) | ||
51 | { | ||
52 | atf_tc_set_md_var(tc, "descr", | ||
53 | "Test that waitid(2) returns EINVAL with 0 options"); | ||
54 | } | ||
55 | |||
56 | ATF_TC_BODY(waitid_invalid, tc) | ||
57 | { | ||
58 | siginfo_t si; | ||
59 | ATF_REQUIRE(waitid(P_ALL, 0, &si, 0) == -1 | ||
60 | && errno == EINVAL); | ||
61 | } | ||
62 | |||
63 | ATF_TC(waitid_exited); | ||
64 | ATF_TC_HEAD(waitid_exited, tc) | ||
65 | { | ||
66 | atf_tc_set_md_var(tc, "descr", | ||
67 | "Test that waitid(2) handled exiting process and code"); | ||
68 | } | ||
69 | |||
70 | ATF_TC_BODY(waitid_exited, tc) | ||
71 | { | ||
72 | siginfo_t si; | ||
73 | pid_t pid; | ||
74 | |||
75 | switch (pid = fork()) { | ||
76 | case 0: | ||
77 | exit(0x5a5a5a5a); | ||
78 | /*NOTREACHED*/ | ||
79 | case -1: | ||
80 | ATF_REQUIRE(pid > 0); | ||
81 | __unreachable(); | ||
82 | default: | ||
83 | ATF_REQUIRE(waitid(P_PID, pid, &si, WEXITED) == 0); | ||
84 | ATF_REQUIRE(si.si_status == 0x5a5a5a5a); | ||
85 | ATF_REQUIRE(si.si_pid == pid); | ||
86 | ATF_REQUIRE(si.si_uid == getuid()); | ||
87 | ATF_REQUIRE(si.si_code == CLD_EXITED); | ||
88 | printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, | ||
89 | (uintmax_t)si.si_utime); | ||
90 | break; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | ATF_TC(waitid_terminated); | ||
95 | ATF_TC_HEAD(waitid_terminated, tc) | ||
96 | { | ||
97 | atf_tc_set_md_var(tc, "descr", | ||
98 | "Test that waitid(2) handled terminated process and code"); | ||
99 | } | ||
100 | |||
101 | ATF_TC_BODY(waitid_terminated, tc) | ||
102 | { | ||
103 | siginfo_t si; | ||
104 | pid_t pid; | ||
105 | |||
106 | switch (pid = fork()) { | ||
107 | case 0: | ||
108 | sleep(100); | ||
109 | /*FALLTHROUGH*/ | ||
110 | case -1: | ||
111 | ATF_REQUIRE(pid > 0); | ||
112 | __unreachable(); | ||
113 | default: | ||
114 | ATF_REQUIRE(kill(pid, SIGTERM) == 0); | ||
115 | ATF_REQUIRE(waitid(P_PID, pid, &si, WEXITED) == 0); | ||
116 | ATF_REQUIRE(si.si_status == SIGTERM); | ||
117 | ATF_REQUIRE(si.si_pid == pid); | ||
118 | ATF_REQUIRE(si.si_uid == getuid()); | ||
119 | ATF_REQUIRE(si.si_code == CLD_KILLED); | ||
120 | printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, | ||
121 | (uintmax_t)si.si_utime); | ||
122 | break; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | ATF_TC(waitid_coredumped); | ||
127 | ATF_TC_HEAD(waitid_coredumped, tc) | ||
128 | { | ||
129 | atf_tc_set_md_var(tc, "descr", | ||
130 | "Test that waitid(2) handled coredumped process and code"); | ||
131 | } | ||
132 | |||
133 | ATF_TC_BODY(waitid_coredumped, tc) | ||
134 | { | ||
135 | siginfo_t si; | ||
136 | pid_t pid; | ||
137 | static const struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY }; | ||
138 | |||
139 | switch (pid = fork()) { | ||
140 | case 0: | ||
141 | ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0); | ||
142 | *(char *)8 = 0; | ||
143 | /*FALLTHROUGH*/ | ||
144 | case -1: | ||
145 | ATF_REQUIRE(pid > 0); | ||
146 | __unreachable(); | ||
147 | default: | ||
148 | ATF_REQUIRE(waitid(P_PID, pid, &si, WEXITED) == 0); | ||
149 | ATF_REQUIRE(si.si_status == SIGSEGV); | ||
150 | ATF_REQUIRE(si.si_pid == pid); | ||
151 | ATF_REQUIRE(si.si_uid == getuid()); | ||
152 | ATF_REQUIRE(si.si_code == CLD_DUMPED); | ||
153 | printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, | ||
154 | (uintmax_t)si.si_utime); | ||
155 | break; | ||
156 | } | ||
157 | } | ||
158 | |||
159 | ATF_TC(waitid_stop_and_go); | ||
160 | ATF_TC_HEAD(waitid_stop_and_go, tc) | ||
161 | { | ||
162 | atf_tc_set_md_var(tc, "descr", | ||
163 | "Test that waitid(2) handled stopped/continued process and code"); | ||
164 | } | ||
165 | |||
166 | ATF_TC_BODY(waitid_stop_and_go, tc) | ||
167 | { | ||
168 | siginfo_t si; | ||
169 | pid_t pid; | ||
170 | static const struct rlimit rl = { 0, 0 }; | ||
171 | |||
172 | ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0); | ||
173 | switch (pid = fork()) { | ||
174 | case 0: | ||
175 | sleep(100); | ||
176 | /*FALLTHROUGH*/ | ||
177 | case -1: | ||
178 | ATF_REQUIRE(pid > 0); | ||
179 | __unreachable(); | ||
180 | default: | ||
181 | ATF_REQUIRE(kill(pid, SIGSTOP) == 0); | ||
182 | ATF_REQUIRE(waitid(P_PID, pid, &si, WSTOPPED) == 0); | ||
183 | ATF_REQUIRE(si.si_status == SIGSTOP); | ||
184 | ATF_REQUIRE(si.si_pid == pid); | ||
185 | ATF_REQUIRE(si.si_uid == getuid()); | ||
186 | ATF_REQUIRE(si.si_code == CLD_STOPPED); | ||
187 | printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, | ||
188 | (uintmax_t)si.si_utime); | ||
189 | |||
190 | ATF_REQUIRE(kill(pid, SIGCONT) == 0); | ||
191 | ATF_REQUIRE(waitid(P_PID, pid, &si, WCONTINUED) == 0); | ||
192 | ATF_REQUIRE(si.si_status == SIGCONT); | ||
193 | ATF_REQUIRE(si.si_pid == pid); | ||
194 | ATF_REQUIRE(si.si_uid == getuid()); | ||
195 | ATF_REQUIRE(si.si_code == CLD_CONTINUED); | ||
196 | printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, | ||
197 | (uintmax_t)si.si_utime); | ||
198 | |||
199 | ATF_REQUIRE(kill(pid, SIGQUIT) == 0); | ||
200 | ATF_REQUIRE(waitid(P_PID, pid, &si, WEXITED) == 0); | ||
201 | ATF_REQUIRE(si.si_status == SIGQUIT); | ||
202 | ATF_REQUIRE(si.si_pid == pid); | ||
203 | ATF_REQUIRE(si.si_uid == getuid()); | ||
204 | ATF_REQUIRE(si.si_code == CLD_KILLED); | ||
205 | printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, | ||
206 | (uintmax_t)si.si_utime); | ||
207 | break; | ||
208 | } | ||
209 | } | ||
210 | |||
211 | ATF_TC(waitid_stopgo_loop); | ||
212 | ATF_TC_HEAD(waitid_stopgo_loop, tc) | ||
213 | { | ||
214 | atf_tc_set_md_var(tc, "descr", | ||
215 | "Test that waitid(2) handled stopped/continued process loop"); | ||
216 | } | ||
217 | |||
218 | ATF_TC_BODY(waitid_stopgo_loop, tc) | ||
219 | { | ||
220 | siginfo_t si; | ||
221 | pid_t pid; | ||
222 | static const struct rlimit rl = { 0, 0 }; | ||
223 | size_t N = 100; | ||
224 | |||
225 | ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0); | ||
226 | switch (pid = fork()) { | ||
227 | case 0: | ||
228 | sleep(100); | ||
229 | /*FALLTHROUGH*/ | ||
230 | case -1: | ||
231 | ATF_REQUIRE(pid > 0); | ||
232 | __unreachable(); | ||
233 | } | ||
234 | |||
235 | printf("Before loop of SIGSTOP/SIGCONT sequence %zu times\n", N); | ||
236 | while (N --> 0) { | ||
237 | ATF_REQUIRE(kill(pid, SIGSTOP) == 0); | ||
238 | ATF_REQUIRE(waitid(P_PID, pid, &si, WSTOPPED) == 0); | ||
239 | ATF_REQUIRE(si.si_status == SIGSTOP); | ||
240 | ATF_REQUIRE(si.si_pid == pid); | ||
241 | ATF_REQUIRE(si.si_uid == getuid()); | ||
242 | ATF_REQUIRE(si.si_code == CLD_STOPPED); | ||
243 | |||
244 | ATF_REQUIRE(kill(pid, SIGCONT) == 0); | ||
245 | ATF_REQUIRE(waitid(P_PID, pid, &si, WCONTINUED) == 0); | ||
246 | ATF_REQUIRE(si.si_status == SIGCONT); | ||
247 | ATF_REQUIRE(si.si_pid == pid); | ||
248 | ATF_REQUIRE(si.si_uid == getuid()); | ||
249 | ATF_REQUIRE(si.si_code == CLD_CONTINUED); | ||
250 | } | ||
251 | ATF_REQUIRE(kill(pid, SIGQUIT) == 0); | ||
252 | ATF_REQUIRE(waitid(P_PID, pid, &si, WEXITED) == 0); | ||
253 | ATF_REQUIRE(si.si_status == SIGQUIT); | ||
254 | ATF_REQUIRE(si.si_pid == pid); | ||
255 | ATF_REQUIRE(si.si_uid == getuid()); | ||
256 | ATF_REQUIRE(si.si_code == CLD_KILLED); | ||
257 | printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, | ||
258 | (uintmax_t)si.si_utime); | ||
259 | } | ||
260 | |||
261 | ATF_TP_ADD_TCS(tp) | ||
262 | { | ||
263 | |||
264 | ATF_TP_ADD_TC(tp, waitid_invalid); | ||
265 | ATF_TP_ADD_TC(tp, waitid_exited); | ||
266 | ATF_TP_ADD_TC(tp, waitid_terminated); | ||
267 | ATF_TP_ADD_TC(tp, waitid_coredumped); | ||
268 | ATF_TP_ADD_TC(tp, waitid_stop_and_go); | ||
269 | ATF_TP_ADD_TC(tp, waitid_stopgo_loop); | ||
270 | |||
271 | return atf_no_error(); | ||
272 | } | ||
diff --git a/src/regress/lib/libc/sys/t_write.c b/src/regress/lib/libc/sys/t_write.c deleted file mode 100644 index 8d01ebfba8..0000000000 --- a/src/regress/lib/libc/sys/t_write.c +++ /dev/null | |||
@@ -1,282 +0,0 @@ | |||
1 | /* $OpenBSD: t_write.c,v 1.4 2021/12/13 16:56:48 deraadt Exp $ */ | ||
2 | /* $NetBSD: t_write.c,v 1.7 2019/07/16 17:29:18 martin Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
27 | * POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #include "macros.h" | ||
31 | |||
32 | #include <sys/uio.h> | ||
33 | #include <sys/mman.h> | ||
34 | |||
35 | #include "atf-c.h" | ||
36 | #include <errno.h> | ||
37 | #include <fcntl.h> | ||
38 | #include <signal.h> | ||
39 | #include <limits.h> | ||
40 | #include <stdio.h> | ||
41 | #include <stdint.h> | ||
42 | #include <string.h> | ||
43 | #include <unistd.h> | ||
44 | #include <paths.h> | ||
45 | |||
46 | static void sighandler(int); | ||
47 | |||
48 | static bool fail = false; | ||
49 | static const char *path = "write"; | ||
50 | |||
51 | static void | ||
52 | sighandler(int signo __unused) | ||
53 | { | ||
54 | fail = false; | ||
55 | } | ||
56 | |||
57 | ATF_TC_WITH_CLEANUP(write_err); | ||
58 | ATF_TC_HEAD(write_err, tc) | ||
59 | { | ||
60 | atf_tc_set_md_var(tc, "descr", "Checks errors from write(2)"); | ||
61 | } | ||
62 | |||
63 | ATF_TC_BODY(write_err, tc) | ||
64 | { | ||
65 | char rbuf[3] = { 'a', 'b', 'c' }; | ||
66 | char wbuf[3] = { 'x', 'y', 'z' }; | ||
67 | int fd; | ||
68 | |||
69 | errno = 0; | ||
70 | ATF_REQUIRE_ERRNO(EBADF, write(-1, wbuf, sizeof(wbuf)) == -1); | ||
71 | |||
72 | fd = open(path, O_RDWR | O_CREAT, 0600); | ||
73 | |||
74 | if (fd >= 0) { | ||
75 | |||
76 | errno = 0; | ||
77 | ATF_REQUIRE_ERRNO(0, write(fd, wbuf, 3) == 3); | ||
78 | |||
79 | errno = 0; | ||
80 | ATF_REQUIRE_ERRNO(EINVAL, write(fd, wbuf, SIZE_MAX) == -1); | ||
81 | |||
82 | errno = 0; | ||
83 | ATF_REQUIRE_ERRNO(EFAULT, write(fd, (void *)-1, 1) == -1); | ||
84 | |||
85 | /* | ||
86 | * Check that the above bogus write(2) | ||
87 | * calls did not corrupt the file. | ||
88 | */ | ||
89 | ATF_REQUIRE(lseek(fd, 0, SEEK_SET) == 0); | ||
90 | ATF_REQUIRE(read(fd, rbuf, 3) == 3); | ||
91 | ATF_REQUIRE(memcmp(rbuf, wbuf, 3) == 0); | ||
92 | |||
93 | (void)close(fd); | ||
94 | (void)unlink(path); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | ATF_TC_CLEANUP(write_err, tc) | ||
99 | { | ||
100 | (void)unlink(path); | ||
101 | } | ||
102 | |||
103 | ATF_TC(write_pipe); | ||
104 | ATF_TC_HEAD(write_pipe, tc) | ||
105 | { | ||
106 | atf_tc_set_md_var(tc, "descr", "Checks for EPIPE from write(2)"); | ||
107 | } | ||
108 | |||
109 | ATF_TC_BODY(write_pipe, tc) | ||
110 | { | ||
111 | int fds[2]; | ||
112 | |||
113 | ATF_REQUIRE(pipe(fds) == 0); | ||
114 | ATF_REQUIRE(signal(SIGPIPE, sighandler) == 0); | ||
115 | |||
116 | ATF_REQUIRE(write(fds[1], "x", 1) != -1); | ||
117 | ATF_REQUIRE(close(fds[0]) == 0); | ||
118 | |||
119 | errno = 0; | ||
120 | fail = true; | ||
121 | |||
122 | if (write(fds[1], "x", 1) != -1 || errno != EPIPE) | ||
123 | atf_tc_fail_nonfatal("expected EPIPE but write(2) succeeded"); | ||
124 | |||
125 | ATF_REQUIRE(close(fds[1]) == 0); | ||
126 | |||
127 | if (fail != false) | ||
128 | atf_tc_fail_nonfatal("SIGPIPE was not raised"); | ||
129 | } | ||
130 | |||
131 | ATF_TC_WITH_CLEANUP(write_pos); | ||
132 | ATF_TC_HEAD(write_pos, tc) | ||
133 | { | ||
134 | atf_tc_set_md_var(tc, "descr", "Checks that write(2) " | ||
135 | "updates the file position"); | ||
136 | } | ||
137 | |||
138 | ATF_TC_BODY(write_pos, tc) | ||
139 | { | ||
140 | const size_t n = 123; | ||
141 | size_t i; | ||
142 | int fd; | ||
143 | |||
144 | fd = open(path, O_RDWR | O_CREAT, 0600); | ||
145 | ATF_REQUIRE(fd >= 0); | ||
146 | |||
147 | for (i = 0; i < n; i++) { | ||
148 | ATF_REQUIRE(write(fd, "x", 1) == 1); | ||
149 | ATF_REQUIRE(lseek(fd, 0, SEEK_CUR) == (off_t)(i + 1)); | ||
150 | } | ||
151 | |||
152 | ATF_REQUIRE(close(fd) == 0); | ||
153 | ATF_REQUIRE(unlink(path) == 0); | ||
154 | } | ||
155 | |||
156 | ATF_TC_CLEANUP(write_pos, tc) | ||
157 | { | ||
158 | (void)unlink(path); | ||
159 | } | ||
160 | |||
161 | ATF_TC_WITH_CLEANUP(write_ret); | ||
162 | ATF_TC_HEAD(write_ret, tc) | ||
163 | { | ||
164 | atf_tc_set_md_var(tc, "descr", "Checks return values from write(2)"); | ||
165 | } | ||
166 | |||
167 | ATF_TC_BODY(write_ret, tc) | ||
168 | { | ||
169 | const size_t n = 99; | ||
170 | char buf[123]; | ||
171 | size_t i, j; | ||
172 | int fd; | ||
173 | |||
174 | fd = open(path, O_WRONLY | O_CREAT, 0600); | ||
175 | ATF_REQUIRE(fd >= 0); | ||
176 | |||
177 | (void)memset(buf, 'x', sizeof(buf)); | ||
178 | |||
179 | for (i = j = 0; i < n; i++) | ||
180 | j += write(fd, buf, sizeof(buf)); | ||
181 | |||
182 | if (j != n * 123) | ||
183 | atf_tc_fail("inconsistent return values from write(2)"); | ||
184 | |||
185 | (void)close(fd); | ||
186 | (void)unlink(path); | ||
187 | } | ||
188 | |||
189 | ATF_TC_CLEANUP(write_ret, tc) | ||
190 | { | ||
191 | (void)unlink(path); | ||
192 | } | ||
193 | |||
194 | ATF_TC(writev_iovmax); | ||
195 | ATF_TC_HEAD(writev_iovmax, tc) | ||
196 | { | ||
197 | atf_tc_set_md_var(tc, "timeout", "10"); | ||
198 | atf_tc_set_md_var(tc, "descr", | ||
199 | "Checks that file descriptor is properly FILE_UNUSE()d " | ||
200 | "when iovcnt is greater than IOV_MAX"); | ||
201 | } | ||
202 | |||
203 | ATF_TC_BODY(writev_iovmax, tc) | ||
204 | { | ||
205 | ssize_t retval; | ||
206 | |||
207 | (void)printf("Calling writev(2, NULL, IOV_MAX + 1)...\n"); | ||
208 | |||
209 | errno = 0; | ||
210 | retval = writev(2, NULL, IOV_MAX + 1); | ||
211 | |||
212 | ATF_REQUIRE_EQ_MSG(retval, -1, "got: %zd", retval); | ||
213 | ATF_REQUIRE_EQ_MSG(errno, EINVAL, "got: %s", strerror(errno)); | ||
214 | } | ||
215 | |||
216 | ATF_TC(write_fault); | ||
217 | |||
218 | ATF_TC_HEAD(write_fault, tc) | ||
219 | { | ||
220 | atf_tc_set_md_var(tc, "descr", | ||
221 | "Check that writing to non-permitted space returns EFAULT"); | ||
222 | } | ||
223 | |||
224 | #define SIZE 8192 | ||
225 | |||
226 | ATF_TC_BODY(write_fault, tc) | ||
227 | { | ||
228 | int fd[2]; | ||
229 | ATF_REQUIRE(pipe(fd) != -1); | ||
230 | // Can't use /dev/null cause it doesn't access the buffer. | ||
231 | |||
232 | void *map = mmap(NULL, SIZE, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); | ||
233 | ATF_REQUIRE(map != MAP_FAILED); | ||
234 | |||
235 | ssize_t retval = write(fd[1], map, SIZE); | ||
236 | |||
237 | ATF_REQUIRE_EQ_MSG(retval, -1, "got: %zd", retval); | ||
238 | ATF_REQUIRE_EQ_MSG(errno, EFAULT, "got: %s", strerror(errno)); | ||
239 | |||
240 | munmap(map, SIZE); | ||
241 | close(fd[0]); | ||
242 | close(fd[1]); | ||
243 | } | ||
244 | |||
245 | ATF_TC(read_fault); | ||
246 | |||
247 | ATF_TC_HEAD(read_fault, tc) | ||
248 | { | ||
249 | atf_tc_set_md_var(tc, "descr", | ||
250 | "Check that reading from non-permitted space returns EFAULT"); | ||
251 | } | ||
252 | |||
253 | ATF_TC_BODY(read_fault, tc) | ||
254 | { | ||
255 | int fd = open(_PATH_DEVZERO, O_RDONLY); | ||
256 | ATF_REQUIRE(fd != -1); | ||
257 | |||
258 | void *map = mmap(NULL, SIZE, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); | ||
259 | ATF_REQUIRE(map != MAP_FAILED); | ||
260 | |||
261 | ssize_t retval = read(fd, map, SIZE); | ||
262 | |||
263 | ATF_REQUIRE_EQ_MSG(retval, -1, "got: %zd", retval); | ||
264 | ATF_REQUIRE_EQ_MSG(errno, EFAULT, "got: %s", strerror(errno)); | ||
265 | |||
266 | munmap(map, SIZE); | ||
267 | close(fd); | ||
268 | } | ||
269 | |||
270 | ATF_TP_ADD_TCS(tp) | ||
271 | { | ||
272 | |||
273 | ATF_TP_ADD_TC(tp, write_err); | ||
274 | ATF_TP_ADD_TC(tp, write_pipe); | ||
275 | ATF_TP_ADD_TC(tp, write_pos); | ||
276 | ATF_TP_ADD_TC(tp, write_ret); | ||
277 | ATF_TP_ADD_TC(tp, writev_iovmax); | ||
278 | ATF_TP_ADD_TC(tp, write_fault); | ||
279 | ATF_TP_ADD_TC(tp, read_fault); | ||
280 | |||
281 | return atf_no_error(); | ||
282 | } | ||
diff --git a/src/regress/lib/libc/telldir/Makefile b/src/regress/lib/libc/telldir/Makefile deleted file mode 100644 index 728ae90e1e..0000000000 --- a/src/regress/lib/libc/telldir/Makefile +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2013/11/03 00:20:24 schwarze Exp $ | ||
2 | |||
3 | PROG = telldir | ||
4 | SRCS = utils.c shortseek.c telldir.c main.c | ||
5 | |||
6 | cleandir: | ||
7 | rm -rf d | ||
8 | |||
9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/telldir/main.c b/src/regress/lib/libc/telldir/main.c deleted file mode 100644 index 23ffa65dbf..0000000000 --- a/src/regress/lib/libc/telldir/main.c +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | /* $OpenBSD: main.c,v 1.1 2013/11/03 00:20:24 schwarze Exp $ */ | ||
2 | |||
3 | /* Written by Ingo Schwarze, 2013, Public domain. */ | ||
4 | |||
5 | void shortseek(void); | ||
6 | void longseek(void); | ||
7 | |||
8 | int | ||
9 | main(void) | ||
10 | { | ||
11 | shortseek(); | ||
12 | longseek(); | ||
13 | return(0); | ||
14 | } | ||
diff --git a/src/regress/lib/libc/telldir/shortseek.c b/src/regress/lib/libc/telldir/shortseek.c deleted file mode 100644 index 9b2141ab4c..0000000000 --- a/src/regress/lib/libc/telldir/shortseek.c +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | /* $OpenBSD: shortseek.c,v 1.1 2013/11/03 00:20:24 schwarze Exp $ */ | ||
2 | |||
3 | /* Written by Otto Moerbeek, 2006, Public domain. */ | ||
4 | /* Modified by Ingo Schwarze, 2013, Public domain. */ | ||
5 | |||
6 | #include <sys/types.h> | ||
7 | #include <dirent.h> | ||
8 | #include <err.h> | ||
9 | #include <limits.h> | ||
10 | #include <stdio.h> | ||
11 | #include <string.h> | ||
12 | |||
13 | #include "utils.h" | ||
14 | |||
15 | #define NFILES 5 | ||
16 | |||
17 | static void | ||
18 | shortloop(DIR *dp, int iend, int iback) | ||
19 | { | ||
20 | struct dirent *f; | ||
21 | char fend[PATH_MAX], fback[PATH_MAX]; | ||
22 | long pos, t, remember = -1; | ||
23 | int i; | ||
24 | |||
25 | rewinddir(dp); | ||
26 | snprintf(fend, sizeof fend, "%d", iend); | ||
27 | snprintf(fback, sizeof fback, "%d", iback); | ||
28 | |||
29 | /* Scan to iend, remember where iback is. */ | ||
30 | |||
31 | for (;;) { | ||
32 | pos = telldir(dp); | ||
33 | f = readdir(dp); | ||
34 | if (f == NULL) | ||
35 | errx(1, "file %s not found", fend); | ||
36 | if (strcmp(fback, f->d_name) == 0) | ||
37 | remember = pos; | ||
38 | if (strcmp(fend, f->d_name) == 0) | ||
39 | break; | ||
40 | } | ||
41 | if (remember == -1) | ||
42 | errx(1, "file %s not found", fback); | ||
43 | |||
44 | /* Go back to iback, checking seekdir, telldir and readdir. */ | ||
45 | |||
46 | seekdir(dp, remember); | ||
47 | if ((t = telldir(dp)) != remember) | ||
48 | errx(1, "tell after seek %s %ld != %ld", fback, t, remember); | ||
49 | if ((t = telldir(dp)) != remember) | ||
50 | errx(1, "tell after tell %s %ld != %ld", fback, t, remember); | ||
51 | f = readdir(dp); | ||
52 | if (f == NULL) | ||
53 | errx(1, "readdir %s at %ld", fback, remember); | ||
54 | |||
55 | if (strcmp(f->d_name, fback)) | ||
56 | errx(1, "name mismatch: %s != %s", f->d_name, fback); | ||
57 | |||
58 | /* Check that readdir can iterate the remaining files. */ | ||
59 | |||
60 | for (i = iback + 1; i < NFILES; i++) { | ||
61 | f = readdir(dp); | ||
62 | if (f == NULL) | ||
63 | errx(1, "readdir %i failed", i); | ||
64 | } | ||
65 | |||
66 | /* Check that readdir stops at the right place. */ | ||
67 | |||
68 | f = readdir(dp); | ||
69 | if (f != NULL) | ||
70 | errx(1, "readdir %i returned %s", NFILES, f->d_name); | ||
71 | } | ||
72 | |||
73 | void | ||
74 | shortseek(void) | ||
75 | { | ||
76 | DIR *dp; | ||
77 | int iend, iback; | ||
78 | |||
79 | createfiles(NFILES); | ||
80 | |||
81 | dp = opendir("d"); | ||
82 | if (dp == NULL) | ||
83 | err(1, "shortseek: opendir"); | ||
84 | |||
85 | for (iend = 0; iend < NFILES; iend++) | ||
86 | for (iback = 0; iback <= iend; iback++) | ||
87 | shortloop(dp, iend, iback); | ||
88 | |||
89 | closedir(dp); | ||
90 | delfiles(); | ||
91 | } | ||
diff --git a/src/regress/lib/libc/telldir/telldir.c b/src/regress/lib/libc/telldir/telldir.c deleted file mode 100644 index d2879cc701..0000000000 --- a/src/regress/lib/libc/telldir/telldir.c +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /* $OpenBSD: telldir.c,v 1.4 2013/11/03 00:20:24 schwarze Exp $ */ | ||
2 | |||
3 | /* Written by Otto Moerbeek, 2006, Public domain. */ | ||
4 | |||
5 | #include <sys/types.h> | ||
6 | #include <dirent.h> | ||
7 | #include <err.h> | ||
8 | #include <limits.h> | ||
9 | #include <stdio.h> | ||
10 | #include <string.h> | ||
11 | |||
12 | #include "utils.h" | ||
13 | |||
14 | #define NFILES 1000 | ||
15 | |||
16 | static void | ||
17 | longloop(DIR *dp, int i) | ||
18 | { | ||
19 | struct dirent *f; | ||
20 | char file[PATH_MAX]; | ||
21 | long pos, t, remember = -1; | ||
22 | |||
23 | rewinddir(dp); | ||
24 | snprintf(file, sizeof file, "%d", i); | ||
25 | |||
26 | /* Scan through all files, remember where file i is. */ | ||
27 | |||
28 | for (;;) { | ||
29 | pos = telldir(dp); | ||
30 | f = readdir(dp); | ||
31 | if (f == NULL) | ||
32 | break; | ||
33 | if (strcmp(file, f->d_name) == 0) | ||
34 | remember = pos; | ||
35 | } | ||
36 | if (remember == -1) | ||
37 | errx(1, "remember %s", file); | ||
38 | |||
39 | /* Go back to i, checking seekdir, telldir and readdir. */ | ||
40 | |||
41 | seekdir(dp, remember); | ||
42 | if ((t = telldir(dp)) != remember) | ||
43 | errx(1, "tell after seek %s %ld != %ld", file, t, remember); | ||
44 | if ((t = telldir(dp)) != remember) | ||
45 | errx(1, "tell after tell %s %ld != %ld", file, t, remember); | ||
46 | f = readdir(dp); | ||
47 | if (f == NULL) | ||
48 | errx(1, "readdir %s at %ld", file, remember); | ||
49 | |||
50 | if (strcmp(f->d_name, file) != 0) | ||
51 | errx(1, "name mismatch: %s != %s", f->d_name, file); | ||
52 | } | ||
53 | |||
54 | void | ||
55 | longseek(void) | ||
56 | { | ||
57 | DIR *dp; | ||
58 | int i; | ||
59 | |||
60 | createfiles(NFILES); | ||
61 | |||
62 | dp = opendir("d"); | ||
63 | if (dp == NULL) | ||
64 | err(1, "longseek: opendir"); | ||
65 | |||
66 | for (i = 0; i < NFILES; i++) | ||
67 | longloop(dp, (i + NFILES/2) % NFILES); | ||
68 | |||
69 | closedir(dp); | ||
70 | delfiles(); | ||
71 | } | ||
diff --git a/src/regress/lib/libc/telldir/utils.c b/src/regress/lib/libc/telldir/utils.c deleted file mode 100644 index 7fb0401d70..0000000000 --- a/src/regress/lib/libc/telldir/utils.c +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | /* $OpenBSD: utils.c,v 1.2 2017/07/27 15:08:37 bluhm Exp $ */ | ||
2 | |||
3 | /* Written by Otto Moerbeek, 2006, Public domain. */ | ||
4 | |||
5 | #include <sys/types.h> | ||
6 | #include <sys/stat.h> | ||
7 | #include <dirent.h> | ||
8 | #include <err.h> | ||
9 | #include <fcntl.h> | ||
10 | #include <limits.h> | ||
11 | #include <stdio.h> | ||
12 | #include <string.h> | ||
13 | #include <unistd.h> | ||
14 | |||
15 | #include "utils.h" | ||
16 | |||
17 | void | ||
18 | createfiles(int nfiles) | ||
19 | { | ||
20 | int i, fd; | ||
21 | char file[PATH_MAX]; | ||
22 | |||
23 | mkdir("d", 0755); | ||
24 | for (i = 0; i < nfiles; i++) { | ||
25 | snprintf(file, sizeof file, "d/%d", i); | ||
26 | if ((fd = open(file, O_CREAT | O_WRONLY, 0600)) == -1) | ||
27 | err(1, "open %s", file); | ||
28 | close(fd); | ||
29 | } | ||
30 | } | ||
31 | |||
32 | void | ||
33 | delfiles(void) | ||
34 | { | ||
35 | DIR *dp; | ||
36 | struct dirent *f; | ||
37 | char file[PATH_MAX]; | ||
38 | |||
39 | dp = opendir("d"); | ||
40 | if (dp == NULL) | ||
41 | err(1, "opendir"); | ||
42 | while ((f = readdir(dp))) { | ||
43 | if (strcmp(f->d_name, ".") == 0 || | ||
44 | strcmp(f->d_name, "..") == 0) | ||
45 | continue; | ||
46 | snprintf(file, sizeof file, "d/%s", f->d_name); | ||
47 | if (unlink(file) == -1) | ||
48 | err(1, "unlink %s", f->d_name); | ||
49 | } | ||
50 | closedir(dp); | ||
51 | if (rmdir("d") == -1) | ||
52 | err(1, "rmdir"); | ||
53 | } | ||
diff --git a/src/regress/lib/libc/telldir/utils.h b/src/regress/lib/libc/telldir/utils.h deleted file mode 100644 index 74ffcd4641..0000000000 --- a/src/regress/lib/libc/telldir/utils.h +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | /* $OpenBSD: utils.h,v 1.1 2013/11/03 00:20:24 schwarze Exp $ */ | ||
2 | |||
3 | /* Written by Ingo Schwarze, 2013, Public domain. */ | ||
4 | |||
5 | void createfiles(int); | ||
6 | void delfiles(void); | ||
diff --git a/src/regress/lib/libc/time/Makefile b/src/regress/lib/libc/time/Makefile deleted file mode 100644 index 1fc8541dc8..0000000000 --- a/src/regress/lib/libc/time/Makefile +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2022/11/06 12:59:46 beck Exp $ | ||
2 | |||
3 | SUBDIR+=strptime | ||
4 | SUBDIR+=time_conversion | ||
5 | |||
6 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/time/strptime/Makefile b/src/regress/lib/libc/time/strptime/Makefile deleted file mode 100644 index 1e1565ced4..0000000000 --- a/src/regress/lib/libc/time/strptime/Makefile +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2012/12/16 18:28:53 jasper Exp $ | ||
2 | |||
3 | PROG= strptime_test | ||
4 | SRCS= main.c | ||
5 | CLEANFILES+= got | ||
6 | |||
7 | REGRESS_TARGETS=do-reg | ||
8 | do-reg: ${PROG} | ||
9 | ./${PROG} < ${.CURDIR}/tests > got | ||
10 | diff -u ${.CURDIR}/expected got | ||
11 | |||
12 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/time/strptime/expected b/src/regress/lib/libc/time/strptime/expected deleted file mode 100644 index 21c95de7f9..0000000000 --- a/src/regress/lib/libc/time/strptime/expected +++ /dev/null | |||
@@ -1,346 +0,0 @@ | |||
1 | --- ctime --- 1 | ||
2 | succeeded | ||
3 | 46 27 23 20 0 98 2 19 | ||
4 | |||
5 | --- ctime --- 2 | ||
6 | succeeded | ||
7 | 46 27 23 20 0 98 2 19 | ||
8 | |||
9 | --- ctime --- 3 | ||
10 | succeeded | ||
11 | 46 27 23 20 0 98 2 19 | ||
12 | |||
13 | --- %a --- 1 | ||
14 | succeeded | ||
15 | -1 -1 -1 -1 -1 -1 0 -1 | ||
16 | |||
17 | --- %a --- 2 | ||
18 | succeeded | ||
19 | -1 -1 -1 -1 -1 -1 0 -1 | ||
20 | |||
21 | --- %a --- 3 | ||
22 | succeeded | ||
23 | -1 -1 -1 -1 -1 -1 1 -1 | ||
24 | |||
25 | --- %a --- 4 | ||
26 | succeeded | ||
27 | -1 -1 -1 -1 -1 -1 1 -1 | ||
28 | |||
29 | --- %a --- 5 | ||
30 | succeeded | ||
31 | -1 -1 -1 -1 -1 -1 2 -1 | ||
32 | |||
33 | --- %a --- 6 | ||
34 | succeeded | ||
35 | -1 -1 -1 -1 -1 -1 2 -1 | ||
36 | |||
37 | --- %a --- 7 | ||
38 | succeeded | ||
39 | -1 -1 -1 -1 -1 -1 3 -1 | ||
40 | |||
41 | --- %a --- 8 | ||
42 | succeeded | ||
43 | -1 -1 -1 -1 -1 -1 3 -1 | ||
44 | |||
45 | --- %a --- 9 | ||
46 | succeeded | ||
47 | -1 -1 -1 -1 -1 -1 4 -1 | ||
48 | |||
49 | --- %a --- 10 | ||
50 | succeeded | ||
51 | -1 -1 -1 -1 -1 -1 4 -1 | ||
52 | |||
53 | --- %a --- 11 | ||
54 | succeeded | ||
55 | -1 -1 -1 -1 -1 -1 5 -1 | ||
56 | |||
57 | --- %a --- 12 | ||
58 | succeeded | ||
59 | -1 -1 -1 -1 -1 -1 5 -1 | ||
60 | |||
61 | --- %a --- 13 | ||
62 | succeeded | ||
63 | -1 -1 -1 -1 -1 -1 6 -1 | ||
64 | |||
65 | --- %a --- 14 | ||
66 | succeeded | ||
67 | -1 -1 -1 -1 -1 -1 6 -1 | ||
68 | |||
69 | --- %a --- 15 | ||
70 | succeeded | ||
71 | -1 -1 -1 -1 -1 -1 6 -1 | ||
72 | urn | ||
73 | |||
74 | --- %a --- 16 | ||
75 | failed | ||
76 | --- %A --- 1 | ||
77 | succeeded | ||
78 | -1 -1 -1 -1 -1 -1 0 -1 | ||
79 | |||
80 | --- %A --- 2 | ||
81 | succeeded | ||
82 | -1 -1 -1 -1 -1 -1 0 -1 | ||
83 | |||
84 | --- %A --- 3 | ||
85 | succeeded | ||
86 | -1 -1 -1 -1 -1 -1 1 -1 | ||
87 | |||
88 | --- %A --- 4 | ||
89 | succeeded | ||
90 | -1 -1 -1 -1 -1 -1 1 -1 | ||
91 | |||
92 | --- %A --- 5 | ||
93 | succeeded | ||
94 | -1 -1 -1 -1 -1 -1 2 -1 | ||
95 | |||
96 | --- %A --- 6 | ||
97 | succeeded | ||
98 | -1 -1 -1 -1 -1 -1 2 -1 | ||
99 | |||
100 | --- %A --- 7 | ||
101 | succeeded | ||
102 | -1 -1 -1 -1 -1 -1 3 -1 | ||
103 | |||
104 | --- %A --- 8 | ||
105 | succeeded | ||
106 | -1 -1 -1 -1 -1 -1 3 -1 | ||
107 | |||
108 | --- %A --- 9 | ||
109 | succeeded | ||
110 | -1 -1 -1 -1 -1 -1 4 -1 | ||
111 | |||
112 | --- %A --- 10 | ||
113 | succeeded | ||
114 | -1 -1 -1 -1 -1 -1 4 -1 | ||
115 | |||
116 | --- %A --- 11 | ||
117 | succeeded | ||
118 | -1 -1 -1 -1 -1 -1 5 -1 | ||
119 | |||
120 | --- %A --- 12 | ||
121 | succeeded | ||
122 | -1 -1 -1 -1 -1 -1 5 -1 | ||
123 | |||
124 | --- %A --- 13 | ||
125 | succeeded | ||
126 | -1 -1 -1 -1 -1 -1 6 -1 | ||
127 | |||
128 | --- %A --- 14 | ||
129 | succeeded | ||
130 | -1 -1 -1 -1 -1 -1 6 -1 | ||
131 | |||
132 | --- %A --- 15 | ||
133 | succeeded | ||
134 | -1 -1 -1 -1 -1 -1 6 -1 | ||
135 | urn | ||
136 | |||
137 | --- %A --- 16 | ||
138 | failed | ||
139 | --- %b --- 1 | ||
140 | succeeded | ||
141 | -1 -1 -1 -1 0 -1 -1 -1 | ||
142 | |||
143 | --- %b --- 2 | ||
144 | succeeded | ||
145 | -1 -1 -1 -1 0 -1 -1 -1 | ||
146 | |||
147 | --- %b --- 3 | ||
148 | succeeded | ||
149 | -1 -1 -1 -1 1 -1 -1 -1 | ||
150 | |||
151 | --- %b --- 4 | ||
152 | succeeded | ||
153 | -1 -1 -1 -1 1 -1 -1 -1 | ||
154 | |||
155 | --- %b --- 5 | ||
156 | succeeded | ||
157 | -1 -1 -1 -1 2 -1 -1 -1 | ||
158 | |||
159 | --- %b --- 6 | ||
160 | succeeded | ||
161 | -1 -1 -1 -1 2 -1 -1 -1 | ||
162 | |||
163 | --- %b --- 7 | ||
164 | succeeded | ||
165 | -1 -1 -1 -1 3 -1 -1 -1 | ||
166 | |||
167 | --- %b --- 8 | ||
168 | succeeded | ||
169 | -1 -1 -1 -1 3 -1 -1 -1 | ||
170 | |||
171 | --- %b --- 9 | ||
172 | succeeded | ||
173 | -1 -1 -1 -1 4 -1 -1 -1 | ||
174 | |||
175 | --- %b --- 10 | ||
176 | succeeded | ||
177 | -1 -1 -1 -1 5 -1 -1 -1 | ||
178 | |||
179 | --- %b --- 11 | ||
180 | succeeded | ||
181 | -1 -1 -1 -1 5 -1 -1 -1 | ||
182 | |||
183 | --- %b --- 12 | ||
184 | succeeded | ||
185 | -1 -1 -1 -1 6 -1 -1 -1 | ||
186 | |||
187 | --- %b --- 13 | ||
188 | succeeded | ||
189 | -1 -1 -1 -1 6 -1 -1 -1 | ||
190 | |||
191 | --- %b --- 14 | ||
192 | succeeded | ||
193 | -1 -1 -1 -1 7 -1 -1 -1 | ||
194 | |||
195 | --- %b --- 15 | ||
196 | succeeded | ||
197 | -1 -1 -1 -1 7 -1 -1 -1 | ||
198 | |||
199 | --- %b --- 16 | ||
200 | succeeded | ||
201 | -1 -1 -1 -1 8 -1 -1 -1 | ||
202 | |||
203 | --- %b --- 17 | ||
204 | succeeded | ||
205 | -1 -1 -1 -1 8 -1 -1 -1 | ||
206 | |||
207 | --- %b --- 18 | ||
208 | succeeded | ||
209 | -1 -1 -1 -1 9 -1 -1 -1 | ||
210 | |||
211 | --- %b --- 19 | ||
212 | succeeded | ||
213 | -1 -1 -1 -1 9 -1 -1 -1 | ||
214 | |||
215 | --- %b --- 20 | ||
216 | succeeded | ||
217 | -1 -1 -1 -1 10 -1 -1 -1 | ||
218 | |||
219 | --- %b --- 21 | ||
220 | succeeded | ||
221 | -1 -1 -1 -1 10 -1 -1 -1 | ||
222 | |||
223 | --- %b --- 22 | ||
224 | succeeded | ||
225 | -1 -1 -1 -1 11 -1 -1 -1 | ||
226 | |||
227 | --- %b --- 23 | ||
228 | succeeded | ||
229 | -1 -1 -1 -1 11 -1 -1 -1 | ||
230 | |||
231 | --- %b --- 25 | ||
232 | succeeded | ||
233 | -1 -1 -1 -1 4 -1 -1 -1 | ||
234 | or | ||
235 | |||
236 | --- %b --- 24 | ||
237 | succeeded | ||
238 | -1 -1 -1 -1 2 -1 -1 -1 | ||
239 | s | ||
240 | |||
241 | --- %b --- 26 | ||
242 | failed | ||
243 | --- %B --- 1 | ||
244 | succeeded | ||
245 | -1 -1 -1 -1 0 -1 -1 -1 | ||
246 | |||
247 | --- %B --- 2 | ||
248 | succeeded | ||
249 | -1 -1 -1 -1 0 -1 -1 -1 | ||
250 | |||
251 | --- %B --- 3 | ||
252 | succeeded | ||
253 | -1 -1 -1 -1 1 -1 -1 -1 | ||
254 | |||
255 | --- %B --- 4 | ||
256 | succeeded | ||
257 | -1 -1 -1 -1 1 -1 -1 -1 | ||
258 | |||
259 | --- %B --- 5 | ||
260 | succeeded | ||
261 | -1 -1 -1 -1 2 -1 -1 -1 | ||
262 | |||
263 | --- %B --- 6 | ||
264 | succeeded | ||
265 | -1 -1 -1 -1 2 -1 -1 -1 | ||
266 | |||
267 | --- %B --- 7 | ||
268 | succeeded | ||
269 | -1 -1 -1 -1 3 -1 -1 -1 | ||
270 | |||
271 | --- %B --- 8 | ||
272 | succeeded | ||
273 | -1 -1 -1 -1 3 -1 -1 -1 | ||
274 | |||
275 | --- %B --- 9 | ||
276 | succeeded | ||
277 | -1 -1 -1 -1 4 -1 -1 -1 | ||
278 | |||
279 | --- %B --- 10 | ||
280 | succeeded | ||
281 | -1 -1 -1 -1 5 -1 -1 -1 | ||
282 | |||
283 | --- %B --- 11 | ||
284 | succeeded | ||
285 | -1 -1 -1 -1 5 -1 -1 -1 | ||
286 | |||
287 | --- %B --- 12 | ||
288 | succeeded | ||
289 | -1 -1 -1 -1 6 -1 -1 -1 | ||
290 | |||
291 | --- %B --- 13 | ||
292 | succeeded | ||
293 | -1 -1 -1 -1 6 -1 -1 -1 | ||
294 | |||
295 | --- %B --- 14 | ||
296 | succeeded | ||
297 | -1 -1 -1 -1 7 -1 -1 -1 | ||
298 | |||
299 | --- %B --- 15 | ||
300 | succeeded | ||
301 | -1 -1 -1 -1 7 -1 -1 -1 | ||
302 | |||
303 | --- %B --- 16 | ||
304 | succeeded | ||
305 | -1 -1 -1 -1 8 -1 -1 -1 | ||
306 | |||
307 | --- %B --- 17 | ||
308 | succeeded | ||
309 | -1 -1 -1 -1 8 -1 -1 -1 | ||
310 | |||
311 | --- %B --- 18 | ||
312 | succeeded | ||
313 | -1 -1 -1 -1 9 -1 -1 -1 | ||
314 | |||
315 | --- %B --- 19 | ||
316 | succeeded | ||
317 | -1 -1 -1 -1 9 -1 -1 -1 | ||
318 | |||
319 | --- %B --- 20 | ||
320 | succeeded | ||
321 | -1 -1 -1 -1 10 -1 -1 -1 | ||
322 | |||
323 | --- %B --- 21 | ||
324 | succeeded | ||
325 | -1 -1 -1 -1 10 -1 -1 -1 | ||
326 | |||
327 | --- %B --- 22 | ||
328 | succeeded | ||
329 | -1 -1 -1 -1 11 -1 -1 -1 | ||
330 | |||
331 | --- %B --- 23 | ||
332 | succeeded | ||
333 | -1 -1 -1 -1 11 -1 -1 -1 | ||
334 | |||
335 | --- %B --- 25 | ||
336 | succeeded | ||
337 | -1 -1 -1 -1 4 -1 -1 -1 | ||
338 | or | ||
339 | |||
340 | --- %B --- 24 | ||
341 | succeeded | ||
342 | -1 -1 -1 -1 2 -1 -1 -1 | ||
343 | s | ||
344 | |||
345 | --- %B --- 26 | ||
346 | failed | ||
diff --git a/src/regress/lib/libc/time/strptime/main.c b/src/regress/lib/libc/time/strptime/main.c deleted file mode 100644 index c4e06a9b59..0000000000 --- a/src/regress/lib/libc/time/strptime/main.c +++ /dev/null | |||
@@ -1,110 +0,0 @@ | |||
1 | /* $OpenBSD: main.c,v 1.2 2008/06/26 05:42:05 ray Exp $ */ | ||
2 | /* $NetBSD: main.c,v 1.4 2002/02/21 07:38:18 itojun Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
27 | * POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | #include <err.h> | ||
30 | #include <stdio.h> | ||
31 | #include <stdlib.h> | ||
32 | #include <string.h> | ||
33 | #include <time.h> | ||
34 | |||
35 | int main(int, char *[]); | ||
36 | void die(void); | ||
37 | |||
38 | void | ||
39 | die(void) | ||
40 | { | ||
41 | |||
42 | if (ferror(stdin)) | ||
43 | err(1, "fgetln"); | ||
44 | else | ||
45 | errx(1, "input is truncated"); | ||
46 | } | ||
47 | |||
48 | int | ||
49 | main(int argc, char *argv[]) | ||
50 | { | ||
51 | char *p, *title, *buf, *format; | ||
52 | size_t len; | ||
53 | struct tm tm; | ||
54 | |||
55 | for (;;) { | ||
56 | p = fgetln(stdin, &len); | ||
57 | if (p == 0) | ||
58 | die(); | ||
59 | title = malloc(len + 1); | ||
60 | memcpy(title, p, len); | ||
61 | title[len] = '\0'; | ||
62 | |||
63 | if (!strcmp(title, "EOF\n")) | ||
64 | return(0); | ||
65 | if (title[0] == '#' || title[0] == '\n') { | ||
66 | free(title); | ||
67 | continue; | ||
68 | } | ||
69 | |||
70 | p = fgetln(stdin, &len); | ||
71 | if (p == 0) | ||
72 | die(); | ||
73 | buf = malloc(len + 1); | ||
74 | memcpy(buf, p, len); | ||
75 | buf[len] = '\0'; | ||
76 | |||
77 | p = fgetln(stdin, &len); | ||
78 | if (p == 0) | ||
79 | die(); | ||
80 | format = malloc(len + 1); | ||
81 | memcpy(format, p, len); | ||
82 | format[len] = '\0'; | ||
83 | |||
84 | tm.tm_sec = -1; | ||
85 | tm.tm_min = -1; | ||
86 | tm.tm_hour = -1; | ||
87 | tm.tm_mday = -1; | ||
88 | tm.tm_mon = -1; | ||
89 | tm.tm_year = -1; | ||
90 | tm.tm_wday = -1; | ||
91 | tm.tm_yday = -1; | ||
92 | |||
93 | p = strptime(buf, format, &tm); | ||
94 | |||
95 | printf("%s", title); | ||
96 | if (p) { | ||
97 | printf("succeeded\n"); | ||
98 | printf("%d %d %d %d %d %d %d %d\n", | ||
99 | tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mday, | ||
100 | tm.tm_mon, tm.tm_year, tm.tm_wday, tm.tm_yday); | ||
101 | printf("%s\n", p); | ||
102 | } else { | ||
103 | printf("failed\n"); | ||
104 | } | ||
105 | |||
106 | free(title); | ||
107 | free(buf); | ||
108 | free(format); | ||
109 | } | ||
110 | } | ||
diff --git a/src/regress/lib/libc/time/strptime/tests b/src/regress/lib/libc/time/strptime/tests deleted file mode 100644 index d96393b2b7..0000000000 --- a/src/regress/lib/libc/time/strptime/tests +++ /dev/null | |||
@@ -1,267 +0,0 @@ | |||
1 | # some intial checks to make sure common things work | ||
2 | --- ctime --- 1 | ||
3 | Tue Jan 20 23:27:46 1998 | ||
4 | %a %b %d %T %Y | ||
5 | --- ctime --- 2 | ||
6 | Tue Jan 20 23:27:46 1998 | ||
7 | %a %b %d %H:%M:%S %Y | ||
8 | --- ctime --- 3 | ||
9 | Tue Jan 20 23:27:46 1998 | ||
10 | %c | ||
11 | |||
12 | # test some valid and invalid day names | ||
13 | --- %a --- 1 | ||
14 | Sun | ||
15 | %a | ||
16 | --- %a --- 2 | ||
17 | Sunday | ||
18 | %a | ||
19 | --- %a --- 3 | ||
20 | Mon | ||
21 | %a | ||
22 | --- %a --- 4 | ||
23 | Monday | ||
24 | %a | ||
25 | --- %a --- 5 | ||
26 | Tue | ||
27 | %a | ||
28 | --- %a --- 6 | ||
29 | Tuesday | ||
30 | %a | ||
31 | --- %a --- 7 | ||
32 | Wed | ||
33 | %a | ||
34 | --- %a --- 8 | ||
35 | Wednesday | ||
36 | %a | ||
37 | --- %a --- 9 | ||
38 | Thu | ||
39 | %a | ||
40 | --- %a --- 10 | ||
41 | Thursday | ||
42 | %a | ||
43 | --- %a --- 11 | ||
44 | Fri | ||
45 | %a | ||
46 | --- %a --- 12 | ||
47 | Friday | ||
48 | %a | ||
49 | --- %a --- 13 | ||
50 | Sat | ||
51 | %a | ||
52 | --- %a --- 14 | ||
53 | Saturday | ||
54 | %a | ||
55 | --- %a --- 15 | ||
56 | Saturn | ||
57 | %a | ||
58 | --- %a --- 16 | ||
59 | Moon | ||
60 | %a | ||
61 | --- %A --- 1 | ||
62 | Sun | ||
63 | %A | ||
64 | --- %A --- 2 | ||
65 | Sunday | ||
66 | %A | ||
67 | --- %A --- 3 | ||
68 | Mon | ||
69 | %A | ||
70 | --- %A --- 4 | ||
71 | Monday | ||
72 | %A | ||
73 | --- %A --- 5 | ||
74 | Tue | ||
75 | %A | ||
76 | --- %A --- 6 | ||
77 | Tuesday | ||
78 | %A | ||
79 | --- %A --- 7 | ||
80 | Wed | ||
81 | %A | ||
82 | --- %A --- 8 | ||
83 | Wednesday | ||
84 | %A | ||
85 | --- %A --- 9 | ||
86 | Thu | ||
87 | %A | ||
88 | --- %A --- 10 | ||
89 | Thursday | ||
90 | %A | ||
91 | --- %A --- 11 | ||
92 | Fri | ||
93 | %A | ||
94 | --- %A --- 12 | ||
95 | Friday | ||
96 | %A | ||
97 | --- %A --- 13 | ||
98 | Sat | ||
99 | %A | ||
100 | --- %A --- 14 | ||
101 | Saturday | ||
102 | %A | ||
103 | --- %A --- 15 | ||
104 | Saturn | ||
105 | %A | ||
106 | --- %A --- 16 | ||
107 | Moon | ||
108 | %A | ||
109 | |||
110 | # test some valid and invalid month names | ||
111 | --- %b --- 1 | ||
112 | Jan | ||
113 | %b | ||
114 | --- %b --- 2 | ||
115 | January | ||
116 | %b | ||
117 | --- %b --- 3 | ||
118 | Feb | ||
119 | %b | ||
120 | --- %b --- 4 | ||
121 | February | ||
122 | %b | ||
123 | --- %b --- 5 | ||
124 | Mar | ||
125 | %b | ||
126 | --- %b --- 6 | ||
127 | March | ||
128 | %b | ||
129 | --- %b --- 7 | ||
130 | Apr | ||
131 | %b | ||
132 | --- %b --- 8 | ||
133 | April | ||
134 | %b | ||
135 | --- %b --- 9 | ||
136 | May | ||
137 | %b | ||
138 | --- %b --- 10 | ||
139 | Jun | ||
140 | %b | ||
141 | --- %b --- 11 | ||
142 | June | ||
143 | %b | ||
144 | --- %b --- 12 | ||
145 | Jul | ||
146 | %b | ||
147 | --- %b --- 13 | ||
148 | July | ||
149 | %b | ||
150 | --- %b --- 14 | ||
151 | Aug | ||
152 | %b | ||
153 | --- %b --- 15 | ||
154 | August | ||
155 | %b | ||
156 | --- %b --- 16 | ||
157 | Sep | ||
158 | %b | ||
159 | --- %b --- 17 | ||
160 | September | ||
161 | %b | ||
162 | --- %b --- 18 | ||
163 | Oct | ||
164 | %b | ||
165 | --- %b --- 19 | ||
166 | October | ||
167 | %b | ||
168 | --- %b --- 20 | ||
169 | Nov | ||
170 | %b | ||
171 | --- %b --- 21 | ||
172 | November | ||
173 | %b | ||
174 | --- %b --- 22 | ||
175 | Dec | ||
176 | %b | ||
177 | --- %b --- 23 | ||
178 | December | ||
179 | %b | ||
180 | --- %b --- 25 | ||
181 | Mayor | ||
182 | %b | ||
183 | --- %b --- 24 | ||
184 | Mars | ||
185 | %b | ||
186 | --- %b --- 26 | ||
187 | Rover | ||
188 | %b | ||
189 | --- %B --- 1 | ||
190 | Jan | ||
191 | %B | ||
192 | --- %B --- 2 | ||
193 | January | ||
194 | %B | ||
195 | --- %B --- 3 | ||
196 | Feb | ||
197 | %B | ||
198 | --- %B --- 4 | ||
199 | February | ||
200 | %B | ||
201 | --- %B --- 5 | ||
202 | Mar | ||
203 | %B | ||
204 | --- %B --- 6 | ||
205 | March | ||
206 | %B | ||
207 | --- %B --- 7 | ||
208 | Apr | ||
209 | %B | ||
210 | --- %B --- 8 | ||
211 | April | ||
212 | %B | ||
213 | --- %B --- 9 | ||
214 | May | ||
215 | %B | ||
216 | --- %B --- 10 | ||
217 | Jun | ||
218 | %B | ||
219 | --- %B --- 11 | ||
220 | June | ||
221 | %B | ||
222 | --- %B --- 12 | ||
223 | Jul | ||
224 | %B | ||
225 | --- %B --- 13 | ||
226 | July | ||
227 | %B | ||
228 | --- %B --- 14 | ||
229 | Aug | ||
230 | %B | ||
231 | --- %B --- 15 | ||
232 | August | ||
233 | %B | ||
234 | --- %B --- 16 | ||
235 | Sep | ||
236 | %B | ||
237 | --- %B --- 17 | ||
238 | September | ||
239 | %B | ||
240 | --- %B --- 18 | ||
241 | Oct | ||
242 | %B | ||
243 | --- %B --- 19 | ||
244 | October | ||
245 | %B | ||
246 | --- %B --- 20 | ||
247 | Nov | ||
248 | %B | ||
249 | --- %B --- 21 | ||
250 | November | ||
251 | %B | ||
252 | --- %B --- 22 | ||
253 | Dec | ||
254 | %B | ||
255 | --- %B --- 23 | ||
256 | December | ||
257 | %B | ||
258 | --- %B --- 25 | ||
259 | Mayor | ||
260 | %B | ||
261 | --- %B --- 24 | ||
262 | Mars | ||
263 | %B | ||
264 | --- %B --- 26 | ||
265 | Rover | ||
266 | %B | ||
267 | EOF | ||
diff --git a/src/regress/lib/libc/time/time_conversion/Makefile b/src/regress/lib/libc/time/time_conversion/Makefile deleted file mode 100644 index a4d1950029..0000000000 --- a/src/regress/lib/libc/time/time_conversion/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2022/11/22 10:40:33 anton Exp $ | ||
2 | |||
3 | PROG= timetest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/time/time_conversion/timetest.c b/src/regress/lib/libc/time/time_conversion/timetest.c deleted file mode 100644 index 0706704ee1..0000000000 --- a/src/regress/lib/libc/time/time_conversion/timetest.c +++ /dev/null | |||
@@ -1,1847 +0,0 @@ | |||
1 | /* $OpenBSD: timetest.c,v 1.4 2023/04/13 11:32:06 mbuhl Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2022 Bob Beck <beck@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <sys/stat.h> | ||
20 | #include <sys/stdint.h> | ||
21 | #include <sys/types.h> | ||
22 | |||
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <string.h> | ||
26 | #include <time.h> | ||
27 | |||
28 | struct timetest { | ||
29 | char *descr; | ||
30 | char *timezone; | ||
31 | time_t time; | ||
32 | struct tm local_tm; | ||
33 | struct tm gmt_tm; | ||
34 | }; | ||
35 | |||
36 | static int tm_match(struct tm * tm1, struct tm *tm2) { | ||
37 | if (tm2->tm_year != tm1->tm_year || | ||
38 | tm2->tm_mon != tm1->tm_mon || | ||
39 | tm2->tm_mday != tm1->tm_mday || | ||
40 | tm2->tm_hour != tm1->tm_hour || | ||
41 | tm2->tm_min != tm1->tm_min || | ||
42 | tm2->tm_sec != tm1->tm_sec || | ||
43 | tm2->tm_wday != tm1->tm_wday || | ||
44 | tm2->tm_yday != tm1->tm_yday || | ||
45 | tm2->tm_yday != tm1->tm_yday || | ||
46 | tm2->tm_isdst != tm1->tm_isdst || | ||
47 | tm2->tm_gmtoff != tm1->tm_gmtoff || | ||
48 | strcmp(tm2->tm_zone, tm1->tm_zone) != 0) | ||
49 | return 0; | ||
50 | return 1; | ||
51 | } | ||
52 | |||
53 | struct timetest timetests[] = { | ||
54 | { | ||
55 | .descr="moon", | ||
56 | .timezone="posix/America/Edmonton", | ||
57 | .time=-16751025, | ||
58 | .local_tm= { | ||
59 | .tm_year=69, | ||
60 | .tm_mon=5, | ||
61 | .tm_mday=20, | ||
62 | .tm_hour=19, | ||
63 | .tm_min=56, | ||
64 | .tm_sec=15, | ||
65 | .tm_wday=5, | ||
66 | .tm_yday=170, | ||
67 | .tm_isdst=0, | ||
68 | .tm_gmtoff=-25200, | ||
69 | .tm_zone="MST" | ||
70 | }, | ||
71 | .gmt_tm= { | ||
72 | .tm_year=69, | ||
73 | .tm_mon=5, | ||
74 | .tm_mday=21, | ||
75 | .tm_hour=2, | ||
76 | .tm_min=56, | ||
77 | .tm_sec=15, | ||
78 | .tm_wday=6, | ||
79 | .tm_yday=171, | ||
80 | .tm_isdst=0, | ||
81 | .tm_gmtoff=0, | ||
82 | .tm_zone="GMT" | ||
83 | }, | ||
84 | }, | ||
85 | { | ||
86 | .descr="moon", | ||
87 | .timezone="right/UTC", | ||
88 | .time=-16751025, | ||
89 | .local_tm= { | ||
90 | .tm_year=69, | ||
91 | .tm_mon=5, | ||
92 | .tm_mday=21, | ||
93 | .tm_hour=2, | ||
94 | .tm_min=56, | ||
95 | .tm_sec=15, | ||
96 | .tm_wday=6, | ||
97 | .tm_yday=171, | ||
98 | .tm_isdst=0, | ||
99 | .tm_gmtoff=0, | ||
100 | .tm_zone="UTC" | ||
101 | }, | ||
102 | .gmt_tm= { | ||
103 | .tm_year=69, | ||
104 | .tm_mon=5, | ||
105 | .tm_mday=21, | ||
106 | .tm_hour=2, | ||
107 | .tm_min=56, | ||
108 | .tm_sec=15, | ||
109 | .tm_wday=6, | ||
110 | .tm_yday=171, | ||
111 | .tm_isdst=0, | ||
112 | .tm_gmtoff=0, | ||
113 | .tm_zone="GMT" | ||
114 | }, | ||
115 | }, | ||
116 | { | ||
117 | .descr="moon", | ||
118 | .timezone="right/America/Edmonton", | ||
119 | .time=-16751025, | ||
120 | .local_tm= { | ||
121 | .tm_year=69, | ||
122 | .tm_mon=5, | ||
123 | .tm_mday=20, | ||
124 | .tm_hour=19, | ||
125 | .tm_min=56, | ||
126 | .tm_sec=15, | ||
127 | .tm_wday=5, | ||
128 | .tm_yday=170, | ||
129 | .tm_isdst=0, | ||
130 | .tm_gmtoff=-25200, | ||
131 | .tm_zone="MST" | ||
132 | }, | ||
133 | .gmt_tm= { | ||
134 | .tm_year=69, | ||
135 | .tm_mon=5, | ||
136 | .tm_mday=21, | ||
137 | .tm_hour=2, | ||
138 | .tm_min=56, | ||
139 | .tm_sec=15, | ||
140 | .tm_wday=6, | ||
141 | .tm_yday=171, | ||
142 | .tm_isdst=0, | ||
143 | .tm_gmtoff=0, | ||
144 | .tm_zone="GMT" | ||
145 | }, | ||
146 | }, | ||
147 | { | ||
148 | .descr="epoch", | ||
149 | .timezone="posix/America/Edmonton", | ||
150 | .time=0, | ||
151 | .local_tm= { | ||
152 | .tm_year=69, | ||
153 | .tm_mon=11, | ||
154 | .tm_mday=31, | ||
155 | .tm_hour=17, | ||
156 | .tm_min=0, | ||
157 | .tm_sec=0, | ||
158 | .tm_wday=3, | ||
159 | .tm_yday=364, | ||
160 | .tm_isdst=0, | ||
161 | .tm_gmtoff=-25200, | ||
162 | .tm_zone="MST" | ||
163 | }, | ||
164 | .gmt_tm= { | ||
165 | .tm_year=70, | ||
166 | .tm_mon=0, | ||
167 | .tm_mday=1, | ||
168 | .tm_hour=0, | ||
169 | .tm_min=0, | ||
170 | .tm_sec=0, | ||
171 | .tm_wday=4, | ||
172 | .tm_yday=0, | ||
173 | .tm_isdst=0, | ||
174 | .tm_gmtoff=0, | ||
175 | .tm_zone="GMT" | ||
176 | }, | ||
177 | }, | ||
178 | { | ||
179 | .descr="epoch", | ||
180 | .timezone="right/UTC", | ||
181 | .time=0, | ||
182 | .local_tm= { | ||
183 | .tm_year=70, | ||
184 | .tm_mon=0, | ||
185 | .tm_mday=1, | ||
186 | .tm_hour=0, | ||
187 | .tm_min=0, | ||
188 | .tm_sec=0, | ||
189 | .tm_wday=4, | ||
190 | .tm_yday=0, | ||
191 | .tm_isdst=0, | ||
192 | .tm_gmtoff=0, | ||
193 | .tm_zone="UTC" | ||
194 | }, | ||
195 | .gmt_tm= { | ||
196 | .tm_year=70, | ||
197 | .tm_mon=0, | ||
198 | .tm_mday=1, | ||
199 | .tm_hour=0, | ||
200 | .tm_min=0, | ||
201 | .tm_sec=0, | ||
202 | .tm_wday=4, | ||
203 | .tm_yday=0, | ||
204 | .tm_isdst=0, | ||
205 | .tm_gmtoff=0, | ||
206 | .tm_zone="GMT" | ||
207 | }, | ||
208 | }, | ||
209 | { | ||
210 | .descr="epoch", | ||
211 | .timezone="right/America/Edmonton", | ||
212 | .time=0, | ||
213 | .local_tm= { | ||
214 | .tm_year=69, | ||
215 | .tm_mon=11, | ||
216 | .tm_mday=31, | ||
217 | .tm_hour=17, | ||
218 | .tm_min=0, | ||
219 | .tm_sec=0, | ||
220 | .tm_wday=3, | ||
221 | .tm_yday=364, | ||
222 | .tm_isdst=0, | ||
223 | .tm_gmtoff=-25200, | ||
224 | .tm_zone="MST" | ||
225 | }, | ||
226 | .gmt_tm= { | ||
227 | .tm_year=70, | ||
228 | .tm_mon=0, | ||
229 | .tm_mday=1, | ||
230 | .tm_hour=0, | ||
231 | .tm_min=0, | ||
232 | .tm_sec=0, | ||
233 | .tm_wday=4, | ||
234 | .tm_yday=0, | ||
235 | .tm_isdst=0, | ||
236 | .tm_gmtoff=0, | ||
237 | .tm_zone="GMT" | ||
238 | }, | ||
239 | }, | ||
240 | { | ||
241 | .descr="epoch - 1", | ||
242 | .timezone="posix/America/Edmonton", | ||
243 | .time=-1, | ||
244 | .local_tm= { | ||
245 | .tm_year=69, | ||
246 | .tm_mon=11, | ||
247 | .tm_mday=31, | ||
248 | .tm_hour=16, | ||
249 | .tm_min=59, | ||
250 | .tm_sec=59, | ||
251 | .tm_wday=3, | ||
252 | .tm_yday=364, | ||
253 | .tm_isdst=0, | ||
254 | .tm_gmtoff=-25200, | ||
255 | .tm_zone="MST" | ||
256 | }, | ||
257 | .gmt_tm= { | ||
258 | .tm_year=69, | ||
259 | .tm_mon=11, | ||
260 | .tm_mday=31, | ||
261 | .tm_hour=23, | ||
262 | .tm_min=59, | ||
263 | .tm_sec=59, | ||
264 | .tm_wday=3, | ||
265 | .tm_yday=364, | ||
266 | .tm_isdst=0, | ||
267 | .tm_gmtoff=0, | ||
268 | .tm_zone="GMT" | ||
269 | }, | ||
270 | }, | ||
271 | { | ||
272 | .descr="epoch - 1", | ||
273 | .timezone="right/UTC", | ||
274 | .time=-1, | ||
275 | .local_tm= { | ||
276 | .tm_year=69, | ||
277 | .tm_mon=11, | ||
278 | .tm_mday=31, | ||
279 | .tm_hour=23, | ||
280 | .tm_min=59, | ||
281 | .tm_sec=59, | ||
282 | .tm_wday=3, | ||
283 | .tm_yday=364, | ||
284 | .tm_isdst=0, | ||
285 | .tm_gmtoff=0, | ||
286 | .tm_zone="UTC" | ||
287 | }, | ||
288 | .gmt_tm= { | ||
289 | .tm_year=69, | ||
290 | .tm_mon=11, | ||
291 | .tm_mday=31, | ||
292 | .tm_hour=23, | ||
293 | .tm_min=59, | ||
294 | .tm_sec=59, | ||
295 | .tm_wday=3, | ||
296 | .tm_yday=364, | ||
297 | .tm_isdst=0, | ||
298 | .tm_gmtoff=0, | ||
299 | .tm_zone="GMT" | ||
300 | }, | ||
301 | }, | ||
302 | { | ||
303 | .descr="epoch - 1", | ||
304 | .timezone="right/America/Edmonton", | ||
305 | .time=-1, | ||
306 | .local_tm= { | ||
307 | .tm_year=69, | ||
308 | .tm_mon=11, | ||
309 | .tm_mday=31, | ||
310 | .tm_hour=16, | ||
311 | .tm_min=59, | ||
312 | .tm_sec=59, | ||
313 | .tm_wday=3, | ||
314 | .tm_yday=364, | ||
315 | .tm_isdst=0, | ||
316 | .tm_gmtoff=-25200, | ||
317 | .tm_zone="MST" | ||
318 | }, | ||
319 | .gmt_tm= { | ||
320 | .tm_year=69, | ||
321 | .tm_mon=11, | ||
322 | .tm_mday=31, | ||
323 | .tm_hour=23, | ||
324 | .tm_min=59, | ||
325 | .tm_sec=59, | ||
326 | .tm_wday=3, | ||
327 | .tm_yday=364, | ||
328 | .tm_isdst=0, | ||
329 | .tm_gmtoff=0, | ||
330 | .tm_zone="GMT" | ||
331 | }, | ||
332 | }, | ||
333 | { | ||
334 | .descr="legacy min", | ||
335 | .timezone="posix/America/Edmonton", | ||
336 | .time=-2147483648, | ||
337 | .local_tm= { | ||
338 | .tm_year=1, | ||
339 | .tm_mon=11, | ||
340 | .tm_mday=13, | ||
341 | .tm_hour=13, | ||
342 | .tm_min=12, | ||
343 | .tm_sec=0, | ||
344 | .tm_wday=5, | ||
345 | .tm_yday=346, | ||
346 | .tm_isdst=0, | ||
347 | .tm_gmtoff=-27232, | ||
348 | .tm_zone="LMT" | ||
349 | }, | ||
350 | .gmt_tm= { | ||
351 | .tm_year=1, | ||
352 | .tm_mon=11, | ||
353 | .tm_mday=13, | ||
354 | .tm_hour=20, | ||
355 | .tm_min=45, | ||
356 | .tm_sec=52, | ||
357 | .tm_wday=5, | ||
358 | .tm_yday=346, | ||
359 | .tm_isdst=0, | ||
360 | .tm_gmtoff=0, | ||
361 | .tm_zone="GMT" | ||
362 | }, | ||
363 | }, | ||
364 | { | ||
365 | .descr="legacy min", | ||
366 | .timezone="right/UTC", | ||
367 | .time=-2147483648, | ||
368 | .local_tm= { | ||
369 | .tm_year=1, | ||
370 | .tm_mon=11, | ||
371 | .tm_mday=13, | ||
372 | .tm_hour=20, | ||
373 | .tm_min=45, | ||
374 | .tm_sec=52, | ||
375 | .tm_wday=5, | ||
376 | .tm_yday=346, | ||
377 | .tm_isdst=0, | ||
378 | .tm_gmtoff=0, | ||
379 | .tm_zone="UTC" | ||
380 | }, | ||
381 | .gmt_tm= { | ||
382 | .tm_year=1, | ||
383 | .tm_mon=11, | ||
384 | .tm_mday=13, | ||
385 | .tm_hour=20, | ||
386 | .tm_min=45, | ||
387 | .tm_sec=52, | ||
388 | .tm_wday=5, | ||
389 | .tm_yday=346, | ||
390 | .tm_isdst=0, | ||
391 | .tm_gmtoff=0, | ||
392 | .tm_zone="GMT" | ||
393 | }, | ||
394 | }, | ||
395 | { | ||
396 | .descr="legacy min - 1", | ||
397 | .timezone="posix/America/Edmonton", | ||
398 | .time=-2147483649, | ||
399 | .local_tm= { | ||
400 | .tm_year=1, | ||
401 | .tm_mon=11, | ||
402 | .tm_mday=13, | ||
403 | .tm_hour=13, | ||
404 | .tm_min=11, | ||
405 | .tm_sec=59, | ||
406 | .tm_wday=5, | ||
407 | .tm_yday=346, | ||
408 | .tm_isdst=0, | ||
409 | .tm_gmtoff=-27232, | ||
410 | .tm_zone="LMT" | ||
411 | }, | ||
412 | .gmt_tm= { | ||
413 | .tm_year=1, | ||
414 | .tm_mon=11, | ||
415 | .tm_mday=13, | ||
416 | .tm_hour=20, | ||
417 | .tm_min=45, | ||
418 | .tm_sec=51, | ||
419 | .tm_wday=5, | ||
420 | .tm_yday=346, | ||
421 | .tm_isdst=0, | ||
422 | .tm_gmtoff=0, | ||
423 | .tm_zone="GMT" | ||
424 | }, | ||
425 | }, | ||
426 | { | ||
427 | .descr="legacy min - 1", | ||
428 | .timezone="right/UTC", | ||
429 | .time=-2147483649, | ||
430 | .local_tm= { | ||
431 | .tm_year=1, | ||
432 | .tm_mon=11, | ||
433 | .tm_mday=13, | ||
434 | .tm_hour=20, | ||
435 | .tm_min=45, | ||
436 | .tm_sec=51, | ||
437 | .tm_wday=5, | ||
438 | .tm_yday=346, | ||
439 | .tm_isdst=0, | ||
440 | .tm_gmtoff=0, | ||
441 | .tm_zone="UTC" | ||
442 | }, | ||
443 | .gmt_tm= { | ||
444 | .tm_year=1, | ||
445 | .tm_mon=11, | ||
446 | .tm_mday=13, | ||
447 | .tm_hour=20, | ||
448 | .tm_min=45, | ||
449 | .tm_sec=51, | ||
450 | .tm_wday=5, | ||
451 | .tm_yday=346, | ||
452 | .tm_isdst=0, | ||
453 | .tm_gmtoff=0, | ||
454 | .tm_zone="GMT" | ||
455 | }, | ||
456 | }, | ||
457 | { | ||
458 | .descr="legacy max", | ||
459 | .timezone="posix/America/Edmonton", | ||
460 | .time=2147483647, | ||
461 | .local_tm= { | ||
462 | .tm_year=138, | ||
463 | .tm_mon=0, | ||
464 | .tm_mday=18, | ||
465 | .tm_hour=20, | ||
466 | .tm_min=14, | ||
467 | .tm_sec=7, | ||
468 | .tm_wday=1, | ||
469 | .tm_yday=17, | ||
470 | .tm_isdst=0, | ||
471 | .tm_gmtoff=-25200, | ||
472 | .tm_zone="MST" | ||
473 | }, | ||
474 | .gmt_tm= { | ||
475 | .tm_year=138, | ||
476 | .tm_mon=0, | ||
477 | .tm_mday=19, | ||
478 | .tm_hour=3, | ||
479 | .tm_min=14, | ||
480 | .tm_sec=7, | ||
481 | .tm_wday=2, | ||
482 | .tm_yday=18, | ||
483 | .tm_isdst=0, | ||
484 | .tm_gmtoff=0, | ||
485 | .tm_zone="GMT" | ||
486 | }, | ||
487 | }, | ||
488 | { | ||
489 | .descr="legacy max", | ||
490 | .timezone="right/UTC", | ||
491 | .time=2147483647, | ||
492 | .local_tm= { | ||
493 | .tm_year=138, | ||
494 | .tm_mon=0, | ||
495 | .tm_mday=19, | ||
496 | .tm_hour=3, | ||
497 | .tm_min=13, | ||
498 | .tm_sec=40, | ||
499 | .tm_wday=2, | ||
500 | .tm_yday=18, | ||
501 | .tm_isdst=0, | ||
502 | .tm_gmtoff=0, | ||
503 | .tm_zone="UTC" | ||
504 | }, | ||
505 | .gmt_tm= { | ||
506 | .tm_year=138, | ||
507 | .tm_mon=0, | ||
508 | .tm_mday=19, | ||
509 | .tm_hour=3, | ||
510 | .tm_min=14, | ||
511 | .tm_sec=7, | ||
512 | .tm_wday=2, | ||
513 | .tm_yday=18, | ||
514 | .tm_isdst=0, | ||
515 | .tm_gmtoff=0, | ||
516 | .tm_zone="GMT" | ||
517 | }, | ||
518 | }, | ||
519 | { | ||
520 | .descr="legacy max + 1", | ||
521 | .timezone="posix/America/Edmonton", | ||
522 | .time=2147483648, | ||
523 | .local_tm= { | ||
524 | .tm_year=138, | ||
525 | .tm_mon=0, | ||
526 | .tm_mday=18, | ||
527 | .tm_hour=20, | ||
528 | .tm_min=14, | ||
529 | .tm_sec=8, | ||
530 | .tm_wday=1, | ||
531 | .tm_yday=17, | ||
532 | .tm_isdst=0, | ||
533 | .tm_gmtoff=-25200, | ||
534 | .tm_zone="MST" | ||
535 | }, | ||
536 | .gmt_tm= { | ||
537 | .tm_year=138, | ||
538 | .tm_mon=0, | ||
539 | .tm_mday=19, | ||
540 | .tm_hour=3, | ||
541 | .tm_min=14, | ||
542 | .tm_sec=8, | ||
543 | .tm_wday=2, | ||
544 | .tm_yday=18, | ||
545 | .tm_isdst=0, | ||
546 | .tm_gmtoff=0, | ||
547 | .tm_zone="GMT" | ||
548 | }, | ||
549 | }, | ||
550 | { | ||
551 | .descr="legacy max + 1", | ||
552 | .timezone="right/UTC", | ||
553 | .time=2147483648, | ||
554 | .local_tm= { | ||
555 | .tm_year=138, | ||
556 | .tm_mon=0, | ||
557 | .tm_mday=19, | ||
558 | .tm_hour=3, | ||
559 | .tm_min=13, | ||
560 | .tm_sec=41, | ||
561 | .tm_wday=2, | ||
562 | .tm_yday=18, | ||
563 | .tm_isdst=0, | ||
564 | .tm_gmtoff=0, | ||
565 | .tm_zone="UTC" | ||
566 | }, | ||
567 | .gmt_tm= { | ||
568 | .tm_year=138, | ||
569 | .tm_mon=0, | ||
570 | .tm_mday=19, | ||
571 | .tm_hour=3, | ||
572 | .tm_min=14, | ||
573 | .tm_sec=8, | ||
574 | .tm_wday=2, | ||
575 | .tm_yday=18, | ||
576 | .tm_isdst=0, | ||
577 | .tm_gmtoff=0, | ||
578 | .tm_zone="GMT" | ||
579 | }, | ||
580 | }, | ||
581 | { | ||
582 | .descr="min", | ||
583 | .timezone="posix/America/Edmonton", | ||
584 | .time=INT64_MIN, | ||
585 | .local_tm= { | ||
586 | .tm_year=0, | ||
587 | .tm_mon=0, | ||
588 | .tm_mday=0, | ||
589 | .tm_hour=0, | ||
590 | .tm_min=0, | ||
591 | .tm_sec=0, | ||
592 | .tm_wday=0, | ||
593 | .tm_yday=0, | ||
594 | .tm_isdst=0, | ||
595 | .tm_gmtoff=0, | ||
596 | .tm_zone="FAILURE" | ||
597 | }, | ||
598 | .gmt_tm= { | ||
599 | .tm_year=0, | ||
600 | .tm_mon=0, | ||
601 | .tm_mday=0, | ||
602 | .tm_hour=0, | ||
603 | .tm_min=0, | ||
604 | .tm_sec=0, | ||
605 | .tm_wday=0, | ||
606 | .tm_yday=0, | ||
607 | .tm_isdst=0, | ||
608 | .tm_gmtoff=0, | ||
609 | .tm_zone="FAILURE" | ||
610 | }, | ||
611 | }, | ||
612 | { | ||
613 | .descr="min", | ||
614 | .timezone="right/UTC", | ||
615 | .time=INT64_MIN, | ||
616 | .local_tm= { | ||
617 | .tm_year=0, | ||
618 | .tm_mon=0, | ||
619 | .tm_mday=0, | ||
620 | .tm_hour=0, | ||
621 | .tm_min=0, | ||
622 | .tm_sec=0, | ||
623 | .tm_wday=0, | ||
624 | .tm_yday=0, | ||
625 | .tm_isdst=0, | ||
626 | .tm_gmtoff=0, | ||
627 | .tm_zone="FAILURE" | ||
628 | }, | ||
629 | .gmt_tm= { | ||
630 | .tm_year=0, | ||
631 | .tm_mon=0, | ||
632 | .tm_mday=0, | ||
633 | .tm_hour=0, | ||
634 | .tm_min=0, | ||
635 | .tm_sec=0, | ||
636 | .tm_wday=0, | ||
637 | .tm_yday=0, | ||
638 | .tm_isdst=0, | ||
639 | .tm_gmtoff=0, | ||
640 | .tm_zone="FAILURE" | ||
641 | }, | ||
642 | }, | ||
643 | { | ||
644 | .descr="max", | ||
645 | .timezone="right/America/Edmonton", | ||
646 | .time=9223372036854775807, | ||
647 | .local_tm= { | ||
648 | .tm_year=0, | ||
649 | .tm_mon=0, | ||
650 | .tm_mday=0, | ||
651 | .tm_hour=0, | ||
652 | .tm_min=0, | ||
653 | .tm_sec=0, | ||
654 | .tm_wday=0, | ||
655 | .tm_yday=0, | ||
656 | .tm_isdst=0, | ||
657 | .tm_gmtoff=0, | ||
658 | .tm_zone="FAILURE" | ||
659 | }, | ||
660 | .gmt_tm= { | ||
661 | .tm_year=0, | ||
662 | .tm_mon=0, | ||
663 | .tm_mday=0, | ||
664 | .tm_hour=0, | ||
665 | .tm_min=0, | ||
666 | .tm_sec=0, | ||
667 | .tm_wday=0, | ||
668 | .tm_yday=0, | ||
669 | .tm_isdst=0, | ||
670 | .tm_gmtoff=0, | ||
671 | .tm_zone="FAILURE" | ||
672 | }, | ||
673 | }, | ||
674 | { | ||
675 | .descr="max", | ||
676 | .timezone="posix/America/Edmonton", | ||
677 | .time=9223372036854775807, | ||
678 | .local_tm= { | ||
679 | .tm_year=0, | ||
680 | .tm_mon=0, | ||
681 | .tm_mday=0, | ||
682 | .tm_hour=0, | ||
683 | .tm_min=0, | ||
684 | .tm_sec=0, | ||
685 | .tm_wday=0, | ||
686 | .tm_yday=0, | ||
687 | .tm_isdst=0, | ||
688 | .tm_gmtoff=0, | ||
689 | .tm_zone="FAILURE" | ||
690 | }, | ||
691 | .gmt_tm= { | ||
692 | .tm_year=0, | ||
693 | .tm_mon=0, | ||
694 | .tm_mday=0, | ||
695 | .tm_hour=0, | ||
696 | .tm_min=0, | ||
697 | .tm_sec=0, | ||
698 | .tm_wday=0, | ||
699 | .tm_yday=0, | ||
700 | .tm_isdst=0, | ||
701 | .tm_gmtoff=0, | ||
702 | .tm_zone="FAILURE" | ||
703 | }, | ||
704 | }, | ||
705 | { | ||
706 | .descr="max", | ||
707 | .timezone="right/UTC", | ||
708 | .time=9223372036854775807, | ||
709 | .local_tm= { | ||
710 | .tm_year=0, | ||
711 | .tm_mon=0, | ||
712 | .tm_mday=0, | ||
713 | .tm_hour=0, | ||
714 | .tm_min=0, | ||
715 | .tm_sec=0, | ||
716 | .tm_wday=0, | ||
717 | .tm_yday=0, | ||
718 | .tm_isdst=0, | ||
719 | .tm_gmtoff=0, | ||
720 | .tm_zone="FAILURE" | ||
721 | }, | ||
722 | .gmt_tm= { | ||
723 | .tm_year=0, | ||
724 | .tm_mon=0, | ||
725 | .tm_mday=0, | ||
726 | .tm_hour=0, | ||
727 | .tm_min=0, | ||
728 | .tm_sec=0, | ||
729 | .tm_wday=0, | ||
730 | .tm_yday=0, | ||
731 | .tm_isdst=0, | ||
732 | .tm_gmtoff=0, | ||
733 | .tm_zone="FAILURE" | ||
734 | }, | ||
735 | }, | ||
736 | { | ||
737 | .descr="min", | ||
738 | .timezone="right/America/Edmonton", | ||
739 | .time=INT64_MIN, | ||
740 | .local_tm= { | ||
741 | .tm_year=0, | ||
742 | .tm_mon=0, | ||
743 | .tm_mday=0, | ||
744 | .tm_hour=0, | ||
745 | .tm_min=0, | ||
746 | .tm_sec=0, | ||
747 | .tm_wday=0, | ||
748 | .tm_yday=0, | ||
749 | .tm_isdst=0, | ||
750 | .tm_gmtoff=0, | ||
751 | .tm_zone="FAILURE" | ||
752 | }, | ||
753 | .gmt_tm= { | ||
754 | .tm_year=0, | ||
755 | .tm_mon=0, | ||
756 | .tm_mday=0, | ||
757 | .tm_hour=0, | ||
758 | .tm_min=0, | ||
759 | .tm_sec=0, | ||
760 | .tm_wday=0, | ||
761 | .tm_yday=0, | ||
762 | .tm_isdst=0, | ||
763 | .tm_gmtoff=0, | ||
764 | .tm_zone="FAILURE" | ||
765 | }, | ||
766 | }, | ||
767 | { | ||
768 | .descr="maxint struct tm", | ||
769 | .timezone="right/America/Edmonton", | ||
770 | .time=67767976204675199, | ||
771 | .local_tm= { | ||
772 | .tm_year=2147481747, | ||
773 | .tm_mon=0, | ||
774 | .tm_mday=31, | ||
775 | .tm_hour=16, | ||
776 | .tm_min=59, | ||
777 | .tm_sec=32, | ||
778 | .tm_wday=4, | ||
779 | .tm_yday=30, | ||
780 | .tm_isdst=0, | ||
781 | .tm_gmtoff=-25200, | ||
782 | .tm_zone="MST" | ||
783 | }, | ||
784 | .gmt_tm= { | ||
785 | .tm_year=2147481747, | ||
786 | .tm_mon=0, | ||
787 | .tm_mday=31, | ||
788 | .tm_hour=23, | ||
789 | .tm_min=59, | ||
790 | .tm_sec=59, | ||
791 | .tm_wday=4, | ||
792 | .tm_yday=30, | ||
793 | .tm_isdst=0, | ||
794 | .tm_gmtoff=0, | ||
795 | .tm_zone="GMT" | ||
796 | }, | ||
797 | }, | ||
798 | { | ||
799 | .descr="minint struct tm", | ||
800 | .timezone="right/America/Edmonton", | ||
801 | .time=-67768038398073601, | ||
802 | .local_tm= { | ||
803 | .tm_year=-2147483578, | ||
804 | .tm_mon=0, | ||
805 | .tm_mday=31, | ||
806 | .tm_hour=16, | ||
807 | .tm_min=26, | ||
808 | .tm_sec=7, | ||
809 | .tm_wday=2, | ||
810 | .tm_yday=30, | ||
811 | .tm_isdst=0, | ||
812 | .tm_gmtoff=-27232, | ||
813 | .tm_zone="LMT" | ||
814 | }, | ||
815 | .gmt_tm= { | ||
816 | .tm_year=-2147483578, | ||
817 | .tm_mon=0, | ||
818 | .tm_mday=31, | ||
819 | .tm_hour=23, | ||
820 | .tm_min=59, | ||
821 | .tm_sec=59, | ||
822 | .tm_wday=2, | ||
823 | .tm_yday=30, | ||
824 | .tm_isdst=0, | ||
825 | .tm_gmtoff=0, | ||
826 | .tm_zone="GMT" | ||
827 | }, | ||
828 | }, | ||
829 | { | ||
830 | .descr="maxint struct tm", | ||
831 | .timezone="right/UTC", | ||
832 | .time=67767976204675199, | ||
833 | .local_tm= { | ||
834 | .tm_year=2147481747, | ||
835 | .tm_mon=0, | ||
836 | .tm_mday=31, | ||
837 | .tm_hour=23, | ||
838 | .tm_min=59, | ||
839 | .tm_sec=32, | ||
840 | .tm_wday=4, | ||
841 | .tm_yday=30, | ||
842 | .tm_isdst=0, | ||
843 | .tm_gmtoff=0, | ||
844 | .tm_zone="UTC" | ||
845 | }, | ||
846 | .gmt_tm= { | ||
847 | .tm_year=2147481747, | ||
848 | .tm_mon=0, | ||
849 | .tm_mday=31, | ||
850 | .tm_hour=23, | ||
851 | .tm_min=59, | ||
852 | .tm_sec=59, | ||
853 | .tm_wday=4, | ||
854 | .tm_yday=30, | ||
855 | .tm_isdst=0, | ||
856 | .tm_gmtoff=0, | ||
857 | .tm_zone="GMT" | ||
858 | }, | ||
859 | }, | ||
860 | { | ||
861 | .descr="minint struct tm", | ||
862 | .timezone="right/UTC", | ||
863 | .time=-67768038398073601, | ||
864 | .local_tm= { | ||
865 | .tm_year=-2147483578, | ||
866 | .tm_mon=0, | ||
867 | .tm_mday=31, | ||
868 | .tm_hour=23, | ||
869 | .tm_min=59, | ||
870 | .tm_sec=59, | ||
871 | .tm_wday=2, | ||
872 | .tm_yday=30, | ||
873 | .tm_isdst=0, | ||
874 | .tm_gmtoff=0, | ||
875 | .tm_zone="UTC" | ||
876 | }, | ||
877 | .gmt_tm= { | ||
878 | .tm_year=-2147483578, | ||
879 | .tm_mon=0, | ||
880 | .tm_mday=31, | ||
881 | .tm_hour=23, | ||
882 | .tm_min=59, | ||
883 | .tm_sec=59, | ||
884 | .tm_wday=2, | ||
885 | .tm_yday=30, | ||
886 | .tm_isdst=0, | ||
887 | .tm_gmtoff=0, | ||
888 | .tm_zone="GMT" | ||
889 | }, | ||
890 | }, | ||
891 | { | ||
892 | .descr="0000", | ||
893 | .timezone="posix/America/Edmonton", | ||
894 | .time=-62167219200, | ||
895 | .local_tm= { | ||
896 | .tm_year=-1901, | ||
897 | .tm_mon=11, | ||
898 | .tm_mday=31, | ||
899 | .tm_hour=16, | ||
900 | .tm_min=26, | ||
901 | .tm_sec=8, | ||
902 | .tm_wday=5, | ||
903 | .tm_yday=364, | ||
904 | .tm_isdst=0, | ||
905 | .tm_gmtoff=-27232, | ||
906 | .tm_zone="LMT" | ||
907 | }, | ||
908 | .gmt_tm= { | ||
909 | .tm_year=-1900, | ||
910 | .tm_mon=0, | ||
911 | .tm_mday=1, | ||
912 | .tm_hour=0, | ||
913 | .tm_min=0, | ||
914 | .tm_sec=0, | ||
915 | .tm_wday=6, | ||
916 | .tm_yday=0, | ||
917 | .tm_isdst=0, | ||
918 | .tm_gmtoff=0, | ||
919 | .tm_zone="GMT" | ||
920 | }, | ||
921 | }, | ||
922 | { | ||
923 | .descr="0000", | ||
924 | .timezone="right/UTC", | ||
925 | .time=-62167219200, | ||
926 | .local_tm= { | ||
927 | .tm_year=-1900, | ||
928 | .tm_mon=0, | ||
929 | .tm_mday=1, | ||
930 | .tm_hour=0, | ||
931 | .tm_min=0, | ||
932 | .tm_sec=0, | ||
933 | .tm_wday=6, | ||
934 | .tm_yday=0, | ||
935 | .tm_isdst=0, | ||
936 | .tm_gmtoff=0, | ||
937 | .tm_zone="UTC" | ||
938 | }, | ||
939 | .gmt_tm= { | ||
940 | .tm_year=-1900, | ||
941 | .tm_mon=0, | ||
942 | .tm_mday=1, | ||
943 | .tm_hour=0, | ||
944 | .tm_min=0, | ||
945 | .tm_sec=0, | ||
946 | .tm_wday=6, | ||
947 | .tm_yday=0, | ||
948 | .tm_isdst=0, | ||
949 | .tm_gmtoff=0, | ||
950 | .tm_zone="GMT" | ||
951 | }, | ||
952 | }, | ||
953 | { | ||
954 | .descr="0000", | ||
955 | .timezone="right/America/Edmonton", | ||
956 | .time=-62167219200, | ||
957 | .local_tm= { | ||
958 | .tm_year=-1901, | ||
959 | .tm_mon=11, | ||
960 | .tm_mday=31, | ||
961 | .tm_hour=16, | ||
962 | .tm_min=26, | ||
963 | .tm_sec=8, | ||
964 | .tm_wday=5, | ||
965 | .tm_yday=364, | ||
966 | .tm_isdst=0, | ||
967 | .tm_gmtoff=-27232, | ||
968 | .tm_zone="LMT" | ||
969 | }, | ||
970 | .gmt_tm= { | ||
971 | .tm_year=-1900, | ||
972 | .tm_mon=0, | ||
973 | .tm_mday=1, | ||
974 | .tm_hour=0, | ||
975 | .tm_min=0, | ||
976 | .tm_sec=0, | ||
977 | .tm_wday=6, | ||
978 | .tm_yday=0, | ||
979 | .tm_isdst=0, | ||
980 | .tm_gmtoff=0, | ||
981 | .tm_zone="GMT" | ||
982 | }, | ||
983 | }, | ||
984 | { | ||
985 | .descr="9999", | ||
986 | .timezone="posix/America/Edmonton", | ||
987 | .time=253402300799, | ||
988 | .local_tm= { | ||
989 | .tm_year=8099, | ||
990 | .tm_mon=11, | ||
991 | .tm_mday=31, | ||
992 | .tm_hour=16, | ||
993 | .tm_min=59, | ||
994 | .tm_sec=59, | ||
995 | .tm_wday=5, | ||
996 | .tm_yday=364, | ||
997 | .tm_isdst=0, | ||
998 | .tm_gmtoff=-25200, | ||
999 | .tm_zone="MST" | ||
1000 | }, | ||
1001 | .gmt_tm= { | ||
1002 | .tm_year=8099, | ||
1003 | .tm_mon=11, | ||
1004 | .tm_mday=31, | ||
1005 | .tm_hour=23, | ||
1006 | .tm_min=59, | ||
1007 | .tm_sec=59, | ||
1008 | .tm_wday=5, | ||
1009 | .tm_yday=364, | ||
1010 | .tm_isdst=0, | ||
1011 | .tm_gmtoff=0, | ||
1012 | .tm_zone="GMT" | ||
1013 | }, | ||
1014 | }, | ||
1015 | { | ||
1016 | .descr="9999", | ||
1017 | .timezone="right/UTC", | ||
1018 | .time=253402300799, | ||
1019 | .local_tm= { | ||
1020 | .tm_year=8099, | ||
1021 | .tm_mon=11, | ||
1022 | .tm_mday=31, | ||
1023 | .tm_hour=23, | ||
1024 | .tm_min=59, | ||
1025 | .tm_sec=32, | ||
1026 | .tm_wday=5, | ||
1027 | .tm_yday=364, | ||
1028 | .tm_isdst=0, | ||
1029 | .tm_gmtoff=0, | ||
1030 | .tm_zone="UTC" | ||
1031 | }, | ||
1032 | .gmt_tm= { | ||
1033 | .tm_year=8099, | ||
1034 | .tm_mon=11, | ||
1035 | .tm_mday=31, | ||
1036 | .tm_hour=23, | ||
1037 | .tm_min=59, | ||
1038 | .tm_sec=59, | ||
1039 | .tm_wday=5, | ||
1040 | .tm_yday=364, | ||
1041 | .tm_isdst=0, | ||
1042 | .tm_gmtoff=0, | ||
1043 | .tm_zone="GMT" | ||
1044 | }, | ||
1045 | }, | ||
1046 | { | ||
1047 | .descr="9999", | ||
1048 | .timezone="right/America/Edmonton", | ||
1049 | .time=253402300799, | ||
1050 | .local_tm= { | ||
1051 | .tm_year=8099, | ||
1052 | .tm_mon=11, | ||
1053 | .tm_mday=31, | ||
1054 | .tm_hour=16, | ||
1055 | .tm_min=59, | ||
1056 | .tm_sec=32, | ||
1057 | .tm_wday=5, | ||
1058 | .tm_yday=364, | ||
1059 | .tm_isdst=0, | ||
1060 | .tm_gmtoff=-25200, | ||
1061 | .tm_zone="MST" | ||
1062 | }, | ||
1063 | .gmt_tm= { | ||
1064 | .tm_year=8099, | ||
1065 | .tm_mon=11, | ||
1066 | .tm_mday=31, | ||
1067 | .tm_hour=23, | ||
1068 | .tm_min=59, | ||
1069 | .tm_sec=59, | ||
1070 | .tm_wday=5, | ||
1071 | .tm_yday=364, | ||
1072 | .tm_isdst=0, | ||
1073 | .tm_gmtoff=0, | ||
1074 | .tm_zone="GMT" | ||
1075 | }, | ||
1076 | }, | ||
1077 | { | ||
1078 | .descr="leap second - 1", | ||
1079 | .timezone="posix/America/Edmonton", | ||
1080 | .time=1483228825, | ||
1081 | .local_tm= { | ||
1082 | .tm_year=116, | ||
1083 | .tm_mon=11, | ||
1084 | .tm_mday=31, | ||
1085 | .tm_hour=17, | ||
1086 | .tm_min=0, | ||
1087 | .tm_sec=25, | ||
1088 | .tm_wday=6, | ||
1089 | .tm_yday=365, | ||
1090 | .tm_isdst=0, | ||
1091 | .tm_gmtoff=-25200, | ||
1092 | .tm_zone="MST" | ||
1093 | }, | ||
1094 | .gmt_tm= { | ||
1095 | .tm_year=117, | ||
1096 | .tm_mon=0, | ||
1097 | .tm_mday=1, | ||
1098 | .tm_hour=0, | ||
1099 | .tm_min=0, | ||
1100 | .tm_sec=25, | ||
1101 | .tm_wday=0, | ||
1102 | .tm_yday=0, | ||
1103 | .tm_isdst=0, | ||
1104 | .tm_gmtoff=0, | ||
1105 | .tm_zone="GMT" | ||
1106 | }, | ||
1107 | }, | ||
1108 | { | ||
1109 | .descr="leap second", | ||
1110 | .timezone="posix/America/Edmonton", | ||
1111 | .time=1483228826, | ||
1112 | .local_tm= { | ||
1113 | .tm_year=116, | ||
1114 | .tm_mon=11, | ||
1115 | .tm_mday=31, | ||
1116 | .tm_hour=17, | ||
1117 | .tm_min=0, | ||
1118 | .tm_sec=26, | ||
1119 | .tm_wday=6, | ||
1120 | .tm_yday=365, | ||
1121 | .tm_isdst=0, | ||
1122 | .tm_gmtoff=-25200, | ||
1123 | .tm_zone="MST" | ||
1124 | }, | ||
1125 | .gmt_tm= { | ||
1126 | .tm_year=117, | ||
1127 | .tm_mon=0, | ||
1128 | .tm_mday=1, | ||
1129 | .tm_hour=0, | ||
1130 | .tm_min=0, | ||
1131 | .tm_sec=26, | ||
1132 | .tm_wday=0, | ||
1133 | .tm_yday=0, | ||
1134 | .tm_isdst=0, | ||
1135 | .tm_gmtoff=0, | ||
1136 | .tm_zone="GMT" | ||
1137 | }, | ||
1138 | }, | ||
1139 | { | ||
1140 | .descr="leap second + 1", | ||
1141 | .timezone="posix/America/Edmonton", | ||
1142 | .time=1483228827, | ||
1143 | .local_tm= { | ||
1144 | .tm_year=116, | ||
1145 | .tm_mon=11, | ||
1146 | .tm_mday=31, | ||
1147 | .tm_hour=17, | ||
1148 | .tm_min=0, | ||
1149 | .tm_sec=27, | ||
1150 | .tm_wday=6, | ||
1151 | .tm_yday=365, | ||
1152 | .tm_isdst=0, | ||
1153 | .tm_gmtoff=-25200, | ||
1154 | .tm_zone="MST" | ||
1155 | }, | ||
1156 | .gmt_tm= { | ||
1157 | .tm_year=117, | ||
1158 | .tm_mon=0, | ||
1159 | .tm_mday=1, | ||
1160 | .tm_hour=0, | ||
1161 | .tm_min=0, | ||
1162 | .tm_sec=27, | ||
1163 | .tm_wday=0, | ||
1164 | .tm_yday=0, | ||
1165 | .tm_isdst=0, | ||
1166 | .tm_gmtoff=0, | ||
1167 | .tm_zone="GMT" | ||
1168 | }, | ||
1169 | }, | ||
1170 | { | ||
1171 | .descr="leap second - 1", | ||
1172 | .timezone="right/UTC", | ||
1173 | .time=1483228825, | ||
1174 | .local_tm= { | ||
1175 | .tm_year=116, | ||
1176 | .tm_mon=11, | ||
1177 | .tm_mday=31, | ||
1178 | .tm_hour=23, | ||
1179 | .tm_min=59, | ||
1180 | .tm_sec=59, | ||
1181 | .tm_wday=6, | ||
1182 | .tm_yday=365, | ||
1183 | .tm_isdst=0, | ||
1184 | .tm_gmtoff=0, | ||
1185 | .tm_zone="UTC" | ||
1186 | }, | ||
1187 | .gmt_tm= { | ||
1188 | .tm_year=117, | ||
1189 | .tm_mon=0, | ||
1190 | .tm_mday=1, | ||
1191 | .tm_hour=0, | ||
1192 | .tm_min=0, | ||
1193 | .tm_sec=25, | ||
1194 | .tm_wday=0, | ||
1195 | .tm_yday=0, | ||
1196 | .tm_isdst=0, | ||
1197 | .tm_gmtoff=0, | ||
1198 | .tm_zone="GMT" | ||
1199 | }, | ||
1200 | }, | ||
1201 | { | ||
1202 | .descr="leap second", | ||
1203 | .timezone="right/UTC", | ||
1204 | .time=1483228826, | ||
1205 | .local_tm= { | ||
1206 | .tm_year=116, | ||
1207 | .tm_mon=11, | ||
1208 | .tm_mday=31, | ||
1209 | .tm_hour=23, | ||
1210 | .tm_min=59, | ||
1211 | .tm_sec=60, | ||
1212 | .tm_wday=6, | ||
1213 | .tm_yday=365, | ||
1214 | .tm_isdst=0, | ||
1215 | .tm_gmtoff=0, | ||
1216 | .tm_zone="UTC" | ||
1217 | }, | ||
1218 | .gmt_tm= { | ||
1219 | .tm_year=117, | ||
1220 | .tm_mon=0, | ||
1221 | .tm_mday=1, | ||
1222 | .tm_hour=0, | ||
1223 | .tm_min=0, | ||
1224 | .tm_sec=26, | ||
1225 | .tm_wday=0, | ||
1226 | .tm_yday=0, | ||
1227 | .tm_isdst=0, | ||
1228 | .tm_gmtoff=0, | ||
1229 | .tm_zone="GMT" | ||
1230 | }, | ||
1231 | }, | ||
1232 | { | ||
1233 | .descr="leap second + 1", | ||
1234 | .timezone="right/UTC", | ||
1235 | .time=1483228827, | ||
1236 | .local_tm= { | ||
1237 | .tm_year=117, | ||
1238 | .tm_mon=0, | ||
1239 | .tm_mday=1, | ||
1240 | .tm_hour=0, | ||
1241 | .tm_min=0, | ||
1242 | .tm_sec=0, | ||
1243 | .tm_wday=0, | ||
1244 | .tm_yday=0, | ||
1245 | .tm_isdst=0, | ||
1246 | .tm_gmtoff=0, | ||
1247 | .tm_zone="UTC" | ||
1248 | }, | ||
1249 | .gmt_tm= { | ||
1250 | .tm_year=117, | ||
1251 | .tm_mon=0, | ||
1252 | .tm_mday=1, | ||
1253 | .tm_hour=0, | ||
1254 | .tm_min=0, | ||
1255 | .tm_sec=27, | ||
1256 | .tm_wday=0, | ||
1257 | .tm_yday=0, | ||
1258 | .tm_isdst=0, | ||
1259 | .tm_gmtoff=0, | ||
1260 | .tm_zone="GMT" | ||
1261 | }, | ||
1262 | }, | ||
1263 | { | ||
1264 | .descr="leap second - 1", | ||
1265 | .timezone="right/America/Edmonton", | ||
1266 | .time=1483228825, | ||
1267 | .local_tm= { | ||
1268 | .tm_year=116, | ||
1269 | .tm_mon=11, | ||
1270 | .tm_mday=31, | ||
1271 | .tm_hour=16, | ||
1272 | .tm_min=59, | ||
1273 | .tm_sec=59, | ||
1274 | .tm_wday=6, | ||
1275 | .tm_yday=365, | ||
1276 | .tm_isdst=0, | ||
1277 | .tm_gmtoff=-25200, | ||
1278 | .tm_zone="MST" | ||
1279 | }, | ||
1280 | .gmt_tm= { | ||
1281 | .tm_year=117, | ||
1282 | .tm_mon=0, | ||
1283 | .tm_mday=1, | ||
1284 | .tm_hour=0, | ||
1285 | .tm_min=0, | ||
1286 | .tm_sec=25, | ||
1287 | .tm_wday=0, | ||
1288 | .tm_yday=0, | ||
1289 | .tm_isdst=0, | ||
1290 | .tm_gmtoff=0, | ||
1291 | .tm_zone="GMT" | ||
1292 | }, | ||
1293 | }, | ||
1294 | { | ||
1295 | .descr="leap second", | ||
1296 | .timezone="right/America/Edmonton", | ||
1297 | .time=1483228826, | ||
1298 | .local_tm= { | ||
1299 | .tm_year=116, | ||
1300 | .tm_mon=11, | ||
1301 | .tm_mday=31, | ||
1302 | .tm_hour=16, | ||
1303 | .tm_min=59, | ||
1304 | .tm_sec=60, | ||
1305 | .tm_wday=6, | ||
1306 | .tm_yday=365, | ||
1307 | .tm_isdst=0, | ||
1308 | .tm_gmtoff=-25200, | ||
1309 | .tm_zone="MST" | ||
1310 | }, | ||
1311 | .gmt_tm= { | ||
1312 | .tm_year=117, | ||
1313 | .tm_mon=0, | ||
1314 | .tm_mday=1, | ||
1315 | .tm_hour=0, | ||
1316 | .tm_min=0, | ||
1317 | .tm_sec=26, | ||
1318 | .tm_wday=0, | ||
1319 | .tm_yday=0, | ||
1320 | .tm_isdst=0, | ||
1321 | .tm_gmtoff=0, | ||
1322 | .tm_zone="GMT" | ||
1323 | }, | ||
1324 | }, | ||
1325 | { | ||
1326 | .descr="leap second + 1", | ||
1327 | .timezone="right/America/Edmonton", | ||
1328 | .time=1483228827, | ||
1329 | .local_tm= { | ||
1330 | .tm_year=116, | ||
1331 | .tm_mon=11, | ||
1332 | .tm_mday=31, | ||
1333 | .tm_hour=17, | ||
1334 | .tm_min=0, | ||
1335 | .tm_sec=0, | ||
1336 | .tm_wday=6, | ||
1337 | .tm_yday=365, | ||
1338 | .tm_isdst=0, | ||
1339 | .tm_gmtoff=-25200, | ||
1340 | .tm_zone="MST" | ||
1341 | }, | ||
1342 | .gmt_tm= { | ||
1343 | .tm_year=117, | ||
1344 | .tm_mon=0, | ||
1345 | .tm_mday=1, | ||
1346 | .tm_hour=0, | ||
1347 | .tm_min=0, | ||
1348 | .tm_sec=27, | ||
1349 | .tm_wday=0, | ||
1350 | .tm_yday=0, | ||
1351 | .tm_isdst=0, | ||
1352 | .tm_gmtoff=0, | ||
1353 | .tm_zone="GMT" | ||
1354 | }, | ||
1355 | }, | ||
1356 | { | ||
1357 | .descr="transition standard to daylight - 1", | ||
1358 | .timezone="posix/America/Edmonton", | ||
1359 | .time=1457859599, | ||
1360 | .local_tm= { | ||
1361 | .tm_year=116, | ||
1362 | .tm_mon=2, | ||
1363 | .tm_mday=13, | ||
1364 | .tm_hour=1, | ||
1365 | .tm_min=59, | ||
1366 | .tm_sec=59, | ||
1367 | .tm_wday=0, | ||
1368 | .tm_yday=72, | ||
1369 | .tm_isdst=0, | ||
1370 | .tm_gmtoff=-25200, | ||
1371 | .tm_zone="MST" | ||
1372 | }, | ||
1373 | .gmt_tm= { | ||
1374 | .tm_year=116, | ||
1375 | .tm_mon=2, | ||
1376 | .tm_mday=13, | ||
1377 | .tm_hour=8, | ||
1378 | .tm_min=59, | ||
1379 | .tm_sec=59, | ||
1380 | .tm_wday=0, | ||
1381 | .tm_yday=72, | ||
1382 | .tm_isdst=0, | ||
1383 | .tm_gmtoff=0, | ||
1384 | .tm_zone="GMT" | ||
1385 | }, | ||
1386 | }, | ||
1387 | { | ||
1388 | .descr="transition standard to daylight", | ||
1389 | .timezone="posix/America/Edmonton", | ||
1390 | .time=1457859600, | ||
1391 | .local_tm= { | ||
1392 | .tm_year=116, | ||
1393 | .tm_mon=2, | ||
1394 | .tm_mday=13, | ||
1395 | .tm_hour=3, | ||
1396 | .tm_min=0, | ||
1397 | .tm_sec=0, | ||
1398 | .tm_wday=0, | ||
1399 | .tm_yday=72, | ||
1400 | .tm_isdst=1, | ||
1401 | .tm_gmtoff=-21600, | ||
1402 | .tm_zone="MDT" | ||
1403 | }, | ||
1404 | .gmt_tm= { | ||
1405 | .tm_year=116, | ||
1406 | .tm_mon=2, | ||
1407 | .tm_mday=13, | ||
1408 | .tm_hour=9, | ||
1409 | .tm_min=0, | ||
1410 | .tm_sec=0, | ||
1411 | .tm_wday=0, | ||
1412 | .tm_yday=72, | ||
1413 | .tm_isdst=0, | ||
1414 | .tm_gmtoff=0, | ||
1415 | .tm_zone="GMT" | ||
1416 | }, | ||
1417 | }, | ||
1418 | { | ||
1419 | .descr="transition standard to daylight + 1", | ||
1420 | .timezone="posix/America/Edmonton", | ||
1421 | .time=1457859601, | ||
1422 | .local_tm= { | ||
1423 | .tm_year=116, | ||
1424 | .tm_mon=2, | ||
1425 | .tm_mday=13, | ||
1426 | .tm_hour=3, | ||
1427 | .tm_min=0, | ||
1428 | .tm_sec=1, | ||
1429 | .tm_wday=0, | ||
1430 | .tm_yday=72, | ||
1431 | .tm_isdst=1, | ||
1432 | .tm_gmtoff=-21600, | ||
1433 | .tm_zone="MDT" | ||
1434 | }, | ||
1435 | .gmt_tm= { | ||
1436 | .tm_year=116, | ||
1437 | .tm_mon=2, | ||
1438 | .tm_mday=13, | ||
1439 | .tm_hour=9, | ||
1440 | .tm_min=0, | ||
1441 | .tm_sec=1, | ||
1442 | .tm_wday=0, | ||
1443 | .tm_yday=72, | ||
1444 | .tm_isdst=0, | ||
1445 | .tm_gmtoff=0, | ||
1446 | .tm_zone="GMT" | ||
1447 | }, | ||
1448 | }, | ||
1449 | { | ||
1450 | .descr="transition standard to daylight - 1", | ||
1451 | .timezone="right/America/Edmonton", | ||
1452 | .time=1457859625, | ||
1453 | .local_tm= { | ||
1454 | .tm_year=116, | ||
1455 | .tm_mon=2, | ||
1456 | .tm_mday=13, | ||
1457 | .tm_hour=1, | ||
1458 | .tm_min=59, | ||
1459 | .tm_sec=59, | ||
1460 | .tm_wday=0, | ||
1461 | .tm_yday=72, | ||
1462 | .tm_isdst=0, | ||
1463 | .tm_gmtoff=-25200, | ||
1464 | .tm_zone="MST" | ||
1465 | }, | ||
1466 | .gmt_tm= { | ||
1467 | .tm_year=116, | ||
1468 | .tm_mon=2, | ||
1469 | .tm_mday=13, | ||
1470 | .tm_hour=9, | ||
1471 | .tm_min=0, | ||
1472 | .tm_sec=25, | ||
1473 | .tm_wday=0, | ||
1474 | .tm_yday=72, | ||
1475 | .tm_isdst=0, | ||
1476 | .tm_gmtoff=0, | ||
1477 | .tm_zone="GMT" | ||
1478 | }, | ||
1479 | }, | ||
1480 | { | ||
1481 | .descr="transition standard to daylight", | ||
1482 | .timezone="right/America/Edmonton", | ||
1483 | .time=1457859626, | ||
1484 | .local_tm= { | ||
1485 | .tm_year=116, | ||
1486 | .tm_mon=2, | ||
1487 | .tm_mday=13, | ||
1488 | .tm_hour=3, | ||
1489 | .tm_min=0, | ||
1490 | .tm_sec=0, | ||
1491 | .tm_wday=0, | ||
1492 | .tm_yday=72, | ||
1493 | .tm_isdst=1, | ||
1494 | .tm_gmtoff=-21600, | ||
1495 | .tm_zone="MDT" | ||
1496 | }, | ||
1497 | .gmt_tm= { | ||
1498 | .tm_year=116, | ||
1499 | .tm_mon=2, | ||
1500 | .tm_mday=13, | ||
1501 | .tm_hour=9, | ||
1502 | .tm_min=0, | ||
1503 | .tm_sec=26, | ||
1504 | .tm_wday=0, | ||
1505 | .tm_yday=72, | ||
1506 | .tm_isdst=0, | ||
1507 | .tm_gmtoff=0, | ||
1508 | .tm_zone="GMT" | ||
1509 | }, | ||
1510 | }, | ||
1511 | { | ||
1512 | .descr="transition standard to daylight + 1", | ||
1513 | .timezone="right/America/Edmonton", | ||
1514 | .time=1457859627, | ||
1515 | .local_tm= { | ||
1516 | .tm_year=116, | ||
1517 | .tm_mon=2, | ||
1518 | .tm_mday=13, | ||
1519 | .tm_hour=3, | ||
1520 | .tm_min=0, | ||
1521 | .tm_sec=1, | ||
1522 | .tm_wday=0, | ||
1523 | .tm_yday=72, | ||
1524 | .tm_isdst=1, | ||
1525 | .tm_gmtoff=-21600, | ||
1526 | .tm_zone="MDT" | ||
1527 | }, | ||
1528 | .gmt_tm= { | ||
1529 | .tm_year=116, | ||
1530 | .tm_mon=2, | ||
1531 | .tm_mday=13, | ||
1532 | .tm_hour=9, | ||
1533 | .tm_min=0, | ||
1534 | .tm_sec=27, | ||
1535 | .tm_wday=0, | ||
1536 | .tm_yday=72, | ||
1537 | .tm_isdst=0, | ||
1538 | .tm_gmtoff=0, | ||
1539 | .tm_zone="GMT" | ||
1540 | }, | ||
1541 | }, | ||
1542 | { | ||
1543 | .descr="transition daylight to standard - 1", | ||
1544 | .timezone="posix/America/Edmonton", | ||
1545 | .time=1478419199, | ||
1546 | .local_tm= { | ||
1547 | .tm_year=116, | ||
1548 | .tm_mon=10, | ||
1549 | .tm_mday=6, | ||
1550 | .tm_hour=1, | ||
1551 | .tm_min=59, | ||
1552 | .tm_sec=59, | ||
1553 | .tm_wday=0, | ||
1554 | .tm_yday=310, | ||
1555 | .tm_isdst=1, | ||
1556 | .tm_gmtoff=-21600, | ||
1557 | .tm_zone="MDT" | ||
1558 | }, | ||
1559 | .gmt_tm= { | ||
1560 | .tm_year=116, | ||
1561 | .tm_mon=10, | ||
1562 | .tm_mday=6, | ||
1563 | .tm_hour=7, | ||
1564 | .tm_min=59, | ||
1565 | .tm_sec=59, | ||
1566 | .tm_wday=0, | ||
1567 | .tm_yday=310, | ||
1568 | .tm_isdst=0, | ||
1569 | .tm_gmtoff=0, | ||
1570 | .tm_zone="GMT" | ||
1571 | }, | ||
1572 | }, | ||
1573 | { | ||
1574 | .descr="transition daylight to standard", | ||
1575 | .timezone="posix/America/Edmonton", | ||
1576 | .time=1478419200, | ||
1577 | .local_tm= { | ||
1578 | .tm_year=116, | ||
1579 | .tm_mon=10, | ||
1580 | .tm_mday=6, | ||
1581 | .tm_hour=1, | ||
1582 | .tm_min=0, | ||
1583 | .tm_sec=0, | ||
1584 | .tm_wday=0, | ||
1585 | .tm_yday=310, | ||
1586 | .tm_isdst=0, | ||
1587 | .tm_gmtoff=-25200, | ||
1588 | .tm_zone="MST" | ||
1589 | }, | ||
1590 | .gmt_tm= { | ||
1591 | .tm_year=116, | ||
1592 | .tm_mon=10, | ||
1593 | .tm_mday=6, | ||
1594 | .tm_hour=8, | ||
1595 | .tm_min=0, | ||
1596 | .tm_sec=0, | ||
1597 | .tm_wday=0, | ||
1598 | .tm_yday=310, | ||
1599 | .tm_isdst=0, | ||
1600 | .tm_gmtoff=0, | ||
1601 | .tm_zone="GMT" | ||
1602 | }, | ||
1603 | }, | ||
1604 | { | ||
1605 | .descr="transition daylight to standard + 1", | ||
1606 | .timezone="posix/America/Edmonton", | ||
1607 | .time=1478419201, | ||
1608 | .local_tm= { | ||
1609 | .tm_year=116, | ||
1610 | .tm_mon=10, | ||
1611 | .tm_mday=6, | ||
1612 | .tm_hour=1, | ||
1613 | .tm_min=0, | ||
1614 | .tm_sec=1, | ||
1615 | .tm_wday=0, | ||
1616 | .tm_yday=310, | ||
1617 | .tm_isdst=0, | ||
1618 | .tm_gmtoff=-25200, | ||
1619 | .tm_zone="MST" | ||
1620 | }, | ||
1621 | .gmt_tm= { | ||
1622 | .tm_year=116, | ||
1623 | .tm_mon=10, | ||
1624 | .tm_mday=6, | ||
1625 | .tm_hour=8, | ||
1626 | .tm_min=0, | ||
1627 | .tm_sec=1, | ||
1628 | .tm_wday=0, | ||
1629 | .tm_yday=310, | ||
1630 | .tm_isdst=0, | ||
1631 | .tm_gmtoff=0, | ||
1632 | .tm_zone="GMT" | ||
1633 | }, | ||
1634 | }, | ||
1635 | { | ||
1636 | .descr="transition daylight to standard - 1", | ||
1637 | .timezone="right/America/Edmonton", | ||
1638 | .time=1478419225, | ||
1639 | .local_tm= { | ||
1640 | .tm_year=116, | ||
1641 | .tm_mon=10, | ||
1642 | .tm_mday=6, | ||
1643 | .tm_hour=1, | ||
1644 | .tm_min=59, | ||
1645 | .tm_sec=59, | ||
1646 | .tm_wday=0, | ||
1647 | .tm_yday=310, | ||
1648 | .tm_isdst=1, | ||
1649 | .tm_gmtoff=-21600, | ||
1650 | .tm_zone="MDT" | ||
1651 | }, | ||
1652 | .gmt_tm= { | ||
1653 | .tm_year=116, | ||
1654 | .tm_mon=10, | ||
1655 | .tm_mday=6, | ||
1656 | .tm_hour=8, | ||
1657 | .tm_min=0, | ||
1658 | .tm_sec=25, | ||
1659 | .tm_wday=0, | ||
1660 | .tm_yday=310, | ||
1661 | .tm_isdst=0, | ||
1662 | .tm_gmtoff=0, | ||
1663 | .tm_zone="GMT" | ||
1664 | }, | ||
1665 | }, | ||
1666 | { | ||
1667 | .descr="transition daylight to standard", | ||
1668 | .timezone="right/America/Edmonton", | ||
1669 | .time=1478419226, | ||
1670 | .local_tm= { | ||
1671 | .tm_year=116, | ||
1672 | .tm_mon=10, | ||
1673 | .tm_mday=6, | ||
1674 | .tm_hour=1, | ||
1675 | .tm_min=0, | ||
1676 | .tm_sec=0, | ||
1677 | .tm_wday=0, | ||
1678 | .tm_yday=310, | ||
1679 | .tm_isdst=0, | ||
1680 | .tm_gmtoff=-25200, | ||
1681 | .tm_zone="MST" | ||
1682 | }, | ||
1683 | .gmt_tm= { | ||
1684 | .tm_year=116, | ||
1685 | .tm_mon=10, | ||
1686 | .tm_mday=6, | ||
1687 | .tm_hour=8, | ||
1688 | .tm_min=0, | ||
1689 | .tm_sec=26, | ||
1690 | .tm_wday=0, | ||
1691 | .tm_yday=310, | ||
1692 | .tm_isdst=0, | ||
1693 | .tm_gmtoff=0, | ||
1694 | .tm_zone="GMT" | ||
1695 | }, | ||
1696 | }, | ||
1697 | { | ||
1698 | .descr="transition daylight to standard + 1", | ||
1699 | .timezone="right/America/Edmonton", | ||
1700 | .time=1478419227, | ||
1701 | .local_tm= { | ||
1702 | .tm_year=116, | ||
1703 | .tm_mon=10, | ||
1704 | .tm_mday=6, | ||
1705 | .tm_hour=1, | ||
1706 | .tm_min=0, | ||
1707 | .tm_sec=1, | ||
1708 | .tm_wday=0, | ||
1709 | .tm_yday=310, | ||
1710 | .tm_isdst=0, | ||
1711 | .tm_gmtoff=-25200, | ||
1712 | .tm_zone="MST" | ||
1713 | }, | ||
1714 | .gmt_tm= { | ||
1715 | .tm_year=116, | ||
1716 | .tm_mon=10, | ||
1717 | .tm_mday=6, | ||
1718 | .tm_hour=8, | ||
1719 | .tm_min=0, | ||
1720 | .tm_sec=27, | ||
1721 | .tm_wday=0, | ||
1722 | .tm_yday=310, | ||
1723 | .tm_isdst=0, | ||
1724 | .tm_gmtoff=0, | ||
1725 | .tm_zone="GMT" | ||
1726 | }, | ||
1727 | }, | ||
1728 | { | ||
1729 | .descr = NULL, | ||
1730 | }, | ||
1731 | }; | ||
1732 | |||
1733 | void printtm(FILE *f, struct tm *tm) | ||
1734 | { | ||
1735 | fprintf(f, "\t\t{\n\t\t\t.tm_year=%d,\n\t\t\t.tm_mon=%d,\n\t\t\t" | ||
1736 | ".tm_mday=%d,\n\t\t\t.tm_hour=%d,\n\t\t\t.tm_min=%d,\n\t\t\t" | ||
1737 | ".tm_sec=%d,\n\t\t\t.tm_wday=%d,\n\t\t\t.tm_yday=%d,\n\t\t\t" | ||
1738 | ".tm_isdst=%d,\n\t\t\t.tm_gmtoff=%ld,\n\t\t\t.tm_zone=\"%s\"" | ||
1739 | "\n\t\t},\n", | ||
1740 | tm->tm_year, | ||
1741 | tm->tm_mon, | ||
1742 | tm->tm_mday, | ||
1743 | tm->tm_hour, | ||
1744 | tm->tm_min, | ||
1745 | tm->tm_sec, | ||
1746 | tm->tm_wday, | ||
1747 | tm->tm_yday, | ||
1748 | tm->tm_isdst, | ||
1749 | tm->tm_gmtoff, | ||
1750 | tm->tm_zone); | ||
1751 | } | ||
1752 | |||
1753 | int dotimetest(struct timetest *test, int print) | ||
1754 | { | ||
1755 | int failures = 0; | ||
1756 | struct tm local = {}, gmt = {}; | ||
1757 | time_t converted; | ||
1758 | if (gmtime_r(&test->time, &gmt) == NULL) { | ||
1759 | memset(&gmt, 0, sizeof(gmt)); | ||
1760 | gmt.tm_zone="FAILURE"; | ||
1761 | } else { | ||
1762 | converted = timegm(&gmt); | ||
1763 | if (converted != test->time) { | ||
1764 | fprintf(stderr, "FAIL: test \"%s\", tz \"%s\" timegm " | ||
1765 | "does not match expected value\n", test->descr, | ||
1766 | test->timezone); | ||
1767 | fprintf(stderr, "expected: %lld\n", test->time); | ||
1768 | fprintf(stderr, "actual: %lld\n", converted); | ||
1769 | failures++; | ||
1770 | } | ||
1771 | } | ||
1772 | if (!tm_match(&test->gmt_tm, &gmt)) { | ||
1773 | fprintf(stderr, "FAIL: test \"%s\", tz \"%s\" gmtime_r does not" | ||
1774 | " match expected value\n", test->descr, test->timezone); | ||
1775 | fprintf(stderr, "expected: "); | ||
1776 | printtm(stderr, &test->gmt_tm); | ||
1777 | fprintf(stderr, "actual: "); | ||
1778 | printtm(stderr, &gmt); | ||
1779 | failures++; | ||
1780 | } | ||
1781 | setenv("TZ", test->timezone, 1); | ||
1782 | if (localtime_r(&test->time, &local) == NULL) { | ||
1783 | memset(&local, 0, sizeof(local)); | ||
1784 | local.tm_zone="FAILURE"; | ||
1785 | } else { | ||
1786 | converted = mktime(&local); | ||
1787 | if (converted != test->time) { | ||
1788 | fprintf(stderr, "FAIL: test \"%s\", tz \"%s\" mktime " | ||
1789 | "does not match expected value\n", test->descr, | ||
1790 | test->timezone); | ||
1791 | fprintf(stderr, "expected: %lld\n", test->time); | ||
1792 | fprintf(stderr, "actual: %lld\n", converted); | ||
1793 | failures++; | ||
1794 | } | ||
1795 | } | ||
1796 | if (!tm_match(&test->local_tm, &local)) { | ||
1797 | fprintf(stderr, "FAIL: test \"%s\", tz \"%s\" localtime_r does " | ||
1798 | "not match expected value\n", test->descr, test->timezone); | ||
1799 | fprintf(stderr, "expected: "); | ||
1800 | printtm(stderr, &test->local_tm); | ||
1801 | fprintf(stderr, "actual: "); | ||
1802 | printtm(stderr, &local); | ||
1803 | failures++; | ||
1804 | } | ||
1805 | if (print) { | ||
1806 | printf("\t{\n\t\t.descr=\"%s\",\n\t\t.timezone=\"%s\",\n\t\t" | ||
1807 | ".time=%lld,\n", test->descr, test->timezone, test->time); | ||
1808 | printf("\t\t.local_tm="); | ||
1809 | printtm(stdout, &local); | ||
1810 | printf("\t\t.gmt_tm="); | ||
1811 | printtm(stdout, &gmt); | ||
1812 | printf("\t},\n"); | ||
1813 | } | ||
1814 | return failures; | ||
1815 | } | ||
1816 | |||
1817 | |||
1818 | void printtmdescr(FILE *f, struct tm *tm, char * descr) | ||
1819 | { | ||
1820 | fprintf(f, "%s: ", descr); | ||
1821 | printtm(f, tm); | ||
1822 | } | ||
1823 | |||
1824 | int main() { | ||
1825 | int failures = 0; | ||
1826 | int verbose = 0; | ||
1827 | struct stat sb; | ||
1828 | size_t i; | ||
1829 | |||
1830 | if (stat("/usr/share/zoneinfo/posix", &sb) == -1 || | ||
1831 | stat("/usr/share/zoneinfo/right", &sb) == -1) { | ||
1832 | fprintf(stderr, "POSIX time zones missing, run the following command:\n\n" | ||
1833 | "\tmake -C ../../../../../share/zoneinfo other_two\n\n" | ||
1834 | "SKIPPED\n"); | ||
1835 | exit(0); | ||
1836 | } | ||
1837 | |||
1838 | for (i = 0; timetests[i].descr != NULL; i++) { | ||
1839 | failures += dotimetest(&timetests[i], verbose); | ||
1840 | } | ||
1841 | if (failures) | ||
1842 | fprintf(stderr, "FAIL: %d time test failures\n", failures); | ||
1843 | else | ||
1844 | printf("SUCCESS: no time test failures\n"); | ||
1845 | exit(failures); | ||
1846 | } | ||
1847 | |||
diff --git a/src/regress/lib/libc/timekeep/Makefile b/src/regress/lib/libc/timekeep/Makefile deleted file mode 100644 index ed7dc60379..0000000000 --- a/src/regress/lib/libc/timekeep/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2020/07/06 13:33:06 pirofti Exp $ | ||
2 | |||
3 | PROGS= test_clock_gettime test_time_skew test_gettimeofday | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/timekeep/test_clock_gettime.c b/src/regress/lib/libc/timekeep/test_clock_gettime.c deleted file mode 100644 index cc1d8e36e3..0000000000 --- a/src/regress/lib/libc/timekeep/test_clock_gettime.c +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | /* $OpenBSD: test_clock_gettime.c,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2020 Paul Irofti <paul@irofti.net> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <assert.h> | ||
19 | #include <time.h> | ||
20 | |||
21 | #define ASSERT_EQ(a, b) assert((a) == (b)) | ||
22 | |||
23 | void | ||
24 | check() | ||
25 | { | ||
26 | struct timespec tp = {0}; | ||
27 | |||
28 | ASSERT_EQ(0, clock_gettime(CLOCK_REALTIME, &tp)); | ||
29 | ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &tp)); | ||
30 | ASSERT_EQ(0, clock_gettime(CLOCK_BOOTTIME, &tp)); | ||
31 | ASSERT_EQ(0, clock_gettime(CLOCK_UPTIME, &tp)); | ||
32 | |||
33 | |||
34 | ASSERT_EQ(0, clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp)); | ||
35 | ASSERT_EQ(0, clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)); | ||
36 | |||
37 | } | ||
38 | |||
39 | int main() | ||
40 | { | ||
41 | check(); | ||
42 | return 0; | ||
43 | } | ||
diff --git a/src/regress/lib/libc/timekeep/test_gettimeofday.c b/src/regress/lib/libc/timekeep/test_gettimeofday.c deleted file mode 100644 index 914058505d..0000000000 --- a/src/regress/lib/libc/timekeep/test_gettimeofday.c +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | /* $OpenBSD: test_gettimeofday.c,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2020 Paul Irofti <paul@irofti.net> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <assert.h> | ||
19 | #include <sys/time.h> | ||
20 | |||
21 | #define ASSERT_EQ(a, b) assert((a) == (b)) | ||
22 | |||
23 | void | ||
24 | check() | ||
25 | { | ||
26 | struct timeval tv = {0}; | ||
27 | struct timezone tzp; | ||
28 | |||
29 | ASSERT_EQ(0, gettimeofday(&tv, NULL)); | ||
30 | ASSERT_EQ(0, gettimeofday(&tv, &tzp)); | ||
31 | } | ||
32 | |||
33 | int main() | ||
34 | { | ||
35 | check(); | ||
36 | return 0; | ||
37 | } | ||
diff --git a/src/regress/lib/libc/timekeep/test_time_skew.c b/src/regress/lib/libc/timekeep/test_time_skew.c deleted file mode 100644 index 7871795f06..0000000000 --- a/src/regress/lib/libc/timekeep/test_time_skew.c +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | /* $OpenBSD: test_time_skew.c,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2020 Paul Irofti <paul@irofti.net> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <sys/time.h> | ||
19 | |||
20 | #include <assert.h> | ||
21 | #include <time.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <stdio.h> | ||
24 | |||
25 | #define ASSERT_EQ(a, b) assert((a) == (b)) | ||
26 | #define ASSERT_NE(a, b) assert((a) != (b)) | ||
27 | |||
28 | void | ||
29 | check() | ||
30 | { | ||
31 | struct timespec tp1, tp2, tout; | ||
32 | |||
33 | tout.tv_sec = 0; | ||
34 | tout.tv_nsec = 100000; | ||
35 | |||
36 | ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &tp1)); | ||
37 | |||
38 | nanosleep(&tout, NULL); | ||
39 | |||
40 | ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &tp2)); | ||
41 | |||
42 | /* tp1 should never be larger than tp2 */ | ||
43 | ASSERT_NE(1, timespeccmp(&tp1, &tp2, >)); | ||
44 | } | ||
45 | |||
46 | int | ||
47 | main(void) | ||
48 | { | ||
49 | int i; | ||
50 | |||
51 | for (i = 0; i < 1000; i++) | ||
52 | check(); | ||
53 | |||
54 | return 0; | ||
55 | } | ||
diff --git a/src/regress/lib/libc/timingsafe/Makefile b/src/regress/lib/libc/timingsafe/Makefile deleted file mode 100644 index 9a679b61f8..0000000000 --- a/src/regress/lib/libc/timingsafe/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2014/06/13 01:55:02 matthew Exp $ | ||
2 | |||
3 | PROG= timingsafe | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/timingsafe/timingsafe.c b/src/regress/lib/libc/timingsafe/timingsafe.c deleted file mode 100644 index d768a808b6..0000000000 --- a/src/regress/lib/libc/timingsafe/timingsafe.c +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
1 | /* $OpenBSD: timingsafe.c,v 1.4 2024/02/04 20:51:21 tb Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2014 Google Inc. | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <assert.h> | ||
19 | #include <stdlib.h> | ||
20 | #include <string.h> | ||
21 | |||
22 | #define ASSERT_EQ(a, b) assert((a) == (b)) | ||
23 | |||
24 | enum { | ||
25 | N = 8 | ||
26 | }; | ||
27 | |||
28 | static unsigned char bufone[N], buftwo[N]; | ||
29 | |||
30 | void | ||
31 | check(void) | ||
32 | { | ||
33 | int cmp = memcmp(bufone, buftwo, N); | ||
34 | |||
35 | /* Check for reflexivity. */ | ||
36 | ASSERT_EQ(0, timingsafe_bcmp(bufone, bufone, N)); | ||
37 | ASSERT_EQ(0, timingsafe_bcmp(buftwo, buftwo, N)); | ||
38 | ASSERT_EQ(0, timingsafe_memcmp(bufone, bufone, N)); | ||
39 | ASSERT_EQ(0, timingsafe_memcmp(buftwo, buftwo, N)); | ||
40 | |||
41 | /* Check that timingsafe_bcmp returns 0 iff memcmp returns 0. */ | ||
42 | ASSERT_EQ(cmp == 0, timingsafe_bcmp(bufone, buftwo, N) == 0); | ||
43 | |||
44 | /* Check that timingsafe_memcmp returns cmp... */ | ||
45 | ASSERT_EQ(cmp < 0, timingsafe_memcmp(bufone, buftwo, N) < 0); | ||
46 | |||
47 | /* ... or -cmp if the argument order is swapped. */ | ||
48 | ASSERT_EQ(-cmp < 0, timingsafe_memcmp(buftwo, bufone, N) < 0); | ||
49 | } | ||
50 | |||
51 | int | ||
52 | main(void) | ||
53 | { | ||
54 | int i, j; | ||
55 | |||
56 | for (i = 0; i < 10000; i++) { | ||
57 | arc4random_buf(bufone, N); | ||
58 | arc4random_buf(buftwo, N); | ||
59 | |||
60 | check(); | ||
61 | for (j = 0; j < N; j++) { | ||
62 | buftwo[j] = bufone[j]; | ||
63 | check(); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | return (0); | ||
68 | } | ||
diff --git a/src/regress/lib/libc/uuid/Makefile b/src/regress/lib/libc/uuid/Makefile deleted file mode 100644 index 301f08fc3a..0000000000 --- a/src/regress/lib/libc/uuid/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2021/08/31 09:57:27 jasper Exp $ | ||
2 | |||
3 | PROG= uuidtest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/uuid/uuidtest.c b/src/regress/lib/libc/uuid/uuidtest.c deleted file mode 100644 index 9f6fd0175d..0000000000 --- a/src/regress/lib/libc/uuid/uuidtest.c +++ /dev/null | |||
@@ -1,261 +0,0 @@ | |||
1 | /* $OpenBSD: uuidtest.c,v 1.2 2023/07/03 13:51:55 jasper Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2021, 2023 Jasper Lievisse Adriaanse <jasper@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <assert.h> | ||
19 | #include <stdio.h> | ||
20 | #include <stdlib.h> | ||
21 | #include <string.h> | ||
22 | #include <uuid.h> | ||
23 | |||
24 | #define ASSERT_EQ(a, b) assert((a) == (b)) | ||
25 | |||
26 | int | ||
27 | main(int argc, char **argv) | ||
28 | { | ||
29 | struct uuid uuid, uuid2, uuid_want; | ||
30 | char *uuid_str, *uuid_str_want; | ||
31 | uint32_t status; | ||
32 | unsigned char bin[16]; | ||
33 | int rc, t = 1; | ||
34 | |||
35 | /* Test invalid input to uuid_from_string() */ | ||
36 | printf("[%d] uuid_from_string (invalid) ", t); | ||
37 | uuid_str = "6fc3134d-011d-463d-a6b4-fe1f3a5e57dX"; | ||
38 | uuid_from_string(uuid_str, &uuid, &status); | ||
39 | if (status != uuid_s_invalid_string_uuid) { | ||
40 | printf("failed to return uuid_s_invalid_string_uuid for '%s'\n", | ||
41 | uuid_str); | ||
42 | return 1; | ||
43 | } | ||
44 | |||
45 | printf("ok\n"); | ||
46 | t++; | ||
47 | |||
48 | /* Test a bad version gets recognized */ | ||
49 | printf("[%d] uuid_from_string (bad version) ", t); | ||
50 | uuid_str = "ffffffff-ffff-ffff-ffff-ffffffffffff"; | ||
51 | uuid_from_string(uuid_str, &uuid, &status); | ||
52 | if (status != uuid_s_bad_version) { | ||
53 | printf("failed to return uuid_s_bad_version for '%s'\n", | ||
54 | uuid_str); | ||
55 | return 1; | ||
56 | } | ||
57 | |||
58 | printf("ok\n"); | ||
59 | t++; | ||
60 | |||
61 | /* Test valid input to uuid_from_string() */ | ||
62 | printf("[%d] uuid_from_string ", t); | ||
63 | uuid_str = "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"; | ||
64 | |||
65 | uuid_want.time_low = 0xf81d4fae; | ||
66 | uuid_want.time_mid = 0x7dec; | ||
67 | uuid_want.time_hi_and_version = 0x11d0; | ||
68 | uuid_want.clock_seq_hi_and_reserved = 0xa7; | ||
69 | uuid_want.clock_seq_low = 0x65; | ||
70 | uuid_want.node[0] = 0x00; | ||
71 | uuid_want.node[1] = 0xa0; | ||
72 | uuid_want.node[2] = 0xc9; | ||
73 | uuid_want.node[3] = 0x1e; | ||
74 | uuid_want.node[4] = 0x6b; | ||
75 | uuid_want.node[5] = 0xf6; | ||
76 | |||
77 | uuid_from_string(uuid_str, &uuid, &status); | ||
78 | if (status != uuid_s_ok) { | ||
79 | printf("failed to return uuid_s_ok for '%s', got %d\n", uuid_str, status); | ||
80 | return 1; | ||
81 | } | ||
82 | |||
83 | ASSERT_EQ(uuid.time_low, uuid_want.time_low); | ||
84 | ASSERT_EQ(uuid.time_mid, uuid_want.time_mid); | ||
85 | ASSERT_EQ(uuid.time_hi_and_version, uuid_want.time_hi_and_version); | ||
86 | ASSERT_EQ(uuid.clock_seq_hi_and_reserved, uuid_want.clock_seq_hi_and_reserved); | ||
87 | ASSERT_EQ(uuid.clock_seq_low, uuid_want.clock_seq_low); | ||
88 | ASSERT_EQ(uuid.node[0], uuid_want.node[0]); | ||
89 | ASSERT_EQ(uuid.node[1], uuid_want.node[1]); | ||
90 | ASSERT_EQ(uuid.node[2], uuid_want.node[2]); | ||
91 | ASSERT_EQ(uuid.node[3], uuid_want.node[3]); | ||
92 | ASSERT_EQ(uuid.node[4], uuid_want.node[4]); | ||
93 | ASSERT_EQ(uuid.node[5], uuid_want.node[5]); | ||
94 | |||
95 | printf("ok\n"); | ||
96 | t++; | ||
97 | |||
98 | printf("[%d] uuid_to_string ", t); | ||
99 | /* re-use the handrolled struct uuid from the previous test. */ | ||
100 | uuid_str_want = "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"; | ||
101 | |||
102 | uuid_to_string(&uuid, &uuid_str, &status); | ||
103 | if (status != uuid_s_ok) { | ||
104 | printf("failed to return uuid_s_ok, got %d\n", status); | ||
105 | return 1; | ||
106 | } | ||
107 | |||
108 | if (strcmp(uuid_str, uuid_str_want) != 0) { | ||
109 | printf("expected '%s', got '%s'\n", uuid_str_want, uuid_str); | ||
110 | return 1; | ||
111 | } | ||
112 | |||
113 | printf("ok\n"); | ||
114 | t++; | ||
115 | |||
116 | printf("[%d] uuid_create_nil ", t); | ||
117 | uuid_create_nil(&uuid, &status); | ||
118 | if (status != uuid_s_ok) { | ||
119 | printf("failed to return uuid_s_ok, got: %d\n", status); | ||
120 | return 1; | ||
121 | } | ||
122 | |||
123 | /* | ||
124 | * At this point we've done a previous test of uuid_to_string already, | ||
125 | * so might as well use it again for uuid_create_nil() here. | ||
126 | */ | ||
127 | uuid_to_string(&uuid, &uuid_str, &status); | ||
128 | if (status != uuid_s_ok) { | ||
129 | printf("uuid_to_string failed to return uuid_s_ok, got %d\n", | ||
130 | status); | ||
131 | return 1; | ||
132 | } | ||
133 | |||
134 | uuid_str_want = "00000000-0000-0000-0000-000000000000"; | ||
135 | if (strcmp(uuid_str, uuid_str_want) != 0) { | ||
136 | printf("expected '%s', got '%s'\n", uuid_str_want, uuid_str); | ||
137 | return 1; | ||
138 | } | ||
139 | |||
140 | printf("ok\n"); | ||
141 | t++; | ||
142 | |||
143 | /* | ||
144 | * Assuming the clock of the system running the test is ahead of the one | ||
145 | * where this test was written, we can test uuid_create along with | ||
146 | * uuid_compare here. | ||
147 | */ | ||
148 | printf("[%d] uuid_create ", t); | ||
149 | uuid_create(&uuid, &status); | ||
150 | if (status != uuid_s_ok) { | ||
151 | printf("uuid_create failed to return uuid_s_ok, got %d\n", | ||
152 | status); | ||
153 | return 1; | ||
154 | } | ||
155 | |||
156 | printf("ok\n"); | ||
157 | t++; | ||
158 | |||
159 | printf("[%d] uuid_compare ", t); | ||
160 | /* uuid was just generated, uuid2 was generated before. */ | ||
161 | uuid_from_string(uuid_str, &uuid2, &status); | ||
162 | rc = uuid_compare(&uuid, &uuid2, &status); | ||
163 | if ((status != uuid_s_ok) || (rc != 1)) { | ||
164 | printf("uuid_compare failed, expected 1 got: %d and status: %d\n", | ||
165 | rc, status); | ||
166 | return 1; | ||
167 | } | ||
168 | |||
169 | printf("ok\n"); | ||
170 | t++; | ||
171 | |||
172 | printf("[%d] uuid_equal ", t); | ||
173 | rc = uuid_equal(&uuid, &uuid, &status); | ||
174 | if ((status != uuid_s_ok) || (rc != 1)) { | ||
175 | printf("uuid_compare failed, expected 1 got: %d and status: %d\n", | ||
176 | rc, status); | ||
177 | return 1; | ||
178 | } | ||
179 | |||
180 | printf("ok\n"); | ||
181 | t++; | ||
182 | |||
183 | printf("[%d] uuid_equal (nil) ", t); | ||
184 | uuid_create_nil(&uuid, &status); | ||
185 | rc = uuid_equal(&uuid, &uuid2, &status); | ||
186 | if ((status != uuid_s_ok) || (rc != 1)) { | ||
187 | printf("uuid_compare failed, expected 1 got: %d and status: %d\n", | ||
188 | rc, status); | ||
189 | return 1; | ||
190 | } | ||
191 | |||
192 | printf("ok\n"); | ||
193 | t++; | ||
194 | |||
195 | printf("[%d] uuid_hash ", t); | ||
196 | uint16_t hash = uuid_hash(&uuid_want, &status); | ||
197 | if ((status != uuid_s_ok) || (hash != 0x4fae)) { | ||
198 | printf("uuid_hash failed, expected 0x4fae got: 0x%04x and status: %d\n", | ||
199 | hash, status); | ||
200 | return 1; | ||
201 | } | ||
202 | |||
203 | printf("ok\n"); | ||
204 | t++; | ||
205 | |||
206 | uuid_str_want = "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"; | ||
207 | printf("[%d] uuid_enc_le ", t); | ||
208 | uuid_from_string(uuid_str_want, &uuid, &status); | ||
209 | /* | ||
210 | * Check two fields to ensure they're in the right order. | ||
211 | * If these two are ok, it's safe to assum the rest are too. | ||
212 | */ | ||
213 | uuid_enc_le(bin, &uuid); | ||
214 | if (bin[4] != 0xec || bin[5] != 0x7d) { | ||
215 | uuid_to_string(&uuid, &uuid_str, &status); | ||
216 | printf("uuid_enc_le failed, expected %s got %s\n", | ||
217 | uuid_str_want, uuid_str); | ||
218 | return 1; | ||
219 | } | ||
220 | |||
221 | printf("ok\n"); | ||
222 | t++; | ||
223 | |||
224 | printf("[%d] uuid_dec_le ", t); | ||
225 | uuid_dec_le(bin, &uuid); | ||
226 | if (uuid_equal(&uuid, &uuid_want, &status) == 0) { | ||
227 | uuid_to_string(&uuid, &uuid_str, &status); | ||
228 | printf("uuid_dec_le failed, expected %s got %s\n", | ||
229 | uuid_str_want, uuid_str); | ||
230 | return 1; | ||
231 | } | ||
232 | |||
233 | printf("ok\n"); | ||
234 | t++; | ||
235 | |||
236 | printf("[%d] uuid_enc_be ", t); | ||
237 | uuid_enc_be(bin, &uuid); | ||
238 | if (bin[4] != 0x7d || bin[5] != 0xec) { | ||
239 | uuid_to_string(&uuid, &uuid_str, &status); | ||
240 | printf("uuid_enc_be failed, expected %s got %s\n", | ||
241 | uuid_str_want, uuid_str); | ||
242 | return 1; | ||
243 | } | ||
244 | |||
245 | printf("ok\n"); | ||
246 | t++; | ||
247 | |||
248 | printf("[%d] uuid_dec_be ", t); | ||
249 | uuid_dec_be(bin, &uuid); | ||
250 | if (uuid_equal(&uuid, &uuid_want, &status) == 0) { | ||
251 | uuid_to_string(&uuid, &uuid_str, &status); | ||
252 | printf("uuid_dec_be failed, expected %s got %s\n", | ||
253 | uuid_str_want, uuid_str); | ||
254 | return 1; | ||
255 | } | ||
256 | |||
257 | printf("ok\n"); | ||
258 | t++; | ||
259 | |||
260 | return 0; | ||
261 | } | ||
diff --git a/src/regress/lib/libc/vis/Makefile b/src/regress/lib/libc/vis/Makefile deleted file mode 100644 index 13e560bbf7..0000000000 --- a/src/regress/lib/libc/vis/Makefile +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2005/08/29 18:41:56 otto Exp $ | ||
2 | |||
3 | PROG= vis_test | ||
4 | CLEANFILES+= valid.out | ||
5 | |||
6 | run-regress-vis_test: ${PROG} | ||
7 | ./${PROG} >${.OBJDIR}/valid.out | ||
8 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/vis/valid.ok b/src/regress/lib/libc/vis/valid.ok deleted file mode 100644 index f8c0efa503..0000000000 --- a/src/regress/lib/libc/vis/valid.ok +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | \^@\^A\^B\^C\^D\^E\^F\^G\^H | ||
2 | \^K\^L\^M\^N\^O\^P\^Q\^R\^S\^T\^U\^V\^W\^X\^Y\^Z\^[\^\\^]\^^\^_ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\^?\M^@\M^A\M^B\M^C\M^D\M^E\M^F\M^G\M^H\M^I\M^J\M^K\M^L\M^M\M^N\M^O\M^P\M^Q\M^R\M^S\M^T\M^U\M^V\M^W\M^X\M^Y\M^Z\M^[\M^\\M^]\M^^\M^_\240\M-!\M-"\M-#\M-$\M-%\M-&\M-'\M-(\M-)\M-*\M-+\M-,\M--\M-.\M-/\M-0\M-1\M-2\M-3\M-4\M-5\M-6\M-7\M-8\M-9\M-:\M-;\M-<\M-=\M->\M-?\M-@\M-A\M-B\M-C\M-D\M-E\M-F\M-G\M-H\M-I\M-J\M-K\M-L\M-M\M-N\M-O\M-P\M-Q\M-R\M-S\M-T\M-U\M-V\M-W\M-X\M-Y\M-Z\M-[\M-\\M-]\M-^\M-_\M-`\M-a\M-b\M-c\M-d\M-e\M-f\M-g\M-h\M-i\M-j\M-k\M-l\M-m\M-n\M-o\M-p\M-q\M-r\M-s\M-t\M-u\M-v\M-w\M-x\M-y\M-z\M-{\M-|\M-}\M-~\M^? | ||
diff --git a/src/regress/lib/libc/vis/vis_test.c b/src/regress/lib/libc/vis/vis_test.c deleted file mode 100644 index 92f2cee32d..0000000000 --- a/src/regress/lib/libc/vis/vis_test.c +++ /dev/null | |||
@@ -1,113 +0,0 @@ | |||
1 | /* $OpenBSD: vis_test.c,v 1.5 2017/07/27 15:08:37 bluhm Exp $ */ | ||
2 | |||
3 | /* Public domain. 2005, Otto Moerbeek */ | ||
4 | |||
5 | #include <limits.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <string.h> | ||
8 | #include <stdio.h> | ||
9 | #include <vis.h> | ||
10 | |||
11 | #define NTESTS 8000 | ||
12 | #define NCH 800 | ||
13 | |||
14 | char ibuf[NCH]; | ||
15 | char obuf[NCH * 4]; | ||
16 | char rbuf[NCH * 4]; | ||
17 | |||
18 | int flags[] = { | ||
19 | VIS_ALL, | ||
20 | VIS_GLOB, | ||
21 | VIS_TAB, | ||
22 | VIS_NL, | ||
23 | VIS_DQ, | ||
24 | VIS_WHITE, | ||
25 | VIS_SAFE | ||
26 | }; | ||
27 | |||
28 | char *flagname[] = { | ||
29 | "VIS_ALL", | ||
30 | "VIS_GLOB", | ||
31 | "VIS_TAB", | ||
32 | "VIS_NL", | ||
33 | "VIS_DQ", | ||
34 | "VIS_WHITE", | ||
35 | "VIS_SAFE" | ||
36 | }; | ||
37 | |||
38 | int title; | ||
39 | |||
40 | void | ||
41 | dotitle(int i, int j) | ||
42 | { | ||
43 | if (title == 0) | ||
44 | printf("%d %s:", i, flagname[j]); | ||
45 | title = 1; | ||
46 | } | ||
47 | |||
48 | int | ||
49 | main(int argc, char *argv[]) | ||
50 | { | ||
51 | |||
52 | char inp[UCHAR_MAX + 1]; | ||
53 | char out[4 * UCHAR_MAX + 1]; | ||
54 | int i, j, fail = 0; | ||
55 | ssize_t owant, o, r; | ||
56 | |||
57 | for (i = 0; i <= UCHAR_MAX; i++) { | ||
58 | inp[i] = i; | ||
59 | } | ||
60 | strvisx(out, inp, UCHAR_MAX + 1, 0); | ||
61 | printf("%s\n", out); | ||
62 | |||
63 | for (i = 0; i < NTESTS; i++) { | ||
64 | arc4random_buf(ibuf, sizeof(ibuf) - 1); | ||
65 | ibuf[sizeof(ibuf) - 1] = '\0'; | ||
66 | title = 0; | ||
67 | |||
68 | for (j = 0; j < sizeof(flags)/sizeof(flags[0]); j++) { | ||
69 | owant = sizeof(ibuf); | ||
70 | o = strnvis(obuf, ibuf, owant, flags[j]); | ||
71 | if (o >= owant) { | ||
72 | owant = o + 1; | ||
73 | o = strnvis(obuf, ibuf, owant, flags[j]); | ||
74 | if (o > owant) { | ||
75 | dotitle(i, j); | ||
76 | printf("HUGE overflow\n"); | ||
77 | } | ||
78 | if (o < owant - 1) { | ||
79 | dotitle(i, j); | ||
80 | printf("over-estimate of overflow\n"); | ||
81 | } | ||
82 | } else if (o > strlen(ibuf) * 4) { | ||
83 | dotitle(i, j); | ||
84 | printf("wants too much %zd %zu\n", | ||
85 | o, strlen(ibuf) * 4); | ||
86 | continue; | ||
87 | } | ||
88 | |||
89 | r = strnunvis(rbuf, obuf, sizeof rbuf); | ||
90 | |||
91 | if (r == -1) { | ||
92 | dotitle(i, j); | ||
93 | printf("cannot decode\n"); | ||
94 | printf("%s\n", obuf); | ||
95 | fail = 1; | ||
96 | } else if (r != strlen(ibuf)) { | ||
97 | dotitle(i, j); | ||
98 | printf("rlen %zd != inlen %zu\n", | ||
99 | r, strlen(ibuf)); | ||
100 | printf("%s\n", obuf); | ||
101 | printf("%s\n", rbuf); | ||
102 | fail = 1; | ||
103 | } else if (bcmp(ibuf, rbuf, r)) { | ||
104 | dotitle(i, j); | ||
105 | printf("strings are different\n"); | ||
106 | printf("%s\n", ibuf); | ||
107 | printf("%s\n", rbuf); | ||
108 | fail = 1; | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | exit(fail); | ||
113 | } | ||
diff --git a/src/regress/lib/libc/wprintf/Makefile b/src/regress/lib/libc/wprintf/Makefile deleted file mode 100644 index 7b1897f2c4..0000000000 --- a/src/regress/lib/libc/wprintf/Makefile +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2011/04/24 08:00:22 stsp Exp $ | ||
2 | |||
3 | PROG= wfp | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/wprintf/wfp.c b/src/regress/lib/libc/wprintf/wfp.c deleted file mode 100644 index fa9bc07166..0000000000 --- a/src/regress/lib/libc/wprintf/wfp.c +++ /dev/null | |||
@@ -1,227 +0,0 @@ | |||
1 | /* $OpenBSD: wfp.c,v 1.2 2020/01/13 16:51:04 bluhm Exp $ */ | ||
2 | /*- | ||
3 | * Copyright (c) 2002, 2005 David Schultz <das@FreeBSD.org> | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * | ||
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
25 | * SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | /* | ||
29 | * Test for wprintf() floating point formats. | ||
30 | */ | ||
31 | |||
32 | #include <assert.h> | ||
33 | #include <err.h> | ||
34 | #include <float.h> | ||
35 | #include <math.h> | ||
36 | #include <stdio.h> | ||
37 | #include <stdarg.h> | ||
38 | #include <stdint.h> | ||
39 | #include <stdlib.h> | ||
40 | #include <string.h> | ||
41 | #include <wchar.h> | ||
42 | |||
43 | #define testfmt(result, fmt, ...) \ | ||
44 | _testfmt((result), __LINE__, #__VA_ARGS__, fmt, __VA_ARGS__) | ||
45 | void _testfmt(const wchar_t *, int, const char *, const wchar_t *, ...); | ||
46 | void smash_stack(void); | ||
47 | |||
48 | int | ||
49 | main(int argc, char *argv[]) | ||
50 | { | ||
51 | /* | ||
52 | * Basic tests of decimal output functionality. | ||
53 | */ | ||
54 | testfmt(L" 1.000000E+00", L"%13E", 1.0); | ||
55 | testfmt(L" 1.000000", L"%13f", 1.0); | ||
56 | testfmt(L" 1", L"%13G", 1.0); | ||
57 | testfmt(L" 1.000000E+00", L"%13LE", 1.0L); | ||
58 | testfmt(L" 1.000000", L"%13Lf", 1.0L); | ||
59 | testfmt(L" 1", L"%13LG", 1.0L); | ||
60 | |||
61 | testfmt(L"2.718282", L"%.*f", -2, 2.7182818); | ||
62 | |||
63 | testfmt(L"1.234568e+06", L"%e", 1234567.8); | ||
64 | testfmt(L"1234567.800000", L"%f", 1234567.8); | ||
65 | testfmt(L"1.23457E+06", L"%G", 1234567.8); | ||
66 | testfmt(L"1.234568e+06", L"%Le", 1234567.8L); | ||
67 | testfmt(L"1234567.800000", L"%Lf", 1234567.8L); | ||
68 | testfmt(L"1.23457E+06", L"%LG", 1234567.8L); | ||
69 | |||
70 | #if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) | ||
71 | testfmt(L"123456789.864210", L"%Lf", 123456789.8642097531L); | ||
72 | testfmt(L"-1.23457E+08", L"%LG", -123456789.8642097531L); | ||
73 | testfmt(L"123456789.8642097531", L"%.10Lf", 123456789.8642097531L); | ||
74 | testfmt(L" 3.141592653589793238e-4000", L"%L27.18Le", | ||
75 | 3.14159265358979323846e-4000L); | ||
76 | #endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) */ | ||
77 | |||
78 | /* | ||
79 | * Infinities and NaNs | ||
80 | */ | ||
81 | #ifdef NAN | ||
82 | testfmt(L"nan", L"%e", NAN); | ||
83 | testfmt(L"NAN", L"%F", NAN); | ||
84 | testfmt(L"nan", L"%g", NAN); | ||
85 | testfmt(L"NAN", L"%LE", (long double)NAN); | ||
86 | testfmt(L" nan", L"%05e", NAN); | ||
87 | #endif /* NAN */ | ||
88 | |||
89 | testfmt(L"INF", L"%E", HUGE_VAL); | ||
90 | testfmt(L"-inf", L"%f", -HUGE_VAL); | ||
91 | testfmt(L"+inf", L"%+g", HUGE_VAL); | ||
92 | testfmt(L" inf", L"%4.2Le", HUGE_VALL); | ||
93 | testfmt(L"-inf", L"%Lf", -HUGE_VALL); | ||
94 | testfmt(L" inf", L"%05e", HUGE_VAL); | ||
95 | testfmt(L" -inf", L"%05e", -HUGE_VAL); | ||
96 | |||
97 | /* | ||
98 | * Padding | ||
99 | */ | ||
100 | testfmt(L"0.000000e+00", L"%e", 0.0); | ||
101 | testfmt(L"0.000000", L"%F", (double)0.0); | ||
102 | testfmt(L"0", L"%G", 0.0); | ||
103 | testfmt(L" 0", L"%3.0Lg", 0.0L); | ||
104 | testfmt(L" 0", L"%5.0f", 0.001); | ||
105 | |||
106 | /* | ||
107 | * Precision specifiers | ||
108 | */ | ||
109 | testfmt(L"1.0123e+00", L"%.4e", 1.0123456789); | ||
110 | testfmt(L"1.0123", L"%.4f", 1.0123456789); | ||
111 | testfmt(L"1.012", L"%.4g", 1.0123456789); | ||
112 | testfmt(L"1.2346e-02", L"%.4e", 0.0123456789); | ||
113 | testfmt(L"0.0123", L"%.4f", 0.0123456789); | ||
114 | testfmt(L"0.01235", L"%.4g", 0.0123456789); | ||
115 | |||
116 | /* | ||
117 | * Signed conversions | ||
118 | */ | ||
119 | testfmt(L"+2.500000e-01", L"%+e", 0.25); | ||
120 | testfmt(L"+0.000000", L"%+F", 0.0); | ||
121 | testfmt(L"-1", L"%+g", -1.0); | ||
122 | |||
123 | testfmt(L"-1.000000e+00", L"% e", -1.0); | ||
124 | testfmt(L"+1.000000", L"% +f", 1.0); | ||
125 | testfmt(L" 1", L"% g", 1.0); | ||
126 | testfmt(L" 0", L"% g", 0.0); | ||
127 | |||
128 | /* | ||
129 | * ``Alternate form'' | ||
130 | */ | ||
131 | testfmt(L"1.250e+00", L"%#.3e", 1.25); | ||
132 | testfmt(L"123.000000", L"%#f", 123.0); | ||
133 | testfmt(L" 12345.", L"%#7.5g", 12345.0); | ||
134 | testfmt(L" 1.00000", L"%#8g", 1.0); | ||
135 | testfmt(L"0.0", L"%#.2g", 0.0); | ||
136 | |||
137 | /* | ||
138 | * Padding and decimal point placement | ||
139 | */ | ||
140 | testfmt(L"03.2E+00", L"%08.1E", 3.25); | ||
141 | testfmt(L"003.25", L"%06.2F", 3.25); | ||
142 | testfmt(L"0003.25", L"%07.4G", 3.25); | ||
143 | |||
144 | testfmt(L"3.14159e-05", L"%g", 3.14159e-5); | ||
145 | testfmt(L"0.000314159", L"%g", 3.14159e-4); | ||
146 | testfmt(L"3.14159e+06", L"%g", 3.14159e6); | ||
147 | testfmt(L"314159", L"%g", 3.14159e5); | ||
148 | testfmt(L"314159.", L"%#g", 3.14159e5); | ||
149 | |||
150 | testfmt(L" 9.000000e+03", L"%13e", 9000.0); | ||
151 | testfmt(L" 9000.000000", L"%12f", 9000.0); | ||
152 | testfmt(L" 9000", L"%5g", 9000.0); | ||
153 | testfmt(L" 900000.", L"%#8g", 900000.0); | ||
154 | testfmt(L" 9e+06", L"%6g", 9000000.0); | ||
155 | testfmt(L" 9.000000e-04", L"%13e", 0.0009); | ||
156 | testfmt(L" 0.000900", L"%9f", 0.0009); | ||
157 | testfmt(L" 0.0009", L"%7g", 0.0009); | ||
158 | testfmt(L" 9e-05", L"%6g", 0.00009); | ||
159 | testfmt(L" 9.00000e-05", L"%#12g", 0.00009); | ||
160 | testfmt(L" 9.e-05", L"%#7.1g", 0.00009); | ||
161 | |||
162 | testfmt(L" 0.0", L"%4.1f", 0.0); | ||
163 | testfmt(L"90.0", L"%4.1f", 90.0); | ||
164 | testfmt(L" 100", L"%4.0f", 100.0); | ||
165 | testfmt(L"9.0e+01", L"%4.1e", 90.0); | ||
166 | testfmt(L"1e+02", L"%4.0e", 100.0); | ||
167 | |||
168 | /* | ||
169 | * Hexadecimal floating point (%a, %A) tests. Some of these | ||
170 | * are only valid if the implementation converts to hex digits | ||
171 | * on nibble boundaries. | ||
172 | */ | ||
173 | testfmt(L"0x0p+0", L"%a", 0x0.0p0); | ||
174 | testfmt(L"0X0.P+0", L"%#LA", 0x0.0p0L); | ||
175 | #ifdef NAN | ||
176 | testfmt(L"inf", L"%La", (long double)INFINITY); | ||
177 | testfmt(L"+INF", L"%+A", INFINITY); | ||
178 | testfmt(L"nan", L"%La", (long double)NAN); | ||
179 | testfmt(L"NAN", L"%A", NAN); | ||
180 | #endif /* NAN */ | ||
181 | |||
182 | testfmt(L" 0x1.23p+0", L"%10a", 0x1.23p0); | ||
183 | testfmt(L" 0x1.23p-500", L"%12a", 0x1.23p-500); | ||
184 | testfmt(L" 0x1.2p+40", L"%10.1a", 0x1.23p40); | ||
185 | testfmt(L" 0X1.230000000000000000000000P-4", L"%32.24A", 0x1.23p-4); | ||
186 | testfmt(L"0x1p-1074", L"%a", 0x1p-1074); | ||
187 | testfmt(L"0x1.2345p-1024", L"%a", 0x1.2345p-1024); | ||
188 | |||
189 | return (0); | ||
190 | } | ||
191 | |||
192 | void | ||
193 | smash_stack(void) | ||
194 | { | ||
195 | static uint32_t junk = 0xdeadbeef; | ||
196 | uint32_t buf[512]; | ||
197 | int i; | ||
198 | |||
199 | for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++) | ||
200 | buf[i] = junk; | ||
201 | } | ||
202 | |||
203 | void | ||
204 | _testfmt(const wchar_t *result, int line, const char *argstr, | ||
205 | const wchar_t *fmt, ...) | ||
206 | { | ||
207 | wchar_t ws[100]; | ||
208 | va_list ap; | ||
209 | |||
210 | va_start(ap, fmt); | ||
211 | smash_stack(); | ||
212 | vswprintf(ws, sizeof(ws)/sizeof(ws[0]), fmt, ap); | ||
213 | if (wcscmp(result, ws) != 0) { | ||
214 | const wchar_t *p = ws; | ||
215 | char f[100], s[100], r[100]; | ||
216 | |||
217 | memset(f, 0, sizeof(f)); | ||
218 | memset(s, 0, sizeof(s)); | ||
219 | memset(r, 0, sizeof(r)); | ||
220 | wcsrtombs(f, &fmt, sizeof(f) - 1, NULL); | ||
221 | wcsrtombs(s, &p, sizeof(s) - 1, NULL); | ||
222 | wcsrtombs(r, &result, sizeof(r) - 1, NULL); | ||
223 | |||
224 | errx(1, "line %d: printf(\"%s\", %s) ==> [%s], expected [%s]", | ||
225 | line, f, argstr, s, r); | ||
226 | } | ||
227 | } | ||