From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by sourceware.org (Postfix) with ESMTPS id 5BF2D3858D32 for ; Mon, 29 May 2023 17:37:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5BF2D3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-19a13476ffeso2765161fac.0 for ; Mon, 29 May 2023 10:37:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685381862; x=1687973862; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=o2FB4+/rJ4uTi2g34v0ippP6OnOx6M0flaFrow+K3No=; b=rF/3rtHrIVsyXvpBXRgYFpCwPwxF5kCBWaD3lb48GEgFklx5MZ+IlIWJYjIpE1IEgW R2SNEJPzFKhtHyk2Ms+kxxSu3njTWL6eR4TULwHJsd3sr/z5R1eouA5Ns2wdH7rPLG17 jkw23tyu4XIEYL3vKEwgXJDpgjI5bIRaRbTsTely5SvN10rfwZ6tCZ+oQfxH3nTPb5uV jRxKTai5UjqXSHMdP9ILytNGnb3eTDtlREePbc2bniZBj6MK7cibwLerJ3tXayPgw9/s cWwioSdsjRHgHlUnyH7snRolQ+ZMfI2pnY7pREpYZGCLwLpxdGHMu13a8rxmyZKnqleJ +ZSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685381862; x=1687973862; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=o2FB4+/rJ4uTi2g34v0ippP6OnOx6M0flaFrow+K3No=; b=Em/4ZllJSYQu0e77pZBepdsTffsY6iSDaZKMtND/7laEpVgGqOI5VcGk+3XwNnGTw0 Syze0jOxKweI0i/tboCtIW0I0ZwRIwxTmT1z2QGZoQqerm4OvIMSDzU/is8oKmNM4G6/ QCZyd8U0B6a4oPB6b2OD8LGVeVxhHhK2OCnSLMWQifSvyaaggzFCswN+5+39h635UgYt 44M71zlC7GzBUbvJLrCpWlslYIYkhA+Nr/0Rnk9iDfEu9g3ojTHfh5G54hmd5pmgSnyq ZqRbXS65SSv0hFOUnn4t9XSptOtOagRVZbmv8nsksNyTLNZQ+YFZex4XOJqsKKikbSMX ztjA== X-Gm-Message-State: AC+VfDwJviLdN0zzDTiWCQ1NgQgiZrpuT5hMQ6RnHV3JsybQb81/37f5 J8Tal9kZOLGSYW2GG5fopzu75A== X-Google-Smtp-Source: ACHHUZ7DDlxu1u3Ag1YpPI/D1gwmjL/LRgIGaTLaVq2cD7Dj/dglVb+e8h+s+eLTA+LVguWb8OeSvg== X-Received: by 2002:a05:6871:40c:b0:19e:b750:f024 with SMTP id d12-20020a056871040c00b0019eb750f024mr5741307oag.4.1685381862607; Mon, 29 May 2023 10:37:42 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c1:4dd5:7120:a40d:fc97:d6db? ([2804:1b3:a7c1:4dd5:7120:a40d:fc97:d6db]) by smtp.gmail.com with ESMTPSA id m2-20020a056870a40200b0019f6751fc26sm1199254oal.7.2023.05.29.10.37.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 May 2023 10:37:41 -0700 (PDT) Message-ID: <5bf23525-60bf-d37a-be6b-7b4ee3705bfa@linaro.org> Date: Mon, 29 May 2023 14:37:39 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.1 Subject: Re: [PATCH v4 1/3] posix: add (failing) test for REG_STARTEND Content-Language: en-US To: =?UTF-8?B?0L3QsNCx?= , Carlos O'Donell Cc: libc-alpha@sourceware.org References: <1d5642ecb4bb477c9fd7e1ebaee868fe4ccbefc7.1683500149.git.nabijaczleweli@nabijaczleweli.xyz> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <1d5642ecb4bb477c9fd7e1ebaee868fe4ccbefc7.1683500149.git.nabijaczleweli@nabijaczleweli.xyz> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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: On 07/05/23 19:56, наб 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$ > > 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 XFAIL, or in this case, move after the patch that actually fixes it. > > Signed-off-by: Ahelenia Ziemiańska > --- > Resending after a week; clean rebase. > > 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 := \ > 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..c3bfac0359 > --- /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. */ I am not sure if we can accept such license. It not the current one used for newer submission, including tests (LGPL 2.1). > + > +#include > +#include > +#include > +#include > +#include > +#include > + > + > +#define M(s, e) (regmatch_t) {.rm_so = s, .rm_eo = e} > +#define MEQ(l, r) ((l).rm_so == (r).rm_so && (l).rm_eo == (r).rm_eo) > + > +static const regmatch_t bound = M(1, 4); > + > +static const char *const regex_ac[] = > + {"^a", "c$", "^a.c$", "^a.*c$", "^a[^c]c$", "^a..", "..c", "[^z]c", NULL}; > +static const char *const regex_aa[] = > + {"^", "^a", "a$", "^\\(a\\).\\1$", "^a[^a]*", NULL}; > +static const char *const data_ac[] = {"_a\0cdef", "_abcdef"}; > +static const char *const data_aa[] = {"_a\0adef", "_abadef"}; > +static const regmatch_t results_ac[] = > + {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[] = > + {M(1, 1), M(1, 2), M(3, 4), M(1, 4), M(1, 3)}; > +static_assert(sizeof(regex_ac) / sizeof(*regex_ac) - 1 == > + sizeof(results_ac) / sizeof(*results_ac), ""); > +static_assert(sizeof(regex_aa) / sizeof(*regex_aa) - 1 == > + sizeof(results_aa) / sizeof(*results_aa), ""); Instead of the static_assert, why not add the input arguments and the expect result on same struct? > + > + > +static bool > +testbunch (const char *const *regexes, const char *const data[static 2], > + const regmatch_t *results) > +{ > +#define BASEERR(data) \ > + err = true, \ > + fprintf (stdout, __FILE__ ": %s: ", *regexes), \ > + fwrite (data[i] + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdout) We have macros that already log and handle the required boilerplate to report tests issues on support/check.h. Newer tests should use it. > + > + bool err = false; > + for (; *regexes; ++regexes, ++results) > + { > + regex_t rgx; > + assert (!regcomp (&rgx, *regexes, 0)); > + > + for (size_t i = 0; i < 2; ++i) > + { > + regmatch_t match = 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 mb_data[2] = {"_aaćdef", "_aćdef"}; > +static const bool mb_exp[] = {false, true}; > + > +static bool > +testmb (void) > +{ > + bool err = false; > + regex_t rgx; > + const char *const regexes[] = {"ać"}; > + assert (!regcomp (&rgx, *regexes, 0)); > + > + for (size_t i = 0; i < 2; ++i) We have array_length macro to avoid putting array sizes everywhere (and they work better if we want to extend the tests). > + { > + regmatch_t match = bound; > + if (regexec (&rgx, mb_data[i], 1, &match, REG_STARTEND) == mb_exp[i]) > + BASEERR(mb_data), fprintf (stdout, ": %s match\n", > + mb_exp[i] ? "no" : "yes"); > + > + if (!MEQ(match, bound)) > + BASEERR(mb_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; Not really need here. > + 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. > +#else > +int > +main(int argc, char **argv) > +{ > + return do_test(argc, argv); > +} > +#endif