Wed Nov 3 16:10:26 2010 UTC ()
add Makefile.inc everywhere so that we can set WARNS=4 by default. Amazing
how many bugs this found :-)


(christos)
diff -r0 -r1.1 src/tests/Makefile.inc
diff -r0 -r1.1 src/tests/crypto/Makefile.inc
diff -r1.3 -r1.4 src/tests/crypto/libcrypto/Makefile.inc
diff -r0 -r1.1 src/tests/dev/Makefile.inc
diff -r0 -r1.1 src/tests/fs/Makefile.inc
diff -r0 -r1.1 src/tests/include/Makefile.inc
diff -r1.1 -r1.2 src/tests/include/t_bitstring.c
diff -r0 -r1.1 src/tests/kernel/Makefile.inc
diff -r1.1 -r1.2 src/tests/kernel/t_extent.c
diff -r1.3 -r1.4 src/tests/kernel/t_filedesc.c
diff -r0 -r1.1 src/tests/kernel/kqueue/Makefile.inc
diff -r1.1 -r1.2 src/tests/kernel/kqueue/t_sig.c
diff -r1.2 -r1.3 src/tests/kernel/tty/t_pr.c
diff -r0 -r1.1 src/tests/lib/Makefile.inc
diff -r0 -r1.1 src/tests/lib/csu/Makefile.inc
diff -r1.6 -r1.7 src/tests/lib/libc/Makefile
diff -r0 -r1.1 src/tests/lib/libc/Makefile.inc
diff -r1.5 -r1.6 src/tests/lib/libc/gen/t_glob_star.c
diff -r1.1 -r1.2 src/tests/lib/libc/hash/t_sha2.c
diff -r1.1 -r1.2 src/tests/lib/libc/stdio/t_fmemopen.c
diff -r1.1 -r1.2 src/tests/lib/libprop/t_basic.c
diff -r1.1 -r1.2 src/tests/lib/libpthread/h_resolv.c
diff -r1.1 -r1.2 src/tests/lib/libpthread/t_barrier.c
diff -r1.1 -r1.2 src/tests/lib/libpthread/t_cond.c
diff -r1.1 -r1.2 src/tests/lib/libpthread/t_preempt.c
diff -r1.1 -r1.2 src/tests/lib/libpthread/t_sigmask.c
diff -r1.1 -r1.2 src/tests/lib/libpthread/t_status.c
diff -r1.4 -r1.5 src/tests/lib/libpthread/t_sem.c
diff -r0 -r1.1 src/tests/lib/semaphore/Makefile.inc
diff -r0 -r1.1 src/tests/libexec/Makefile.inc
diff -r1.1 -r1.2 src/tests/libexec/ld.elf_so/t_dlinfo.c
diff -r0 -r1.1 src/tests/modules/Makefile.inc
diff -r1.1 -r1.2 src/tests/modules/t_builtin.c
diff -r1.4 -r1.5 src/tests/modules/t_modctl.c
diff -r1.4 -r1.5 src/tests/modules/k_helper/k_helper.c
diff -r1.1 -r1.2 src/tests/modules/k_helper2/k_helper2.c
diff -r0 -r1.1 src/tests/net/Makefile.inc
diff -r1.2 -r1.3 src/tests/net/bpf/t_div-by-zero.c
diff -r1.2 -r1.3 src/tests/net/carp/t_basic.c
diff -r1.5 -r1.6 src/tests/net/icmp/t_forward.c
diff -r1.8 -r1.9 src/tests/net/icmp/t_ping.c
diff -r1.2 -r1.3 src/tests/net/if_loop/t_pr.c
diff -r1.3 -r1.4 src/tests/net/sys/t_connect.c
diff -r1.1 -r1.2 src/tests/net/sys/t_listen.c
diff -r0 -r1.1 src/tests/rump/Makefile.inc
diff -r0 -r1.1 src/tests/util/Makefile.inc
diff -r1.3 -r1.4 src/tests/util/df/getmntinfo.c
diff -r1.2 -r1.3 src/tests/util/id/pwgr.c

File Added: src/tests/Makefile.inc
# $NetBSD: Makefile.inc,v 1.1 2010/11/03 16:10:19 christos Exp $
WARNS ?= 4

File Added: src/tests/crypto/Makefile.inc
.include "../Makefile.inc"

cvs diff -r1.3 -r1.4 src/tests/crypto/libcrypto/Makefile.inc (switch to unified diff)

--- src/tests/crypto/libcrypto/Makefile.inc 2010/07/13 21:13:21 1.3
+++ src/tests/crypto/libcrypto/Makefile.inc 2010/11/03 16:10:19 1.4
@@ -1,27 +1,28 @@ @@ -1,27 +1,28 @@
1# $NetBSD: Makefile.inc,v 1.3 2010/07/13 21:13:21 jmmv Exp $ 1# $NetBSD: Makefile.inc,v 1.4 2010/11/03 16:10:19 christos Exp $
2 2
3.include <bsd.own.mk> 3.include <bsd.own.mk>
4 4# Not yet
 5# .include "../Makefile.inc"
5TESTSDIR= ${TESTSBASE}/crypto/libcrypto 6TESTSDIR= ${TESTSBASE}/crypto/libcrypto
6ATFFILE= no 7ATFFILE= no
7 8
8.if defined(HELPER_NAME) 9.if defined(HELPER_NAME)
9HELPER_SRCS?= ${HELPER_NAME}.c 10HELPER_SRCS?= ${HELPER_NAME}.c
10 11
11PROG= h_${HELPER_NAME} 12PROG= h_${HELPER_NAME}
12SRCS= ${HELPER_SRCS} 13SRCS= ${HELPER_SRCS}
13MAN= # empty 14MAN= # empty
14BINDIR= ${TESTSDIR} 15BINDIR= ${TESTSDIR}
15 16
16DPADD+= ${LIBCRYPTO} ${LIBCRYPT} 17DPADD+= ${LIBCRYPTO} ${LIBCRYPT}
17LDADD+= -lcrypto -lcrypt 18LDADD+= -lcrypto -lcrypt
18 19
19CPPFLAGS+= -DOPENSSL_FIPS 20CPPFLAGS+= -DOPENSSL_FIPS
20CPPFLAGS+= -I${OPENSSLSRC} -I${OPENSSLSRC}/crypto 21CPPFLAGS+= -I${OPENSSLSRC} -I${OPENSSLSRC}/crypto
21CRYPTODIST= ${NETBSDSRCDIR}/crypto 22CRYPTODIST= ${NETBSDSRCDIR}/crypto
22.include "${NETBSDSRCDIR}/crypto/Makefile.openssl" 23.include "${NETBSDSRCDIR}/crypto/Makefile.openssl"
23.PATH: ${OPENSSLSRC}/crypto/${HELPER_DIR} 24.PATH: ${OPENSSLSRC}/crypto/${HELPER_DIR}
24 25
25.include <bsd.test.mk> 26.include <bsd.test.mk>
26.include <bsd.prog.mk> 27.include <bsd.prog.mk>
27.endif 28.endif

File Added: src/tests/dev/Makefile.inc
.include "../Makefile.inc"

File Added: src/tests/fs/Makefile.inc
.include "../Makefile.inc"

File Added: src/tests/include/Makefile.inc
.include "../Makefile.inc"

cvs diff -r1.1 -r1.2 src/tests/include/t_bitstring.c (switch to unified diff)

--- src/tests/include/t_bitstring.c 2010/07/17 19:26:27 1.1
+++ src/tests/include/t_bitstring.c 2010/11/03 16:10:20 1.2
@@ -1,305 +1,304 @@ @@ -1,305 +1,304 @@
1/* $NetBSD: t_bitstring.c,v 1.1 2010/07/17 19:26:27 jmmv Exp $ */ 1/* $NetBSD: t_bitstring.c,v 1.2 2010/11/03 16:10:20 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1993, 2008, 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 1993, 2008, 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <assert.h> 29#include <assert.h>
30#include <bitstring.h> 30#include <bitstring.h>
31#include <stdio.h> 31#include <stdio.h>
32#include <stdlib.h> 32#include <stdlib.h>
33 33
34#include <atf-c.h> 34#include <atf-c.h>
35 35
36static void 36static void
37clearbits(bitstr_t *b, int n) 37clearbits(bitstr_t *b, int n)
38{ 38{
39 int i = bitstr_size(n); 39 int i = bitstr_size(n);
40 40
41 while(i--) 41 while(i--)
42 *(b + i) = 0; 42 *(b + i) = 0;
43} 43}
44 44
45static void 45static void
46printbits(FILE *file, bitstr_t *b, int n) 46printbits(FILE *file, bitstr_t *b, int n)
47{ 47{
48 int i; 48 int i;
49 int jc, js; 49 int jc, js;
50 50
51 bit_ffc(b, n, &jc); 51 bit_ffc(b, n, &jc);
52 bit_ffs(b, n, &js); 52 bit_ffs(b, n, &js);
53 53
54 (void) fprintf(file, "%3d %3d ", jc, js); 54 (void) fprintf(file, "%3d %3d ", jc, js);
55 55
56 for (i=0; i < n; i++) { 56 for (i=0; i < n; i++) {
57 (void) fprintf(file, "%c", (bit_test(b, i) ? '1' : '0')); 57 (void) fprintf(file, "%c", (bit_test(b, i) ? '1' : '0'));
58 } 58 }
59 59
60 (void) fprintf(file, "%c", '\n'); 60 (void) fprintf(file, "%c", '\n');
61} 61}
62 62
63static void 63static void
64calculate_data(FILE *file, const int test_length) 64calculate_data(FILE *file, const int test_length)
65{ 65{
66 int b, i; 66 int i;
67 bitstr_t *bs; 67 bitstr_t *bs;
68 bitstr_t bit_decl(bss, 37); /* Mostly a random number. */ 
69 68
70 assert(test_length >= 4); 69 assert(test_length >= 4);
71 70
72 (void) fprintf(file, "Testing with TEST_LENGTH = %d\n\n", test_length); 71 (void) fprintf(file, "Testing with TEST_LENGTH = %d\n\n", test_length);
73 72
74 (void) fprintf(file, "test _bit_byte, _bit_mask, and bitstr_size\n"); 73 (void) fprintf(file, "test _bit_byte, _bit_mask, and bitstr_size\n");
75 (void) fprintf(file, " i _bit_byte(i) _bit_mask(i) bitstr_size(i)\n"); 74 (void) fprintf(file, " i _bit_byte(i) _bit_mask(i) bitstr_size(i)\n");
76 75
77 for (i=0; i < test_length; i++) { 76 for (i=0; i < test_length; i++) {
78 (void) fprintf(file, "%3d%15d%15d%15d\n", 77 (void) fprintf(file, "%3d%15u%15u%15zu\n",
79 i, _bit_byte(i), _bit_mask(i), bitstr_size(i)); 78 i, _bit_byte(i), _bit_mask(i), bitstr_size(i));
80 } 79 }
81 80
82 bs = bit_alloc(test_length); 81 bs = bit_alloc(test_length);
83 clearbits(bs, test_length); 82 clearbits(bs, test_length);
84 (void) fprintf(file, "\ntest bit_alloc, clearbits, bit_ffc, bit_ffs\n"); 83 (void) fprintf(file, "\ntest bit_alloc, clearbits, bit_ffc, bit_ffs\n");
85 (void) fprintf(file, "be: 0 -1 "); 84 (void) fprintf(file, "be: 0 -1 ");
86 for (i=0; i < test_length; i++) 85 for (i=0; i < test_length; i++)
87 (void) fprintf(file, "%c", '0'); 86 (void) fprintf(file, "%c", '0');
88 (void) fprintf(file, "\nis: "); 87 (void) fprintf(file, "\nis: ");
89 printbits(file, bs, test_length); 88 printbits(file, bs, test_length);
90 89
91 (void) fprintf(file, "\ntest bit_set\n"); 90 (void) fprintf(file, "\ntest bit_set\n");
92 for (i=0; i < test_length; i+=3) 91 for (i=0; i < test_length; i+=3)
93 bit_set(bs, i); 92 bit_set(bs, i);
94 (void) fprintf(file, "be: 1 0 "); 93 (void) fprintf(file, "be: 1 0 ");
95 for (i=0; i < test_length; i++) 94 for (i=0; i < test_length; i++)
96 (void) fprintf(file, "%c", *("100" + (i % 3))); 95 (void) fprintf(file, "%c", *("100" + (i % 3)));
97 (void) fprintf(file, "\nis: "); 96 (void) fprintf(file, "\nis: ");
98 printbits(file, bs, test_length); 97 printbits(file, bs, test_length);
99 98
100 (void) fprintf(file, "\ntest bit_clear\n"); 99 (void) fprintf(file, "\ntest bit_clear\n");
101 for (i=0; i < test_length; i+=6) 100 for (i=0; i < test_length; i+=6)
102 bit_clear(bs, i); 101 bit_clear(bs, i);
103 (void) fprintf(file, "be: 0 3 "); 102 (void) fprintf(file, "be: 0 3 ");
104 for (i=0; i < test_length; i++) 103 for (i=0; i < test_length; i++)
105 (void) fprintf(file, "%c", *("000100" + (i % 6))); 104 (void) fprintf(file, "%c", *("000100" + (i % 6)));
106 (void) fprintf(file, "\nis: "); 105 (void) fprintf(file, "\nis: ");
107 printbits(file, bs, test_length); 106 printbits(file, bs, test_length);
108 107
109 (void) fprintf(file, "\ntest bit_test using previous bitstring\n"); 108 (void) fprintf(file, "\ntest bit_test using previous bitstring\n");
110 (void) fprintf(file, " i bit_test(i)\n"); 109 (void) fprintf(file, " i bit_test(i)\n");
111 for (i=0; i < test_length; i++) 110 for (i=0; i < test_length; i++)
112 (void) fprintf(file, "%3d%15d\n", i, bit_test(bs, i)); 111 (void) fprintf(file, "%3d%15d\n", i, bit_test(bs, i));
113 112
114 clearbits(bs, test_length); 113 clearbits(bs, test_length);
115 (void) fprintf(file, "\ntest clearbits\n"); 114 (void) fprintf(file, "\ntest clearbits\n");
116 (void) fprintf(file, "be: 0 -1 "); 115 (void) fprintf(file, "be: 0 -1 ");
117 for (i=0; i < test_length; i++) 116 for (i=0; i < test_length; i++)
118 (void) fprintf(file, "%c", '0'); 117 (void) fprintf(file, "%c", '0');
119 (void) fprintf(file, "\nis: "); 118 (void) fprintf(file, "\nis: ");
120 printbits(file, bs, test_length); 119 printbits(file, bs, test_length);
121 120
122 (void) fprintf(file, "\ntest bit_nset and bit_nclear\n"); 121 (void) fprintf(file, "\ntest bit_nset and bit_nclear\n");
123 bit_nset(bs, 1, test_length - 2); 122 bit_nset(bs, 1, test_length - 2);
124 (void) fprintf(file, "be: 0 1 0"); 123 (void) fprintf(file, "be: 0 1 0");
125 for (i=0; i < test_length - 2; i++) 124 for (i=0; i < test_length - 2; i++)
126 (void) fprintf(file, "%c", '1'); 125 (void) fprintf(file, "%c", '1');
127 (void) fprintf(file, "0\nis: "); 126 (void) fprintf(file, "0\nis: ");
128 printbits(file, bs, test_length); 127 printbits(file, bs, test_length);
129 128
130 bit_nclear(bs, 2, test_length - 3); 129 bit_nclear(bs, 2, test_length - 3);
131 (void) fprintf(file, "be: 0 1 01"); 130 (void) fprintf(file, "be: 0 1 01");
132 for (i=0; i < test_length - 4; i++) 131 for (i=0; i < test_length - 4; i++)
133 (void) fprintf(file, "%c", '0'); 132 (void) fprintf(file, "%c", '0');
134 (void) fprintf(file, "10\nis: "); 133 (void) fprintf(file, "10\nis: ");
135 printbits(file, bs, test_length); 134 printbits(file, bs, test_length);
136 135
137 bit_nclear(bs, 0, test_length - 1); 136 bit_nclear(bs, 0, test_length - 1);
138 (void) fprintf(file, "be: 0 -1 "); 137 (void) fprintf(file, "be: 0 -1 ");
139 for (i=0; i < test_length; i++) 138 for (i=0; i < test_length; i++)
140 (void) fprintf(file, "%c", '0'); 139 (void) fprintf(file, "%c", '0');
141 (void) fprintf(file, "\nis: "); 140 (void) fprintf(file, "\nis: ");
142 printbits(file, bs, test_length); 141 printbits(file, bs, test_length);
143 bit_nset(bs, 0, test_length - 2); 142 bit_nset(bs, 0, test_length - 2);
144 (void) fprintf(file, "be: %3d 0 ",test_length - 1); 143 (void) fprintf(file, "be: %3d 0 ",test_length - 1);
145 for (i=0; i < test_length - 1; i++) 144 for (i=0; i < test_length - 1; i++)
146 (void) fprintf(file, "%c", '1'); 145 (void) fprintf(file, "%c", '1');
147 fprintf(file, "%c", '0'); 146 fprintf(file, "%c", '0');
148 (void) fprintf(file, "\nis: "); 147 (void) fprintf(file, "\nis: ");
149 printbits(file, bs, test_length); 148 printbits(file, bs, test_length);
150 bit_nclear(bs, 0, test_length - 1); 149 bit_nclear(bs, 0, test_length - 1);
151 (void) fprintf(file, "be: 0 -1 "); 150 (void) fprintf(file, "be: 0 -1 ");
152 for (i=0; i < test_length; i++) 151 for (i=0; i < test_length; i++)
153 (void) fprintf(file, "%c", '0'); 152 (void) fprintf(file, "%c", '0');
154 (void) fprintf(file, "\nis: "); 153 (void) fprintf(file, "\nis: ");
155 printbits(file, bs, test_length); 154 printbits(file, bs, test_length);
156 155
157 (void) fprintf(file, "\n"); 156 (void) fprintf(file, "\n");
158 (void) fprintf(file, "first 1 bit should move right 1 position each line\n"); 157 (void) fprintf(file, "first 1 bit should move right 1 position each line\n");
159 for (i=0; i < test_length; i++) { 158 for (i=0; i < test_length; i++) {
160 bit_nclear(bs, 0, test_length - 1); 159 bit_nclear(bs, 0, test_length - 1);
161 bit_nset(bs, i, test_length - 1); 160 bit_nset(bs, i, test_length - 1);
162 (void) fprintf(file, "%3d ", i); printbits(file, bs, test_length); 161 (void) fprintf(file, "%3d ", i); printbits(file, bs, test_length);
163 } 162 }
164 163
165 (void) fprintf(file, "\n"); 164 (void) fprintf(file, "\n");
166 (void) fprintf(file, "first 0 bit should move right 1 position each line\n"); 165 (void) fprintf(file, "first 0 bit should move right 1 position each line\n");
167 for (i=0; i < test_length; i++) { 166 for (i=0; i < test_length; i++) {
168 bit_nset(bs, 0, test_length - 1); 167 bit_nset(bs, 0, test_length - 1);
169 bit_nclear(bs, i, test_length - 1); 168 bit_nclear(bs, i, test_length - 1);
170 (void) fprintf(file, "%3d ", i); printbits(file, bs, test_length); 169 (void) fprintf(file, "%3d ", i); printbits(file, bs, test_length);
171 } 170 }
172 171
173 (void) fprintf(file, "\n"); 172 (void) fprintf(file, "\n");
174 (void) fprintf(file, "first 0 bit should move left 1 position each line\n"); 173 (void) fprintf(file, "first 0 bit should move left 1 position each line\n");
175 for (i=0; i < test_length; i++) { 174 for (i=0; i < test_length; i++) {
176 bit_nclear(bs, 0, test_length - 1); 175 bit_nclear(bs, 0, test_length - 1);
177 bit_nset(bs, 0, test_length - 1 - i); 176 bit_nset(bs, 0, test_length - 1 - i);
178 (void) fprintf(file, "%3d ", i); printbits(file, bs, test_length); 177 (void) fprintf(file, "%3d ", i); printbits(file, bs, test_length);
179 } 178 }
180 179
181 (void) fprintf(file, "\n"); 180 (void) fprintf(file, "\n");
182 (void) fprintf(file, "first 1 bit should move left 1 position each line\n"); 181 (void) fprintf(file, "first 1 bit should move left 1 position each line\n");
183 for (i=0; i < test_length; i++) { 182 for (i=0; i < test_length; i++) {
184 bit_nset(bs, 0, test_length - 1); 183 bit_nset(bs, 0, test_length - 1);
185 bit_nclear(bs, 0, test_length - 1 - i); 184 bit_nclear(bs, 0, test_length - 1 - i);
186 (void) fprintf(file, "%3d ", i); printbits(file, bs, test_length); 185 (void) fprintf(file, "%3d ", i); printbits(file, bs, test_length);
187 } 186 }
188 187
189 (void) fprintf(file, "\n"); 188 (void) fprintf(file, "\n");
190 (void) fprintf(file, "0 bit should move right 1 position each line\n"); 189 (void) fprintf(file, "0 bit should move right 1 position each line\n");
191 for (i=0; i < test_length; i++) { 190 for (i=0; i < test_length; i++) {
192 bit_nset(bs, 0, test_length - 1); 191 bit_nset(bs, 0, test_length - 1);
193 bit_nclear(bs, i, i); 192 bit_nclear(bs, i, i);
194 (void) fprintf(file, "%3d ", i); printbits(file, bs, test_length); 193 (void) fprintf(file, "%3d ", i); printbits(file, bs, test_length);
195 } 194 }
196 195
197 (void) fprintf(file, "\n"); 196 (void) fprintf(file, "\n");
198 (void) fprintf(file, "1 bit should move right 1 position each line\n"); 197 (void) fprintf(file, "1 bit should move right 1 position each line\n");
199 for (i=0; i < test_length; i++) { 198 for (i=0; i < test_length; i++) {
200 bit_nclear(bs, 0, test_length - 1); 199 bit_nclear(bs, 0, test_length - 1);
201 bit_nset(bs, i, i); 200 bit_nset(bs, i, i);
202 (void) fprintf(file, "%3d ", i); printbits(file, bs, test_length); 201 (void) fprintf(file, "%3d ", i); printbits(file, bs, test_length);
203 } 202 }
204 203
205 (void) free(bs); 204 (void) free(bs);
206} 205}
207 206
208void 207static void
209one_check(const atf_tc_t *tc, const int test_length) 208one_check(const atf_tc_t *tc, const int test_length)
210{ 209{
211 FILE *out; 210 FILE *out;
212 char command[1024]; 211 char command[1024];
213 212
214 ATF_REQUIRE((out = fopen("out", "w")) != NULL); 213 ATF_REQUIRE((out = fopen("out", "w")) != NULL);
215 calculate_data(out, test_length); 214 calculate_data(out, test_length);
216 fclose(out); 215 fclose(out);
217 216
218 /* XXX The following is a huge hack that was added to simplify the 217 /* XXX The following is a huge hack that was added to simplify the
219 * conversion of these tests from src/regress/ to src/tests/. The 218 * conversion of these tests from src/regress/ to src/tests/. The
220 * tests in this file should be checking their own results, without 219 * tests in this file should be checking their own results, without
221 * having to resort to external data files. */ 220 * having to resort to external data files. */
222 snprintf(command, sizeof(command), "diff -u %s/d_bitstring_%d.out out", 221 snprintf(command, sizeof(command), "diff -u %s/d_bitstring_%d.out out",
223 atf_tc_get_config_var(tc, "srcdir"), test_length); 222 atf_tc_get_config_var(tc, "srcdir"), test_length);
224 if (system(command) != EXIT_SUCCESS) 223 if (system(command) != EXIT_SUCCESS)
225 atf_tc_fail("Test failed; see output for details"); 224 atf_tc_fail("Test failed; see output for details");
226} 225}
227 226
228ATF_TC(bits_8); 227ATF_TC(bits_8);
229ATF_TC_HEAD(bits_8, tc) 228ATF_TC_HEAD(bits_8, tc)
230{ 229{
231 atf_tc_set_md_var(tc, "descr", "Checks 8-bit long bitstrings"); 230 atf_tc_set_md_var(tc, "descr", "Checks 8-bit long bitstrings");
232 atf_tc_set_md_var(tc, "use.fs", "true"); 231 atf_tc_set_md_var(tc, "use.fs", "true");
233} 232}
234ATF_TC_BODY(bits_8, tc) 233ATF_TC_BODY(bits_8, tc)
235{ 234{
236 one_check(tc, 8); 235 one_check(tc, 8);
237} 236}
238 237
239ATF_TC(bits_27); 238ATF_TC(bits_27);
240ATF_TC_HEAD(bits_27, tc) 239ATF_TC_HEAD(bits_27, tc)
241{ 240{
242 atf_tc_set_md_var(tc, "descr", "Checks 27-bit long bitstrings"); 241 atf_tc_set_md_var(tc, "descr", "Checks 27-bit long bitstrings");
243 atf_tc_set_md_var(tc, "use.fs", "true"); 242 atf_tc_set_md_var(tc, "use.fs", "true");
244} 243}
245ATF_TC_BODY(bits_27, tc) 244ATF_TC_BODY(bits_27, tc)
246{ 245{
247 one_check(tc, 27); 246 one_check(tc, 27);
248} 247}
249 248
250ATF_TC(bits_32); 249ATF_TC(bits_32);
251ATF_TC_HEAD(bits_32, tc) 250ATF_TC_HEAD(bits_32, tc)
252{ 251{
253 atf_tc_set_md_var(tc, "descr", "Checks 32-bit long bitstrings"); 252 atf_tc_set_md_var(tc, "descr", "Checks 32-bit long bitstrings");
254 atf_tc_set_md_var(tc, "use.fs", "true"); 253 atf_tc_set_md_var(tc, "use.fs", "true");
255} 254}
256ATF_TC_BODY(bits_32, tc) 255ATF_TC_BODY(bits_32, tc)
257{ 256{
258 one_check(tc, 32); 257 one_check(tc, 32);
259} 258}
260 259
261ATF_TC(bits_49); 260ATF_TC(bits_49);
262ATF_TC_HEAD(bits_49, tc) 261ATF_TC_HEAD(bits_49, tc)
263{ 262{
264 atf_tc_set_md_var(tc, "descr", "Checks 49-bit long bitstrings"); 263 atf_tc_set_md_var(tc, "descr", "Checks 49-bit long bitstrings");
265 atf_tc_set_md_var(tc, "use.fs", "true"); 264 atf_tc_set_md_var(tc, "use.fs", "true");
266} 265}
267ATF_TC_BODY(bits_49, tc) 266ATF_TC_BODY(bits_49, tc)
268{ 267{
269 one_check(tc, 49); 268 one_check(tc, 49);
270} 269}
271 270
272ATF_TC(bits_64); 271ATF_TC(bits_64);
273ATF_TC_HEAD(bits_64, tc) 272ATF_TC_HEAD(bits_64, tc)
274{ 273{
275 atf_tc_set_md_var(tc, "descr", "Checks 64-bit long bitstrings"); 274 atf_tc_set_md_var(tc, "descr", "Checks 64-bit long bitstrings");
276 atf_tc_set_md_var(tc, "use.fs", "true"); 275 atf_tc_set_md_var(tc, "use.fs", "true");
277} 276}
278ATF_TC_BODY(bits_64, tc) 277ATF_TC_BODY(bits_64, tc)
279{ 278{
280 one_check(tc, 64); 279 one_check(tc, 64);
281} 280}
282 281
283ATF_TC(bits_67); 282ATF_TC(bits_67);
284ATF_TC_HEAD(bits_67, tc) 283ATF_TC_HEAD(bits_67, tc)
285{ 284{
286 atf_tc_set_md_var(tc, "descr", "Checks 67-bit long bitstrings"); 285 atf_tc_set_md_var(tc, "descr", "Checks 67-bit long bitstrings");
287 atf_tc_set_md_var(tc, "use.fs", "true"); 286 atf_tc_set_md_var(tc, "use.fs", "true");
288} 287}
289ATF_TC_BODY(bits_67, tc) 288ATF_TC_BODY(bits_67, tc)
290{ 289{
291 one_check(tc, 67); 290 one_check(tc, 67);
292} 291}
293 292
294ATF_TP_ADD_TCS(tp) 293ATF_TP_ADD_TCS(tp)
295{ 294{
296 295
297 ATF_TP_ADD_TC(tp, bits_8); 296 ATF_TP_ADD_TC(tp, bits_8);
298 ATF_TP_ADD_TC(tp, bits_27); 297 ATF_TP_ADD_TC(tp, bits_27);
299 ATF_TP_ADD_TC(tp, bits_32); 298 ATF_TP_ADD_TC(tp, bits_32);
300 ATF_TP_ADD_TC(tp, bits_49); 299 ATF_TP_ADD_TC(tp, bits_49);
301 ATF_TP_ADD_TC(tp, bits_64); 300 ATF_TP_ADD_TC(tp, bits_64);
302 ATF_TP_ADD_TC(tp, bits_67); 301 ATF_TP_ADD_TC(tp, bits_67);
303 302
304 return atf_no_error(); 303 return atf_no_error();
305} 304}

File Added: src/tests/kernel/Makefile.inc
.include "../Makefile.inc"

cvs diff -r1.1 -r1.2 src/tests/kernel/t_extent.c (switch to unified diff)

--- src/tests/kernel/t_extent.c 2009/02/20 21:39:57 1.1
+++ src/tests/kernel/t_extent.c 2010/11/03 16:10:20 1.2
@@ -1,385 +1,385 @@ @@ -1,385 +1,385 @@
1/* $NetBSD: t_extent.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $ */ 1/* $NetBSD: t_extent.c,v 1.2 2010/11/03 16:10:20 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__COPYRIGHT("@(#) Copyright (c) 2008\ 30__COPYRIGHT("@(#) Copyright (c) 2008\
31 The NetBSD Foundation, inc. All rights reserved."); 31 The NetBSD Foundation, inc. All rights reserved.");
32__RCSID("$NetBSD: t_extent.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $"); 32__RCSID("$NetBSD: t_extent.c,v 1.2 2010/11/03 16:10:20 christos Exp $");
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#include <sys/queue.h> 35#include <sys/queue.h>
36#include <sys/extent.h> 36#include <sys/extent.h>
37 37
38#include <stdio.h> 38#include <stdio.h>
39#include <stdlib.h> 39#include <stdlib.h>
40#include <string.h> 40#include <string.h>
41 41
42#include <atf-c.h> 42#include <atf-c.h>
43 43
44#include "../h_macros.h" 44#include "../h_macros.h"
45 45
46static int ret; 46static int ret;
47static struct extent *ex; 47static struct extent *ex;
48 48
49#define h_create(name, start, end, flags) \ 49#define h_create(name, start, end, flags) \
50 ATF_REQUIRE((ex = extent_create(name, \ 50 ATF_REQUIRE((ex = extent_create(name, \
51 start, end, 0, 0, 0, flags)) != NULL); 51 start, end, 0, 0, 0, flags)) != NULL);
52 52
53#define h_alloc_region(start, size) \ 53#define h_alloc_region(start, size) \
54 ATF_REQUIRE_EQ_MSG(ret = extent_alloc_region(ex, \ 54 ATF_REQUIRE_EQ_MSG(ret = extent_alloc_region(ex, \
55 start, size, 0), 0, "%s", strerror(ret)); 55 start, size, 0), 0, "%s", strerror(ret));
56 56
57#define h_free(start, size) \ 57#define h_free(start, size) \
58 ATF_REQUIRE_EQ_MSG(ret = extent_free(ex, \ 58 ATF_REQUIRE_EQ_MSG(ret = extent_free(ex, \
59 start, size, 0), 0, "%s", strerror(ret)); 59 start, size, 0), 0, "%s", strerror(ret));
60 60
61static void 61static void
62h_alloc_subregion(u_long substart, u_long subend, u_long size, 62h_alloc_subregion(u_long substart, u_long subend, u_long size,
63 u_long alignment, u_long boundary, int expret, u_long expres) 63 u_long alignment, u_long boundary, int expret, u_long expres)
64{ 64{
65 u_long result; 65 u_long result;
66 66
67#define FAIL(fmt, ...) \ 67#define FAIL(fmt, ...) \
68 atf_tc_fail("extent_alloc_subregion1(ex, %#lx, %#lx, %#lx, %#lx, 0, " \ 68 atf_tc_fail("extent_alloc_subregion1(ex, %#lx, %#lx, %#lx, %#lx, 0, " \
69 "%#lx, 0, &result): " fmt, substart, subend, size, alignment, \ 69 "%#lx, 0, &result): " fmt, substart, subend, size, alignment, \
70 boundary, ##__VA_ARGS__) 70 boundary, ##__VA_ARGS__)
71 71
72 ret = extent_alloc_subregion1(ex, substart, subend, size, 72 ret = extent_alloc_subregion1(ex, substart, subend, size,
73 alignment, 0, boundary, 0, &result); 73 alignment, 0, boundary, 0, &result);
74 74
75 if (ret != expret) 75 if (ret != expret)
76 FAIL("%s", strerror(errno)); 76 FAIL("%s", strerror(errno));
77 77
78 if (expret == 0 && result != expres) 78 if (expret == 0 && result != expres)
79 FAIL("result should be: %#lx, got: %#lx", expres, result); 79 FAIL("result should be: %#lx, got: %#lx", expres, result);
80#undef FAIL 80#undef FAIL
81} 81}
82 82
83static void 83static void
84h_require(const char *name, u_long start, 84h_require(const char *name, u_long start,
85 u_long end, u_long flags, const char *exp) 85 u_long end, long flags, const char *exp)
86{ 86{
87 char buf[4096]; 87 char buf[4096];
88 struct extent_region *rp; 88 struct extent_region *rp;
89 int n = 0; 89 int n = 0;
90 90
91 ATF_REQUIRE_STREQ_MSG(ex->ex_name, name, 91 ATF_REQUIRE_STREQ_MSG(ex->ex_name, name,
92 "expected: \"%s\", got: \"%s\"", name, ex->ex_name); 92 "expected: \"%s\", got: \"%s\"", name, ex->ex_name);
93 ATF_REQUIRE_EQ_MSG(ex->ex_start, start, 93 ATF_REQUIRE_EQ_MSG(ex->ex_start, start,
94 "expected: %#lx, got: %#lx", start, ex->ex_start); 94 "expected: %#lx, got: %#lx", start, ex->ex_start);
95 ATF_REQUIRE_EQ_MSG(ex->ex_end, end, 95 ATF_REQUIRE_EQ_MSG(ex->ex_end, end,
96 "expected: %#lx, got: %#lx", end, ex->ex_end); 96 "expected: %#lx, got: %#lx", end, ex->ex_end);
97 ATF_REQUIRE_EQ_MSG(ex->ex_flags, flags, 97 ATF_REQUIRE_EQ_MSG(ex->ex_flags, flags,
98 "expected: %#lx, got: %#lx", flags, ex->ex_flags); 98 "expected: %#lx, got: %#lx", flags, ex->ex_flags);
99 99
100 (void)memset(buf, 0, sizeof(buf)); 100 (void)memset(buf, 0, sizeof(buf));
101 LIST_FOREACH(rp, &ex->ex_regions, er_link) 101 LIST_FOREACH(rp, &ex->ex_regions, er_link)
102 n += snprintf(buf + n, sizeof(buf) - n, 102 n += snprintf(buf + n, sizeof(buf) - n,
103 "0x%lx - 0x%lx\n", rp->er_start, rp->er_end); 103 "0x%lx - 0x%lx\n", rp->er_start, rp->er_end);
104 104
105 if (strcmp(buf, exp) == 0) 105 if (strcmp(buf, exp) == 0)
106 return; 106 return;
107 107
108 printf("Incorrect extent map\n"); 108 printf("Incorrect extent map\n");
109 printf("Expected:\n%s\n", exp); 109 printf("Expected:\n%s\n", exp);
110 printf("Got:\n%s\n", buf); 110 printf("Got:\n%s\n", buf);
111 atf_tc_fail("incorrect extent map"); 111 atf_tc_fail("incorrect extent map");
112} 112}
113 113
114ATF_TC(coalesce); 114ATF_TC(coalesce);
115ATF_TC_HEAD(coalesce, tc) 115ATF_TC_HEAD(coalesce, tc)
116{ 116{
117 atf_tc_set_md_var(tc, "descr", "Checks coalescing of regions"); 117 atf_tc_set_md_var(tc, "descr", "Checks coalescing of regions");
118} 118}
119ATF_TC_BODY(coalesce, tc) 119ATF_TC_BODY(coalesce, tc)
120{ 120{
121 h_create("test1", 0, 0x4f, 0); 121 h_create("test1", 0, 0x4f, 0);
122 122
123 h_alloc_region(0x00, 0x10); 123 h_alloc_region(0x00, 0x10);
124 h_alloc_region(0x20, 0x10); 124 h_alloc_region(0x20, 0x10);
125 h_alloc_region(0x40, 0x10); 125 h_alloc_region(0x40, 0x10);
126 h_alloc_region(0x10, 0x10); 126 h_alloc_region(0x10, 0x10);
127 h_alloc_subregion(0, 0x4f, 0x10, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x30); 127 h_alloc_subregion(0, 0x4f, 0x10, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x30);
128 128
129 h_require("test1", 0x00, 0x4f, 0x00, 129 h_require("test1", 0x00, 0x4f, 0x00,
130 "0x0 - 0x4f\n"); 130 "0x0 - 0x4f\n");
131 131
132 extent_destroy(ex); 132 extent_destroy(ex);
133} 133}
134 134
135ATF_TC(subregion1); 135ATF_TC(subregion1);
136ATF_TC_HEAD(subregion1, tc) 136ATF_TC_HEAD(subregion1, tc)
137{ 137{
138 atf_tc_set_md_var(tc, "descr", 138 atf_tc_set_md_var(tc, "descr",
139 "Checks that subregions work (PR kern/7539)"); 139 "Checks that subregions work (PR kern/7539)");
140} 140}
141ATF_TC_BODY(subregion1, tc) 141ATF_TC_BODY(subregion1, tc)
142{ 142{
143 h_create("test2", 0, 0x2f, EX_NOCOALESCE); 143 h_create("test2", 0, 0x2f, EX_NOCOALESCE);
144 144
145 h_alloc_region(0x00, 0x10); 145 h_alloc_region(0x00, 0x10);
146 h_alloc_subregion(0x20, 0x30, 0x10, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x20); 146 h_alloc_subregion(0x20, 0x30, 0x10, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x20);
147 147
148 h_require("test2", 0x00, 0x2f, 0x2, 148 h_require("test2", 0x00, 0x2f, 0x2,
149 "0x0 - 0xf\n" 149 "0x0 - 0xf\n"
150 "0x20 - 0x2f\n"); 150 "0x20 - 0x2f\n");
151 151
152 extent_destroy(ex); 152 extent_destroy(ex);
153} 153}
154 154
155ATF_TC(subregion2); 155ATF_TC(subregion2);
156ATF_TC_HEAD(subregion2, tc) 156ATF_TC_HEAD(subregion2, tc)
157{ 157{
158 atf_tc_set_md_var(tc, "descr", 158 atf_tc_set_md_var(tc, "descr",
159 "Checks that subregion allocations don't overlap with existing " 159 "Checks that subregion allocations don't overlap with existing "
160 "ones (fixed in 1.25)"); 160 "ones (fixed in 1.25)");
161} 161}
162ATF_TC_BODY(subregion2, tc) 162ATF_TC_BODY(subregion2, tc)
163{ 163{
164 h_create("test3", 0, 0x3f, EX_NOCOALESCE); 164 h_create("test3", 0, 0x3f, EX_NOCOALESCE);
165 165
166 h_alloc_region(0x00, 0x20); 166 h_alloc_region(0x00, 0x20);
167 h_alloc_region(0x30, 0x10); 167 h_alloc_region(0x30, 0x10);
168 h_alloc_subregion(0x10, 0x3f, 0x10, 168 h_alloc_subregion(0x10, 0x3f, 0x10,
169 EX_NOALIGN, EX_NOBOUNDARY, 0, 0x20); 169 EX_NOALIGN, EX_NOBOUNDARY, 0, 0x20);
170 170
171 h_require("test3", 0x00, 0x3f, 0x2, 171 h_require("test3", 0x00, 0x3f, 0x2,
172 "0x0 - 0x1f\n" 172 "0x0 - 0x1f\n"
173 "0x20 - 0x2f\n" 173 "0x20 - 0x2f\n"
174 "0x30 - 0x3f\n"); 174 "0x30 - 0x3f\n");
175 175
176 extent_destroy(ex); 176 extent_destroy(ex);
177} 177}
178 178
179ATF_TC(bound1); 179ATF_TC(bound1);
180ATF_TC_HEAD(bound1, tc) 180ATF_TC_HEAD(bound1, tc)
181{ 181{
182 atf_tc_set_md_var(tc, "descr", 182 atf_tc_set_md_var(tc, "descr",
183 "Checks for overflow in boundary check, before an allocated region " 183 "Checks for overflow in boundary check, before an allocated region "
184 "(fixed in 1.32)"); 184 "(fixed in 1.32)");
185} 185}
186ATF_TC_BODY(bound1, tc) 186ATF_TC_BODY(bound1, tc)
187{ 187{
188 h_create("test4", 0xf0000000, 0xffffffff, 0); 188 h_create("test4", 0xf0000000, 0xffffffff, 0);
189 189
190 h_alloc_region(0xf1000000, 0x1); 190 h_alloc_region(0xf1000000, 0x1);
191 h_alloc_subregion(0xf0000000, 0xffffffff, 0x1, 191 h_alloc_subregion(0xf0000000, 0xffffffff, 0x1,
192 EX_NOALIGN, 0x20000000, 0, 0xf0000000); 192 EX_NOALIGN, 0x20000000, 0, 0xf0000000);
193 193
194 h_require("test4", 0xf0000000, 0xffffffff, 0x0, 194 h_require("test4", 0xf0000000, 0xffffffff, 0x0,
195 "0xf0000000 - 0xf0000000\n" 195 "0xf0000000 - 0xf0000000\n"
196 "0xf1000000 - 0xf1000000\n"); 196 "0xf1000000 - 0xf1000000\n");
197 197
198 extent_destroy(ex); 198 extent_destroy(ex);
199} 199}
200 200
201ATF_TC(bound2); 201ATF_TC(bound2);
202ATF_TC_HEAD(bound2, tc) 202ATF_TC_HEAD(bound2, tc)
203{ 203{
204 atf_tc_set_md_var(tc, "descr", 204 atf_tc_set_md_var(tc, "descr",
205 "Checks for overflow in boundary checks, before the subregion end " 205 "Checks for overflow in boundary checks, before the subregion end "
206 "(fixed in 1.32)"); 206 "(fixed in 1.32)");
207} 207}
208ATF_TC_BODY(bound2, tc) 208ATF_TC_BODY(bound2, tc)
209{ 209{
210 h_create("test5", 0xf0000000, 0xffffffff, 0); 210 h_create("test5", 0xf0000000, 0xffffffff, 0);
211 211
212 h_alloc_subregion(0xf0000000, 0xffffffff, 0x1, 212 h_alloc_subregion(0xf0000000, 0xffffffff, 0x1,
213 EX_NOALIGN, 0x20000000, 0, 0xf0000000); 213 EX_NOALIGN, 0x20000000, 0, 0xf0000000);
214 214
215 h_require("test5", 0xf0000000, 0xffffffff, 0x0, 215 h_require("test5", 0xf0000000, 0xffffffff, 0x0,
216 "0xf0000000 - 0xf0000000\n"); 216 "0xf0000000 - 0xf0000000\n");
217 217
218 extent_destroy(ex); 218 extent_destroy(ex);
219} 219}
220 220
221ATF_TC(bound3); 221ATF_TC(bound3);
222ATF_TC_HEAD(bound3, tc) 222ATF_TC_HEAD(bound3, tc)
223{ 223{
224 atf_tc_set_md_var(tc, "descr", 224 atf_tc_set_md_var(tc, "descr",
225 "Checks allocation beyond last boundary line: last two " 225 "Checks allocation beyond last boundary line: last two "
226 "allocations should succeed without boundary \"fixups\""); 226 "allocations should succeed without boundary \"fixups\"");
227} 227}
228ATF_TC_BODY(bound3, tc) 228ATF_TC_BODY(bound3, tc)
229{ 229{
230 h_create("test6", 0, 11, 0); 230 h_create("test6", 0, 11, 0);
231 231
232 h_alloc_subregion(0, 11, 8, EX_NOALIGN, 8, 0, 0); 232 h_alloc_subregion(0, 11, 8, EX_NOALIGN, 8, 0, 0);
233 h_alloc_subregion(0, 11, 2, EX_NOALIGN, 8, 0, 0x8); 233 h_alloc_subregion(0, 11, 2, EX_NOALIGN, 8, 0, 0x8);
234 h_alloc_subregion(0, 11, 2, EX_NOALIGN, 8, 0, 0xa); 234 h_alloc_subregion(0, 11, 2, EX_NOALIGN, 8, 0, 0xa);
235 235
236 h_require("test6", 0x0, 0xb, 0x0, "0x0 - 0xb\n"); 236 h_require("test6", 0x0, 0xb, 0x0, "0x0 - 0xb\n");
237 237
238 extent_destroy(ex); 238 extent_destroy(ex);
239} 239}
240 240
241ATF_TC(bound4); 241ATF_TC(bound4);
242ATF_TC_HEAD(bound4, tc) 242ATF_TC_HEAD(bound4, tc)
243{ 243{
244 atf_tc_set_md_var(tc, "descr", 244 atf_tc_set_md_var(tc, "descr",
245 "Checks allocation beyond last boundary line: last allocation " 245 "Checks allocation beyond last boundary line: last allocation "
246 "should be bumped to the next boundary and exactly fit the " 246 "should be bumped to the next boundary and exactly fit the "
247 "remaining space"); 247 "remaining space");
248} 248}
249ATF_TC_BODY(bound4, tc) 249ATF_TC_BODY(bound4, tc)
250{ 250{
251 h_create("test7", 0, 11, 0); 251 h_create("test7", 0, 11, 0);
252 252
253 h_alloc_subregion(0, 11, 7, EX_NOALIGN, 8, 0, 0); 253 h_alloc_subregion(0, 11, 7, EX_NOALIGN, 8, 0, 0);
254 h_alloc_subregion(0, 11, 4, EX_NOALIGN, 8, 0, 8); 254 h_alloc_subregion(0, 11, 4, EX_NOALIGN, 8, 0, 8);
255 255
256 h_require("test7", 0x0, 0xb, 0x0, 256 h_require("test7", 0x0, 0xb, 0x0,
257 "0x0 - 0x6\n" 257 "0x0 - 0x6\n"
258 "0x8 - 0xb\n"); 258 "0x8 - 0xb\n");
259 259
260 extent_destroy(ex); 260 extent_destroy(ex);
261} 261}
262 262
263ATF_TC(subregion3); 263ATF_TC(subregion3);
264ATF_TC_HEAD(subregion3, tc) 264ATF_TC_HEAD(subregion3, tc)
265{ 265{
266 atf_tc_set_md_var(tc, "descr", 266 atf_tc_set_md_var(tc, "descr",
267 "Checks that we don't allocate a region pasts the end of " 267 "Checks that we don't allocate a region pasts the end of "
268 "subregion (i.e., the second alloc_subregion should fail). " 268 "subregion (i.e., the second alloc_subregion should fail). "
269 "subr_extent.c prior to rev. 1.43 allocated region starting " 269 "subr_extent.c prior to rev. 1.43 allocated region starting "
270 "from 0x10"); 270 "from 0x10");
271} 271}
272ATF_TC_BODY(subregion3, tc) 272ATF_TC_BODY(subregion3, tc)
273{ 273{
274 h_create("test8", 0, 0x4f, EX_NOCOALESCE); 274 h_create("test8", 0, 0x4f, EX_NOCOALESCE);
275 275
276 h_alloc_region(0x30, 0x10); 276 h_alloc_region(0x30, 0x10);
277 h_alloc_subregion(0, 0xf, 0x10, EX_NOALIGN, EX_NOBOUNDARY, 0, 0); 277 h_alloc_subregion(0, 0xf, 0x10, EX_NOALIGN, EX_NOBOUNDARY, 0, 0);
278 h_alloc_subregion(0, 0xf, 0x10, EX_NOALIGN, EX_NOBOUNDARY, EAGAIN, 0); 278 h_alloc_subregion(0, 0xf, 0x10, EX_NOALIGN, EX_NOBOUNDARY, EAGAIN, 0);
279 279
280 h_require("test8", 0x0, 0x4f, 0x2, 280 h_require("test8", 0x0, 0x4f, 0x2,
281 "0x0 - 0xf\n" 281 "0x0 - 0xf\n"
282 "0x30 - 0x3f\n"); 282 "0x30 - 0x3f\n");
283 283
284 extent_destroy(ex); 284 extent_destroy(ex);
285} 285}
286 286
287ATF_TC(bound5); 287ATF_TC(bound5);
288ATF_TC_HEAD(bound5, tc) 288ATF_TC_HEAD(bound5, tc)
289{ 289{
290 atf_tc_set_md_var(tc, "descr", 290 atf_tc_set_md_var(tc, "descr",
291 "When allocating a region with a boundary constraint, checks " 291 "When allocating a region with a boundary constraint, checks "
292 "proper detection of overflaps once the candidate region has " 292 "proper detection of overflaps once the candidate region has "
293 "been aligned. subr_extent.c prior 1.45 could corrupt the extent " 293 "been aligned. subr_extent.c prior 1.45 could corrupt the extent "
294 "map in this situation"); 294 "map in this situation");
295} 295}
296ATF_TC_BODY(bound5, tc) 296ATF_TC_BODY(bound5, tc)
297{ 297{
298 h_create("test9", 0, 0x4f, 0); 298 h_create("test9", 0, 0x4f, 0);
299 299
300 h_alloc_subregion(0, 0x10, 4, EX_NOALIGN, 0, 0, 0); 300 h_alloc_subregion(0, 0x10, 4, EX_NOALIGN, 0, 0, 0);
301 h_alloc_subregion(0xd, 0x20, 2, EX_NOALIGN, 0, 0, 0xd); 301 h_alloc_subregion(0xd, 0x20, 2, EX_NOALIGN, 0, 0, 0xd);
302 h_alloc_subregion(0, 0x4f, 8, EX_NOALIGN, 8, 0, 0x10); 302 h_alloc_subregion(0, 0x4f, 8, EX_NOALIGN, 8, 0, 0x10);
303 303
304 h_require("test9", 0x0, 0x4f, 0x0, 304 h_require("test9", 0x0, 0x4f, 0x0,
305 "0x0 - 0x3\n" 305 "0x0 - 0x3\n"
306 "0xd - 0xe\n" 306 "0xd - 0xe\n"
307 "0x10 - 0x17\n"); 307 "0x10 - 0x17\n");
308 308
309 extent_destroy(ex); 309 extent_destroy(ex);
310} 310}
311 311
312ATF_TC(free); 312ATF_TC(free);
313ATF_TC_HEAD(free, tc) 313ATF_TC_HEAD(free, tc)
314{ 314{
315 atf_tc_set_md_var(tc, "descr", "Checks extent_free()"); 315 atf_tc_set_md_var(tc, "descr", "Checks extent_free()");
316} 316}
317ATF_TC_BODY(free, tc) 317ATF_TC_BODY(free, tc)
318{ 318{
319 h_create("test10", 0xc0002000, 0xffffe000, EX_BOUNDZERO); 319 h_create("test10", 0xc0002000, 0xffffe000, EX_BOUNDZERO);
320 320
321 h_alloc_subregion(0xc0002000, 0xffffe000, 0x2000, 321 h_alloc_subregion(0xc0002000, 0xffffe000, 0x2000,
322 0x10000, 0x10000, 0, 0xc0010000); 322 0x10000, 0x10000, 0, 0xc0010000);
323 h_alloc_subregion(0xc0002000, 0xffffe000, 0x2000, 323 h_alloc_subregion(0xc0002000, 0xffffe000, 0x2000,
324 0x10000, 0x10000, 0, 0xc0020000); 324 0x10000, 0x10000, 0, 0xc0020000);
325 325
326 h_require("test10", 0xc0002000, 0xffffe000, 0x0, 326 h_require("test10", 0xc0002000, 0xffffe000, 0x0,
327 "0xc0010000 - 0xc0011fff\n" 327 "0xc0010000 - 0xc0011fff\n"
328 "0xc0020000 - 0xc0021fff\n"); 328 "0xc0020000 - 0xc0021fff\n");
329 329
330 h_free(0xc0020000, 0x2000); 330 h_free(0xc0020000, 0x2000);
331 h_require("test10", 0xc0002000, 0xffffe000, 0x0, 331 h_require("test10", 0xc0002000, 0xffffe000, 0x0,
332 "0xc0010000 - 0xc0011fff\n"); 332 "0xc0010000 - 0xc0011fff\n");
333 333
334 h_alloc_subregion(0xc0002000, 0xffffe000, 0x10000, 334 h_alloc_subregion(0xc0002000, 0xffffe000, 0x10000,
335 0x10000, 0x10000, 0, 0xc0022000); 335 0x10000, 0x10000, 0, 0xc0022000);
336 336
337 h_require("test10", 0xc0002000, 0xffffe000, 0x0, 337 h_require("test10", 0xc0002000, 0xffffe000, 0x0,
338 "0xc0010000 - 0xc0011fff\n" 338 "0xc0010000 - 0xc0011fff\n"
339 "0xc0022000 - 0xc0031fff\n"); 339 "0xc0022000 - 0xc0031fff\n");
340 340
341 extent_destroy(ex); 341 extent_destroy(ex);
342} 342}
343 343
344ATF_TC(subregion4); 344ATF_TC(subregion4);
345ATF_TC_HEAD(subregion4, tc) 345ATF_TC_HEAD(subregion4, tc)
346{ 346{
347 atf_tc_set_md_var(tc, "descr", 347 atf_tc_set_md_var(tc, "descr",
348 "Checks for off-by-one bug which would cause a region at the end " 348 "Checks for off-by-one bug which would cause a region at the end "
349 "of the extent to be allocated multiple times (fixed in 1.51)"); 349 "of the extent to be allocated multiple times (fixed in 1.51)");
350} 350}
351ATF_TC_BODY(subregion4, tc) 351ATF_TC_BODY(subregion4, tc)
352{ 352{
353 h_create("test11", 0x10, 0x20, EX_NOCOALESCE); 353 h_create("test11", 0x10, 0x20, EX_NOCOALESCE);
354 354
355 h_alloc_subregion(0x10, 0x13, 0x4, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x10); 355 h_alloc_subregion(0x10, 0x13, 0x4, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x10);
356 h_alloc_subregion(0x1e, 0x1f, 0x2, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x1e); 356 h_alloc_subregion(0x1e, 0x1f, 0x2, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x1e);
357 h_alloc_subregion(0x20, 0x20, 0x1, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x20); 357 h_alloc_subregion(0x20, 0x20, 0x1, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x20);
358 h_alloc_subregion(0x20, 0x20, 0x1, EX_NOALIGN, EX_NOBOUNDARY, EAGAIN, 0); 358 h_alloc_subregion(0x20, 0x20, 0x1, EX_NOALIGN, EX_NOBOUNDARY, EAGAIN, 0);
359 h_alloc_subregion(0x10, 0x20, 0x1, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x14); 359 h_alloc_subregion(0x10, 0x20, 0x1, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x14);
360 360
361 h_require("test11", 0x10, 0x20, 0x2, 361 h_require("test11", 0x10, 0x20, 0x2,
362 "0x10 - 0x13\n" 362 "0x10 - 0x13\n"
363 "0x14 - 0x14\n" 363 "0x14 - 0x14\n"
364 "0x1e - 0x1f\n" 364 "0x1e - 0x1f\n"
365 "0x20 - 0x20\n"); 365 "0x20 - 0x20\n");
366 366
367 extent_destroy(ex); 367 extent_destroy(ex);
368} 368}
369 369
370ATF_TP_ADD_TCS(tp) 370ATF_TP_ADD_TCS(tp)
371{ 371{
372 ATF_TP_ADD_TC(tp, coalesce); 372 ATF_TP_ADD_TC(tp, coalesce);
373 ATF_TP_ADD_TC(tp, subregion1); 373 ATF_TP_ADD_TC(tp, subregion1);
374 ATF_TP_ADD_TC(tp, subregion2); 374 ATF_TP_ADD_TC(tp, subregion2);
375 ATF_TP_ADD_TC(tp, bound1); 375 ATF_TP_ADD_TC(tp, bound1);
376 ATF_TP_ADD_TC(tp, bound2); 376 ATF_TP_ADD_TC(tp, bound2);
377 ATF_TP_ADD_TC(tp, bound3); 377 ATF_TP_ADD_TC(tp, bound3);
378 ATF_TP_ADD_TC(tp, bound4); 378 ATF_TP_ADD_TC(tp, bound4);
379 ATF_TP_ADD_TC(tp, subregion3); 379 ATF_TP_ADD_TC(tp, subregion3);
380 ATF_TP_ADD_TC(tp, bound5); 380 ATF_TP_ADD_TC(tp, bound5);
381 ATF_TP_ADD_TC(tp, free); 381 ATF_TP_ADD_TC(tp, free);
382 ATF_TP_ADD_TC(tp, subregion4); 382 ATF_TP_ADD_TC(tp, subregion4);
383 383
384 return atf_no_error(); 384 return atf_no_error();
385} 385}

cvs diff -r1.3 -r1.4 src/tests/kernel/t_filedesc.c (switch to unified diff)

--- src/tests/kernel/t_filedesc.c 2010/08/04 14:28:28 1.3
+++ src/tests/kernel/t_filedesc.c 2010/11/03 16:10:20 1.4
@@ -1,108 +1,109 @@ @@ -1,108 +1,109 @@
1/* $NetBSD: t_filedesc.c,v 1.3 2010/08/04 14:28:28 pooka Exp $ */ 1/* $NetBSD: t_filedesc.c,v 1.4 2010/11/03 16:10:20 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__RCSID("$NetBSD: t_filedesc.c,v 1.3 2010/08/04 14:28:28 pooka Exp $"); 30__RCSID("$NetBSD: t_filedesc.c,v 1.4 2010/11/03 16:10:20 christos Exp $");
31 31
32#include <sys/types.h> 32#include <sys/types.h>
33 33
34#include <assert.h> 34#include <assert.h>
35#include <atf-c.h> 35#include <atf-c.h>
36#include <fcntl.h> 36#include <fcntl.h>
37#include <stdlib.h> 37#include <stdlib.h>
 38#include <pthread.h>
38 39
39#include <rump/rump.h> 40#include <rump/rump.h>
40#include <rump/rump_syscalls.h> 41#include <rump/rump_syscalls.h>
41 42
42#include "../h_macros.h" 43#include "../h_macros.h"
43 44
44ATF_TC(getfilerace); 45ATF_TC(getfilerace);
45ATF_TC_HEAD(getfilerace, tc) 46ATF_TC_HEAD(getfilerace, tc)
46{ 47{
47 48
48 atf_tc_set_md_var(tc, "descr", "race between multithreaded proc. " 49 atf_tc_set_md_var(tc, "descr", "race between multithreaded proc. "
49 "fd_getfile() and fd_close()"); 50 "fd_getfile() and fd_close()");
50 /* PR kern/43694 */ 51 /* PR kern/43694 */
51} 52}
52 53
53static int fd; 54static int fd;
54static volatile bool quit; 55static volatile bool quit;
55 56
56static void * 57static void *
57wrkwrk(void *arg) 58wrkwrk(void *arg)
58{ 59{
59 60
60 /* just something to cause fd_getfile() to be called */ 61 /* just something to cause fd_getfile() to be called */
61 while (!quit) 62 while (!quit)
62 rump_sys_write(fd, &fd, sizeof(fd)); 63 rump_sys_write(fd, &fd, sizeof(fd));
63 64
64 return NULL; 65 return NULL;
65} 66}
66 67
67/* for me, 1000 triggers extremely seldom, 10k sometimes, 100k almost always */ 68/* for me, 1000 triggers extremely seldom, 10k sometimes, 100k almost always */
68#define DEFAULT_ITERATIONS 10000 69#define DEFAULT_ITERATIONS 10000
69 70
70ATF_TC_BODY(getfilerace, tc) 71ATF_TC_BODY(getfilerace, tc)
71{ 72{
72 pthread_t pt; 73 pthread_t pt;
73 int fd_wrk; 74 int fd_wrk;
74 int i, iters; 75 int i, iters;
75 76
76 /* 77 /*
77 * Want a multiprocessor virtual kernel. A multiprocessor host 78 * Want a multiprocessor virtual kernel. A multiprocessor host
78 * probably helps too, but that's harder to do in software... 79 * probably helps too, but that's harder to do in software...
79 */ 80 */
80 setenv("RUMP_NCPU", "2", 1); 81 setenv("RUMP_NCPU", "2", 1);
81 rump_init(); 82 rump_init();
82 83
83 fd = fd_wrk = rump_sys_open("/dev/null", O_RDWR, 0); 84 fd = fd_wrk = rump_sys_open("/dev/null", O_RDWR, 0);
84 if (fd == -1) 85 if (fd == -1)
85 atf_tc_fail_errno("cannot open /dev/null"); 86 atf_tc_fail_errno("cannot open /dev/null");
86 87
87 if (atf_tc_has_config_var(tc, "iters")) 88 if (atf_tc_has_config_var(tc, "iters"))
88 iters = atoi(atf_tc_get_config_var(tc, "iters")); 89 iters = atoi(atf_tc_get_config_var(tc, "iters"));
89 else 90 else
90 iters = DEFAULT_ITERATIONS; 91 iters = DEFAULT_ITERATIONS;
91 92
92 pthread_create(&pt, NULL, wrkwrk, NULL); 93 pthread_create(&pt, NULL, wrkwrk, NULL);
93 for (i = 0; i < iters; i++) { 94 for (i = 0; i < iters; i++) {
94 rump_sys_close(fd_wrk); 95 rump_sys_close(fd_wrk);
95 fd_wrk = rump_sys_open("/dev/null", O_RDWR, 0); 96 fd_wrk = rump_sys_open("/dev/null", O_RDWR, 0);
96 assert(fd == fd_wrk); 97 assert(fd == fd_wrk);
97 } 98 }
98 99
99 quit = true; 100 quit = true;
100 pthread_join(pt, NULL); 101 pthread_join(pt, NULL);
101} 102}
102 103
103ATF_TP_ADD_TCS(tp) 104ATF_TP_ADD_TCS(tp)
104{ 105{
105 ATF_TP_ADD_TC(tp, getfilerace); 106 ATF_TP_ADD_TC(tp, getfilerace);
106 107
107 return atf_no_error(); 108 return atf_no_error();
108} 109}

File Added: src/tests/kernel/kqueue/Makefile.inc
.include "../Makefile.inc"

cvs diff -r1.1 -r1.2 src/tests/kernel/kqueue/t_sig.c (switch to unified diff)

--- src/tests/kernel/kqueue/t_sig.c 2009/02/20 21:39:57 1.1
+++ src/tests/kernel/kqueue/t_sig.c 2010/11/03 16:10:20 1.2
@@ -1,133 +1,133 @@ @@ -1,133 +1,133 @@
1/* $NetBSD: t_sig.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $ */ 1/* $NetBSD: t_sig.c,v 1.2 2010/11/03 16:10:20 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Luke Mewburn and Jaromir Dolecek. 8 * by Luke Mewburn and Jaromir Dolecek.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 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 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 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__COPYRIGHT("@(#) Copyright (c) 2008\ 33__COPYRIGHT("@(#) Copyright (c) 2008\
34 The NetBSD Foundation, inc. All rights reserved."); 34 The NetBSD Foundation, inc. All rights reserved.");
35__RCSID("$NetBSD: t_sig.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $"); 35__RCSID("$NetBSD: t_sig.c,v 1.2 2010/11/03 16:10:20 christos Exp $");
36 36
37#include <sys/event.h> 37#include <sys/event.h>
38#include <sys/ioctl.h> 38#include <sys/ioctl.h>
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/time.h> 40#include <sys/time.h>
41#include <sys/wait.h> 41#include <sys/wait.h>
42 42
43#include <inttypes.h> 43#include <inttypes.h>
44#include <signal.h> 44#include <signal.h>
45#include <stdio.h> 45#include <stdio.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <unistd.h> 47#include <unistd.h>
48 48
49#include <atf-c.h> 49#include <atf-c.h>
50 50
51#include "../../h_macros.h" 51#include "../../h_macros.h"
52 52
53#define NSIGNALS 5 53#define NSIGNALS 5
54 54
55ATF_TC(sig); 55ATF_TC(sig);
56ATF_TC_HEAD(sig, tc) 56ATF_TC_HEAD(sig, tc)
57{ 57{
58 atf_tc_set_md_var(tc, "descr", "Checks EVFILT_SIGNAL"); 58 atf_tc_set_md_var(tc, "descr", "Checks EVFILT_SIGNAL");
59} 59}
60ATF_TC_BODY(sig, tc) 60ATF_TC_BODY(sig, tc)
61{ 61{
62 struct timespec timeout; 62 struct timespec timeout;
63 struct kfilter_mapping km; 63 struct kfilter_mapping km;
64 struct kevent event[1]; 64 struct kevent event[1];
65 char namebuf[32]; 65 char namebuf[32];
66 pid_t pid, child; 66 pid_t pid, child;
67 int kq, n, num, status; 67 int kq, n, num, status;
68 68
69 pid = getpid(); 69 pid = getpid();
70 (void)printf("my pid: %d\n", pid); 70 (void)printf("my pid: %d\n", pid);
71 71
72 /* fork a child to send signals */ 72 /* fork a child to send signals */
73 RL(child = fork()); 73 RL(child = fork());
74 if (child == 0) { 74 if (child == 0) {
75 int i; 75 int i;
76 (void)sleep(2); 76 (void)sleep(2);
77 for(i = 0; i < NSIGNALS; ++i) { 77 for(i = 0; i < NSIGNALS; ++i) {
78 (void)kill(pid, SIGUSR1); 78 (void)kill(pid, SIGUSR1);
79 (void)sleep(2); 79 (void)sleep(2);
80 } 80 }
81 _exit(0); 81 _exit(0);
82 /* NOTREACHED */ 82 /* NOTREACHED */
83 } 83 }
84 84
85 RL(kq = kqueue()); 85 RL(kq = kqueue());
86 86
87 (void)strlcpy(namebuf, "EVFILT_SIGNAL", sizeof(namebuf)); 87 (void)strlcpy(namebuf, "EVFILT_SIGNAL", sizeof(namebuf));
88 km.name = namebuf; 88 km.name = namebuf;
89 RL(ioctl(kq, KFILTER_BYNAME, &km)); 89 RL(ioctl(kq, KFILTER_BYNAME, &km));
90 (void)printf("got %d as filter number for `%s'.\n", km.filter, km.name); 90 (void)printf("got %d as filter number for `%s'.\n", km.filter, km.name);
91 91
92 /* ignore the signal to avoid taking it for real */ 92 /* ignore the signal to avoid taking it for real */
93 REQUIRE_LIBC(signal(SIGUSR1, SIG_IGN), SIG_ERR); 93 REQUIRE_LIBC(signal(SIGUSR1, SIG_IGN), SIG_ERR);
94 94
95 event[0].ident = SIGUSR1; 95 event[0].ident = SIGUSR1;
96 event[0].filter = km.filter; 96 event[0].filter = km.filter;
97 event[0].flags = EV_ADD | EV_ENABLE; 97 event[0].flags = EV_ADD | EV_ENABLE;
98 98
99 RL(kevent(kq, event, 1, NULL, 0, NULL)); 99 RL(kevent(kq, event, 1, NULL, 0, NULL));
100 100
101 (void)sleep(1); 101 (void)sleep(1);
102 102
103 timeout.tv_sec = 1; 103 timeout.tv_sec = 1;
104 timeout.tv_nsec = 0; 104 timeout.tv_nsec = 0;
105 105
106 for (num = 0; num < NSIGNALS; num += n) { 106 for (num = 0; num < NSIGNALS; num += n) {
107 struct timeval then, now, diff; 107 struct timeval then, now, diff;
108 108
109 RL(gettimeofday(&then, NULL)); 109 RL(gettimeofday(&then, NULL));
110 RL(n = kevent(kq, NULL, 0, event, 1, &timeout)); 110 RL(n = kevent(kq, NULL, 0, event, 1, &timeout));
111 RL(gettimeofday(&now, NULL)); 111 RL(gettimeofday(&now, NULL));
112 timersub(&now, &then, &diff); 112 timersub(&now, &then, &diff);
113 113
114 (void)printf("sig: kevent returned %d in %ld.%06ld\n", 114 (void)printf("sig: kevent returned %d in %lld.%06ld\n",
115 n, diff.tv_sec, diff.tv_usec); 115 n, (long long)diff.tv_sec, (long)diff.tv_usec);
116 116
117 if (n == 0) 117 if (n == 0)
118 continue; 118 continue;
119 119
120 (void)printf("sig: kevent flags: 0x%x, data: %" PRId64 " (# " 120 (void)printf("sig: kevent flags: 0x%x, data: %" PRId64 " (# "
121 "times signal posted)\n", event[0].flags, event[0].data); 121 "times signal posted)\n", event[0].flags, event[0].data);
122 } 122 }
123 123
124 (void)waitpid(child, &status, 0); 124 (void)waitpid(child, &status, 0);
125 (void)printf("sig: finished successfully\n"); 125 (void)printf("sig: finished successfully\n");
126} 126}
127 127
128ATF_TP_ADD_TCS(tp) 128ATF_TP_ADD_TCS(tp)
129{ 129{
130 ATF_TP_ADD_TC(tp, sig); 130 ATF_TP_ADD_TC(tp, sig);
131 131
132 return atf_no_error(); 132 return atf_no_error();
133} 133}

cvs diff -r1.2 -r1.3 src/tests/kernel/tty/t_pr.c (switch to unified diff)

--- src/tests/kernel/tty/t_pr.c 2010/07/03 08:18:30 1.2
+++ src/tests/kernel/tty/t_pr.c 2010/11/03 16:10:20 1.3
@@ -1,41 +1,40 @@ @@ -1,41 +1,40 @@
1/* $NetBSD: t_pr.c,v 1.2 2010/07/03 08:18:30 jmmv Exp $ */ 1/* $NetBSD: t_pr.c,v 1.3 2010/11/03 16:10:20 christos Exp $ */
2 2
3#include <sys/types.h> 3#include <sys/types.h>
4#include <sys/ioctl.h> 4#include <sys/ioctl.h>
5#include <sys/tty.h> 5#include <sys/tty.h>
6 6
7#include <atf-c.h> 7#include <atf-c.h>
8#include <fcntl.h> 8#include <fcntl.h>
9 9
10#include <rump/rump.h> 10#include <rump/rump.h>
11#include <rump/rump_syscalls.h> 11#include <rump/rump_syscalls.h>
12 12
13ATF_TC(ptyioctl); 13ATF_TC(ptyioctl);
14ATF_TC_HEAD(ptyioctl, tc) 14ATF_TC_HEAD(ptyioctl, tc)
15{ 15{
16 16
17 atf_tc_set_md_var(tc, "descr", "ioctl on pty"); 17 atf_tc_set_md_var(tc, "descr", "ioctl on pty");
18} 18}
19 19
20ATF_TC_BODY(ptyioctl, tc) 20ATF_TC_BODY(ptyioctl, tc)
21{ 21{
22 struct termios tio; 22 struct termios tio;
23 int fd; 23 int fd;
24 24
25 rump_init(); 25 rump_init();
26 fd = rump_sys_open("/dev/ptyp1", O_RDWR); 26 fd = rump_sys_open("/dev/ptyp1", O_RDWR);
27 if (fd == -1) 27 ATF_CHECK(fd != -1);
28 err(1, "open"); 
29 28
30 /* boom, dies with null deref under ptcwakeup() */ 29 /* boom, dies with null deref under ptcwakeup() */
31 atf_tc_expect_signal(-1, "PR kern/40688"); 30 atf_tc_expect_signal(-1, "PR kern/40688");
32 rump_sys_ioctl(fd, TIOCGETA, &tio); 31 rump_sys_ioctl(fd, TIOCGETA, &tio);
33} 32}
34 33
35ATF_TP_ADD_TCS(tp) 34ATF_TP_ADD_TCS(tp)
36{ 35{
37 36
38 ATF_TP_ADD_TC(tp, ptyioctl); 37 ATF_TP_ADD_TC(tp, ptyioctl);
39 38
40 return atf_no_error(); 39 return atf_no_error();
41} 40}

File Added: src/tests/lib/Makefile.inc
.include "../Makefile.inc"

File Added: src/tests/lib/csu/Makefile.inc
.include "../Makefile.inc"

cvs diff -r1.6 -r1.7 src/tests/lib/libc/Makefile (switch to unified diff)

--- src/tests/lib/libc/Makefile 2010/09/09 22:25:38 1.6
+++ src/tests/lib/libc/Makefile 2010/11/03 16:10:21 1.7
@@ -1,12 +1,12 @@ @@ -1,12 +1,12 @@
1# $NetBSD: Makefile,v 1.6 2010/09/09 22:25:38 christos Exp $ 1# $NetBSD: Makefile,v 1.7 2010/11/03 16:10:21 christos Exp $
2 2
3.include <bsd.own.mk> 3.include <bsd.own.mk>
4 4
5TESTS_SUBDIRS+= gen hash stdlib 5TESTS_SUBDIRS+= gen hash stdlib stdio
6 6
7# Disabled for now, only test in there is very expensive 7# Disabled for now, only test in there is very expensive
8#SUBDIR+= string 8SUBDIR+= string
9 9
10TESTSDIR= ${TESTSBASE}/lib/libc 10TESTSDIR= ${TESTSBASE}/lib/libc
11 11
12.include <bsd.test.mk> 12.include <bsd.test.mk>

File Added: src/tests/lib/libc/Makefile.inc
.include "../Makefile.inc"

cvs diff -r1.5 -r1.6 src/tests/lib/libc/gen/Attic/t_glob_star.c (switch to unified diff)

--- src/tests/lib/libc/gen/Attic/t_glob_star.c 2010/10/13 11:19:28 1.5
+++ src/tests/lib/libc/gen/Attic/t_glob_star.c 2010/11/03 16:10:21 1.6
@@ -1,225 +1,225 @@ @@ -1,225 +1,225 @@
1/* $NetBSD: t_glob_star.c,v 1.5 2010/10/13 11:19:28 pooka Exp $ */ 1/* $NetBSD: t_glob_star.c,v 1.6 2010/11/03 16:10:21 christos Exp $ */
2/*- 2/*-
3 * Copyright (c) 2010 The NetBSD Foundation, Inc. 3 * Copyright (c) 2010 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Christos Zoulas 7 * by Christos Zoulas
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 12 *
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the 17 * the documentation and/or other materials provided with the
18 * distribution. 18 * distribution.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE. 31 * SUCH DAMAGE.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__RCSID("$NetBSD: t_glob_star.c,v 1.5 2010/10/13 11:19:28 pooka Exp $"); 35__RCSID("$NetBSD: t_glob_star.c,v 1.6 2010/11/03 16:10:21 christos Exp $");
36 36
37#include <atf-c.h> 37#include <atf-c.h>
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/stat.h> 40#include <sys/stat.h>
41 41
42#include <dirent.h> 42#include <dirent.h>
43#include <glob.h> 43#include <glob.h>
44#include <stdio.h> 44#include <stdio.h>
45#include <stdlib.h> 45#include <stdlib.h>
46#include <string.h> 46#include <string.h>
47#include <errno.h> 47#include <errno.h>
48 48
49#include "../../../h_macros.h" 49#include "../../../h_macros.h"
50 50
51 51
52#ifdef DEBUG 52#ifdef DEBUG
53#define DPRINTF(a) printf a 53#define DPRINTF(a) printf a
54#else 54#else
55#define DPRINTF(a) 55#define DPRINTF(a)
56#endif 56#endif
57 57
58ATF_TC(t_glob_star); 58ATF_TC(t_glob_star);
59ATF_TC(t_glob_star_not); 59ATF_TC(t_glob_star_not);
60 60
61struct gl_file { 61struct gl_file {
62 const char *name; 62 const char *name;
63 int dir; 63 int dir;
64}; 64};
65 65
66static struct gl_file a[] = { 66static struct gl_file a[] = {
67 { "1", 0 }, 67 { "1", 0 },
68 { "b", 1 }, 68 { "b", 1 },
69 { "3", 0 }, 69 { "3", 0 },
70 { "4", 0 }, 70 { "4", 0 },
71}; 71};
72 72
73static struct gl_file b[] = { 73static struct gl_file b[] = {
74 { "x", 0 }, 74 { "x", 0 },
75 { "y", 0 }, 75 { "y", 0 },
76 { "z", 0 }, 76 { "z", 0 },
77 { "w", 0 }, 77 { "w", 0 },
78}; 78};
79 79
80struct gl_dir { 80struct gl_dir {
81 const char *name; /* directory name */ 81 const char *name; /* directory name */
82 const struct gl_file *dir; 82 const struct gl_file *dir;
83 size_t len, pos; 83 size_t len, pos;
84}; 84};
85 85
86static struct gl_dir d[] = { 86static struct gl_dir d[] = {
87 { "a", a, __arraycount(a), 0 }, 87 { "a", a, __arraycount(a), 0 },
88 { "a/b", b, __arraycount(b), 0 }, 88 { "a/b", b, __arraycount(b), 0 },
89}; 89};
90 90
91static const char *glob_star[] = {  91static const char *glob_star[] = {
92 "a/1", "a/3", "a/4", "a/b", "a/b/w", "a/b/x", "a/b/y", "a/b/z", 92 "a/1", "a/3", "a/4", "a/b", "a/b/w", "a/b/x", "a/b/y", "a/b/z",
93}; 93};
94 94
95static const char *glob_star_not[] = { 95static const char *glob_star_not[] = {
96 "a/1", "a/3", "a/4", "a/b", 96 "a/1", "a/3", "a/4", "a/b",
97}; 97};
98 98
99static void 99static void
100trim(char *buf, size_t len, const char *name) 100trim(char *buf, size_t len, const char *name)
101{ 101{
102 char *path = buf, *epath = buf + len; 102 char *path = buf, *epath = buf + len;
103 while (path < epath && (*path++ = *name++) != '\0') 103 while (path < epath && (*path++ = *name++) != '\0')
104 continue; 104 continue;
105 path--; 105 path--;
106 while (path > buf && *--path == '/') 106 while (path > buf && *--path == '/')
107 *path = '\0'; 107 *path = '\0';
108} 108}
109 109
110static void * 110static void *
111gl_opendir(const char *dir) 111gl_opendir(const char *dir)
112{ 112{
113 size_t i; 113 size_t i;
114 char buf[MAXPATHLEN]; 114 char buf[MAXPATHLEN];
115 trim(buf, sizeof(buf), dir); 115 trim(buf, sizeof(buf), dir);
116 116
117 for (i = 0; i < __arraycount(d); i++) 117 for (i = 0; i < __arraycount(d); i++)
118 if (strcmp(buf, d[i].name) == 0) { 118 if (strcmp(buf, d[i].name) == 0) {
119 DPRINTF(("opendir %s %zu\n", buf, i)); 119 DPRINTF(("opendir %s %zu\n", buf, i));
120 return &d[i]; 120 return &d[i];
121 } 121 }
122 errno = ENOENT; 122 errno = ENOENT;
123 return NULL; 123 return NULL;
124} 124}
125 125
126static struct dirent * 126static struct dirent *
127gl_readdir(void *v) 127gl_readdir(void *v)
128{ 128{
129 static struct dirent dir; 129 static struct dirent dir;
130 struct gl_dir *d = v; 130 struct gl_dir *dd = v;
131 if (d->pos < d->len) { 131 if (dd->pos < dd->len) {
132 const struct gl_file *f = &d->dir[d->pos++]; 132 const struct gl_file *f = &dd->dir[dd->pos++];
133 strcpy(dir.d_name, f->name); 133 strcpy(dir.d_name, f->name);
134 dir.d_namlen = strlen(f->name); 134 dir.d_namlen = strlen(f->name);
135 dir.d_ino = d->pos; 135 dir.d_ino = dd->pos;
136 dir.d_type = f->dir ? DT_DIR : DT_REG; 136 dir.d_type = f->dir ? DT_DIR : DT_REG;
137 DPRINTF(("readdir %s %d\n", dir.d_name, dir.d_type)); 137 DPRINTF(("readdir %s %d\n", dir.d_name, dir.d_type));
138 dir.d_reclen = _DIRENT_RECLEN(&dir, dir.d_namlen); 138 dir.d_reclen = _DIRENT_RECLEN(&dir, dir.d_namlen);
139 return &dir; 139 return &dir;
140 } 140 }
141 return NULL; 141 return NULL;
142} 142}
143 143
144static int 144static int
145gl_stat(const char *name , __gl_stat_t *st) 145gl_stat(const char *name , __gl_stat_t *st)
146{ 146{
147 char buf[MAXPATHLEN]; 147 char buf[MAXPATHLEN];
148 trim(buf, sizeof(buf), name); 148 trim(buf, sizeof(buf), name);
149 memset(st, 0, sizeof(*st)); 149 memset(st, 0, sizeof(*st));
150 if (strcmp(buf, "a") == 0 || strcmp(buf, "a/b") == 0) 150 if (strcmp(buf, "a") == 0 || strcmp(buf, "a/b") == 0)
151 st->st_mode |= _S_IFDIR; 151 st->st_mode |= _S_IFDIR;
152 DPRINTF(("stat %s %d\n", buf, st->st_mode)); 152 DPRINTF(("stat %s %d\n", buf, st->st_mode));
153 return 0; 153 return 0;
154} 154}
155 155
156static int 156static int
157gl_lstat(const char *name , __gl_stat_t *st) 157gl_lstat(const char *name , __gl_stat_t *st)
158{ 158{
159 return gl_stat(name, st); 159 return gl_stat(name, st);
160} 160}
161 161
162static void 162static void
163gl_closedir(void *v) 163gl_closedir(void *v)
164{ 164{
165 struct gl_dir *d = v; 165 struct gl_dir *dd = v;
166 d->pos = 0; 166 dd->pos = 0;
167 DPRINTF(("closedir %p\n", d)); 167 DPRINTF(("closedir %p\n", dd));
168} 168}
169 169
170static void 170static void
171run(const char *p, int flags, const char **res, size_t len) 171run(const char *p, int flags, const char **res, size_t len)
172{ 172{
173 glob_t gl; 173 glob_t gl;
174 size_t i; 174 size_t i;
175 175
176 memset(&gl, 0, sizeof(gl)); 176 memset(&gl, 0, sizeof(gl));
177 gl.gl_opendir = gl_opendir; 177 gl.gl_opendir = gl_opendir;
178 gl.gl_readdir = gl_readdir; 178 gl.gl_readdir = gl_readdir;
179 gl.gl_closedir = gl_closedir; 179 gl.gl_closedir = gl_closedir;
180 gl.gl_stat = gl_stat; 180 gl.gl_stat = gl_stat;
181 gl.gl_lstat = gl_lstat; 181 gl.gl_lstat = gl_lstat;
182 182
183 RZ(glob(p, GLOB_ALTDIRFUNC | flags, NULL, &gl)); 183 RZ(glob(p, GLOB_ALTDIRFUNC | flags, NULL, &gl));
184 184
185 for (i = 0; i < gl.gl_pathc; i++) 185 for (i = 0; i < gl.gl_pathc; i++)
186 DPRINTF(("%s\n", gl.gl_pathv[i])); 186 DPRINTF(("%s\n", gl.gl_pathv[i]));
187 187
188 ATF_CHECK(len == gl.gl_pathc); 188 ATF_CHECK(len == gl.gl_pathc);
189 for (i = 0; i < gl.gl_pathc; i++) 189 for (i = 0; i < gl.gl_pathc; i++)
190 ATF_CHECK_STREQ(gl.gl_pathv[i], res[i]); 190 ATF_CHECK_STREQ(gl.gl_pathv[i], res[i]);
191 191
192 globfree(&gl); 192 globfree(&gl);
193} 193}
194 194
195 195
196ATF_TC_HEAD(t_glob_star, tc) 196ATF_TC_HEAD(t_glob_star, tc)
197{ 197{
198 atf_tc_set_md_var(tc, "descr", 198 atf_tc_set_md_var(tc, "descr",
199 "Test glob(3) ** with GLOB_STAR"); 199 "Test glob(3) ** with GLOB_STAR");
200} 200}
201 201
202ATF_TC_BODY(t_glob_star, tc) 202ATF_TC_BODY(t_glob_star, tc)
203{ 203{
204 run("a/**", GLOB_STAR, glob_star, __arraycount(glob_star)); 204 run("a/**", GLOB_STAR, glob_star, __arraycount(glob_star));
205} 205}
206 206
207ATF_TC_HEAD(t_glob_star_not, tc) 207ATF_TC_HEAD(t_glob_star_not, tc)
208{ 208{
209 atf_tc_set_md_var(tc, "descr", 209 atf_tc_set_md_var(tc, "descr",
210 "Test glob(3) ** without GLOB_STAR"); 210 "Test glob(3) ** without GLOB_STAR");
211} 211}
212 212
213 213
214ATF_TC_BODY(t_glob_star_not, tc) 214ATF_TC_BODY(t_glob_star_not, tc)
215{ 215{
216 run("a/**", 0, glob_star_not, __arraycount(glob_star_not)); 216 run("a/**", 0, glob_star_not, __arraycount(glob_star_not));
217} 217}
218 218
219ATF_TP_ADD_TCS(tp) 219ATF_TP_ADD_TCS(tp)
220{ 220{
221 ATF_TP_ADD_TC(tp, t_glob_star); 221 ATF_TP_ADD_TC(tp, t_glob_star);
222 ATF_TP_ADD_TC(tp, t_glob_star_not); 222 ATF_TP_ADD_TC(tp, t_glob_star_not);
223 223
224 return atf_no_error(); 224 return atf_no_error();
225} 225}

cvs diff -r1.1 -r1.2 src/tests/lib/libc/hash/t_sha2.c (switch to unified diff)

--- src/tests/lib/libc/hash/t_sha2.c 2010/01/24 21:12:17 1.1
+++ src/tests/lib/libc/hash/t_sha2.c 2010/11/03 16:10:22 1.2
@@ -1,243 +1,243 @@ @@ -1,243 +1,243 @@
1/* $NetBSD: t_sha2.c,v 1.1 2010/01/24 21:12:17 joerg Exp $ */ 1/* $NetBSD: t_sha2.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */
2/*- 2/*-
3 * Copyright (c) 20010 The NetBSD Foundation, Inc. 3 * Copyright (c) 20010 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Joerg Sonnenberger. 7 * by Joerg Sonnenberger.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 12 *
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the 17 * the documentation and/or other materials provided with the
18 * distribution. 18 * distribution.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE. 31 * SUCH DAMAGE.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__RCSID("$NetBSD: t_sha2.c,v 1.1 2010/01/24 21:12:17 joerg Exp $"); 35__RCSID("$NetBSD: t_sha2.c,v 1.2 2010/11/03 16:10:22 christos Exp $");
36 36
37#include <atf-c.h> 37#include <atf-c.h>
38#include <sys/types.h> 38#include <sys/types.h>
39#include <sha2.h> 39#include <sha2.h>
40#include <string.h> 40#include <string.h>
41 41
42ATF_TC(t_sha256); 42ATF_TC(t_sha256);
43ATF_TC(t_sha384); 43ATF_TC(t_sha384);
44ATF_TC(t_sha512); 44ATF_TC(t_sha512);
45 45
46ATF_TP_ADD_TCS(tp) 46ATF_TP_ADD_TCS(tp)
47{ 47{
48 ATF_TP_ADD_TC(tp, t_sha256); 48 ATF_TP_ADD_TC(tp, t_sha256);
49 ATF_TP_ADD_TC(tp, t_sha384); 49 ATF_TP_ADD_TC(tp, t_sha384);
50 ATF_TP_ADD_TC(tp, t_sha512); 50 ATF_TP_ADD_TC(tp, t_sha512);
51 51
52 return atf_no_error(); 52 return atf_no_error();
53} 53}
54 54
55struct testvector { 55struct testvector {
56 const char *vector; 56 const char *vector;
57 const char *hash; 57 const char *hash;
58}; 58};
59 59
60static const struct testvector test256[] = { 60static const struct testvector test256[] = {
61 { "hello, world", "09ca7e4eaa6e8ae9c7d261167129184883644d07dfba7cbfbc4c8a2e08360d5b" }, 61 { "hello, world", "09ca7e4eaa6e8ae9c7d261167129184883644d07dfba7cbfbc4c8a2e08360d5b" },
62 { "", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, 62 { "", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" },
63 { "a", "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb" }, 63 { "a", "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb" },
64 { "ab", "fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603" }, 64 { "ab", "fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603" },
65 { "abc", "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" }, 65 { "abc", "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" },
66 { "abcd", "88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589" }, 66 { "abcd", "88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589" },
67 { "abcde", "36bbe50ed96841d10443bcb670d6554f0a34b761be67ec9c4a8ad2c0c44ca42c" }, 67 { "abcde", "36bbe50ed96841d10443bcb670d6554f0a34b761be67ec9c4a8ad2c0c44ca42c" },
68 { "abcdef", "bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c4721" }, 68 { "abcdef", "bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c4721" },
69 { "abcdefg", "7d1a54127b222502f5b79b5fb0803061152a44f92b37e23c6527baf665d4da9a" }, 69 { "abcdefg", "7d1a54127b222502f5b79b5fb0803061152a44f92b37e23c6527baf665d4da9a" },
70 { "abcdefgh", "9c56cc51b374c3ba189210d5b6d4bf57790d351c96c47c02190ecf1e430635ab" }, 70 { "abcdefgh", "9c56cc51b374c3ba189210d5b6d4bf57790d351c96c47c02190ecf1e430635ab" },
71 { "abcdefghi", "19cc02f26df43cc571bc9ed7b0c4d29224a3ec229529221725ef76d021c8326f" }, 71 { "abcdefghi", "19cc02f26df43cc571bc9ed7b0c4d29224a3ec229529221725ef76d021c8326f" },
72 { "abcdefghij", "72399361da6a7754fec986dca5b7cbaf1c810a28ded4abaf56b2106d06cb78b0" }, 72 { "abcdefghij", "72399361da6a7754fec986dca5b7cbaf1c810a28ded4abaf56b2106d06cb78b0" },
73 { "abcdefghijk", "ca2f2069ea0c6e4658222e06f8dd639659cbb5e67cbbba6734bc334a3799bc68" }, 73 { "abcdefghijk", "ca2f2069ea0c6e4658222e06f8dd639659cbb5e67cbbba6734bc334a3799bc68" },
74 { "abcdefghijkl", "d682ed4ca4d989c134ec94f1551e1ec580dd6d5a6ecde9f3d35e6e4a717fbde4" }, 74 { "abcdefghijkl", "d682ed4ca4d989c134ec94f1551e1ec580dd6d5a6ecde9f3d35e6e4a717fbde4" },
75 { "abcdefghijklm", "ff10304f1af23606ede1e2d8abcdc94c229047a61458d809d8bbd53ede1f6598" }, 75 { "abcdefghijklm", "ff10304f1af23606ede1e2d8abcdc94c229047a61458d809d8bbd53ede1f6598" },
76 { "abcdefghijklmn", "0653c7e992d7aad40cb2635738b870e4c154afb346340d02c797d490dd52d5f9" }, 76 { "abcdefghijklmn", "0653c7e992d7aad40cb2635738b870e4c154afb346340d02c797d490dd52d5f9" },
77 { "abcdefghijklmno", "41c7760c50efde99bf574ed8fffc7a6dd3405d546d3da929b214c8945acf8a97" }, 77 { "abcdefghijklmno", "41c7760c50efde99bf574ed8fffc7a6dd3405d546d3da929b214c8945acf8a97" },
78 { "abcdefghijklmnop", "f39dac6cbaba535e2c207cd0cd8f154974223c848f727f98b3564cea569b41cf" }, 78 { "abcdefghijklmnop", "f39dac6cbaba535e2c207cd0cd8f154974223c848f727f98b3564cea569b41cf" },
79 { "abcdefghijklmnopq", "918a954ac4dfb54ac39f068d9868227f69ab39bc362e2c9b0083bf6a109d6ad7" }, 79 { "abcdefghijklmnopq", "918a954ac4dfb54ac39f068d9868227f69ab39bc362e2c9b0083bf6a109d6ad7" },
80 { "abcdefghijklmnopqr", "2d1222692afaf56e95a8ab00879ed023a00db3e26fa14236e542748579285efa" }, 80 { "abcdefghijklmnopqr", "2d1222692afaf56e95a8ab00879ed023a00db3e26fa14236e542748579285efa" },
81 { "abcdefghijklmnopqrs", "e250f886728b77ba63722c7e65fc73e203101a84281b32332fd67cc6a1ae3e22" }, 81 { "abcdefghijklmnopqrs", "e250f886728b77ba63722c7e65fc73e203101a84281b32332fd67cc6a1ae3e22" },
82 { "abcdefghijklmnopqrst", "dd65eea0329dcb94b17187af9dff28c31a1d78026737a16af75979a1fa4618e5" }, 82 { "abcdefghijklmnopqrst", "dd65eea0329dcb94b17187af9dff28c31a1d78026737a16af75979a1fa4618e5" },
83 { "abcdefghijklmnopqrstu", "25f62a5a3d414ec6e20907df7f367f2b72625aade552db64c07933f6044fc49a" }, 83 { "abcdefghijklmnopqrstu", "25f62a5a3d414ec6e20907df7f367f2b72625aade552db64c07933f6044fc49a" },
84 { "abcdefghijklmnopqrstuv", "f69f9b70d1c9a5442258ca76f8b0a7a45fcb4e31c36141b6357ec591328b0624" }, 84 { "abcdefghijklmnopqrstuv", "f69f9b70d1c9a5442258ca76f8b0a7a45fcb4e31c36141b6357ec591328b0624" },
85 { "abcdefghijklmnopqrstuvw", "7f07818e14d08944ce145629ca54332f5cfad148c590efbcb5c377f4d336e5f4" }, 85 { "abcdefghijklmnopqrstuvw", "7f07818e14d08944ce145629ca54332f5cfad148c590efbcb5c377f4d336e5f4" },
86 { "abcdefghijklmnopqrstuvwq", "063132d7fbec0acb79b2f228777eec8885e7f09bc1896b3ce5aa1843e83de048" }, 86 { "abcdefghijklmnopqrstuvwq", "063132d7fbec0acb79b2f228777eec8885e7f09bc1896b3ce5aa1843e83de048" },
87}; 87};
88 88
89static const struct testvector test384[] = { 89static const struct testvector test384[] = {
90 { "hello, world", "1fcdb6059ce05172a26bbe2a3ccc88ed5a8cd5fc53edfd9053304d429296a6da23b1cd9e5c9ed3bb34f00418a70cdb7e" }, 90 { "hello, world", "1fcdb6059ce05172a26bbe2a3ccc88ed5a8cd5fc53edfd9053304d429296a6da23b1cd9e5c9ed3bb34f00418a70cdb7e" },
91 { "", "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b" }, 91 { "", "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b" },
92 { "a", "54a59b9f22b0b80880d8427e548b7c23abd873486e1f035dce9cd697e85175033caa88e6d57bc35efae0b5afd3145f31" }, 92 { "a", "54a59b9f22b0b80880d8427e548b7c23abd873486e1f035dce9cd697e85175033caa88e6d57bc35efae0b5afd3145f31" },
93 { "ab", "c7be03ba5bcaa384727076db0018e99248e1a6e8bd1b9ef58a9ec9dd4eeebb3f48b836201221175befa74ddc3d35afdd" }, 93 { "ab", "c7be03ba5bcaa384727076db0018e99248e1a6e8bd1b9ef58a9ec9dd4eeebb3f48b836201221175befa74ddc3d35afdd" },
94 { "abc", "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7" }, 94 { "abc", "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7" },
95 { "abcd", "1165b3406ff0b52a3d24721f785462ca2276c9f454a116c2b2ba20171a7905ea5a026682eb659c4d5f115c363aa3c79b" }, 95 { "abcd", "1165b3406ff0b52a3d24721f785462ca2276c9f454a116c2b2ba20171a7905ea5a026682eb659c4d5f115c363aa3c79b" },
96 { "abcde", "4c525cbeac729eaf4b4665815bc5db0c84fe6300068a727cf74e2813521565abc0ec57a37ee4d8be89d097c0d2ad52f0" }, 96 { "abcde", "4c525cbeac729eaf4b4665815bc5db0c84fe6300068a727cf74e2813521565abc0ec57a37ee4d8be89d097c0d2ad52f0" },
97 { "abcdef", "c6a4c65b227e7387b9c3e839d44869c4cfca3ef583dea64117859b808c1e3d8ae689e1e314eeef52a6ffe22681aa11f5" }, 97 { "abcdef", "c6a4c65b227e7387b9c3e839d44869c4cfca3ef583dea64117859b808c1e3d8ae689e1e314eeef52a6ffe22681aa11f5" },
98 { "abcdefg", "9f11fc131123f844c1226f429b6a0a6af0525d9f40f056c7fc16cdf1b06bda08e302554417a59fa7dcf6247421959d22" }, 98 { "abcdefg", "9f11fc131123f844c1226f429b6a0a6af0525d9f40f056c7fc16cdf1b06bda08e302554417a59fa7dcf6247421959d22" },
99 { "abcdefgh", "9000cd7cada59d1d2eb82912f7f24e5e69cc5517f68283b005fa27c285b61e05edf1ad1a8a9bded6fd29eb87d75ad806" }, 99 { "abcdefgh", "9000cd7cada59d1d2eb82912f7f24e5e69cc5517f68283b005fa27c285b61e05edf1ad1a8a9bded6fd29eb87d75ad806" },
100 { "abcdefghi", "ef54915b60cf062b8dd0c29ae3cad69abe6310de63ac081f46ef019c5c90897caefd79b796cfa81139788a260ded52df" }, 100 { "abcdefghi", "ef54915b60cf062b8dd0c29ae3cad69abe6310de63ac081f46ef019c5c90897caefd79b796cfa81139788a260ded52df" },
101 { "abcdefghij", "a12070030a02d86b0ddacd0d3a5b598344513d0a051e7355053e556a0055489c1555399b03342845c4adde2dc44ff66c" }, 101 { "abcdefghij", "a12070030a02d86b0ddacd0d3a5b598344513d0a051e7355053e556a0055489c1555399b03342845c4adde2dc44ff66c" },
102 { "abcdefghijk", "2440d0e751fe5b8b1aba067e20be00b9deecc5e218b0b4b37202de824bcd04294d67c8d0b73e393afa844fa9ca25fa51" }, 102 { "abcdefghijk", "2440d0e751fe5b8b1aba067e20be00b9deecc5e218b0b4b37202de824bcd04294d67c8d0b73e393afa844fa9ca25fa51" },
103 { "abcdefghijkl", "103ca96c06a1ce798f08f8eff0dfb0ccdb567d48b285b23d0cd773454667a3c2fa5f1b58d9cdf2329bd9979730bfaaff" }, 103 { "abcdefghijkl", "103ca96c06a1ce798f08f8eff0dfb0ccdb567d48b285b23d0cd773454667a3c2fa5f1b58d9cdf2329bd9979730bfaaff" },
104 { "abcdefghijklm", "89a7179df195462f047393c36e4843183eb38404bdfbacfd0b0f9c2556632a2799f19c3ecf48bdb7c9bdf95d3f6c3704" }, 104 { "abcdefghijklm", "89a7179df195462f047393c36e4843183eb38404bdfbacfd0b0f9c2556632a2799f19c3ecf48bdb7c9bdf95d3f6c3704" },
105 { "abcdefghijklmn", "3bc463b0a5614d39fd207cbfd108534bce68d5438235c6c577b34b70fe219954adceaf8808d1fad4a44fc9c420ea8ff1" }, 105 { "abcdefghijklmn", "3bc463b0a5614d39fd207cbfd108534bce68d5438235c6c577b34b70fe219954adceaf8808d1fad4a44fc9c420ea8ff1" },
106 { "abcdefghijklmno", "5149860ee76dd6666308189e60090d615e36ce0c0ef753a610cca0524a022900489d70167a47cc74c4dd9f9f340066af" }, 106 { "abcdefghijklmno", "5149860ee76dd6666308189e60090d615e36ce0c0ef753a610cca0524a022900489d70167a47cc74c4dd9f9f340066af" },
107 { "abcdefghijklmnop", "96d3c1b54b1938600abe5b57232e185df1c5856f74656b8f9837c5317cf5b22ac38226fafc8c946b9d20aca1b0c53a98" }, 107 { "abcdefghijklmnop", "96d3c1b54b1938600abe5b57232e185df1c5856f74656b8f9837c5317cf5b22ac38226fafc8c946b9d20aca1b0c53a98" },
108 { "abcdefghijklmnopq", "dae0d8c29d8f1137df3afb8f502dc474d3bbb56de0c10fc219547826f23f38f37ec29e4ed203908e6e7955c83a138129" }, 108 { "abcdefghijklmnopq", "dae0d8c29d8f1137df3afb8f502dc474d3bbb56de0c10fc219547826f23f38f37ec29e4ed203908e6e7955c83a138129" },
109 { "abcdefghijklmnopqr", "5cfa62716d985d3b1efab0ed3460e7b7f6af9439ae8ee5c58b20e68607eeec3e8c6df8481f5f36e726eaa56512acea6e" }, 109 { "abcdefghijklmnopqr", "5cfa62716d985d3b1efab0ed3460e7b7f6af9439ae8ee5c58b20e68607eeec3e8c6df8481f5f36e726eaa56512acea6e" },
110 { "abcdefghijklmnopqrs", "c5d404fc93b0e59ecb5f40446da201876faf18a0af46e577ae2f7a4fe56dc4c419afff7edec90ff3de160d0c5e7a5ec1" }, 110 { "abcdefghijklmnopqrs", "c5d404fc93b0e59ecb5f40446da201876faf18a0af46e577ae2f7a4fe56dc4c419afff7edec90ff3de160d0c5e7a5ec1" },
111 { "abcdefghijklmnopqrst", "bc1511cd8b813544cb60b13d1ceb63e81f46aa3ca114a23fc5c3aba54f9965cdf9afa68e2dc2a680934e429dff5aa7f2" }, 111 { "abcdefghijklmnopqrst", "bc1511cd8b813544cb60b13d1ceb63e81f46aa3ca114a23fc5c3aba54f9965cdf9afa68e2dc2a680934e429dff5aa7f2" },
112 { "abcdefghijklmnopqrstu", "8f18622d37e0aceabba191e3836b30e8970aca202ce6e811f586ec5f950edb7bf799cc88a18468a3effb063397242d95" }, 112 { "abcdefghijklmnopqrstu", "8f18622d37e0aceabba191e3836b30e8970aca202ce6e811f586ec5f950edb7bf799cc88a18468a3effb063397242d95" },
113 { "abcdefghijklmnopqrstuv", "c8a4f46e609626543ce6c1362721fcbe95c8e7405aaee61da4f2da1740f0351172c98a66530f8607bf8609e387ff8456" }, 113 { "abcdefghijklmnopqrstuv", "c8a4f46e609626543ce6c1362721fcbe95c8e7405aaee61da4f2da1740f0351172c98a66530f8607bf8609e387ff8456" },
114 { "abcdefghijklmnopqrstuvw", "2daff33b3bd67de61550070696b431d54b1397b40d053912b07a94260812185907726e3efbe9ae9fc078659cd2ce36db" }, 114 { "abcdefghijklmnopqrstuvw", "2daff33b3bd67de61550070696b431d54b1397b40d053912b07a94260812185907726e3efbe9ae9fc078659cd2ce36db" },
115 { "abcdefghijklmnopqrstuvwq", "87dc70a2eaa0dd0b687f91f26383866161026e41bb310a9e32b7a17c99284db85b9743476a30caeedf3fbb3c8072bc5e" }, 115 { "abcdefghijklmnopqrstuvwq", "87dc70a2eaa0dd0b687f91f26383866161026e41bb310a9e32b7a17c99284db85b9743476a30caeedf3fbb3c8072bc5e" },
116}; 116};
117 117
118static const struct testvector test512[] = { 118static const struct testvector test512[] = {
119 { "hello, world", "8710339dcb6814d0d9d2290ef422285c9322b7163951f9a0ca8f883d3305286f44139aa374848e4174f5aada663027e4548637b6d19894aec4fb6c46a139fbf9" }, 119 { "hello, world", "8710339dcb6814d0d9d2290ef422285c9322b7163951f9a0ca8f883d3305286f44139aa374848e4174f5aada663027e4548637b6d19894aec4fb6c46a139fbf9" },
120 { "", "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" }, 120 { "", "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" },
121 { "a", "1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75" }, 121 { "a", "1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75" },
122 { "ab", "2d408a0717ec188158278a796c689044361dc6fdde28d6f04973b80896e1823975cdbf12eb63f9e0591328ee235d80e9b5bf1aa6a44f4617ff3caf6400eb172d" }, 122 { "ab", "2d408a0717ec188158278a796c689044361dc6fdde28d6f04973b80896e1823975cdbf12eb63f9e0591328ee235d80e9b5bf1aa6a44f4617ff3caf6400eb172d" },
123 { "abc", "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" }, 123 { "abc", "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" },
124 { "abcd", "d8022f2060ad6efd297ab73dcc5355c9b214054b0d1776a136a669d26a7d3b14f73aa0d0ebff19ee333368f0164b6419a96da49e3e481753e7e96b716bdccb6f" }, 124 { "abcd", "d8022f2060ad6efd297ab73dcc5355c9b214054b0d1776a136a669d26a7d3b14f73aa0d0ebff19ee333368f0164b6419a96da49e3e481753e7e96b716bdccb6f" },
125 { "abcde", "878ae65a92e86cac011a570d4c30a7eaec442b85ce8eca0c2952b5e3cc0628c2e79d889ad4d5c7c626986d452dd86374b6ffaa7cd8b67665bef2289a5c70b0a1" }, 125 { "abcde", "878ae65a92e86cac011a570d4c30a7eaec442b85ce8eca0c2952b5e3cc0628c2e79d889ad4d5c7c626986d452dd86374b6ffaa7cd8b67665bef2289a5c70b0a1" },
126 { "abcdef", "e32ef19623e8ed9d267f657a81944b3d07adbb768518068e88435745564e8d4150a0a703be2a7d88b61e3d390c2bb97e2d4c311fdc69d6b1267f05f59aa920e7" }, 126 { "abcdef", "e32ef19623e8ed9d267f657a81944b3d07adbb768518068e88435745564e8d4150a0a703be2a7d88b61e3d390c2bb97e2d4c311fdc69d6b1267f05f59aa920e7" },
127 { "abcdefg", "d716a4188569b68ab1b6dfac178e570114cdf0ea3a1cc0e31486c3e41241bc6a76424e8c37ab26f096fc85ef9886c8cb634187f4fddff645fb099f1ff54c6b8c" }, 127 { "abcdefg", "d716a4188569b68ab1b6dfac178e570114cdf0ea3a1cc0e31486c3e41241bc6a76424e8c37ab26f096fc85ef9886c8cb634187f4fddff645fb099f1ff54c6b8c" },
128 { "abcdefgh", "a3a8c81bc97c2560010d7389bc88aac974a104e0e2381220c6e084c4dccd1d2d17d4f86db31c2a851dc80e6681d74733c55dcd03dd96f6062cdda12a291ae6ce" }, 128 { "abcdefgh", "a3a8c81bc97c2560010d7389bc88aac974a104e0e2381220c6e084c4dccd1d2d17d4f86db31c2a851dc80e6681d74733c55dcd03dd96f6062cdda12a291ae6ce" },
129 { "abcdefghi", "f22d51d25292ca1d0f68f69aedc7897019308cc9db46efb75a03dd494fc7f126c010e8ade6a00a0c1a5f1b75d81e0ed5a93ce98dc9b833db7839247b1d9c24fe" }, 129 { "abcdefghi", "f22d51d25292ca1d0f68f69aedc7897019308cc9db46efb75a03dd494fc7f126c010e8ade6a00a0c1a5f1b75d81e0ed5a93ce98dc9b833db7839247b1d9c24fe" },
130 { "abcdefghij", "ef6b97321f34b1fea2169a7db9e1960b471aa13302a988087357c520be957ca119c3ba68e6b4982c019ec89de3865ccf6a3cda1fe11e59f98d99f1502c8b9745" }, 130 { "abcdefghij", "ef6b97321f34b1fea2169a7db9e1960b471aa13302a988087357c520be957ca119c3ba68e6b4982c019ec89de3865ccf6a3cda1fe11e59f98d99f1502c8b9745" },
131 { "abcdefghijk", "2798fd001ee8800e3da09ee99ae9600de2d0ccf464ab782c92fcc06ce3847cef0743365f1d49c2c8b4426db1635433f937d508672a9d0cb673b84f368eca1b23" }, 131 { "abcdefghijk", "2798fd001ee8800e3da09ee99ae9600de2d0ccf464ab782c92fcc06ce3847cef0743365f1d49c2c8b4426db1635433f937d508672a9d0cb673b84f368eca1b23" },
132 { "abcdefghijkl", "17807c728ee3ba35e7cf7af823116d26e41e5d4d6c2ff1f3720d3d96aacb6f69de642e63d5b73fc396c12be38b2bd5d884257c32c8f6d0854ae6b540f86dda2e" }, 132 { "abcdefghijkl", "17807c728ee3ba35e7cf7af823116d26e41e5d4d6c2ff1f3720d3d96aacb6f69de642e63d5b73fc396c12be38b2bd5d884257c32c8f6d0854ae6b540f86dda2e" },
133 { "abcdefghijklm", "e11a66f7b9a2acda5663e9434377137d73ea560a32782230412642a463c8558123bfb7c0dbf17851e9aa58cc9587c3b4f5e3f7f38dcb6f890702e5bed4d5b54a" }, 133 { "abcdefghijklm", "e11a66f7b9a2acda5663e9434377137d73ea560a32782230412642a463c8558123bfb7c0dbf17851e9aa58cc9587c3b4f5e3f7f38dcb6f890702e5bed4d5b54a" },
134 { "abcdefghijklmn", "8334134081070bf7fcc8bf1c242d24bb3182a5119e5fb19d8bbf6b9d0cdb7fed5336e83415fce93094c0e55123cf69e14d7ae41b22289232699824e31125b6d9" }, 134 { "abcdefghijklmn", "8334134081070bf7fcc8bf1c242d24bb3182a5119e5fb19d8bbf6b9d0cdb7fed5336e83415fce93094c0e55123cf69e14d7ae41b22289232699824e31125b6d9" },
135 { "abcdefghijklmno", "db723f341a042d8de1aa813efd5e02fc1745ccbe259486257514804e2ec4bcebb2a46f1e4ad442154943f9e97e1bc47c3ae0eddab7de0c01a9c51f15342a5b19" }, 135 { "abcdefghijklmno", "db723f341a042d8de1aa813efd5e02fc1745ccbe259486257514804e2ec4bcebb2a46f1e4ad442154943f9e97e1bc47c3ae0eddab7de0c01a9c51f15342a5b19" },
136 { "abcdefghijklmnop", "d0cadd6834fa0c157b36cca30ee8b0b1435d841aa5b5ac850c11ae80a1440f51743e98fb1f1e7376c70f2f65404f088c28bcb4a511df2e64111f8f7424364b60" }, 136 { "abcdefghijklmnop", "d0cadd6834fa0c157b36cca30ee8b0b1435d841aa5b5ac850c11ae80a1440f51743e98fb1f1e7376c70f2f65404f088c28bcb4a511df2e64111f8f7424364b60" },
137 { "abcdefghijklmnopq", "6196942a8495b721f82bbc385c74c1f10eeadf35db8adc9cf1a05ddeed19351228279644cd5d686ee48a31631ebb64747a2b68b733dd6015e3d27750878fa875" }, 137 { "abcdefghijklmnopq", "6196942a8495b721f82bbc385c74c1f10eeadf35db8adc9cf1a05ddeed19351228279644cd5d686ee48a31631ebb64747a2b68b733dd6015e3d27750878fa875" },
138 { "abcdefghijklmnopqr", "fb3bd1fc157ea6f7a6728986a59b271b766fb723f6b7cf2b4194437435f2c497f33b6a56ae7eb3830fa9e04d5ebb4cb5e3f4d4bd812c498bdf0167e125de3fba" }, 138 { "abcdefghijklmnopqr", "fb3bd1fc157ea6f7a6728986a59b271b766fb723f6b7cf2b4194437435f2c497f33b6a56ae7eb3830fa9e04d5ebb4cb5e3f4d4bd812c498bdf0167e125de3fba" },
139 { "abcdefghijklmnopqrs", "836f9ecf2aa02f522a94f1370af45a9fd538ac3c70e3b709d614b2f8981881d6b0070fc6387b74ee371fc2549309f82926e78084b401deb61a106c399089bee8" }, 139 { "abcdefghijklmnopqrs", "836f9ecf2aa02f522a94f1370af45a9fd538ac3c70e3b709d614b2f8981881d6b0070fc6387b74ee371fc2549309f82926e78084b401deb61a106c399089bee8" },
140 { "abcdefghijklmnopqrst", "8cd9c137651425fb32d193d99b281735ec68eb5fd296f16459d1b33eac7badcfce0dca22eadaa5f209fa4ac3bbecd41342bac8b8a5dc3626e7f22cdc96e17cb4" }, 140 { "abcdefghijklmnopqrst", "8cd9c137651425fb32d193d99b281735ec68eb5fd296f16459d1b33eac7badcfce0dca22eadaa5f209fa4ac3bbecd41342bac8b8a5dc3626e7f22cdc96e17cb4" },
141 { "abcdefghijklmnopqrstu", "7079853a3e36241a8d83639f168ef38e883d7f72851a84ef3ed4d91c6a3896cf542b8b4518c2816fb19d4692a4b9aae65cb857e3642ce0a3936e20363bcbd4ca" }, 141 { "abcdefghijklmnopqrstu", "7079853a3e36241a8d83639f168ef38e883d7f72851a84ef3ed4d91c6a3896cf542b8b4518c2816fb19d4692a4b9aae65cb857e3642ce0a3936e20363bcbd4ca" },
142 { "abcdefghijklmnopqrstuv", "a4e8a90b7058fb078e6cdcfd0c6a33c366437eb9084eac657830356804c9f9b53f121496d8e972d8707a4cf02615e6f58ed1a770c28ac79ffd845401fe18a928" }, 142 { "abcdefghijklmnopqrstuv", "a4e8a90b7058fb078e6cdcfd0c6a33c366437eb9084eac657830356804c9f9b53f121496d8e972d8707a4cf02615e6f58ed1a770c28ac79ffd845401fe18a928" },
143 { "abcdefghijklmnopqrstuvw", "d91b1fd7c7785975493826719f333d090b214ff42351c84d8f8b2538509a28d2d59a36d0ac798d99d3908083b072a4be606ae391def5daa74156350fec71dd24" }, 143 { "abcdefghijklmnopqrstuvw", "d91b1fd7c7785975493826719f333d090b214ff42351c84d8f8b2538509a28d2d59a36d0ac798d99d3908083b072a4be606ae391def5daa74156350fec71dd24" },
144 { "abcdefghijklmnopqrstuvwq", "404eb5652173323320cac6bf8d9714aef0747693a8ab4570700c6262268d367f30e31c44fa66860568ff058fe39c9aa8dac76bc78566c691a884cb9052c4aa0a" }, 144 { "abcdefghijklmnopqrstuvwq", "404eb5652173323320cac6bf8d9714aef0747693a8ab4570700c6262268d367f30e31c44fa66860568ff058fe39c9aa8dac76bc78566c691a884cb9052c4aa0a" },
145}; 145};
146 146
147void 147static void
148digest2string(const uint8_t *digest, char *string, size_t len) 148digest2string(const uint8_t *digest, char *string, size_t len)
149{ 149{
150 while (len--) { 150 while (len--) {
151 if (*digest / 16 < 10) 151 if (*digest / 16 < 10)
152 *string++ = '0' + *digest / 16; 152 *string++ = '0' + *digest / 16;
153 else 153 else
154 *string++ = 'a' + *digest / 16 - 10; 154 *string++ = 'a' + *digest / 16 - 10;
155 if (*digest % 16 < 10) 155 if (*digest % 16 < 10)
156 *string++ = '0' + *digest % 16; 156 *string++ = '0' + *digest % 16;
157 else 157 else
158 *string++ = 'a' + *digest % 16 - 10; 158 *string++ = 'a' + *digest % 16 - 10;
159 ++digest; 159 ++digest;
160 } 160 }
161 *string = '\0'; 161 *string = '\0';
162} 162}
163 163
164ATF_TC_HEAD(t_sha256, tc) 164ATF_TC_HEAD(t_sha256, tc)
165{ 165{
166 atf_tc_set_md_var(tc, "descr", 166 atf_tc_set_md_var(tc, "descr",
167 "Test SHA256 functions for consistent results"); 167 "Test SHA256 functions for consistent results");
168} 168}
169 169
170ATF_TC_BODY(t_sha256, tc) 170ATF_TC_BODY(t_sha256, tc)
171{ 171{
172 size_t i, j, len; 172 size_t i, j, len;
173 SHA256_CTX ctx; 173 SHA256_CTX ctx;
174 char buf[256]; 174 unsigned char buf[256];
175 char digest[8 + SHA256_DIGEST_LENGTH]; 175 unsigned char digest[8 + SHA256_DIGEST_LENGTH];
176 char output[SHA256_DIGEST_STRING_LENGTH]; 176 char output[SHA256_DIGEST_STRING_LENGTH];
177 177
178 for (i = 0; i < sizeof(test256) / sizeof(test256[0]); ++i) { 178 for (i = 0; i < sizeof(test256) / sizeof(test256[0]); ++i) {
179 len = strlen(test256[i].vector); 179 len = strlen(test256[i].vector);
180 for (j = 0; j < 8; ++j) { 180 for (j = 0; j < 8; ++j) {
181 SHA256_Init(&ctx); 181 SHA256_Init(&ctx);
182 memcpy(buf + j, test256[i].vector, len); 182 memcpy(buf + j, test256[i].vector, len);
183 SHA256_Update(&ctx, buf + j, len); 183 SHA256_Update(&ctx, buf + j, len);
184 SHA256_Final(digest + j, &ctx); 184 SHA256_Final(digest + j, &ctx);
185 digest2string(digest + j, output, SHA256_DIGEST_LENGTH); 185 digest2string(digest + j, output, SHA256_DIGEST_LENGTH);
186 ATF_CHECK_STREQ(test256[i].hash, output); 186 ATF_CHECK_STREQ(test256[i].hash, output);
187 } 187 }
188 } 188 }
189} 189}
190 190
191ATF_TC_HEAD(t_sha384, tc) 191ATF_TC_HEAD(t_sha384, tc)
192{ 192{
193 atf_tc_set_md_var(tc, "descr", 193 atf_tc_set_md_var(tc, "descr",
194 "Test SHA384 functions for consistent results"); 194 "Test SHA384 functions for consistent results");
195} 195}
196 196
197ATF_TC_BODY(t_sha384, tc) 197ATF_TC_BODY(t_sha384, tc)
198{ 198{
199 size_t i, j, len; 199 size_t i, j, len;
200 SHA384_CTX ctx; 200 SHA384_CTX ctx;
201 char buf[384]; 201 unsigned char buf[384];
202 char digest[8 + SHA384_DIGEST_LENGTH]; 202 unsigned char digest[8 + SHA384_DIGEST_LENGTH];
203 char output[SHA384_DIGEST_STRING_LENGTH]; 203 char output[SHA384_DIGEST_STRING_LENGTH];
204 204
205 for (i = 0; i < sizeof(test384) / sizeof(test384[0]); ++i) { 205 for (i = 0; i < sizeof(test384) / sizeof(test384[0]); ++i) {
206 len = strlen(test384[i].vector); 206 len = strlen(test384[i].vector);
207 for (j = 0; j < 8; ++j) { 207 for (j = 0; j < 8; ++j) {
208 SHA384_Init(&ctx); 208 SHA384_Init(&ctx);
209 memcpy(buf + j, test384[i].vector, len); 209 memcpy(buf + j, test384[i].vector, len);
210 SHA384_Update(&ctx, buf + j, len); 210 SHA384_Update(&ctx, buf + j, len);
211 SHA384_Final(digest + j, &ctx); 211 SHA384_Final(digest + j, &ctx);
212 digest2string(digest + j, output, SHA384_DIGEST_LENGTH); 212 digest2string(digest + j, output, SHA384_DIGEST_LENGTH);
213 ATF_CHECK_STREQ(test384[i].hash, output); 213 ATF_CHECK_STREQ(test384[i].hash, output);
214 } 214 }
215 } 215 }
216} 216}
217 217
218ATF_TC_HEAD(t_sha512, tc) 218ATF_TC_HEAD(t_sha512, tc)
219{ 219{
220 atf_tc_set_md_var(tc, "descr", 220 atf_tc_set_md_var(tc, "descr",
221 "Test SHA512 functions for consistent results"); 221 "Test SHA512 functions for consistent results");
222} 222}
223 223
224ATF_TC_BODY(t_sha512, tc) 224ATF_TC_BODY(t_sha512, tc)
225{ 225{
226 size_t i, j, len; 226 size_t i, j, len;
227 SHA512_CTX ctx; 227 SHA512_CTX ctx;
228 char buf[512]; 228 unsigned char buf[512];
229 char digest[8 + SHA512_DIGEST_LENGTH]; 229 unsigned char digest[8 + SHA512_DIGEST_LENGTH];
230 char output[SHA512_DIGEST_STRING_LENGTH]; 230 char output[SHA512_DIGEST_STRING_LENGTH];
231 231
232 for (i = 0; i < sizeof(test512) / sizeof(test512[0]); ++i) { 232 for (i = 0; i < sizeof(test512) / sizeof(test512[0]); ++i) {
233 len = strlen(test512[i].vector); 233 len = strlen(test512[i].vector);
234 for (j = 0; j < 8; ++j) { 234 for (j = 0; j < 8; ++j) {
235 SHA512_Init(&ctx); 235 SHA512_Init(&ctx);
236 memcpy(buf + j, test512[i].vector, len); 236 memcpy(buf + j, test512[i].vector, len);
237 SHA512_Update(&ctx, buf + j, len); 237 SHA512_Update(&ctx, buf + j, len);
238 SHA512_Final(digest + j, &ctx); 238 SHA512_Final(digest + j, &ctx);
239 digest2string(digest + j, output, SHA512_DIGEST_LENGTH); 239 digest2string(digest + j, output, SHA512_DIGEST_LENGTH);
240 ATF_CHECK_STREQ(test512[i].hash, output); 240 ATF_CHECK_STREQ(test512[i].hash, output);
241 } 241 }
242 } 242 }
243} 243}

cvs diff -r1.1 -r1.2 src/tests/lib/libc/stdio/t_fmemopen.c (switch to unified diff)

--- src/tests/lib/libc/stdio/t_fmemopen.c 2010/09/24 09:21:53 1.1
+++ src/tests/lib/libc/stdio/t_fmemopen.c 2010/11/03 16:10:22 1.2
@@ -1,1170 +1,1172 @@ @@ -1,1170 +1,1172 @@
1/* $NetBSD: t_fmemopen.c,v 1.1 2010/09/24 09:21:53 tnozaki Exp $ */ 1/* $NetBSD: t_fmemopen.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2010 Takehiko NOZAKI, 4 * Copyright (c)2010 Takehiko NOZAKI,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 * 27 *
28 */ 28 */
29 29
30#if defined(__NetBSD__) 30#if defined(__NetBSD__)
31#include <atf-c.h> 31#include <atf-c.h>
32#else 32#else
33#if defined(__linux__) 33#if defined(__linux__)
34#define _GNU_SOURCE 34#define _GNU_SOURCE
35#include <features.h> 35#include <features.h>
36#endif 36#endif
37#include <assert.h> 37#include <assert.h>
38#include <stdio.h> 38#include <stdio.h>
39#define ATF_TC(arg0) static void arg0##_head(void) 39#define ATF_TC(arg0) static void arg0##_head(void)
40#define ATF_TC_HEAD(arg0, arg1) static void arg0##_head() 40#define ATF_TC_HEAD(arg0, arg1) static void arg0##_head()
41#define atf_tc_set_md_var(arg0, arg1, ...) do { \ 41#define atf_tc_set_md_var(arg0, arg1, ...) do { \
42 printf(__VA_ARGS__); \ 42 printf(__VA_ARGS__); \
43 puts(""); \ 43 puts(""); \
44} while (/*CONSTCOND*/0) 44} while (/*CONSTCOND*/0)
45#define ATF_TC_BODY(arg0, arg1) static void arg0##_body() 45#define ATF_TC_BODY(arg0, arg1) static void arg0##_body()
46#define ATF_CHECK(arg0) assert(arg0) 46#define ATF_CHECK(arg0) assert(arg0)
47#define ATF_TP_ADD_TCS(arg0) int main(void) 47#define ATF_TP_ADD_TCS(arg0) int main(void)
48#define ATF_TP_ADD_TC(arg0, arg1) arg1##_head(); arg1##_body() 48#define ATF_TP_ADD_TC(arg0, arg1) arg1##_head(); arg1##_body()
49#define atf_no_error() 0 49#define atf_no_error() 0
50#endif 50#endif
51 51
52#include <errno.h> 52#include <errno.h>
53#include <stdio.h> 53#include <stdio.h>
54#include <limits.h> 54#include <limits.h>
55#include <stdlib.h> 55#include <stdlib.h>
56#include <string.h> 56#include <string.h>
57 57
58const char *mode_rwa[] = { 58const char *mode_rwa[] = {
59 "r", "rb", "r+", "rb+", "r+b", 59 "r", "rb", "r+", "rb+", "r+b",
60 "w", "wb", "w+", "wb+", "w+b", 60 "w", "wb", "w+", "wb+", "w+b",
61 "a", "ab", "a+", "ab+", "a+b", 61 "a", "ab", "a+", "ab+", "a+b",
62 NULL 62 NULL
63}; 63};
64 64
65const char *mode_r[] = { "r", "rb", "r+", "rb+", "r+b", NULL }; 65const char *mode_r[] = { "r", "rb", "r+", "rb+", "r+b", NULL };
66const char *mode_w[] = { "w", "wb", "w+", "wb+", "w+b", NULL }; 66const char *mode_w[] = { "w", "wb", "w+", "wb+", "w+b", NULL };
67const char *mode_a[] = { "a", "ab", "a+", "ab+", "a+b", NULL };  67const char *mode_a[] = { "a", "ab", "a+", "ab+", "a+b", NULL };
68 68
69struct testcase { 69struct testcase {
70 const char *s; 70 const char *s;
71 size_t n; 71 off_t n;
72} testcases[] = { 72} testcases[] = {
73#define TESTSTR(s) { s, sizeof(s)-1 } 73#define TESTSTR(s) { s, sizeof(s)-1 }
74 TESTSTR("\0he quick brown fox jumps over the lazy dog"), 74 TESTSTR("\0he quick brown fox jumps over the lazy dog"),
75 TESTSTR("T\0e quick brown fox jumps over the lazy dog"), 75 TESTSTR("T\0e quick brown fox jumps over the lazy dog"),
76 TESTSTR("Th\0 quick brown fox jumps over the lazy dog"), 76 TESTSTR("Th\0 quick brown fox jumps over the lazy dog"),
77 TESTSTR("The\0quick brown fox jumps over the lazy dog"), 77 TESTSTR("The\0quick brown fox jumps over the lazy dog"),
78 TESTSTR("The \0uick brown fox jumps over the lazy dog"), 78 TESTSTR("The \0uick brown fox jumps over the lazy dog"),
79 TESTSTR("The q\0ick brown fox jumps over the lazy dog"), 79 TESTSTR("The q\0ick brown fox jumps over the lazy dog"),
80 TESTSTR("The qu\0ck brown fox jumps over the lazy dog"), 80 TESTSTR("The qu\0ck brown fox jumps over the lazy dog"),
81 TESTSTR("The qui\0k brown fox jumps over the lazy dog"), 81 TESTSTR("The qui\0k brown fox jumps over the lazy dog"),
82 TESTSTR("The quic\0 brown fox jumps over the lazy dog"), 82 TESTSTR("The quic\0 brown fox jumps over the lazy dog"),
83 TESTSTR("The quick\0brown fox jumps over the lazy dog"), 83 TESTSTR("The quick\0brown fox jumps over the lazy dog"),
84 TESTSTR("The quick \0rown fox jumps over the lazy dog"), 84 TESTSTR("The quick \0rown fox jumps over the lazy dog"),
85 TESTSTR("The quick b\0own fox jumps over the lazy dog"), 85 TESTSTR("The quick b\0own fox jumps over the lazy dog"),
86 TESTSTR("The quick br\0wn fox jumps over the lazy dog"), 86 TESTSTR("The quick br\0wn fox jumps over the lazy dog"),
87 TESTSTR("The quick bro\0n fox jumps over the lazy dog"), 87 TESTSTR("The quick bro\0n fox jumps over the lazy dog"),
88 TESTSTR("The quick brow\0 fox jumps over the lazy dog"), 88 TESTSTR("The quick brow\0 fox jumps over the lazy dog"),
89 TESTSTR("The quick brown\0fox jumps over the lazy dog"), 89 TESTSTR("The quick brown\0fox jumps over the lazy dog"),
90 TESTSTR("The quick brown \0ox jumps over the lazy dog"), 90 TESTSTR("The quick brown \0ox jumps over the lazy dog"),
91 TESTSTR("The quick brown f\0x jumps over the lazy dog"), 91 TESTSTR("The quick brown f\0x jumps over the lazy dog"),
92 TESTSTR("The quick brown fo\0 jumps over the lazy dog"), 92 TESTSTR("The quick brown fo\0 jumps over the lazy dog"),
93 TESTSTR("The quick brown fox\0jumps over the lazy dog"), 93 TESTSTR("The quick brown fox\0jumps over the lazy dog"),
94 TESTSTR("The quick brown fox \0umps over the lazy dog"), 94 TESTSTR("The quick brown fox \0umps over the lazy dog"),
95 TESTSTR("The quick brown fox j\0mps over the lazy dog"), 95 TESTSTR("The quick brown fox j\0mps over the lazy dog"),
96 TESTSTR("The quick brown fox ju\0ps over the lazy dog"), 96 TESTSTR("The quick brown fox ju\0ps over the lazy dog"),
97 TESTSTR("The quick brown fox jum\0s over the lazy dog"), 97 TESTSTR("The quick brown fox jum\0s over the lazy dog"),
98 TESTSTR("The quick brown fox jump\0 over the lazy dog"), 98 TESTSTR("The quick brown fox jump\0 over the lazy dog"),
99 TESTSTR("The quick brown fox jumps\0over the lazy dog"), 99 TESTSTR("The quick brown fox jumps\0over the lazy dog"),
100 TESTSTR("The quick brown fox jumps \0ver the lazy dog"), 100 TESTSTR("The quick brown fox jumps \0ver the lazy dog"),
101 TESTSTR("The quick brown fox jumps o\0er the lazy dog"), 101 TESTSTR("The quick brown fox jumps o\0er the lazy dog"),
102 TESTSTR("The quick brown fox jumps ov\0r the lazy dog"), 102 TESTSTR("The quick brown fox jumps ov\0r the lazy dog"),
103 TESTSTR("The quick brown fox jumps ove\0 the lazy dog"), 103 TESTSTR("The quick brown fox jumps ove\0 the lazy dog"),
104 TESTSTR("The quick brown fox jumps over\0the lazy dog"), 104 TESTSTR("The quick brown fox jumps over\0the lazy dog"),
105 TESTSTR("The quick brown fox jumps over \0he lazy dog"), 105 TESTSTR("The quick brown fox jumps over \0he lazy dog"),
106 TESTSTR("The quick brown fox jumps over t\0e lazy dog"), 106 TESTSTR("The quick brown fox jumps over t\0e lazy dog"),
107 TESTSTR("The quick brown fox jumps over th\0 lazy dog"), 107 TESTSTR("The quick brown fox jumps over th\0 lazy dog"),
108 TESTSTR("The quick brown fox jumps over the\0lazy dog"), 108 TESTSTR("The quick brown fox jumps over the\0lazy dog"),
109 TESTSTR("The quick brown fox jumps over the \0azy dog"), 109 TESTSTR("The quick brown fox jumps over the \0azy dog"),
110 TESTSTR("The quick brown fox jumps over the l\0zy dog"), 110 TESTSTR("The quick brown fox jumps over the l\0zy dog"),
111 TESTSTR("The quick brown fox jumps over the la\0y dog"), 111 TESTSTR("The quick brown fox jumps over the la\0y dog"),
112 TESTSTR("The quick brown fox jumps over the laz\0 dog"), 112 TESTSTR("The quick brown fox jumps over the laz\0 dog"),
113 TESTSTR("The quick brown fox jumps over the lazy\0dog"), 113 TESTSTR("The quick brown fox jumps over the lazy\0dog"),
114 TESTSTR("The quick brown fox jumps over the lazy \0og"), 114 TESTSTR("The quick brown fox jumps over the lazy \0og"),
115 TESTSTR("The quick brown fox jumps over the lazy d\0g"), 115 TESTSTR("The quick brown fox jumps over the lazy d\0g"),
116 TESTSTR("The quick brown fox jumps over the lazy do\0"), 116 TESTSTR("The quick brown fox jumps over the lazy do\0"),
117 TESTSTR("The quick brown fox jumps over the lazy dog"), 117 TESTSTR("The quick brown fox jumps over the lazy dog"),
118 { NULL, 0 }, 118 { NULL, 0 },
119}; 119};
120 120
121ATF_TC(test00); 121ATF_TC(test00);
122ATF_TC_HEAD(test00, tc) 122ATF_TC_HEAD(test00, tc)
123{ 123{
124 atf_tc_set_md_var(tc, "descr", "test00"); 124 atf_tc_set_md_var(tc, "descr", "test00");
125} 125}
126ATF_TC_BODY(test00, tc) 126ATF_TC_BODY(test00, tc)
127{ 127{
128 const char **p; 128 const char **p;
129 char buf[BUFSIZ]; 129 char buf[BUFSIZ];
130 FILE *fp; 130 FILE *fp;
131 131
132 for (p = &mode_rwa[0]; *p != NULL; ++p) { 132 for (p = &mode_rwa[0]; *p != NULL; ++p) {
133 fp = fmemopen(&buf[0], sizeof(buf), *p); 133 fp = fmemopen(&buf[0], sizeof(buf), *p);
134/* 134/*
135 * Upon successful completion, fmemopen() shall return a pointer to the 135 * Upon successful completion, fmemopen() shall return a pointer to the
136 * object controlling the stream. 136 * object controlling the stream.
137 */ 137 */
138 ATF_CHECK(fp != NULL); 138 ATF_CHECK(fp != NULL);
139 139
140 ATF_CHECK(fclose(fp) == 0); 140 ATF_CHECK(fclose(fp) == 0);
141 } 141 }
142} 142}
143 143
144ATF_TC(test01); 144ATF_TC(test01);
145ATF_TC_HEAD(test01, tc) 145ATF_TC_HEAD(test01, tc)
146{ 146{
147 atf_tc_set_md_var(tc, "descr", "test01"); 147 atf_tc_set_md_var(tc, "descr", "test01");
148} 148}
149ATF_TC_BODY(test01, tc) 149ATF_TC_BODY(test01, tc)
150{ 150{
151 const char **p; 151 const char **p;
152 const char *mode[] = { 152 const char *mode[] = {
153 "r+", "rb+", "r+b", 153 "r+", "rb+", "r+b",
154 "w+", "wb+", "w+b", 154 "w+", "wb+", "w+b",
155 "a+", "ab+", "a+b", 155 "a+", "ab+", "a+b",
156 NULL 156 NULL
157 }; 157 };
158 FILE *fp; 158 FILE *fp;
159 159
160 for (p = &mode[0]; *p != NULL; ++p) { 160 for (p = &mode[0]; *p != NULL; ++p) {
161/* 161/*
162 * If a null pointer is specified as the buf argument, fmemopen() shall 162 * If a null pointer is specified as the buf argument, fmemopen() shall
163 * allocate size bytes of memory as if by a call to malloc(). 163 * allocate size bytes of memory as if by a call to malloc().
164 */ 164 */
165 fp = fmemopen(NULL, BUFSIZ, *p); 165 fp = fmemopen(NULL, BUFSIZ, *p);
166 ATF_CHECK(fp != NULL); 166 ATF_CHECK(fp != NULL);
167 167
168/* 168/*
169 * If buf is a null pointer, the initial position shall always be set 169 * If buf is a null pointer, the initial position shall always be set
170 * to the beginning of the buffer. 170 * to the beginning of the buffer.
171 */ 171 */
172 ATF_CHECK(ftello(fp) == (off_t)0); 172 ATF_CHECK(ftello(fp) == (off_t)0);
173 173
174 ATF_CHECK(fclose(fp) == 0); 174 ATF_CHECK(fclose(fp) == 0);
175 } 175 }
176} 176}
177 177
178ATF_TC(test02); 178ATF_TC(test02);
179ATF_TC_HEAD(test02, tc) 179ATF_TC_HEAD(test02, tc)
180{ 180{
181 atf_tc_set_md_var(tc, "descr", "test02"); 181 atf_tc_set_md_var(tc, "descr", "test02");
182} 182}
183ATF_TC_BODY(test02, tc) 183ATF_TC_BODY(test02, tc)
184{ 184{
185 const char **p; 185 const char **p;
186 char buf[BUFSIZ]; 186 char buf[BUFSIZ];
187 FILE *fp; 187 FILE *fp;
188 188
189 for (p = &mode_r[0]; *p != NULL; ++p) { 189 for (p = &mode_r[0]; *p != NULL; ++p) {
190 190
191 memset(&buf[0], 0x1, sizeof(buf)); 191 memset(&buf[0], 0x1, sizeof(buf));
192 fp = fmemopen(&buf[0], sizeof(buf), *p); 192 fp = fmemopen(&buf[0], sizeof(buf), *p);
193 ATF_CHECK(fp != NULL); 193 ATF_CHECK(fp != NULL);
194 194
195/* 195/*
196 * This position is initially set to either the beginning of the buffer 196 * This position is initially set to either the beginning of the buffer
197 * (for r and w modes) 197 * (for r and w modes)
198 */ 198 */
199 ATF_CHECK((unsigned char)buf[0] == 0x1); 199 ATF_CHECK((unsigned char)buf[0] == 0x1);
200 ATF_CHECK(ftello(fp) == (off_t)0); 200 ATF_CHECK(ftello(fp) == (off_t)0);
201 201
202/* 202/*
203 * The stream also maintains the size of the current buffer contents. 203 * The stream also maintains the size of the current buffer contents.
204 * For modes r and r+ the size is set to the value given by the size argument. 204 * For modes r and r+ the size is set to the value given by the size argument.
205 */ 205 */
206#if !defined(__GLIBC__) 206#if !defined(__GLIBC__)
207 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); 207 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0);
208 ATF_CHECK(ftello(fp) == (off_t)sizeof(buf)); 208 ATF_CHECK(ftello(fp) == (off_t)sizeof(buf));
209#endif 209#endif
210 ATF_CHECK(fclose(fp) == 0); 210 ATF_CHECK(fclose(fp) == 0);
211 } 211 }
212} 212}
213 213
214ATF_TC(test03); 214ATF_TC(test03);
215ATF_TC_HEAD(test03, tc) 215ATF_TC_HEAD(test03, tc)
216{ 216{
217 atf_tc_set_md_var(tc, "descr", "test03"); 217 atf_tc_set_md_var(tc, "descr", "test03");
218} 218}
219ATF_TC_BODY(test03, tc) 219ATF_TC_BODY(test03, tc)
220{ 220{
221 const char **p; 221 const char **p;
222 char buf[BUFSIZ]; 222 char buf[BUFSIZ];
223 FILE *fp; 223 FILE *fp;
224  224
225 for (p = &mode_w[0]; *p != NULL; ++p) { 225 for (p = &mode_w[0]; *p != NULL; ++p) {
226 226
227 memset(&buf[0], 0x1, sizeof(buf)); 227 memset(&buf[0], 0x1, sizeof(buf));
228 fp = fmemopen(&buf[0], sizeof(buf), *p); 228 fp = fmemopen(&buf[0], sizeof(buf), *p);
229 ATF_CHECK(fp != NULL); 229 ATF_CHECK(fp != NULL);
230 230
231/* 231/*
232 * This position is initially set to either the beginning of the buffer 232 * This position is initially set to either the beginning of the buffer
233 * (for r and w modes) 233 * (for r and w modes)
234 */ 234 */
235 ATF_CHECK(buf[0] == '\0'); 235 ATF_CHECK(buf[0] == '\0');
236 ATF_CHECK(ftello(fp) == (off_t)0); 236 ATF_CHECK(ftello(fp) == (off_t)0);
237 237
238/* 238/*
239 * For modes w and w+ the initial size is zero 239 * For modes w and w+ the initial size is zero
240 */ 240 */
241 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); 241 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0);
242 ATF_CHECK(ftello(fp) == (off_t)0); 242 ATF_CHECK(ftello(fp) == (off_t)0);
243 243
244 ATF_CHECK(fclose(fp) == 0); 244 ATF_CHECK(fclose(fp) == 0);
245 } 245 }
246} 246}
247 247
248ATF_TC(test04); 248ATF_TC(test04);
249ATF_TC_HEAD(test04, tc) 249ATF_TC_HEAD(test04, tc)
250{ 250{
251 atf_tc_set_md_var(tc, "descr", "test04"); 251 atf_tc_set_md_var(tc, "descr", "test04");
252} 252}
253ATF_TC_BODY(test04, tc) 253ATF_TC_BODY(test04, tc)
254{ 254{
255 const char **p; 255 const char **p;
256 char buf[BUFSIZ]; 256 char buf[BUFSIZ];
257 FILE *fp; 257 FILE *fp;
258 258
259/* 259/*
260 * or to the first null byte in the buffer (for a modes) 260 * or to the first null byte in the buffer (for a modes)
261 */ 261 */
262 for (p = &mode_a[0]; *p != NULL; ++p) { 262 for (p = &mode_a[0]; *p != NULL; ++p) {
263 263
264 memset(&buf[0], 0x1, sizeof(buf)); 264 memset(&buf[0], 0x1, sizeof(buf));
265 fp = fmemopen(&buf[0], sizeof(buf), *p); 265 fp = fmemopen(&buf[0], sizeof(buf), *p);
266 ATF_CHECK(fp != NULL); 266 ATF_CHECK(fp != NULL);
267 267
268 ATF_CHECK((unsigned char)buf[0] == 0x1); 268 ATF_CHECK((unsigned char)buf[0] == 0x1);
269 269
270/* If no null byte is found in append mode, 270/* If no null byte is found in append mode,
271 * the initial position is set to one byte after the end of the buffer. 271 * the initial position is set to one byte after the end of the buffer.
272 */ 272 */
273#if !defined(__GLIBC__) 273#if !defined(__GLIBC__)
274 ATF_CHECK(ftello(fp) == (off_t)sizeof(buf)); 274 ATF_CHECK(ftello(fp) == (off_t)sizeof(buf));
275#endif 275#endif
276 276
277/* 277/*
278 * and for modes a and a+ the initial size is either the position of the 278 * and for modes a and a+ the initial size is either the position of the
279 * first null byte in the buffer or the value of the size argument 279 * first null byte in the buffer or the value of the size argument
280 * if no null byte is found. 280 * if no null byte is found.
281 */ 281 */
282#if !defined(__GLIBC__) 282#if !defined(__GLIBC__)
283 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); 283 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0);
284 ATF_CHECK(ftello(fp) == (off_t)sizeof(buf)); 284 ATF_CHECK(ftello(fp) == (off_t)sizeof(buf));
285#endif 285#endif
286 286
287 ATF_CHECK(fclose(fp) == 0); 287 ATF_CHECK(fclose(fp) == 0);
288 } 288 }
289} 289}
290 290
291ATF_TC(test05); 291ATF_TC(test05);
292ATF_TC_HEAD(test05, tc) 292ATF_TC_HEAD(test05, tc)
293{ 293{
294 atf_tc_set_md_var(tc, "descr", "test05"); 294 atf_tc_set_md_var(tc, "descr", "test05");
295} 295}
296ATF_TC_BODY(test05, tc) 296ATF_TC_BODY(test05, tc)
297{ 297{
298 const char **p; 298 const char **p;
299 FILE *fp; 299 FILE *fp;
300 char buf[BUFSIZ]; 300 char buf[BUFSIZ];
301 301
302 for (p = &mode_rwa[0]; *p != NULL; ++p) { 302 for (p = &mode_rwa[0]; *p != NULL; ++p) {
303/* 303/*
304 * Otherwise, a null pointer shall be returned, and errno shall be set 304 * Otherwise, a null pointer shall be returned, and errno shall be set
305 * to indicate the error. 305 * to indicate the error.
306 */ 306 */
307 errno = 0; 307 errno = 0;
308 fp = fmemopen(NULL, (size_t)0, *p); 308 fp = fmemopen(NULL, (size_t)0, *p);
309 ATF_CHECK(fp == NULL); 309 ATF_CHECK(fp == NULL);
310 ATF_CHECK(errno == EINVAL); 310 ATF_CHECK(errno == EINVAL);
311 311
312 errno = 0; 312 errno = 0;
313 fp = fmemopen((void *)&buf[0], 0, *p); 313 fp = fmemopen((void *)&buf[0], 0, *p);
314 ATF_CHECK(fp == NULL); 314 ATF_CHECK(fp == NULL);
315 ATF_CHECK(errno == EINVAL); 315 ATF_CHECK(errno == EINVAL);
316 } 316 }
317} 317}
318 318
319ATF_TC(test06); 319ATF_TC(test06);
320ATF_TC_HEAD(test06, tc) 320ATF_TC_HEAD(test06, tc)
321{ 321{
322 atf_tc_set_md_var(tc, "descr", "test06"); 322 atf_tc_set_md_var(tc, "descr", "test06");
323} 323}
324ATF_TC_BODY(test06, tc) 324ATF_TC_BODY(test06, tc)
325{ 325{
326 const char **p; 326 const char **p;
327 const char *mode[] = { "", " ", "???", NULL }; 327 const char *mode[] = { "", " ", "???", NULL };
328 FILE *fp; 328 FILE *fp;
329 329
330 for (p = &mode[0]; *p != NULL; ++p) { 330 for (p = &mode[0]; *p != NULL; ++p) {
331/* 331/*
332 * The value of the mode argument is not valid. 332 * The value of the mode argument is not valid.
333 */ 333 */
334 fp = fmemopen(NULL, 1, *p); 334 fp = fmemopen(NULL, 1, *p);
335 ATF_CHECK(fp == NULL); 335 ATF_CHECK(fp == NULL);
336 ATF_CHECK(errno == EINVAL); 336 ATF_CHECK(errno == EINVAL);
337 } 337 }
338} 338}
339 339
340ATF_TC(test07); 340ATF_TC(test07);
341ATF_TC_HEAD(test07, tc) 341ATF_TC_HEAD(test07, tc)
342{ 342{
343 atf_tc_set_md_var(tc, "descr", "test07"); 343 atf_tc_set_md_var(tc, "descr", "test07");
344} 344}
345ATF_TC_BODY(test07, tc) 345ATF_TC_BODY(test07, tc)
346{ 346{
347#if !defined(__GLIBC__) 347#if !defined(__GLIBC__)
348 const char **p; 348 const char **p;
349 const char *mode[] = { 349 const char *mode[] = {
350 "r", "rb", 350 "r", "rb",
351 "w", "wb", 351 "w", "wb",
352 "a", "ab", 352 "a", "ab",
353 NULL 353 NULL
354 }; 354 };
355 FILE *fp; 355 FILE *fp;
356 356
357 for (p = &mode[0]; *p != NULL; ++p) { 357 for (p = &mode[0]; *p != NULL; ++p) {
358/* 358/*
359 * Because this feature is only useful when the stream is opened for updating 359 * Because this feature is only useful when the stream is opened for updating
360 * (because there is no way to get a pointer to the buffer) the fmemopen() 360 * (because there is no way to get a pointer to the buffer) the fmemopen()
361 * call may fail if the mode argument does not include a '+' .  361 * call may fail if the mode argument does not include a '+' .
362 */ 362 */
363 errno = 0; 363 errno = 0;
364 fp = fmemopen(NULL, 1, *p); 364 fp = fmemopen(NULL, 1, *p);
365 ATF_CHECK(fp == NULL); 365 ATF_CHECK(fp == NULL);
366 ATF_CHECK(errno == EINVAL); 366 ATF_CHECK(errno == EINVAL);
367 } 367 }
368#endif 368#endif
369} 369}
370 370
371ATF_TC(test08); 371ATF_TC(test08);
372ATF_TC_HEAD(test08, tc) 372ATF_TC_HEAD(test08, tc)
373{ 373{
374 atf_tc_set_md_var(tc, "descr", "test08"); 374 atf_tc_set_md_var(tc, "descr", "test08");
375} 375}
376ATF_TC_BODY(test08, tc) 376ATF_TC_BODY(test08, tc)
377{ 377{
378#if !defined(__GLIBC__) 378#if !defined(__GLIBC__)
379 const char **p; 379 const char **p;
380 const char *mode[] = { 380 const char *mode[] = {
381 "r+", "rb+", "r+b", 381 "r+", "rb+", "r+b",
382 "w+", "wb+", "w+b", 382 "w+", "wb+", "w+b",
383 "a+", "ab+", "a+b", 383 "a+", "ab+", "a+b",
384 NULL 384 NULL
385 }; 385 };
386 FILE *fp; 386 FILE *fp;
387 387
388 for (p = &mode[0]; *p != NULL; ++p) { 388 for (p = &mode[0]; *p != NULL; ++p) {
389/* 389/*
390 * The buf argument is a null pointer and the allocation of a buffer of 390 * The buf argument is a null pointer and the allocation of a buffer of
391 * length size has failed. 391 * length size has failed.
392 */ 392 */
393 fp = fmemopen(NULL, SIZE_MAX, *p); 393 fp = fmemopen(NULL, SIZE_MAX, *p);
394 ATF_CHECK(fp == NULL); 394 ATF_CHECK(fp == NULL);
395 ATF_CHECK(errno == ENOMEM); 395 ATF_CHECK(errno == ENOMEM);
396 } 396 }
397#endif 397#endif
398} 398}
399 399
400/* 400/*
401 * test09 - test14: 401 * test09 - test14:
402 * An attempt to seek a memory buffer stream to a negative position or to a 402 * An attempt to seek a memory buffer stream to a negative position or to a
403 * position larger than the buffer size given in the size argument shall fail. 403 * position larger than the buffer size given in the size argument shall fail.
404 */ 404 */
405 405
406ATF_TC(test09); 406ATF_TC(test09);
407ATF_TC_HEAD(test09, tc) 407ATF_TC_HEAD(test09, tc)
408{ 408{
409 atf_tc_set_md_var(tc, "descr", "test09"); 409 atf_tc_set_md_var(tc, "descr", "test09");
410} 410}
411ATF_TC_BODY(test09, tc) 411ATF_TC_BODY(test09, tc)
412{ 412{
413 struct testcase *t; 413 struct testcase *t;
414 const char **p; 414 const char **p;
415 char buf[BUFSIZ]; 415 char buf[BUFSIZ];
416 FILE *fp; 416 FILE *fp;
417 off_t i; 417 off_t i;
418 418
419 for (t = &testcases[0]; t->s != NULL; ++t) { 419 for (t = &testcases[0]; t->s != NULL; ++t) {
420 for (p = &mode_rwa[0]; *p != NULL; ++p) { 420 for (p = &mode_rwa[0]; *p != NULL; ++p) {
421 421
422 memcpy(&buf[0], t->s, t->n); 422 memcpy(&buf[0], t->s, t->n);
423 fp = fmemopen(&buf[0], t->n, *p); 423 fp = fmemopen(&buf[0], t->n, *p);
424 ATF_CHECK(fp != NULL); 424 ATF_CHECK(fp != NULL);
425 425
426/* 426/*
427 * test fmemopen_seek(SEEK_SET) 427 * test fmemopen_seek(SEEK_SET)
428 */ 428 */
429 /* zero */ 429 /* zero */
430 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_SET) == 0); 430 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_SET) == 0);
431 ATF_CHECK(ftello(fp) == (off_t)0); 431 ATF_CHECK(ftello(fp) == (off_t)0);
432 432
433 /* positive */ 433 /* positive */
434 for (i = (off_t)1; i <= (off_t)t->n; ++i) { 434 for (i = (off_t)1; i <= (off_t)t->n; ++i) {
435 ATF_CHECK(fseeko(fp, i, SEEK_SET) == 0); 435 ATF_CHECK(fseeko(fp, i, SEEK_SET) == 0);
436 ATF_CHECK(ftello(fp) == i); 436 ATF_CHECK(ftello(fp) == i);
437 } 437 }
438 /* positive + OOB */ 438 /* positive + OOB */
439 ATF_CHECK(fseeko(fp, t->n + 1, SEEK_SET) == -1); 439 ATF_CHECK(fseeko(fp, t->n + 1, SEEK_SET) == -1);
440 ATF_CHECK(ftello(fp) == t->n); 440 ATF_CHECK(ftello(fp) == t->n);
441 441
442 /* negative + OOB */ 442 /* negative + OOB */
443 ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_SET) == -1); 443 ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_SET) == -1);
444 ATF_CHECK(ftello(fp) == t->n); 444 ATF_CHECK(ftello(fp) == t->n);
445 445
446 ATF_CHECK(fclose(fp) == 0); 446 ATF_CHECK(fclose(fp) == 0);
447 } 447 }
448 } 448 }
449} 449}
450 450
451const char *mode_rw[] = { 451const char *mode_rw[] = {
452 "r", "rb", "r+", "rb+", "r+b", 452 "r", "rb", "r+", "rb+", "r+b",
453 "w", "wb", "w+", "wb+", "w+b", 453 "w", "wb", "w+", "wb+", "w+b",
454 NULL 454 NULL
455}; 455};
456 456
457ATF_TC(test10); 457ATF_TC(test10);
458ATF_TC_HEAD(test10, tc) 458ATF_TC_HEAD(test10, tc)
459{ 459{
460 atf_tc_set_md_var(tc, "descr", "test10"); 460 atf_tc_set_md_var(tc, "descr", "test10");
461} 461}
462ATF_TC_BODY(test10, tc) 462ATF_TC_BODY(test10, tc)
463{ 463{
464 struct testcase *t; 464 struct testcase *t;
465 off_t len, i; 465 off_t len, i;
466 const char **p; 466 const char **p;
467 char buf[BUFSIZ]; 467 char buf[BUFSIZ];
468 FILE *fp; 468 FILE *fp;
469 469
470 for (t = &testcases[0]; t->s != NULL; ++t) { 470 for (t = &testcases[0]; t->s != NULL; ++t) {
471 len = (off_t)strnlen(t->s, t->n); 471 len = (off_t)strnlen(t->s, t->n);
472 for (p = &mode_rw[0]; *p != NULL; ++p) { 472 for (p = &mode_rw[0]; *p != NULL; ++p) {
473 473
474 memcpy(&buf[0], t->s, t->n); 474 memcpy(&buf[0], t->s, t->n);
475 fp = fmemopen(&buf[0], t->n, *p); 475 fp = fmemopen(&buf[0], t->n, *p);
476 ATF_CHECK(fp != NULL); 476 ATF_CHECK(fp != NULL);
477 477
478/* 478/*
479 * test fmemopen_seek(SEEK_CUR) 479 * test fmemopen_seek(SEEK_CUR)
480 */ 480 */
481 ATF_CHECK(ftello(fp) == (off_t)0); 481 ATF_CHECK(ftello(fp) == (off_t)0);
482 482
483 /* zero */ 483 /* zero */
484 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_CUR) == 0); 484 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_CUR) == 0);
485 ATF_CHECK(ftello(fp) == (off_t)0); 485 ATF_CHECK(ftello(fp) == (off_t)0);
486 486
487 /* negative & OOB */ 487 /* negative & OOB */
488 ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_CUR) == -1); 488 ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_CUR) == -1);
489 ATF_CHECK(ftello(fp) == (off_t)0); 489 ATF_CHECK(ftello(fp) == (off_t)0);
490 490
491 /* positive */ 491 /* positive */
492 for (i = 0; i < (off_t)t->n; ++i) { 492 for (i = 0; i < (off_t)t->n; ++i) {
493 ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == 0); 493 ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == 0);
494 ATF_CHECK(ftello(fp) == i + 1); 494 ATF_CHECK(ftello(fp) == i + 1);
495 } 495 }
496 496
497 /* positive & OOB */ 497 /* positive & OOB */
498 ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == -1); 498 ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == -1);
499 ATF_CHECK(ftello(fp) == (off_t)t->n); 499 ATF_CHECK(ftello(fp) == (off_t)t->n);
500 500
501 ATF_CHECK(fclose(fp) == 0); 501 ATF_CHECK(fclose(fp) == 0);
502 } 502 }
503 } 503 }
504} 504}
505 505
506ATF_TC(test11); 506ATF_TC(test11);
507ATF_TC_HEAD(test11, tc) 507ATF_TC_HEAD(test11, tc)
508{ 508{
509 atf_tc_set_md_var(tc, "descr", "test11"); 509 atf_tc_set_md_var(tc, "descr", "test11");
510} 510}
511ATF_TC_BODY(test11, tc) 511ATF_TC_BODY(test11, tc)
512{ 512{
513 struct testcase *t; 513 struct testcase *t;
514 off_t len, rest, i; 514 off_t len, rest, i;
515 const char **p; 515 const char **p;
516 char buf[BUFSIZ]; 516 char buf[BUFSIZ];
517 FILE *fp; 517 FILE *fp;
518 518
519 /* test fmemopen_seek(SEEK_CUR) */ 519 /* test fmemopen_seek(SEEK_CUR) */
520 for (t = &testcases[0]; t->s != NULL; ++t) { 520 for (t = &testcases[0]; t->s != NULL; ++t) {
521 len = (off_t)strnlen(t->s, t->n); 521 len = (off_t)strnlen(t->s, t->n);
522 rest = (off_t)t->n - len; 522 rest = (off_t)t->n - len;
523 for (p = &mode_a[0]; *p != NULL; ++p) { 523 for (p = &mode_a[0]; *p != NULL; ++p) {
524 524
525 memcpy(&buf[0], t->s, t->n); 525 memcpy(&buf[0], t->s, t->n);
526 fp = fmemopen(&buf[0], t->n, *p); 526 fp = fmemopen(&buf[0], t->n, *p);
527 ATF_CHECK(fp != NULL); 527 ATF_CHECK(fp != NULL);
528/* 528/*
529 * test fmemopen_seek(SEEK_CUR) 529 * test fmemopen_seek(SEEK_CUR)
530 */ 530 */
531#if defined(__GLIBC__) 531#if defined(__GLIBC__)
532 if (i < (off_t)t->n) { 532 if (i < (off_t)t->n) {
533#endif 533#endif
534 /* zero */ 534 /* zero */
535 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_CUR) == 0); 535 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_CUR) == 0);
536 ATF_CHECK(ftello(fp) == len); 536 ATF_CHECK(ftello(fp) == len);
537 537
538 /* posive */ 538 /* posive */
539 for (i = (off_t)1; i <= rest; ++i) { 539 for (i = (off_t)1; i <= rest; ++i) {
540 ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == 0); 540 ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == 0);
541 ATF_CHECK(ftello(fp) == len + i); 541 ATF_CHECK(ftello(fp) == len + i);
542 } 542 }
543 543
544 /* positive + OOB */ 544 /* positive + OOB */
545 ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == -1); 545 ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == -1);
546 ATF_CHECK(ftello(fp) == (off_t)t->n); 546 ATF_CHECK(ftello(fp) == (off_t)t->n);
547 547
548 /* negative */ 548 /* negative */
549 for (i = (off_t)1; i <= (off_t)t->n; ++i) { 549 for (i = (off_t)1; i <= (off_t)t->n; ++i) {
550 ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_CUR) == 0); 550 ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_CUR) == 0);
551 ATF_CHECK(ftello(fp) == (off_t)t->n - i); 551 ATF_CHECK(ftello(fp) == (off_t)t->n - i);
552 } 552 }
553 553
554 /* negative + OOB */ 554 /* negative + OOB */
555 ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_CUR) == -1); 555 ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_CUR) == -1);
556 ATF_CHECK(ftello(fp) == (off_t)0); 556 ATF_CHECK(ftello(fp) == (off_t)0);
557 557
558#if defined(__GLIBC__) 558#if defined(__GLIBC__)
559 } 559 }
560#endif 560#endif
561 ATF_CHECK(fclose(fp) == 0); 561 ATF_CHECK(fclose(fp) == 0);
562 } 562 }
563 } 563 }
564} 564}
565 565
566ATF_TC(test12); 566ATF_TC(test12);
567ATF_TC_HEAD(test12, tc) 567ATF_TC_HEAD(test12, tc)
568{ 568{
569 atf_tc_set_md_var(tc, "descr", "test12"); 569 atf_tc_set_md_var(tc, "descr", "test12");
570} 570}
571ATF_TC_BODY(test12, tc) 571ATF_TC_BODY(test12, tc)
572{ 572{
573 struct testcase *t; 573 struct testcase *t;
574 off_t len, rest, i; 574 off_t len, rest, i;
575 const char **p; 575 const char **p;
576 char buf[BUFSIZ]; 576 char buf[BUFSIZ];
577 FILE *fp; 577 FILE *fp;
578 578
579 /* test fmemopen_seek(SEEK_END) */ 579 /* test fmemopen_seek(SEEK_END) */
580 for (t = &testcases[0]; t->s != NULL; ++t) { 580 for (t = &testcases[0]; t->s != NULL; ++t) {
581 len = (off_t)strnlen(t->s, t->n); 581 len = (off_t)strnlen(t->s, t->n);
582 rest = t->n - len; 582 rest = t->n - len;
583 for (p = &mode_r[0]; *p != NULL; ++p) { 583 for (p = &mode_r[0]; *p != NULL; ++p) {
584 584
585 memcpy(buf, t->s, t->n); 585 memcpy(buf, t->s, t->n);
586 fp = fmemopen(&buf[0], t->n, *p); 586 fp = fmemopen(&buf[0], t->n, *p);
587 ATF_CHECK(fp != NULL); 587 ATF_CHECK(fp != NULL);
588 588
589/* 589/*
590 * test fmemopen_seek(SEEK_END) 590 * test fmemopen_seek(SEEK_END)
591 */ 591 */
592#if !defined(__GLIBC__) 592#if !defined(__GLIBC__)
593 ATF_CHECK(ftello(fp) == (off_t)0); 593 ATF_CHECK(ftello(fp) == (off_t)0);
594 594
595 /* zero */ 595 /* zero */
596 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); 596 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0);
597 ATF_CHECK(ftello(fp) == len); 597 ATF_CHECK(ftello(fp) == len);
598 598
599 /* positive + OOB */ 599 /* positive + OOB */
600 ATF_CHECK(fseeko(fp, rest + 1, SEEK_END) == -1); 600 ATF_CHECK(fseeko(fp, rest + 1, SEEK_END) == -1);
601 ATF_CHECK(ftello(fp) == len); 601 ATF_CHECK(ftello(fp) == len);
602 602
603 /* negative + OOB */ 603 /* negative + OOB */
604 ATF_CHECK(fseeko(fp, -(len + 1), SEEK_END) == -1); 604 ATF_CHECK(fseeko(fp, -(len + 1), SEEK_END) == -1);
605 ATF_CHECK(ftello(fp) == len); 605 ATF_CHECK(ftello(fp) == len);
606 606
607 /* positive */ 607 /* positive */
608 for (i = 1; i <= rest; ++i) { 608 for (i = 1; i <= rest; ++i) {
609 ATF_CHECK(fseeko(fp, i, SEEK_END) == 0); 609 ATF_CHECK(fseeko(fp, i, SEEK_END) == 0);
610 ATF_CHECK(ftello(fp) == len + i); 610 ATF_CHECK(ftello(fp) == len + i);
611 } 611 }
612 612
613 /* negative */ 613 /* negative */
614 for (i = 1; i < len; ++i) { 614 for (i = 1; i < len; ++i) {
615 ATF_CHECK(fseeko(fp, -i, SEEK_END) == 0); 615 ATF_CHECK(fseeko(fp, -i, SEEK_END) == 0);
616 ATF_CHECK(ftello(fp) == len - i); 616 ATF_CHECK(ftello(fp) == len - i);
617 } 617 }
618#endif 618#endif
619 ATF_CHECK(fclose(fp) == 0); 619 ATF_CHECK(fclose(fp) == 0);
620 } 620 }
621 } 621 }
622} 622}
623 623
624ATF_TC(test13); 624ATF_TC(test13);
625ATF_TC_HEAD(test13, tc) 625ATF_TC_HEAD(test13, tc)
626{ 626{
627 atf_tc_set_md_var(tc, "descr", "test13"); 627 atf_tc_set_md_var(tc, "descr", "test13");
628} 628}
629ATF_TC_BODY(test13, tc) 629ATF_TC_BODY(test13, tc)
630{ 630{
631 struct testcase *t; 631 struct testcase *t;
632 off_t len, rest, i; 632 off_t len, rest, i;
633 const char **p; 633 const char **p;
634 char buf[BUFSIZ]; 634 char buf[BUFSIZ];
635 FILE *fp; 635 FILE *fp;
636 636
637 /* test fmemopen_seek(SEEK_END) */ 637 /* test fmemopen_seek(SEEK_END) */
638 for (t = &testcases[0]; t->s != NULL; ++t) { 638 for (t = &testcases[0]; t->s != NULL; ++t) {
639 len = (off_t)strnlen(t->s, t->n); 639 len = (off_t)strnlen(t->s, t->n);
640 rest = t->n - len; 640 rest = t->n - len;
641 for (p = &mode_w[0]; *p != NULL; ++p) { 641 for (p = &mode_w[0]; *p != NULL; ++p) {
642 642
643 memcpy(buf, t->s, t->n); 643 memcpy(buf, t->s, t->n);
644 fp = fmemopen(&buf[0], t->n, *p); 644 fp = fmemopen(&buf[0], t->n, *p);
645 ATF_CHECK(fp != NULL); 645 ATF_CHECK(fp != NULL);
646/* 646/*
647 * test fmemopen_seek(SEEK_END) 647 * test fmemopen_seek(SEEK_END)
648 */ 648 */
649#if !defined(__GLIBC__) 649#if !defined(__GLIBC__)
650 ATF_CHECK(ftello(fp) == (off_t)0); 650 ATF_CHECK(ftello(fp) == (off_t)0);
651 ATF_CHECK(buf[0] == '\0'); 651 ATF_CHECK(buf[0] == '\0');
652 652
653 /* zero */ 653 /* zero */
654 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); 654 ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0);
655 ATF_CHECK(ftello(fp) == (off_t)0); 655 ATF_CHECK(ftello(fp) == (off_t)0);
656 656
657 /* positive + OOB */ 657 /* positive + OOB */
658 ATF_CHECK(fseeko(fp, (off_t)t->n + 1, SEEK_END) == -1); 658 ATF_CHECK(fseeko(fp, (off_t)t->n + 1, SEEK_END) == -1);
659 ATF_CHECK(ftello(fp) == (off_t)0); 659 ATF_CHECK(ftello(fp) == (off_t)0);
660 660
661 /* negative + OOB */ 661 /* negative + OOB */
662 ATF_CHECK(fseeko(fp, -1, SEEK_END) == -1); 662 ATF_CHECK(fseeko(fp, -1, SEEK_END) == -1);
663 ATF_CHECK(ftello(fp) == (off_t)0); 663 ATF_CHECK(ftello(fp) == (off_t)0);
664 664
665 /* positive */ 665 /* positive */
666 for (i = 1; i <= t->n; ++i) { 666 for (i = 1; i <= t->n; ++i) {
667 ATF_CHECK(fseeko(fp, i, SEEK_END) == 0); 667 ATF_CHECK(fseeko(fp, i, SEEK_END) == 0);
668 ATF_CHECK(ftello(fp) == i); 668 ATF_CHECK(ftello(fp) == i);
669 } 669 }
670#endif 670#endif
671 ATF_CHECK(fclose(fp) == 0); 671 ATF_CHECK(fclose(fp) == 0);
672 } 672 }
673 } 673 }
674} 674}
675 675
676ATF_TC(test14); 676ATF_TC(test14);
677ATF_TC_HEAD(test14, tc) 677ATF_TC_HEAD(test14, tc)
678{ 678{
679 atf_tc_set_md_var(tc, "descr", "test14"); 679 atf_tc_set_md_var(tc, "descr", "test14");
680} 680}
681ATF_TC_BODY(test14, tc) 681ATF_TC_BODY(test14, tc)
682{ 682{
683 struct testcase *t; 683 struct testcase *t;
684 off_t len, rest, i; 684 off_t len, rest, i;
685 const char **p; 685 const char **p;
686 char buf[BUFSIZ]; 686 char buf[BUFSIZ];
687 FILE *fp; 687 FILE *fp;
688 688
689 /* test fmemopen_seek(SEEK_END) */ 689 /* test fmemopen_seek(SEEK_END) */
690 for (t = &testcases[0]; t->s != NULL; ++t) { 690 for (t = &testcases[0]; t->s != NULL; ++t) {
691 len = (off_t)strnlen(t->s, t->n); 691 len = (off_t)strnlen(t->s, t->n);
692 rest = (off_t)t->n - len; 692 rest = (off_t)t->n - len;
693 for (p = &mode_a[0]; *p != NULL; ++p) { 693 for (p = &mode_a[0]; *p != NULL; ++p) {
694 694
695 memcpy(buf, t->s, t->n); 695 memcpy(buf, t->s, t->n);
696 fp = fmemopen(&buf[0], t->n, *p); 696 fp = fmemopen(&buf[0], t->n, *p);
697 ATF_CHECK(fp != NULL); 697 ATF_CHECK(fp != NULL);
698/* 698/*
699 * test fmemopen_seek(SEEK_END) 699 * test fmemopen_seek(SEEK_END)
700 */ 700 */
701#if !defined(__GLIBC__) 701#if !defined(__GLIBC__)
702 ATF_CHECK(ftello(fp) == len); 702 ATF_CHECK(ftello(fp) == len);
703 703
704 /* zero */ 704 /* zero */
705 ATF_CHECK(fseeko(fp, 0, SEEK_END) == 0); 705 ATF_CHECK(fseeko(fp, 0, SEEK_END) == 0);
706 ATF_CHECK(ftello(fp) == len); 706 ATF_CHECK(ftello(fp) == len);
707 707
708 /* positive + OOB */ 708 /* positive + OOB */
709 ATF_CHECK(fseeko(fp, rest + 1, SEEK_END) == -1); 709 ATF_CHECK(fseeko(fp, rest + 1, SEEK_END) == -1);
710 ATF_CHECK(ftello(fp) == len); 710 ATF_CHECK(ftello(fp) == len);
711 711
712 /* negative + OOB */ 712 /* negative + OOB */
713 ATF_CHECK(fseeko(fp, -(len + 1), SEEK_END) == -1); 713 ATF_CHECK(fseeko(fp, -(len + 1), SEEK_END) == -1);
714 ATF_CHECK(ftello(fp) == len); 714 ATF_CHECK(ftello(fp) == len);
715 715
716 /* positive */ 716 /* positive */
717 for (i = 1; i <= rest; ++i) { 717 for (i = 1; i <= rest; ++i) {
718 ATF_CHECK(fseeko(fp, i, SEEK_END) == 0); 718 ATF_CHECK(fseeko(fp, i, SEEK_END) == 0);
719 ATF_CHECK(ftello(fp) == len + i); 719 ATF_CHECK(ftello(fp) == len + i);
720 } 720 }
721 721
722 /* negative */ 722 /* negative */
723 for (i = 1; i < len; ++i) { 723 for (i = 1; i < len; ++i) {
724 ATF_CHECK(fseeko(fp, -i, SEEK_END) == 0); 724 ATF_CHECK(fseeko(fp, -i, SEEK_END) == 0);
725 ATF_CHECK(ftello(fp) == len - i); 725 ATF_CHECK(ftello(fp) == len - i);
726 } 726 }
727#endif 727#endif
728 ATF_CHECK(fclose(fp) == 0); 728 ATF_CHECK(fclose(fp) == 0);
729 } 729 }
730 } 730 }
731} 731}
732 732
733const char *mode_rw1[] = { 733const char *mode_rw1[] = {
734 "r", "rb", "r+", "rb+", "r+b", 734 "r", "rb", "r+", "rb+", "r+b",
735 "w+", "wb+", 735 "w+", "wb+",
736 NULL 736 NULL
737}; 737};
738 738
739/* test15 - 18: 739/* test15 - 18:
740 * When a stream open for writing is flushed or closed, a null byte is written 740 * When a stream open for writing is flushed or closed, a null byte is written
741 * at the current position or at the end of the buffer, depending on the size 741 * at the current position or at the end of the buffer, depending on the size
742 * of the contents. 742 * of the contents.
743 */ 743 */
744 744
745ATF_TC(test15); 745ATF_TC(test15);
746ATF_TC_HEAD(test15, tc) 746ATF_TC_HEAD(test15, tc)
747{ 747{
748 atf_tc_set_md_var(tc, "descr", "test15"); 748 atf_tc_set_md_var(tc, "descr", "test15");
749} 749}
750ATF_TC_BODY(test15, tc) 750ATF_TC_BODY(test15, tc)
751{ 751{
752 struct testcase *t; 752 struct testcase *t;
753 const char **p; 753 const char **p;
754 char buf0[BUFSIZ], buf1[BUFSIZ]; 754 char buf0[BUFSIZ];
755 FILE *fp; 755 FILE *fp;
756 size_t i; 756 int i;
757 757
758 for (t = &testcases[0]; t->s != NULL; ++t) { 758 for (t = &testcases[0]; t->s != NULL; ++t) {
759 for (p = &mode_rw1[0]; *p != NULL; ++p) { 759 for (p = &mode_rw1[0]; *p != NULL; ++p) {
760 760
761 memcpy(&buf0[0], t->s, t->n); 761 memcpy(&buf0[0], t->s, t->n);
762 fp = fmemopen(&buf0[0], t->n, *p); 762 fp = fmemopen(&buf0[0], t->n, *p);
763 ATF_CHECK(fp != NULL); 763 ATF_CHECK(fp != NULL);
764/* 764/*
765 * test fmemopen_read + fgetc(3) 765 * test fmemopen_read + fgetc(3)
766 */ 766 */
767 for (i = (size_t)0; i < t->n; ++i) { 767 for (i = 0; i < t->n; ++i) {
768 ATF_CHECK(ftello(fp) == (off_t)i); 768 ATF_CHECK(ftello(fp) == (off_t)i);
769 ATF_CHECK(fgetc(fp) == buf0[i]); 769 ATF_CHECK(fgetc(fp) == buf0[i]);
770 ATF_CHECK(feof(fp) == 0); 770 ATF_CHECK(feof(fp) == 0);
771 ATF_CHECK(ftello(fp) == (off_t)i + 1); 771 ATF_CHECK(ftello(fp) == (off_t)i + 1);
772 } 772 }
773 ATF_CHECK(fgetc(fp) == EOF); 773 ATF_CHECK(fgetc(fp) == EOF);
774 ATF_CHECK(feof(fp) != 0); 774 ATF_CHECK(feof(fp) != 0);
775 ATF_CHECK(ftello(fp) == (off_t)t->n); 775 ATF_CHECK(ftello(fp) == (off_t)t->n);
776 ATF_CHECK(fclose(fp) == 0); 776 ATF_CHECK(fclose(fp) == 0);
777 } 777 }
778 } 778 }
779} 779}
780 780
781ATF_TC(test16); 781ATF_TC(test16);
782ATF_TC_HEAD(test16, tc) 782ATF_TC_HEAD(test16, tc)
783{ 783{
784 atf_tc_set_md_var(tc, "descr", "test16"); 784 atf_tc_set_md_var(tc, "descr", "test16");
785} 785}
786ATF_TC_BODY(test16, tc) 786ATF_TC_BODY(test16, tc)
787{ 787{
788 struct testcase *t; 788 struct testcase *t;
789 const char **p; 789 const char **p;
790 char buf0[BUFSIZ], buf1[BUFSIZ]; 790 char buf0[BUFSIZ], buf1[BUFSIZ];
791 FILE *fp; 791 FILE *fp;
792 792
793 for (t = &testcases[0]; t->s != NULL; ++t) { 793 for (t = &testcases[0]; t->s != NULL; ++t) {
794 for (p = &mode_rw1[0]; *p != NULL; ++p) { 794 for (p = &mode_rw1[0]; *p != NULL; ++p) {
795 795
796 memcpy(&buf0[0], t->s, t->n); 796 memcpy(&buf0[0], t->s, t->n);
797 buf1[t->n] = 0x1; 797 buf1[t->n] = 0x1;
798 fp = fmemopen(&buf0[0], t->n, *p); 798 fp = fmemopen(&buf0[0], t->n, *p);
799 ATF_CHECK(fp != NULL); 799 ATF_CHECK(fp != NULL);
800/* 800/*
801 * test fmemopen_read + fread(4) 801 * test fmemopen_read + fread(4)
802 */ 802 */
803 ATF_CHECK(ftello(fp) == (off_t)0); 803 ATF_CHECK(ftello(fp) == (off_t)0);
804 ATF_CHECK(fread(&buf1[0], 1, sizeof(buf1), fp) == t->n); 804 ATF_CHECK(fread(&buf1[0], 1, sizeof(buf1), fp) == (size_t)t->n);
805 ATF_CHECK(feof(fp) != 0); 805 ATF_CHECK(feof(fp) != 0);
806 ATF_CHECK(memcmp(&buf0[0], &buf1[0], t->n) == 0); 806 ATF_CHECK(memcmp(&buf0[0], &buf1[0], t->n) == 0);
807 ATF_CHECK((unsigned char)buf1[t->n] == 0x1); 807 ATF_CHECK((unsigned char)buf1[t->n] == 0x1);
808 808
809 ATF_CHECK(fclose(fp) == 0); 809 ATF_CHECK(fclose(fp) == 0);
810 } 810 }
811 } 811 }
812} 812}
813 813
814const char *mode_a1[] = { "a+", "ab+", NULL }; 814const char *mode_a1[] = { "a+", "ab+", NULL };
815 815
816ATF_TC(test17); 816ATF_TC(test17);
817ATF_TC_HEAD(test17, tc) 817ATF_TC_HEAD(test17, tc)
818{ 818{
819 atf_tc_set_md_var(tc, "descr", "test17"); 819 atf_tc_set_md_var(tc, "descr", "test17");
820} 820}
821ATF_TC_BODY(test17, tc) 821ATF_TC_BODY(test17, tc)
822{ 822{
823 struct testcase *t; 823 struct testcase *t;
824 size_t len, i; 824 size_t len;
 825 int i;
825 const char **p; 826 const char **p;
826 char buf[BUFSIZ]; 827 char buf[BUFSIZ];
827 FILE *fp; 828 FILE *fp;
828 829
829 for (t = &testcases[0]; t->s != NULL; ++t) { 830 for (t = &testcases[0]; t->s != NULL; ++t) {
830 len = strnlen(t->s, t->n); 831 len = strnlen(t->s, t->n);
831 for (p = &mode_a1[0]; *p != NULL; ++p) { 832 for (p = &mode_a1[0]; *p != NULL; ++p) {
832 833
833 memcpy(&buf[0], t->s, t->n); 834 memcpy(&buf[0], t->s, t->n);
834 fp = fmemopen(&buf[0], t->n, *p); 835 fp = fmemopen(&buf[0], t->n, *p);
835 ATF_CHECK(fp != NULL); 836 ATF_CHECK(fp != NULL);
836/* 837/*
837 * test fmemopen_read + fgetc(3) 838 * test fmemopen_read + fgetc(3)
838 */ 839 */
839#if defined(__GLIBC__) 840#if defined(__GLIBC__)
840 if (i < t->n) { 841 if (i < t->n) {
841#endif 842#endif
842 for (i = len; i < t->n; ++i) { 843 for (i = len; i < t->n; ++i) {
843 ATF_CHECK(ftello(fp) == (off_t)i); 844 ATF_CHECK(ftello(fp) == (off_t)i);
844 ATF_CHECK(fgetc(fp) == buf[i]); 845 ATF_CHECK(fgetc(fp) == buf[i]);
845 ATF_CHECK(feof(fp) == 0); 846 ATF_CHECK(feof(fp) == 0);
846 ATF_CHECK(ftello(fp) == (off_t)i + 1); 847 ATF_CHECK(ftello(fp) == (off_t)i + 1);
847 } 848 }
848 ATF_CHECK(fgetc(fp) == EOF); 849 ATF_CHECK(fgetc(fp) == EOF);
849 ATF_CHECK(feof(fp) != 0); 850 ATF_CHECK(feof(fp) != 0);
850 ATF_CHECK(ftello(fp) == (off_t)t->n); 851 ATF_CHECK(ftello(fp) == (off_t)t->n);
851 rewind(fp); 852 rewind(fp);
852 for (i = (size_t)0; i < t->n; ++i) { 853 for (i = 0; i < t->n; ++i) {
853 ATF_CHECK(ftello(fp) == (off_t)i); 854 ATF_CHECK(ftello(fp) == (off_t)i);
854 ATF_CHECK(fgetc(fp) == buf[i]); 855 ATF_CHECK(fgetc(fp) == buf[i]);
855 ATF_CHECK(feof(fp) == 0); 856 ATF_CHECK(feof(fp) == 0);
856 ATF_CHECK(ftello(fp) == (off_t)i + 1); 857 ATF_CHECK(ftello(fp) == (off_t)i + 1);
857 } 858 }
858 ATF_CHECK(fgetc(fp) == EOF); 859 ATF_CHECK(fgetc(fp) == EOF);
859 ATF_CHECK(feof(fp) != 0); 860 ATF_CHECK(feof(fp) != 0);
860 ATF_CHECK(ftello(fp) == (off_t)t->n); 861 ATF_CHECK(ftello(fp) == (off_t)t->n);
861#if defined(__GLIBC__) 862#if defined(__GLIBC__)
862 } 863 }
863#endif 864#endif
864 ATF_CHECK(fclose(fp) == 0); 865 ATF_CHECK(fclose(fp) == 0);
865 } 866 }
866 } 867 }
867} 868}
868 869
869ATF_TC(test18); 870ATF_TC(test18);
870ATF_TC_HEAD(test18, tc) 871ATF_TC_HEAD(test18, tc)
871{ 872{
872 atf_tc_set_md_var(tc, "descr", "test18"); 873 atf_tc_set_md_var(tc, "descr", "test18");
873} 874}
874ATF_TC_BODY(test18, tc) 875ATF_TC_BODY(test18, tc)
875{ 876{
876 struct testcase *t; 877 struct testcase *t;
877 size_t len, i; 878 size_t len;
878 const char **p; 879 const char **p;
879 char buf0[BUFSIZ], buf1[BUFSIZ]; 880 char buf0[BUFSIZ], buf1[BUFSIZ];
880 FILE *fp; 881 FILE *fp;
881 882
882 for (t = &testcases[0]; t->s != NULL; ++t) { 883 for (t = &testcases[0]; t->s != NULL; ++t) {
883 len = strnlen(t->s, t->n); 884 len = strnlen(t->s, t->n);
884 for (p = &mode_a1[0]; *p != NULL; ++p) { 885 for (p = &mode_a1[0]; *p != NULL; ++p) {
885 886
886 memcpy(&buf0[0], t->s, t->n); 887 memcpy(&buf0[0], t->s, t->n);
887 buf1[t->n - len] = 0x1; 888 buf1[t->n - len] = 0x1;
888 fp = fmemopen(&buf0[0], t->n, *p); 889 fp = fmemopen(&buf0[0], t->n, *p);
889 ATF_CHECK(fp != NULL); 890 ATF_CHECK(fp != NULL);
890/* 891/*
891 * test fmemopen_read + fread(3) 892 * test fmemopen_read + fread(3)
892 */ 893 */
893#if defined(__GLIBC__) 894#if defined(__GLIBC__)
894 if (i < t->n) { 895 if (i < t->n) {
895#endif 896#endif
896 ATF_CHECK(ftello(fp) == (off_t)len); 897 ATF_CHECK(ftello(fp) == (off_t)len);
897 ATF_CHECK(fread(&buf1[0], 1, sizeof(buf1), fp) 898 ATF_CHECK(fread(&buf1[0], 1, sizeof(buf1), fp)
898 == t->n - len); 899 == t->n - len);
899 ATF_CHECK(feof(fp) != 0); 900 ATF_CHECK(feof(fp) != 0);
900 ATF_CHECK(!memcmp(&buf0[len], &buf1[0], t->n - len)); 901 ATF_CHECK(!memcmp(&buf0[len], &buf1[0], t->n - len));
901 ATF_CHECK((unsigned char)buf1[t->n - len] == 0x1); 902 ATF_CHECK((unsigned char)buf1[t->n - len] == 0x1);
902 rewind(fp); 903 rewind(fp);
903 buf1[t->n] = 0x1; 904 buf1[t->n] = 0x1;
904 ATF_CHECK(ftello(fp) == (off_t)0); 905 ATF_CHECK(ftello(fp) == (off_t)0);
905 ATF_CHECK(fread(&buf1[0], 1, sizeof(buf1), fp) 906 ATF_CHECK(fread(&buf1[0], 1, sizeof(buf1), fp)
906 == t->n); 907 == (size_t)t->n);
907 ATF_CHECK(feof(fp) != 0); 908 ATF_CHECK(feof(fp) != 0);
908 ATF_CHECK(!memcmp(&buf0[0], &buf1[0], t->n)); 909 ATF_CHECK(!memcmp(&buf0[0], &buf1[0], t->n));
909 ATF_CHECK((unsigned char)buf1[t->n] == 0x1); 910 ATF_CHECK((unsigned char)buf1[t->n] == 0x1);
910#if defined(__GLIBC__) 911#if defined(__GLIBC__)
911 } 912 }
912#endif 913#endif
913 ATF_CHECK(fclose(fp) == 0); 914 ATF_CHECK(fclose(fp) == 0);
914 } 915 }
915 } 916 }
916} 917}
917 918
918/* 919/*
919 * test19 - test22: 920 * test19 - test22:
920 * If a stream open for update is flushed or closed and the last write has 921 * If a stream open for update is flushed or closed and the last write has
921 * advanced the current buffer size, a null byte is written at the end of the 922 * advanced the current buffer size, a null byte is written at the end of the
922 * buffer if it fits. 923 * buffer if it fits.
923 */ 924 */
924 925
925const char *mode_rw2[] = { 926const char *mode_rw2[] = {
926 "r+", "rb+", "r+b", 927 "r+", "rb+", "r+b",
927 "w", "wb", "w+", "wb+", "w+b", 928 "w", "wb", "w+", "wb+", "w+b",
928 NULL 929 NULL
929}; 930};
930 931
931ATF_TC(test19); 932ATF_TC(test19);
932ATF_TC_HEAD(test19, tc) 933ATF_TC_HEAD(test19, tc)
933{ 934{
934 atf_tc_set_md_var(tc, "descr", "test19"); 935 atf_tc_set_md_var(tc, "descr", "test19");
935} 936}
936ATF_TC_BODY(test19, tc) 937ATF_TC_BODY(test19, tc)
937{ 938{
938 struct testcase *t; 939 struct testcase *t;
939 size_t len, i; 940 size_t len;
 941 int i;
940 const char **p; 942 const char **p;
941 char buf[BUFSIZ]; 943 char buf[BUFSIZ];
942 FILE *fp; 944 FILE *fp;
943 945
944 for (t = &testcases[0]; t->s != NULL; ++t) { 946 for (t = &testcases[0]; t->s != NULL; ++t) {
945 len = strnlen(t->s, t->n); 947 len = strnlen(t->s, t->n);
946 for (p = &mode_rw2[0]; *p != NULL; ++p) { 948 for (p = &mode_rw2[0]; *p != NULL; ++p) {
947 949
948 memcpy(&buf[0], t->s, t->n); 950 memcpy(&buf[0], t->s, t->n);
949 buf[t->n] = 0x1; 951 buf[t->n] = 0x1;
950 fp = fmemopen(&buf[0], t->n + 1, *p); 952 fp = fmemopen(&buf[0], t->n + 1, *p);
951 ATF_CHECK(fp != NULL); 953 ATF_CHECK(fp != NULL);
952 setbuf(fp, NULL); 954 setbuf(fp, NULL);
953/* 955/*
954 * test fmemopen_write + fputc(3) 956 * test fmemopen_write + fputc(3)
955 */ 957 */
956 for (i = (size_t)0; i < t->n; ++i) { 958 for (i = 0; i < t->n; ++i) {
957 ATF_CHECK(ftello(fp) == (off_t)i); 959 ATF_CHECK(ftello(fp) == (off_t)i);
958 ATF_CHECK(fputc(t->s[i], fp) == t->s[i]); 960 ATF_CHECK(fputc(t->s[i], fp) == t->s[i]);
959 ATF_CHECK(buf[i] == t->s[i]); 961 ATF_CHECK(buf[i] == t->s[i]);
960 ATF_CHECK(ftello(fp) == (off_t)i + 1); 962 ATF_CHECK(ftello(fp) == (off_t)i + 1);
961 ATF_CHECK(buf[i] == t->s[i]); 963 ATF_CHECK(buf[i] == t->s[i]);
962#if !defined(__GLIBC__) 964#if !defined(__GLIBC__)
963 ATF_CHECK(buf[i + 1] == '\0'); 965 ATF_CHECK(buf[i + 1] == '\0');
964#endif 966#endif
965 } 967 }
966 968
967/* don't accept non nul character at end of buffer */ 969/* don't accept non nul character at end of buffer */
968 ATF_CHECK(fputc(0x1, fp) == EOF); 970 ATF_CHECK(fputc(0x1, fp) == EOF);
969 ATF_CHECK(ftello(fp) == (off_t)t->n); 971 ATF_CHECK(ftello(fp) == (off_t)t->n);
970 ATF_CHECK(feof(fp) == 0); 972 ATF_CHECK(feof(fp) == 0);
971 973
972/* accept nul character at end of buffer */ 974/* accept nul character at end of buffer */
973 ATF_CHECK(fputc('\0', fp) == '\0'); 975 ATF_CHECK(fputc('\0', fp) == '\0');
974 ATF_CHECK(ftello(fp) == (off_t)t->n + 1); 976 ATF_CHECK(ftello(fp) == (off_t)t->n + 1);
975 ATF_CHECK(feof(fp) == 0); 977 ATF_CHECK(feof(fp) == 0);
976 978
977/* reach EOF */ 979/* reach EOF */
978 ATF_CHECK(fputc('\0', fp) == EOF); 980 ATF_CHECK(fputc('\0', fp) == EOF);
979 ATF_CHECK(ftello(fp) == (off_t)t->n + 1); 981 ATF_CHECK(ftello(fp) == (off_t)t->n + 1);
980 982
981 /* compare */ 983 /* compare */
982 ATF_CHECK(memcmp(&buf[0], t->s, t->n) == 0); 984 ATF_CHECK(memcmp(&buf[0], t->s, t->n) == 0);
983 ATF_CHECK(buf[t->n] == '\0'); 985 ATF_CHECK(buf[t->n] == '\0');
984 986
985 ATF_CHECK(fclose(fp) == 0); 987 ATF_CHECK(fclose(fp) == 0);
986 } 988 }
987 } 989 }
988} 990}
989 991
990ATF_TC(test20); 992ATF_TC(test20);
991ATF_TC_HEAD(test20, tc) 993ATF_TC_HEAD(test20, tc)
992{ 994{
993 atf_tc_set_md_var(tc, "descr", "test20"); 995 atf_tc_set_md_var(tc, "descr", "test20");
994} 996}
995ATF_TC_BODY(test20, tc) 997ATF_TC_BODY(test20, tc)
996{ 998{
997 struct testcase *t; 999 struct testcase *t;
998 size_t len, i; 1000 size_t len;
999 const char **p; 1001 const char **p;
1000 char buf[BUFSIZ]; 1002 char buf[BUFSIZ];
1001 FILE *fp; 1003 FILE *fp;
1002 1004
1003 for (t = &testcases[0]; t->s != NULL; ++t) { 1005 for (t = &testcases[0]; t->s != NULL; ++t) {
1004 len = strnlen(t->s, t->n); 1006 len = strnlen(t->s, t->n);
1005 for (p = &mode_rw2[0]; *p != NULL; ++p) { 1007 for (p = &mode_rw2[0]; *p != NULL; ++p) {
1006 1008
1007 memcpy(&buf[0], t->s, t->n); 1009 memcpy(&buf[0], t->s, t->n);
1008 buf[t->n] = 0x1; 1010 buf[t->n] = 0x1;
1009 fp = fmemopen(&buf[0], t->n + 1, *p); 1011 fp = fmemopen(&buf[0], t->n + 1, *p);
1010 ATF_CHECK(fp != NULL); 1012 ATF_CHECK(fp != NULL);
1011 setbuf(fp, NULL); 1013 setbuf(fp, NULL);
1012 ATF_CHECK(fwrite(t->s, 1, t->n, fp) == t->n); 1014 ATF_CHECK(fwrite(t->s, 1, t->n, fp) == (size_t)t->n);
1013/* 1015/*
1014 * test fmemopen_write + fwrite(3) 1016 * test fmemopen_write + fwrite(3)
1015 */ 1017 */
1016#if !defined(__GLIBC__) 1018#if !defined(__GLIBC__)
1017 ATF_CHECK(buf[t->n] == '\0'); 1019 ATF_CHECK(buf[t->n] == '\0');
1018 1020
1019/* don't accept non nul character at end of buffer */ 1021/* don't accept non nul character at end of buffer */
1020 ATF_CHECK(fwrite("\x1", 1, 1, fp) == 0); 1022 ATF_CHECK(fwrite("\x1", 1, 1, fp) == 0);
1021 ATF_CHECK(ftello(fp) == (off_t)t->n); 1023 ATF_CHECK(ftello(fp) == (off_t)t->n);
1022 ATF_CHECK(feof(fp) == 0); 1024 ATF_CHECK(feof(fp) == 0);
1023#endif 1025#endif
1024 1026
1025/* accept nul character at end of buffer */ 1027/* accept nul character at end of buffer */
1026 ATF_CHECK(fwrite("\x0", 1, 1, fp) == 1); 1028 ATF_CHECK(fwrite("\x0", 1, 1, fp) == 1);
1027 ATF_CHECK(ftello(fp) == (off_t)t->n + 1); 1029 ATF_CHECK(ftello(fp) == (off_t)t->n + 1);
1028 ATF_CHECK(feof(fp) == 0); 1030 ATF_CHECK(feof(fp) == 0);
1029 1031
1030/* reach EOF */ 1032/* reach EOF */
1031 ATF_CHECK(fputc('\0', fp) == EOF); 1033 ATF_CHECK(fputc('\0', fp) == EOF);
1032 ATF_CHECK(ftello(fp) == (off_t)t->n + 1); 1034 ATF_CHECK(ftello(fp) == (off_t)t->n + 1);
1033 1035
1034/* compare */ 1036/* compare */
1035 ATF_CHECK(memcmp(&buf[0], t->s, t->n) == 0); 1037 ATF_CHECK(memcmp(&buf[0], t->s, t->n) == 0);
1036 ATF_CHECK(buf[t->n] == '\0'); 1038 ATF_CHECK(buf[t->n] == '\0');
1037 1039
1038 ATF_CHECK(fclose(fp) == 0); 1040 ATF_CHECK(fclose(fp) == 0);
1039 } 1041 }
1040 } 1042 }
1041} 1043}
1042 1044
1043ATF_TC(test21); 1045ATF_TC(test21);
1044ATF_TC_HEAD(test21, tc) 1046ATF_TC_HEAD(test21, tc)
1045{ 1047{
1046 atf_tc_set_md_var(tc, "descr", "test21"); 1048 atf_tc_set_md_var(tc, "descr", "test21");
1047} 1049}
1048ATF_TC_BODY(test21, tc) 1050ATF_TC_BODY(test21, tc)
1049{ 1051{
1050 struct testcase *t; 1052 struct testcase *t;
1051 size_t len, i; 1053 int len, i;
1052 const char **p; 1054 const char **p;
1053 char buf[BUFSIZ]; 1055 char buf[BUFSIZ];
1054 FILE *fp; 1056 FILE *fp;
1055 1057
1056 for (t = &testcases[0]; t->s != NULL; ++t) { 1058 for (t = &testcases[0]; t->s != NULL; ++t) {
1057 len = strnlen(t->s, t->n); 1059 len = strnlen(t->s, t->n);
1058 for (p = &mode_a[0]; *p != NULL; ++p) { 1060 for (p = &mode_a[0]; *p != NULL; ++p) {
1059 memcpy(&buf[0], t->s, t->n); 1061 memcpy(&buf[0], t->s, t->n);
1060 fp = fmemopen(&buf[0], t->n, *p); 1062 fp = fmemopen(&buf[0], t->n, *p);
1061 ATF_CHECK(fp != NULL); 1063 ATF_CHECK(fp != NULL);
1062 setbuf(fp, NULL); 1064 setbuf(fp, NULL);
1063/* 1065/*
1064 * test fmemopen_write + fputc(3) 1066 * test fmemopen_write + fputc(3)
1065 */ 1067 */
1066 if (len < t->n) { 1068 if (len < t->n) {
1067 for (i = len; i < t->n - 1; ++i) { 1069 for (i = len; i < t->n - 1; ++i) {
1068 ATF_CHECK(ftello(fp) == (off_t)i); 1070 ATF_CHECK(ftello(fp) == (off_t)i);
1069 ATF_CHECK(fputc(t->s[i - len], fp) 1071 ATF_CHECK(fputc(t->s[i - len], fp)
1070 == t->s[i - len]); 1072 == t->s[i - len]);
1071 ATF_CHECK(buf[i] == t->s[i - len]); 1073 ATF_CHECK(buf[i] == t->s[i - len]);
1072 ATF_CHECK(ftello(fp) == (off_t)i + 1); 1074 ATF_CHECK(ftello(fp) == (off_t)i + 1);
1073#if !defined(__GLIBC__) 1075#if !defined(__GLIBC__)
1074 ATF_CHECK(buf[i + 1] == '\0'); 1076 ATF_CHECK(buf[i + 1] == '\0');
1075#endif 1077#endif
1076 } 1078 }
1077 1079
1078/* don't accept non nul character at end of buffer */ 1080/* don't accept non nul character at end of buffer */
1079 ATF_CHECK(ftello(fp) == (off_t)t->n - 1); 1081 ATF_CHECK(ftello(fp) == (off_t)t->n - 1);
1080 ATF_CHECK(fputc(0x1, fp) == EOF); 1082 ATF_CHECK(fputc(0x1, fp) == EOF);
1081 ATF_CHECK(ftello(fp) == (off_t)t->n - 1); 1083 ATF_CHECK(ftello(fp) == (off_t)t->n - 1);
1082 1084
1083/* accept nul character at end of buffer */ 1085/* accept nul character at end of buffer */
1084 ATF_CHECK(ftello(fp) == (off_t)t->n - 1); 1086 ATF_CHECK(ftello(fp) == (off_t)t->n - 1);
1085 ATF_CHECK(fputc('\0', fp) == '\0'); 1087 ATF_CHECK(fputc('\0', fp) == '\0');
1086 ATF_CHECK(ftello(fp) == (off_t)t->n); 1088 ATF_CHECK(ftello(fp) == (off_t)t->n);
1087 } 1089 }
1088 1090
1089/* reach EOF */ 1091/* reach EOF */
1090 ATF_CHECK(ftello(fp) == (off_t)t->n); 1092 ATF_CHECK(ftello(fp) == (off_t)t->n);
1091 ATF_CHECK(fputc('\0', fp) == EOF); 1093 ATF_CHECK(fputc('\0', fp) == EOF);
1092 ATF_CHECK(ftello(fp) == (off_t)t->n); 1094 ATF_CHECK(ftello(fp) == (off_t)t->n);
1093 1095
1094 ATF_CHECK(fclose(fp) == 0); 1096 ATF_CHECK(fclose(fp) == 0);
1095 } 1097 }
1096 } 1098 }
1097} 1099}
1098 1100
1099ATF_TC(test22); 1101ATF_TC(test22);
1100ATF_TC_HEAD(test22, tc) 1102ATF_TC_HEAD(test22, tc)
1101{ 1103{
1102 atf_tc_set_md_var(tc, "descr", "test22"); 1104 atf_tc_set_md_var(tc, "descr", "test22");
1103} 1105}
1104ATF_TC_BODY(test22, tc) 1106ATF_TC_BODY(test22, tc)
1105{ 1107{
1106 struct testcase *t0, *t1; 1108 struct testcase *t0, *t1;
1107 size_t len0, len1, i, nleft; 1109 size_t len0, len1, nleft;
1108 const char **p; 1110 const char **p;
1109 char buf[BUFSIZ]; 1111 char buf[BUFSIZ];
1110 FILE *fp; 1112 FILE *fp;
1111 1113
1112 for (t0 = &testcases[0]; t0->s != NULL; ++t0) { 1114 for (t0 = &testcases[0]; t0->s != NULL; ++t0) {
1113 len0 = strnlen(t0->s, t0->n); 1115 len0 = strnlen(t0->s, t0->n);
1114 for (t1 = &testcases[0]; t1->s != NULL; ++t1) { 1116 for (t1 = &testcases[0]; t1->s != NULL; ++t1) {
1115 len1 = strnlen(t1->s, t1->n); 1117 len1 = strnlen(t1->s, t1->n);
1116 for (p = &mode_a[0]; *p != NULL; ++p) { 1118 for (p = &mode_a[0]; *p != NULL; ++p) {
1117 1119
1118 memcpy(&buf[0], t0->s, t0->n); 1120 memcpy(&buf[0], t0->s, t0->n);
1119 fp = fmemopen(&buf[0], t0->n, *p); 1121 fp = fmemopen(&buf[0], t0->n, *p);
1120 ATF_CHECK(fp != NULL); 1122 ATF_CHECK(fp != NULL);
1121 setbuf(fp, NULL); 1123 setbuf(fp, NULL);
1122/* 1124/*
1123 * test fmemopen_write + fwrite(3) 1125 * test fmemopen_write + fwrite(3)
1124 */ 1126 */
1125 nleft = t0->n - len0; 1127 nleft = t0->n - len0;
1126#if !defined(__GLIBC__) 1128#if !defined(__GLIBC__)
1127 if (nleft == 0 || len1 == nleft - 1) { 1129 if (nleft == 0 || len1 == nleft - 1) {
1128 ATF_CHECK(fwrite(t1->s, 1, t1->n, fp) 1130 ATF_CHECK(fwrite(t1->s, 1, t1->n, fp)
1129 == nleft); 1131 == nleft);
1130 ATF_CHECK(ftell(fp) == t1->n); 1132 ATF_CHECK(ftell(fp) == t1->n);
1131 } else { 1133 } else {
1132 ATF_CHECK(fwrite(t1->s, 1, t1->n, fp) 1134 ATF_CHECK(fwrite(t1->s, 1, t1->n, fp)
1133 == nleft - 1); 1135 == nleft - 1);
1134 ATF_CHECK(ftell(fp) == t1->n - 1); 1136 ATF_CHECK(ftell(fp) == t1->n - 1);
1135 } 1137 }
1136#endif 1138#endif
1137 ATF_CHECK(fclose(fp) == 0); 1139 ATF_CHECK(fclose(fp) == 0);
1138 } 1140 }
1139 } 1141 }
1140 } 1142 }
1141} 1143}
1142 1144
1143ATF_TP_ADD_TCS(tp) 1145ATF_TP_ADD_TCS(tp)
1144{ 1146{
1145 ATF_TP_ADD_TC(tp, test00); 1147 ATF_TP_ADD_TC(tp, test00);
1146 ATF_TP_ADD_TC(tp, test01); 1148 ATF_TP_ADD_TC(tp, test01);
1147 ATF_TP_ADD_TC(tp, test02); 1149 ATF_TP_ADD_TC(tp, test02);
1148 ATF_TP_ADD_TC(tp, test03); 1150 ATF_TP_ADD_TC(tp, test03);
1149 ATF_TP_ADD_TC(tp, test04); 1151 ATF_TP_ADD_TC(tp, test04);
1150 ATF_TP_ADD_TC(tp, test05); 1152 ATF_TP_ADD_TC(tp, test05);
1151 ATF_TP_ADD_TC(tp, test06); 1153 ATF_TP_ADD_TC(tp, test06);
1152 ATF_TP_ADD_TC(tp, test07); 1154 ATF_TP_ADD_TC(tp, test07);
1153 ATF_TP_ADD_TC(tp, test08); 1155 ATF_TP_ADD_TC(tp, test08);
1154 ATF_TP_ADD_TC(tp, test09); 1156 ATF_TP_ADD_TC(tp, test09);
1155 ATF_TP_ADD_TC(tp, test10); 1157 ATF_TP_ADD_TC(tp, test10);
1156 ATF_TP_ADD_TC(tp, test11); 1158 ATF_TP_ADD_TC(tp, test11);
1157 ATF_TP_ADD_TC(tp, test12); 1159 ATF_TP_ADD_TC(tp, test12);
1158 ATF_TP_ADD_TC(tp, test13); 1160 ATF_TP_ADD_TC(tp, test13);
1159 ATF_TP_ADD_TC(tp, test14); 1161 ATF_TP_ADD_TC(tp, test14);
1160 ATF_TP_ADD_TC(tp, test15); 1162 ATF_TP_ADD_TC(tp, test15);
1161 ATF_TP_ADD_TC(tp, test16); 1163 ATF_TP_ADD_TC(tp, test16);
1162 ATF_TP_ADD_TC(tp, test17); 1164 ATF_TP_ADD_TC(tp, test17);
1163 ATF_TP_ADD_TC(tp, test18); 1165 ATF_TP_ADD_TC(tp, test18);
1164 ATF_TP_ADD_TC(tp, test19); 1166 ATF_TP_ADD_TC(tp, test19);
1165 ATF_TP_ADD_TC(tp, test20); 1167 ATF_TP_ADD_TC(tp, test20);
1166 ATF_TP_ADD_TC(tp, test21); 1168 ATF_TP_ADD_TC(tp, test21);
1167 ATF_TP_ADD_TC(tp, test22); 1169 ATF_TP_ADD_TC(tp, test22);
1168 1170
1169 return atf_no_error(); 1171 return atf_no_error();
1170} 1172}

cvs diff -r1.1 -r1.2 src/tests/lib/libprop/Attic/t_basic.c (switch to unified diff)

--- src/tests/lib/libprop/Attic/t_basic.c 2010/07/16 13:56:31 1.1
+++ src/tests/lib/libprop/Attic/t_basic.c 2010/11/03 16:10:22 1.2
@@ -1,168 +1,169 @@ @@ -1,168 +1,169 @@
1/* $NetBSD: t_basic.c,v 1.1 2010/07/16 13:56:31 jmmv Exp $ */ 1/* $NetBSD: t_basic.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * Written by Jason Thorpe 5/26/2006. 30 * Written by Jason Thorpe 5/26/2006.
31 * Public domain. 31 * Public domain.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__COPYRIGHT("@(#) Copyright (c) 2008\ 35__COPYRIGHT("@(#) Copyright (c) 2008\
36 The NetBSD Foundation, inc. All rights reserved."); 36 The NetBSD Foundation, inc. All rights reserved.");
37__RCSID("$NetBSD: t_basic.c,v 1.1 2010/07/16 13:56:31 jmmv Exp $"); 37__RCSID("$NetBSD: t_basic.c,v 1.2 2010/11/03 16:10:22 christos Exp $");
38 38
39#include <prop/proplib.h> 
40#include <stdlib.h> 39#include <stdlib.h>
 40#include <string.h>
 41#include <prop/proplib.h>
41 42
42#include <atf-c.h> 43#include <atf-c.h>
43 44
44static const char compare1[] = 45static const char compare1[] =
45"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 46"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
46"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" 47"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
47"<plist version=\"1.0\">\n" 48"<plist version=\"1.0\">\n"
48"<dict>\n" 49"<dict>\n"
49" <key>false-val</key>\n" 50" <key>false-val</key>\n"
50" <false/>\n" 51" <false/>\n"
51" <key>one</key>\n" 52" <key>one</key>\n"
52" <integer>1</integer>\n" 53" <integer>1</integer>\n"
53" <key>three</key>\n" 54" <key>three</key>\n"
54" <array>\n" 55" <array>\n"
55" <dict>\n" 56" <dict>\n"
56" <key>one</key>\n" 57" <key>one</key>\n"
57" <integer>1</integer>\n" 58" <integer>1</integer>\n"
58" <key>two</key>\n" 59" <key>two</key>\n"
59" <string>number-two</string>\n" 60" <string>number-two</string>\n"
60" </dict>\n" 61" </dict>\n"
61" <dict>\n" 62" <dict>\n"
62" <key>one</key>\n" 63" <key>one</key>\n"
63" <integer>1</integer>\n" 64" <integer>1</integer>\n"
64" <key>two</key>\n" 65" <key>two</key>\n"
65" <string>number-two</string>\n" 66" <string>number-two</string>\n"
66" </dict>\n" 67" </dict>\n"
67" <dict>\n" 68" <dict>\n"
68" <key>one</key>\n" 69" <key>one</key>\n"
69" <integer>1</integer>\n" 70" <integer>1</integer>\n"
70" <key>two</key>\n" 71" <key>two</key>\n"
71" <string>number-two</string>\n" 72" <string>number-two</string>\n"
72" </dict>\n" 73" </dict>\n"
73" </array>\n" 74" </array>\n"
74" <key>true-val</key>\n" 75" <key>true-val</key>\n"
75" <true/>\n" 76" <true/>\n"
76" <key>two</key>\n" 77" <key>two</key>\n"
77" <string>number-two</string>\n" 78" <string>number-two</string>\n"
78"</dict>\n" 79"</dict>\n"
79"</plist>\n"; 80"</plist>\n";
80 81
81ATF_TC(simple); 82ATF_TC(simple);
82ATF_TC_HEAD(simple, tc) 83ATF_TC_HEAD(simple, tc)
83{ 84{
84 atf_tc_set_md_var(tc, "descr", "Checks basic functionality of proplib"); 85 atf_tc_set_md_var(tc, "descr", "Checks basic functionality of proplib");
85} 86}
86ATF_TC_BODY(simple, tc) 87ATF_TC_BODY(simple, tc)
87{ 88{
88 prop_dictionary_t dict; 89 prop_dictionary_t dict;
89 char *ext1; 90 char *ext1;
90 91
91 dict = prop_dictionary_create(); 92 dict = prop_dictionary_create();
92 ATF_REQUIRE(dict != NULL); 93 ATF_REQUIRE(dict != NULL);
93 94
94 { 95 {
95 prop_number_t num = prop_number_create_integer(1); 96 prop_number_t num = prop_number_create_integer(1);
96 ATF_REQUIRE(num != NULL); 97 ATF_REQUIRE(num != NULL);
97 98
98 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "one", num), true); 99 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "one", num), true);
99 prop_object_release(num); 100 prop_object_release(num);
100 } 101 }
101 102
102 { 103 {
103 prop_string_t str = prop_string_create_cstring("number-two"); 104 prop_string_t str = prop_string_create_cstring("number-two");
104 ATF_REQUIRE(str != NULL); 105 ATF_REQUIRE(str != NULL);
105 106
106 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "two", str), true); 107 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "two", str), true);
107 prop_object_release(str); 108 prop_object_release(str);
108 } 109 }
109 110
110 { 111 {
111 prop_array_t arr; 112 prop_array_t arr;
112 prop_dictionary_t dict_copy; 113 prop_dictionary_t dict_copy;
113 int i; 114 int i;
114 115
115 arr = prop_array_create(); 116 arr = prop_array_create();
116 ATF_REQUIRE(arr != NULL); 117 ATF_REQUIRE(arr != NULL);
117 118
118 for (i = 0; i < 3; ++i) { 119 for (i = 0; i < 3; ++i) {
119 dict_copy = prop_dictionary_copy(dict); 120 dict_copy = prop_dictionary_copy(dict);
120 ATF_REQUIRE(dict_copy != NULL); 121 ATF_REQUIRE(dict_copy != NULL);
121 ATF_REQUIRE_EQ(prop_array_add(arr, dict_copy), true); 122 ATF_REQUIRE_EQ(prop_array_add(arr, dict_copy), true);
122 prop_object_release(dict_copy); 123 prop_object_release(dict_copy);
123 } 124 }
124 125
125 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "three", arr), true); 126 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "three", arr), true);
126 prop_object_release(arr); 127 prop_object_release(arr);
127 } 128 }
128 129
129 { 130 {
130 prop_bool_t val = prop_bool_create(true); 131 prop_bool_t val = prop_bool_create(true);
131 ATF_REQUIRE(val != NULL); 132 ATF_REQUIRE(val != NULL);
132 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "true-val", val), true); 133 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "true-val", val), true);
133 prop_object_release(val); 134 prop_object_release(val);
134 135
135 val = prop_bool_create(false); 136 val = prop_bool_create(false);
136 ATF_REQUIRE(val != NULL); 137 ATF_REQUIRE(val != NULL);
137 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "false-val", val), true); 138 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "false-val", val), true);
138 prop_object_release(val); 139 prop_object_release(val);
139 } 140 }
140 141
141 ext1 = prop_dictionary_externalize(dict); 142 ext1 = prop_dictionary_externalize(dict);
142 ATF_REQUIRE(ext1 != NULL); 143 ATF_REQUIRE(ext1 != NULL);
143 ATF_REQUIRE_STREQ(compare1, ext1); 144 ATF_REQUIRE_STREQ(compare1, ext1);
144 145
145 { 146 {
146 prop_dictionary_t dict2; 147 prop_dictionary_t dict2;
147 char *ext2; 148 char *ext2;
148 149
149 dict2 = prop_dictionary_internalize(ext1); 150 dict2 = prop_dictionary_internalize(ext1);
150 ATF_REQUIRE(dict2 != NULL); 151 ATF_REQUIRE(dict2 != NULL);
151 ext2 = prop_dictionary_externalize(dict2); 152 ext2 = prop_dictionary_externalize(dict2);
152 ATF_REQUIRE(ext2 != NULL); 153 ATF_REQUIRE(ext2 != NULL);
153 ATF_REQUIRE_STREQ(ext1, ext2); 154 ATF_REQUIRE_STREQ(ext1, ext2);
154 prop_object_release(dict2); 155 prop_object_release(dict2);
155 free(ext2); 156 free(ext2);
156 } 157 }
157 158
158 prop_object_release(dict); 159 prop_object_release(dict);
159 free(ext1); 160 free(ext1);
160} 161}
161 162
162ATF_TP_ADD_TCS(tp) 163ATF_TP_ADD_TCS(tp)
163{ 164{
164 165
165 ATF_TP_ADD_TC(tp, simple); 166 ATF_TP_ADD_TC(tp, simple);
166 167
167 return atf_no_error(); 168 return atf_no_error();
168} 169}

cvs diff -r1.1 -r1.2 src/tests/lib/libpthread/h_resolv.c (switch to unified diff)

--- src/tests/lib/libpthread/h_resolv.c 2010/07/16 15:42:53 1.1
+++ src/tests/lib/libpthread/h_resolv.c 2010/11/03 16:10:22 1.2
@@ -1,208 +1,208 @@ @@ -1,208 +1,208 @@
1/* $NetBSD: h_resolv.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ 1/* $NetBSD: h_resolv.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2004, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2004, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas. 8 * by Christos Zoulas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 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 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 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__COPYRIGHT("@(#) Copyright (c) 2008\ 33__COPYRIGHT("@(#) Copyright (c) 2008\
34 The NetBSD Foundation, inc. All rights reserved."); 34 The NetBSD Foundation, inc. All rights reserved.");
35__RCSID("$NetBSD: h_resolv.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); 35__RCSID("$NetBSD: h_resolv.c,v 1.2 2010/11/03 16:10:22 christos Exp $");
36 36
37#include <pthread.h> 37#include <pthread.h>
38#include <stdio.h> 38#include <stdio.h>
39#include <netdb.h> 39#include <netdb.h>
40#include <stdlib.h> 40#include <stdlib.h>
41#include <unistd.h> 41#include <unistd.h>
42#include <err.h> 42#include <err.h>
43#include <string.h> 43#include <string.h>
44#include <stringlist.h> 44#include <stringlist.h>
45 45
46#define NTHREADS 10 46#define NTHREADS 10
47#define NHOSTS 100 47#define NHOSTS 100
48#define WS " \t\n\r" 48#define WS " \t\n\r"
49 49
50static StringList *hosts = NULL; 50static StringList *hosts = NULL;
51static int debug = 0; 51static int debug = 0;
52static int *ask = NULL; 52static int *ask = NULL;
53static int *got = NULL; 53static int *got = NULL;
54 54
55static void usage(void) __attribute__((__noreturn__)); 55static void usage(void) __attribute__((__noreturn__));
56static void load(const char *); 56static void load(const char *);
57static void resolvone(int); 57static void resolvone(int);
58static void *resolvloop(void *); 58static void *resolvloop(void *);
59static void run(int *); 59static void run(int *);
60 60
61static pthread_mutex_t stats = PTHREAD_MUTEX_INITIALIZER; 61static pthread_mutex_t stats = PTHREAD_MUTEX_INITIALIZER;
62 62
63static void 63static void
64usage(void) 64usage(void)
65{ 65{
66 (void)fprintf(stderr, 66 (void)fprintf(stderr,
67 "Usage: %s [-d] [-h <nhosts>] [-n <nthreads>] <file> ...\n", 67 "Usage: %s [-d] [-h <nhosts>] [-n <nthreads>] <file> ...\n",
68 getprogname()); 68 getprogname());
69 exit(1); 69 exit(1);
70} 70}
71 71
72static void 72static void
73load(const char *fname) 73load(const char *fname)
74{ 74{
75 FILE *fp; 75 FILE *fp;
76 size_t len; 76 size_t len;
77 char *line; 77 char *line;
78 78
79 if ((fp = fopen(fname, "r")) == NULL) 79 if ((fp = fopen(fname, "r")) == NULL)
80 err(1, "Cannot open `%s'", fname); 80 err(1, "Cannot open `%s'", fname);
81 while ((line = fgetln(fp, &len)) != NULL) { 81 while ((line = fgetln(fp, &len)) != NULL) {
82 char c = line[len]; 82 char c = line[len];
83 char *ptr; 83 char *ptr;
84 line[len] = '\0'; 84 line[len] = '\0';
85 for (ptr = strtok(line, WS); ptr; ptr = strtok(NULL, WS)) 85 for (ptr = strtok(line, WS); ptr; ptr = strtok(NULL, WS))
86 sl_add(hosts, strdup(ptr)); 86 sl_add(hosts, strdup(ptr));
87 line[len] = c; 87 line[len] = c;
88 } 88 }
89 89
90 (void)fclose(fp); 90 (void)fclose(fp);
91} 91}
92 92
93static void 93static void
94resolvone(int n) 94resolvone(int n)
95{ 95{
96 char buf[1024]; 96 char buf[1024];
97 pthread_t self = pthread_self(); 97 pthread_t self = pthread_self();
98 size_t i = (random() & 0x0fffffff) % hosts->sl_cur; 98 size_t i = (random() & 0x0fffffff) % hosts->sl_cur;
99 char *host = hosts->sl_str[i]; 99 char *host = hosts->sl_str[i];
100 struct addrinfo *res; 100 struct addrinfo *res;
101 int error, len; 101 int error, len;
102 if (debug) { 102 if (debug) {
103 len = snprintf(buf, sizeof(buf), "%p: %d resolving %s %d\n", 103 len = snprintf(buf, sizeof(buf), "%p: %d resolving %s %d\n",
104 self, n, host, (int)i); 104 self, n, host, (int)i);
105 (void)write(STDOUT_FILENO, buf, len); 105 (void)write(STDOUT_FILENO, buf, len);
106 } 106 }
107 error = getaddrinfo(host, NULL, NULL, &res); 107 error = getaddrinfo(host, NULL, NULL, &res);
108 if (debug) { 108 if (debug) {
109 len = snprintf(buf, sizeof(buf), "%p: host %s %s\n", 109 len = snprintf(buf, sizeof(buf), "%p: host %s %s\n",
110 self, host, error ? "not found" : "ok"); 110 self, host, error ? "not found" : "ok");
111 (void)write(STDOUT_FILENO, buf, len); 111 (void)write(STDOUT_FILENO, buf, len);
112 } 112 }
113 pthread_mutex_lock(&stats); 113 pthread_mutex_lock(&stats);
114 ask[i]++; 114 ask[i]++;
115 got[i] += error == 0; 115 got[i] += error == 0;
116 pthread_mutex_unlock(&stats); 116 pthread_mutex_unlock(&stats);
117 if (error == 0) 117 if (error == 0)
118 freeaddrinfo(res); 118 freeaddrinfo(res);
119} 119}
120 120
121static void * 121static void *
122resolvloop(void *p) 122resolvloop(void *p)
123{ 123{
124 int *nhosts = (int *)p; 124 int *nhosts = (int *)p;
125 if (*nhosts == 0) 125 if (*nhosts == 0)
126 return NULL; 126 return NULL;
127 do 127 do
128 resolvone(*nhosts); 128 resolvone(*nhosts);
129 while (--(*nhosts)); 129 while (--(*nhosts));
130 return NULL; 130 return NULL;
131} 131}
132 132
133static void 133static void
134run(int *nhosts) 134run(int *nhosts)
135{ 135{
136 pthread_t self = pthread_self(); 136 pthread_t self = pthread_self();
137 if (pthread_create(&self, NULL, resolvloop, nhosts) != 0) 137 if (pthread_create(&self, NULL, resolvloop, nhosts) != 0)
138 err(1, "pthread_create"); 138 err(1, "pthread_create");
139} 139}
140 140
141int 141int
142main(int argc, char *argv[]) 142main(int argc, char *argv[])
143{ 143{
144 int nthreads = NTHREADS; 144 int nthreads = NTHREADS;
145 int nhosts = NHOSTS; 145 int nhosts = NHOSTS;
146 int i, c, done, *nleft; 146 int i, c, done, *nleft;
147 hosts = sl_init(); 147 hosts = sl_init();
148 148
149 srandom(1234); 149 srandom(1234);
150 150
151 while ((c = getopt(argc, argv, "dh:n:")) != -1) 151 while ((c = getopt(argc, argv, "dh:n:")) != -1)
152 switch (c) { 152 switch (c) {
153 case 'd': 153 case 'd':
154 debug++; 154 debug++;
155 break; 155 break;
156 case 'h': 156 case 'h':
157 nhosts = atoi(optarg); 157 nhosts = atoi(optarg);
158 break; 158 break;
159 case 'n': 159 case 'n':
160 nthreads = atoi(optarg); 160 nthreads = atoi(optarg);
161 break; 161 break;
162 default: 162 default:
163 usage(); 163 usage();
164 } 164 }
165 165
166 for (i = optind; i < argc; i++) 166 for (i = optind; i < argc; i++)
167 load(argv[i]); 167 load(argv[i]);
168 168
169 if (hosts->sl_cur == 0) 169 if (hosts->sl_cur == 0)
170 usage(); 170 usage();
171 171
172 if ((nleft = malloc(nthreads * sizeof(int))) == NULL) 172 if ((nleft = malloc(nthreads * sizeof(int))) == NULL)
173 err(1, "malloc"); 173 err(1, "malloc");
174 if ((ask = calloc(hosts->sl_cur, sizeof(int))) == NULL) 174 if ((ask = calloc(hosts->sl_cur, sizeof(int))) == NULL)
175 err(1, "calloc"); 175 err(1, "calloc");
176 if ((got = calloc(hosts->sl_cur, sizeof(int))) == NULL) 176 if ((got = calloc(hosts->sl_cur, sizeof(int))) == NULL)
177 err(1, "calloc"); 177 err(1, "calloc");
178 178
179 179
180 for (i = 0; i < nthreads; i++) { 180 for (i = 0; i < nthreads; i++) {
181 nleft[i] = nhosts; 181 nleft[i] = nhosts;
182 run(&nleft[i]); 182 run(&nleft[i]);
183 } 183 }
184 184
185 for (done = 0; !done;) { 185 for (done = 0; !done;) {
186 done = 1; 186 done = 1;
187 for (i = 0; i < nthreads; i++) { 187 for (i = 0; i < nthreads; i++) {
188 if (nleft[i] != 0) { 188 if (nleft[i] != 0) {
189 done = 0; 189 done = 0;
190 break; 190 break;
191 } 191 }
192 } 192 }
193 sleep(1); 193 sleep(1);
194 } 194 }
195 c = 0; 195 c = 0;
196 for (i = 0; i < hosts->sl_cur; i++) { 196 for (i = 0; i < (int)hosts->sl_cur; i++) {
197 if (ask[i] != got[i] && got[i] != 0) { 197 if (ask[i] != got[i] && got[i] != 0) {
198 warnx("Error: host %s ask %d got %d\n", 198 warnx("Error: host %s ask %d got %d\n",
199 hosts->sl_str[i], ask[i], got[i]); 199 hosts->sl_str[i], ask[i], got[i]);
200 c++; 200 c++;
201 } 201 }
202 } 202 }
203 free(nleft); 203 free(nleft);
204 free(ask); 204 free(ask);
205 free(got); 205 free(got);
206 sl_free(hosts, 1); 206 sl_free(hosts, 1);
207 return c; 207 return c;
208} 208}

cvs diff -r1.1 -r1.2 src/tests/lib/libpthread/t_barrier.c (switch to unified diff)

--- src/tests/lib/libpthread/t_barrier.c 2010/07/16 15:42:53 1.1
+++ src/tests/lib/libpthread/t_barrier.c 2010/11/03 16:10:22 1.2
@@ -1,110 +1,110 @@ @@ -1,110 +1,110 @@
1/* $NetBSD: t_barrier.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ 1/* $NetBSD: t_barrier.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__COPYRIGHT("@(#) Copyright (c) 2008\ 30__COPYRIGHT("@(#) Copyright (c) 2008\
31 The NetBSD Foundation, inc. All rights reserved."); 31 The NetBSD Foundation, inc. All rights reserved.");
32__RCSID("$NetBSD: t_barrier.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); 32__RCSID("$NetBSD: t_barrier.c,v 1.2 2010/11/03 16:10:22 christos Exp $");
33 33
34#include <pthread.h> 34#include <pthread.h>
35#include <stdio.h> 35#include <stdio.h>
36#include <unistd.h> 36#include <unistd.h>
37 37
38#include <atf-c.h> 38#include <atf-c.h>
39 39
40#include "h_common.h" 40#include "h_common.h"
41 41
42#define COUNT 5 42#define COUNT 5
43 43
44pthread_barrier_t barrier; 44pthread_barrier_t barrier;
45pthread_mutex_t mutex; 45pthread_mutex_t mutex;
46int serial_count; 46int serial_count;
47int after_barrier_count; 47int after_barrier_count;
48 48
49static void * 49static void *
50threadfunc(void *arg) 50threadfunc(void *arg)
51{ 51{
52 int which = (int)(long)arg; 52 int which = (int)(long)arg;
53 int ret; 53 int rv;
54 54
55 printf("thread %d entering barrier\n", which); 55 printf("thread %d entering barrier\n", which);
56 ret = pthread_barrier_wait(&barrier); 56 rv = pthread_barrier_wait(&barrier);
57 printf("thread %d leaving barrier -> %d\n", which, ret); 57 printf("thread %d leaving barrier -> %d\n", which, rv);
58 58
59 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); 59 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
60 after_barrier_count++; 60 after_barrier_count++;
61 if (ret == PTHREAD_BARRIER_SERIAL_THREAD) 61 if (rv == PTHREAD_BARRIER_SERIAL_THREAD)
62 serial_count++; 62 serial_count++;
63 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); 63 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
64 64
65 return NULL; 65 return NULL;
66} 66}
67 67
68ATF_TC(barrier); 68ATF_TC(barrier);
69ATF_TC_HEAD(barrier, tc) 69ATF_TC_HEAD(barrier, tc)
70{ 70{
71 atf_tc_set_md_var(tc, "descr", "Checks barriers"); 71 atf_tc_set_md_var(tc, "descr", "Checks barriers");
72} 72}
73ATF_TC_BODY(barrier, tc) 73ATF_TC_BODY(barrier, tc)
74{ 74{
75 int i; 75 int i;
76 pthread_t new[COUNT]; 76 pthread_t new[COUNT];
77 void *joinval; 77 void *joinval;
78 78
79 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); 79 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
80 PTHREAD_REQUIRE(pthread_barrier_init(&barrier, NULL, COUNT)); 80 PTHREAD_REQUIRE(pthread_barrier_init(&barrier, NULL, COUNT));
81 81
82 for (i = 0; i < COUNT; i++) { 82 for (i = 0; i < COUNT; i++) {
83 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); 83 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
84 ATF_REQUIRE_EQ(after_barrier_count, 0); 84 ATF_REQUIRE_EQ(after_barrier_count, 0);
85 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); 85 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
86 PTHREAD_REQUIRE(pthread_create(&new[i], NULL, threadfunc, 86 PTHREAD_REQUIRE(pthread_create(&new[i], NULL, threadfunc,
87 (void *)(long)i)); 87 (void *)(long)i));
88 sleep(2); 88 sleep(2);
89 } 89 }
90 90
91 for (i = 0; i < COUNT; i++) { 91 for (i = 0; i < COUNT; i++) {
92 PTHREAD_REQUIRE(pthread_join(new[i], &joinval)); 92 PTHREAD_REQUIRE(pthread_join(new[i], &joinval));
93 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); 93 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
94 ATF_REQUIRE(after_barrier_count > i); 94 ATF_REQUIRE(after_barrier_count > i);
95 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); 95 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
96 printf("main joined with thread %d\n", i); 96 printf("main joined with thread %d\n", i);
97 } 97 }
98 98
99 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); 99 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
100 ATF_REQUIRE_EQ(after_barrier_count, COUNT); 100 ATF_REQUIRE_EQ(after_barrier_count, COUNT);
101 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); 101 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
102 ATF_REQUIRE_EQ(serial_count, 1); 102 ATF_REQUIRE_EQ(serial_count, 1);
103} 103}
104 104
105ATF_TP_ADD_TCS(tp) 105ATF_TP_ADD_TCS(tp)
106{ 106{
107 ATF_TP_ADD_TC(tp, barrier); 107 ATF_TP_ADD_TC(tp, barrier);
108 108
109 return atf_no_error(); 109 return atf_no_error();
110} 110}

cvs diff -r1.1 -r1.2 src/tests/lib/libpthread/t_cond.c (switch to unified diff)

--- src/tests/lib/libpthread/t_cond.c 2010/07/16 15:42:53 1.1
+++ src/tests/lib/libpthread/t_cond.c 2010/11/03 16:10:22 1.2
@@ -1,510 +1,510 @@ @@ -1,510 +1,510 @@
1/* $NetBSD: t_cond.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ 1/* $NetBSD: t_cond.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__COPYRIGHT("@(#) Copyright (c) 2008\ 30__COPYRIGHT("@(#) Copyright (c) 2008\
31 The NetBSD Foundation, inc. All rights reserved."); 31 The NetBSD Foundation, inc. All rights reserved.");
32__RCSID("$NetBSD: t_cond.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); 32__RCSID("$NetBSD: t_cond.c,v 1.2 2010/11/03 16:10:22 christos Exp $");
33 33
34#include <sys/time.h> 34#include <sys/time.h>
35 35
36#include <errno.h> 36#include <errno.h>
37#include <pthread.h> 37#include <pthread.h>
38#include <stdio.h> 38#include <stdio.h>
39#include <unistd.h> 39#include <unistd.h>
40 40
41#include <atf-c.h> 41#include <atf-c.h>
42 42
43#include "h_common.h" 43#include "h_common.h"
44 44
45static pthread_mutex_t mutex; 45static pthread_mutex_t mutex;
46static pthread_cond_t cond; 46static pthread_cond_t cond;
47static pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER; 47static pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER;
48static pthread_cond_t static_cond = PTHREAD_COND_INITIALIZER; 48static pthread_cond_t static_cond = PTHREAD_COND_INITIALIZER;
49static int count, share, toggle, total; 49static int count, share, toggle, total;
50 50
51static void * 51static void *
52signal_delay_wait_threadfunc(void *arg) 52signal_delay_wait_threadfunc(void *arg)
53{ 53{
54 int *share = (int *) arg; 54 int *shared = (int *) arg;
55 55
56 printf("2: Second thread.\n"); 56 printf("2: Second thread.\n");
57 57
58 printf("2: Locking mutex\n"); 58 printf("2: Locking mutex\n");
59 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); 59 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
60 printf("2: Got mutex.\n"); 60 printf("2: Got mutex.\n");
61 printf("Shared value: %d. Changing to 0.\n", *share); 61 printf("Shared value: %d. Changing to 0.\n", *shared);
62 *share = 0; 62 *shared = 0;
63 63
64 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); 64 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
65 PTHREAD_REQUIRE(pthread_cond_signal(&cond)); 65 PTHREAD_REQUIRE(pthread_cond_signal(&cond));
66 66
67 return NULL; 67 return NULL;
68} 68}
69 69
70ATF_TC(signal_delay_wait); 70ATF_TC(signal_delay_wait);
71ATF_TC_HEAD(signal_delay_wait, tc) 71ATF_TC_HEAD(signal_delay_wait, tc)
72{ 72{
73 atf_tc_set_md_var(tc, "descr", "Checks condition variables"); 73 atf_tc_set_md_var(tc, "descr", "Checks condition variables");
74} 74}
75ATF_TC_BODY(signal_delay_wait, tc) 75ATF_TC_BODY(signal_delay_wait, tc)
76{ 76{
77 int x; 77 int x;
78 pthread_t new; 78 pthread_t new;
79 void *joinval; 79 void *joinval;
80 int sharedval; 80 int sharedval;
81 81
82 printf("1: condition variable test 1\n"); 82 printf("1: condition variable test 1\n");
83 83
84 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); 84 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
85 PTHREAD_REQUIRE(pthread_cond_init(&cond, NULL)); 85 PTHREAD_REQUIRE(pthread_cond_init(&cond, NULL));
86 86
87 x = 20; 87 x = 20;
88 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); 88 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
89 89
90 sharedval = 1; 90 sharedval = 1;
91 91
92 PTHREAD_REQUIRE(pthread_create(&new, NULL, signal_delay_wait_threadfunc, 92 PTHREAD_REQUIRE(pthread_create(&new, NULL, signal_delay_wait_threadfunc,
93 &sharedval)); 93 &sharedval));
94 94
95 printf("1: Before waiting.\n"); 95 printf("1: Before waiting.\n");
96 do { 96 do {
97 sleep(2); 97 sleep(2);
98 PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex)); 98 PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex));
99 printf("1: After waiting, in loop.\n"); 99 printf("1: After waiting, in loop.\n");
100 } while (sharedval != 0); 100 } while (sharedval != 0);
101 101
102 printf("1: After the loop.\n"); 102 printf("1: After the loop.\n");
103 103
104 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); 104 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
105 105
106 printf("1: After releasing the mutex.\n"); 106 printf("1: After releasing the mutex.\n");
107 PTHREAD_REQUIRE(pthread_join(new, &joinval)); 107 PTHREAD_REQUIRE(pthread_join(new, &joinval));
108 108
109 printf("1: Thread joined.\n"); 109 printf("1: Thread joined.\n");
110} 110}
111 111
112static void * 112static void *
113signal_before_unlock_threadfunc(void *arg) 113signal_before_unlock_threadfunc(void *arg)
114{ 114{
115 int *share = (int *) arg; 115 int *shared = (int *) arg;
116 116
117 printf("2: Second thread.\n"); 117 printf("2: Second thread.\n");
118 118
119 printf("2: Locking mutex\n"); 119 printf("2: Locking mutex\n");
120 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); 120 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
121 printf("2: Got mutex.\n"); 121 printf("2: Got mutex.\n");
122 printf("Shared value: %d. Changing to 0.\n", *share); 122 printf("Shared value: %d. Changing to 0.\n", *shared);
123 *share = 0; 123 *shared = 0;
124 124
125 /* Signal first, then unlock, for a different test than #1. */ 125 /* Signal first, then unlock, for a different test than #1. */
126 PTHREAD_REQUIRE(pthread_cond_signal(&cond)); 126 PTHREAD_REQUIRE(pthread_cond_signal(&cond));
127 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); 127 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
128 128
129 return NULL; 129 return NULL;
130} 130}
131 131
132ATF_TC(signal_before_unlock); 132ATF_TC(signal_before_unlock);
133ATF_TC_HEAD(signal_before_unlock, tc) 133ATF_TC_HEAD(signal_before_unlock, tc)
134{ 134{
135 atf_tc_set_md_var(tc, "descr", 135 atf_tc_set_md_var(tc, "descr",
136 "Checks condition variables: signal before unlocking mutex"); 136 "Checks condition variables: signal before unlocking mutex");
137} 137}
138ATF_TC_BODY(signal_before_unlock, tc) 138ATF_TC_BODY(signal_before_unlock, tc)
139{ 139{
140 int x; 140 int x;
141 pthread_t new; 141 pthread_t new;
142 void *joinval; 142 void *joinval;
143 int sharedval; 143 int sharedval;
144 144
145 printf("1: condition variable test 2\n"); 145 printf("1: condition variable test 2\n");
146 146
147 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); 147 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
148 PTHREAD_REQUIRE(pthread_cond_init(&cond, NULL)); 148 PTHREAD_REQUIRE(pthread_cond_init(&cond, NULL));
149 149
150 x = 20; 150 x = 20;
151 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); 151 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
152 152
153 sharedval = 1; 153 sharedval = 1;
154 154
155 PTHREAD_REQUIRE(pthread_create(&new, NULL, 155 PTHREAD_REQUIRE(pthread_create(&new, NULL,
156 signal_before_unlock_threadfunc, &sharedval)); 156 signal_before_unlock_threadfunc, &sharedval));
157 157
158 printf("1: Before waiting.\n"); 158 printf("1: Before waiting.\n");
159 do { 159 do {
160 sleep(2); 160 sleep(2);
161 PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex)); 161 PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex));
162 printf("1: After waiting, in loop.\n"); 162 printf("1: After waiting, in loop.\n");
163 } while (sharedval != 0); 163 } while (sharedval != 0);
164 164
165 printf("1: After the loop.\n"); 165 printf("1: After the loop.\n");
166 166
167 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); 167 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
168 168
169 printf("1: After releasing the mutex.\n"); 169 printf("1: After releasing the mutex.\n");
170 PTHREAD_REQUIRE(pthread_join(new, &joinval)); 170 PTHREAD_REQUIRE(pthread_join(new, &joinval));
171 171
172 printf("1: Thread joined.\n"); 172 printf("1: Thread joined.\n");
173} 173}
174 174
175static void * 175static void *
176signal_before_unlock_static_init_threadfunc(void *arg) 176signal_before_unlock_static_init_threadfunc(void *arg)
177{ 177{
178 int *share = (int *) arg; 178 int *shared = (int *) arg;
179 179
180 printf("2: Second thread.\n"); 180 printf("2: Second thread.\n");
181 181
182 printf("2: Locking mutex\n"); 182 printf("2: Locking mutex\n");
183 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); 183 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
184 printf("2: Got mutex.\n"); 184 printf("2: Got mutex.\n");
185 printf("Shared value: %d. Changing to 0.\n", *share); 185 printf("Shared value: %d. Changing to 0.\n", *shared);
186 *share = 0; 186 *shared = 0;
187 187
188 /* Signal first, then unlock, for a different test than #1. */ 188 /* Signal first, then unlock, for a different test than #1. */
189 PTHREAD_REQUIRE(pthread_cond_signal(&static_cond)); 189 PTHREAD_REQUIRE(pthread_cond_signal(&static_cond));
190 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); 190 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
191 191
192 return NULL; 192 return NULL;
193} 193}
194 194
195ATF_TC(signal_before_unlock_static_init); 195ATF_TC(signal_before_unlock_static_init);
196ATF_TC_HEAD(signal_before_unlock_static_init, tc) 196ATF_TC_HEAD(signal_before_unlock_static_init, tc)
197{ 197{
198 atf_tc_set_md_var(tc, "descr", 198 atf_tc_set_md_var(tc, "descr",
199 "Checks condition variables: signal before unlocking " 199 "Checks condition variables: signal before unlocking "
200 "mutex, use static initializers"); 200 "mutex, use static initializers");
201} 201}
202ATF_TC_BODY(signal_before_unlock_static_init, tc) 202ATF_TC_BODY(signal_before_unlock_static_init, tc)
203{ 203{
204 int x; 204 int x;
205 pthread_t new; 205 pthread_t new;
206 void *joinval; 206 void *joinval;
207 int sharedval; 207 int sharedval;
208 208
209 printf("1: condition variable test 3\n"); 209 printf("1: condition variable test 3\n");
210 210
211 x = 20; 211 x = 20;
212 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); 212 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
213 213
214 sharedval = 1; 214 sharedval = 1;
215 215
216 PTHREAD_REQUIRE(pthread_create(&new, NULL, 216 PTHREAD_REQUIRE(pthread_create(&new, NULL,
217 signal_before_unlock_static_init_threadfunc, &sharedval)); 217 signal_before_unlock_static_init_threadfunc, &sharedval));
218 218
219 printf("1: Before waiting.\n"); 219 printf("1: Before waiting.\n");
220 do { 220 do {
221 sleep(2); 221 sleep(2);
222 PTHREAD_REQUIRE(pthread_cond_wait(&static_cond, &static_mutex)); 222 PTHREAD_REQUIRE(pthread_cond_wait(&static_cond, &static_mutex));
223 printf("1: After waiting, in loop.\n"); 223 printf("1: After waiting, in loop.\n");
224 } while (sharedval != 0); 224 } while (sharedval != 0);
225 225
226 printf("1: After the loop.\n"); 226 printf("1: After the loop.\n");
227 227
228 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); 228 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
229 229
230 printf("1: After releasing the mutex.\n"); 230 printf("1: After releasing the mutex.\n");
231 PTHREAD_REQUIRE(pthread_join(new, &joinval)); 231 PTHREAD_REQUIRE(pthread_join(new, &joinval));
232 232
233 printf("1: Thread joined.\n"); 233 printf("1: Thread joined.\n");
234} 234}
235 235
236static void * 236static void *
237signal_wait_race_threadfunc(void *arg) 237signal_wait_race_threadfunc(void *arg)
238{ 238{
239 printf("2: Second thread.\n"); 239 printf("2: Second thread.\n");
240 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); 240 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
241 printf("2: Before the loop.\n"); 241 printf("2: Before the loop.\n");
242 while (count>0) { 242 while (count>0) {
243 count--; 243 count--;
244 total++; 244 total++;
245 toggle = 0; 245 toggle = 0;
246 /* printf("2: Before signal %d.\n", count); */ 246 /* printf("2: Before signal %d.\n", count); */
247 PTHREAD_REQUIRE(pthread_cond_signal(&static_cond)); 247 PTHREAD_REQUIRE(pthread_cond_signal(&static_cond));
248 do { 248 do {
249 PTHREAD_REQUIRE(pthread_cond_wait(&static_cond, 249 PTHREAD_REQUIRE(pthread_cond_wait(&static_cond,
250 &static_mutex)); 250 &static_mutex));
251 } while (toggle != 1); 251 } while (toggle != 1);
252 } 252 }
253 printf("2: After the loop.\n"); 253 printf("2: After the loop.\n");
254 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); 254 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
255 255
256 return NULL; 256 return NULL;
257} 257}
258 258
259ATF_TC(signal_wait_race); 259ATF_TC(signal_wait_race);
260ATF_TC_HEAD(signal_wait_race, tc) 260ATF_TC_HEAD(signal_wait_race, tc)
261{ 261{
262 atf_tc_set_md_var(tc, "descr", "Checks condition variables"); 262 atf_tc_set_md_var(tc, "descr", "Checks condition variables");
263} 263}
264ATF_TC_BODY(signal_wait_race, tc) 264ATF_TC_BODY(signal_wait_race, tc)
265{ 265{
266 pthread_t new; 266 pthread_t new;
267 void *joinval; 267 void *joinval;
268 int sharedval; 268 int sharedval;
269 269
270 printf("1: condition variable test 4\n"); 270 printf("1: condition variable test 4\n");
271 271
272 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); 272 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
273 273
274 count = 50000; 274 count = 50000;
275 toggle = 0; 275 toggle = 0;
276 276
277 PTHREAD_REQUIRE(pthread_create(&new, NULL, signal_wait_race_threadfunc, 277 PTHREAD_REQUIRE(pthread_create(&new, NULL, signal_wait_race_threadfunc,
278 &sharedval)); 278 &sharedval));
279 279
280 printf("1: Before waiting.\n"); 280 printf("1: Before waiting.\n");
281 while (count>0) { 281 while (count>0) {
282 count--; 282 count--;
283 total++; 283 total++;
284 toggle = 1; 284 toggle = 1;
285 /* printf("1: Before signal %d.\n", count); */ 285 /* printf("1: Before signal %d.\n", count); */
286 PTHREAD_REQUIRE(pthread_cond_signal(&static_cond)); 286 PTHREAD_REQUIRE(pthread_cond_signal(&static_cond));
287 do { 287 do {
288 PTHREAD_REQUIRE(pthread_cond_wait(&static_cond, 288 PTHREAD_REQUIRE(pthread_cond_wait(&static_cond,
289 &static_mutex)); 289 &static_mutex));
290 } while (toggle != 0); 290 } while (toggle != 0);
291 } 291 }
292 printf("1: After the loop.\n"); 292 printf("1: After the loop.\n");
293 293
294 toggle = 1; 294 toggle = 1;
295 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); 295 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
296 PTHREAD_REQUIRE(pthread_cond_signal(&static_cond)); 296 PTHREAD_REQUIRE(pthread_cond_signal(&static_cond));
297 297
298 printf("1: After releasing the mutex.\n"); 298 printf("1: After releasing the mutex.\n");
299 PTHREAD_REQUIRE(pthread_join(new, &joinval)); 299 PTHREAD_REQUIRE(pthread_join(new, &joinval));
300 300
301 printf("1: Thread joined. Final count = %d, total = %d\n", 301 printf("1: Thread joined. Final count = %d, total = %d\n",
302 count, total); 302 count, total);
303 303
304 ATF_REQUIRE_EQ(count, 0); 304 ATF_REQUIRE_EQ(count, 0);
305 ATF_REQUIRE_EQ(total, 50000); 305 ATF_REQUIRE_EQ(total, 50000);
306} 306}
307 307
308static void * 308static void *
309broadcast_threadfunc(void *arg) 309broadcast_threadfunc(void *arg)
310{ 310{
311 printf("2: Second thread.\n"); 311 printf("2: Second thread.\n");
312 312
313 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); 313 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
314 while (count>0) { 314 while (count>0) {
315 count--; 315 count--;
316 total++; 316 total++;
317 toggle = 0; 317 toggle = 0;
318 PTHREAD_REQUIRE(pthread_cond_signal(&static_cond)); 318 PTHREAD_REQUIRE(pthread_cond_signal(&static_cond));
319 do { 319 do {
320 PTHREAD_REQUIRE(pthread_cond_wait(&static_cond, 320 PTHREAD_REQUIRE(pthread_cond_wait(&static_cond,
321 &static_mutex)); 321 &static_mutex));
322 } while (toggle != 1); 322 } while (toggle != 1);
323 } 323 }
324 printf("2: After the loop.\n"); 324 printf("2: After the loop.\n");
325 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); 325 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
326 326
327 return NULL; 327 return NULL;
328} 328}
329 329
330 330
331ATF_TC(broadcast); 331ATF_TC(broadcast);
332ATF_TC_HEAD(broadcast, tc) 332ATF_TC_HEAD(broadcast, tc)
333{ 333{
334 atf_tc_set_md_var(tc, "descr", 334 atf_tc_set_md_var(tc, "descr",
335 "Checks condition variables: use pthread_cond_broadcast()"); 335 "Checks condition variables: use pthread_cond_broadcast()");
336} 336}
337ATF_TC_BODY(broadcast, tc) 337ATF_TC_BODY(broadcast, tc)
338{ 338{
339 pthread_t new; 339 pthread_t new;
340 void *joinval; 340 void *joinval;
341 int sharedval; 341 int sharedval;
342 342
343 printf("1: condition variable test 5\n"); 343 printf("1: condition variable test 5\n");
344 344
345 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); 345 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
346 346
347 count = 50000; 347 count = 50000;
348 toggle = 0; 348 toggle = 0;
349 349
350 PTHREAD_REQUIRE(pthread_create(&new, NULL, broadcast_threadfunc, 350 PTHREAD_REQUIRE(pthread_create(&new, NULL, broadcast_threadfunc,
351 &sharedval)); 351 &sharedval));
352 352
353 printf("1: Before waiting.\n"); 353 printf("1: Before waiting.\n");
354 while (count>0) { 354 while (count>0) {
355 count--; 355 count--;
356 total++; 356 total++;
357 toggle = 1; 357 toggle = 1;
358 PTHREAD_REQUIRE(pthread_cond_broadcast(&static_cond)); 358 PTHREAD_REQUIRE(pthread_cond_broadcast(&static_cond));
359 do { 359 do {
360 PTHREAD_REQUIRE(pthread_cond_wait(&static_cond, 360 PTHREAD_REQUIRE(pthread_cond_wait(&static_cond,
361 &static_mutex)); 361 &static_mutex));
362 } while (toggle != 0); 362 } while (toggle != 0);
363 } 363 }
364 printf("1: After the loop.\n"); 364 printf("1: After the loop.\n");
365 365
366 toggle = 1; 366 toggle = 1;
367 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); 367 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
368 PTHREAD_REQUIRE(pthread_cond_signal(&static_cond)); 368 PTHREAD_REQUIRE(pthread_cond_signal(&static_cond));
369 369
370 printf("1: After releasing the mutex.\n"); 370 printf("1: After releasing the mutex.\n");
371 PTHREAD_REQUIRE(pthread_join(new, &joinval)); 371 PTHREAD_REQUIRE(pthread_join(new, &joinval));
372 372
373 printf("1: Thread joined. Final count = %d, total = %d\n", count, 373 printf("1: Thread joined. Final count = %d, total = %d\n", count,
374 total); 374 total);
375 375
376 ATF_REQUIRE_EQ(count, 0); 376 ATF_REQUIRE_EQ(count, 0);
377 ATF_REQUIRE_EQ(total, 50000); 377 ATF_REQUIRE_EQ(total, 50000);
378} 378}
379 379
380static void * 380static void *
381bogus_timedwaits_threadfunc(void *arg) 381bogus_timedwaits_threadfunc(void *arg)
382{ 382{
383 return NULL; 383 return NULL;
384} 384}
385 385
386ATF_TC(bogus_timedwaits); 386ATF_TC(bogus_timedwaits);
387ATF_TC_HEAD(bogus_timedwaits, tc) 387ATF_TC_HEAD(bogus_timedwaits, tc)
388{ 388{
389 atf_tc_set_md_var(tc, "descr", 389 atf_tc_set_md_var(tc, "descr",
390 "Checks condition variables: bogus timedwaits"); 390 "Checks condition variables: bogus timedwaits");
391} 391}
392ATF_TC_BODY(bogus_timedwaits, tc) 392ATF_TC_BODY(bogus_timedwaits, tc)
393{ 393{
394 pthread_t new; 394 pthread_t new;
395 struct timespec ts; 395 struct timespec ts;
396 struct timeval tv; 396 struct timeval tv;
397 397
398 printf("condition variable test 6: bogus timedwaits\n"); 398 printf("condition variable test 6: bogus timedwaits\n");
399 399
400 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); 400 PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
401 401
402 printf("unthreaded test (past)\n"); 402 printf("unthreaded test (past)\n");
403 gettimeofday(&tv, NULL); 403 gettimeofday(&tv, NULL);
404 tv.tv_sec -= 2; /* Place the time in the past */ 404 tv.tv_sec -= 2; /* Place the time in the past */
405 TIMEVAL_TO_TIMESPEC(&tv, &ts); 405 TIMEVAL_TO_TIMESPEC(&tv, &ts);
406 406
407 ATF_REQUIRE_EQ_MSG(pthread_cond_timedwait(&static_cond, &static_mutex, 407 ATF_REQUIRE_EQ_MSG(pthread_cond_timedwait(&static_cond, &static_mutex,
408 &ts), ETIMEDOUT, "pthread_cond_timedwait() (unthreaded) in the " 408 &ts), ETIMEDOUT, "pthread_cond_timedwait() (unthreaded) in the "
409 "past"); 409 "past");
410 410
411 printf("unthreaded test (zero time)\n"); 411 printf("unthreaded test (zero time)\n");
412 tv.tv_sec = 0; 412 tv.tv_sec = 0;
413 tv.tv_usec = 0; 413 tv.tv_usec = 0;
414 TIMEVAL_TO_TIMESPEC(&tv, &ts); 414 TIMEVAL_TO_TIMESPEC(&tv, &ts);
415 415
416 ATF_REQUIRE_EQ_MSG(pthread_cond_timedwait(&static_cond, &static_mutex, 416 ATF_REQUIRE_EQ_MSG(pthread_cond_timedwait(&static_cond, &static_mutex,
417 &ts), ETIMEDOUT, "pthread_cond_timedwait() (unthreaded) with zero " 417 &ts), ETIMEDOUT, "pthread_cond_timedwait() (unthreaded) with zero "
418 "time"); 418 "time");
419 419
420 PTHREAD_REQUIRE(pthread_create(&new, NULL, bogus_timedwaits_threadfunc, 420 PTHREAD_REQUIRE(pthread_create(&new, NULL, bogus_timedwaits_threadfunc,
421 NULL)); 421 NULL));
422 PTHREAD_REQUIRE(pthread_join(new, NULL)); 422 PTHREAD_REQUIRE(pthread_join(new, NULL));
423 423
424 printf("threaded test\n"); 424 printf("threaded test\n");
425 gettimeofday(&tv, NULL); 425 gettimeofday(&tv, NULL);
426 tv.tv_sec -= 2; /* Place the time in the past */ 426 tv.tv_sec -= 2; /* Place the time in the past */
427 TIMEVAL_TO_TIMESPEC(&tv, &ts); 427 TIMEVAL_TO_TIMESPEC(&tv, &ts);
428 428
429 ATF_REQUIRE_EQ_MSG(pthread_cond_timedwait(&static_cond, &static_mutex, 429 ATF_REQUIRE_EQ_MSG(pthread_cond_timedwait(&static_cond, &static_mutex,
430 &ts), ETIMEDOUT, "pthread_cond_timedwait() (threaded) in the past"); 430 &ts), ETIMEDOUT, "pthread_cond_timedwait() (threaded) in the past");
431 431
432 printf("threaded test (zero time)\n"); 432 printf("threaded test (zero time)\n");
433 tv.tv_sec = 0; 433 tv.tv_sec = 0;
434 tv.tv_usec = 0; 434 tv.tv_usec = 0;
435 TIMEVAL_TO_TIMESPEC(&tv, &ts); 435 TIMEVAL_TO_TIMESPEC(&tv, &ts);
436 436
437 ATF_REQUIRE_EQ_MSG(pthread_cond_timedwait(&static_cond, &static_mutex, 437 ATF_REQUIRE_EQ_MSG(pthread_cond_timedwait(&static_cond, &static_mutex,
438 &ts), ETIMEDOUT, "pthread_cond_timedwait() (threaded) with zero " 438 &ts), ETIMEDOUT, "pthread_cond_timedwait() (threaded) with zero "
439 "time"); 439 "time");
440 440
441 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); 441 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
442} 442}
443 443
444static void 444static void
445unlock(void *arg) 445unlock(void *arg)
446{ 446{
447 pthread_mutex_unlock((pthread_mutex_t *)arg); 447 pthread_mutex_unlock((pthread_mutex_t *)arg);
448} 448}
449 449
450static void * 450static void *
451destroy_after_cancel_threadfunc(void *arg) 451destroy_after_cancel_threadfunc(void *arg)
452{ 452{
453 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); 453 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
454 454
455 pthread_cleanup_push(unlock, &mutex); 455 pthread_cleanup_push(unlock, &mutex);
456 456
457 while (1) { 457 while (1) {
458 share = 1; 458 share = 1;
459 PTHREAD_REQUIRE(pthread_cond_broadcast(&cond)); 459 PTHREAD_REQUIRE(pthread_cond_broadcast(&cond));
460 PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex)); 460 PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex));
461 } 461 }
462 462
463 pthread_cleanup_pop(0); 463 pthread_cleanup_pop(0);
464 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); 464 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
465 465
466 return NULL; 466 return NULL;
467} 467}
468 468
469ATF_TC(destroy_after_cancel); 469ATF_TC(destroy_after_cancel);
470ATF_TC_HEAD(destroy_after_cancel, tc) 470ATF_TC_HEAD(destroy_after_cancel, tc)
471{ 471{
472 atf_tc_set_md_var(tc, "descr", "Checks destroying a condition variable " 472 atf_tc_set_md_var(tc, "descr", "Checks destroying a condition variable "
473 "after cancelling a wait"); 473 "after cancelling a wait");
474} 474}
475ATF_TC_BODY(destroy_after_cancel, tc) 475ATF_TC_BODY(destroy_after_cancel, tc)
476{ 476{
477 pthread_t thread; 477 pthread_t thread;
478 478
479 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); 479 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
480 PTHREAD_REQUIRE(pthread_cond_init(&cond, NULL)); 480 PTHREAD_REQUIRE(pthread_cond_init(&cond, NULL));
481 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); 481 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
482 PTHREAD_REQUIRE(pthread_create(&thread, NULL, 482 PTHREAD_REQUIRE(pthread_create(&thread, NULL,
483 destroy_after_cancel_threadfunc, NULL)); 483 destroy_after_cancel_threadfunc, NULL));
484 484
485 while (share == 0) { 485 while (share == 0) {
486 PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex)); 486 PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex));
487 } 487 }
488 488
489 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); 489 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
490 PTHREAD_REQUIRE(pthread_cancel(thread)); 490 PTHREAD_REQUIRE(pthread_cancel(thread));
491 491
492 PTHREAD_REQUIRE(pthread_join(thread, NULL)); 492 PTHREAD_REQUIRE(pthread_join(thread, NULL));
493 PTHREAD_REQUIRE(pthread_cond_destroy(&cond)); 493 PTHREAD_REQUIRE(pthread_cond_destroy(&cond));
494 494
495 PTHREAD_REQUIRE(pthread_mutex_destroy(&mutex)); 495 PTHREAD_REQUIRE(pthread_mutex_destroy(&mutex));
496} 496}
497 497
498ATF_TP_ADD_TCS(tp) 498ATF_TP_ADD_TCS(tp)
499{ 499{
500 500
501 ATF_TP_ADD_TC(tp, signal_delay_wait); 501 ATF_TP_ADD_TC(tp, signal_delay_wait);
502 ATF_TP_ADD_TC(tp, signal_before_unlock); 502 ATF_TP_ADD_TC(tp, signal_before_unlock);
503 ATF_TP_ADD_TC(tp, signal_before_unlock_static_init); 503 ATF_TP_ADD_TC(tp, signal_before_unlock_static_init);
504 ATF_TP_ADD_TC(tp, signal_wait_race); 504 ATF_TP_ADD_TC(tp, signal_wait_race);
505 ATF_TP_ADD_TC(tp, broadcast); 505 ATF_TP_ADD_TC(tp, broadcast);
506 ATF_TP_ADD_TC(tp, bogus_timedwaits); 506 ATF_TP_ADD_TC(tp, bogus_timedwaits);
507 ATF_TP_ADD_TC(tp, destroy_after_cancel); 507 ATF_TP_ADD_TC(tp, destroy_after_cancel);
508 508
509 return atf_no_error(); 509 return atf_no_error();
510} 510}

cvs diff -r1.1 -r1.2 src/tests/lib/libpthread/t_preempt.c (switch to unified diff)

--- src/tests/lib/libpthread/t_preempt.c 2010/07/16 15:42:53 1.1
+++ src/tests/lib/libpthread/t_preempt.c 2010/11/03 16:10:22 1.2
@@ -1,127 +1,128 @@ @@ -1,127 +1,128 @@
1/* $NetBSD: t_preempt.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ 1/* $NetBSD: t_preempt.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__COPYRIGHT("@(#) Copyright (c) 2008\ 30__COPYRIGHT("@(#) Copyright (c) 2008\
31 The NetBSD Foundation, inc. All rights reserved."); 31 The NetBSD Foundation, inc. All rights reserved.");
32__RCSID("$NetBSD: t_preempt.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); 32__RCSID("$NetBSD: t_preempt.c,v 1.2 2010/11/03 16:10:22 christos Exp $");
33 33
34#include <errno.h> 34#include <errno.h>
35#include <fcntl.h> 35#include <fcntl.h>
36#include <pthread.h> 36#include <pthread.h>
37#include <stdio.h> 37#include <stdio.h>
38#include <stdlib.h> 38#include <stdlib.h>
39#include <string.h> 39#include <string.h>
40#include <unistd.h> 40#include <unistd.h>
41 41
42#include <atf-c.h> 42#include <atf-c.h>
43 43
44#include "h_common.h" 44#include "h_common.h"
45 45
46pthread_mutex_t mutex; 46pthread_mutex_t mutex;
47pthread_cond_t cond; 47pthread_cond_t cond;
48int started; 48int started;
49 49
50#define HUGE_BUFFER 1<<20 50#define HUGE_BUFFER 1<<20
51#define NTHREADS 1 51#define NTHREADS 1
52 52
53static void * 53static void *
54threadfunc(void *arg) 54threadfunc(void *arg)
55{ 55{
56 printf("2: Second thread.\n"); 56 printf("2: Second thread.\n");
57 57
58 printf("2: Locking mutex\n"); 58 printf("2: Locking mutex\n");
59 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); 59 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
60 printf("2: Got mutex.\n"); 60 printf("2: Got mutex.\n");
61 started++; 61 started++;
62 62
63 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); 63 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
64 PTHREAD_REQUIRE(pthread_cond_signal(&cond)); 64 PTHREAD_REQUIRE(pthread_cond_signal(&cond));
65 sleep(1); 65 sleep(1);
66 66
67 return NULL; 67 return NULL;
68} 68}
69 69
70ATF_TC(preempt1); 70ATF_TC(preempt1);
71ATF_TC_HEAD(preempt1, tc) 71ATF_TC_HEAD(preempt1, tc)
72{ 72{
73 atf_tc_set_md_var(tc, "descr", 73 atf_tc_set_md_var(tc, "descr",
74 "Checks kernel preemption during a large uiomove"); 74 "Checks kernel preemption during a large uiomove");
75} 75}
76ATF_TC_BODY(preempt1, tc) 76ATF_TC_BODY(preempt1, tc)
77{ 77{
78 int ret, i; 78 int i;
 79 ssize_t rv;
79 pthread_t new; 80 pthread_t new;
80 void *joinval; 81 void *joinval;
81 82
82 char *mem; 83 char *mem;
83 int fd; 84 int fd;
84 85
85 mem = malloc(HUGE_BUFFER); 86 mem = malloc(HUGE_BUFFER);
86 ATF_REQUIRE_MSG(mem != NULL, "%s", strerror(errno)); 87 ATF_REQUIRE_MSG(mem != NULL, "%s", strerror(errno));
87 88
88 fd = open("/dev/urandom", O_RDONLY, 0); 89 fd = open("/dev/urandom", O_RDONLY, 0);
89 ATF_REQUIRE_MSG(fd != -1, "%s", strerror(errno)); 90 ATF_REQUIRE_MSG(fd != -1, "%s", strerror(errno));
90 91
91 printf("1: preempt test\n"); 92 printf("1: preempt test\n");
92 93
93 PTHREAD_REQUIRE(pthread_cond_init(&cond, NULL)); 94 PTHREAD_REQUIRE(pthread_cond_init(&cond, NULL));
94 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); 95 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
95 96
96 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); 97 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
97 98
98 started = 0; 99 started = 0;
99 100
100 for (i = 0; i < NTHREADS; i++) { 101 for (i = 0; i < NTHREADS; i++) {
101 PTHREAD_REQUIRE(pthread_create(&new, NULL, threadfunc, NULL)); 102 PTHREAD_REQUIRE(pthread_create(&new, NULL, threadfunc, NULL));
102 } 103 }
103 104
104 while (started < NTHREADS) { 105 while (started < NTHREADS) {
105 PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex)); 106 PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex));
106 } 107 }
107 108
108 printf("1: Thread has started.\n"); 109 printf("1: Thread has started.\n");
109 110
110 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); 111 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
111 printf("1: After releasing the mutex.\n"); 112 printf("1: After releasing the mutex.\n");
112 113
113 ret = read(fd, mem, HUGE_BUFFER); 114 rv = read(fd, mem, HUGE_BUFFER);
114 close(fd); 115 close(fd);
115 ATF_REQUIRE_EQ(ret, HUGE_BUFFER); 116 ATF_REQUIRE_EQ(rv, HUGE_BUFFER);
116 117
117 PTHREAD_REQUIRE(pthread_join(new, &joinval)); 118 PTHREAD_REQUIRE(pthread_join(new, &joinval));
118 119
119 printf("1: Thread joined.\n"); 120 printf("1: Thread joined.\n");
120} 121}
121 122
122ATF_TP_ADD_TCS(tp) 123ATF_TP_ADD_TCS(tp)
123{ 124{
124 ATF_TP_ADD_TC(tp, preempt1); 125 ATF_TP_ADD_TC(tp, preempt1);
125 126
126 return atf_no_error(); 127 return atf_no_error();
127} 128}

cvs diff -r1.1 -r1.2 src/tests/lib/libpthread/t_sigmask.c (switch to unified diff)

--- src/tests/lib/libpthread/t_sigmask.c 2010/07/16 15:42:53 1.1
+++ src/tests/lib/libpthread/t_sigmask.c 2010/11/03 16:10:22 1.2
@@ -1,263 +1,263 @@ @@ -1,263 +1,263 @@
1/* $NetBSD: t_sigmask.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ 1/* $NetBSD: t_sigmask.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__COPYRIGHT("@(#) Copyright (c) 2008, 2010\ 30__COPYRIGHT("@(#) Copyright (c) 2008, 2010\
31 The NetBSD Foundation, inc. All rights reserved."); 31 The NetBSD Foundation, inc. All rights reserved.");
32__RCSID("$NetBSD: t_sigmask.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); 32__RCSID("$NetBSD: t_sigmask.c,v 1.2 2010/11/03 16:10:22 christos Exp $");
33 33
34/* 34/*
35 * Regression test for pthread_sigmask when SA upcalls aren't started yet. 35 * Regression test for pthread_sigmask when SA upcalls aren't started yet.
36 * 36 *
37 * Written by Christian Limpach <cl@NetBSD.org>, December 2003. 37 * Written by Christian Limpach <cl@NetBSD.org>, December 2003.
38 * Public domain. 38 * Public domain.
39 */ 39 */
40 40
41#include <errno.h> 41#include <errno.h>
42#include <pthread.h> 42#include <pthread.h>
43#include <signal.h> 43#include <signal.h>
44#include <stdio.h> 44#include <stdio.h>
45#include <unistd.h> 45#include <unistd.h>
46 46
47#include <sys/resource.h> 47#include <sys/resource.h>
48 48
49#include <atf-c.h> 49#include <atf-c.h>
50 50
51#include "h_common.h" 51#include "h_common.h"
52 52
53static volatile sig_atomic_t flag; 53static volatile sig_atomic_t flag;
54static volatile sig_atomic_t flag2; 54static volatile sig_atomic_t flag2;
55 55
56static volatile pthread_t thr_usr1; 56static volatile pthread_t thr_usr1;
57static volatile pthread_t thr_usr2; 57static volatile pthread_t thr_usr2;
58 58
59static sig_atomic_t count = 0; 59static sig_atomic_t count = 0;
60 60
61ATF_TC(upcalls_not_started); 61ATF_TC(upcalls_not_started);
62ATF_TC_HEAD(upcalls_not_started, tc) 62ATF_TC_HEAD(upcalls_not_started, tc)
63{ 63{
64 atf_tc_set_md_var(tc, "descr", "Checks pthread_sigmask when SA upcalls " 64 atf_tc_set_md_var(tc, "descr", "Checks pthread_sigmask when SA upcalls "
65 "aren't started yet"); 65 "aren't started yet");
66} 66}
67ATF_TC_BODY(upcalls_not_started, tc) 67ATF_TC_BODY(upcalls_not_started, tc)
68{ 68{
69 sigset_t nset; 69 sigset_t nset;
70 struct rlimit rlim; 70 struct rlimit rlim;
71 71
72 rlim.rlim_cur = rlim.rlim_max = 0; 72 rlim.rlim_cur = rlim.rlim_max = 0;
73 (void) setrlimit(RLIMIT_CORE, &rlim); 73 (void) setrlimit(RLIMIT_CORE, &rlim);
74 74
75 sigemptyset(&nset); 75 sigemptyset(&nset);
76 sigaddset(&nset, SIGFPE); 76 sigaddset(&nset, SIGFPE);
77 pthread_sigmask(SIG_BLOCK, &nset, NULL); 77 pthread_sigmask(SIG_BLOCK, &nset, NULL);
78 78
79 kill(getpid(), SIGFPE); 79 kill(getpid(), SIGFPE);
80} 80}
81 81
82static void 82static void
83upcalls_not_started_handler1(int sig, siginfo_t *info, void *ctx) 83upcalls_not_started_handler1(int sig, siginfo_t *info, void *ctx)
84{ 84{
85 85
86 kill(getpid(), SIGUSR2); 86 kill(getpid(), SIGUSR2);
87 /* 87 /*
88 * If the mask is properly set, SIGUSR2 will not be handled 88 * If the mask is properly set, SIGUSR2 will not be handled
89 * until this handler returns. 89 * until this handler returns.
90 */ 90 */
91 flag = 1; 91 flag = 1;
92} 92}
93 93
94static void 94static void
95upcalls_not_started_handler2(int sig, siginfo_t *info, void *ctx) 95upcalls_not_started_handler2(int sig, siginfo_t *info, void *ctx)
96{ 96{
97 if (flag == 1) 97 if (flag == 1)
98 flag = 2; 98 flag = 2;
99} 99}
100 100
101ATF_TC(before_threads); 101ATF_TC(before_threads);
102ATF_TC_HEAD(before_threads, tc) 102ATF_TC_HEAD(before_threads, tc)
103{ 103{
104 atf_tc_set_md_var(tc, "descr", "Checks that signal masks are respected " 104 atf_tc_set_md_var(tc, "descr", "Checks that signal masks are respected "
105 "before threads are started"); 105 "before threads are started");
106} 106}
107ATF_TC_BODY(before_threads, tc) 107ATF_TC_BODY(before_threads, tc)
108{ 108{
109 struct sigaction act; 109 struct sigaction act;
110 int ret; 110 int ret;
111 111
112 act.sa_sigaction = upcalls_not_started_handler1; 112 act.sa_sigaction = upcalls_not_started_handler1;
113 sigemptyset(&act.sa_mask); 113 sigemptyset(&act.sa_mask);
114 sigaddset(&act.sa_mask, SIGUSR2); 114 sigaddset(&act.sa_mask, SIGUSR2);
115 act.sa_flags = SA_SIGINFO; 115 act.sa_flags = SA_SIGINFO;
116 116
117 ATF_REQUIRE_EQ(sigaction(SIGUSR1, &act, NULL), 0); 117 ATF_REQUIRE_EQ(sigaction(SIGUSR1, &act, NULL), 0);
118 118
119 act.sa_sigaction = upcalls_not_started_handler2; 119 act.sa_sigaction = upcalls_not_started_handler2;
120 sigemptyset(&act.sa_mask); 120 sigemptyset(&act.sa_mask);
121 act.sa_flags = SA_SIGINFO; 121 act.sa_flags = SA_SIGINFO;
122 ret = sigaction(SIGUSR2, &act, NULL); 122 ret = sigaction(SIGUSR2, &act, NULL);
123 123
124 kill(getpid(), SIGUSR1); 124 kill(getpid(), SIGUSR1);
125 125
126 ATF_REQUIRE_EQ(flag, 2); 126 ATF_REQUIRE_EQ(flag, 2);
127 printf("Success: Both handlers ran in order\n"); 127 printf("Success: Both handlers ran in order\n");
128} 128}
129 129
130static void 130static void
131respected_while_running_handler1(int sig, siginfo_t *info, void *ctx) 131respected_while_running_handler1(int sig, siginfo_t *info, void *ctx)
132{ 132{
133 133
134 kill(getpid(), SIGUSR2); 134 kill(getpid(), SIGUSR2);
135 /* 135 /*
136 * If the mask is properly set, SIGUSR2 will not be handled 136 * If the mask is properly set, SIGUSR2 will not be handled
137 * by the current thread until this handler returns. 137 * by the current thread until this handler returns.
138 */ 138 */
139 flag = 1; 139 flag = 1;
140 thr_usr1 = pthread_self(); 140 thr_usr1 = pthread_self();
141} 141}
142 142
143static void 143static void
144respected_while_running_handler2(int sig, siginfo_t *info, void *ctx) 144respected_while_running_handler2(int sig, siginfo_t *info, void *ctx)
145{ 145{
146 if (flag == 1) 146 if (flag == 1)
147 flag = 2; 147 flag = 2;
148 flag2 = 1; 148 flag2 = 1;
149 thr_usr2 = pthread_self(); 149 thr_usr2 = pthread_self();
150} 150}
151 151
152static void * 152static void *
153respected_while_running_threadroutine(void *arg) 153respected_while_running_threadroutine(void *arg)
154{ 154{
155 155
156 kill(getpid(), SIGUSR1); 156 kill(getpid(), SIGUSR1);
157 sleep(1); 157 sleep(1);
158 158
159 if (flag == 2) 159 if (flag == 2)
160 printf("Success: Both handlers ran in order\n"); 160 printf("Success: Both handlers ran in order\n");
161 else if (flag == 1 && flag2 == 1 && thr_usr1 != thr_usr2) 161 else if (flag == 1 && flag2 == 1 && thr_usr1 != thr_usr2)
162 printf("Success: Handlers were invoked by different threads\n"); 162 printf("Success: Handlers were invoked by different threads\n");
163 else { 163 else {
164 printf("Failure: flag=%d, flag2=%d, thr1=%p, thr2=%p\n", 164 printf("Failure: flag=%d, flag2=%d, thr1=%p, thr2=%p\n",
165 (int)flag, (int)flag2, (void *)thr_usr1, (void *)thr_usr2); 165 (int)flag, (int)flag2, (void *)thr_usr1, (void *)thr_usr2);
166 atf_tc_fail("failure"); 166 atf_tc_fail("failure");
167 } 167 }
168 168
169 return NULL; 169 return NULL;
170} 170}
171 171
172ATF_TC(respected_while_running); 172ATF_TC(respected_while_running);
173ATF_TC_HEAD(respected_while_running, tc) 173ATF_TC_HEAD(respected_while_running, tc)
174{ 174{
175 atf_tc_set_md_var(tc, "descr", "Checks that signal masks are respected " 175 atf_tc_set_md_var(tc, "descr", "Checks that signal masks are respected "
176 "while threads are running"); 176 "while threads are running");
177} 177}
178ATF_TC_BODY(respected_while_running, tc) 178ATF_TC_BODY(respected_while_running, tc)
179{ 179{
180 struct sigaction act; 180 struct sigaction act;
181 pthread_t thread; 181 pthread_t thread;
182 int ret; 182 int rv;
183 183
184 act.sa_sigaction = respected_while_running_handler1; 184 act.sa_sigaction = respected_while_running_handler1;
185 sigemptyset(&act.sa_mask); 185 sigemptyset(&act.sa_mask);
186 sigaddset(&act.sa_mask, SIGUSR2); 186 sigaddset(&act.sa_mask, SIGUSR2);
187 act.sa_flags = SA_SIGINFO; 187 act.sa_flags = SA_SIGINFO;
188 188
189 ATF_REQUIRE_EQ(sigaction(SIGUSR1, &act, NULL), 0); 189 ATF_REQUIRE_EQ(sigaction(SIGUSR1, &act, NULL), 0);
190 190
191 act.sa_sigaction = respected_while_running_handler2; 191 act.sa_sigaction = respected_while_running_handler2;
192 sigemptyset(&act.sa_mask); 192 sigemptyset(&act.sa_mask);
193 act.sa_flags = SA_SIGINFO; 193 act.sa_flags = SA_SIGINFO;
194 ret = sigaction(SIGUSR2, &act, NULL); 194 rv = sigaction(SIGUSR2, &act, NULL);
195 195
196 PTHREAD_REQUIRE(pthread_create(&thread, NULL, 196 PTHREAD_REQUIRE(pthread_create(&thread, NULL,
197 respected_while_running_threadroutine, NULL)); 197 respected_while_running_threadroutine, NULL));
198 PTHREAD_REQUIRE(pthread_join(thread, NULL)); 198 PTHREAD_REQUIRE(pthread_join(thread, NULL));
199} 199}
200 200
201static void 201static void
202incorrect_mask_bug_handler(int sig) 202incorrect_mask_bug_handler(int sig)
203{ 203{
204 count++; 204 count++;
205} 205}
206 206
207static void * 207static void *
208incorrect_mask_bug_sleeper(void* arg) 208incorrect_mask_bug_sleeper(void* arg)
209{ 209{
210 int i; 210 int i;
211 for (i = 0; i < 10; i++) 211 for (i = 0; i < 10; i++)
212 sleep(1); 212 sleep(1);
213 213
214 atf_tc_fail("sleeper"); 214 atf_tc_fail("sleeper");
215} 215}
216 216
217ATF_TC(incorrect_mask_bug); 217ATF_TC(incorrect_mask_bug);
218ATF_TC_HEAD(incorrect_mask_bug, tc) 218ATF_TC_HEAD(incorrect_mask_bug, tc)
219{ 219{
220 atf_tc_set_md_var(tc, "descr", "Checks for bug in libpthread where " 220 atf_tc_set_md_var(tc, "descr", "Checks for bug in libpthread where "
221 "incorrect signal mask was used"); 221 "incorrect signal mask was used");
222} 222}
223ATF_TC_BODY(incorrect_mask_bug, tc) 223ATF_TC_BODY(incorrect_mask_bug, tc)
224{ 224{
225 pthread_t id; 225 pthread_t id;
226 struct sigaction act; 226 struct sigaction act;
227 227
228 act.sa_sigaction = NULL; 228 act.sa_sigaction = NULL;
229 sigemptyset(&act.sa_mask); 229 sigemptyset(&act.sa_mask);
230 act.sa_flags = 0; 230 act.sa_flags = 0;
231 act.sa_handler = incorrect_mask_bug_handler; 231 act.sa_handler = incorrect_mask_bug_handler;
232 232
233 ATF_REQUIRE_EQ_MSG(sigaction(SIGALRM, &act, NULL), 0, "%s", 233 ATF_REQUIRE_EQ_MSG(sigaction(SIGALRM, &act, NULL), 0, "%s",
234 strerror(errno)); 234 strerror(errno));
235 235
236 sigaddset(&act.sa_mask, SIGALRM); 236 sigaddset(&act.sa_mask, SIGALRM);
237 PTHREAD_REQUIRE(pthread_sigmask(SIG_SETMASK, &act.sa_mask, NULL)); 237 PTHREAD_REQUIRE(pthread_sigmask(SIG_SETMASK, &act.sa_mask, NULL));
238 238
239 PTHREAD_REQUIRE(pthread_create(&id, NULL, incorrect_mask_bug_sleeper, 239 PTHREAD_REQUIRE(pthread_create(&id, NULL, incorrect_mask_bug_sleeper,
240 NULL)); 240 NULL));
241 sleep(1); 241 sleep(1);
242 242
243 sigemptyset(&act.sa_mask); 243 sigemptyset(&act.sa_mask);
244 PTHREAD_REQUIRE(pthread_sigmask(SIG_SETMASK, &act.sa_mask, NULL)); 244 PTHREAD_REQUIRE(pthread_sigmask(SIG_SETMASK, &act.sa_mask, NULL));
245 245
246 for (;;) { 246 for (;;) {
247 alarm(1); 247 alarm(1);
248 if (select(1, NULL, NULL, NULL, NULL) == -1 && errno == EINTR) 248 if (select(1, NULL, NULL, NULL, NULL) == -1 && errno == EINTR)
249 if (count == 2) 249 if (count == 2)
250 return; 250 return;
251 } 251 }
252} 252}
253 253
254ATF_TP_ADD_TCS(tp) 254ATF_TP_ADD_TCS(tp)
255{ 255{
256 256
257 ATF_TP_ADD_TC(tp, upcalls_not_started); 257 ATF_TP_ADD_TC(tp, upcalls_not_started);
258 ATF_TP_ADD_TC(tp, before_threads); 258 ATF_TP_ADD_TC(tp, before_threads);
259 ATF_TP_ADD_TC(tp, respected_while_running); 259 ATF_TP_ADD_TC(tp, respected_while_running);
260 ATF_TP_ADD_TC(tp, incorrect_mask_bug); 260 ATF_TP_ADD_TC(tp, incorrect_mask_bug);
261 261
262 return atf_no_error(); 262 return atf_no_error();
263} 263}

cvs diff -r1.1 -r1.2 src/tests/lib/libpthread/Attic/t_status.c (switch to unified diff)

--- src/tests/lib/libpthread/Attic/t_status.c 2010/07/16 15:42:53 1.1
+++ src/tests/lib/libpthread/Attic/t_status.c 2010/11/03 16:10:22 1.2
@@ -1,124 +1,124 @@ @@ -1,124 +1,124 @@
1/* $NetBSD: t_status.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ 1/* $NetBSD: t_status.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__COPYRIGHT("@(#) Copyright (c) 2010\ 30__COPYRIGHT("@(#) Copyright (c) 2010\
31 The NetBSD Foundation, inc. All rights reserved."); 31 The NetBSD Foundation, inc. All rights reserved.");
32__RCSID("$NetBSD: t_status.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); 32__RCSID("$NetBSD: t_status.c,v 1.2 2010/11/03 16:10:22 christos Exp $");
33 33
34#include <sys/resource.h> 34#include <sys/resource.h>
35#include <sys/wait.h> 35#include <sys/wait.h>
36 36
37#include <err.h> 37#include <err.h>
38#include <pthread.h> 38#include <pthread.h>
39#include <stdio.h> 39#include <stdio.h>
40#include <stdlib.h> 40#include <stdlib.h>
41#include <string.h> 41#include <string.h>
42#include <unistd.h> 42#include <unistd.h>
43 43
44#include <atf-c.h> 44#include <atf-c.h>
45 45
46#define NUM 100 46#define NUM 100
47 47
48static void * 48static void *
49threadfunc(void *arg) 49threadfunc(void *arg)
50{ 50{
51 51
52 sleep(1000); 52 sleep(1000);
53 return 0; 53 return 0;
54} 54}
55 55
56int 56static int
57child(const int seed) 57child(const int seed)
58{ 58{
59 pthread_t thr[NUM]; 59 pthread_t thr[NUM];
60 int i, j, res, errors; 60 int i, j, res, errors;
61 char nam[20]; 61 char nam[20];
62 struct rlimit sl; 62 struct rlimit sl;
63 63
64 srandom(seed); 64 srandom(seed);
65 getrlimit(RLIMIT_STACK, &sl); 65 getrlimit(RLIMIT_STACK, &sl);
66 66
67 errors = 0; 67 errors = 0;
68 for (i = 0; i < NUM; i++) { 68 for (i = 0; i < NUM; i++) {
69 res = pthread_create(&thr[i], 0, threadfunc, 0); 69 res = pthread_create(&thr[i], 0, threadfunc, 0);
70 if (res) 70 if (res)
71 errx(1, "pthread_create iter %d: %s", i, strerror(res)); 71 errx(1, "pthread_create iter %d: %s", i, strerror(res));
72 for (j = 0; j <= i; j++) { 72 for (j = 0; j <= i; j++) {
73 res = pthread_getname_np(thr[j], nam, sizeof(nam)); 73 res = pthread_getname_np(thr[j], nam, sizeof(nam));
74 if (res) { 74 if (res) {
75 warnx("getname(%d/%d): %s\n", i, j, 75 warnx("getname(%d/%d): %s\n", i, j,
76 strerror(res)); 76 strerror(res));
77 errors++; 77 errors++;
78 } 78 }
79 } 79 }
80 if (errors) 80 if (errors)
81 break; 81 break;
82 malloc((random() & 7) * sl.rlim_cur); 82 malloc((random() & 7) * sl.rlim_cur);
83 } 83 }
84 if (errors) 84 if (errors)
85 printf("%d errors; seed was %d\n", errors, seed); 85 printf("%d errors; seed was %d\n", errors, seed);
86 return errors > 0 ? EXIT_FAILURE : EXIT_SUCCESS; 86 return errors > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
87} 87}
88 88
89void 89static void
90do_test(const int seed) 90do_test(const int seed)
91{ 91{
92 pid_t pid = fork(); 92 pid_t pid = fork();
93 ATF_REQUIRE(pid != -1); 93 ATF_REQUIRE(pid != -1);
94 if (pid == 0) { 94 if (pid == 0) {
95 exit(child(seed)); 95 exit(child(seed));
96 } else { 96 } else {
97 int status; 97 int status;
98 ATF_CHECK_EQ(pid, waitpid(pid, &status, 0)); 98 ATF_CHECK_EQ(pid, waitpid(pid, &status, 0));
99 if (!(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS)) 99 if (!(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS))
100 atf_tc_fail_nonfatal("Check with seed %d failed", seed); 100 atf_tc_fail_nonfatal("Check with seed %d failed", seed);
101 } 101 }
102} 102}
103 103
104ATF_TC(findthreads); 104ATF_TC(findthreads);
105ATF_TC_HEAD(findthreads, tc) 105ATF_TC_HEAD(findthreads, tc)
106{ 106{
107 atf_tc_set_md_var(tc, "descr", "Tests libpthread's ability to remember " 107 atf_tc_set_md_var(tc, "descr", "Tests libpthread's ability to remember "
108 "the tests it has created"); 108 "the tests it has created");
109} 109}
110ATF_TC_BODY(findthreads, tc) 110ATF_TC_BODY(findthreads, tc)
111{ 111{
112 int i; 112 int i;
113 113
114 for (i = 0; i < 100; i++) 114 for (i = 0; i < 100; i++)
115 do_test(i); 115 do_test(i);
116} 116}
117 117
118ATF_TP_ADD_TCS(tp) 118ATF_TP_ADD_TCS(tp)
119{ 119{
120 120
121 ATF_TP_ADD_TC(tp, findthreads); 121 ATF_TP_ADD_TC(tp, findthreads);
122 122
123 return atf_no_error(); 123 return atf_no_error();
124} 124}

cvs diff -r1.4 -r1.5 src/tests/lib/libpthread/t_sem.c (switch to unified diff)

--- src/tests/lib/libpthread/t_sem.c 2010/07/21 17:23:08 1.4
+++ src/tests/lib/libpthread/t_sem.c 2010/11/03 16:10:22 1.5
@@ -1,311 +1,311 @@ @@ -1,311 +1,311 @@
1/* $NetBSD: t_sem.c,v 1.4 2010/07/21 17:23:08 jmmv Exp $ */ 1/* $NetBSD: t_sem.c,v 1.5 2010/11/03 16:10:22 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29/*- 29/*-
30 * Copyright (c)2004 YAMAMOTO Takashi, 30 * Copyright (c)2004 YAMAMOTO Takashi,
31 * All rights reserved. 31 * All rights reserved.
32 * 32 *
33 * Redistribution and use in source and binary forms, with or without 33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions 34 * modification, are permitted provided that the following conditions
35 * are met: 35 * are met:
36 * 1. Redistributions of source code must retain the above copyright 36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer. 37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright 38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the 39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution. 40 * documentation and/or other materials provided with the distribution.
41 * 41 *
42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * SUCH DAMAGE. 52 * SUCH DAMAGE.
53 */ 53 */
54 54
55/**************************************************************************** 55/****************************************************************************
56 * 56 *
57 * Copyright (C) 2000 Jason Evans <jasone@freebsd.org>. 57 * Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
58 * All rights reserved. 58 * All rights reserved.
59 * 59 *
60 * Redistribution and use in source and binary forms, with or without 60 * Redistribution and use in source and binary forms, with or without
61 * modification, are permitted provided that the following conditions 61 * modification, are permitted provided that the following conditions
62 * are met: 62 * are met:
63 * 1. Redistributions of source code must retain the above copyright 63 * 1. Redistributions of source code must retain the above copyright
64 * notice(s), this list of conditions and the following disclaimer as 64 * notice(s), this list of conditions and the following disclaimer as
65 * the first lines of this file unmodified other than the possible 65 * the first lines of this file unmodified other than the possible
66 * addition of one or more copyright notices. 66 * addition of one or more copyright notices.
67 * 2. Redistributions in binary form must reproduce the above copyright 67 * 2. Redistributions in binary form must reproduce the above copyright
68 * notice(s), this list of conditions and the following disclaimer in 68 * notice(s), this list of conditions and the following disclaimer in
69 * the documentation and/or other materials provided with the 69 * the documentation and/or other materials provided with the
70 * distribution. 70 * distribution.
71 * 71 *
72 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 72 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
73 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 73 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
74 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 74 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
75 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE 75 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
76 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 76 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
77 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 77 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
78 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 78 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
79 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 79 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
80 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 80 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
81 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 81 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
82 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 82 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83 * 83 *
84 ****************************************************************************/ 84 ****************************************************************************/
85 85
86#include <sys/cdefs.h> 86#include <sys/cdefs.h>
87__COPYRIGHT("@(#) Copyright (c) 2008, 2010\ 87__COPYRIGHT("@(#) Copyright (c) 2008, 2010\
88 The NetBSD Foundation, inc. All rights reserved."); 88 The NetBSD Foundation, inc. All rights reserved.");
89__RCSID("$NetBSD: t_sem.c,v 1.4 2010/07/21 17:23:08 jmmv Exp $"); 89__RCSID("$NetBSD: t_sem.c,v 1.5 2010/11/03 16:10:22 christos Exp $");
90 90
91#include <errno.h> 91#include <errno.h>
92#include <fcntl.h> 92#include <fcntl.h>
93#include <pthread.h> 93#include <pthread.h>
94#include <semaphore.h> 94#include <semaphore.h>
95#include <signal.h> 95#include <signal.h>
96#include <stdio.h> 96#include <stdio.h>
97#include <stdlib.h> 97#include <stdlib.h>
98#include <string.h> 98#include <string.h>
99#include <unistd.h> 99#include <unistd.h>
100 100
101#include <atf-c.h> 101#include <atf-c.h>
102#include <atf-c/config.h> 102#include <atf-c/config.h>
103 103
104#include "h_common.h" 104#include "h_common.h"
105 105
106#define NTHREADS 10 106#define NTHREADS 10
107 107
108#define _LIBC_R_ 108#define _LIBC_R_
109 109
110#define SEM_REQUIRE(x) \ 110#define SEM_REQUIRE(x) \
111 ATF_REQUIRE_EQ_MSG(x, 0, "%s", strerror(errno)) 111 ATF_REQUIRE_EQ_MSG(x, 0, "%s", strerror(errno))
112 112
113static sem_t sem; 113static sem_t sem;
114 114
115ATF_TC(named); 115ATF_TC(named);
116ATF_TC_HEAD(named, tc) 116ATF_TC_HEAD(named, tc)
117{ 117{
118 atf_tc_set_md_var(tc, "descr", "Checks named semaphores"); 118 atf_tc_set_md_var(tc, "descr", "Checks named semaphores");
119} 119}
120ATF_TC_BODY(named, tc) 120ATF_TC_BODY(named, tc)
121{ 121{
122 sem_t *sem; 122 sem_t *semp;
123 123
124 ATF_REQUIRE_MSG(-1 != sysconf(_SC_SEMAPHORES), "%s", strerror(errno)); 124 ATF_REQUIRE_MSG(-1 != sysconf(_SC_SEMAPHORES), "%s", strerror(errno));
125 125
126 printf("Test begin\n"); 126 printf("Test begin\n");
127 127
128 (void) sem_unlink("/foo"); 128 (void) sem_unlink("/foo");
129 sem = sem_open("/foo", O_CREAT | O_EXCL, 0644, 0); 129 semp = sem_open("/foo", O_CREAT | O_EXCL, 0644, 0);
130 ATF_REQUIRE_MSG(sem != SEM_FAILED, "%s", strerror(errno)); 130 ATF_REQUIRE_MSG(semp != SEM_FAILED, "%s", strerror(errno));
131 SEM_REQUIRE(sem_close(sem)); 131 SEM_REQUIRE(sem_close(semp));
132 SEM_REQUIRE(sem_unlink("/foo")); 132 SEM_REQUIRE(sem_unlink("/foo"));
133 133
134 printf("Test end\n"); 134 printf("Test end\n");
135} 135}
136 136
137ATF_TC(unnamed); 137ATF_TC(unnamed);
138ATF_TC_HEAD(unnamed, tc) 138ATF_TC_HEAD(unnamed, tc)
139{ 139{
140 atf_tc_set_md_var(tc, "descr", "Checks unnamed semaphores"); 140 atf_tc_set_md_var(tc, "descr", "Checks unnamed semaphores");
141} 141}
142 142
143static void * 143static void *
144entry(void * a_arg) 144entry(void * a_arg)
145{ 145{
146 pthread_t self = pthread_self(); 146 pthread_t self = pthread_self();
147 sem_t * sem = (sem_t *) a_arg; 147 sem_t *semp = (sem_t *) a_arg;
148 148
149 printf("Thread %p waiting for semaphore...\n", self); 149 printf("Thread %p waiting for semaphore...\n", self);
150 sem_wait(sem); 150 sem_wait(semp);
151 printf("Thread %p got semaphore\n", self); 151 printf("Thread %p got semaphore\n", self);
152 152
153 return NULL; 153 return NULL;
154} 154}
155 155
156ATF_TC_BODY(unnamed, tc) 156ATF_TC_BODY(unnamed, tc)
157{ 157{
158 sem_t sem_a, sem_b; 158 sem_t sem_a, sem_b;
159 pthread_t threads[NTHREADS]; 159 pthread_t threads[NTHREADS];
160 unsigned i, j; 160 unsigned i, j;
161 int val; 161 int val;
162 162
163 ATF_REQUIRE_MSG(-1 != sysconf(_SC_SEMAPHORES), "%s", strerror(errno)); 163 ATF_REQUIRE_MSG(-1 != sysconf(_SC_SEMAPHORES), "%s", strerror(errno));
164 164
165 printf("Test begin\n"); 165 printf("Test begin\n");
166 166
167 SEM_REQUIRE(sem_init(&sem_b, 0, 0)); 167 SEM_REQUIRE(sem_init(&sem_b, 0, 0));
168 SEM_REQUIRE(sem_getvalue(&sem_b, &val)); 168 SEM_REQUIRE(sem_getvalue(&sem_b, &val));
169 ATF_REQUIRE_EQ(0, val); 169 ATF_REQUIRE_EQ(0, val);
170 170
171 SEM_REQUIRE(sem_post(&sem_b)); 171 SEM_REQUIRE(sem_post(&sem_b));
172 SEM_REQUIRE(sem_getvalue(&sem_b, &val)); 172 SEM_REQUIRE(sem_getvalue(&sem_b, &val));
173 ATF_REQUIRE_EQ(1, val); 173 ATF_REQUIRE_EQ(1, val);
174 174
175 SEM_REQUIRE(sem_wait(&sem_b)); 175 SEM_REQUIRE(sem_wait(&sem_b));
176 ATF_REQUIRE_EQ(sem_trywait(&sem_b), -1); 176 ATF_REQUIRE_EQ(sem_trywait(&sem_b), -1);
177 ATF_REQUIRE_EQ(errno, EAGAIN); 177 ATF_REQUIRE_EQ(errno, EAGAIN);
178 SEM_REQUIRE(sem_post(&sem_b)); 178 SEM_REQUIRE(sem_post(&sem_b));
179 SEM_REQUIRE(sem_trywait(&sem_b)); 179 SEM_REQUIRE(sem_trywait(&sem_b));
180 SEM_REQUIRE(sem_post(&sem_b)); 180 SEM_REQUIRE(sem_post(&sem_b));
181 SEM_REQUIRE(sem_wait(&sem_b)); 181 SEM_REQUIRE(sem_wait(&sem_b));
182 SEM_REQUIRE(sem_post(&sem_b)); 182 SEM_REQUIRE(sem_post(&sem_b));
183 183
184 SEM_REQUIRE(sem_destroy(&sem_b)); 184 SEM_REQUIRE(sem_destroy(&sem_b));
185 185
186 SEM_REQUIRE(sem_init(&sem_a, 0, 0)); 186 SEM_REQUIRE(sem_init(&sem_a, 0, 0));
187 187
188 for (j = 0; j < 2; j++) { 188 for (j = 0; j < 2; j++) {
189 for (i = 0; i < NTHREADS; i++) { 189 for (i = 0; i < NTHREADS; i++) {
190 PTHREAD_REQUIRE(pthread_create(&threads[i], NULL, 190 PTHREAD_REQUIRE(pthread_create(&threads[i], NULL,
191 entry, (void *) &sem_a)); 191 entry, (void *) &sem_a));
192 } 192 }
193 193
194 for (i = 0; i < NTHREADS; i++) { 194 for (i = 0; i < NTHREADS; i++) {
195 usleep(10000); 195 usleep(10000);
196 printf("main loop %u: posting...\n", j+1); 196 printf("main loop %u: posting...\n", j+1);
197 SEM_REQUIRE(sem_post(&sem_a)); 197 SEM_REQUIRE(sem_post(&sem_a));
198 } 198 }
199 199
200 for (i = 0; i < NTHREADS; i++) { 200 for (i = 0; i < NTHREADS; i++) {
201 PTHREAD_REQUIRE(pthread_join(threads[i], NULL)); 201 PTHREAD_REQUIRE(pthread_join(threads[i], NULL));
202 } 202 }
203 } 203 }
204 204
205 SEM_REQUIRE(sem_destroy(&sem_a)); 205 SEM_REQUIRE(sem_destroy(&sem_a));
206 206
207 printf("Test end\n"); 207 printf("Test end\n");
208} 208}
209 209
210static void 210static void
211sighandler(int signo) 211sighandler(int signo)
212{ 212{
213 /* printf("signal %d\n", signo); */ 213 /* printf("signal %d\n", signo); */
214 214
215 ATF_REQUIRE_EQ_MSG(signo, SIGALRM, "unexpected signal"); 215 ATF_REQUIRE_EQ_MSG(signo, SIGALRM, "unexpected signal");
216 SEM_REQUIRE(sem_post(&sem)); 216 SEM_REQUIRE(sem_post(&sem));
217} 217}
218 218
219static void 219static void
220alarm_ms(const int ms) 220alarm_ms(const int ms)
221{ 221{
222 struct itimerval timer; 222 struct itimerval timer;
223 timer.it_interval.tv_sec = 0; 223 timer.it_interval.tv_sec = 0;
224 timer.it_interval.tv_usec = 0; 224 timer.it_interval.tv_usec = 0;
225 timer.it_value.tv_sec = 0; 225 timer.it_value.tv_sec = 0;
226 timer.it_value.tv_usec = ms * 1000; 226 timer.it_value.tv_usec = ms * 1000;
227 ATF_REQUIRE(setitimer(ITIMER_REAL, &timer, NULL) == 0); 227 ATF_REQUIRE(setitimer(ITIMER_REAL, &timer, NULL) == 0);
228} 228}
229 229
230static void * 230static void *
231threadfunc(void *arg) 231threadfunc(void *arg)
232{ 232{
233 int i; 233 int i;
234 234
235 printf("Entering loop\n"); 235 printf("Entering loop\n");
236 for (i = 0; i < 500; ) { 236 for (i = 0; i < 500; ) {
237 if ((i & 1) != 0) { 237 if ((i & 1) != 0) {
238 ATF_REQUIRE(sem_wait(&sem) != -1); 238 ATF_REQUIRE(sem_wait(&sem) != -1);
239 } else { 239 } else {
240 const int ret = sem_trywait(&sem); 240 const int ret = sem_trywait(&sem);
241 if (ret == -1) { 241 if (ret == -1) {
242 ATF_REQUIRE(errno == EAGAIN); 242 ATF_REQUIRE(errno == EAGAIN);
243 continue; 243 continue;
244 } 244 }
245 } 245 }
246 printf("%s: %d\n", __func__, i); 246 printf("%s: %d\n", __func__, i);
247 alarm_ms(5); 247 alarm_ms(5);
248 i++; 248 i++;
249 } 249 }
250 250
251 return NULL; 251 return NULL;
252} 252}
253 253
254static void 254static void
255before_start_test(const bool use_pthread) 255before_start_test(const bool use_pthread)
256{ 256{
257 pthread_t t; 257 pthread_t t;
258 258
259 SEM_REQUIRE(sem_init(&sem, 0, 0)); 259 SEM_REQUIRE(sem_init(&sem, 0, 0));
260 ATF_REQUIRE(SIG_ERR != signal(SIGALRM, sighandler)); 260 ATF_REQUIRE(SIG_ERR != signal(SIGALRM, sighandler));
261 261
262 alarm_ms(5); 262 alarm_ms(5);
263 263
264 if (use_pthread) { 264 if (use_pthread) {
265 PTHREAD_REQUIRE(pthread_create(&t, NULL, threadfunc, NULL)); 265 PTHREAD_REQUIRE(pthread_create(&t, NULL, threadfunc, NULL));
266 PTHREAD_REQUIRE(pthread_join(t, NULL)); 266 PTHREAD_REQUIRE(pthread_join(t, NULL));
267 } else { 267 } else {
268 threadfunc(NULL); 268 threadfunc(NULL);
269 } 269 }
270} 270}
271 271
272ATF_TC(before_start_no_threads); 272ATF_TC(before_start_no_threads);
273ATF_TC_HEAD(before_start_no_threads, tc) 273ATF_TC_HEAD(before_start_no_threads, tc)
274{ 274{
275 atf_tc_set_md_var(tc, "descr", "Checks using semaphores without any " 275 atf_tc_set_md_var(tc, "descr", "Checks using semaphores without any "
276 "thread running"); 276 "thread running");
277 atf_tc_set_md_var(tc, "timeout", "40"); 277 atf_tc_set_md_var(tc, "timeout", "40");
278} 278}
279ATF_TC_BODY(before_start_no_threads, tc) 279ATF_TC_BODY(before_start_no_threads, tc)
280{ 280{
281 before_start_test(false); 281 before_start_test(false);
282} 282}
283 283
284ATF_TC(before_start_one_thread); 284ATF_TC(before_start_one_thread);
285ATF_TC_HEAD(before_start_one_thread, tc) 285ATF_TC_HEAD(before_start_one_thread, tc)
286{ 286{
287 atf_tc_set_md_var(tc, "descr", "Checks using semaphores before " 287 atf_tc_set_md_var(tc, "descr", "Checks using semaphores before "
288 "starting one thread"); 288 "starting one thread");
289 atf_tc_set_md_var(tc, "timeout", "40"); 289 atf_tc_set_md_var(tc, "timeout", "40");
290} 290}
291ATF_TC_BODY(before_start_one_thread, tc) 291ATF_TC_BODY(before_start_one_thread, tc)
292{ 292{
293 /* TODO(jmmv): This really is a race condition test. However, we can't 293 /* TODO(jmmv): This really is a race condition test. However, we can't
294 * yet mark it as such because ATF does not provide such functionality. 294 * yet mark it as such because ATF does not provide such functionality.
295 * Let's just mark it as an unconditional expected timeout as I haven't 295 * Let's just mark it as an unconditional expected timeout as I haven't
296 * got it to pass any single time. */ 296 * got it to pass any single time. */
297 atf_tc_expect_timeout("Race condition; it is probably unsafe to call " 297 atf_tc_expect_timeout("Race condition; it is probably unsafe to call "
298 "sem_post from a signal handler when using the pthread version"); 298 "sem_post from a signal handler when using the pthread version");
299 299
300 before_start_test(true); 300 before_start_test(true);
301} 301}
302 302
303ATF_TP_ADD_TCS(tp) 303ATF_TP_ADD_TCS(tp)
304{ 304{
305 ATF_TP_ADD_TC(tp, named); 305 ATF_TP_ADD_TC(tp, named);
306 ATF_TP_ADD_TC(tp, unnamed); 306 ATF_TP_ADD_TC(tp, unnamed);
307 ATF_TP_ADD_TC(tp, before_start_no_threads); 307 ATF_TP_ADD_TC(tp, before_start_no_threads);
308 ATF_TP_ADD_TC(tp, before_start_one_thread); 308 ATF_TP_ADD_TC(tp, before_start_one_thread);
309 309
310 return atf_no_error(); 310 return atf_no_error();
311} 311}

File Added: src/tests/lib/semaphore/Makefile.inc
.include "../Makefile.inc"

File Added: src/tests/libexec/Makefile.inc
.include "../Makefile.inc"

cvs diff -r1.1 -r1.2 src/tests/libexec/ld.elf_so/t_dlinfo.c (switch to unified diff)

--- src/tests/libexec/ld.elf_so/t_dlinfo.c 2009/09/24 21:33:45 1.1
+++ src/tests/libexec/ld.elf_so/t_dlinfo.c 2010/11/03 16:10:23 1.2
@@ -1,92 +1,93 @@ @@ -1,92 +1,93 @@
1/* $NetBSD: t_dlinfo.c,v 1.1 2009/09/24 21:33:45 pooka Exp $ */ 1/* $NetBSD: t_dlinfo.c,v 1.2 2010/11/03 16:10:23 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30#include <sys/types.h> 30#include <sys/types.h>
31 31
32#include <atf-c.h> 32#include <atf-c.h>
33#include <dlfcn.h> 33#include <dlfcn.h>
34#include <link_elf.h> 34#include <link_elf.h>
35 35
36#include "../../h_macros.h" 36#include "../../h_macros.h"
37 37
38ATF_TC(rtld_dlinfo_linkmap_self); 38ATF_TC(rtld_dlinfo_linkmap_self);
39ATF_TC_HEAD(rtld_dlinfo_linkmap_self, tc) 39ATF_TC_HEAD(rtld_dlinfo_linkmap_self, tc)
40{ 40{
41 atf_tc_set_md_var(tc, "descr", "dlinfo with RTLD_SELF handle works"); 41 atf_tc_set_md_var(tc, "descr", "dlinfo with RTLD_SELF handle works");
42} 42}
43ATF_TC_BODY(rtld_dlinfo_linkmap_self, tc) 43ATF_TC_BODY(rtld_dlinfo_linkmap_self, tc)
44{ 44{
45 struct link_map *map; 45 struct link_map *map;
46 int rv; 46 int rv;
47 47
48 rv = dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &map); 48 rv = dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &map);
49 ATF_CHECK_EQ(rv, 0); 49 ATF_CHECK_EQ(rv, 0);
50 ATF_CHECK((strstr(map->l_name, "t_dlinfo") != NULL)); 50 ATF_CHECK((strstr(map->l_name, "t_dlinfo") != NULL));
51} 51}
52 52
53ATF_TC(rtld_dlinfo_linkmap_inval); 53ATF_TC(rtld_dlinfo_linkmap_inval);
54ATF_TC_HEAD(rtld_dlinfo_linkmap_inval, tc) 54ATF_TC_HEAD(rtld_dlinfo_linkmap_inval, tc)
55{ 55{
56 atf_tc_set_md_var(tc, "descr", "dlinfo with invalid handle fails"); 56 atf_tc_set_md_var(tc, "descr", "dlinfo with invalid handle fails");
57} 57}
58ATF_TC_BODY(rtld_dlinfo_linkmap_inval, tc) 58ATF_TC_BODY(rtld_dlinfo_linkmap_inval, tc)
59{ 59{
60 void *v; 60 void *v;
61 int rv; 61 int rv;
62 62
63 rv = dlinfo(NULL, RTLD_DI_LINKMAP, &v); 63 rv = dlinfo(NULL, RTLD_DI_LINKMAP, &v);
64 ATF_CHECK_EQ(rv, -1); 64 ATF_CHECK_EQ(rv, -1);
65} 65}
66 66
67ATF_TC(rtld_dlinfo_linkmap_dlopen); 67ATF_TC(rtld_dlinfo_linkmap_dlopen);
68ATF_TC_HEAD(rtld_dlinfo_linkmap_dlopen, tc) 68ATF_TC_HEAD(rtld_dlinfo_linkmap_dlopen, tc)
69{ 69{
70 atf_tc_set_md_var(tc, "descr", "dlinfo dlopen'd handle works"); 70 atf_tc_set_md_var(tc, "descr", "dlinfo dlopen'd handle works");
71} 71}
72ATF_TC_BODY(rtld_dlinfo_linkmap_dlopen, tc) 72ATF_TC_BODY(rtld_dlinfo_linkmap_dlopen, tc)
73{ 73{
74 struct link_map *map; 74 struct link_map *map;
75 void *handle; 75 void *handle;
76 int rv; 76 int rv;
77 77
78 handle = dlopen("libutil.so", RTLD_LAZY); 78 handle = dlopen("libutil.so", RTLD_LAZY);
79 ATF_CHECK(handle); 79 ATF_CHECK(handle);
80 80
81 rv = dlinfo(handle, RTLD_DI_LINKMAP, &map); 81 rv = dlinfo(handle, RTLD_DI_LINKMAP, &map);
82 ATF_CHECK_EQ(rv, 0); 82 ATF_CHECK_EQ(rv, 0);
83 ATF_CHECK((strstr(map->l_name, "libutil.so") != NULL)); 83 ATF_CHECK((strstr(map->l_name, "libutil.so") != NULL));
84 dlclose(handle); 84 dlclose(handle);
85} 85}
86 86
87ATF_TP_ADD_TCS(tp) 87ATF_TP_ADD_TCS(tp)
88{ 88{
89 ATF_TP_ADD_TC(tp, rtld_dlinfo_linkmap_self); 89 ATF_TP_ADD_TC(tp, rtld_dlinfo_linkmap_self);
90 ATF_TP_ADD_TC(tp, rtld_dlinfo_linkmap_inval); 90 ATF_TP_ADD_TC(tp, rtld_dlinfo_linkmap_inval);
91 ATF_TP_ADD_TC(tp, rtld_dlinfo_linkmap_dlopen); 91 ATF_TP_ADD_TC(tp, rtld_dlinfo_linkmap_dlopen);
 92 return 0;
92} 93}

File Added: src/tests/modules/Makefile.inc
.include "../Makefile.inc"

cvs diff -r1.1 -r1.2 src/tests/modules/t_builtin.c (switch to unified diff)

--- src/tests/modules/t_builtin.c 2010/08/27 09:56:40 1.1
+++ src/tests/modules/t_builtin.c 2010/11/03 16:10:23 1.2
@@ -1,192 +1,194 @@ @@ -1,192 +1,194 @@
1/* $NetBSD: t_builtin.c,v 1.1 2010/08/27 09:56:40 pooka Exp $ */ 1/* $NetBSD: t_builtin.c,v 1.2 2010/11/03 16:10:23 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. All rights reserved. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/module.h> 30#include <sys/module.h>
31#include <sys/mount.h> 31#include <sys/mount.h>
32 32
33#include <atf-c.h> 33#include <atf-c.h>
34#include <fcntl.h> 34#include <fcntl.h>
35#include <stdbool.h> 35#include <stdbool.h>
36 36
37#include <miscfs/kernfs/kernfs.h> 37#include <miscfs/kernfs/kernfs.h>
38 38
39#include <rump/rump.h> 39#include <rump/rump.h>
40#include <rump/rump_syscalls.h> 40#include <rump/rump_syscalls.h>
41 41
42#include "../h_macros.h" 42#include "../h_macros.h"
43 43
44#define MYMP "/mnt" 44#define MYMP "/mnt"
45#define HZFILE MYMP "/hz" 45#define HZFILE MYMP "/hz"
46 46
 47static char kernfs[] = "kernfs";
 48
47static bool 49static bool
48check_kernfs(void) 50check_kernfs(void)
49{ 51{
50 char buf[16]; 52 char buf[16];
51 bool rv = true; 53 bool rv = true;
52 int fd; 54 int fd;
53 55
54 fd = rump_sys_open(HZFILE, O_RDONLY); 56 fd = rump_sys_open(HZFILE, O_RDONLY);
55 if (fd == -1) 57 if (fd == -1)
56 return false; 58 return false;
57 if (rump_sys_read(fd, buf, sizeof(buf)) < 1) 59 if (rump_sys_read(fd, buf, sizeof(buf)) < 1)
58 rv = false; 60 rv = false;
59 RL(rump_sys_close(fd)); 61 RL(rump_sys_close(fd));
60 62
61 return rv; 63 return rv;
62} 64}
63 65
64ATF_TC(disable); 66ATF_TC(disable);
65ATF_TC_HEAD(disable, tc) 67ATF_TC_HEAD(disable, tc)
66{ 68{
67 69
68 atf_tc_set_md_var(tc, "descr", "Tests that builtin modules can " 70 atf_tc_set_md_var(tc, "descr", "Tests that builtin modules can "
69 "be disabled"); 71 "be disabled");
70} 72}
71 73
72ATF_TC_BODY(disable, tc) 74ATF_TC_BODY(disable, tc)
73{ 75{
74 76
75 rump_init(); 77 rump_init();
76 RL(rump_sys_mkdir(MYMP, 0777)); 78 RL(rump_sys_mkdir(MYMP, 0777));
77 RL(rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0)); 79 RL(rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0));
78 ATF_REQUIRE(check_kernfs()); 80 ATF_REQUIRE(check_kernfs());
79 RL(rump_sys_unmount(MYMP, 0)); 81 RL(rump_sys_unmount(MYMP, 0));
80 RL(rump_sys_modctl(MODCTL_UNLOAD, "kernfs")); 82 RL(rump_sys_modctl(MODCTL_UNLOAD, kernfs));
81} 83}
82 84
83ATF_TC(noauto); 85ATF_TC(noauto);
84ATF_TC_HEAD(noauto, tc) 86ATF_TC_HEAD(noauto, tc)
85{ 87{
86 atf_tc_set_md_var(tc, "descr", "Tests that disabled builtin modules " 88 atf_tc_set_md_var(tc, "descr", "Tests that disabled builtin modules "
87 "will not autoload"); 89 "will not autoload");
88} 90}
89 91
90ATF_TC_BODY(noauto, tc) 92ATF_TC_BODY(noauto, tc)
91{ 93{
92 94
93 rump_init(); 95 rump_init();
94 RL(rump_sys_mkdir(MYMP, 0777)); 96 RL(rump_sys_mkdir(MYMP, 0777));
95 97
96 RL(rump_sys_modctl(MODCTL_UNLOAD, "kernfs")); 98 RL(rump_sys_modctl(MODCTL_UNLOAD, kernfs));
97 99
98 ATF_REQUIRE_ERRNO(ENODEV, 100 ATF_REQUIRE_ERRNO(ENODEV,
99 rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0) == -1); 101 rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0) == -1);
100} 102}
101 103
102ATF_TC(forcereload); 104ATF_TC(forcereload);
103ATF_TC_HEAD(forcereload, tc) 105ATF_TC_HEAD(forcereload, tc)
104{ 106{
105 atf_tc_set_md_var(tc, "descr", "Tests that disabled builtin modules " 107 atf_tc_set_md_var(tc, "descr", "Tests that disabled builtin modules "
106 "can be force-reloaded"); 108 "can be force-reloaded");
107} 109}
108 110
109ATF_TC_BODY(forcereload, tc) 111ATF_TC_BODY(forcereload, tc)
110{ 112{
111 struct modctl_load mod; 113 struct modctl_load mod;
112 114
113 rump_init(); 115 rump_init();
114 RL(rump_sys_mkdir(MYMP, 0777)); 116 RL(rump_sys_mkdir(MYMP, 0777));
115 117
116 RL(rump_sys_modctl(MODCTL_UNLOAD, "kernfs")); 118 RL(rump_sys_modctl(MODCTL_UNLOAD, kernfs));
117 ATF_REQUIRE_ERRNO(ENODEV, 119 ATF_REQUIRE_ERRNO(ENODEV,
118 rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0) == -1); 120 rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0) == -1);
119 121
120 memset(&mod, 0, sizeof(mod)); 122 memset(&mod, 0, sizeof(mod));
121 mod.ml_filename = "kernfs"; 123 mod.ml_filename = kernfs;
122 mod.ml_flags = MODCTL_LOAD_FORCE; 124 mod.ml_flags = MODCTL_LOAD_FORCE;
123 125
124 RL(rump_sys_modctl(MODCTL_LOAD, &mod)); 126 RL(rump_sys_modctl(MODCTL_LOAD, &mod));
125 127
126 RL(rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0)); 128 RL(rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0));
127 ATF_REQUIRE(check_kernfs()); 129 ATF_REQUIRE(check_kernfs());
128 RL(rump_sys_unmount(MYMP, 0)); 130 RL(rump_sys_unmount(MYMP, 0));
129} 131}
130 132
131ATF_TC(disabledstat); 133ATF_TC(disabledstat);
132ATF_TC_HEAD(disabledstat, tc) 134ATF_TC_HEAD(disabledstat, tc)
133{ 135{
134 atf_tc_set_md_var(tc, "descr", "Tests that disabled builtin modules " 136 atf_tc_set_md_var(tc, "descr", "Tests that disabled builtin modules "
135 "show up in modstat with refcount -1"); 137 "show up in modstat with refcount -1");
136} 138}
137 139
138ATF_TC_BODY(disabledstat, tc) 140ATF_TC_BODY(disabledstat, tc)
139{ 141{
140 struct modstat ms[128]; 142 struct modstat ms[128];
141 struct iovec iov; 143 struct iovec iov;
142 int i; 144 size_t i;
143 bool found = false; 145 bool found = false;
144 146
145 rump_init(); 147 rump_init();
146 RL(rump_sys_mkdir(MYMP, 0777)); 148 RL(rump_sys_mkdir(MYMP, 0777));
147 149
148 RL(rump_sys_modctl(MODCTL_UNLOAD, "kernfs")); 150 RL(rump_sys_modctl(MODCTL_UNLOAD, kernfs));
149 151
150 iov.iov_base = ms; 152 iov.iov_base = ms;
151 iov.iov_len = sizeof(ms); 153 iov.iov_len = sizeof(ms);
152 RL(rump_sys_modctl(MODCTL_STAT, &iov)); 154 RL(rump_sys_modctl(MODCTL_STAT, &iov));
153 155
154 for (i = 0; i < __arraycount(ms); i++) { 156 for (i = 0; i < __arraycount(ms); i++) {
155 if (strcmp(ms[i].ms_name, "kernfs") == 0) { 157 if (strcmp(ms[i].ms_name, kernfs) == 0) {
156 ATF_REQUIRE_EQ(ms[i].ms_refcnt, -1); 158 ATF_REQUIRE_EQ(ms[i].ms_refcnt, (u_int)-1);
157 found = 1; 159 found = 1;
158 break; 160 break;
159 } 161 }
160 } 162 }
161 ATF_REQUIRE(found); 163 ATF_REQUIRE(found);
162} 164}
163 165
164ATF_TC(busydisable); 166ATF_TC(busydisable);
165ATF_TC_HEAD(busydisable, tc) 167ATF_TC_HEAD(busydisable, tc)
166{ 168{
167 atf_tc_set_md_var(tc, "descr", "Tests that busy builtin modules " 169 atf_tc_set_md_var(tc, "descr", "Tests that busy builtin modules "
168 "cannot be disabled"); 170 "cannot be disabled");
169} 171}
170 172
171ATF_TC_BODY(busydisable, tc) 173ATF_TC_BODY(busydisable, tc)
172{ 174{
173 175
174 rump_init(); 176 rump_init();
175 RL(rump_sys_mkdir(MYMP, 0777)); 177 RL(rump_sys_mkdir(MYMP, 0777));
176 RL(rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0)); 178 RL(rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0));
177 ATF_REQUIRE(check_kernfs()); 179 ATF_REQUIRE(check_kernfs());
178 ATF_REQUIRE_ERRNO(EBUSY, 180 ATF_REQUIRE_ERRNO(EBUSY,
179 rump_sys_modctl(MODCTL_UNLOAD, "kernfs") == -1); 181 rump_sys_modctl(MODCTL_UNLOAD, kernfs) == -1);
180} 182}
181 183
182ATF_TP_ADD_TCS(tp) 184ATF_TP_ADD_TCS(tp)
183{ 185{
184 186
185 ATF_TP_ADD_TC(tp, disable); 187 ATF_TP_ADD_TC(tp, disable);
186 ATF_TP_ADD_TC(tp, noauto); 188 ATF_TP_ADD_TC(tp, noauto);
187 ATF_TP_ADD_TC(tp, forcereload); 189 ATF_TP_ADD_TC(tp, forcereload);
188 ATF_TP_ADD_TC(tp, disabledstat); 190 ATF_TP_ADD_TC(tp, disabledstat);
189 ATF_TP_ADD_TC(tp, busydisable); 191 ATF_TP_ADD_TC(tp, busydisable);
190 192
191 return atf_no_error(); 193 return atf_no_error();
192} 194}

cvs diff -r1.4 -r1.5 src/tests/modules/t_modctl.c (switch to unified diff)

--- src/tests/modules/t_modctl.c 2010/08/21 13:21:48 1.4
+++ src/tests/modules/t_modctl.c 2010/11/03 16:10:23 1.5
@@ -1,514 +1,515 @@ @@ -1,514 +1,515 @@
1/* $NetBSD: t_modctl.c,v 1.4 2010/08/21 13:21:48 pgoyette Exp $ */ 1/* $NetBSD: t_modctl.c,v 1.5 2010/11/03 16:10:23 christos Exp $ */
2/* 2/*
3 * Copyright (c) 2008 The NetBSD Foundation, Inc. 3 * Copyright (c) 2008 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.4 2010/08/21 13:21:48 pgoyette Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.5 2010/11/03 16:10:23 christos Exp $");
31 31
32#include <sys/module.h> 32#include <sys/module.h>
33#include <sys/sysctl.h> 33#include <sys/sysctl.h>
34 34
35#include <assert.h> 35#include <assert.h>
36#include <errno.h> 36#include <errno.h>
37#include <stdarg.h> 37#include <stdarg.h>
38#include <stdbool.h> 38#include <stdbool.h>
39#include <stdio.h> 39#include <stdio.h>
40#include <stdlib.h> 40#include <stdlib.h>
41#include <string.h> 41#include <string.h>
42 42
43#include <prop/proplib.h> 43#include <prop/proplib.h>
44 44
45#include <atf-c.h> 45#include <atf-c.h>
46 46
47static bool have_modular = false; 47static bool have_modular = false;
48 48
49enum presence_check { both_checks, stat_check, sysctl_check }; 49enum presence_check { both_checks, stat_check, sysctl_check };
50 50
51/* --------------------------------------------------------------------- */ 51/* --------------------------------------------------------------------- */
52/* Auxiliary functions */ 52/* Auxiliary functions */
53/* --------------------------------------------------------------------- */ 53/* --------------------------------------------------------------------- */
54 54
55/* 55/*
56 * Checks if the kernel has 'options MODULAR' built into it and returns 56 * Checks if the kernel has 'options MODULAR' built into it and returns
57 * a boolean indicating this condition. This function must be called 57 * a boolean indicating this condition. This function must be called
58 * during the test program's initialization and the result be stored 58 * during the test program's initialization and the result be stored
59 * globally for further (efficient) usage of require_modular(). 59 * globally for further (efficient) usage of require_modular().
60 */ 60 */
61static 61static
62bool 62bool
63check_modular(void) 63check_modular(void)
64{ 64{
65 bool res; 65 bool res;
66 struct iovec iov; 66 struct iovec iov;
67 67
68 iov.iov_base = NULL; 68 iov.iov_base = NULL;
69 iov.iov_len = 0; 69 iov.iov_len = 0;
70 70
71 if (modctl(MODCTL_STAT, &iov) == 0) 71 if (modctl(MODCTL_STAT, &iov) == 0)
72 res = true; 72 res = true;
73 else 73 else
74 res = (errno != ENOSYS); 74 res = (errno != ENOSYS);
75 75
76 return res; 76 return res;
77} 77}
78 78
79/* 79/*
80 * Makes sure that the kernel has 'options MODULAR' built into it and 80 * Makes sure that the kernel has 'options MODULAR' built into it and
81 * skips the test otherwise. Cannot be called unless check_modular() 81 * skips the test otherwise. Cannot be called unless check_modular()
82 * has been executed before. 82 * has been executed before.
83 */ 83 */
84static 84static
85void 85void
86require_modular(void) 86require_modular(void)
87{ 87{
88 88
89 if (!have_modular) 89 if (!have_modular)
90 atf_tc_skip("Kernel does not have 'options MODULAR'."); 90 atf_tc_skip("Kernel does not have 'options MODULAR'.");
91} 91}
92 92
93static 93static
94bool 94bool
95get_modstat_info(const char *name, modstat_t *msdest) 95get_modstat_info(const char *name, modstat_t *msdest)
96{ 96{
97 bool found; 97 bool found;
98 size_t len; 98 size_t len;
99 struct iovec iov; 99 struct iovec iov;
100 modstat_t *ms; 100 modstat_t *ms;
101 101
102 for (len = 4096; ;) { 102 for (len = 4096; ;) {
103 iov.iov_base = malloc(len); 103 iov.iov_base = malloc(len);
104 iov.iov_len = len; 104 iov.iov_len = len;
105 if (modctl(MODCTL_STAT, &iov) != 0) { 105 if (modctl(MODCTL_STAT, &iov) != 0) {
106 int err = errno; 106 int err = errno;
107 fprintf(stderr, "modctl(MODCTL_STAT) failed: %s\n", 107 fprintf(stderr, "modctl(MODCTL_STAT) failed: %s\n",
108 strerror(err)); 108 strerror(err));
109 atf_tc_fail("Failed to query module status"); 109 atf_tc_fail("Failed to query module status");
110 } 110 }
111 if (len >= iov.iov_len) 111 if (len >= iov.iov_len)
112 break; 112 break;
113 free(iov.iov_base); 113 free(iov.iov_base);
114 len = iov.iov_len; 114 len = iov.iov_len;
115 } 115 }
116 116
117 found = false; 117 found = false;
118 len = iov.iov_len / sizeof(modstat_t); 118 len = iov.iov_len / sizeof(modstat_t);
119 for (ms = (modstat_t *)iov.iov_base; len != 0 && !found; 119 for (ms = (modstat_t *)iov.iov_base; len != 0 && !found;
120 ms++, len--) { 120 ms++, len--) {
121 if (strcmp(ms->ms_name, name) == 0) { 121 if (strcmp(ms->ms_name, name) == 0) {
122 if (msdest != NULL) 122 if (msdest != NULL)
123 *msdest = *ms; 123 *msdest = *ms;
124 found = true; 124 found = true;
125 } 125 }
126 } 126 }
127 127
128 free(iov.iov_base); 128 free(iov.iov_base);
129 129
130 return found; 130 return found;
131} 131}
132 132
133/* 133/*
134 * Queries a sysctl property. 134 * Queries a sysctl property.
135 */ 135 */
136static 136static
137bool 137bool
138get_sysctl(const char *name, void *buf, const size_t len) 138get_sysctl(const char *name, void *buf, const size_t len)
139{ 139{
140 size_t len2 = len; 140 size_t len2 = len;
141 printf("Querying sysctl variable: %s\n", name); 141 printf("Querying sysctl variable: %s\n", name);
142 int ret = sysctlbyname(name, buf, &len2, NULL, 0); 142 int ret = sysctlbyname(name, buf, &len2, NULL, 0);
143 if (ret == -1 && errno != ENOENT) { 143 if (ret == -1 && errno != ENOENT) {
144 fprintf(stderr, "sysctlbyname(2) failed: %s\n", 144 fprintf(stderr, "sysctlbyname(2) failed: %s\n",
145 strerror(errno)); 145 strerror(errno));
146 atf_tc_fail("Failed to query %s", name); 146 atf_tc_fail("Failed to query %s", name);
147 } 147 }
148 return ret != -1; 148 return ret != -1;
149} 149}
150 150
151/* 151/*
152 * Returns a boolean indicating if the k_helper module was loaded 152 * Returns a boolean indicating if the k_helper module was loaded
153 * successfully. This implementation uses modctl(2)'s MODCTL_STAT 153 * successfully. This implementation uses modctl(2)'s MODCTL_STAT
154 * subcommand to do the check. 154 * subcommand to do the check.
155 */ 155 */
156static 156static
157bool 157bool
158k_helper_is_present_stat(void) 158k_helper_is_present_stat(void)
159{ 159{
160 160
161 return get_modstat_info("k_helper", NULL); 161 return get_modstat_info("k_helper", NULL);
162} 162}
163 163
164/* 164/*
165 * Returns a boolean indicating if the k_helper module was loaded 165 * Returns a boolean indicating if the k_helper module was loaded
166 * successfully. This implementation uses the module's sysctl 166 * successfully. This implementation uses the module's sysctl
167 * installed node to do the check. 167 * installed node to do the check.
168 */ 168 */
169static 169static
170bool 170bool
171k_helper_is_present_sysctl(void) 171k_helper_is_present_sysctl(void)
172{ 172{
173 size_t present; 173 size_t present;
174 174
175 return get_sysctl("vendor.k_helper.present", &present, 175 return get_sysctl("vendor.k_helper.present", &present,
176 sizeof(present)); 176 sizeof(present));
177} 177}
178 178
179/* 179/*
180 * Returns a boolean indicating if the k_helper module was loaded 180 * Returns a boolean indicating if the k_helper module was loaded
181 * successfully. The 'how' parameter specifies the implementation to 181 * successfully. The 'how' parameter specifies the implementation to
182 * use to do the check. 182 * use to do the check.
183 */ 183 */
184static 184static
185bool 185bool
186k_helper_is_present(enum presence_check how) 186k_helper_is_present(enum presence_check how)
187{ 187{
188 bool found; 188 bool found;
189 189
190 switch (how) { 190 switch (how) {
191 case both_checks: 191 case both_checks:
192 found = k_helper_is_present_stat(); 192 found = k_helper_is_present_stat();
193 ATF_CHECK(k_helper_is_present_sysctl() == found); 193 ATF_CHECK(k_helper_is_present_sysctl() == found);
194 break; 194 break;
195 195
196 case stat_check: 196 case stat_check:
197 found = k_helper_is_present_stat(); 197 found = k_helper_is_present_stat();
198 break; 198 break;
199 199
200 case sysctl_check: 200 case sysctl_check:
201 found = k_helper_is_present_sysctl(); 201 found = k_helper_is_present_sysctl();
202 break; 202 break;
203 203
204 default: 204 default:
205 assert(false); 205 found = false;
 206 assert(found);
206 } 207 }
207 208
208 return found; 209 return found;
209} 210}
210 211
211/* 212/*
212 * Loads the specified module from a file. If fatal is set and an error 213 * Loads the specified module from a file. If fatal is set and an error
213 * occurs when loading the module, an error message is printed and the 214 * occurs when loading the module, an error message is printed and the
214 * test case is aborted. 215 * test case is aborted.
215 */ 216 */
216static 217static
217int 218int
218load(prop_dictionary_t props, bool fatal, const char *fmt, ...) 219load(prop_dictionary_t props, bool fatal, const char *fmt, ...)
219{ 220{
220 int err; 221 int err;
221 va_list ap; 222 va_list ap;
222 char filename[MAXPATHLEN], *propsstr; 223 char filename[MAXPATHLEN], *propsstr;
223 modctl_load_t ml; 224 modctl_load_t ml;
224 225
225 if (props == NULL) { 226 if (props == NULL) {
226 props = prop_dictionary_create(); 227 props = prop_dictionary_create();
227 propsstr = prop_dictionary_externalize(props); 228 propsstr = prop_dictionary_externalize(props);
228 ATF_CHECK(propsstr != NULL); 229 ATF_CHECK(propsstr != NULL);
229 prop_object_release(props); 230 prop_object_release(props);
230 } else { 231 } else {
231 propsstr = prop_dictionary_externalize(props); 232 propsstr = prop_dictionary_externalize(props);
232 ATF_CHECK(propsstr != NULL); 233 ATF_CHECK(propsstr != NULL);
233 } 234 }
234 235
235 va_start(ap, fmt); 236 va_start(ap, fmt);
236 vsnprintf(filename, sizeof(filename), fmt, ap); 237 vsnprintf(filename, sizeof(filename), fmt, ap);
237 va_end(ap); 238 va_end(ap);
238 239
239 ml.ml_filename = filename; 240 ml.ml_filename = filename;
240 ml.ml_flags = 0; 241 ml.ml_flags = 0;
241 ml.ml_props = propsstr; 242 ml.ml_props = propsstr;
242 ml.ml_propslen = strlen(propsstr); 243 ml.ml_propslen = strlen(propsstr);
243 244
244 printf("Loading module %s\n", filename); 245 printf("Loading module %s\n", filename);
245 err = 0; 246 err = 0;
246 if (modctl(MODCTL_LOAD, &ml) == -1) { 247 if (modctl(MODCTL_LOAD, &ml) == -1) {
247 err = errno; 248 err = errno;
248 fprintf(stderr, "modctl(MODCTL_LOAD, %s), failed: %s\n", 249 fprintf(stderr, "modctl(MODCTL_LOAD, %s), failed: %s\n",
249 filename, strerror(err)); 250 filename, strerror(err));
250 if (fatal) 251 if (fatal)
251 atf_tc_fail("Module load failed"); 252 atf_tc_fail("Module load failed");
252 } 253 }
253 254
254 free(propsstr); 255 free(propsstr);
255 256
256 return err; 257 return err;
257} 258}
258 259
259/* 260/*
260 * Unloads the specified module. If silent is true, nothing will be 261 * Unloads the specified module. If silent is true, nothing will be
261 * printed and no errors will be raised if the unload was unsuccessful. 262 * printed and no errors will be raised if the unload was unsuccessful.
262 */ 263 */
263static 264static
264int 265int
265unload(const char *name, bool fatal) 266unload(const char *name, bool fatal)
266{ 267{
267 int err; 268 int err;
268 269
269 printf("Unloading module %s\n", name); 270 printf("Unloading module %s\n", name);
270 err = 0; 271 err = 0;
271 if (modctl(MODCTL_UNLOAD, __UNCONST(name)) == -1) { 272 if (modctl(MODCTL_UNLOAD, __UNCONST(name)) == -1) {
272 err = errno; 273 err = errno;
273 fprintf(stderr, "modctl(MODCTL_UNLOAD, %s) failed: %s\n", 274 fprintf(stderr, "modctl(MODCTL_UNLOAD, %s) failed: %s\n",
274 name, strerror(err)); 275 name, strerror(err));
275 if (fatal) 276 if (fatal)
276 atf_tc_fail("Module unload failed"); 277 atf_tc_fail("Module unload failed");
277 } 278 }
278 return err; 279 return err;
279} 280}
280 281
281/* 282/*
282 * A silent version of unload, to be called as part of the cleanup 283 * A silent version of unload, to be called as part of the cleanup
283 * process only. 284 * process only.
284 */ 285 */
285static 286static
286int 287void
287unload_cleanup(const char *name) 288unload_cleanup(const char *name)
288{ 289{
289 290
290 (void)modctl(MODCTL_UNLOAD, __UNCONST(name)); 291 (void)modctl(MODCTL_UNLOAD, __UNCONST(name));
291} 292}
292 293
293/* --------------------------------------------------------------------- */ 294/* --------------------------------------------------------------------- */
294/* Test cases */ 295/* Test cases */
295/* --------------------------------------------------------------------- */ 296/* --------------------------------------------------------------------- */
296 297
297ATF_TC_WITH_CLEANUP(cmd_load); 298ATF_TC_WITH_CLEANUP(cmd_load);
298ATF_TC_HEAD(cmd_load, tc) 299ATF_TC_HEAD(cmd_load, tc)
299{ 300{
300 atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command"); 301 atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command");
301 atf_tc_set_md_var(tc, "require.user", "root"); 302 atf_tc_set_md_var(tc, "require.user", "root");
302} 303}
303ATF_TC_BODY(cmd_load, tc) 304ATF_TC_BODY(cmd_load, tc)
304{ 305{
305 char longname[MAXPATHLEN]; 306 char longname[MAXPATHLEN];
306 size_t i; 307 size_t i;
307 308
308 require_modular(); 309 require_modular();
309 310
310 ATF_CHECK(load(NULL, false, "") == ENOENT); 311 ATF_CHECK(load(NULL, false, "") == ENOENT);
311 ATF_CHECK(load(NULL, false, "non-existent.o") == ENOENT); 312 ATF_CHECK(load(NULL, false, "non-existent.o") == ENOENT);
312 313
313 for (i = 0; i < MAXPATHLEN - 1; i++) 314 for (i = 0; i < MAXPATHLEN - 1; i++)
314 longname[i] = 'a'; 315 longname[i] = 'a';
315 longname[MAXPATHLEN - 1] = '\0'; 316 longname[MAXPATHLEN - 1] = '\0';
316 ATF_CHECK(load(NULL, false, longname) == ENAMETOOLONG); 317 ATF_CHECK(load(NULL, false, longname) == ENAMETOOLONG);
317 318
318 ATF_CHECK(!k_helper_is_present(stat_check)); 319 ATF_CHECK(!k_helper_is_present(stat_check));
319 load(NULL, true, "%s/k_helper/k_helper.kmod", 320 load(NULL, true, "%s/k_helper/k_helper.kmod",
320 atf_tc_get_config_var(tc, "srcdir")); 321 atf_tc_get_config_var(tc, "srcdir"));
321 printf("Checking if load was successful\n"); 322 printf("Checking if load was successful\n");
322 ATF_CHECK(k_helper_is_present(stat_check)); 323 ATF_CHECK(k_helper_is_present(stat_check));
323} 324}
324ATF_TC_CLEANUP(cmd_load, tc) 325ATF_TC_CLEANUP(cmd_load, tc)
325{ 326{
326 unload_cleanup("k_helper"); 327 unload_cleanup("k_helper");
327} 328}
328 329
329ATF_TC_WITH_CLEANUP(cmd_load_props); 330ATF_TC_WITH_CLEANUP(cmd_load_props);
330ATF_TC_HEAD(cmd_load_props, tc) 331ATF_TC_HEAD(cmd_load_props, tc)
331{ 332{
332 atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command, " 333 atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command, "
333 "providing extra load-time properties"); 334 "providing extra load-time properties");
334 atf_tc_set_md_var(tc, "require.user", "root"); 335 atf_tc_set_md_var(tc, "require.user", "root");
335} 336}
336ATF_TC_BODY(cmd_load_props, tc) 337ATF_TC_BODY(cmd_load_props, tc)
337{ 338{
338 prop_dictionary_t props; 339 prop_dictionary_t props;
339 340
340 require_modular(); 341 require_modular();
341 342
342 printf("Loading module without properties\n"); 343 printf("Loading module without properties\n");
343 props = prop_dictionary_create(); 344 props = prop_dictionary_create();
344 load(props, true, "%s/k_helper/k_helper.kmod", 345 load(props, true, "%s/k_helper/k_helper.kmod",
345 atf_tc_get_config_var(tc, "srcdir")); 346 atf_tc_get_config_var(tc, "srcdir"));
346 prop_object_release(props); 347 prop_object_release(props);
347 { 348 {
348 int ok; 349 int ok;
349 ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok", 350 ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok",
350 &ok, sizeof(ok))); 351 &ok, sizeof(ok)));
351 ATF_CHECK(!ok); 352 ATF_CHECK(!ok);
352 } 353 }
353 unload("k_helper", true); 354 unload("k_helper", true);
354 355
355 printf("Loading module with a string property\n"); 356 printf("Loading module with a string property\n");
356 props = prop_dictionary_create(); 357 props = prop_dictionary_create();
357 prop_dictionary_set(props, "prop_str", 358 prop_dictionary_set(props, "prop_str",
358 prop_string_create_cstring("1st string")); 359 prop_string_create_cstring("1st string"));
359 load(props, true, "%s/k_helper/k_helper.kmod", 360 load(props, true, "%s/k_helper/k_helper.kmod",
360 atf_tc_get_config_var(tc, "srcdir")); 361 atf_tc_get_config_var(tc, "srcdir"));
361 prop_object_release(props); 362 prop_object_release(props);
362 { 363 {
363 int ok; 364 int ok;
364 ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok", 365 ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok",
365 &ok, sizeof(ok))); 366 &ok, sizeof(ok)));
366 ATF_CHECK(ok); 367 ATF_CHECK(ok);
367 368
368 char val[128]; 369 char val[128];
369 ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_val", 370 ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_val",
370 &val, sizeof(val))); 371 &val, sizeof(val)));
371 ATF_CHECK(strcmp(val, "1st string") == 0); 372 ATF_CHECK(strcmp(val, "1st string") == 0);
372 } 373 }
373 unload("k_helper", true); 374 unload("k_helper", true);
374 375
375 printf("Loading module with a different string property\n"); 376 printf("Loading module with a different string property\n");
376 props = prop_dictionary_create(); 377 props = prop_dictionary_create();
377 prop_dictionary_set(props, "prop_str", 378 prop_dictionary_set(props, "prop_str",
378 prop_string_create_cstring("2nd string")); 379 prop_string_create_cstring("2nd string"));
379 load(props, true, "%s/k_helper/k_helper.kmod", 380 load(props, true, "%s/k_helper/k_helper.kmod",
380 atf_tc_get_config_var(tc, "srcdir")); 381 atf_tc_get_config_var(tc, "srcdir"));
381 prop_object_release(props); 382 prop_object_release(props);
382 { 383 {
383 int ok; 384 int ok;
384 ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok", 385 ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok",
385 &ok, sizeof(ok))); 386 &ok, sizeof(ok)));
386 ATF_CHECK(ok); 387 ATF_CHECK(ok);
387 388
388 char val[128]; 389 char val[128];
389 ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_val", 390 ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_val",
390 &val, sizeof(val))); 391 &val, sizeof(val)));
391 ATF_CHECK(strcmp(val, "2nd string") == 0); 392 ATF_CHECK(strcmp(val, "2nd string") == 0);
392 } 393 }
393 unload("k_helper", true); 394 unload("k_helper", true);
394} 395}
395ATF_TC_CLEANUP(cmd_load_props, tc) 396ATF_TC_CLEANUP(cmd_load_props, tc)
396{ 397{
397 unload_cleanup("k_helper"); 398 unload_cleanup("k_helper");
398} 399}
399 400
400ATF_TC_WITH_CLEANUP(cmd_load_recurse); 401ATF_TC_WITH_CLEANUP(cmd_load_recurse);
401ATF_TC_HEAD(cmd_load_recurse, tc) 402ATF_TC_HEAD(cmd_load_recurse, tc)
402{ 403{
403 atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command, " 404 atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command, "
404 "with recursive module_load()"); 405 "with recursive module_load()");
405 atf_tc_set_md_var(tc, "require.user", "root"); 406 atf_tc_set_md_var(tc, "require.user", "root");
406} 407}
407ATF_TC_BODY(cmd_load_recurse, tc) 408ATF_TC_BODY(cmd_load_recurse, tc)
408{ 409{
409 prop_dictionary_t props; 410 prop_dictionary_t props;
410 char filename[MAXPATHLEN]; 411 char filename[MAXPATHLEN];
411 412
412 require_modular(); 413 require_modular();
413 414
414 printf("Loading module with request to load another module\n"); 415 printf("Loading module with request to load another module\n");
415 props = prop_dictionary_create(); 416 props = prop_dictionary_create();
416 snprintf(filename, sizeof(filename), "%s/k_helper2/k_helper2.kmod", 417 snprintf(filename, sizeof(filename), "%s/k_helper2/k_helper2.kmod",
417 atf_tc_get_config_var(tc, "srcdir")); 418 atf_tc_get_config_var(tc, "srcdir"));
418 prop_dictionary_set(props, "prop_recurse", 419 prop_dictionary_set(props, "prop_recurse",
419 prop_string_create_cstring(filename)); 420 prop_string_create_cstring(filename));
420 load(props, true, "%s/k_helper/k_helper.kmod", 421 load(props, true, "%s/k_helper/k_helper.kmod",
421 atf_tc_get_config_var(tc, "srcdir")); 422 atf_tc_get_config_var(tc, "srcdir"));
422 { 423 {
423 int ok; 424 int ok;
424 ATF_CHECK(get_sysctl("vendor.k_helper.prop_int_load", 425 ATF_CHECK(get_sysctl("vendor.k_helper.prop_int_load",
425 &ok, sizeof(ok))); 426 &ok, sizeof(ok)));
426 ATF_CHECK(ok == 0); 427 ATF_CHECK(ok == 0);
427 ATF_CHECK(get_sysctl("vendor.k_helper2.present", 428 ATF_CHECK(get_sysctl("vendor.k_helper2.present",
428 &ok, sizeof(ok))); 429 &ok, sizeof(ok)));
429 ATF_CHECK(ok); 430 ATF_CHECK(ok);
430 } 431 }
431 unload("k_helper", true); 432 unload("k_helper", true);
432 unload("k_helper2", true); 433 unload("k_helper2", true);
433} 434}
434ATF_TC_CLEANUP(cmd_load_recurse, tc) 435ATF_TC_CLEANUP(cmd_load_recurse, tc)
435{ 436{
436 unload_cleanup("k_helper"); 437 unload_cleanup("k_helper");
437 unload_cleanup("k_helper2"); 438 unload_cleanup("k_helper2");
438} 439}
439 440
440ATF_TC_WITH_CLEANUP(cmd_stat); 441ATF_TC_WITH_CLEANUP(cmd_stat);
441ATF_TC_HEAD(cmd_stat, tc) 442ATF_TC_HEAD(cmd_stat, tc)
442{ 443{
443 atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_STAT command"); 444 atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_STAT command");
444 atf_tc_set_md_var(tc, "require.user", "root"); 445 atf_tc_set_md_var(tc, "require.user", "root");
445} 446}
446ATF_TC_BODY(cmd_stat, tc) 447ATF_TC_BODY(cmd_stat, tc)
447{ 448{
448 require_modular(); 449 require_modular();
449 450
450 ATF_CHECK(!k_helper_is_present(both_checks)); 451 ATF_CHECK(!k_helper_is_present(both_checks));
451 452
452 load(NULL, true, "%s/k_helper/k_helper.kmod", 453 load(NULL, true, "%s/k_helper/k_helper.kmod",
453 atf_tc_get_config_var(tc, "srcdir")); 454 atf_tc_get_config_var(tc, "srcdir"));
454 ATF_CHECK(k_helper_is_present(both_checks)); 455 ATF_CHECK(k_helper_is_present(both_checks));
455 { 456 {
456 modstat_t ms; 457 modstat_t ms;
457 ATF_CHECK(get_modstat_info("k_helper", &ms)); 458 ATF_CHECK(get_modstat_info("k_helper", &ms));
458 459
459 ATF_CHECK(ms.ms_class == MODULE_CLASS_MISC); 460 ATF_CHECK(ms.ms_class == MODULE_CLASS_MISC);
460 ATF_CHECK(ms.ms_source == MODULE_SOURCE_FILESYS); 461 ATF_CHECK(ms.ms_source == MODULE_SOURCE_FILESYS);
461 ATF_CHECK(ms.ms_refcnt == 0); 462 ATF_CHECK(ms.ms_refcnt == 0);
462 } 463 }
463 unload("k_helper", true); 464 unload("k_helper", true);
464 465
465 ATF_CHECK(!k_helper_is_present(both_checks)); 466 ATF_CHECK(!k_helper_is_present(both_checks));
466} 467}
467ATF_TC_CLEANUP(cmd_stat, tc) 468ATF_TC_CLEANUP(cmd_stat, tc)
468{ 469{
469 unload_cleanup("k_helper"); 470 unload_cleanup("k_helper");
470} 471}
471 472
472ATF_TC_WITH_CLEANUP(cmd_unload); 473ATF_TC_WITH_CLEANUP(cmd_unload);
473ATF_TC_HEAD(cmd_unload, tc) 474ATF_TC_HEAD(cmd_unload, tc)
474{ 475{
475 atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_UNLOAD command"); 476 atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_UNLOAD command");
476 atf_tc_set_md_var(tc, "require.user", "root"); 477 atf_tc_set_md_var(tc, "require.user", "root");
477} 478}
478ATF_TC_BODY(cmd_unload, tc) 479ATF_TC_BODY(cmd_unload, tc)
479{ 480{
480 require_modular(); 481 require_modular();
481 482
482 load(NULL, true, "%s/k_helper/k_helper.kmod", 483 load(NULL, true, "%s/k_helper/k_helper.kmod",
483 atf_tc_get_config_var(tc, "srcdir")); 484 atf_tc_get_config_var(tc, "srcdir"));
484 485
485 ATF_CHECK(unload("", false) == ENOENT); 486 ATF_CHECK(unload("", false) == ENOENT);
486 ATF_CHECK(unload("non-existent.kmod", false) == ENOENT); 487 ATF_CHECK(unload("non-existent.kmod", false) == ENOENT);
487 ATF_CHECK(unload("k_helper.kmod", false) == ENOENT); 488 ATF_CHECK(unload("k_helper.kmod", false) == ENOENT);
488 489
489 ATF_CHECK(k_helper_is_present(stat_check)); 490 ATF_CHECK(k_helper_is_present(stat_check));
490 unload("k_helper", true); 491 unload("k_helper", true);
491 printf("Checking if unload was successful\n"); 492 printf("Checking if unload was successful\n");
492 ATF_CHECK(!k_helper_is_present(stat_check)); 493 ATF_CHECK(!k_helper_is_present(stat_check));
493} 494}
494ATF_TC_CLEANUP(cmd_unload, tc) 495ATF_TC_CLEANUP(cmd_unload, tc)
495{ 496{
496 unload_cleanup("k_helper"); 497 unload_cleanup("k_helper");
497} 498}
498 499
499/* --------------------------------------------------------------------- */ 500/* --------------------------------------------------------------------- */
500/* Main */ 501/* Main */
501/* --------------------------------------------------------------------- */ 502/* --------------------------------------------------------------------- */
502 503
503ATF_TP_ADD_TCS(tp) 504ATF_TP_ADD_TCS(tp)
504{ 505{
505 have_modular = check_modular(); 506 have_modular = check_modular();
506 507
507 ATF_TP_ADD_TC(tp, cmd_load); 508 ATF_TP_ADD_TC(tp, cmd_load);
508 ATF_TP_ADD_TC(tp, cmd_load_props); 509 ATF_TP_ADD_TC(tp, cmd_load_props);
509 ATF_TP_ADD_TC(tp, cmd_stat); 510 ATF_TP_ADD_TC(tp, cmd_stat);
510 ATF_TP_ADD_TC(tp, cmd_load_recurse); 511 ATF_TP_ADD_TC(tp, cmd_load_recurse);
511 ATF_TP_ADD_TC(tp, cmd_unload); 512 ATF_TP_ADD_TC(tp, cmd_unload);
512 513
513 return atf_no_error(); 514 return atf_no_error();
514} 515}

cvs diff -r1.4 -r1.5 src/tests/modules/k_helper/k_helper.c (switch to unified diff)

--- src/tests/modules/k_helper/k_helper.c 2010/08/21 13:21:48 1.4
+++ src/tests/modules/k_helper/k_helper.c 2010/11/03 16:10:23 1.5
@@ -1,202 +1,202 @@ @@ -1,202 +1,202 @@
1/* $NetBSD: k_helper.c,v 1.4 2010/08/21 13:21:48 pgoyette Exp $ */ 1/* $NetBSD: k_helper.c,v 1.5 2010/11/03 16:10:23 christos Exp $ */
2/* 2/*
3 * Copyright (c) 2008 The NetBSD Foundation, Inc. 3 * Copyright (c) 2008 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: k_helper.c,v 1.4 2010/08/21 13:21:48 pgoyette Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: k_helper.c,v 1.5 2010/11/03 16:10:23 christos Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/kernel.h> 33#include <sys/kernel.h>
34#include <sys/module.h> 34#include <sys/module.h>
35#include <sys/sysctl.h> 35#include <sys/sysctl.h>
36 36
37#include <prop/proplib.h> 37#include <prop/proplib.h>
38 38
39MODULE(MODULE_CLASS_MISC, k_helper, NULL); 39MODULE(MODULE_CLASS_MISC, k_helper, NULL);
40 40
41/* --------------------------------------------------------------------- */ 41/* --------------------------------------------------------------------- */
42/* Sysctl interface to query information about the module. */ 42/* Sysctl interface to query information about the module. */
43/* --------------------------------------------------------------------- */ 43/* --------------------------------------------------------------------- */
44 44
45/* TODO: Change the integer variables below that represent booleans to 45/* TODO: Change the integer variables below that represent booleans to
46 * bools, once sysctl(8) supports CTLTYPE_BOOL nodes. */ 46 * bools, once sysctl(8) supports CTLTYPE_BOOL nodes. */
47 47
48static struct sysctllog *clog; 48static struct sysctllog *clogp;
49static int present = 1; 49static int present = 1;
50static int prop_str_ok; 50static int prop_str_ok;
51static char prop_str_val[128]; 51static char prop_str_val[128];
52static int prop_int_ok; 52static int prop_int_ok;
53static int64_t prop_int_val; 53static int64_t prop_int_val;
54static int prop_int_load; 54static int prop_int_load;
55 55
56#define K_HELPER 0x12345678 56#define K_HELPER 0x12345678
57#define K_HELPER_PRESENT 0 57#define K_HELPER_PRESENT 0
58#define K_HELPER_PROP_STR_OK 1 58#define K_HELPER_PROP_STR_OK 1
59#define K_HELPER_PROP_STR_VAL 2 59#define K_HELPER_PROP_STR_VAL 2
60#define K_HELPER_PROP_INT_OK 3 60#define K_HELPER_PROP_INT_OK 3
61#define K_HELPER_PROP_INT_VAL 4 61#define K_HELPER_PROP_INT_VAL 4
62#define K_HELPER_PROP_INT_LOAD 5 62#define K_HELPER_PROP_INT_LOAD 5
63 63
64SYSCTL_SETUP(sysctl_k_helper_setup, "sysctl k_helper subtree setup") 64SYSCTL_SETUP(sysctl_k_helper_setup, "sysctl k_helper subtree setup")
65{ 65{
66 66
67 sysctl_createv(clog, 0, NULL, NULL, 67 sysctl_createv(clog, 0, NULL, NULL,
68 CTLFLAG_PERMANENT, 68 CTLFLAG_PERMANENT,
69 CTLTYPE_NODE, "k_helper", NULL, 69 CTLTYPE_NODE, "k_helper", NULL,
70 NULL, 0, NULL, 0, 70 NULL, 0, NULL, 0,
71 CTL_VENDOR, K_HELPER, CTL_EOL); 71 CTL_VENDOR, K_HELPER, CTL_EOL);
72 72
73 sysctl_createv(clog, 0, NULL, NULL, 73 sysctl_createv(clog, 0, NULL, NULL,
74 CTLFLAG_PERMANENT, 74 CTLFLAG_PERMANENT,
75 CTLTYPE_INT, "present", 75 CTLTYPE_INT, "present",
76 SYSCTL_DESCR("Whether the module was loaded or not"), 76 SYSCTL_DESCR("Whether the module was loaded or not"),
77 NULL, 0, &present, 0, 77 NULL, 0, &present, 0,
78 CTL_VENDOR, K_HELPER, K_HELPER_PRESENT, CTL_EOL); 78 CTL_VENDOR, K_HELPER, K_HELPER_PRESENT, CTL_EOL);
79 79
80 sysctl_createv(clog, 0, NULL, NULL, 80 sysctl_createv(clog, 0, NULL, NULL,
81 CTLFLAG_PERMANENT, 81 CTLFLAG_PERMANENT,
82 CTLTYPE_INT, "prop_str_ok", 82 CTLTYPE_INT, "prop_str_ok",
83 SYSCTL_DESCR("String property's validity"), 83 SYSCTL_DESCR("String property's validity"),
84 NULL, 0, &prop_str_ok, 0, 84 NULL, 0, &prop_str_ok, 0,
85 CTL_VENDOR, K_HELPER, K_HELPER_PROP_STR_OK, CTL_EOL); 85 CTL_VENDOR, K_HELPER, K_HELPER_PROP_STR_OK, CTL_EOL);
86 86
87 sysctl_createv(clog, 0, NULL, NULL, 87 sysctl_createv(clog, 0, NULL, NULL,
88 CTLFLAG_PERMANENT, 88 CTLFLAG_PERMANENT,
89 CTLTYPE_STRING, "prop_str_val", 89 CTLTYPE_STRING, "prop_str_val",
90 SYSCTL_DESCR("String property's value"), 90 SYSCTL_DESCR("String property's value"),
91 NULL, 0, &prop_str_val, 0, 91 NULL, 0, &prop_str_val, 0,
92 CTL_VENDOR, K_HELPER, K_HELPER_PROP_STR_VAL, CTL_EOL); 92 CTL_VENDOR, K_HELPER, K_HELPER_PROP_STR_VAL, CTL_EOL);
93 93
94 sysctl_createv(clog, 0, NULL, NULL, 94 sysctl_createv(clog, 0, NULL, NULL,
95 CTLFLAG_PERMANENT, 95 CTLFLAG_PERMANENT,
96 CTLTYPE_INT, "prop_int_ok", 96 CTLTYPE_INT, "prop_int_ok",
97 SYSCTL_DESCR("String property's validity"), 97 SYSCTL_DESCR("String property's validity"),
98 NULL, 0, &prop_int_ok, 0, 98 NULL, 0, &prop_int_ok, 0,
99 CTL_VENDOR, K_HELPER, K_HELPER_PROP_INT_OK, CTL_EOL); 99 CTL_VENDOR, K_HELPER, K_HELPER_PROP_INT_OK, CTL_EOL);
100 100
101 sysctl_createv(clog, 0, NULL, NULL, 101 sysctl_createv(clog, 0, NULL, NULL,
102 CTLFLAG_PERMANENT, 102 CTLFLAG_PERMANENT,
103 CTLTYPE_QUAD, "prop_int_val", 103 CTLTYPE_QUAD, "prop_int_val",
104 SYSCTL_DESCR("String property's value"), 104 SYSCTL_DESCR("String property's value"),
105 NULL, 0, &prop_int_val, 0, 105 NULL, 0, &prop_int_val, 0,
106 CTL_VENDOR, K_HELPER, K_HELPER_PROP_INT_VAL, CTL_EOL); 106 CTL_VENDOR, K_HELPER, K_HELPER_PROP_INT_VAL, CTL_EOL);
107 107
108 sysctl_createv(clog, 0, NULL, NULL, 108 sysctl_createv(clog, 0, NULL, NULL,
109 CTLFLAG_PERMANENT, 109 CTLFLAG_PERMANENT,
110 CTLTYPE_INT, "prop_int_load", 110 CTLTYPE_INT, "prop_int_load",
111 SYSCTL_DESCR("Status of recursive modload"), 111 SYSCTL_DESCR("Status of recursive modload"),
112 NULL, 0, &prop_int_load, 0, 112 NULL, 0, &prop_int_load, 0,
113 CTL_VENDOR, K_HELPER, K_HELPER_PROP_INT_LOAD, CTL_EOL); 113 CTL_VENDOR, K_HELPER, K_HELPER_PROP_INT_LOAD, CTL_EOL);
114} 114}
115 115
116/* --------------------------------------------------------------------- */ 116/* --------------------------------------------------------------------- */
117/* Module management. */ 117/* Module management. */
118/* --------------------------------------------------------------------- */ 118/* --------------------------------------------------------------------- */
119 119
120static 120static
121int 121int
122k_helper_init(prop_dictionary_t props) 122k_helper_init(prop_dictionary_t props)
123{ 123{
124 prop_object_t p; 124 prop_object_t p;
125 125
126 p = prop_dictionary_get(props, "prop_str"); 126 p = prop_dictionary_get(props, "prop_str");
127 if (p == NULL) 127 if (p == NULL)
128 prop_str_ok = 0; 128 prop_str_ok = 0;
129 else if (prop_object_type(p) != PROP_TYPE_STRING) 129 else if (prop_object_type(p) != PROP_TYPE_STRING)
130 prop_str_ok = 0; 130 prop_str_ok = 0;
131 else { 131 else {
132 const char *msg = prop_string_cstring_nocopy(p); 132 const char *msg = prop_string_cstring_nocopy(p);
133 if (msg == NULL) 133 if (msg == NULL)
134 prop_str_ok = 0; 134 prop_str_ok = 0;
135 else { 135 else {
136 strlcpy(prop_str_val, msg, sizeof(prop_str_val)); 136 strlcpy(prop_str_val, msg, sizeof(prop_str_val));
137 prop_str_ok = 1; 137 prop_str_ok = 1;
138 } 138 }
139 } 139 }
140 if (!prop_str_ok) 140 if (!prop_str_ok)
141 strlcpy(prop_str_val, "", sizeof(prop_str_val)); 141 strlcpy(prop_str_val, "", sizeof(prop_str_val));
142 142
143 p = prop_dictionary_get(props, "prop_int"); 143 p = prop_dictionary_get(props, "prop_int");
144 if (p == NULL) 144 if (p == NULL)
145 prop_int_ok = 0; 145 prop_int_ok = 0;
146 else if (prop_object_type(p) != PROP_TYPE_NUMBER) 146 else if (prop_object_type(p) != PROP_TYPE_NUMBER)
147 prop_int_ok = 0; 147 prop_int_ok = 0;
148 else { 148 else {
149 prop_int_val = prop_number_integer_value(p); 149 prop_int_val = prop_number_integer_value(p);
150 prop_int_ok = 1; 150 prop_int_ok = 1;
151 } 151 }
152 if (!prop_int_ok) 152 if (!prop_int_ok)
153 prop_int_val = -1; 153 prop_int_val = -1;
154 154
155 p = prop_dictionary_get(props, "prop_recurse"); 155 p = prop_dictionary_get(props, "prop_recurse");
156 if (p != NULL && prop_object_type(p) == PROP_TYPE_STRING) { 156 if (p != NULL && prop_object_type(p) == PROP_TYPE_STRING) {
157 const char *recurse_name = prop_string_cstring_nocopy(p); 157 const char *recurse_name = prop_string_cstring_nocopy(p);
158 if (recurse_name != NULL) 158 if (recurse_name != NULL)
159 prop_int_load = module_load(recurse_name, 159 prop_int_load = module_load(recurse_name,
160 MODCTL_NO_PROP, NULL, MODULE_CLASS_ANY); 160 MODCTL_NO_PROP, NULL, MODULE_CLASS_ANY);
161 else 161 else
162 prop_int_load = -1; 162 prop_int_load = -1;
163 } else 163 } else
164 prop_int_load = -2; 164 prop_int_load = -2;
165 165
166 sysctl_k_helper_setup(&clog); 166 sysctl_k_helper_setup(&clogp);
167 167
168 return 0; 168 return 0;
169} 169}
170 170
171static 171static
172int 172int
173k_helper_fini(void *arg) 173k_helper_fini(void *arg)
174{ 174{
175 175
176 sysctl_teardown(&clog); 176 sysctl_teardown(&clogp);
177 177
178 return 0; 178 return 0;
179} 179}
180 180
181static 181static
182int 182int
183k_helper_modcmd(modcmd_t cmd, void *arg) 183k_helper_modcmd(modcmd_t cmd, void *arg)
184{ 184{
185 int ret; 185 int ret;
186 186
187 switch (cmd) { 187 switch (cmd) {
188 case MODULE_CMD_INIT: 188 case MODULE_CMD_INIT:
189 ret = k_helper_init(arg); 189 ret = k_helper_init(arg);
190 break; 190 break;
191 191
192 case MODULE_CMD_FINI: 192 case MODULE_CMD_FINI:
193 ret = k_helper_fini(arg); 193 ret = k_helper_fini(arg);
194 break; 194 break;
195 195
196 case MODULE_CMD_STAT: 196 case MODULE_CMD_STAT:
197 default: 197 default:
198 ret = ENOTTY; 198 ret = ENOTTY;
199 } 199 }
200 200
201 return ret; 201 return ret;
202} 202}

cvs diff -r1.1 -r1.2 src/tests/modules/k_helper2/k_helper2.c (switch to unified diff)

--- src/tests/modules/k_helper2/k_helper2.c 2010/08/21 13:21:48 1.1
+++ src/tests/modules/k_helper2/k_helper2.c 2010/11/03 16:10:23 1.2
@@ -1,115 +1,115 @@ @@ -1,115 +1,115 @@
1/* $NetBSD: k_helper2.c,v 1.1 2010/08/21 13:21:48 pgoyette Exp $ */ 1/* $NetBSD: k_helper2.c,v 1.2 2010/11/03 16:10:23 christos Exp $ */
2/* 2/*
3 * Copyright (c) 2010 The NetBSD Foundation, Inc. 3 * Copyright (c) 2010 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: k_helper2.c,v 1.1 2010/08/21 13:21:48 pgoyette Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: k_helper2.c,v 1.2 2010/11/03 16:10:23 christos Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/kernel.h> 33#include <sys/kernel.h>
34#include <sys/module.h> 34#include <sys/module.h>
35#include <sys/sysctl.h> 35#include <sys/sysctl.h>
36 36
37#include <prop/proplib.h> 37#include <prop/proplib.h>
38 38
39MODULE(MODULE_CLASS_MISC, k_helper2, NULL); 39MODULE(MODULE_CLASS_MISC, k_helper2, NULL);
40 40
41/* --------------------------------------------------------------------- */ 41/* --------------------------------------------------------------------- */
42/* Sysctl interface to query information about the module. */ 42/* Sysctl interface to query information about the module. */
43/* --------------------------------------------------------------------- */ 43/* --------------------------------------------------------------------- */
44 44
45/* TODO: Change the integer variables below that represent booleans to 45/* TODO: Change the integer variables below that represent booleans to
46 * bools, once sysctl(8) supports CTLTYPE_BOOL nodes. */ 46 * bools, once sysctl(8) supports CTLTYPE_BOOL nodes. */
47 47
48static struct sysctllog *clog; 48static struct sysctllog *clogp;
49static int present = 1; 49static int present = 1;
50 50
51#define K_HELPER2 0x23456781 51#define K_HELPER2 0x23456781
52#define K_HELPER_PRESENT 0 52#define K_HELPER_PRESENT 0
53 53
54SYSCTL_SETUP(sysctl_k_helper2_setup, "sysctl k_helper subtree setup") 54SYSCTL_SETUP(sysctl_k_helper2_setup, "sysctl k_helper subtree setup")
55{ 55{
56 56
57 sysctl_createv(clog, 0, NULL, NULL, 57 sysctl_createv(clog, 0, NULL, NULL,
58 CTLFLAG_PERMANENT, 58 CTLFLAG_PERMANENT,
59 CTLTYPE_NODE, "k_helper2", NULL, 59 CTLTYPE_NODE, "k_helper2", NULL,
60 NULL, 0, NULL, 0, 60 NULL, 0, NULL, 0,
61 CTL_VENDOR, K_HELPER2, CTL_EOL); 61 CTL_VENDOR, K_HELPER2, CTL_EOL);
62 62
63 sysctl_createv(clog, 0, NULL, NULL, 63 sysctl_createv(clog, 0, NULL, NULL,
64 CTLFLAG_PERMANENT, 64 CTLFLAG_PERMANENT,
65 CTLTYPE_INT, "present", 65 CTLTYPE_INT, "present",
66 SYSCTL_DESCR("Whether the module was loaded or not"), 66 SYSCTL_DESCR("Whether the module was loaded or not"),
67 NULL, 0, &present, 0, 67 NULL, 0, &present, 0,
68 CTL_VENDOR, K_HELPER2, K_HELPER_PRESENT, CTL_EOL); 68 CTL_VENDOR, K_HELPER2, K_HELPER_PRESENT, CTL_EOL);
69} 69}
70 70
71/* --------------------------------------------------------------------- */ 71/* --------------------------------------------------------------------- */
72/* Module management. */ 72/* Module management. */
73/* --------------------------------------------------------------------- */ 73/* --------------------------------------------------------------------- */
74 74
75static 75static
76int 76int
77k_helper2_init(prop_dictionary_t props) 77k_helper2_init(prop_dictionary_t props)
78{ 78{
79 sysctl_k_helper2_setup(&clog); 79 sysctl_k_helper2_setup(&clogp);
80 80
81 return 0; 81 return 0;
82} 82}
83 83
84static 84static
85int 85int
86k_helper2_fini(void *arg) 86k_helper2_fini(void *arg)
87{ 87{
88 88
89 sysctl_teardown(&clog); 89 sysctl_teardown(&clogp);
90 90
91 return 0; 91 return 0;
92} 92}
93 93
94static 94static
95int 95int
96k_helper2_modcmd(modcmd_t cmd, void *arg) 96k_helper2_modcmd(modcmd_t cmd, void *arg)
97{ 97{
98 int ret; 98 int ret;
99 99
100 switch (cmd) { 100 switch (cmd) {
101 case MODULE_CMD_INIT: 101 case MODULE_CMD_INIT:
102 ret = k_helper2_init(arg); 102 ret = k_helper2_init(arg);
103 break; 103 break;
104 104
105 case MODULE_CMD_FINI: 105 case MODULE_CMD_FINI:
106 ret = k_helper2_fini(arg); 106 ret = k_helper2_fini(arg);
107 break; 107 break;
108 108
109 case MODULE_CMD_STAT: 109 case MODULE_CMD_STAT:
110 default: 110 default:
111 ret = ENOTTY; 111 ret = ENOTTY;
112 } 112 }
113 113
114 return ret; 114 return ret;
115} 115}

File Added: src/tests/net/Makefile.inc
.include "../Makefile.inc"

cvs diff -r1.2 -r1.3 src/tests/net/bpf/t_div-by-zero.c (switch to unified diff)

--- src/tests/net/bpf/t_div-by-zero.c 2010/04/21 11:19:44 1.2
+++ src/tests/net/bpf/t_div-by-zero.c 2010/11/03 16:10:24 1.3
@@ -1,53 +1,53 @@ @@ -1,53 +1,53 @@
1#include <sys/types.h> 1#include <sys/types.h>
2#include <sys/ioctl.h> 2#include <sys/ioctl.h>
3 3
4#include <net/bpf.h> 4#include <net/bpf.h>
5 5
6#include <atf-c.h> 6#include <atf-c.h>
7#include <fcntl.h> 7#include <fcntl.h>
8 8
9#include <rump/rump.h> 9#include <rump/rump.h>
10#include <rump/rumpuser.h> 10#include <rump/rumpuser.h>
 11#include <rump/rump_syscalls.h>
11 12
12ATF_TC(div_by_zero); 13ATF_TC(div_by_zero);
13ATF_TC_HEAD(div_by_zero, tc) 14ATF_TC_HEAD(div_by_zero, tc)
14{ 15{
15 16
16 atf_tc_set_md_var(tc, "descr", "Check that BPF rejects a filter " 17 atf_tc_set_md_var(tc, "descr", "Check that BPF rejects a filter "
17 "which divides by 0"); 18 "which divides by 0");
18} 19}
19 20
20ATF_TC_BODY(div_by_zero, tc) 21ATF_TC_BODY(div_by_zero, tc)
21{ 22{
22 struct bpf_program bp; 23 struct bpf_program bp;
23 int fd; 24 int fd;
24 25
25 /* 26 /*
26 * Source code for following program: 27 * Source code for following program:
27 * link[0:4]/0 = 2 28 * link[0:4]/0 = 2
28 */ 29 */
29 struct bpf_insn bins[] = { 30 struct bpf_insn bins[] = {
30 { 0x20, 0, 0, 0x00000000 }, 31 { 0x20, 0, 0, 0x00000000 },
31 { 0x34, 0, 0, 0x00000000 }, 32 { 0x34, 0, 0, 0x00000000 },
32 { 0x15, 0, 1, 0x00000002 }, 33 { 0x15, 0, 1, 0x00000002 },
33 { 0x6, 0, 0, 0x00000060 }, 34 { 0x6, 0, 0, 0x00000060 },
34 { 0x6, 0, 0, 0x00000000 }, 35 { 0x6, 0, 0, 0x00000000 },
35 }; 36 };
36 37
37 bp.bf_len = __arraycount(bins); 38 bp.bf_len = __arraycount(bins);
38 bp.bf_insns = bins; 39 bp.bf_insns = bins;
39 40
40 rump_init(); 41 rump_init();
41 fd = rump_sys_open("/dev/bpf", O_RDWR); 42 fd = rump_sys_open("/dev/bpf", O_RDWR);
42 if (fd == -1) 43 ATF_CHECK(fd != -1);
43 err(1, "open bpf"); 
44 ATF_REQUIRE_EQ_MSG(rump_sys_ioctl(fd, BIOCSETF, &bp), -1, 44 ATF_REQUIRE_EQ_MSG(rump_sys_ioctl(fd, BIOCSETF, &bp), -1,
45 "bpf accepted program with division by zero"); 45 "bpf accepted program with division by zero");
46} 46}
47 47
48ATF_TP_ADD_TCS(tp) 48ATF_TP_ADD_TCS(tp)
49{ 49{
50 50
51 ATF_TP_ADD_TC(tp, div_by_zero); 51 ATF_TP_ADD_TC(tp, div_by_zero);
52 return atf_no_error(); 52 return atf_no_error();
53} 53}

cvs diff -r1.2 -r1.3 src/tests/net/carp/Attic/t_basic.c (switch to unified diff)

--- src/tests/net/carp/Attic/t_basic.c 2010/08/11 13:10:03 1.2
+++ src/tests/net/carp/Attic/t_basic.c 2010/11/03 16:10:24 1.3
@@ -1,220 +1,221 @@ @@ -1,220 +1,221 @@
1/* $NetBSD: t_basic.c,v 1.2 2010/08/11 13:10:03 pooka Exp $ */ 1/* $NetBSD: t_basic.c,v 1.3 2010/11/03 16:10:24 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31#ifndef lint 31#ifndef lint
32__RCSID("$NetBSD: t_basic.c,v 1.2 2010/08/11 13:10:03 pooka Exp $"); 32__RCSID("$NetBSD: t_basic.c,v 1.3 2010/11/03 16:10:24 christos Exp $");
33#endif /* not lint */ 33#endif /* not lint */
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/socket.h> 36#include <sys/socket.h>
 37#include <sys/wait.h>
37 38
38#include <netinet/in.h> 39#include <netinet/in.h>
39#include <netinet/in_systm.h> 40#include <netinet/in_systm.h>
40#include <netinet/ip_carp.h> 41#include <netinet/ip_carp.h>
41 42
42#include <rump/rump.h> 43#include <rump/rump.h>
43#include <rump/rump_syscalls.h> 44#include <rump/rump_syscalls.h>
44 45
45#include <atf-c.h> 46#include <atf-c.h>
46#include <errno.h> 47#include <errno.h>
47#include <stdio.h> 48#include <stdio.h>
48#include <stdlib.h> 49#include <stdlib.h>
49#include <string.h> 50#include <string.h>
50#include <unistd.h> 51#include <unistd.h>
51 52
52#include "../config/netconfig.c" 53#include "../config/netconfig.c"
53#include "../../h_macros.h" 54#include "../../h_macros.h"
54 55
55static bool oknow = false; 56static bool oknow = false;
56 57
57static void 58static void
58sighnd(int sig) 59sighnd(int sig)
59{ 60{
60 61
61 ATF_REQUIRE_EQ(sig, SIGCHLD); 62 ATF_REQUIRE_EQ(sig, SIGCHLD);
62 if (oknow) 63 if (oknow)
63 return; 64 return;
64 65
65 atf_tc_fail("child died unexpectedly"); 66 atf_tc_fail("child died unexpectedly");
66} 67}
67 68
68ATF_TC(handover); 69ATF_TC(handover);
69ATF_TC_HEAD(handover, tc) 70ATF_TC_HEAD(handover, tc)
70{ 71{
71 72
72 atf_tc_set_md_var(tc, "descr", "check that carp handover works if " 73 atf_tc_set_md_var(tc, "descr", "check that carp handover works if "
73 "the master dies"); 74 "the master dies");
74 atf_tc_set_md_var(tc, "use.fs", "true"); 75 atf_tc_set_md_var(tc, "use.fs", "true");
75} 76}
76 77
77#define THEBUS "buuuuuuus,etherbus" 78#define THEBUS "buuuuuuus,etherbus"
78 79
79static void 80static void
80child(bool master) 81child(bool master)
81{ 82{
82 char ifname[IFNAMSIZ]; 83 char ifname[IFNAMSIZ];
83 struct carpreq cr; 84 struct carpreq cr;
84 struct ifreq ifr; 85 struct ifreq ifr;
85 const char *carpif; 86 const char *carpif;
86 int s; 87 int s;
87 88
88 /* helps reading carp debug output */ 89 /* helps reading carp debug output */
89 if (master) 90 if (master)
90 carpif = "carp0"; 91 carpif = "carp0";
91 else 92 else
92 carpif = "carp1"; 93 carpif = "carp1";
93 94
94 /* 95 /*
95 * Should use sysctl, bug debug is dabug. 96 * Should use sysctl, bug debug is dabug.
96 */ 97 */
97 { 98 {
98 //extern int rumpns_carp_opts[]; /* XXX */ 99 //extern int rumpns_carp_opts[]; /* XXX */
99 //rumpns_carp_opts[CARPCTL_LOG] = 1; 100 //rumpns_carp_opts[CARPCTL_LOG] = 1;
100 } 101 }
101 102
102 103
103 rump_init(); 104 rump_init();
104 105
105 memset(&ifr, 0, sizeof(ifr)); 106 memset(&ifr, 0, sizeof(ifr));
106 strlcpy(ifr.ifr_name, carpif, sizeof(ifr.ifr_name)); 107 strlcpy(ifr.ifr_name, carpif, sizeof(ifr.ifr_name));
107 108
108 RL(s = rump_sys_socket(PF_INET, SOCK_DGRAM, 0)); 109 RL(s = rump_sys_socket(PF_INET, SOCK_DGRAM, 0));
109 RL(rump_sys_ioctl(s, SIOCIFCREATE, &ifr)); 110 RL(rump_sys_ioctl(s, SIOCIFCREATE, &ifr));
110 111
111 netcfg_rump_makeshmif(THEBUS, ifname); 112 netcfg_rump_makeshmif(THEBUS, ifname);
112 113
113 if (master) 114 if (master)
114 netcfg_rump_if(ifname, "10.1.1.1", "255.255.255.0"); 115 netcfg_rump_if(ifname, "10.1.1.1", "255.255.255.0");
115 else 116 else
116 netcfg_rump_if(ifname, "10.1.1.2", "255.255.255.0"); 117 netcfg_rump_if(ifname, "10.1.1.2", "255.255.255.0");
117 118
118 /* configure the carp interface */ 119 /* configure the carp interface */
119 ifr.ifr_data = &cr; 120 ifr.ifr_data = &cr;
120 RL(rump_sys_ioctl(s, SIOCGVH, &ifr)); 121 RL(rump_sys_ioctl(s, SIOCGVH, &ifr));
121 122
122 strlcpy(cr.carpr_carpdev, ifname, sizeof(cr.carpr_carpdev)); 123 strlcpy(cr.carpr_carpdev, ifname, sizeof(cr.carpr_carpdev));
123 cr.carpr_vhid = 175; 124 cr.carpr_vhid = 175;
124 if (master) 125 if (master)
125 cr.carpr_advskew = 0; 126 cr.carpr_advskew = 0;
126 else 127 else
127 cr.carpr_advskew = 200; 128 cr.carpr_advskew = 200;
128 cr.carpr_advbase = 1; 129 cr.carpr_advbase = 1;
129 strcpy(cr.carpr_key, "s3cret"); 130 strcpy((char *)cr.carpr_key, "s3cret");
130 131
131 RL(rump_sys_ioctl(s, SIOCSVH, &ifr)); 132 RL(rump_sys_ioctl(s, SIOCSVH, &ifr));
132 netcfg_rump_if(carpif, "10.1.1.100", "255.255.255.0"); 133 netcfg_rump_if(carpif, "10.1.1.100", "255.255.255.0");
133 134
134 /* tassa pause()en enka muuta voi */ 135 /* tassa pause()en enka muuta voi */
135 pause(); 136 pause();
136} 137}
137 138
138ATF_TC_BODY(handover, tc) 139ATF_TC_BODY(handover, tc)
139{ 140{
140 char ifname[IFNAMSIZ]; 141 char ifname[IFNAMSIZ];
141 pid_t mpid, cpid; 142 pid_t mpid, cpid;
142 int i, status; 143 int i, status;
143 144
144 signal(SIGCHLD, sighnd); 145 signal(SIGCHLD, sighnd);
145 146
146 /* fork master */ 147 /* fork master */
147 switch (mpid = fork()) { 148 switch (mpid = fork()) {
148 case -1: 149 case -1:
149 atf_tc_fail_errno("fork failed"); 150 atf_tc_fail_errno("fork failed");
150 /*NOTREACHED*/ 151 /*NOTREACHED*/
151 case 0: 152 case 0:
152 child(true); 153 child(true);
153 /*NOTREACHED*/ 154 /*NOTREACHED*/
154 default: 155 default:
155 break; 156 break;
156 } 157 }
157 158
158 usleep(500000); 159 usleep(500000);
159 160
160 /* fork backup */ 161 /* fork backup */
161 switch (cpid = fork()) { 162 switch (cpid = fork()) {
162 case -1: 163 case -1:
163 kill(mpid, SIGKILL); 164 kill(mpid, SIGKILL);
164 atf_tc_fail_errno("fork failed"); 165 atf_tc_fail_errno("fork failed");
165 /*NOTREACHED*/ 166 /*NOTREACHED*/
166 case 0: 167 case 0:
167 child(false); 168 child(false);
168 /*NOTREACHED*/ 169 /*NOTREACHED*/
169 default: 170 default:
170 break; 171 break;
171 } 172 }
172 173
173 usleep(500000); 174 usleep(500000);
174 175
175 rump_init(); 176 rump_init();
176 netcfg_rump_makeshmif(THEBUS, ifname); 177 netcfg_rump_makeshmif(THEBUS, ifname);
177 netcfg_rump_if(ifname, "10.1.1.240", "255.255.255.0"); 178 netcfg_rump_if(ifname, "10.1.1.240", "255.255.255.0");
178 179
179 /* check that the primary addresses are up */ 180 /* check that the primary addresses are up */
180 ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.1", 1000), true); 181 ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.1", 1000), true);
181 ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.2", 1000), true); 182 ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.2", 1000), true);
182 183
183 /* give carp a while to croak */ 184 /* give carp a while to croak */
184 sleep(4); 185 sleep(4);
185 186
186 /* check that the shared IP works */ 187 /* check that the shared IP works */
187 ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.100", 500), true); 188 ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.100", 500), true);
188 189
189 /* KILLING SPREE */ 190 /* KILLING SPREE */
190 oknow = true; 191 oknow = true;
191 kill(mpid, SIGKILL); 192 kill(mpid, SIGKILL);
192 wait(&status); 193 wait(&status);
193 usleep(10000); /* just in case */ 194 usleep(10000); /* just in case */
194 oknow = false; 195 oknow = false;
195 196
196 /* check that primary is now dead */ 197 /* check that primary is now dead */
197 ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.1", 100), false); 198 ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.1", 100), false);
198 199
199 /* do it in installments. carp will cluck meanwhile */ 200 /* do it in installments. carp will cluck meanwhile */
200 for (i = 0; i < 5; i++) { 201 for (i = 0; i < 5; i++) {
201 if (netcfg_rump_pingtest("10.1.1.100", 1000) == true) 202 if (netcfg_rump_pingtest("10.1.1.100", 1000) == true)
202 break; 203 break;
203 } 204 }
204 if (i == 5) 205 if (i == 5)
205 atf_tc_fail("failed to failover"); 206 atf_tc_fail("failed to failover");
206 207
207 /* to kill the child */ 208 /* to kill the child */
208 oknow = true; 209 oknow = true;
209 kill(cpid, SIGKILL); 210 kill(cpid, SIGKILL);
210 211
211 /* clean & done */ 212 /* clean & done */
212} 213}
213 214
214ATF_TP_ADD_TCS(tp) 215ATF_TP_ADD_TCS(tp)
215{ 216{
216 217
217 ATF_TP_ADD_TC(tp, handover); 218 ATF_TP_ADD_TC(tp, handover);
218 219
219 return atf_no_error(); 220 return atf_no_error();
220} 221}

cvs diff -r1.5 -r1.6 src/tests/net/icmp/t_forward.c (switch to unified diff)

--- src/tests/net/icmp/t_forward.c 2010/07/26 14:10:31 1.5
+++ src/tests/net/icmp/t_forward.c 2010/11/03 16:10:24 1.6
@@ -1,172 +1,171 @@ @@ -1,172 +1,171 @@
1/* $NetBSD: t_forward.c,v 1.5 2010/07/26 14:10:31 pooka Exp $ */ 1/* $NetBSD: t_forward.c,v 1.6 2010/11/03 16:10:24 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31#ifndef lint 31#ifndef lint
32__RCSID("$NetBSD: t_forward.c,v 1.5 2010/07/26 14:10:31 pooka Exp $"); 32__RCSID("$NetBSD: t_forward.c,v 1.6 2010/11/03 16:10:24 christos Exp $");
33#endif /* not lint */ 33#endif /* not lint */
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/socket.h> 36#include <sys/socket.h>
37#include <sys/time.h> 37#include <sys/time.h>
38#include <sys/sysctl.h> 38#include <sys/sysctl.h>
39#include <sys/wait.h> 39#include <sys/wait.h>
40 40
41#include <arpa/inet.h> 41#include <arpa/inet.h>
42 42
43#include <netinet/in.h> 43#include <netinet/in.h>
44#include <netinet/in_systm.h> 44#include <netinet/in_systm.h>
45#include <netinet/ip.h> 45#include <netinet/ip.h>
46#include <netinet/ip_icmp.h> 46#include <netinet/ip_icmp.h>
47#include <netinet/icmp_var.h> 47#include <netinet/icmp_var.h>
48#include <net/route.h> 48#include <net/route.h>
49 49
50#include <rump/rump.h> 50#include <rump/rump.h>
51#include <rump/rump_syscalls.h> 51#include <rump/rump_syscalls.h>
52 52
53#include <atf-c.h> 53#include <atf-c.h>
54#include <errno.h> 54#include <errno.h>
55#include <stdio.h> 55#include <stdio.h>
56#include <stdlib.h> 56#include <stdlib.h>
57#include <string.h> 57#include <string.h>
58#include <unistd.h> 58#include <unistd.h>
59 59
60#include "../../h_macros.h" 60#include "../../h_macros.h"
61#include "../config/netconfig.c" 61#include "../config/netconfig.c"
62 62
63/* 63/*
64 * Since our maxttl is in our private namespace, we don't need raw packet 64 * Since our maxttl is in our private namespace, we don't need raw packet
65 * construction like traceroute(8) -- we can just use the global maxttl. 65 * construction like traceroute(8) -- we can just use the global maxttl.
66 */ 66 */
67static void 67static void
68sendttl(void) 68sendttl(void)
69{ 69{
70 extern int rumpns_ip_defttl; 
71 struct sockaddr_in sin; 70 struct sockaddr_in sin;
72 char payload[1024]; 71 char payload[1024];
73 char ifname[IFNAMSIZ]; 72 char ifname[IFNAMSIZ];
74 int mib[4] = { CTL_NET, PF_INET, IPPROTO_IP, IPCTL_DEFTTL }; 73 int mib[4] = { CTL_NET, PF_INET, IPPROTO_IP, IPCTL_DEFTTL };
75 int nv; 74 int nv;
76 int s; 75 int s;
77 76
78 netcfg_rump_makeshmif("bus1", ifname); 77 netcfg_rump_makeshmif("bus1", ifname);
79 netcfg_rump_if(ifname, "1.0.0.1", "255.255.255.0"); 78 netcfg_rump_if(ifname, "1.0.0.1", "255.255.255.0");
80 netcfg_rump_route("0.0.0.0", "0.0.0.0", "1.0.0.2"); /* default router */ 79 netcfg_rump_route("0.0.0.0", "0.0.0.0", "1.0.0.2"); /* default router */
81 80
82 /* set global ttl to 1 */ 81 /* set global ttl to 1 */
83 nv = 1; 82 nv = 1;
84 if (rump_sys___sysctl(mib, 4, NULL, NULL, &nv, sizeof(nv)) == -1) 83 if (rump_sys___sysctl(mib, 4, NULL, NULL, &nv, sizeof(nv)) == -1)
85 atf_tc_fail_errno("set ttl"); 84 atf_tc_fail_errno("set ttl");
86 85
87 s = rump_sys_socket(PF_INET, SOCK_DGRAM, 0); 86 s = rump_sys_socket(PF_INET, SOCK_DGRAM, 0);
88 if (s == -1) 87 if (s == -1)
89 atf_tc_fail_errno("create send socket"); 88 atf_tc_fail_errno("create send socket");
90 89
91 memset(&sin, 0, sizeof(sin)); 90 memset(&sin, 0, sizeof(sin));
92 sin.sin_len = sizeof(sin); 91 sin.sin_len = sizeof(sin);
93 sin.sin_family = AF_INET; 92 sin.sin_family = AF_INET;
94 sin.sin_port = htons(33434); 93 sin.sin_port = htons(33434);
95 sin.sin_addr.s_addr = inet_addr("9.9.9.9"); 94 sin.sin_addr.s_addr = inet_addr("9.9.9.9");
96 95
97 /* send udp datagram with ttl == 1 */ 96 /* send udp datagram with ttl == 1 */
98 if (rump_sys_sendto(s, payload, sizeof(payload), 0, 97 if (rump_sys_sendto(s, payload, sizeof(payload), 0,
99 (struct sockaddr *)&sin, sizeof(sin)) == -1) 98 (struct sockaddr *)&sin, sizeof(sin)) == -1)
100 atf_tc_fail_errno("sendto"); 99 atf_tc_fail_errno("sendto");
101} 100}
102 101
103static void 102static void
104router(void) 103router(void)
105{ 104{
106 int mib[4] = { CTL_NET, PF_INET, IPPROTO_ICMP, 105 int mib[4] = { CTL_NET, PF_INET, IPPROTO_ICMP,
107 ICMPCTL_RETURNDATABYTES }; 106 ICMPCTL_RETURNDATABYTES };
108 char ifname[IFNAMSIZ]; 107 char ifname[IFNAMSIZ];
109 int nv; 108 int nv;
110 109
111 /* set returndatabytes to 200 */ 110 /* set returndatabytes to 200 */
112 nv = 200; 111 nv = 200;
113 if (rump_sys___sysctl(mib, 4, NULL, NULL, &nv, sizeof(nv)) == -1) 112 if (rump_sys___sysctl(mib, 4, NULL, NULL, &nv, sizeof(nv)) == -1)
114 atf_tc_fail_errno("sysctl returndatabytes"); 113 atf_tc_fail_errno("sysctl returndatabytes");
115 114
116 netcfg_rump_makeshmif("bus1", ifname); 115 netcfg_rump_makeshmif("bus1", ifname);
117 netcfg_rump_if(ifname, "1.0.0.2", "255.255.255.0"); 116 netcfg_rump_if(ifname, "1.0.0.2", "255.255.255.0");
118 117
119 /* 118 /*
120 * Wait for parent to send us the data and for us to have 119 * Wait for parent to send us the data and for us to have
121 * a chance to process it. 120 * a chance to process it.
122 */ 121 */
123 sleep(1); 122 sleep(1);
124 exit(0); 123 exit(0);
125} 124}
126 125
127ATF_TC(returndatabytes); 126ATF_TC(returndatabytes);
128ATF_TC_HEAD(returndatabytes, tc) 127ATF_TC_HEAD(returndatabytes, tc)
129{ 128{
130 129
131 atf_tc_set_md_var(tc, "descr", "icmp.returndatabytes with certain " 130 atf_tc_set_md_var(tc, "descr", "icmp.returndatabytes with certain "
132 "packets can cause kernel panic"); 131 "packets can cause kernel panic");
133 atf_tc_set_md_var(tc, "use.fs", "true"); 132 atf_tc_set_md_var(tc, "use.fs", "true");
134 atf_tc_set_md_var(tc, "timeout", "4"); /* just in case */ 133 atf_tc_set_md_var(tc, "timeout", "4"); /* just in case */
135 /* PR kern/43548 */ 134 /* PR kern/43548 */
136} 135}
137 136
138ATF_TC_BODY(returndatabytes, tc) 137ATF_TC_BODY(returndatabytes, tc)
139{ 138{
140 pid_t cpid; 139 pid_t cpid;
141 int status; 140 int status;
142 141
143 cpid = fork(); 142 cpid = fork();
144 rump_init(); 143 rump_init();
145 144
146 switch (cpid) { 145 switch (cpid) {
147 case -1: 146 case -1:
148 atf_tc_fail_errno("fork failed"); 147 atf_tc_fail_errno("fork failed");
149 case 0: 148 case 0:
150 router(); 149 router();
151 break; 150 break;
152 default: 151 default:
153 sendttl(); 152 sendttl();
154 if (wait(&status) == -1) 153 if (wait(&status) == -1)
155 atf_tc_fail_errno("wait"); 154 atf_tc_fail_errno("wait");
156 if (WIFEXITED(status)) { 155 if (WIFEXITED(status)) {
157 if (WEXITSTATUS(status)) 156 if (WEXITSTATUS(status))
158 atf_tc_fail("child exited with status %d", 157 atf_tc_fail("child exited with status %d",
159 WEXITSTATUS(status)); 158 WEXITSTATUS(status));
160 } else { 159 } else {
161 atf_tc_fail("child died"); 160 atf_tc_fail("child died");
162 } 161 }
163 } 162 }
164} 163}
165 164
166ATF_TP_ADD_TCS(tp) 165ATF_TP_ADD_TCS(tp)
167{ 166{
168 167
169 ATF_TP_ADD_TC(tp, returndatabytes); 168 ATF_TP_ADD_TC(tp, returndatabytes);
170 169
171 return atf_no_error(); 170 return atf_no_error();
172} 171}

cvs diff -r1.8 -r1.9 src/tests/net/icmp/t_ping.c (switch to unified diff)

--- src/tests/net/icmp/t_ping.c 2010/08/26 17:24:14 1.8
+++ src/tests/net/icmp/t_ping.c 2010/11/03 16:10:24 1.9
@@ -1,430 +1,430 @@ @@ -1,430 +1,430 @@
1/* $NetBSD: t_ping.c,v 1.8 2010/08/26 17:24:14 pooka Exp $ */ 1/* $NetBSD: t_ping.c,v 1.9 2010/11/03 16:10:24 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31#ifndef lint 31#ifndef lint
32__RCSID("$NetBSD: t_ping.c,v 1.8 2010/08/26 17:24:14 pooka Exp $"); 32__RCSID("$NetBSD: t_ping.c,v 1.9 2010/11/03 16:10:24 christos Exp $");
33#endif /* not lint */ 33#endif /* not lint */
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/resource.h> 36#include <sys/resource.h>
37#include <sys/sysctl.h> 37#include <sys/sysctl.h>
38#include <sys/wait.h> 38#include <sys/wait.h>
39 39
40#include <atf-c.h> 40#include <atf-c.h>
41#include <assert.h> 41#include <assert.h>
42#include <fcntl.h> 42#include <fcntl.h>
43#include <stdio.h> 43#include <stdio.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <string.h> 45#include <string.h>
46#include <unistd.h> 46#include <unistd.h>
47 47
48#include <netinet/in.h> 48#include <netinet/in.h>
49#include <netinet/ip_var.h> 49#include <netinet/ip_var.h>
50 50
51#include <rump/rump.h> 51#include <rump/rump.h>
52#include <rump/rump_syscalls.h> 52#include <rump/rump_syscalls.h>
53 53
54#include "../../h_macros.h" 54#include "../../h_macros.h"
55#include "../config/netconfig.c" 55#include "../config/netconfig.c"
56 56
57ATF_TC(simpleping); 57ATF_TC(simpleping);
58ATF_TC_HEAD(simpleping, tc) 58ATF_TC_HEAD(simpleping, tc)
59{ 59{
60 60
61 atf_tc_set_md_var(tc, "descr", "check that kernel responds to ping"); 61 atf_tc_set_md_var(tc, "descr", "check that kernel responds to ping");
62 atf_tc_set_md_var(tc, "use.fs", "true"); 62 atf_tc_set_md_var(tc, "use.fs", "true");
63 atf_tc_set_md_var(tc, "timeout", "2"); 63 atf_tc_set_md_var(tc, "timeout", "2");
64} 64}
65 65
66ATF_TC_BODY(simpleping, tc) 66ATF_TC_BODY(simpleping, tc)
67{ 67{
68 char ifname[IFNAMSIZ]; 68 char ifname[IFNAMSIZ];
69 pid_t cpid; 69 pid_t cpid;
70 bool win, win2; 70 bool win, win2;
71 71
72 cpid = fork(); 72 cpid = fork();
73 rump_init(); 73 rump_init();
74 netcfg_rump_makeshmif("but-can-i-buy-your-ether-bus", ifname); 74 netcfg_rump_makeshmif("but-can-i-buy-your-ether-bus", ifname);
75 75
76 switch (cpid) { 76 switch (cpid) {
77 case -1: 77 case -1:
78 atf_tc_fail_errno("fork failed"); 78 atf_tc_fail_errno("fork failed");
79 case 0: 79 case 0:
80 netcfg_rump_if(ifname, "1.1.1.10", "255.255.255.0"); 80 netcfg_rump_if(ifname, "1.1.1.10", "255.255.255.0");
81 pause(); 81 pause();
82 break; 82 break;
83 default: 83 default:
84 break; 84 break;
85 } 85 }
86 86
87 usleep(500000); 87 usleep(500000);
88 88
89 netcfg_rump_if(ifname, "1.1.1.20", "255.255.255.0"); 89 netcfg_rump_if(ifname, "1.1.1.20", "255.255.255.0");
90 90
91 /* 91 /*
92 * The beauty of shmif is that we don't have races here. 92 * The beauty of shmif is that we don't have races here.
93 */ 93 */
94 win = netcfg_rump_pingtest("1.1.1.10", 500); 94 win = netcfg_rump_pingtest("1.1.1.10", 500);
95 win2 = netcfg_rump_pingtest("1.1.1.30", 500); 95 win2 = netcfg_rump_pingtest("1.1.1.30", 500);
96 96
97 kill(cpid, SIGKILL); 97 kill(cpid, SIGKILL);
98 98
99 if (!win) 99 if (!win)
100 atf_tc_fail("ping failed"); 100 atf_tc_fail("ping failed");
101 if (win2) 101 if (win2)
102 atf_tc_fail("non-existent host responded"); 102 atf_tc_fail("non-existent host responded");
103} 103}
104 104
105ATF_TC(floodping); 105ATF_TC(floodping);
106ATF_TC_HEAD(floodping, tc) 106ATF_TC_HEAD(floodping, tc)
107{ 107{
108 108
109 atf_tc_set_md_var(tc, "descr", "see how kernel responds to floodping"); 109 atf_tc_set_md_var(tc, "descr", "see how kernel responds to floodping");
110 atf_tc_set_md_var(tc, "use.fs", "true"); 110 atf_tc_set_md_var(tc, "use.fs", "true");
111} 111}
112 112
113/* why the hell isn't this available in userspace??? */ 113/* why the hell isn't this available in userspace??? */
114static uint16_t 114static uint16_t
115in_cksum(void *data, size_t len) 115in_cksum(void *data, size_t len)
116{ 116{
117 uint16_t *buf = data; 117 uint16_t *buf = data;
118 unsigned sum; 118 unsigned sum;
119 119
120 for (sum = 0; len > 1; len -= 2) 120 for (sum = 0; len > 1; len -= 2)
121 sum += *buf++; 121 sum += *buf++;
122 if (len) 122 if (len)
123 sum += *(uint8_t *)buf; 123 sum += *(uint8_t *)buf;
124 124
125 sum = (sum >> 16) + (sum & 0xffff); 125 sum = (sum >> 16) + (sum & 0xffff);
126 sum += (sum >> 16); 126 sum += (sum >> 16);
127 127
128 return ~sum; 128 return ~sum;
129} 129}
130 130
131static int 131static int
132doping(const char *target, int loops, int pktsize) 132doping(const char *target, int loops, size_t pktsize)
133{ 133{
134 char sndbuf[IP_MAXPACKET - sizeof(struct ip)]; 134 char sndbuf[IP_MAXPACKET - sizeof(struct ip)];
135 char recvbuf[IP_MAXPACKET]; 135 char recvbuf[IP_MAXPACKET];
136 struct sockaddr_in dst, pingee; 136 struct sockaddr_in dst, pingee;
137 struct icmp *icmp; 137 struct icmp *icmp;
138 socklen_t slen; 138 socklen_t slen;
139 ssize_t n; 139 ssize_t n;
140 int loop, i, succ; 140 int loop, succ;
141 int x, xnon, s; 141 int x, xnon, s;
142 142
143 RL(s = rump_sys_socket(PF_INET, SOCK_RAW, IPPROTO_ICMP)); 143 RL(s = rump_sys_socket(PF_INET, SOCK_RAW, IPPROTO_ICMP));
144 RL(x = rump_sys_fcntl(s, F_GETFL, 0)); 144 RL(x = rump_sys_fcntl(s, F_GETFL, 0));
145 xnon = x | O_NONBLOCK; 145 xnon = x | O_NONBLOCK;
146 146
147 memset(&dst, 0, sizeof(dst)); 147 memset(&dst, 0, sizeof(dst));
148 dst.sin_len = sizeof(dst); 148 dst.sin_len = sizeof(dst);
149 dst.sin_family = AF_INET; 149 dst.sin_family = AF_INET;
150 dst.sin_addr.s_addr = inet_addr(target); 150 dst.sin_addr.s_addr = inet_addr(target);
151 151
152 icmp = (struct icmp *)sndbuf; 152 icmp = (struct icmp *)sndbuf;
153 memset(icmp, 0, sizeof(*icmp)); 153 memset(icmp, 0, sizeof(*icmp));
154 icmp->icmp_type = ICMP_ECHO; 154 icmp->icmp_type = ICMP_ECHO;
155 icmp->icmp_id = htons(37); 155 icmp->icmp_id = htons(37);
156 156
157 if (pktsize < sizeof(*icmp)) 157 if (pktsize < sizeof(*icmp))
158 pktsize = sizeof(*icmp); 158 pktsize = sizeof(*icmp);
159 if (pktsize > sizeof(sndbuf)) 159 if (pktsize > sizeof(sndbuf))
160 pktsize = sizeof(sndbuf); 160 pktsize = sizeof(sndbuf);
161 161
162 RL(rump_sys_setsockopt(s, SOL_SOCKET, SO_SNDBUF, 162 RL(rump_sys_setsockopt(s, SOL_SOCKET, SO_SNDBUF,
163 &pktsize, sizeof(pktsize))); 163 &pktsize, sizeof(pktsize)));
164 RL(rump_sys_setsockopt(s, SOL_SOCKET, SO_RCVBUF, 164 RL(rump_sys_setsockopt(s, SOL_SOCKET, SO_RCVBUF,
165 &pktsize, sizeof(pktsize))); 165 &pktsize, sizeof(pktsize)));
166 166
167 slen = sizeof(pingee); 167 slen = sizeof(pingee);
168 succ = 0; 168 succ = 0;
169 for (loop = 0; loop < loops; loop++) { 169 for (loop = 0; loop < loops; loop++) {
170 RL(rump_sys_fcntl(s, F_SETFL, x)); 170 RL(rump_sys_fcntl(s, F_SETFL, x));
171 icmp->icmp_seq = htons(loop); 171 icmp->icmp_seq = htons(loop);
172 icmp->icmp_cksum = 0; 172 icmp->icmp_cksum = 0;
173 icmp->icmp_cksum = in_cksum(icmp, pktsize); 173 icmp->icmp_cksum = in_cksum(icmp, pktsize);
174 RL(rump_sys_sendto(s, icmp, pktsize, 0, 174 RL(rump_sys_sendto(s, icmp, pktsize, 0,
175 (struct sockaddr *)&dst, sizeof(dst))); 175 (struct sockaddr *)&dst, sizeof(dst)));
176 176
177 RL(rump_sys_fcntl(s, F_SETFL, xnon)); 177 RL(rump_sys_fcntl(s, F_SETFL, xnon));
178 while ((n = rump_sys_recvfrom(s, recvbuf, sizeof(recvbuf), 0, 178 while ((n = rump_sys_recvfrom(s, recvbuf, sizeof(recvbuf), 0,
179 (struct sockaddr *)&pingee, &slen)) > 0) { 179 (struct sockaddr *)&pingee, &slen)) > 0) {
180 succ++; 180 succ++;
181 } 181 }
182 if (n == -1 && errno == EAGAIN) 182 if (n == -1 && errno == EAGAIN)
183 continue; 183 continue;
184 atf_tc_fail_errno("recv failed"); 184 atf_tc_fail_errno("recv failed");
185 } 185 }
186 186
187 rump_sys_close(s); 187 rump_sys_close(s);
188 return succ; 188 return succ;
189} 189}
190 190
191#define LOOPS 10000 191#define LOOPS 10000
192 192
193ATF_TC_BODY(floodping, tc) 193ATF_TC_BODY(floodping, tc)
194{ 194{
195 char ifname[IFNAMSIZ]; 195 char ifname[IFNAMSIZ];
196 pid_t cpid; 196 pid_t cpid;
197 int succ; 197 int succ;
198 198
199 cpid = fork(); 199 cpid = fork();
200 rump_init(); 200 rump_init();
201 netcfg_rump_makeshmif("thank-you-driver-for-getting-me-here", ifname); 201 netcfg_rump_makeshmif("thank-you-driver-for-getting-me-here", ifname);
202 202
203 switch (cpid) { 203 switch (cpid) {
204 case -1: 204 case -1:
205 atf_tc_fail_errno("fork failed"); 205 atf_tc_fail_errno("fork failed");
206 case 0: 206 case 0:
207 netcfg_rump_if(ifname, "1.1.1.10", "255.255.255.0"); 207 netcfg_rump_if(ifname, "1.1.1.10", "255.255.255.0");
208 pause(); 208 pause();
209 break; 209 break;
210 default: 210 default:
211 break; 211 break;
212 } 212 }
213 213
214 netcfg_rump_if(ifname, "1.1.1.20", "255.255.255.0"); 214 netcfg_rump_if(ifname, "1.1.1.20", "255.255.255.0");
215 215
216 succ = doping("1.1.1.10", LOOPS, 56); 216 succ = doping("1.1.1.10", LOOPS, 56);
217 printf("got %d/%d\n", succ, LOOPS); 217 printf("got %d/%d\n", succ, LOOPS);
218 218
219 kill(cpid, SIGKILL); 219 kill(cpid, SIGKILL);
220} 220}
221 221
222ATF_TC(floodping2); 222ATF_TC(floodping2);
223ATF_TC_HEAD(floodping2, tc) 223ATF_TC_HEAD(floodping2, tc)
224{ 224{
225 225
226 atf_tc_set_md_var(tc, "descr", "two hosts floodpinging each other"); 226 atf_tc_set_md_var(tc, "descr", "two hosts floodpinging each other");
227 atf_tc_set_md_var(tc, "use.fs", "true"); 227 atf_tc_set_md_var(tc, "use.fs", "true");
228} 228}
229 229
230ATF_TC_BODY(floodping2, tc) 230ATF_TC_BODY(floodping2, tc)
231{ 231{
232 char ifname[IFNAMSIZ]; 232 char ifname[IFNAMSIZ];
233 pid_t cpid; 233 pid_t cpid;
234 int succ; 234 int succ;
235 235
236 cpid = fork(); 236 cpid = fork();
237 rump_init(); 237 rump_init();
238 netcfg_rump_makeshmif("floodping2", ifname); 238 netcfg_rump_makeshmif("floodping2", ifname);
239 239
240 switch (cpid) { 240 switch (cpid) {
241 case -1: 241 case -1:
242 atf_tc_fail_errno("fork failed"); 242 atf_tc_fail_errno("fork failed");
243 case 0: 243 case 0:
244 netcfg_rump_if(ifname, "1.1.1.10", "255.255.255.0"); 244 netcfg_rump_if(ifname, "1.1.1.10", "255.255.255.0");
245 succ = doping("1.1.1.20", LOOPS, 56); 245 succ = doping("1.1.1.20", LOOPS, 56);
246 break; 246 break;
247 default: 247 default:
248 netcfg_rump_if(ifname, "1.1.1.20", "255.255.255.0"); 248 netcfg_rump_if(ifname, "1.1.1.20", "255.255.255.0");
249 succ = doping("1.1.1.10", LOOPS, 56); 249 succ = doping("1.1.1.10", LOOPS, 56);
250 break; 250 break;
251 } 251 }
252 252
253 printf("got %d/%d\n", succ, LOOPS); 253 printf("got %d/%d\n", succ, LOOPS);
254} 254}
255 255
256ATF_TC(pingsize); 256ATF_TC(pingsize);
257ATF_TC_HEAD(pingsize, tc) 257ATF_TC_HEAD(pingsize, tc)
258{ 258{
259 259
260 atf_tc_set_md_var(tc, "descr", "ping with packets min <= size <= max"); 260 atf_tc_set_md_var(tc, "descr", "ping with packets min <= size <= max");
261 atf_tc_set_md_var(tc, "use.fs", "true"); 261 atf_tc_set_md_var(tc, "use.fs", "true");
262} 262}
263 263
264ATF_TC_BODY(pingsize, tc) 264ATF_TC_BODY(pingsize, tc)
265{ 265{
266 char ifname[IFNAMSIZ]; 266 char ifname[IFNAMSIZ];
267 pid_t cpid; 267 pid_t cpid;
268 int succ, i; 268 int succ, i;
269 269
270 cpid = fork(); 270 cpid = fork();
271 rump_init(); 271 rump_init();
272 netcfg_rump_makeshmif("jippikaiee", ifname); 272 netcfg_rump_makeshmif("jippikaiee", ifname);
273 273
274 switch (cpid) { 274 switch (cpid) {
275 case -1: 275 case -1:
276 atf_tc_fail_errno("fork failed"); 276 atf_tc_fail_errno("fork failed");
277 case 0: 277 case 0:
278 netcfg_rump_if(ifname, "1.1.1.10", "255.255.255.0"); 278 netcfg_rump_if(ifname, "1.1.1.10", "255.255.255.0");
279 pause(); 279 pause();
280 break; 280 break;
281 default: 281 default:
282 break; 282 break;
283 } 283 }
284 284
285 netcfg_rump_if(ifname, "1.1.1.20", "255.255.255.0"); 285 netcfg_rump_if(ifname, "1.1.1.20", "255.255.255.0");
286 286
287 succ = 0; 287 succ = 0;
288 288
289 /* small sizes */ 289 /* small sizes */
290 for (i = 0 ; i < IP_MAXPACKET - 60000; i++) 290 for (i = 0 ; i < IP_MAXPACKET - 60000; i++)
291 succ += doping("1.1.1.10", 1, i); 291 succ += doping("1.1.1.10", 1, i);
292 292
293 /* medium sizes */ 293 /* medium sizes */
294 for (i = IP_MAXPACKET - 60000; i < IP_MAXPACKET - 100; i += 1000) 294 for (i = IP_MAXPACKET - 60000; i < IP_MAXPACKET - 100; i += 1000)
295 succ += doping("1.1.1.10", 1, i); 295 succ += doping("1.1.1.10", 1, i);
296 296
297 /* big sizes */ 297 /* big sizes */
298 for (i = IP_MAXPACKET - 100; i < IP_MAXPACKET; i += 10) 298 for (i = IP_MAXPACKET - 100; i < IP_MAXPACKET; i += 10)
299 succ += doping("1.1.1.10", 1, i); 299 succ += doping("1.1.1.10", 1, i);
300 300
301 printf("got %d/%d\n", succ, IP_MAXPACKET); 301 printf("got %d/%d\n", succ, IP_MAXPACKET);
302 kill(cpid, SIGKILL); 302 kill(cpid, SIGKILL);
303} 303}
304 304
305ATF_TC(ping_of_death); 305ATF_TC(ping_of_death);
306ATF_TC_HEAD(ping_of_death, tc) 306ATF_TC_HEAD(ping_of_death, tc)
307{ 307{
308 308
309 atf_tc_set_md_var(tc, "descr", "send a \"ping of death\""); 309 atf_tc_set_md_var(tc, "descr", "send a \"ping of death\"");
310 atf_tc_set_md_var(tc, "use.fs", "true"); 310 atf_tc_set_md_var(tc, "use.fs", "true");
311 atf_tc_set_md_var(tc, "timeout", "2"); 311 atf_tc_set_md_var(tc, "timeout", "2");
312} 312}
313 313
314ATF_TC_BODY(ping_of_death, tc) 314ATF_TC_BODY(ping_of_death, tc)
315{ 315{
316 char data[1500]; 316 char data[1500];
317 struct sockaddr_in dst; 317 struct sockaddr_in dst;
318 struct ip *ip; 318 struct ip *ip;
319 struct icmp *icmp; 319 struct icmp *icmp;
320 char ifname[IFNAMSIZ]; 320 char ifname[IFNAMSIZ];
321 pid_t cpid; 321 pid_t cpid;
322 size_t tot, frag; 322 size_t tot, frag;
323 int s, x, loop; 323 int s, x, loop;
324 324
325 cpid = fork(); 325 cpid = fork();
326 rump_init(); 326 rump_init();
327 netcfg_rump_makeshmif("jippikaiee", ifname); 327 netcfg_rump_makeshmif("jippikaiee", ifname);
328 328
329 switch (cpid) { 329 switch (cpid) {
330 case -1: 330 case -1:
331 atf_tc_fail_errno("fork failed"); 331 atf_tc_fail_errno("fork failed");
332 case 0: 332 case 0:
333 /* wait until we receive a too long IP packet */ 333 /* wait until we receive a too long IP packet */
334 for (loop = 0;; loop++) { 334 for (loop = 0;; loop++) {
335 uint64_t ipstat[IP_NSTATS]; 335 uint64_t ipstat[IP_NSTATS];
336 size_t arglen; 336 size_t arglen;
337 int mib[4]; 337 int mib[4];
338 338
339 if (loop == 1) 339 if (loop == 1)
340 netcfg_rump_if(ifname, 340 netcfg_rump_if(ifname,
341 "1.1.1.10", "255.255.255.0"); 341 "1.1.1.10", "255.255.255.0");
342 342
343 mib[0] = CTL_NET; 343 mib[0] = CTL_NET;
344 mib[1] = PF_INET; 344 mib[1] = PF_INET;
345 mib[2] = IPPROTO_IP; 345 mib[2] = IPPROTO_IP;
346 mib[3] = IPCTL_STATS; 346 mib[3] = IPCTL_STATS;
347 347
348 arglen = sizeof(ipstat); 348 arglen = sizeof(ipstat);
349 RL(rump_sys___sysctl(mib, 4, &ipstat, &arglen, 349 RL(rump_sys___sysctl(mib, 4, &ipstat, &arglen,
350 NULL, 0)); 350 NULL, 0));
351 if (loop == 0 && ipstat[IP_STAT_TOOLONG] != 0) 351 if (loop == 0 && ipstat[IP_STAT_TOOLONG] != 0)
352 _exit(1); 352 _exit(1);
353 if (ipstat[IP_STAT_TOOLONG]) 353 if (ipstat[IP_STAT_TOOLONG])
354 break; 354 break;
355 usleep(10000); 355 usleep(10000);
356 } 356 }
357 357
358 _exit(0); 358 _exit(0);
359 break; 359 break;
360 default: 360 default:
361 break; 361 break;
362 } 362 }
363 363
364 netcfg_rump_if(ifname, "1.1.1.20", "255.255.255.0"); 364 netcfg_rump_if(ifname, "1.1.1.20", "255.255.255.0");
365 365
366 RL(s = rump_sys_socket(PF_INET, SOCK_RAW, 0)); 366 RL(s = rump_sys_socket(PF_INET, SOCK_RAW, 0));
367 x = 1; 367 x = 1;
368 RL(rump_sys_setsockopt(s, IPPROTO_IP, IP_HDRINCL, &x, sizeof(x))); 368 RL(rump_sys_setsockopt(s, IPPROTO_IP, IP_HDRINCL, &x, sizeof(x)));
369 369
370 memset(&dst, 0, sizeof(dst)); 370 memset(&dst, 0, sizeof(dst));
371 dst.sin_len = sizeof(dst); 371 dst.sin_len = sizeof(dst);
372 dst.sin_family = AF_INET; 372 dst.sin_family = AF_INET;
373 dst.sin_addr.s_addr = inet_addr("1.1.1.10"); 373 dst.sin_addr.s_addr = inet_addr("1.1.1.10");
374 374
375 /* construct packet */ 375 /* construct packet */
376 memset(data, 0, sizeof(data)); 376 memset(data, 0, sizeof(data));
377 ip = (struct ip *)data; 377 ip = (struct ip *)data;
378 ip->ip_v = 4; 378 ip->ip_v = 4;
379 ip->ip_hl = sizeof(*ip) >> 2; 379 ip->ip_hl = sizeof(*ip) >> 2;
380 ip->ip_p = IPPROTO_ICMP; 380 ip->ip_p = IPPROTO_ICMP;
381 ip->ip_ttl = IPDEFTTL; 381 ip->ip_ttl = IPDEFTTL;
382 ip->ip_dst = dst.sin_addr; 382 ip->ip_dst = dst.sin_addr;
383 ip->ip_id = 1234; 383 ip->ip_id = 1234;
384 384
385 icmp = (struct icmp *)(ip + 1); 385 icmp = (struct icmp *)(ip + 1);
386 icmp->icmp_type = ICMP_ECHO; 386 icmp->icmp_type = ICMP_ECHO;
387 icmp->icmp_cksum = in_cksum(icmp, sizeof(*icmp)); 387 icmp->icmp_cksum = in_cksum(icmp, sizeof(*icmp));
388 388
389 for (;;) { 389 for (;;) {
390 int status; 390 int status;
391 391
392 /* resolve arp before sending raw stuff */ 392 /* resolve arp before sending raw stuff */
393 netcfg_rump_pingtest("1.1.1.10", 1); 393 netcfg_rump_pingtest("1.1.1.10", 1);
394 394
395 for (tot = 0; 395 for (tot = 0;
396 tot < 65538 - sizeof(*ip); 396 tot < 65538 - sizeof(*ip);
397 tot += (frag - sizeof(*ip))) { 397 tot += (frag - sizeof(*ip))) {
398 frag = MIN(65538 - tot, sizeof(data)); 398 frag = MIN(65538 - tot, sizeof(data));
399 ip->ip_off = tot >> 3; 399 ip->ip_off = tot >> 3;
400 assert(ip->ip_off << 3 == tot); 400 assert((size_t)ip->ip_off << 3 == tot);
401 ip->ip_len = frag; 401 ip->ip_len = frag;
402 402
403 if (frag == sizeof(data)) { 403 if (frag == sizeof(data)) {
404 ip->ip_off |= IP_MF; 404 ip->ip_off |= IP_MF;
405 } 405 }
406 406
407 RL(rump_sys_sendto(s, data, frag, 0, 407 RL(rump_sys_sendto(s, data, frag, 0,
408 (struct sockaddr *)&dst, sizeof(dst))); 408 (struct sockaddr *)&dst, sizeof(dst)));
409 } 409 }
410 if (waitpid(-1, &status, WNOHANG) > 0) { 410 if (waitpid(-1, &status, WNOHANG) > 0) {
411 if (WIFEXITED(status) && WEXITSTATUS(status) == 0) 411 if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
412 break; 412 break;
413 atf_tc_fail("child did not exit clean"); 413 atf_tc_fail("child did not exit clean");
414 } 414 }
415  415
416 usleep(10000); 416 usleep(10000);
417 } 417 }
418} 418}
419 419
420ATF_TP_ADD_TCS(tp) 420ATF_TP_ADD_TCS(tp)
421{ 421{
422 422
423 ATF_TP_ADD_TC(tp, simpleping); 423 ATF_TP_ADD_TC(tp, simpleping);
424 ATF_TP_ADD_TC(tp, floodping); 424 ATF_TP_ADD_TC(tp, floodping);
425 ATF_TP_ADD_TC(tp, floodping2); 425 ATF_TP_ADD_TC(tp, floodping2);
426 ATF_TP_ADD_TC(tp, pingsize); 426 ATF_TP_ADD_TC(tp, pingsize);
427 ATF_TP_ADD_TC(tp, ping_of_death); 427 ATF_TP_ADD_TC(tp, ping_of_death);
428 428
429 return atf_no_error(); 429 return atf_no_error();
430} 430}

cvs diff -r1.2 -r1.3 src/tests/net/if_loop/t_pr.c (switch to unified diff)

--- src/tests/net/if_loop/t_pr.c 2010/07/26 14:07:04 1.2
+++ src/tests/net/if_loop/t_pr.c 2010/11/03 16:10:25 1.3
@@ -1,141 +1,140 @@ @@ -1,141 +1,140 @@
1/* $NetBSD: t_pr.c,v 1.2 2010/07/26 14:07:04 pooka Exp $ */ 1/* $NetBSD: t_pr.c,v 1.3 2010/11/03 16:10:25 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31#ifndef lint 31#ifndef lint
32__RCSID("$NetBSD: t_pr.c,v 1.2 2010/07/26 14:07:04 pooka Exp $"); 32__RCSID("$NetBSD: t_pr.c,v 1.3 2010/11/03 16:10:25 christos Exp $");
33#endif /* not lint */ 33#endif /* not lint */
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/socket.h> 36#include <sys/socket.h>
37 37
38#include <netinet/in.h> 38#include <netinet/in.h>
39#include <net/route.h> 39#include <net/route.h>
40 40
41#include <rump/rump.h> 41#include <rump/rump.h>
42#include <rump/rump_syscalls.h> 42#include <rump/rump_syscalls.h>
43 43
44#include <atf-c.h> 44#include <atf-c.h>
45#include <errno.h> 45#include <errno.h>
46#include <stdio.h> 46#include <stdio.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49#include <unistd.h> 49#include <unistd.h>
50 50
51#include "../config/netconfig.c" 51#include "../config/netconfig.c"
52#include "../../h_macros.h" 52#include "../../h_macros.h"
53 53
54ATF_TC(loopmtu); 54ATF_TC(loopmtu);
55ATF_TC_HEAD(loopmtu, tc) 55ATF_TC_HEAD(loopmtu, tc)
56{ 56{
57 57
58 atf_tc_set_md_var(tc, "descr", "test lo0 fragmentation"); 58 atf_tc_set_md_var(tc, "descr", "test lo0 fragmentation");
59 /* PR kern/43664 */ 59 /* PR kern/43664 */
60} 60}
61 61
62ATF_TC_BODY(loopmtu, tc) 62ATF_TC_BODY(loopmtu, tc)
63{ 63{
64 char ifname[IFNAMSIZ]; 64 char ifname[IFNAMSIZ];
65 size_t len; 
66 struct { 65 struct {
67 struct rt_msghdr m_rtm; 66 struct rt_msghdr m_rtm;
68 struct sockaddr_in m_sin; 67 struct sockaddr_in m_sin;
69 } m_rtmsg; 68 } m_rtmsg;
70#define rtm m_rtmsg.m_rtm 69#define rtm m_rtmsg.m_rtm
71#define rsin m_rtmsg.m_sin 70#define rsin m_rtmsg.m_sin
72 struct sockaddr_in sin; 71 struct sockaddr_in sin;
73 struct ifreq ifr; 72 struct ifreq ifr;
74 char data[2000]; 73 char data[2000];
75 int s; 74 int s;
76 75
77 strcpy(ifname, "lo0"); 76 strcpy(ifname, "lo0");
78 rump_init(); 77 rump_init();
79 78
80 /* first, config lo0 & route */ 79 /* first, config lo0 & route */
81 netcfg_rump_if(ifname, "127.0.0.1", "255.0.0.0"); 80 netcfg_rump_if(ifname, "127.0.0.1", "255.0.0.0");
82 netcfg_rump_route("127.0.0.1", "255.0.0.0", "127.0.0.1"); 81 netcfg_rump_route("127.0.0.1", "255.0.0.0", "127.0.0.1");
83 82
84 if ((s = rump_sys_socket(PF_ROUTE, SOCK_RAW, 0)) == -1) 83 if ((s = rump_sys_socket(PF_ROUTE, SOCK_RAW, 0)) == -1)
85 atf_tc_fail_errno("routing socket"); 84 atf_tc_fail_errno("routing socket");
86 85
87 /* 86 /*
88 * set MTU for interface so that route MTU doesn't 87 * set MTU for interface so that route MTU doesn't
89 * get overridden by it. 88 * get overridden by it.
90 */ 89 */
91 memset(&ifr, 0, sizeof(ifr)); 90 memset(&ifr, 0, sizeof(ifr));
92 strcpy(ifr.ifr_name, "lo0"); 91 strcpy(ifr.ifr_name, "lo0");
93 ifr.ifr_mtu = 1300; 92 ifr.ifr_mtu = 1300;
94 if (rump_sys_ioctl(s, SIOCSIFMTU, &ifr) == -1) 93 if (rump_sys_ioctl(s, SIOCSIFMTU, &ifr) == -1)
95 atf_tc_fail_errno("set mtu"); 94 atf_tc_fail_errno("set mtu");
96 95
97 /* change route MTU to 100 */ 96 /* change route MTU to 100 */
98 memset(&m_rtmsg, 0, sizeof(m_rtmsg)); 97 memset(&m_rtmsg, 0, sizeof(m_rtmsg));
99 rtm.rtm_type = RTM_CHANGE; 98 rtm.rtm_type = RTM_CHANGE;
100 rtm.rtm_flags = RTF_STATIC; 99 rtm.rtm_flags = RTF_STATIC;
101 rtm.rtm_version = RTM_VERSION; 100 rtm.rtm_version = RTM_VERSION;
102 rtm.rtm_seq = 3; 101 rtm.rtm_seq = 3;
103 rtm.rtm_inits = RTV_MTU; 102 rtm.rtm_inits = RTV_MTU;
104 rtm.rtm_addrs = RTA_DST; 103 rtm.rtm_addrs = RTA_DST;
105 rtm.rtm_rmx.rmx_mtu = 100; 104 rtm.rtm_rmx.rmx_mtu = 100;
106 rtm.rtm_msglen = sizeof(m_rtmsg); 105 rtm.rtm_msglen = sizeof(m_rtmsg);
107 106
108 memset(&rsin, 0, sizeof(rsin)); 107 memset(&rsin, 0, sizeof(rsin));
109 rsin.sin_family = AF_INET; 108 rsin.sin_family = AF_INET;
110 rsin.sin_len = sizeof(rsin); 109 rsin.sin_len = sizeof(rsin);
111 rsin.sin_addr.s_addr = inet_addr("127.0.0.1"); 110 rsin.sin_addr.s_addr = inet_addr("127.0.0.1");
112 111
113 if (rump_sys_write(s, &m_rtmsg, sizeof(m_rtmsg)) != sizeof(m_rtmsg)) 112 if (rump_sys_write(s, &m_rtmsg, sizeof(m_rtmsg)) != sizeof(m_rtmsg))
114 atf_tc_fail_errno("set route mtu"); 113 atf_tc_fail_errno("set route mtu");
115 rump_sys_close(s); 114 rump_sys_close(s);
116 115
117 /* open raw socket */ 116 /* open raw socket */
118 s = rump_sys_socket(PF_INET, SOCK_RAW, 0); 117 s = rump_sys_socket(PF_INET, SOCK_RAW, 0);
119 if (s == -1) 118 if (s == -1)
120 atf_tc_fail_errno("raw socket"); 119 atf_tc_fail_errno("raw socket");
121 120
122 /* then, send data */ 121 /* then, send data */
123 memset(&sin, 0, sizeof(sin)); 122 memset(&sin, 0, sizeof(sin));
124 sin.sin_family = AF_INET; 123 sin.sin_family = AF_INET;
125 sin.sin_len = sizeof(sin); 124 sin.sin_len = sizeof(sin);
126 sin.sin_port = htons(12345); 125 sin.sin_port = htons(12345);
127 sin.sin_addr.s_addr = inet_addr("127.0.0.1"); 126 sin.sin_addr.s_addr = inet_addr("127.0.0.1");
128 127
129 atf_tc_expect_signal(SIGABRT, "PR kern/43664"); 128 atf_tc_expect_signal(SIGABRT, "PR kern/43664");
130 if (rump_sys_sendto(s, data, sizeof(data), 0, 129 if (rump_sys_sendto(s, data, sizeof(data), 0,
131 (struct sockaddr *)&sin, sizeof(sin)) == -1) 130 (struct sockaddr *)&sin, sizeof(sin)) == -1)
132 atf_tc_fail_errno("sendto failed"); 131 atf_tc_fail_errno("sendto failed");
133} 132}
134 133
135ATF_TP_ADD_TCS(tp) 134ATF_TP_ADD_TCS(tp)
136{ 135{
137 136
138 ATF_TP_ADD_TC(tp, loopmtu); 137 ATF_TP_ADD_TC(tp, loopmtu);
139 138
140 return atf_no_error(); 139 return atf_no_error();
141} 140}

cvs diff -r1.3 -r1.4 src/tests/net/sys/Attic/t_connect.c (switch to unified diff)

--- src/tests/net/sys/Attic/t_connect.c 2010/06/12 15:01:04 1.3
+++ src/tests/net/sys/Attic/t_connect.c 2010/11/03 16:10:25 1.4
@@ -1,97 +1,98 @@ @@ -1,97 +1,98 @@
1/* $NetBSD: t_connect.c,v 1.3 2010/06/12 15:01:04 wiz Exp $ */ 1/* $NetBSD: t_connect.c,v 1.4 2010/11/03 16:10:25 christos Exp $ */
2/* 2/*
3 * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. 3 * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <err.h> 29#include <err.h>
30#include <errno.h> 30#include <errno.h>
31#include <string.h> 31#include <string.h>
32#include <unistd.h> 32#include <unistd.h>
33 33
34#include <arpa/inet.h> 34#include <arpa/inet.h>
35#include <netinet/in.h> 35#include <netinet/in.h>
36 36
37#include <atf-c.h> 37#include <atf-c.h>
38 38
39ATF_TC(low_port); 39ATF_TC(low_port);
40ATF_TC_HEAD(low_port, tc) 40ATF_TC_HEAD(low_port, tc)
41{ 41{
42 atf_tc_set_md_var(tc, "descr", "Checks that low-port allocation " 42 atf_tc_set_md_var(tc, "descr", "Checks that low-port allocation "
43 "works"); 43 "works");
44 atf_tc_set_md_var(tc, "require.user", "root"); 44 atf_tc_set_md_var(tc, "require.user", "root");
45} 45}
46ATF_TC_BODY(low_port, tc) 46ATF_TC_BODY(low_port, tc)
47{ 47{
48 struct sockaddr_in sin, sinlist; 48 struct sockaddr_in sin, sinlist;
49 int sd, val, slist; 49 int sd, val, slist;
50 socklen_t slen; 50 socklen_t slen;
51 51
52 slist = socket(AF_INET, SOCK_STREAM, 0); 52 slist = socket(AF_INET, SOCK_STREAM, 0);
53 sd = socket(AF_INET, SOCK_STREAM, 0); 53 sd = socket(AF_INET, SOCK_STREAM, 0);
54 54
55 /* bind listening socket */ 55 /* bind listening socket */
56 memset(&sinlist, 0, sizeof(sinlist)); 56 memset(&sinlist, 0, sizeof(sinlist));
57 sinlist.sin_family = AF_INET; 57 sinlist.sin_family = AF_INET;
58 sinlist.sin_port = htons(31522); 58 sinlist.sin_port = htons(31522);
59 sinlist.sin_addr.s_addr = inet_addr("127.0.0.1"); 59 sinlist.sin_addr.s_addr = inet_addr("127.0.0.1");
60 60
61 ATF_REQUIRE_EQ(bind(slist, 61 ATF_REQUIRE_EQ(bind(slist,
62 (struct sockaddr *)&sinlist, sizeof(sinlist)), 0); 62 (struct sockaddr *)&sinlist, sizeof(sinlist)), 0);
63 ATF_REQUIRE_EQ(listen(slist, 1), 0); 63 ATF_REQUIRE_EQ(listen(slist, 1), 0);
64 64
65 val = IP_PORTRANGE_LOW; 65 val = IP_PORTRANGE_LOW;
66 if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val, 66 if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val,
67 sizeof(val)) == -1) 67 sizeof(val)) == -1)
68 atf_tc_fail("setsockopt failed: %s", strerror(errno)); 68 atf_tc_fail("setsockopt failed: %s", strerror(errno));
69 69
70 memset(&sin, 0, sizeof(sin)); 70 memset(&sin, 0, sizeof(sin));
71 71
72 sin.sin_port = htons(31522); 72 sin.sin_port = htons(31522);
73 sin.sin_addr.s_addr = inet_addr("127.0.0.1"); 73 sin.sin_addr.s_addr = inet_addr("127.0.0.1");
74 sin.sin_family = AF_INET; 74 sin.sin_family = AF_INET;
75 75
76 if (connect(sd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { 76 if (connect(sd, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
77 int err = errno; 77 int serrno = errno;
78 atf_tc_fail("connect failed: %s%s", 78 atf_tc_fail("connect failed: %s%s",
79 strerror(err), 79 strerror(serrno),
80 err != EACCES ? "" : " (see http://mail-index.netbsd.org/" 80 serrno != EACCES ? "" :
 81 " (see http://mail-index.netbsd.org/"
81 "source-changes/2007/12/16/0011.html)"); 82 "source-changes/2007/12/16/0011.html)");
82 } 83 }
83 84
84 slen = sizeof(sin); 85 slen = sizeof(sin);
85 ATF_REQUIRE_EQ(getsockname(sd, (struct sockaddr *)&sin, &slen), 0); 86 ATF_REQUIRE_EQ(getsockname(sd, (struct sockaddr *)&sin, &slen), 0);
86 ATF_REQUIRE_EQ(slen, sizeof(sin)); 87 ATF_REQUIRE_EQ(slen, sizeof(sin));
87 ATF_REQUIRE(ntohs(sin.sin_port) <= IPPORT_RESERVEDMAX); 88 ATF_REQUIRE(ntohs(sin.sin_port) <= IPPORT_RESERVEDMAX);
88 89
89 close(sd); 90 close(sd);
90} 91}
91 92
92ATF_TP_ADD_TCS(tp) 93ATF_TP_ADD_TCS(tp)
93{ 94{
94 ATF_TP_ADD_TC(tp, low_port); 95 ATF_TP_ADD_TC(tp, low_port);
95 96
96 return atf_no_error(); 97 return atf_no_error();
97} 98}

cvs diff -r1.1 -r1.2 src/tests/net/sys/Attic/t_listen.c (switch to unified diff)

--- src/tests/net/sys/Attic/t_listen.c 2008/05/01 15:38:17 1.1
+++ src/tests/net/sys/Attic/t_listen.c 2010/11/03 16:10:25 1.2
@@ -1,70 +1,72 @@ @@ -1,70 +1,72 @@
1/* $NetBSD: t_listen.c,v 1.1 2008/05/01 15:38:17 jmmv Exp $ */ 1/* $NetBSD: t_listen.c,v 1.2 2010/11/03 16:10:25 christos Exp $ */
2/* 2/*
3 * Copyright (c) 2007 The NetBSD Foundation, Inc. 3 * Copyright (c) 2007 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <err.h> 29#include <err.h>
30#include <errno.h> 30#include <errno.h>
31#include <string.h> 31#include <string.h>
32#include <unistd.h> 32#include <unistd.h>
33 33
34#include <netinet/in.h> 34#include <netinet/in.h>
35 35
36#include <atf-c.h> 36#include <atf-c.h>
37 37
38ATF_TC(low_port); 38ATF_TC(low_port);
39ATF_TC_HEAD(low_port, tc) 39ATF_TC_HEAD(low_port, tc)
40{ 40{
41 atf_tc_set_md_var(tc, "descr", "Checks that low-port allocation " 41 atf_tc_set_md_var(tc, "descr", "Checks that low-port allocation "
42 "works"); 42 "works");
43 atf_tc_set_md_var(tc, "require.user", "root"); 43 atf_tc_set_md_var(tc, "require.user", "root");
44} 44}
45ATF_TC_BODY(low_port, tc) 45ATF_TC_BODY(low_port, tc)
46{ 46{
47 int sd, val; 47 int sd, val;
48 48
49 sd = socket(AF_INET, SOCK_STREAM, 0); 49 sd = socket(AF_INET, SOCK_STREAM, 0);
50 50
51 val = IP_PORTRANGE_LOW; 51 val = IP_PORTRANGE_LOW;
52 if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val, 52 if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val,
53 sizeof(val)) == -1) 53 sizeof(val)) == -1)
54 atf_tc_fail("setsockopt failed: %s", strerror(errno)); 54 atf_tc_fail("setsockopt failed: %s", strerror(errno));
55 55
56 if (listen(sd, 5) == -1) { 56 if (listen(sd, 5) == -1) {
57 int err = errno; 57 int serrno = errno;
58 atf_tc_fail("listen failed: %s%s", 58 atf_tc_fail("listen failed: %s%s",
59 strerror(err), 59 strerror(serrno),
60 err != EACCES ? "" : " (see http://mail-index.netbsd.org/" 60 serrno != EACCES ? "" :
 61 " (see http://mail-index.netbsd.org/"
61 "source-changes/2007/12/16/0011.html)"); 62 "source-changes/2007/12/16/0011.html)");
62 } 63 }
63 64
64 close(sd); 65 close(sd);
65} 66}
66 67
67ATF_TP_ADD_TCS(tp) 68ATF_TP_ADD_TCS(tp)
68{ 69{
69 ATF_TP_ADD_TC(tp, low_port); 70 ATF_TP_ADD_TC(tp, low_port);
 71 return 0;
70} 72}

File Added: src/tests/rump/Makefile.inc
.include "../Makefile.inc"

File Added: src/tests/util/Attic/Makefile.inc
.include "../Makefile.inc"

cvs diff -r1.3 -r1.4 src/tests/util/df/Attic/getmntinfo.c (switch to unified diff)

--- src/tests/util/df/Attic/getmntinfo.c 2008/04/28 20:24:12 1.3
+++ src/tests/util/df/Attic/getmntinfo.c 2010/11/03 16:10:25 1.4
@@ -1,218 +1,218 @@ @@ -1,218 +1,218 @@
1/* $NetBSD: getmntinfo.c,v 1.3 2008/04/28 20:24:12 martin Exp $ */ 1/* $NetBSD: getmntinfo.c,v 1.4 2010/11/03 16:10:25 christos Exp $ */
2/* 2/*
3 * Copyright (c) 2007 The NetBSD Foundation, Inc. 3 * Copyright (c) 2007 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE. 25 * POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28#include <sys/param.h> 28#include <sys/param.h>
29#include <sys/ucred.h> 29#include <sys/ucred.h>
30#include <sys/mount.h> 30#include <sys/mount.h>
31 31
32#include <err.h> 32#include <err.h>
33#include <stdlib.h> 33#include <stdlib.h>
34#include <string.h> 34#include <string.h>
35 35
36#define KB * 1024 36#define KB * 1024
37#define MB * 1024 KB 37#define MB * 1024 KB
38#define GB * 1024 MB 38#define GB * 1024 MB
39 39
40static struct statvfs *getnewstatvfs(void); 40static struct statvfs *getnewstatvfs(void);
41static void other_variants(const struct statvfs *, const int *, int, 41static void other_variants(const struct statvfs *, const int *, int,
42 const int *, int); 42 const int *, int);
43static void setup_filer(void); 43static void setup_filer(void);
44static void setup_ld0g(void); 44static void setup_ld0g(void);
45static void setup_strpct(void); 45static void setup_strpct(void);
46 46
47static struct statvfs *allstatvfs; 47static struct statvfs *allstatvfs;
48static int sftotal, sfused; 48static int sftotal, sfused;
49 49
50struct statvfs * 50struct statvfs *
51getnewstatvfs(void) 51getnewstatvfs(void)
52{ 52{
53 53
54 if (sftotal == sfused) { 54 if (sftotal == sfused) {
55 sftotal = sftotal ? sftotal * 2 : 1; 55 sftotal = sftotal ? sftotal * 2 : 1;
56 allstatvfs = realloc(allstatvfs, 56 allstatvfs = realloc(allstatvfs,
57 sftotal * sizeof(struct statvfs)); 57 sftotal * sizeof(struct statvfs));
58 if (allstatvfs == NULL) 58 if (allstatvfs == NULL)
59 err(EXIT_FAILURE, "realloc"); 59 err(EXIT_FAILURE, "realloc");
60 } 60 }
61 61
62 return (&allstatvfs[sfused++]); 62 return (&allstatvfs[sfused++]);
63} 63}
64 64
65void 65void
66other_variants(const struct statvfs *tmpl, const int *minfree, int minfreecnt, 66other_variants(const struct statvfs *tmpl, const int *minfree, int minfreecnt,
67 const int *consumed, int consumedcnt) 67 const int *consumed, int consumedcnt)
68{ 68{
69 int64_t total, used; 69 int64_t total, used;
70 struct statvfs *sf; 70 struct statvfs *sf;
71 int i, j; 71 int i, j;
72 72
73 for (i = 0; i < minfreecnt; i++) 73 for (i = 0; i < minfreecnt; i++)
74 for (j = 0; j < consumedcnt; j++) { 74 for (j = 0; j < consumedcnt; j++) {
75 sf = getnewstatvfs(); 75 sf = getnewstatvfs();
76 *sf = *tmpl; 76 *sf = *tmpl;
77 total = (int64_t)(u_long)sf->f_blocks * sf->f_bsize; 77 total = (int64_t)(u_long)sf->f_blocks * sf->f_bsize;
78 used = total * consumed[j] / 100; 78 used = total * consumed[j] / 100;
79 sf->f_bfree = (total - used) / sf->f_bsize; 79 sf->f_bfree = (total - used) / sf->f_bsize;
80 sf->f_bavail = (total * (100 - minfree[i]) / 100 - 80 sf->f_bavail = (total * (100 - minfree[i]) / 100 -
81 used) / (int)sf->f_bsize; 81 used) / (int)sf->f_bsize;
82 sf->f_bresvd = sf->f_bfree - sf->f_bavail; 82 sf->f_bresvd = sf->f_bfree - sf->f_bavail;
83 } 83 }
84} 84}
85 85
86/* 86/*
87 * Parameter taken from: 87 * Parameter taken from:
88 * http://mail-index.NetBSD.org/tech-userlevel/2004/03/24/0001.html 88 * http://mail-index.NetBSD.org/tech-userlevel/2004/03/24/0001.html
89 */ 89 */
90void 90void
91setup_filer(void) 91setup_filer(void)
92{ 92{
93 static const struct statvfs tmpl = { 93 static const struct statvfs tmpl = {
94#define BSIZE 512 94#define BSIZE 512
95#define TOTAL 1147ULL GB 95#define TOTAL 1147ULL GB
96#define USED 132ULL MB 96#define USED 132ULL MB
97 .f_bsize = BSIZE, 97 .f_bsize = BSIZE,
98 .f_frsize = BSIZE, 98 .f_frsize = BSIZE,
99 .f_blocks = TOTAL / BSIZE, 99 .f_blocks = TOTAL / BSIZE,
100 .f_bfree = (TOTAL - USED) / BSIZE, 100 .f_bfree = (TOTAL - USED) / BSIZE,
101 .f_bavail = (TOTAL - USED) / BSIZE, 101 .f_bavail = (TOTAL - USED) / BSIZE,
102 .f_bresvd = 0, 102 .f_bresvd = 0,
103 .f_mntfromname = "filer:/", 103 .f_mntfromname = "filer:/",
104 .f_mntonname = "/filer", 104 .f_mntonname = "/filer",
105#undef USED 105#undef USED
106#undef TOTAL 106#undef TOTAL
107#undef BSIZE 107#undef BSIZE
108 }; 108 };
109 static const int minfree[] = { 0, 5, 10, 15, }; 109 static const int minfree[] = { 0, 5, 10, 15, };
110 static const int consumed[] = { 0, 20, 60, 95, 100 }; 110 static const int consumed[] = { 0, 20, 60, 95, 100 };
111 111
112 *getnewstatvfs() = tmpl; 112 *getnewstatvfs() = tmpl;
113 other_variants(&tmpl, minfree, sizeof(minfree) / sizeof(minfree[0]), 113 other_variants(&tmpl, minfree, sizeof(minfree) / sizeof(minfree[0]),
114 consumed, sizeof(consumed) / sizeof(consumed[0])); 114 consumed, sizeof(consumed) / sizeof(consumed[0]));
115} 115}
116 116
117/* 117/*
118 * Parameter taken from: 118 * Parameter taken from:
119 * http://mail-index.NetBSD.org/current-users/2004/03/01/0038.html 119 * http://mail-index.NetBSD.org/current-users/2004/03/01/0038.html
120 */ 120 */
121void 121void
122setup_ld0g(void) 122setup_ld0g(void)
123{ 123{
124 static const struct statvfs tmpl = { 124 static const struct statvfs tmpl = {
125#define BSIZE 4096 /* Guess */ 125#define BSIZE 4096 /* Guess */
126#define TOTAL 1308726116ULL KB 126#define TOTAL 1308726116ULL KB
127#define USED 17901268ULL KB 127#define USED 17901268ULL KB
128#define AVAIL 1225388540ULL KB 128#define AVAIL 1225388540ULL KB
129 .f_bsize = BSIZE, 129 .f_bsize = BSIZE,
130 .f_frsize = BSIZE, 130 .f_frsize = BSIZE,
131 .f_blocks = TOTAL / BSIZE, 131 .f_blocks = TOTAL / BSIZE,
132 .f_bfree = (TOTAL - USED) / BSIZE, 132 .f_bfree = (TOTAL - USED) / BSIZE,
133 .f_bavail = AVAIL / BSIZE, 133 .f_bavail = AVAIL / BSIZE,
134 .f_bresvd = (TOTAL - USED) / BSIZE - AVAIL / BSIZE, 134 .f_bresvd = (TOTAL - USED) / BSIZE - AVAIL / BSIZE,
135 .f_mntfromname = "/dev/ld0g", 135 .f_mntfromname = "/dev/ld0g",
136 .f_mntonname = "/anon-root", 136 .f_mntonname = "/anon-root",
137#undef AVAIL 137#undef AVAIL
138#undef USED 138#undef USED
139#undef TOTAL 139#undef TOTAL
140#undef BSIZE 140#undef BSIZE
141 }; 141 };
142 static const int minfree[] = { 0, 5, 10, 15, }; 142 static const int minfree[] = { 0, 5, 10, 15, };
143 static const int consumed[] = { 0, 20, 60, 95, 100 }; 143 static const int consumed[] = { 0, 20, 60, 95, 100 };
144 144
145 *getnewstatvfs() = tmpl; 145 *getnewstatvfs() = tmpl;
146 other_variants(&tmpl, minfree, sizeof(minfree) / sizeof(minfree[0]), 146 other_variants(&tmpl, minfree, sizeof(minfree) / sizeof(minfree[0]),
147 consumed, sizeof(consumed) / sizeof(consumed[0])); 147 consumed, sizeof(consumed) / sizeof(consumed[0]));
148} 148}
149 149
150/* 150/*
151 * Test of strpct() with huge number. 151 * Test of strpct() with huge number.
152 */ 152 */
153void 153void
154setup_strpct(void) 154setup_strpct(void)
155{ 155{
156 static const struct statvfs tmpl = { 156 static const struct statvfs tmpl = {
157#define BSIZE 4096 /* Guess */ 157#define BSIZE 4096 /* Guess */
158#define TOTAL 0x4ffffffffULL KB 158#define TOTAL 0x4ffffffffULL KB
159#define USED (TOTAL / 2) 159#define USED (TOTAL / 2)
160#define AVAIL (TOTAL / 2) 160#define AVAIL (TOTAL / 2)
161 .f_bsize = BSIZE, 161 .f_bsize = BSIZE,
162 .f_frsize = BSIZE, 162 .f_frsize = BSIZE,
163 .f_blocks = TOTAL / BSIZE, 163 .f_blocks = TOTAL / BSIZE,
164 .f_bfree = (TOTAL - USED) / BSIZE, 164 .f_bfree = (TOTAL - USED) / BSIZE,
165 .f_bavail = AVAIL / BSIZE, 165 .f_bavail = AVAIL / BSIZE,
166 .f_bresvd = (TOTAL - USED) / BSIZE - AVAIL / BSIZE, 166 .f_bresvd = (TOTAL - USED) / BSIZE - AVAIL / BSIZE,
167 .f_mntfromname = "/dev/strpct", 167 .f_mntfromname = "/dev/strpct",
168 .f_mntonname = "/strpct", 168 .f_mntonname = "/strpct",
169#undef AVAIL 169#undef AVAIL
170#undef USED 170#undef USED
171#undef TOTAL 171#undef TOTAL
172#undef BSIZE 172#undef BSIZE
173 }; 173 };
174 174
175 *getnewstatvfs() = tmpl; 175 *getnewstatvfs() = tmpl;
176} 176}
177 177
178/* 178/*
179 * Parameter taken from: 179 * Parameter taken from:
180 * http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=23600 180 * http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=23600
181 */ 181 */
182void 182static void
183setup_pr23600(void) 183setup_pr23600(void)
184{ 184{
185 static const struct statvfs tmpl = { 185 static const struct statvfs tmpl = {
186#define BSIZE 512 186#define BSIZE 512
187#define TOTAL 20971376ULL 187#define TOTAL 20971376ULL
188#define USED 5719864ULL 188#define USED 5719864ULL
189#define AVAIL 15251512ULL 189#define AVAIL 15251512ULL
190 .f_bsize = BSIZE, 190 .f_bsize = BSIZE,
191 .f_frsize = BSIZE, 191 .f_frsize = BSIZE,
192 .f_blocks = TOTAL, 192 .f_blocks = TOTAL,
193 .f_bfree = TOTAL - USED, 193 .f_bfree = TOTAL - USED,
194 .f_bavail = AVAIL, 194 .f_bavail = AVAIL,
195 .f_bresvd = TOTAL - USED - AVAIL, 195 .f_bresvd = TOTAL - USED - AVAIL,
196 .f_mntfromname = "/dev/wd0e", 196 .f_mntfromname = "/dev/wd0e",
197 .f_mntonname = "/mount/windows/C", 197 .f_mntonname = "/mount/windows/C",
198#undef AVAIL 198#undef AVAIL
199#undef USED 199#undef USED
200#undef TOTAL 200#undef TOTAL
201#undef BSIZE 201#undef BSIZE
202 }; 202 };
203 203
204 *getnewstatvfs() = tmpl; 204 *getnewstatvfs() = tmpl;
205} 205}
206 206
207int 207int
208getmntinfo(struct statvfs **mntbuf, int flags) 208getmntinfo(struct statvfs **mntbuf, int flags)
209{ 209{
210 210
211 setup_filer(); 211 setup_filer();
212 setup_ld0g(); 212 setup_ld0g();
213 setup_strpct(); 213 setup_strpct();
214 setup_pr23600(); 214 setup_pr23600();
215 215
216 *mntbuf = allstatvfs; 216 *mntbuf = allstatvfs;
217 return (sfused); 217 return (sfused);
218} 218}

cvs diff -r1.2 -r1.3 src/tests/util/id/Attic/pwgr.c (switch to unified diff)

--- src/tests/util/id/Attic/pwgr.c 2008/04/28 20:24:12 1.2
+++ src/tests/util/id/Attic/pwgr.c 2010/11/03 16:10:26 1.3
@@ -1,186 +1,187 @@ @@ -1,186 +1,187 @@
1/* $NetBSD: pwgr.c,v 1.2 2008/04/28 20:24:12 martin Exp $ */ 1/* $NetBSD: pwgr.c,v 1.3 2010/11/03 16:10:26 christos Exp $ */
2/* 2/*
3 * Copyright (c) 2007 The NetBSD Foundation, Inc. 3 * Copyright (c) 2007 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE. 25 * POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28/* 28/*
29 * This file implements replacements for all user/group-related functions 29 * This file implements replacements for all user/group-related functions
30 * called by id(1). It provides fake but deterministic user and group 30 * called by id(1). It provides fake but deterministic user and group
31 * information. The details are as such: 31 * information. The details are as such:
32 * User root, uid 0, primary group 0 (wheel). 32 * User root, uid 0, primary group 0 (wheel).
33 * User test, uid 100, primary group 100 (users), secondary group 0 (wheel). 33 * User test, uid 100, primary group 100 (users), secondary group 0 (wheel).
34 */ 34 */
35 35
36#include <sys/types.h> 36#include <sys/types.h>
37 37
38#include <errno.h> 38#include <errno.h>
39#include <grp.h> 39#include <grp.h>
40#include <pwd.h> 40#include <pwd.h>
41#include <stdlib.h> 41#include <stdlib.h>
 42#include <unistd.h>
42#include <string.h> 43#include <string.h>
43 44
44char Login[16]; 45char Login[16];
45struct group GrEntry; 46struct group GrEntry;
46struct passwd PwEntry; 47struct passwd PwEntry;
47 48
48gid_t 49gid_t
49getgid(void) 50getgid(void)
50{ 51{
51 return 100; 52 return 100;
52} 53}
53 54
54gid_t 55gid_t
55getegid(void) 56getegid(void)
56{ 57{
57 if (getenv("LIBFAKE_EGID_ROOT") != NULL) 58 if (getenv("LIBFAKE_EGID_ROOT") != NULL)
58 return 0; 59 return 0;
59 else 60 else
60 return 100; 61 return 100;
61} 62}
62 63
63uid_t 64uid_t
64getuid(void) 65getuid(void)
65{ 66{
66 return 100; 67 return 100;
67} 68}
68 69
69uid_t 70uid_t
70geteuid(void) 71geteuid(void)
71{ 72{
72 if (getenv("LIBFAKE_EUID_ROOT") != NULL) 73 if (getenv("LIBFAKE_EUID_ROOT") != NULL)
73 return 0; 74 return 0;
74 else 75 else
75 return 100; 76 return 100;
76} 77}
77 78
78char * 79char *
79getlogin(void) 80getlogin(void)
80{ 81{
81 strcpy(Login, "test"); 82 strcpy(Login, "test");
82 return Login; 83 return Login;
83} 84}
84 85
85struct group * 86struct group *
86getgrgid(gid_t gid) 87getgrgid(gid_t gid)
87{ 88{
88 struct group *g = &GrEntry; 89 struct group *g = &GrEntry;
89 90
90 memset(g, 0, sizeof(*g)); 91 memset(g, 0, sizeof(*g));
91 if (gid == 0) { 92 if (gid == 0) {
92 g->gr_name = "wheel"; 93 g->gr_name = __UNCONST("wheel");
93 g->gr_gid = 0; 94 g->gr_gid = 0;
94 } else if (gid == 100) { 95 } else if (gid == 100) {
95 g->gr_name = "users"; 96 g->gr_name = __UNCONST("users");
96 g->gr_gid = 100; 97 g->gr_gid = 100;
97 } else 98 } else
98 g = NULL; 99 g = NULL;
99 100
100 return g; 101 return g;
101} 102}
102 103
103int 104int
104getgrouplist(const char *name, int basegid, int *groups, int *ngroups) 105getgrouplist(const char *name, gid_t basegid, gid_t *groups, int *ngroups)
105{ 106{
106 int cnt, ret; 107 int cnt, ret;
107 108
108 if (name == "root") { 109 if (strcmp(name, "root") == 0) {
109 if (*ngroups >= 1) { 110 if (*ngroups >= 1) {
110 groups[0] = basegid; 111 groups[0] = basegid;
111 cnt = 1; 112 cnt = 1;
112 } 113 }
113 114
114 ret = (*ngroups >= cnt) ? 0 : -1; 115 ret = (*ngroups >= cnt) ? 0 : -1;
115 *ngroups = cnt; 116 *ngroups = cnt;
116 } else if (name == "test") { 117 } else if (strcmp(name, "test") == 0) {
117 if (*ngroups >= 1) { 118 if (*ngroups >= 1) {
118 groups[0] = basegid; 119 groups[0] = basegid;
119 cnt = 1; 120 cnt = 1;
120 } 121 }
121 122
122 if (*ngroups >= 2) { 123 if (*ngroups >= 2) {
123 groups[1] = 0; 124 groups[1] = 0;
124 cnt = 2; 125 cnt = 2;
125 } 126 }
126 127
127 ret = (*ngroups >= cnt) ? 0 : -1; 128 ret = (*ngroups >= cnt) ? 0 : -1;
128 *ngroups = cnt; 129 *ngroups = cnt;
129 } else 130 } else
130 ret = -1; 131 ret = -1;
131 132
132 return ret; 133 return ret;
133} 134}
134 135
135int 136int
136getgroups(int gidsetlen, gid_t *gidset) 137getgroups(int gidsetlen, gid_t *gidset)
137{ 138{
138 if (gidsetlen < 2) { 139 if (gidsetlen < 2) {
139 errno = EINVAL; 140 errno = EINVAL;
140 return -1; 141 return -1;
141 } 142 }
142 143
143 gidset[0] = 100; 144 gidset[0] = 100;
144 gidset[1] = 0; 145 gidset[1] = 0;
145 return 2; 146 return 2;
146} 147}
147 148
148struct passwd * 149struct passwd *
149getpwnam(const char *login) 150getpwnam(const char *login)
150{ 151{
151 struct passwd *p = &PwEntry; 152 struct passwd *p = &PwEntry;
152 153
153 memset(p, 0, sizeof(*p)); 154 memset(p, 0, sizeof(*p));
154 if (strcmp(login, "root") == 0) { 155 if (strcmp(login, "root") == 0) {
155 p->pw_name = "root"; 156 p->pw_name = __UNCONST("root");
156 p->pw_uid = 0; 157 p->pw_uid = 0;
157 p->pw_gid = 0; 158 p->pw_gid = 0;
158 } else if (strcmp(login, "test") == 0) { 159 } else if (strcmp(login, "test") == 0) {
159 p->pw_name = "test"; 160 p->pw_name = __UNCONST("test");
160 p->pw_uid = 100; 161 p->pw_uid = 100;
161 p->pw_gid = 100; 162 p->pw_gid = 100;
162 } else 163 } else
163 p = NULL; 164 p = NULL;
164 165
165 return p; 166 return p;
166} 167}
167 168
168struct passwd * 169struct passwd *
169getpwuid(uid_t uid) 170getpwuid(uid_t uid)
170{ 171{
171 struct passwd *p = &PwEntry; 172 struct passwd *p = &PwEntry;
172 173
173 memset(p, 0, sizeof(*p)); 174 memset(p, 0, sizeof(*p));
174 if (uid == 0) { 175 if (uid == 0) {
175 p->pw_name = "root"; 176 p->pw_name = __UNCONST("root");
176 p->pw_uid = 0; 177 p->pw_uid = 0;
177 p->pw_gid = 0; 178 p->pw_gid = 0;
178 } else if (uid == 100) { 179 } else if (uid == 100) {
179 p->pw_name = "test"; 180 p->pw_name = __UNCONST("test");
180 p->pw_uid = 100; 181 p->pw_uid = 100;
181 p->pw_gid = 100; 182 p->pw_gid = 100;
182 } else 183 } else
183 p = NULL; 184 p = NULL;
184 185
185 return p; 186 return p;
186} 187}