git: f0d1236f0fc9 - main - libc: Add memset test for int-to-char conversion
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 13 Jul 2024 13:08:31 UTC
The branch main has been updated by fuz:
URL: https://cgit.FreeBSD.org/src/commit/?id=f0d1236f0fc944165b657306a39d44fcc6aaa709
commit f0d1236f0fc944165b657306a39d44fcc6aaa709
Author: Strahinja Stanišić <strajabot@FreeBSD.org>
AuthorDate: 2024-07-13 12:53:07 +0000
Commit: Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2024-07-13 13:07:49 +0000
libc: Add memset test for int-to-char conversion
Test case to check if an implementation of memset correctly
handles the value passed being wider than a byte
Approved by: emaste
Reviewed By: fuz (GSoC mentor), emaste
Sponsored by: Google LLC (GSoC 2024)
Differential Revision: https://reviews.freebsd.org/D45738
---
lib/libc/tests/string/Makefile | 2 ++
lib/libc/tests/string/memset_test.c | 29 +++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/lib/libc/tests/string/Makefile b/lib/libc/tests/string/Makefile
index 4fce79685c0e..c71a83eede61 100644
--- a/lib/libc/tests/string/Makefile
+++ b/lib/libc/tests/string/Makefile
@@ -12,6 +12,7 @@ ATF_TESTS_C+= flsll_test
ATF_TESTS_C+= memccpy_test
ATF_TESTS_C+= memcmp_test
ATF_TESTS_C+= memrchr_test
+ATF_TESTS_C+= memset2_test
ATF_TESTS_C+= memset_s_test
ATF_TESTS_C+= strncmp_test
ATF_TESTS_C+= stpncpy_test
@@ -45,6 +46,7 @@ NETBSD_ATF_TESTS_C+= strpbrk_test
NETBSD_ATF_TESTS_C+= strrchr_test
NETBSD_ATF_TESTS_C+= swab_test
+SRCS.memset2_test= memset_test.c
SRCS.strcmp2_test= strcmp_test.c
SRCS.strerror2_test= strerror_test.c
diff --git a/lib/libc/tests/string/memset_test.c b/lib/libc/tests/string/memset_test.c
new file mode 100644
index 000000000000..b898ad5af251
--- /dev/null
+++ b/lib/libc/tests/string/memset_test.c
@@ -0,0 +1,29 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Strahinja Stanisic <strajabot@FreeBSD.org>
+ */
+
+#include <assert.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(int_char_conv);
+ATF_TC_BODY(int_char_conv, tc)
+{
+ char b[64];
+ int c = 0xDEADBEEF;
+ memset(&b, c, 64);
+ for(int i = 0; i < 64; i++) {
+ assert(b[i] == (char)c);
+ }
+
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, int_char_conv);
+ return (atf_no_error());
+}
+