xref: /aosp_15_r20/external/pigweed/pw_allocator/examples/custom_allocator_test_harness.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2024 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 // DOCSTAG: [pw_allocator-examples-custom_allocator-test_harness]
17 #include <cstddef>
18 
19 #include "examples/custom_allocator.h"
20 #include "pw_allocator/test_harness.h"
21 #include "pw_allocator/testing.h"
22 
23 namespace examples {
24 
25 class CustomAllocatorTestHarness : public pw::allocator::test::TestHarness {
26  public:
27   static constexpr size_t kCapacity = 0x1000;
28   static constexpr size_t kThreshold = 0x800;
29 
CustomAllocatorTestHarness()30   CustomAllocatorTestHarness() : custom_(allocator_, kThreshold) {}
31 
Init()32   pw::Allocator* Init() override { return &custom_; }
33 
34  private:
35   pw::allocator::test::AllocatorForTest<kCapacity> allocator_;
36   CustomAllocator custom_;
37 };
38 
39 }  // namespace examples
40