From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by sourceware.org (Postfix) with ESMTP id C3DBD385700B for ; Mon, 29 May 2023 20:10:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C3DBD385700B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=nabijaczleweli.xyz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nabijaczleweli.xyz Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 259CC8EEC; Mon, 29 May 2023 22:10:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1685391004; bh=PpO84p5/LpsrIsNtcZCrtfhBQ3D/MapWGs5Z0urNmVk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qs6mqKJI71sNYr5rP5LbK9GnX7a6RQiKOB1cjoVIW+P8MH22t8sTsoiyW59TtZ5s6 CzV3YjTJbuCVekhMIB2q6pvHXq10naljQh3CgeBpLaC8rnf3Uir7mYMCdZ/mas/2zu 68pT7FJsGEAGqRdkU0xxoyYA9hRImfNOp8rOcIkxB9Ue+VC5xdusq54aOjpkVCc6KG qQr/I1B8OXmkcbDX3uZz0gFLIm4Gbrexwg//q3rE+YBLRlbrgvub62VF7KZNoLPCUB ay/aGIzntzSlz3Sc6nEZEdPV5xTdtmApK4ogoBmv32bdWpul88uyGB8vJqSlNq1dvy WOqqqyJ71C/uA== Date: Mon, 29 May 2023 22:10:02 +0200 From: =?utf-8?B?0L3QsNCx?= To: Adhemerval Zanella Netto Cc: Carlos O'Donell , libc-alpha@sourceware.org Subject: Re: [PATCH v4 1/3] posix: add (failing) test for REG_STARTEND Message-ID: References: <1d5642ecb4bb477c9fd7e1ebaee868fe4ccbefc7.1683500149.git.nabijaczleweli@nabijaczleweli.xyz> <5bf23525-60bf-d37a-be6b-7b4ee3705bfa@linaro.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="wx62bgonypccfs67" Content-Disposition: inline In-Reply-To: <5bf23525-60bf-d37a-be6b-7b4ee3705bfa@linaro.org> User-Agent: NeoMutt/20230517 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_INFOUSMEBIZ,PDS_RDNS_DYNAMIC_FP,RDNS_DYNAMIC,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --wx62bgonypccfs67 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, May 29, 2023 at 02:37:39PM -0300, Adhemerval Zanella Netto wrote: > On 07/05/23 19:56, =D0=BD=D0=B0=D0=B1 via Libc-alpha wrote: > > This test passes on NetBSD, the illumos gate, and musl > > with https://www.openwall.com/lists/musl/2023/04/20/2; > > it's nothing revolutionary and the behaviour it tests > > is largely guaranteed by the 4.4BSD-Lite manual; > > nevertheless, it currently fails with > > tst-reg-startend.c: ^a: a^@c: no match$ > > tst-reg-startend.c: ^a: a^@c: wanted {1, 2}, got {1, 4}$ > > tst-reg-startend.c: ^a: abc: no match$ > > tst-reg-startend.c: ^a: abc: wanted {1, 2}, got {1, 4}$ > > tst-reg-startend.c: ^a.c$: a^@c: no match$ > > tst-reg-startend.c: ^a.c$: abc: no match$ > > tst-reg-startend.c: ^a.*c$: a^@c: no match$ > > tst-reg-startend.c: ^a.*c$: abc: no match$ > > tst-reg-startend.c: ^a[^c]c$: a^@c: no match$ > > tst-reg-startend.c: ^a[^c]c$: abc: no match$ > > tst-reg-startend.c: ^a..: a^@c: no match$ > > tst-reg-startend.c: ^a..: abc: no match$ > > tst-reg-startend.c: ..c: a^@c: no match$ > >=20 > > The test may also be compiled stand-alone (-DSTANDALONE) > > and on all platforms that have the interface > > (hence the macro to initialise regmatch_ts, > > which start with pointer fields on the illumos gate), > > for ease of testing and inclusion in other test suites. > Tests that should triggers newer regressions should be either marks as XF= AIL, > or in this case, move after the patch that actually fixes it.=20 I've moved it to the end as 3/3 locally. > > diff --git a/posix/tst-reg-startend.c b/posix/tst-reg-startend.c > > new file mode 100644 > > index 0000000000..c3bfac0359 > > --- /dev/null > > +++ b/posix/tst-reg-startend.c > > @@ -0,0 +1,124 @@ > > +/* Permission to use, copy, modify, and/or distribute this software fo= r any > > + purpose with or without fee is hereby granted. > > + > > + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRA= NTIES > > + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF > > + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE= FOR > > + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMA= GES > > + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN = AN > > + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OU= T OF > > + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ > I am not sure if we can accept such license. It not the current one used = for > newer submission, including tests (LGPL 2.1). There are tests and other glibc code under ISC-style licences already but sure; I've slapped Unlicense text on this, which appears to be preferred by the Foundation since I'm an EU citizen (and the Unlicense is also already used in glibc). > > +static_assert(sizeof(regex_ac) / sizeof(*regex_ac) - 1 =3D=3D > > + sizeof(results_ac) / sizeof(*results_ac), ""); > > +static_assert(sizeof(regex_aa) / sizeof(*regex_aa) - 1 =3D=3D > > + sizeof(results_aa) / sizeof(*results_aa), ""); > Instead of the static_assert, why not add the input arguments and the > expect result on same struct? Applied. > > +static bool > > +testbunch (const char *const *regexes, const char *const data[static 2= ], > > + const regmatch_t *results) > > +{ > > +#define BASEERR(data) \ > > + err =3D true, \ > > + fprintf (stdout, __FILE__ ": %s: ", *regexes), \ > > + fwrite (data[i] + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdou= t) > We have macros that already log and handle the required boilerplate to > report tests issues on support/check.h. Newer tests should use it. I've used those for recording errors, but since the error logging takes format strings, it don't allow arbitrary data being logged. > > + for (size_t i =3D 0; i < 2; ++i) > We have array_length macro to avoid putting array sizes everywhere (and t= hey > work better if we want to extend the tests). Converted everything into 0-terminated arrays. > > +static int > > +do_test (int argc, char **argv) > > +{ > > + (void) argc, (void) argv; > Not really need here. And forbidden by the new wrapper. > > + assert (setlocale (LC_ALL, "C.UTF-8")); > > + > > + return testbunch (regex_ac, data_ac, results_ac) || > > + testbunch (regex_aa, data_aa, results_aa) || > > + testmb (); > > +} > > + > > + > > +#ifndef STANDALONE > > +#include "../test-skeleton.c" > Use #include instead. Applied. v6 scissor-patch follows. Best, -- >8 -- Date: Fri, 21 Apr 2023 23:57:16 +0200 Subject: [PATCH v5 3/3] posix: add test for REG_STARTEND This test passes on NetBSD, the illumos gate, musl with https://www.openwall.com/lists/musl/2023/05/14/1, and now glibc. It's nothing revolutionary and the behaviour it tests is largely guaranteed by the 4.4BSD-Lite manual; nevertheless, it used to fail with tst-reg-startend.c: ^a: a^@c: no match$ tst-reg-startend.c: ^a: a^@c: wanted {1, 2}, got {1, 4}$ tst-reg-startend.c: ^a: abc: no match$ tst-reg-startend.c: ^a: abc: wanted {1, 2}, got {1, 4}$ tst-reg-startend.c: ^a.c$: a^@c: no match$ tst-reg-startend.c: ^a.c$: abc: no match$ tst-reg-startend.c: ^a.*c$: a^@c: no match$ tst-reg-startend.c: ^a.*c$: abc: no match$ tst-reg-startend.c: ^a[^c]c$: a^@c: no match$ tst-reg-startend.c: ^a[^c]c$: abc: no match$ tst-reg-startend.c: ^a..: a^@c: no match$ tst-reg-startend.c: ^a..: abc: no match$ tst-reg-startend.c: ..c: a^@c: no match$ Signed-off-by: Ahelenia Ziemia=C5=84ska --- posix/Makefile | 1 + posix/tst-reg-startend.c | 142 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 posix/tst-reg-startend.c diff --git a/posix/Makefile b/posix/Makefile index e19b74cd67..abc0ff1f60 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -295,6 +295,7 @@ tests :=3D \ tst-posix_spawn-setsid \ tst-preadwrite \ tst-preadwrite64 \ + tst-reg-startend \ tst-regcomp-truncated \ tst-regex \ tst-regex2 \ diff --git a/posix/tst-reg-startend.c b/posix/tst-reg-startend.c new file mode 100644 index 0000000000..854d430676 --- /dev/null +++ b/posix/tst-reg-startend.c @@ -0,0 +1,142 @@ +/* This is free and unencumbered software released into the public domain. + + Anyone is free to copy, modify, publish, use, compile, sell, or + distribute this software, either in source code form or as a compiled + binary, for any purpose, commercial or non-commercial, and by any + means. + + In jurisdictions that recognize copyright laws, the author or authors + of this software dedicate any and all copyright interest in the + software to the public domain. We make this dedication for the benefit + of the public at large and to the detriment of our heirs and + successors. We intend this dedication to be an overt act of + relinquishment in perpetuity of all present and future rights to this + software under copyright law. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. */ + + +#include +#include +#include +#include +#include +#include +#include + + +static const regmatch_t bound =3D {1, 4}; + + +struct reg_res { + const char *regex; + regmatch_t result; +}; +static const struct reg_res reg_res_ac[] =3D { + {"^a", {1, 2}}, + {"c$", {3, 4}}, + {"^a.c$", {1, 4}}, + {"^a.*c$", {1, 4}}, + {"^a[^c]c$", {1, 4}}, + {"^a..", {1, 4}}, + {"..c", {1, 4}}, + {"[^z]c", {2, 4}}, + {} +}; +static const char *const data_ac[] =3D {"_a\0cdef", "_abcdef", NULL}; + +static const struct reg_res reg_res_aa[] =3D { + {"^", {1, 1}}, + {"^a", {1, 2}}, + {"a$", {3, 4}}, + {"^\\(a\\).\\1$", {1, 4}}, + {"^a[^a]*" , {1, 3}}, + {} +}; +static const char *const data_aa[] =3D {"_a\0adef", "_abadef", NULL}; + + +static void +testbunch (const struct reg_res *reg_reses, const char *const *const data) +{ +#define BASEERR(data) \ + support_record_failure (), \ + fprintf (stdout, __FILE__ ": %s: ", reg_reses->regex), \ + fwrite (data + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdout) + + for (; reg_reses->regex; ++reg_reses) + { + regex_t rgx; + assert (!regcomp (&rgx, reg_reses->regex, 0)); + + for (const char *const *dt =3D data; *dt; ++dt) + { + regmatch_t match =3D bound; + if (regexec (&rgx, *dt, 1, &match, REG_STARTEND)) + BASEERR(dt), fputs (": no match\n", stdout); + + if (memcmp(&match, ®_reses->result, sizeof (regmatch_t))) + BASEERR(dt), fprintf (stdout, ": wanted {%d, %d}, got {%d, %d}= \n", + (int)reg_reses->result.rm_so, + (int)reg_reses->result.rm_eo, + (int)match.rm_so, (int)match.rm_eo); + } + + regfree(&rgx); + } +} + + +struct mb_data_exp { + const char *data; + bool exp; +}; +static const struct mb_data_exp mb_data_exp[] =3D { + {"_aa=C4=87def", false}, + {"_a=C4=87def", true}, + {} +}; + +static void +testmb (void) +{ + regex_t rgx; + const struct reg_res reg_reses[] =3D {{"a=C4=87"}}; + assert (!regcomp (&rgx, reg_reses->regex, 0)); + + for (const struct mb_data_exp *de =3D mb_data_exp; de->data; ++de) + { + regmatch_t match =3D bound; + if (regexec (&rgx, de->data, 1, &match, REG_STARTEND) =3D=3D de->exp) + BASEERR(de->data), fprintf (stdout, ": %s match\n", + de->exp ? "no" : "yes"); + + if (memcmp(&match, &bound, sizeof (regmatch_t))) + BASEERR(de->data), fprintf (stdout, ": wanted {%d, %d}, got {%d, %= d}\n", + (int)bound.rm_so, (int)bound.rm_eo, + (int)match.rm_so, (int)match.rm_eo); + } + + regfree(&rgx); +} + + +static int +do_test (void) +{ + assert (setlocale (LC_ALL, "C.UTF-8")); + + testbunch (reg_res_ac, data_ac); + testbunch (reg_res_aa, data_aa); + testmb (); + return 0; +} + + +#include --=20 2.30.2 --wx62bgonypccfs67 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEfWlHToQCjFzAxEFjvP0LAY0mWPEFAmR1BpoACgkQvP0LAY0m WPEKrhAAunI7kWja8M1ksg4jsgrYqJ7fiPcFTAzPbZ3KNmIyXVIlzWsguFhMIfRj jIbAftCAjrqK+hsdb6iH2Igep2Yj0OImZlJexqTFyW7jYRVxyPw9wYL2ghbH4FpO T7LKS71s8AdLy51AqPebzezFyE+BOJNJ6ForI5cXgn6F7wY3JNt0CSuSw5muON39 b1ek6mzz2raa6Cclne4XWsb7wk9lSsrCPwOCO5tsKvky6YZgpNnoB9joGA6wv9/T i46q12+lDC7m36BGCO2ZGt1d4KgFxRSS8x3hCnOqUCjYOoucnmbMhH5UeLgAyUe+ 8V5ETWvr0SUnq7c80G7oUvpIqbbfcQJXZwqcFJUJ3nEQmr2MVTrg/SvK3d/stfFT EEOVOwJ1OUShQsp/LseEUwg5m2/JRKGQEbn7eQ06UsqHkAhSaNA9lpf+pAeffMCX mZtCTw18Ess+kpp7NvJ8mEeYZHszrb8PWaFi35/9b1GbBQaZymnx24CHoLjQecsj pztY3CnPzAPPICcLCtjG8aY93dU7aqKNdsHlLu4oQZQACfGLHMw4yIQqF+d74Bi2 RLsmHs1py7SxR+hCt3OzuK/q1wEWJcqhutLqIMu5umxKIK/vrcGSE98HYPYbZGZs nzqUeNcmVVvaTp1SrJmp5QYQboFw3ibk26WrDED2+nliycmHrus= =p7tG -----END PGP SIGNATURE----- --wx62bgonypccfs67--