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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HTML_MESSAGE,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 17385 invoked from network); 9 Aug 2021 05:52:16 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 9 Aug 2021 05:52:16 -0000 Received: (qmail 29815 invoked by uid 550); 9 Aug 2021 05:52:14 -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 29797 invoked from network); 9 Aug 2021 05:52:12 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h= mime-version:references:in-reply-to:from:date:message-id:subject :to:cc:content-type; s=sasl; bh=LYaxFBDNDg9aWYEM/y8cBjYIvFmkZ458 hCpXNjB+jrg=; b=TpMxbud7wDA9wpJcvpQvcVuD9OT/pgukRpIza49lhQkjANkV uW8zN67D2V3Thp2o6+D/9v/4xI1iV6Zw7Y0HIQYqyAy9V+l9g7gGcBp6/aU55m8K VT3fWOR3xgs+Dc7CUYWChUJvXhB/+fOW7lPIxuePV5h0exjqgH2ze7jr3oI= X-Gm-Message-State: AOAM531U1Cuz9dHRFsnNtGa18jVk/9nvZ/Gf7jUEFAOnyKwzH6egsRnF bsGjDUYrIldG7iOXOoorvPT4QAIDXompKxv4Yww= X-Google-Smtp-Source: ABdhPJybOIlSfDqkCncJCWx0V/UFP3ToI0+G1PTAnPcsqbeS2vfTMcb+gODOKZIN311TBRjW3rTkKp+9nlOf3fObYUw= X-Received: by 2002:aa7:d70b:: with SMTP id t11mr25470059edq.20.1628488312916; Sun, 08 Aug 2021 22:51:52 -0700 (PDT) MIME-Version: 1.0 References: <20210808112908.44345-1-galibert@pobox.com> <20210808230616.GZ13220@brightrain.aerifal.cx> In-Reply-To: <20210808230616.GZ13220@brightrain.aerifal.cx> From: Olivier Galibert Date: Mon, 9 Aug 2021 07:51:42 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Rich Felker Cc: musl@lists.openwall.com, =?UTF-8?Q?=C3=89rico_Nogueira?= Content-Type: multipart/alternative; boundary="000000000000698e6205c919fbed" X-Pobox-Relay-ID: E6EE6748-F8D5-11EB-9A6E-D5C30F5B5667-92059326!pb-smtp20.pobox.com Subject: Re: [musl] [PATCH] stdlib: Add test for the qsort_r extension --000000000000698e6205c919fbed Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Indeed it is :-) OG. Le lun. 9 ao=C3=BBt 2021 =C3=A0 01:06, Rich Felker a =C3= =A9crit : > On Sun, Aug 08, 2021 at 05:31:07PM -0300, =C3=89rico Nogueira wrote: > > Tests should be included in libc-test instead, musl doesn't carry test > > code. > > > > http://nsz.repo.hu/git/?p=3Dlibc-test > > I'm pretty sure this *is* a patch against libc-test (see the directory > structure and "test.h"). > > > On Sun Aug 8, 2021 at 8:29 AM -03, Olivier Galibert wrote: > > > 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 > > + if (strcmp(a[i], a_sorted[i]) !=3D 0) { > > > + t_error("string sort failed at index %d\n", i); > > > + t_printf("\ti\tgot\twant\n"); > > > + for (i=3D0; i > > + t_printf("\t%d\t%s\t%s\n", i, a[i], a_sorted[i]); > > > + break; > > > + } > > > + } > > > +} > > > + > > > +static void int_test(int *a, int *a_sorted, int len) > > > +{ > > > + int i; > > > + qsort_r(a, len, sizeof *a, icmp, expected_arg); > > > + for (i=3D0; i > > + if (a[i] !=3D a_sorted[i]) { > > > + t_error("integer sort failed at index %d\n", i); > > > + t_printf("\ti\tgot\twant\n"); > > > + for (i=3D0; i > > + t_printf("\t%d\t%d\t%d\n", i, a[i], a_sorted[i]); > > > + break; > > > + } > > > + } > > > +} > > > + > > > +static void uint64_gen(uint64_t *p, uint64_t *p_sorted, int n) > > > +{ > > > + int i; > > > + uint64_t r =3D 0; > > > + t_randseed(n); > > > + for (i =3D 0; i < n; i++) { > > > + r +=3D t_randn(20); > > > + p[i] =3D r; > > > + } > > > + memcpy(p_sorted, p, n * sizeof *p); > > > + t_shuffle(p, n); > > > +} > > > + > > > +static void uint64_test(uint64_t *a, uint64_t *a_sorted, int len) > > > +{ > > > + int i; > > > + qsort_r(a, len, sizeof *a, cmp64, expected_arg); > > > + for (i=3D0; i > > + if (a[i] !=3D a_sorted[i]) { > > > + t_error("uint64 sort failed at index %d\n", i); > > > + t_printf("\ti\tgot\twant\n"); > > > + for (i=3D0; i > > + t_printf("\t%d\t%" PRIu64 "\t%" PRIu64 "\n", i, a[i], a_sorted[i]); > > > + break; > > > + } > > > + } > > > +} > > > + > > > +#define T(a, a_sorted) do { \ > > > + char p[] =3D a; \ > > > + qsort_r(p, sizeof p - 1, 1, ccmp, expected_arg); \ > > > + if (memcmp(p, a_sorted, sizeof p) !=3D 0) { \ > > > + t_error("character sort failed\n"); \ > > > + t_printf("\tgot: \"%s\"\n", p); \ > > > + t_printf("\twant: \"%s\"\n", a_sorted); \ > > > + } \ > > > +} while(0) > > > + > > > +static void char_test(void) > > > +{ > > > + T("", ""); > > > + T("1", "1"); > > > + T("11", "11"); > > > + T("12", "12"); > > > + T("21", "12"); > > > + T("111", "111"); > > > + T("211", "112"); > > > + T("121", "112"); > > > + T("112", "112"); > > > + T("221", "122"); > > > + T("212", "122"); > > > + T("122", "122"); > > > + T("123", "123"); > > > + T("132", "123"); > > > + T("213", "123"); > > > + T("231", "123"); > > > + T("321", "123"); > > > + T("312", "123"); > > > + T("1423", "1234"); > > > + T("51342", "12345"); > > > + T("261435", "123456"); > > > + T("4517263", "1234567"); > > > + T("37245618", "12345678"); > > > + T("812436597", "123456789"); > > > + T("987654321", "123456789"); > > > + T("321321321", "111222333"); > > > + T("49735862185236174", "11223344556677889"); > > > +} > > > + > > > +int main(void) > > > +{ > > > + int i; > > > + > > > + expected_arg =3D &expected_arg; > > > + > > > + str_test(s, s_sorted, sizeof s/sizeof*s); > > > + int_test(n, n_sorted, sizeof n/sizeof*n); > > > + char_test(); > > > + for (i =3D 1023; i<=3D1026; i++) { > > > + uint64_t p[1026], p_sorted[1026]; > > > + uint64_gen(p, p_sorted, i); > > > + uint64_test(p, p_sorted, i); > > > + } > > > + return t_status; > > > +} > > > -- > > > 2.32.0 > --000000000000698e6205c919fbed Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Indeed it is :-)

=C2=A0 OG.

Le=C2=A0lun. 9 ao=C3=BBt 2021 =C3=A0 01:06, Rich = Felker <dalias@libc.org> a =C3= =A9crit=C2=A0:
On Sun, Aug 08, 2021= at 05:31:07PM -0300, =C3=89rico Nogueira wrote:
> Tests should be included in libc-test instead, musl doesn't carry = test
> code.
>
> http://nsz.repo.hu/git/?p=3Dlibc-test

I'm pretty sure this *is* a patch against libc-test (see the directory<= br> structure and "test.h").

> On Sun Aug 8, 2021 at 8:29 AM -03, Olivier Galibert wrote:
> > 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<= br> > > new file mode 100644
> > index 0000000..97a48c2
> > --- /dev/null
> > +++ b/src/functional/qsort_r.c
> > @@ -0,0 +1,202 @@
> > +#define _GNU_SOURCE
> > +
> > +#include <inttypes.h>
> > +#include <stdlib.h>
> > +#include <stdio.h>
> > +#include <string.h>
> > +#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", "Cer= es",
> > + "Helga", "Drepper", "Emeralda", &= quot;Zoran",
> > + "Momo", "Frank", "Pema", "Xa= vier",
> > + "Yeva", "Gedun", "Irina", "N= ono",
> > + "Wiener", "Vincent", "Tsering", &= quot;Karnica",
> > + "Lulu", "Quincy", "Osama", "= Riley",
> > + "Ursula", "Sam"
> > +};
> > +static const char *s_sorted[] =3D {
> > + "Alice", "Bob", "Ceres", "Dr= epper",
> > + "Emeralda", "Frank", "Gedun", &qu= ot;Helga",
> > + "Irina", "John", "Karnica", "= ;Lulu",
> > + "Momo", "Nono", "Osama", "Pe= ma",
> > + "Quincy", "Riley", "Sam", "T= sering",
> > + "Ursula", "Vincent", "Wiener", &q= uot;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<len; i++) {
> > + if (strcmp(a[i], a_sorted[i]) !=3D 0) {
> > + t_error("string sort failed at index %d\n", i);
> > + t_printf("\ti\tgot\twant\n");
> > + for (i=3D0; i<len; i++)
> > + t_printf("\t%d\t%s\t%s\n", i, a[i], a_sorted[i]);
> > + break;
> > + }
> > + }
> > +}
> > +
> > +static void int_test(int *a, int *a_sorted, int len)
> > +{
> > + int i;
> > + qsort_r(a, len, sizeof *a, icmp, expected_arg);
> > + for (i=3D0; i<len; i++) {
> > + if (a[i] !=3D a_sorted[i]) {
> > + t_error("integer sort failed at index %d\n", i);
> > + t_printf("\ti\tgot\twant\n");
> > + for (i=3D0; i<len; i++)
> > + t_printf("\t%d\t%d\t%d\n", i, a[i], a_sorted[i]);
> > + break;
> > + }
> > + }
> > +}
> > +
> > +static void uint64_gen(uint64_t *p, uint64_t *p_sorted, int n) > > +{
> > + int i;
> > + uint64_t r =3D 0;
> > + t_randseed(n);
> > + for (i =3D 0; i < n; i++) {
> > + r +=3D t_randn(20);
> > + p[i] =3D r;
> > + }
> > + memcpy(p_sorted, p, n * sizeof *p);
> > + t_shuffle(p, n);
> > +}
> > +
> > +static void uint64_test(uint64_t *a, uint64_t *a_sorted, int len= )
> > +{
> > + int i;
> > + qsort_r(a, len, sizeof *a, cmp64, expected_arg);
> > + for (i=3D0; i<len; i++) {
> > + if (a[i] !=3D a_sorted[i]) {
> > + t_error("uint64 sort failed at index %d\n", i);
> > + t_printf("\ti\tgot\twant\n");
> > + for (i=3D0; i<len; i++)
> > + t_printf("\t%d\t%" PRIu64 "\t%" PRIu64 &quo= t;\n", i, a[i], a_sorted[i]);
> > + break;
> > + }
> > + }
> > +}
> > +
> > +#define T(a, a_sorted) do { \
> > + char p[] =3D a; \
> > + qsort_r(p, sizeof p - 1, 1, ccmp, expected_arg); \
> > + if (memcmp(p, a_sorted, sizeof p) !=3D 0) { \
> > + t_error("character sort failed\n"); \
> > + t_printf("\tgot: \"%s\"\n", p); \
> > + t_printf("\twant: \"%s\"\n", a_sorted); \ > > + } \
> > +} while(0)
> > +
> > +static void char_test(void)
> > +{
> > + T("", "");
> > + T("1", "1");
> > + T("11", "11");
> > + T("12", "12");
> > + T("21", "12");
> > + T("111", "111");
> > + T("211", "112");
> > + T("121", "112");
> > + T("112", "112");
> > + T("221", "122");
> > + T("212", "122");
> > + T("122", "122");
> > + T("123", "123");
> > + T("132", "123");
> > + T("213", "123");
> > + T("231", "123");
> > + T("321", "123");
> > + T("312", "123");
> > + T("1423", "1234");
> > + T("51342", "12345");
> > + T("261435", "123456");
> > + T("4517263", "1234567");
> > + T("37245618", "12345678");
> > + T("812436597", "123456789");
> > + T("987654321", "123456789");
> > + T("321321321", "111222333");
> > + T("49735862185236174", "11223344556677889")= ;
> > +}
> > +
> > +int main(void)
> > +{
> > + int i;
> > +
> > + expected_arg =3D &expected_arg;
> > +
> > + str_test(s, s_sorted, sizeof s/sizeof*s);
> > + int_test(n, n_sorted, sizeof n/sizeof*n);
> > + char_test();
> > + for (i =3D 1023; i<=3D1026; i++) {
> > + uint64_t p[1026], p_sorted[1026];
> > + uint64_gen(p, p_sorted, i);
> > + uint64_test(p, p_sorted, i);
> > + }
> > + return t_status;
> > +}
> > --
> > 2.32.0
--000000000000698e6205c919fbed--