C/C++ API Reference
Loading...
Searching...
No Matches
fuzzing.h
1// Copyright 2023 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include <cstddef>
17
18#include "pw_allocator/allocator.h"
19#include "pw_allocator/test_harness.h"
20#include "pw_fuzzer/fuzztest.h"
21
22namespace pw::allocator::test {
23
25
34fuzzer::Domain<Request> ArbitraryRequest(size_t max_size);
35
45template <size_t kMaxRequests, size_t kMaxSize>
47 return fuzzer::VectorOf<kMaxRequests>(ArbitraryRequest(kMaxSize));
48}
49
82// }
84template <size_t kIndex, typename... Args>
85Request MakeRequest(Args... args) {
86 if constexpr (kIndex == 0) {
87 return AllocationRequest{static_cast<size_t>(args)...};
88 }
89 if constexpr (kIndex == 1) {
90 return DeallocationRequest{static_cast<size_t>(args)...};
91 }
92 if constexpr (kIndex == 2) {
93 return ReallocationRequest{static_cast<size_t>(args)...};
94 }
95 return Request();
96}
97
98inline constexpr size_t kMaxRequests = 256;
99inline constexpr size_t kMaxSize = 2048;
100
101inline auto DefaultArbitraryRequests() {
102 return pw::allocator::test::ArbitraryRequests<kMaxRequests, kMaxSize>();
103}
104
106
107} // namespace pw::allocator::test
Request MakeRequest(Args... args)
Definition: fuzzing.h:85
auto ArbitraryRequests()
Definition: fuzzing.h:46
fuzzer::Domain< Request > ArbitraryRequest(size_t max_size)
Represents a request to allocate some memory.
Definition: test_harness.h:30
Represents a request to free some allocated memory.
Definition: test_harness.h:36
Represents a request to reallocate allocated memory with a new size.
Definition: test_harness.h:41