157a33737SSchrodinger ZHU Yifan //===-- Unittests for memset_explicit -------------------------------------===// 257a33737SSchrodinger ZHU Yifan // 357a33737SSchrodinger ZHU Yifan // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 457a33737SSchrodinger ZHU Yifan // See https://llvm.org/LICENSE.txt for license information. 557a33737SSchrodinger ZHU Yifan // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 657a33737SSchrodinger ZHU Yifan // 757a33737SSchrodinger ZHU Yifan //===----------------------------------------------------------------------===// 857a33737SSchrodinger ZHU Yifan 957a33737SSchrodinger ZHU Yifan #include "memory_utils/memory_check_utils.h" 10*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 1157a33737SSchrodinger ZHU Yifan #include "src/string/memset_explicit.h" 1257a33737SSchrodinger ZHU Yifan #include "test/UnitTest/Test.h" 1357a33737SSchrodinger ZHU Yifan 14*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 1557a33737SSchrodinger ZHU Yifan 1657a33737SSchrodinger ZHU Yifan // Apply the same tests as memset 1757a33737SSchrodinger ZHU Yifan 1857a33737SSchrodinger ZHU Yifan static inline void Adaptor(cpp::span<char> p1, uint8_t value, size_t size) { 1957a33737SSchrodinger ZHU Yifan LIBC_NAMESPACE::memset_explicit(p1.begin(), value, size); 2057a33737SSchrodinger ZHU Yifan } 2157a33737SSchrodinger ZHU Yifan 2257a33737SSchrodinger ZHU Yifan TEST(LlvmLibcmemsetExplicitTest, SizeSweep) { 2357a33737SSchrodinger ZHU Yifan static constexpr size_t kMaxSize = 400; 2457a33737SSchrodinger ZHU Yifan Buffer DstBuffer(kMaxSize); 2557a33737SSchrodinger ZHU Yifan for (size_t size = 0; size < kMaxSize; ++size) { 2657a33737SSchrodinger ZHU Yifan const char value = size % 10; 2757a33737SSchrodinger ZHU Yifan auto dst = DstBuffer.span().subspan(0, size); 2857a33737SSchrodinger ZHU Yifan ASSERT_TRUE((CheckMemset<Adaptor>(dst, value, size))); 2957a33737SSchrodinger ZHU Yifan } 3057a33737SSchrodinger ZHU Yifan } 3157a33737SSchrodinger ZHU Yifan 32*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 33