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/test_harness.h"
19#include "pw_fuzzer/fuzztest.h"
20
21namespace pw::allocator::test {
22
31fuzzer::Domain<Request> ArbitraryRequest(size_t max_size);
32
42template <size_t kMaxRequests, size_t kMaxSize>
43auto ArbitraryRequests() {
44 return fuzzer::VectorOf<kMaxRequests>(ArbitraryRequest(kMaxSize));
45}
46
79// }
81template <size_t kIndex, typename... Args>
82Request MakeRequest(Args... args) {
83 if constexpr (kIndex == 0) {
84 return AllocationRequest{static_cast<size_t>(args)...};
85 }
86 if constexpr (kIndex == 1) {
87 return DeallocationRequest{static_cast<size_t>(args)...};
88 }
89 if constexpr (kIndex == 2) {
90 return ReallocationRequest{static_cast<size_t>(args)...};
91 }
92 return Request();
93}
94
95} // namespace pw::allocator::test