2 * Copyright (C) 2020 Edward Tomasz Napierala <trasz@FreeBSD.org>
3 * Copyright (C) 2004 Maxim Sobolev <sobomax@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Test for qsort_r(3) routine.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
38 #include "test-sort.h"
43 sorthelp_r(void *thunk, const void *a, const void *b)
47 ATF_REQUIRE_EQ(*(int *)thunk, THUNK);
51 /* Don't use "return *oa - *ob" since it's easy to cause overflow! */
59 ATF_TC_WITHOUT_HEAD(qsort_r_test);
60 ATF_TC_BODY(qsort_r_test, tc)
62 int testvector[IVEC_LEN];
63 int sresvector[IVEC_LEN];
67 for (j = 2; j < IVEC_LEN; j++) {
68 /* Populate test vectors */
69 for (i = 0; i < j; i++)
70 testvector[i] = sresvector[i] = initvector[i];
72 /* Sort using qsort_r(3) */
73 qsort_r(testvector, j, sizeof(testvector[0]), &thunk,
75 /* Sort using reference slow sorting routine */
79 for (i = 0; i < j; i++)
80 ATF_CHECK_MSG(testvector[i] == sresvector[i],
81 "item at index %d didn't match: %d != %d",
82 i, testvector[i], sresvector[i]);
89 ATF_TP_ADD_TC(tp, qsort_r_test);
91 return (atf_no_error());