]>
git.saurik.com Git - apple/xnu.git/blob - tests/safe_allocation_src/test_utils.h
1 #ifndef TESTS_SAFE_ALLOCATION_TEST_UTILS_H
2 #define TESTS_SAFE_ALLOCATION_TEST_UTILS_H
4 #include <libkern/c++/bounded_ptr.h>
5 #include <libkern/c++/safe_allocation.h>
6 #include <darwintest_utils.h>
12 struct assert_trapping_policy
{
20 struct malloc_allocator
{
24 return std::malloc(n
);
28 deallocate(void* p
, size_t n
)
34 struct tracking_allocator
{
41 did_deallocate
= false;
43 static std::size_t allocated_size
;
44 static std::size_t deallocated_size
;
45 static bool did_allocate
;
46 static bool did_deallocate
;
49 allocate(std::size_t n
)
53 return std::malloc(n
);
57 deallocate(void* p
, std::size_t n
)
59 did_deallocate
= true;
65 std::size_t tracking_allocator::allocated_size
= 0;
66 std::size_t tracking_allocator::deallocated_size
= 0;
67 bool tracking_allocator::did_allocate
= false;
68 bool tracking_allocator::did_deallocate
= false;
70 struct tracking_trapping_policy
{
83 bool tracking_trapping_policy::did_trap
= false;
86 using test_safe_allocation
= libkern::safe_allocation
<T
, malloc_allocator
, assert_trapping_policy
>;
89 using tracked_safe_allocation
= libkern::safe_allocation
<T
, tracking_allocator
, assert_trapping_policy
>;
92 using test_bounded_ptr
= libkern::bounded_ptr
<T
, assert_trapping_policy
>;
93 } // end anonymous namespace
95 #define CHECK(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__)
97 #endif // !TESTS_SAFE_ALLOCATION_TEST_UTILS_H