From nobody Thu Dec 28 17:20:11 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 4T1Fd81XWbz56CGf; Thu, 28 Dec 2023 17:20:12 +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 4T1Fd80cMQz3ZlM; Thu, 28 Dec 2023 17:20:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703784012; 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=bB5yP0ojpzczIwYpPk2ytLfzTk0ir+ZDxSX6Ozaer4k=; b=jTIyFiVLlj4kfCYCNyh2QcShh701cHwCpUbHMstfUfDnyibW4UCe+Ae10oy3vyHiRlfv/P tpqYUhQYc7VWkRbWTZUJCBu/PXCZc3a5br/KLVlgVLmNzV3ZIE+0HcJFx/tOfYrzC3GoxJ DGDRetEu0bWGFLYNT3ci/gv0ww7vbjmYZGbjHtvUuT8Ot2Enj90zg371l+ODfWehQlN0mx V7nspJwoiiprUIUbVNcxbhQyledeehMz1zK3QEYpYQqMZzdNgG6gTTaNvqv/OTYvS6jyJi 5MvIgnq/QQxWwI306ynGW9dnOcwkU45sAFs5npIl8vkWx89Te82rr3CKHIDI+A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703784012; a=rsa-sha256; cv=none; b=cus1JlBjhr/iP7VnEDUCNh1usWzZhTAs95rdFVPwbAvJuSZ0sboqAwe+9sSRls5gTcCbiC rkVlssFBp9X1COSBC+LZXUL0WMmGMvCSe5Co8O47OFw+6kxZ/6CBoh8qyzW9csjAUqiwRC HV+p4qXzX7R/Q6TkRofDDflXko7+bq3MmIh8yFDv0XO0/tuuHqeZwlrkoH9GTb5tcsMDA2 EsjQQkTIp4/VbJ6HSNJgjBLTdB/Q1husk0cGswKn+aaV1vcfCzhBYCjjM4vtvGosnZWO0s hQeYQy9tosfk3wEoK3sHk19sgMSQpTx34E+aBEv8RAJWugwQirZKgrjNDk5fMg== 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=1703784012; 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=bB5yP0ojpzczIwYpPk2ytLfzTk0ir+ZDxSX6Ozaer4k=; b=mXvPjAykfwLfmne8FHW/q5rW4y9idWHo1eswKCmx5ee0TJ8ynamXchmVNWRg79IcVpVMS1 OmhXYsFgGbLbakFQw38aTkCS5b8QcItFpNcE9xEhs3uRIEUK4emf9DNRmctvW65L1G3vIH xtoZtSneInpeEr4OX/AWvdBcNXDM4s0xjPhDVHEhwqGxjtd2MF1MRNog9PYWDCpkBYn5Ew ZpQ1Uxpp5S5nREFbgu39yeHVHbXYPEZI0+1fdZjgRReYHENCgYViAq5WDOJ3QlT9Uf6/Yt 9/HPZhEPbUUxLG0t6UNAZfacuuBl/aPTD0TdMmUpB5WjwvLBDHG2Vn6oEvEsCQ== 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 4T1Fd76gRVzXF4; Thu, 28 Dec 2023 17:20:11 +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 3BSHKBcd078711; Thu, 28 Dec 2023 17:20:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BSHKBeF078702; Thu, 28 Dec 2023 17:20:11 GMT (envelope-from git) Date: Thu, 28 Dec 2023 17:20:11 GMT Message-Id: <202312281720.3BSHKBeF078702@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Robert Clausecker Subject: git: 7aaa37fa1db6 - stable/14 - lib/libc/tests/string/memcmp_test.c: extend test to support custom memcmp function 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 7aaa37fa1db603fe10143b03ed07f3a8db771484 Auto-Submitted: auto-generated The branch stable/14 has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=7aaa37fa1db603fe10143b03ed07f3a8db771484 commit 7aaa37fa1db603fe10143b03ed07f3a8db771484 Author: Robert Clausecker AuthorDate: 2023-07-14 11:56:12 +0000 Commit: Robert Clausecker CommitDate: 2023-12-28 17:02:41 +0000 lib/libc/tests/string/memcmp_test.c: extend test to support custom memcmp function Extend the tests to permit loading an external memcmp function and testing it over using the libc version. This was added by the example of other tests in the test suite doing the same thing and helped tremendously in development. This change was originally part of D41442 but was taken out to permit separate review as extrapolated from @ngie's request in D41349. Sponsored by: FreeBSD Foundation Approved by: ngie Differential Revision: https://reviews.freebsd.org/D41528 (cherry picked from commit b166580681e3af173ec368656019d02ba1cc55ad) --- lib/libc/tests/string/memcmp_test.c | 57 +++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/lib/libc/tests/string/memcmp_test.c b/lib/libc/tests/string/memcmp_test.c index bfe209dd1b85..824e0d27ac0e 100644 --- a/lib/libc/tests/string/memcmp_test.c +++ b/lib/libc/tests/string/memcmp_test.c @@ -25,18 +25,21 @@ */ #include +#include #include #include #include #include +static int (*memcmp_fn)(const void *, const void *, size_t); + ATF_TC_WITHOUT_HEAD(zero); ATF_TC_BODY(zero, tc) { - assert(memcmp("a", "b", 0) == 0); - assert(memcmp("", "", 0) == 0); + assert(memcmp_fn("a", "b", 0) == 0); + assert(memcmp_fn("", "", 0) == 0); } ATF_TC_WITHOUT_HEAD(eq); @@ -48,9 +51,9 @@ ATF_TC_BODY(eq, tc) for (i = 0; i < 256; i++) data1[i] = data2[i] = i ^ 0x55; for (i = 1; i < 256; i++) - assert(memcmp(data1, data2, i) == 0); + assert(memcmp_fn(data1, data2, i) == 0); for (i = 1; i < 256; i++) - assert(memcmp(data1 + i, data2 + i, 256 - i) == 0); + assert(memcmp_fn(data1 + i, data2 + i, 256 - i) == 0); } ATF_TC_WITHOUT_HEAD(neq); @@ -64,9 +67,9 @@ ATF_TC_BODY(neq, tc) data2[i] = i ^ 0x55; } for (i = 1; i < 256; i++) - assert(memcmp(data1, data2, i) != 0); + assert(memcmp_fn(data1, data2, i) != 0); for (i = 1; i < 256; i++) - assert(memcmp(data1 + i, data2 + i, 256 - i) != 0); + assert(memcmp_fn(data1 + i, data2 + i, 256 - i) != 0); } ATF_TC_WITHOUT_HEAD(diff); @@ -80,37 +83,43 @@ ATF_TC_BODY(diff, tc) data1[128] = 255; data2[128] = 0; for (i = 1; i < 66; i++) { - assert(memcmp(data1 + 128, data2 + 128, i) == 255); - assert(memcmp(data2 + 128, data1 + 128, i) == -255); - assert(memcmp(data1 + 129 - i, data2 + 129 - i, i) == 255); - assert(memcmp(data2 + 129 - i, data1 + 129 - i, i) == -255); - assert(memcmp(data1 + 129 - i, data2 + 129 - i, i * 2) == 255); - assert(memcmp(data2 + 129 - i, data1 + 129 - i, i * 2) == -255); + assert(memcmp_fn(data1 + 128, data2 + 128, i) == 255); + assert(memcmp_fn(data2 + 128, data1 + 128, i) == -255); + assert(memcmp_fn(data1 + 129 - i, data2 + 129 - i, i) == 255); + assert(memcmp_fn(data2 + 129 - i, data1 + 129 - i, i) == -255); + assert(memcmp_fn(data1 + 129 - i, data2 + 129 - i, i * 2) == 255); + assert(memcmp_fn(data2 + 129 - i, data1 + 129 - i, i * 2) == -255); } data1[128] = 'c'; data2[128] = 'e'; for (i = 1; i < 66; i++) { - assert(memcmp(data1 + 128, data2 + 128, i) == -2); - assert(memcmp(data2 + 128, data1 + 128, i) == 2); - assert(memcmp(data1 + 129 - i, data2 + 129 - i, i) == -2); - assert(memcmp(data2 + 129 - i, data1 + 129 - i, i) == 2); - assert(memcmp(data1 + 129 - i, data2 + 129 - i, i * 2) == -2); - assert(memcmp(data2 + 129 - i, data1 + 129 - i, i * 2) == 2); + assert(memcmp_fn(data1 + 128, data2 + 128, i) == -2); + assert(memcmp_fn(data2 + 128, data1 + 128, i) == 2); + assert(memcmp_fn(data1 + 129 - i, data2 + 129 - i, i) == -2); + assert(memcmp_fn(data2 + 129 - i, data1 + 129 - i, i) == 2); + assert(memcmp_fn(data1 + 129 - i, data2 + 129 - i, i * 2) == -2); + assert(memcmp_fn(data2 + 129 - i, data1 + 129 - i, i * 2) == 2); } memset(data1 + 129, 'A', sizeof(data1) - 129); memset(data2 + 129, 'Z', sizeof(data2) - 129); for (i = 1; i < 66; i++) { - assert(memcmp(data1 + 128, data2 + 128, i) == -2); - assert(memcmp(data2 + 128, data1 + 128, i) == 2); - assert(memcmp(data1 + 129 - i, data2 + 129 - i, i) == -2); - assert(memcmp(data2 + 129 - i, data1 + 129 - i, i) == 2); - assert(memcmp(data1 + 129 - i, data2 + 129 - i, i * 2) == -2); - assert(memcmp(data2 + 129 - i, data1 + 129 - i, i * 2) == 2); + assert(memcmp_fn(data1 + 128, data2 + 128, i) == -2); + assert(memcmp_fn(data2 + 128, data1 + 128, i) == 2); + assert(memcmp_fn(data1 + 129 - i, data2 + 129 - i, i) == -2); + assert(memcmp_fn(data2 + 129 - i, data1 + 129 - i, i) == 2); + assert(memcmp_fn(data1 + 129 - i, data2 + 129 - i, i * 2) == -2); + assert(memcmp_fn(data2 + 129 - i, data1 + 129 - i, i * 2) == 2); } } ATF_TP_ADD_TCS(tp) { + void *dl_handle; + + dl_handle = dlopen(NULL, RTLD_LAZY); + memcmp_fn = dlsym(dl_handle, "test_memcmp"); + if (memcmp_fn == NULL) + memcmp_fn = memcmp; ATF_TP_ADD_TC(tp, zero); ATF_TP_ADD_TC(tp, eq);