1 //===-- Unittests for memcpy ----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "memory_utils/memory_check_utils.h"
10 #include "src/string/memcpy.h"
11 #include "test/UnitTest/Test.h"
13 namespace LIBC_NAMESPACE
{
15 // Adapt CheckMemcpy signature to memcpy.
16 static inline void Adaptor(cpp::span
<char> dst
, cpp::span
<char> src
,
18 LIBC_NAMESPACE::memcpy(dst
.begin(), src
.begin(), size
);
21 TEST(LlvmLibcMemcpyTest
, SizeSweep
) {
22 static constexpr size_t kMaxSize
= 400;
23 Buffer
SrcBuffer(kMaxSize
);
24 Buffer
DstBuffer(kMaxSize
);
25 Randomize(SrcBuffer
.span());
26 for (size_t size
= 0; size
< kMaxSize
; ++size
) {
27 auto src
= SrcBuffer
.span().subspan(0, size
);
28 auto dst
= DstBuffer
.span().subspan(0, size
);
29 ASSERT_TRUE(CheckMemcpy
<Adaptor
>(dst
, src
, size
));
33 } // namespace LIBC_NAMESPACE