1//===-- Unittests for memset ----------------------------------------------===//
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/memset.h"
11#include "test/UnitTest/Test.h"
12
13namespace LIBC_NAMESPACE {
14
15// Adapt CheckMemset signature to memset.
16static inline void Adaptor(cpp::span<char> p1, uint8_t value, size_t size) {
17 LIBC_NAMESPACE::memset(ptr: p1.begin(), value, count: size);
18}
19
20TEST(LlvmLibcMemsetTest, SizeSweep) {
21 static constexpr size_t kMaxSize = 400;
22 Buffer DstBuffer(kMaxSize);
23 for (size_t size = 0; size < kMaxSize; ++size) {
24 const char value = size % 10;
25 auto dst = DstBuffer.span().subspan(offset: 0, count: size);
26 ASSERT_TRUE((CheckMemset<Adaptor>(dst, value, size)));
27 }
28}
29
30} // namespace LIBC_NAMESPACE
31

source code of libc/test/src/string/memset_test.cpp