From nobody Thu Feb 02 14:46:38 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 4P71nq0k7rz3fK2w; Thu, 2 Feb 2023 14:46:39 +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 4P71nq0Bqzz4krt; Thu, 2 Feb 2023 14:46:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675349199; 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=+A60CP4PgzHIDOo6iApJLMuAWSsRdlUbT0KvvZrsNeU=; b=JNopZbNiCXptX2TzywN0c4Vbxz3cSi57BgqdKrL86/Q2a6kzVW/96t72m12f+6EfqLBd2v BrF7t3pbWQjuuMAJ4j/sx9XOVd8IXVJ8AHt89ARXJrwsBjqXdCaaz07wZ0gSLFXFNCEUli bnYWrVDW/u+pRwFLts2aMnUDk7WGKG7o/08jG2TPan0y+XQ2Ul2FwMm4NwUPugdDkYZC8h wKvo1qTLoVArK53vgmLcYDSb+Y6tVRUUkzwZuxu5zYa40aalQYE5MwFxgNXmLkGbtvkBlw msMCBgE3EcIz/RL9r/vYfZVI1EcyLVwpXU2tLjzm2tt/UKrknLcTUX5Lqz846w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675349199; 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=+A60CP4PgzHIDOo6iApJLMuAWSsRdlUbT0KvvZrsNeU=; b=B1oe5ezw0YtN7fDawwytA9xUIqFBEQt44gJOKZsvTWtg/g5UTd7eJOwvg1ojQLboAeDk/3 BBHBpycXPGvFymKBpNtvHaFBTR8IUfwvmM+I6rXvMjCowIvShvYhSZoztfLOVG7N/WOOJi 6MbPbLA3TtdIVgtlP2dhr6b/QR7Hg18SITfFrhKSvseCL8jyVY56+yg3bBaHVKY3YLAo3g hySesQJw5ekQR/k9uX3d9r3XlAghOinK1GTJlRkvEaNjnwrnw3qV9Hm1js4xAh1jQA7Up8 gEJjdotT2uBIcab9rcmUL/pLRBuO6k8hfDycvcv7J26e6jMYAwFFALv2tvpZcw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675349199; a=rsa-sha256; cv=none; b=MiSJzQI/VdlCDwFvAt0QOm7Qoe78LO8oNcm/nf6usGAXl1HYiq0545htwXHPRhHBwk+VT2 y3+m36Kl8j692K3UIYY7F91wuQeT3ogUO9hRiCGtRiHO7LY7u0bLoMgMJNRFb4VGD6e1tk Tf+RW7cMdShmavY7YzH5DKjWS2Zv1EtxE/BI+IDiTBZa6vD1mvtCTwFsaZ+9lWw+qw7YKv BJm5p1e6gMFYP42SJ1mc56og6I5mSH4xMjHvwQWN7eZA164PC8w74l937GCo8a/j6I1iby /zt4f5JAQkavSOC+rJHGCH3L1KwasNIgrYiuSakCIPAUf8HShTNnRaWFGpsSPQ== 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 4P71np6N2Lzy4l; Thu, 2 Feb 2023 14:46:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 312EkcTT077174; Thu, 2 Feb 2023 14:46:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 312EkcDd077173; Thu, 2 Feb 2023 14:46:38 GMT (envelope-from git) Date: Thu, 2 Feb 2023 14:46:38 GMT Message-Id: <202302021446.312EkcDd077173@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: 606d0e4a9a86 - main - libc: Add tests for strchrnul(3). 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: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 606d0e4a9a862a7b4e3469a084834ca0e888afa4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=606d0e4a9a862a7b4e3469a084834ca0e888afa4 commit 606d0e4a9a862a7b4e3469a084834ca0e888afa4 Author: Dag-Erling Smørgrav AuthorDate: 2023-02-01 20:06:20 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-02-02 14:45:45 +0000 libc: Add tests for strchrnul(3). MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D38286 --- contrib/netbsd-tests/lib/libc/string/t_strchr.c | 12 +- contrib/netbsd-tests/lib/libc/string/t_strchrnul.c | 293 +++++++++++++++++++++ lib/libc/tests/string/Makefile | 1 + 3 files changed, 300 insertions(+), 6 deletions(-) diff --git a/contrib/netbsd-tests/lib/libc/string/t_strchr.c b/contrib/netbsd-tests/lib/libc/string/t_strchr.c index 5dd9a62213ab..4bc304e71267 100644 --- a/contrib/netbsd-tests/lib/libc/string/t_strchr.c +++ b/contrib/netbsd-tests/lib/libc/string/t_strchr.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_strchr.c,v 1.2 2017/01/10 15:34:49 christos Exp $ */ +/* $NetBSD: t_strchr.c,v 1.3 2023/01/30 19:49:49 christos Exp $ */ /* * Written by J.T. Conklin @@ -247,7 +247,7 @@ ATF_TC_BODY(strchr_basic, tc) }; dl_handle = dlopen(NULL, RTLD_LAZY); - strchr_fn = dlsym(dl_handle, "test_strlen"); + strchr_fn = dlsym(dl_handle, "test_strchr"); if (!strchr_fn) strchr_fn = strchr; @@ -269,11 +269,11 @@ ATF_TC_BODY(strchr_basic, tc) /* Then for the '/' in the strings */ verify_strchr(buf + a, '/', t, a); - /* check zero extension of char arg */ - verify_strchr(buf + a, 0xffffff00 | '/', t, a); + /* check zero extension of char arg */ + verify_strchr(buf + a, 0xffffff00 | '/', t, a); - /* Replace all the '/' with 0xff */ - while ((off = slow_strchr(buf + a, '/')) != NULL) + /* Replace all the '/' with 0xff */ + while ((off = slow_strchr(buf + a, '/')) != NULL) *off = 0xff; buf[a + len] = 0xff; diff --git a/contrib/netbsd-tests/lib/libc/string/t_strchrnul.c b/contrib/netbsd-tests/lib/libc/string/t_strchrnul.c new file mode 100644 index 000000000000..62ac702523aa --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/string/t_strchrnul.c @@ -0,0 +1,293 @@ +/* $NetBSD: t_strchrnul.c,v 1.1 2023/01/30 19:49:49 christos Exp $ */ + +/* + * Written by J.T. Conklin + * Public domain. + */ + +#include +#include +#include +#include +#include +#include + +static char *slow_strchrnul(char *, int); +static void verify_strchrnul(char *, int, unsigned int, unsigned int); + +char * (*volatile strchrnul_fn)(const char *, int); + +static char * +slow_strchrnul(char *buf, int ch) +{ + unsigned char c = 1; + + ch &= 0xff; + + for (; ; buf++) { + c = *buf; + if (c == ch || c == 0) + return buf; + } +} + +static void +verify_strchrnul(char *buf, int ch, unsigned int t, unsigned int a) +{ + const char *off, *ok_off; + + off = strchrnul_fn(buf, ch); + ok_off = slow_strchrnul(buf, ch); + if (off == ok_off) + return; + + fprintf(stderr, "test_strchrnul(\"%s\", %#x) gave %zd not %zd (test %d, " + "alignment %d)\n", + buf, ch, off ? off - buf : -1, ok_off ? ok_off - buf : -1, t, a); + + atf_tc_fail("Check stderr for details"); +} + +ATF_TC(strchrnul_basic); +ATF_TC_HEAD(strchrnul_basic, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Test strchrnul(3) results"); +} + +ATF_TC_BODY(strchrnul_basic, tc) +{ + void *dl_handle; + char *off; + char buf[32]; + unsigned int t, a; + + const char *tab[] = { + "", + "a", + "aa", + "abc", + "abcd", + "abcde", + "abcdef", + "abcdefg", + "abcdefgh", + + "/", + "//", + "/a", + "/a/", + "/ab", + "/ab/", + "/abc", + "/abc/", + "/abcd", + "/abcd/", + "/abcde", + "/abcde/", + "/abcdef", + "/abcdef/", + "/abcdefg", + "/abcdefg/", + "/abcdefgh", + "/abcdefgh/", + + "a/", + "a//", + "a/a", + "a/a/", + "a/ab", + "a/ab/", + "a/abc", + "a/abc/", + "a/abcd", + "a/abcd/", + "a/abcde", + "a/abcde/", + "a/abcdef", + "a/abcdef/", + "a/abcdefg", + "a/abcdefg/", + "a/abcdefgh", + "a/abcdefgh/", + + "ab/", + "ab//", + "ab/a", + "ab/a/", + "ab/ab", + "ab/ab/", + "ab/abc", + "ab/abc/", + "ab/abcd", + "ab/abcd/", + "ab/abcde", + "ab/abcde/", + "ab/abcdef", + "ab/abcdef/", + "ab/abcdefg", + "ab/abcdefg/", + "ab/abcdefgh", + "ab/abcdefgh/", + + "abc/", + "abc//", + "abc/a", + "abc/a/", + "abc/ab", + "abc/ab/", + "abc/abc", + "abc/abc/", + "abc/abcd", + "abc/abcd/", + "abc/abcde", + "abc/abcde/", + "abc/abcdef", + "abc/abcdef/", + "abc/abcdefg", + "abc/abcdefg/", + "abc/abcdefgh", + "abc/abcdefgh/", + + "abcd/", + "abcd//", + "abcd/a", + "abcd/a/", + "abcd/ab", + "abcd/ab/", + "abcd/abc", + "abcd/abc/", + "abcd/abcd", + "abcd/abcd/", + "abcd/abcde", + "abcd/abcde/", + "abcd/abcdef", + "abcd/abcdef/", + "abcd/abcdefg", + "abcd/abcdefg/", + "abcd/abcdefgh", + "abcd/abcdefgh/", + + "abcde/", + "abcde//", + "abcde/a", + "abcde/a/", + "abcde/ab", + "abcde/ab/", + "abcde/abc", + "abcde/abc/", + "abcde/abcd", + "abcde/abcd/", + "abcde/abcde", + "abcde/abcde/", + "abcde/abcdef", + "abcde/abcdef/", + "abcde/abcdefg", + "abcde/abcdefg/", + "abcde/abcdefgh", + "abcde/abcdefgh/", + + "abcdef/", + "abcdef//", + "abcdef/a", + "abcdef/a/", + "abcdef/ab", + "abcdef/ab/", + "abcdef/abc", + "abcdef/abc/", + "abcdef/abcd", + "abcdef/abcd/", + "abcdef/abcde", + "abcdef/abcde/", + "abcdef/abcdef", + "abcdef/abcdef/", + "abcdef/abcdefg", + "abcdef/abcdefg/", + "abcdef/abcdefgh", + "abcdef/abcdefgh/", + + "abcdefg/", + "abcdefg//", + "abcdefg/a", + "abcdefg/a/", + "abcdefg/ab", + "abcdefg/ab/", + "abcdefg/abc", + "abcdefg/abc/", + "abcdefg/abcd", + "abcdefg/abcd/", + "abcdefg/abcde", + "abcdefg/abcde/", + "abcdefg/abcdef", + "abcdefg/abcdef/", + "abcdefg/abcdefg", + "abcdefg/abcdefg/", + "abcdefg/abcdefgh", + "abcdefg/abcdefgh/", + + "abcdefgh/", + "abcdefgh//", + "abcdefgh/a", + "abcdefgh/a/", + "abcdefgh/ab", + "abcdefgh/ab/", + "abcdefgh/abc", + "abcdefgh/abc/", + "abcdefgh/abcd", + "abcdefgh/abcd/", + "abcdefgh/abcde", + "abcdefgh/abcde/", + "abcdefgh/abcdef", + "abcdefgh/abcdef/", + "abcdefgh/abcdefg", + "abcdefgh/abcdefg/", + "abcdefgh/abcdefgh", + "abcdefgh/abcdefgh/", + }; + + dl_handle = dlopen(NULL, RTLD_LAZY); + strchrnul_fn = dlsym(dl_handle, "test_strchrnul"); + if (!strchrnul_fn) + strchrnul_fn = strchrnul; + + for (a = 3; a < 3 + sizeof(long); ++a) { + /* Put char and a \0 before the buffer */ + buf[a-1] = '/'; + buf[a-2] = '0'; + buf[a-3] = 0xff; + for (t = 0; t < (sizeof(tab) / sizeof(tab[0])); ++t) { + int len = strlen(tab[t]) + 1; + memcpy(&buf[a], tab[t], len); + + /* Put the char we are looking for after the \0 */ + buf[a + len] = '/'; + + /* Check search for NUL at end of string */ + verify_strchrnul(buf + a, 0, t, a); + + /* Then for the '/' in the strings */ + verify_strchrnul(buf + a, '/', t, a); + + /* check zero extension of char arg */ + verify_strchrnul(buf + a, 0xffffff00 | '/', t, a); + + /* Replace all the '/' with 0xff */ + while (*(off = slow_strchrnul(buf + a, '/')) != '\0') + *off = 0xff; + + buf[a + len] = 0xff; + + /* Check we can search for 0xff as well as '/' */ + verify_strchrnul(buf + a, 0xff, t, a); + } + } + (void)dlclose(dl_handle); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, strchrnul_basic); + + return atf_no_error(); +} diff --git a/lib/libc/tests/string/Makefile b/lib/libc/tests/string/Makefile index eacf7e15c27c..5d1944113a1a 100644 --- a/lib/libc/tests/string/Makefile +++ b/lib/libc/tests/string/Makefile @@ -18,6 +18,7 @@ NETBSD_ATF_TESTS_C+= memmem_test NETBSD_ATF_TESTS_C+= memset_test NETBSD_ATF_TESTS_C+= strcat_test NETBSD_ATF_TESTS_C+= strchr_test +NETBSD_ATF_TESTS_C+= strchrnul_test NETBSD_ATF_TESTS_C+= strcmp_test NETBSD_ATF_TESTS_C+= strcpy_test NETBSD_ATF_TESTS_C+= strcspn_test