From patchwork Fri Apr 28 12:36:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 1774943 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=miQux6Oi; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q7By74xVbz23tl for ; Fri, 28 Apr 2023 22:39:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A992389941A for ; Fri, 28 Apr 2023 12:39:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A992389941A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685581; bh=tlNEtebp7KXbBMxWmreFZFf963d796h0ItWHP+dBXhY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=miQux6Oihl4gb5Rx+ahcwqAZm9pS5b1mvLlOdgAcAhLkic2jeVmMSNZQu6tw3OEDU XotjhZgFPphn3gTB9Pv6sz+OnRVAu1M/Mxbd8h1dx7v7aZ4sUGP01agYGttCN0tfk6 eTeMLyUTSahf3KcDi2cLk4kU5qBp6kHeF5sboyfo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by sourceware.org (Postfix) with ESMTP id 6BA9E385277B for ; Fri, 28 Apr 2023 12:36:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6BA9E385277B Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 8DE357404 for ; Fri, 28 Apr 2023 14:36:29 +0200 (CEST) Date: Fri, 28 Apr 2023 14:36:28 +0200 To: libc-alpha@sourceware.org Subject: [PATCH v3 1/3] posix: add (failing) test for REG_STARTEND Message-ID: <9dee3d2ba84f09e883cf7a7dfcda486fda735382.1682685278.git.nabijaczleweli@nabijaczleweli.xyz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20230407 X-Spam-Status: No, score=-9.7 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?b?0L3QsNCxIHZpYSBMaWJjLWFscGhh?= From: =?utf-8?b?0L3QsNCx?= Reply-To: =?utf-8?b?0L3QsNCx?= Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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ńska --- Resending after a week, per guidelines. Clean rebase, includes the v2 of the test (idents renamed for compatibility), no changes to the non-test code. Keep me in CC, please. 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. */ + +#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), ""); + + +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) + + 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) + { + 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; + 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" +#else +int +main(int argc, char **argv) +{ + return do_test(argc, argv); +} +#endif