1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++03, c++11, c++14 10 // TODO: Change to XFAIL once https://github.com/llvm/llvm-project/issues/40340 is fixed 11 // UNSUPPORTED: availability-pmr-missing 12 13 // <memory_resource> 14 15 // class monotonic_buffer_resource 16 17 #include <memory_resource> 18 #include <cassert> 19 20 #include "count_new.h" 21 #include "test_macros.h" 22 test_geometric_progression()23void test_geometric_progression() { 24 // mem.res.monotonic.buffer 1.3 25 // Each additional buffer is larger than the previous one, following a 26 // geometric progression. 27 28 globalMemCounter.reset(); 29 std::pmr::monotonic_buffer_resource mono1(100, std::pmr::new_delete_resource()); 30 std::pmr::memory_resource& r1 = mono1; 31 32 assert(globalMemCounter.checkNewCalledEq(0)); 33 std::size_t next_buffer_size = 100; 34 void* ret = r1.allocate(10, 1); 35 assert(ret != nullptr); 36 assert(globalMemCounter.checkNewCalledEq(1)); 37 assert(globalMemCounter.last_new_size >= next_buffer_size); 38 next_buffer_size = globalMemCounter.last_new_size + 1; 39 40 int new_called = 1; 41 while (new_called < 5) { 42 ret = r1.allocate(10, 1); 43 if (globalMemCounter.new_called > new_called) { 44 assert(globalMemCounter.new_called == new_called + 1); 45 assert(globalMemCounter.last_new_size >= next_buffer_size); 46 next_buffer_size = globalMemCounter.last_new_size + 1; 47 new_called += 1; 48 } 49 } 50 } 51 main(int,char **)52int main(int, char**) { 53 #if TEST_SUPPORTS_LIBRARY_INTERNAL_ALLOCATIONS && !defined(DISABLE_NEW_COUNT) 54 test_geometric_progression(); 55 #endif 56 57 return 0; 58 } 59