From nobody Thu Dec 21 02:25:29 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SwZ6225sYz548Kp; Thu, 21 Dec 2023 02:25:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SwZ621chQz4PNj; Thu, 21 Dec 2023 02:25:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703125530; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YCFBQJt/Dw2DHEoYgvNbDffFFNa0iN9HqpFWI1URbv4=; b=EAChcjwuDpVQoSBW8+Ur2wyoaAiJRdfLXPB2bF4ZCgz4gK63V24t8aEnRDF4DsK1ImV16O ShqSG0qmNkfozZgLQwx+Ny8ms2zdk1LmgvLf/bjr87V9NHUoIugTgnalme945Q/T18ngay 3V0ZBTnqpK8Cf/D2j0556BwSybYD0oUF3W+LBd9xvB/VDWlHWnZWo2qeTkuBq+TiTupIVn dCurAA7+EOhcn3efYPyfw3x2LDxr4we3ZBU2WP0Ot8uj1Sr4RfOIJAJB2mw4XqwOlpi8cx CfkiBhNkJnkvJnCR+pQOwRT3f9whoV7fd2z9xarVWLRAHHE4YVLxzd76fh+TyQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703125530; a=rsa-sha256; cv=none; b=j1DERstRuIpR3DS9N5y9ne3NAD6puio0GFAPXOCdEihtAXvUJcFBVm8zh4k4BuyI6IM27N 4skfG24IfDEAyvJL/Hsj4g9Z/6MK/UlLQDH3hJ0wegxp8abP4KNYBXM0oxVVYToKS1ywZg o/1aP6AK2jpSkcBVYZQIk4YCTV4r1XVwRneg8Pt9lzr9iZkYbRBFxzs41t78FlRYqdJHcL CItyC4ER5pTa7XsJ8wErZKd0fKGrmjyN8VLQVhwLACjIjcuWWDPrByO65YAAjGQjZzddYy 5Uv4dRpXC5DQoS7p6sMBEyKWEKrfz1OnjVvlRAwmbh+DDSmYPibYm5xFyX6i+w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703125530; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YCFBQJt/Dw2DHEoYgvNbDffFFNa0iN9HqpFWI1URbv4=; b=WNWyP2hoKbKGjeaIbg1qQdX2hAkaiFezynC6lYR93DOjMVCuMbxG3b0dsiEOpFwyn9FvBZ Em1W/4InOAB8/aOK/X68Q6n/1oDxZQ6sDKSIM9V/FVM6DHPEMGGD94aQ98s4noEA7NV9Ae rx3Yz9ShtJbSdvGspnw1o8BwGGBCDDAx4scWHh/mF/fqHA3bRCgf9zcaxx+5VgEoAnSRAV JDtO7H3LJ13Uqkc6gwIIBYOHEVVpP+WaTQ4h29pC1yGCODUBuVMc37QeaUFlGdJDMeSHOZ atRhfeY9RjXdPSMzl+Cmu0l6UdP0XVPAVIqhiKJrXimUPq5529d436HbjNRXUw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SwZ620NZTzQ5; Thu, 21 Dec 2023 02:25:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BL2PTs0037727; Thu, 21 Dec 2023 02:25:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BL2PTDc037724; Thu, 21 Dec 2023 02:25:29 GMT (envelope-from git) Date: Thu, 21 Dec 2023 02:25:29 GMT Message-Id: <202312210225.3BL2PTDc037724@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Robert Clausecker Subject: git: a0ecf2224ea3 - main - lib/libc/tests/string/strcspn_test.c: add test for correct match order List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: fuz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a0ecf2224ea35d029d33541878f0eee42f5fd84f Auto-Submitted: auto-generated The branch main has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=a0ecf2224ea35d029d33541878f0eee42f5fd84f commit a0ecf2224ea35d029d33541878f0eee42f5fd84f Author: Robert Clausecker AuthorDate: 2023-12-19 16:27:24 +0000 Commit: Robert Clausecker CommitDate: 2023-12-21 02:16:57 +0000 lib/libc/tests/string/strcspn_test.c: add test for correct match order This new unit test verifies that if there are multiple matches, the first match is returned, ignoring later matches. Approved by: mjg (blanket, via IRC) MFC after: 1 week MFC to: stable/14 --- lib/libc/tests/string/strcspn_test.c | 51 +++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/libc/tests/string/strcspn_test.c b/lib/libc/tests/string/strcspn_test.c index 6cb2a04d3e64..293fc2bc8d4e 100644 --- a/lib/libc/tests/string/strcspn_test.c +++ b/lib/libc/tests/string/strcspn_test.c @@ -150,7 +150,7 @@ ATF_TC_BODY(set_alignments, tc) #ifndef STRSPN /* test all positions in which set could match buf */ static void -test_match_positions(char *buf, char *set, size_t buflen, size_t setlen) +test_match_positions(char *buf, char *set, size_t buflen, size_t setlen) { size_t i, j, outcome; @@ -206,6 +206,54 @@ ATF_TC_BODY(match_positions, tc) test_match_positions(buf, set, 16, 8); test_match_positions(buf, set, 8, 8); } + +/* if there are two matches, check that the earlier match is taken */ +static void +test_match_order(char *buf, char *set, size_t buflen, size_t setlen) +{ + size_t i, j, k, l, outcome; + + memset(buf, '-', buflen); + + for (i = 0; i < setlen; i++) + set[i] = 'A' + i; + + buf[buflen] = '\0'; + set[setlen] = '\0'; + + for (i = 0; i < setlen; i++) + for (j = 0; j < setlen; j++) + for (k = 0; k + 1 < buflen; k++) + for (l = k + 1; l < buflen; l++) { + buf[k] = set[i]; + buf[l] = set[j]; + outcome = strcspn(buf, set); + ATF_CHECK_EQ_MSG(k, outcome, + "strcspn(\"%s\", \"%s\") = %zu != %zu", + buf, set, outcome, k); + buf[k] = '-'; + buf[l] = '-'; + } +} + +ATF_TC_WITHOUT_HEAD(match_order); +ATF_TC_BODY(match_order, tc) +{ + char buf[33], set[65]; + + test_match_order(buf, set, 32, 64); + test_match_order(buf, set, 16, 64); + test_match_order(buf, set, 8, 64); + test_match_order(buf, set, 32, 32); + test_match_order(buf, set, 16, 32); + test_match_order(buf, set, 8, 32); + test_match_order(buf, set, 32, 16); + test_match_order(buf, set, 16, 16); + test_match_order(buf, set, 8, 16); + test_match_order(buf, set, 32, 8); + test_match_order(buf, set, 16, 8); + test_match_order(buf, set, 8, 8); +} #endif /* !defined(STRSPN) */ ATF_TP_ADD_TCS(tp) @@ -214,6 +262,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, set_alignments); #ifndef STRSPN ATF_TP_ADD_TC(tp, match_positions); + ATF_TP_ADD_TC(tp, match_order); #endif return (atf_no_error());