1 | //===-- Unittests for memcpy ----------------------------------------------===// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "memory_utils/memory_check_utils.h" |
10 | #include "src/string/memcpy.h" |
11 | #include "test/UnitTest/Test.h" |
12 | |
13 | namespace LIBC_NAMESPACE { |
14 | |
15 | // Adapt CheckMemcpy signature to memcpy. |
16 | static inline void Adaptor(cpp::span<char> dst, cpp::span<char> src, |
17 | size_t size) { |
18 | LIBC_NAMESPACE::memcpy(dst.begin(), src.begin(), size); |
19 | } |
20 | |
21 | TEST(LlvmLibcMemcpyTest, SizeSweep) { |
22 | static constexpr size_t kMaxSize = 400; |
23 | Buffer SrcBuffer(kMaxSize); |
24 | Buffer DstBuffer(kMaxSize); |
25 | Randomize(buffer: SrcBuffer.span()); |
26 | for (size_t size = 0; size < kMaxSize; ++size) { |
27 | auto src = SrcBuffer.span().subspan(offset: 0, count: size); |
28 | auto dst = DstBuffer.span().subspan(offset: 0, count: size); |
29 | ASSERT_TRUE(CheckMemcpy<Adaptor>(dst, src, size)); |
30 | } |
31 | } |
32 | |
33 | } // namespace LIBC_NAMESPACE |
34 | |