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 15E7E3858C83 for ; Sat, 22 Apr 2023 02:21:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 15E7E3858C83 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 913AD6D02 for ; Sat, 22 Apr 2023 04:21:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1682130111; bh=b50saTz10x0rkIbzwNPEBw5gjkcOu/Y3/goZxzwWE4U=; h=Date:From:To:Subject:From; b=R8l1o6ETUF+k+5Ftb9pHtbcRNtfFN4dylT5scAGAqev+9dqzOVnAmQ/iFdHncJKr+ PcpHIPwhdyJqQk65vPRGCj/jCeYz2Zo8v23uy2keESuI/wZCX9pbnCZEGwOgPdsWCN VtBOZ3ZVC2VQFHXq3S13EZeQf7kwhJL0IM4wqKOAbTWOURUxp7cTrx/HEACjEbq9qf gBXZ4M/b1pOz6OdCilmDuWWaW8LetJx5mYAyotv7Zg/pLjipD2S/xjkN2uaumFT/tA QnkJbZ9Fd+O5HDHG9l/LarfRzCs2Eei4CDAs7ufyU3IIO2sQgo/kg0I6n9elGWIQva FZewqbVqf6WmQ== Date: Sat, 22 Apr 2023 04:21:50 +0200 From: =?utf-8?B?0L3QsNCx?= To: libc-alpha@sourceware.org Subject: [PATCH 1/3] posix: add (failing) test for REG_STARTEND Message-ID: <6ae8f638ecd1a0f0d76a104c8903baf96ecd317a.1682130047.git.nabijaczleweli@nabijaczleweli.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="zx433ifozxx4u67k" Content-Disposition: inline User-Agent: NeoMutt/20230407 X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_INFOUSMEBIZ,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: --zx433ifozxx4u67k Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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$ 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. Signed-off-by: Ahelenia Ziemia=C5=84ska --- Please keep me in CC, as I'm not subscribed. posix/Makefile | 1 + posix/tst-reg-startend.c | 124 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 posix/tst-reg-startend.c diff --git a/posix/Makefile b/posix/Makefile index cc77e939ad..24aeb781ca 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..ed2be224f4 --- /dev/null +++ b/posix/tst-reg-startend.c @@ -0,0 +1,124 @@ +/* Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + 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 DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + +#include +#include +#include +#include +#include +#include + + +#define M(s, e) (regmatch_t) {.rm_so =3D s, .rm_eo =3D e} +#define MEQ(l, r) ((l).rm_so =3D=3D (r).rm_so && (l).rm_eo =3D=3D (r).rm_e= o) + +static const regmatch_t bound =3D M(1, 4); + +static const char *const regex_ac[] =3D + {"^a", "c$", "^a.c$", "^a.*c$", "^a[^c]c$", "^a..", "..c", "[^z]c", NULL= }; +static const char *const regex_aa[] =3D + {"^", "^a", "a$", "^\\(a\\).\\1$", "^a[^a]*", NULL}; +static const char *const data_ac[] =3D {"_a\0cdef", "_abcdef"}; +static const char *const data_aa[] =3D {"_a\0adef", "_abadef"}; +static const regmatch_t results_ac[] =3D + {M(1, 2), M(3, 4), M(1, 4), M(1, 4), M(1, 4), M(1, 4), M(1, 4), M(2, 4)}; +static const regmatch_t results_aa[] =3D + {M(1, 1), M(1, 2), M(3, 4), M(1, 4), M(1, 3)}; +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), ""); + + +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, stdout) + + bool err =3D false; + for (; *regexes; ++regexes, ++results) + { + regex_t rgx; + assert (!regcomp (&rgx, *regexes, 0)); + + for (size_t i =3D 0; i < 2; ++i) + { + regmatch_t match =3D bound; + if (regexec (&rgx, data[i], 1, &match, REG_STARTEND)) + BASEERR(data), fputs (": no match\n", stdout); + + if (!MEQ(match, *results)) + BASEERR(data), fprintf (stdout, ": wanted {%d, %d}, got {%d, %= d}\n", + (int)results->rm_so, (int)results->rm_= eo, + (int)match.rm_so, (int)match.rm_eo); + } + + regfree(&rgx); + } + + return err; +} + + +static const char *const a=C4=87_data[2] =3D {"_aa=C4=87def", "_a=C4=87def= "}; +static const bool a=C4=87_exp[] =3D {false, true}; + +static bool +testa=C4=87 (void) +{ + bool err =3D false; + regex_t rgx; + const char *const regexes[] =3D {"a=C4=87"}; + assert (!regcomp (&rgx, *regexes, 0)); + + for (size_t i =3D 0; i < 2; ++i) + { + regmatch_t match =3D bound; + if (regexec (&rgx, a=C4=87_data[i], 1, &match, REG_STARTEND) =3D=3D = a=C4=87_exp[i]) + BASEERR(a=C4=87_data), fprintf (stdout, ": %s match\n", + a=C4=87_exp[i] ? "no" : "yes"); + + if (!MEQ(match, bound)) + BASEERR(a=C4=87_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); + return err; +} + + +static int +do_test (int argc, char **argv) +{ + (void) argc, (void) argv; + assert (setlocale (LC_ALL, "C.UTF-8")); + + return testbunch (regex_ac, data_ac, results_ac) || + testbunch (regex_aa, data_aa, results_aa) || + testa=C4=87 (); +} + + +#ifndef STANDALONE +#include "../test-skeleton.c" +#else +int +main(int argc, char **argv) +{ + return do_test(argc, argv); +} +#endif --=20 2.30.2 --zx433ifozxx4u67k Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEfWlHToQCjFzAxEFjvP0LAY0mWPEFAmRDRL4ACgkQvP0LAY0m WPGC1RAAtFxVHzebKi7OL3ewh/Vx9bGRAIhlfMMsuazq7lu0Ae6HwZZTmIZ+OeTK UGW+JjNh86A69o5blzJmY7TdJboiHlrpXtfe8LDo+PBQe9A+fsF7zxfcUj+B5kKs SnNPrhRbl2yDeYaIvYZdkJYp13ju1/u6xgjkCZzuRNx72rGIBmxqt3elTYH3tTpZ 0gaH/snGSRIzzrPZaY5X5kl36YSZg8Azxv/MJNT0EC5mr7tiZREc/+vop7fWqCwx sWWPp2xPGuclJscEgs+DUkpk7sTPR+0/hn/Lsc112iJLVraRlenWh//H646cUQoM w9g39iiO4+glkwPzTrFFtGYugDUAI6uLNu2sKtvVK8y7BeFNjPpiU5gwAdxUfvIw wo1E74SNFlKDw/cnCwARJ+VgeUkX1GMPpuJhpPZ8nrNoQm1xjszp/vLvC2COLfZK UqpbXKQLcj13zQwnSZ43YdKPvhNx9xdwLXG1KBvnzVIzrUswqGZbcCYFRcRabZ6J hJqSUI+Nz7bOtYMdaz5EXuM4GRKDExvj0lOrNY3xY8mOASI1/soA5NV57SGIrqQk gfMnPJjBf8DXMxOGSTi2oEfg1wFQuf/rlb5W0fKXEKm27lV27VDe48DpMgvN+Es6 CpZycp+8ahOHxMpzDfHURiLuzn++72hQPHLmuDpCZhSQDKF2aGo= =AnFz -----END PGP SIGNATURE----- --zx433ifozxx4u67k--