From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 21701 invoked from network); 8 Aug 2021 11:30:10 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 8 Aug 2021 11:30:10 -0000 Received: (qmail 20269 invoked by uid 550); 8 Aug 2021 11:30:09 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 20239 invoked from network); 8 Aug 2021 11:30:08 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:mime-version:content-transfer-encoding; s=sasl; bh=iz/KWq9qcaLCKQrUvWtSKnfo6P+F/dptjYF3qf3Lszw=; b=l91U klP2rk6lf7Mn3kZdJB42c4BGIsoI9dSsCzse0XNWw7ycKNFrhy0EINM2RekJpQGG PbXLkA61D8BE0EkzA3I8SVsbXs6876ESPhMejKra8cM9GcwX7McBjNMm84c7ODVn iyABuD6mwLL5repNjyk1SSRgduN4MzC+h1Wmd6s= From: Olivier Galibert To: musl@lists.openwall.com Cc: Olivier Galibert Date: Sun, 8 Aug 2021 13:29:09 +0200 Message-Id: <20210808112908.44345-1-galibert@pobox.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Pobox-Relay-ID: F4AAE838-F83B-11EB-A8E8-FD8818BA3BAF-92059326!pb-smtp2.pobox.com Content-Transfer-Encoding: quoted-printable Subject: [musl] [PATCH] stdlib: Add test for the qsort_r extension This allows to validate the associated musl patch. --- src/functional/qsort_r.c | 202 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 src/functional/qsort_r.c diff --git a/src/functional/qsort_r.c b/src/functional/qsort_r.c new file mode 100644 index 0000000..97a48c2 --- /dev/null +++ b/src/functional/qsort_r.c @@ -0,0 +1,202 @@ +#define _GNU_SOURCE + +#include +#include +#include +#include +#include "test.h" + +void *expected_arg; + +static int scmp(const void *a, const void *b, void *arg) +{ + if (arg !=3D expected_arg) { + t_error("argument passing failed\n"); + t_printf("\tgot: %p\n", arg); + t_printf("\twant: %p\n", expected_arg); + } + + return strcmp(*(char **)a, *(char **)b); +} + +static int icmp(const void *a, const void *b, void *arg) +{ + if (arg !=3D expected_arg) { + t_error("argument passing failed\n"); + t_printf("\tgot: %p\n", arg); + t_printf("\twant: %p\n", expected_arg); + } + + return *(int*)a - *(int*)b; +} + +static int ccmp(const void *a, const void *b, void *arg) +{ + if (arg !=3D expected_arg) { + t_error("argument passing failed\n"); + t_printf("\tgot: %p\n", arg); + t_printf("\twant: %p\n", expected_arg); + } + + return *(char*)a - *(char*)b; +} + +static int cmp64(const void *a, const void *b, void *arg) +{ + if (arg !=3D expected_arg) { + t_error("argument passing failed\n"); + t_printf("\tgot: %p\n", arg); + t_printf("\twant: %p\n", expected_arg); + } + + const uint64_t *ua =3D a, *ub =3D b; + return *ua < *ub ? -1 : *ua !=3D *ub; +} + +/* 26 items -- even */ +static const char *s[] =3D { + "Bob", "Alice", "John", "Ceres", + "Helga", "Drepper", "Emeralda", "Zoran", + "Momo", "Frank", "Pema", "Xavier", + "Yeva", "Gedun", "Irina", "Nono", + "Wiener", "Vincent", "Tsering", "Karnica", + "Lulu", "Quincy", "Osama", "Riley", + "Ursula", "Sam" +}; +static const char *s_sorted[] =3D { + "Alice", "Bob", "Ceres", "Drepper", + "Emeralda", "Frank", "Gedun", "Helga", + "Irina", "John", "Karnica", "Lulu", + "Momo", "Nono", "Osama", "Pema", + "Quincy", "Riley", "Sam", "Tsering", + "Ursula", "Vincent", "Wiener", "Xavier", + "Yeva", "Zoran" +}; + +/* 23 items -- odd, prime */ +static int n[] =3D { + 879045, 394, 99405644, 33434, 232323, 4334, 5454, + 343, 45545, 454, 324, 22, 34344, 233, 45345, 343, + 848405, 3434, 3434344, 3535, 93994, 2230404, 4334 +}; +static int n_sorted[] =3D { + 22, 233, 324, 343, 343, 394, 454, 3434, + 3535, 4334, 4334, 5454, 33434, 34344, 45345, 45545, + 93994, 232323, 848405, 879045, 2230404, 3434344, 99405644 +}; + +static void str_test(const char **a, const char **a_sorted, int len) +{ + int i; + qsort_r(a, len, sizeof *a, scmp, expected_arg); + for (i=3D0; i