Pigweed
 
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
32fuzzer::Domain<Request> ArbitraryRequest(size_t max_size);
33
43template <size_t kMaxRequests, size_t kMaxSize>
44auto ArbitraryRequests() {
45 return fuzzer::VectorOf<kMaxRequests>(ArbitraryRequest(kMaxSize));
46}
47
80// }
82template <size_t kIndex, typename... Args>
83Request MakeRequest(Args... args) {
84 if constexpr (kIndex == 0) {
85 return AllocationRequest{static_cast<size_t>(args)...};
86 }
87 if constexpr (kIndex == 1) {
88 return DeallocationRequest{static_cast<size_t>(args)...};
89 }
90 if constexpr (kIndex == 2) {
91 return ReallocationRequest{static_cast<size_t>(args)...};
92 }
93 return Request();
94}
95
96inline constexpr size_t kMaxRequests = 256;
97inline constexpr size_t kMaxSize = 2048;
98
99inline auto DefaultArbitraryRequests() {
100 return pw::allocator::test::ArbitraryRequests<kMaxRequests, kMaxSize>();
101}
102
103} // namespace pw::allocator::test