mirror of
https://github.com/opnsense/src.git
synced 2026-06-14 19:20:18 -04:00
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
This commit is contained in:
parent
69dace892d
commit
f0d1236f0f
2 changed files with 31 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
29
lib/libc/tests/string/memset_test.c
Normal file
29
lib/libc/tests/string/memset_test.c
Normal file
|
|
@ -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());
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue