diff options
author | millert <> | 2017-05-17 15:13:30 +0000 |
---|---|---|
committer | millert <> | 2017-05-17 15:13:30 +0000 |
commit | a5ab3b8cdd64750c6facf4db12d4c2e6b9502424 (patch) | |
tree | 7cfa547338fc0523c442dcfb4d6716f4792cd5eb /src/regress/lib/libc | |
parent | ae5a5006e37f7a3e29b7e75e240e83cd1b3f87ae (diff) | |
download | openbsd-a5ab3b8cdd64750c6facf4db12d4c2e6b9502424.tar.gz openbsd-a5ab3b8cdd64750c6facf4db12d4c2e6b9502424.tar.bz2 openbsd-a5ab3b8cdd64750c6facf4db12d4c2e6b9502424.zip |
There's no need to track the number of errors (and the counter might
wrap), make it a flag instead. Pointed out by schwarze@
Diffstat (limited to 'src/regress/lib/libc')
-rw-r--r-- | src/regress/lib/libc/qsort/qsort_test.c | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/src/regress/lib/libc/qsort/qsort_test.c b/src/regress/lib/libc/qsort/qsort_test.c index 4b2100de97..f78137504a 100644 --- a/src/regress/lib/libc/qsort/qsort_test.c +++ b/src/regress/lib/libc/qsort/qsort_test.c | |||
@@ -116,7 +116,7 @@ static int | |||
116 | test_distribution(int dist, int m, int n, int *x, int *y, int *z) | 116 | test_distribution(int dist, int m, int n, int *x, int *y, int *z) |
117 | { | 117 | { |
118 | int i, j; | 118 | int i, j; |
119 | int errors = 0; | 119 | int ret = 0; |
120 | 120 | ||
121 | /* Fill in x[] based on distribution and 'm' */ | 121 | /* Fill in x[] based on distribution and 'm' */ |
122 | fill_test_array(x, n, dist, m); | 122 | fill_test_array(x, n, dist, m); |
@@ -128,11 +128,12 @@ test_distribution(int dist, int m, int n, int *x, int *y, int *z) | |||
128 | if (sigsetjmp(cmpjmp, 1) != 0) { | 128 | if (sigsetjmp(cmpjmp, 1) != 0) { |
129 | warnx("qsort aborted: %zu compares, dist %d, m: %d, n: %d", | 129 | warnx("qsort aborted: %zu compares, dist %d, m: %d, n: %d", |
130 | compares, dist, m, n); | 130 | compares, dist, m, n); |
131 | errors++; | 131 | ret = 1; |
132 | } else { | 132 | } else { |
133 | qsort(y, n, sizeof(y[0]), cmp_checked); | 133 | qsort(y, n, sizeof(y[0]), cmp_checked); |
134 | heapsort(z, n, sizeof(z[0]), cmp); | 134 | heapsort(z, n, sizeof(z[0]), cmp); |
135 | errors += check_result("copy", y, z, dist, m, n); | 135 | if (check_result("copy", y, z, dist, m, n) != 0) |
136 | ret = 1; | ||
136 | } | 137 | } |
137 | 138 | ||
138 | /* Test on reversed copy of x[] */ | 139 | /* Test on reversed copy of x[] */ |
@@ -142,11 +143,12 @@ test_distribution(int dist, int m, int n, int *x, int *y, int *z) | |||
142 | if (sigsetjmp(cmpjmp, 1) != 0) { | 143 | if (sigsetjmp(cmpjmp, 1) != 0) { |
143 | warnx("qsort aborted (%s): %zu compares, dist %d, m: %d, n: %d", | 144 | warnx("qsort aborted (%s): %zu compares, dist %d, m: %d, n: %d", |
144 | "reversed", compares, dist, m, n); | 145 | "reversed", compares, dist, m, n); |
145 | errors++; | 146 | ret = 1; |
146 | } else { | 147 | } else { |
147 | qsort(y, n, sizeof(y[0]), cmp_checked); | 148 | qsort(y, n, sizeof(y[0]), cmp_checked); |
148 | heapsort(z, n, sizeof(z[0]), cmp); | 149 | heapsort(z, n, sizeof(z[0]), cmp); |
149 | errors += check_result("reversed", y, z, dist, m, n); | 150 | if (check_result("reversed", y, z, dist, m, n) != 0) |
151 | ret = 1; | ||
150 | } | 152 | } |
151 | 153 | ||
152 | /* Test with front half of x[] reversed */ | 154 | /* Test with front half of x[] reversed */ |
@@ -158,11 +160,12 @@ test_distribution(int dist, int m, int n, int *x, int *y, int *z) | |||
158 | if (sigsetjmp(cmpjmp, 1) != 0) { | 160 | if (sigsetjmp(cmpjmp, 1) != 0) { |
159 | warnx("qsort aborted (%s): %zu compares, dist %d, m: %d, n: %d", | 161 | warnx("qsort aborted (%s): %zu compares, dist %d, m: %d, n: %d", |
160 | "front reversed", compares, dist, m, n); | 162 | "front reversed", compares, dist, m, n); |
161 | errors++; | 163 | ret = 1; |
162 | } else { | 164 | } else { |
163 | qsort(y, n, sizeof(y[0]), cmp_checked); | 165 | qsort(y, n, sizeof(y[0]), cmp_checked); |
164 | heapsort(z, n, sizeof(z[0]), cmp); | 166 | heapsort(z, n, sizeof(z[0]), cmp); |
165 | errors += check_result("front reversed", y, z, dist, m, n); | 167 | if (check_result("front reversed", y, z, dist, m, n) != 0) |
168 | ret = 1; | ||
166 | } | 169 | } |
167 | 170 | ||
168 | /* Test with back half of x[] reversed */ | 171 | /* Test with back half of x[] reversed */ |
@@ -174,11 +177,12 @@ test_distribution(int dist, int m, int n, int *x, int *y, int *z) | |||
174 | if (sigsetjmp(cmpjmp, 1) != 0) { | 177 | if (sigsetjmp(cmpjmp, 1) != 0) { |
175 | warnx("qsort aborted (%s): %zu compares, dist %d, m: %d, n: %d", | 178 | warnx("qsort aborted (%s): %zu compares, dist %d, m: %d, n: %d", |
176 | "back reversed", compares, dist, m, n); | 179 | "back reversed", compares, dist, m, n); |
177 | errors++; | 180 | ret = 1; |
178 | } else { | 181 | } else { |
179 | qsort(y, n, sizeof(y[0]), cmp_checked); | 182 | qsort(y, n, sizeof(y[0]), cmp_checked); |
180 | heapsort(z, n, sizeof(z[0]), cmp); | 183 | heapsort(z, n, sizeof(z[0]), cmp); |
181 | errors += check_result("back reversed", y, z, dist, m, n); | 184 | if (check_result("back reversed", y, z, dist, m, n) != 0) |
185 | ret = 1; | ||
182 | } | 186 | } |
183 | 187 | ||
184 | /* Test on sorted copy of x[] */ | 188 | /* Test on sorted copy of x[] */ |
@@ -189,10 +193,11 @@ test_distribution(int dist, int m, int n, int *x, int *y, int *z) | |||
189 | if (sigsetjmp(cmpjmp, 1) != 0) { | 193 | if (sigsetjmp(cmpjmp, 1) != 0) { |
190 | warnx("qsort aborted (%s): %zu compares, dist %d, m: %d, n: %d", | 194 | warnx("qsort aborted (%s): %zu compares, dist %d, m: %d, n: %d", |
191 | "sorted", compares, dist, m, n); | 195 | "sorted", compares, dist, m, n); |
192 | errors++; | 196 | ret = 1; |
193 | } else { | 197 | } else { |
194 | qsort(y, n, sizeof(y[0]), cmp_checked); | 198 | qsort(y, n, sizeof(y[0]), cmp_checked); |
195 | errors += check_result("sorted", y, x, dist, m, n); | 199 | if (check_result("sorted", y, x, dist, m, n) != 0) |
200 | ret = 1; | ||
196 | } | 201 | } |
197 | 202 | ||
198 | /* Test with i%5 added to x[i] (dither) */ | 203 | /* Test with i%5 added to x[i] (dither) */ |
@@ -202,21 +207,22 @@ test_distribution(int dist, int m, int n, int *x, int *y, int *z) | |||
202 | if (sigsetjmp(cmpjmp, 1) != 0) { | 207 | if (sigsetjmp(cmpjmp, 1) != 0) { |
203 | warnx("qsort aborted (%s): %zu compares, dist %d, m: %d, n: %d", | 208 | warnx("qsort aborted (%s): %zu compares, dist %d, m: %d, n: %d", |
204 | "dithered", compares, dist, m, n); | 209 | "dithered", compares, dist, m, n); |
205 | errors++; | 210 | ret = 1; |
206 | } else { | 211 | } else { |
207 | qsort(y, n, sizeof(y[0]), cmp_checked); | 212 | qsort(y, n, sizeof(y[0]), cmp_checked); |
208 | heapsort(z, n, sizeof(z[0]), cmp); | 213 | heapsort(z, n, sizeof(z[0]), cmp); |
209 | errors += check_result("dithered", y, z, dist, m, n); | 214 | if (check_result("dithered", y, z, dist, m, n) != 0) |
215 | ret = 1; | ||
210 | } | 216 | } |
211 | 217 | ||
212 | return errors; | 218 | return ret; |
213 | } | 219 | } |
214 | 220 | ||
215 | static int | 221 | static int |
216 | run_tests(int m, int n) | 222 | run_tests(int m, int n) |
217 | { | 223 | { |
218 | int *x, *y, *z; | 224 | int *x, *y, *z; |
219 | int errors = 0; | 225 | int ret = 0; |
220 | double nlgn; | 226 | double nlgn; |
221 | enum distribution dist; | 227 | enum distribution dist; |
222 | 228 | ||
@@ -236,13 +242,15 @@ run_tests(int m, int n) | |||
236 | if (y == NULL || y == NULL || z == NULL) | 242 | if (y == NULL || y == NULL || z == NULL) |
237 | err(1, NULL); | 243 | err(1, NULL); |
238 | 244 | ||
239 | for (dist = SAWTOOTH; dist != INVALID; dist++) | 245 | for (dist = SAWTOOTH; dist != INVALID; dist++) { |
240 | errors += test_distribution(dist, m, n, x, y, z); | 246 | if (test_distribution(dist, m, n, x, y, z) != 0) |
247 | ret = 1; | ||
248 | } | ||
241 | 249 | ||
242 | free(x); | 250 | free(x); |
243 | free(y); | 251 | free(y); |
244 | free(z); | 252 | free(z); |
245 | return errors; | 253 | return ret; |
246 | } | 254 | } |
247 | 255 | ||
248 | int | 256 | int |
@@ -250,13 +258,14 @@ main(int argc, char *argv[]) | |||
250 | { | 258 | { |
251 | int *nn, nums[] = { 100, 1023, 1024, 1025, 4095, 4096, 4097, -1 }; | 259 | int *nn, nums[] = { 100, 1023, 1024, 1025, 4095, 4096, 4097, -1 }; |
252 | int m, n; | 260 | int m, n; |
253 | int errors = 0; | 261 | int ret = 0; |
254 | 262 | ||
255 | for (nn = nums; (n = *nn) > 0; nn++) { | 263 | for (nn = nums; (n = *nn) > 0; nn++) { |
256 | for (m = 1; m < 2 * n; m *= 2) { | 264 | for (m = 1; m < 2 * n; m *= 2) { |
257 | errors += run_tests(m, n); | 265 | if (run_tests(m, n) != 0) |
266 | ret = 1; | ||
258 | } | 267 | } |
259 | } | 268 | } |
260 | 269 | ||
261 | return errors; | 270 | return ret; |
262 | } | 271 | } |