xref: /aosp_15_r20/external/llvm-libc/test/src/string/memset_explicit_test.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1  //===-- Unittests for memset_explicit -------------------------------------===//
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/__support/macros/config.h"
11  #include "src/string/memset_explicit.h"
12  #include "test/UnitTest/Test.h"
13  
14  namespace LIBC_NAMESPACE_DECL {
15  
16  // Apply the same tests as memset
17  
Adaptor(cpp::span<char> p1,uint8_t value,size_t size)18  static inline void Adaptor(cpp::span<char> p1, uint8_t value, size_t size) {
19    LIBC_NAMESPACE::memset_explicit(p1.begin(), value, size);
20  }
21  
TEST(LlvmLibcmemsetExplicitTest,SizeSweep)22  TEST(LlvmLibcmemsetExplicitTest, SizeSweep) {
23    static constexpr size_t kMaxSize = 400;
24    Buffer DstBuffer(kMaxSize);
25    for (size_t size = 0; size < kMaxSize; ++size) {
26      const char value = size % 10;
27      auto dst = DstBuffer.span().subspan(0, size);
28      ASSERT_TRUE((CheckMemset<Adaptor>(dst, value, size)));
29    }
30  }
31  
32  } // namespace LIBC_NAMESPACE_DECL
33