Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F107343591
D41567.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D41567.diff
View Options
diff --git a/lib/libc/tests/string/Makefile b/lib/libc/tests/string/Makefile
--- a/lib/libc/tests/string/Makefile
+++ b/lib/libc/tests/string/Makefile
@@ -13,6 +13,7 @@
ATF_TESTS_C+= stpncpy_test
ATF_TESTS_C+= strcspn_test
ATF_TESTS_C+= strerror2_test
+ATF_TESTS_C+= strspn_test
ATF_TESTS_C+= strverscmp_test
ATF_TESTS_C+= strxfrm_test
ATF_TESTS_C+= wcscasecmp_test
@@ -34,7 +35,6 @@
NETBSD_ATF_TESTS_C+= strlen_test
NETBSD_ATF_TESTS_C+= strpbrk_test
NETBSD_ATF_TESTS_C+= strrchr_test
-NETBSD_ATF_TESTS_C+= strspn_test
NETBSD_ATF_TESTS_C+= swab_test
SRCS.strerror2_test= strerror_test.c
diff --git a/lib/libc/tests/string/strcspn_test.c b/lib/libc/tests/string/strcspn_test.c
--- a/lib/libc/tests/string/strcspn_test.c
+++ b/lib/libc/tests/string/strcspn_test.c
@@ -42,6 +42,12 @@
enum { NOMATCH, MATCH };
+#ifdef STRSPN
+#define STRXSPN strspn
+#else
+#define STRXSPN strcspn
+#endif
+
static void
testcase(char *buf, size_t buflen, char *set, size_t setlen, int want_match)
{
@@ -50,7 +56,11 @@
assert(setlen < UCHAR_MAX - 2);
for (i = 0; i < buflen; i++)
+#ifdef STRSPN
+ buf[i] = UCHAR_MAX - i % (setlen > 0 ? setlen : 1);
+#else /* strcspn */
buf[i] = 1 + i % (UCHAR_MAX - setlen - 1);
+#endif
buf[i] = '\0';
@@ -59,15 +69,25 @@
set[i] = '\0';
+#ifdef STRSPN
+ if (setlen == 0)
+ expected = 0;
+ else if (want_match == MATCH && buflen > 0) {
+ buf[buflen - 1] = 1;
+ expected = buflen - 1;
+ } else
+ expected = buflen;
+#else /* strcspn */
if (want_match == MATCH && buflen > 0 && setlen > 0) {
buf[buflen - 1] = UCHAR_MAX;
expected = buflen - 1;
} else
expected = buflen;
+#endif
- outcome = strcspn(buf, set);
- ATF_CHECK_EQ_MSG(expected, outcome, "strcspn(%p[%zu], %p[%zu]) = %zu != %zu",
- buf, buflen, set, setlen, outcome, expected);
+ outcome = STRXSPN(buf, set);
+ ATF_CHECK_EQ_MSG(expected, outcome, "%s(%p[%zu], %p[%zu]) = %zu != %zu",
+ __XSTRING(STRXSPN), buf, buflen, set, setlen, outcome, expected);
}
/* test set with all alignments and lengths of buf */
diff --git a/lib/libc/tests/string/strspn_test.c b/lib/libc/tests/string/strspn_test.c
new file mode 100644
--- /dev/null
+++ b/lib/libc/tests/string/strspn_test.c
@@ -0,0 +1,30 @@
+/*-
+ * Copyright (c) 2023 The FreeBSD Foundation
+ *
+ * This software was developed by Robert Clausecker <fuz@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ''AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE
+ */
+
+#define STRSPN
+#include "strcspn_test.c"
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jan 13, 6:58 PM (19 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15785126
Default Alt Text
D41567.diff (3 KB)
Attached To
Mode
D41567: lib/libc/amd64/string: add strspn(3) scalar, x86-64-v2 implementation, unit tests
Attached
Detach File
Event Timeline
Log In to Comment