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 // struct pool_options
16 // class unsynchronized_pool_resource
17 // class synchronized_pool_resource
18 
19 #include <memory_resource>
20 #include <cassert>
21 #include <cstdint> // SIZE_MAX, UINT32_MAX
22 
assert_options(const std::pmr::pool_options & actual,const std::pmr::pool_options & expected)23 static void assert_options(const std::pmr::pool_options& actual, const std::pmr::pool_options& expected) {
24   assert(actual.max_blocks_per_chunk == expected.max_blocks_per_chunk);
25   assert(actual.largest_required_pool_block == expected.largest_required_pool_block);
26 }
27 
test_pool_options(std::pmr::pool_options initial,std::pmr::pool_options expected)28 void test_pool_options(std::pmr::pool_options initial, std::pmr::pool_options expected) {
29   std::pmr::unsynchronized_pool_resource mr(initial, std::pmr::null_memory_resource());
30   assert_options(mr.options(), expected);
31 
32   std::pmr::synchronized_pool_resource mr2(initial, std::pmr::null_memory_resource());
33   assert_options(mr2.options(), expected);
34 }
35 
main(int,char **)36 int main(int, char**) {
37   test_pool_options({0, 0}, {1048576, 1048576});
38   test_pool_options({0, 1}, {1048576, 8});
39   test_pool_options({0, 2}, {1048576, 8});
40   test_pool_options({0, 4}, {1048576, 8});
41   test_pool_options({0, 8}, {1048576, 8});
42   test_pool_options({0, 16}, {1048576, 16});
43   test_pool_options({0, 32}, {1048576, 32});
44   test_pool_options({0, 1024}, {1048576, 1024});
45   test_pool_options({0, 1048576}, {1048576, 1048576});
46   test_pool_options({0, 2097152}, {1048576, 2097152});
47   test_pool_options({0, 1073741824}, {1048576, 1073741824});
48   test_pool_options({0, 2147483648}, {1048576, 1073741824});
49   test_pool_options({1, 0}, {16, 1048576});
50   test_pool_options({1, 1}, {16, 8});
51   test_pool_options({1, 2}, {16, 8});
52   test_pool_options({1, 4}, {16, 8});
53   test_pool_options({1, 8}, {16, 8});
54   test_pool_options({1, 16}, {16, 16});
55   test_pool_options({1, 32}, {16, 32});
56   test_pool_options({1, 1024}, {16, 1024});
57   test_pool_options({1, 1048576}, {16, 1048576});
58   test_pool_options({1, 2097152}, {16, 2097152});
59   test_pool_options({1, 1073741824}, {16, 1073741824});
60   test_pool_options({1, 2147483648}, {16, 1073741824});
61   test_pool_options({2, 0}, {16, 1048576});
62   test_pool_options({2, 1}, {16, 8});
63   test_pool_options({2, 2}, {16, 8});
64   test_pool_options({2, 4}, {16, 8});
65   test_pool_options({2, 8}, {16, 8});
66   test_pool_options({2, 16}, {16, 16});
67   test_pool_options({2, 32}, {16, 32});
68   test_pool_options({2, 1024}, {16, 1024});
69   test_pool_options({2, 1048576}, {16, 1048576});
70   test_pool_options({2, 2097152}, {16, 2097152});
71   test_pool_options({2, 1073741824}, {16, 1073741824});
72   test_pool_options({2, 2147483648}, {16, 1073741824});
73   test_pool_options({4, 0}, {16, 1048576});
74   test_pool_options({4, 1}, {16, 8});
75   test_pool_options({4, 2}, {16, 8});
76   test_pool_options({4, 4}, {16, 8});
77   test_pool_options({4, 8}, {16, 8});
78   test_pool_options({4, 16}, {16, 16});
79   test_pool_options({4, 32}, {16, 32});
80   test_pool_options({4, 1024}, {16, 1024});
81   test_pool_options({4, 1048576}, {16, 1048576});
82   test_pool_options({4, 2097152}, {16, 2097152});
83   test_pool_options({4, 1073741824}, {16, 1073741824});
84   test_pool_options({4, 2147483648}, {16, 1073741824});
85   test_pool_options({8, 0}, {16, 1048576});
86   test_pool_options({8, 1}, {16, 8});
87   test_pool_options({8, 2}, {16, 8});
88   test_pool_options({8, 4}, {16, 8});
89   test_pool_options({8, 8}, {16, 8});
90   test_pool_options({8, 16}, {16, 16});
91   test_pool_options({8, 32}, {16, 32});
92   test_pool_options({8, 1024}, {16, 1024});
93   test_pool_options({8, 1048576}, {16, 1048576});
94   test_pool_options({8, 2097152}, {16, 2097152});
95   test_pool_options({8, 1073741824}, {16, 1073741824});
96   test_pool_options({8, 2147483648}, {16, 1073741824});
97   test_pool_options({16, 0}, {16, 1048576});
98   test_pool_options({16, 1}, {16, 8});
99   test_pool_options({16, 2}, {16, 8});
100   test_pool_options({16, 4}, {16, 8});
101   test_pool_options({16, 8}, {16, 8});
102   test_pool_options({16, 16}, {16, 16});
103   test_pool_options({16, 32}, {16, 32});
104   test_pool_options({16, 1024}, {16, 1024});
105   test_pool_options({16, 1048576}, {16, 1048576});
106   test_pool_options({16, 2097152}, {16, 2097152});
107   test_pool_options({16, 1073741824}, {16, 1073741824});
108   test_pool_options({16, 2147483648}, {16, 1073741824});
109   test_pool_options({32, 0}, {32, 1048576});
110   test_pool_options({32, 1}, {32, 8});
111   test_pool_options({32, 2}, {32, 8});
112   test_pool_options({32, 4}, {32, 8});
113   test_pool_options({32, 8}, {32, 8});
114   test_pool_options({32, 16}, {32, 16});
115   test_pool_options({32, 32}, {32, 32});
116   test_pool_options({32, 1024}, {32, 1024});
117   test_pool_options({32, 1048576}, {32, 1048576});
118   test_pool_options({32, 2097152}, {32, 2097152});
119   test_pool_options({32, 1073741824}, {32, 1073741824});
120   test_pool_options({32, 2147483648}, {32, 1073741824});
121   test_pool_options({1024, 0}, {1024, 1048576});
122   test_pool_options({1024, 1}, {1024, 8});
123   test_pool_options({1024, 2}, {1024, 8});
124   test_pool_options({1024, 4}, {1024, 8});
125   test_pool_options({1024, 8}, {1024, 8});
126   test_pool_options({1024, 16}, {1024, 16});
127   test_pool_options({1024, 32}, {1024, 32});
128   test_pool_options({1024, 1024}, {1024, 1024});
129   test_pool_options({1024, 1048576}, {1024, 1048576});
130   test_pool_options({1024, 2097152}, {1024, 2097152});
131   test_pool_options({1024, 1073741824}, {1024, 1073741824});
132   test_pool_options({1024, 2147483648}, {1024, 1073741824});
133   test_pool_options({1048576, 0}, {1048576, 1048576});
134   test_pool_options({1048576, 1}, {1048576, 8});
135   test_pool_options({1048576, 2}, {1048576, 8});
136   test_pool_options({1048576, 4}, {1048576, 8});
137   test_pool_options({1048576, 8}, {1048576, 8});
138   test_pool_options({1048576, 16}, {1048576, 16});
139   test_pool_options({1048576, 32}, {1048576, 32});
140   test_pool_options({1048576, 1024}, {1048576, 1024});
141   test_pool_options({1048576, 1048576}, {1048576, 1048576});
142   test_pool_options({1048576, 2097152}, {1048576, 2097152});
143   test_pool_options({1048576, 1073741824}, {1048576, 1073741824});
144   test_pool_options({1048576, 2147483648}, {1048576, 1073741824});
145   test_pool_options({2097152, 0}, {1048576, 1048576});
146   test_pool_options({2097152, 1}, {1048576, 8});
147   test_pool_options({2097152, 2}, {1048576, 8});
148   test_pool_options({2097152, 4}, {1048576, 8});
149   test_pool_options({2097152, 8}, {1048576, 8});
150   test_pool_options({2097152, 16}, {1048576, 16});
151   test_pool_options({2097152, 32}, {1048576, 32});
152   test_pool_options({2097152, 1024}, {1048576, 1024});
153   test_pool_options({2097152, 1048576}, {1048576, 1048576});
154   test_pool_options({2097152, 2097152}, {1048576, 2097152});
155   test_pool_options({2097152, 1073741824}, {1048576, 1073741824});
156   test_pool_options({2097152, 2147483648}, {1048576, 1073741824});
157   test_pool_options({1073741824, 0}, {1048576, 1048576});
158   test_pool_options({1073741824, 1}, {1048576, 8});
159   test_pool_options({1073741824, 2}, {1048576, 8});
160   test_pool_options({1073741824, 4}, {1048576, 8});
161   test_pool_options({1073741824, 8}, {1048576, 8});
162   test_pool_options({1073741824, 16}, {1048576, 16});
163   test_pool_options({1073741824, 32}, {1048576, 32});
164   test_pool_options({1073741824, 1024}, {1048576, 1024});
165   test_pool_options({1073741824, 1048576}, {1048576, 1048576});
166   test_pool_options({1073741824, 2097152}, {1048576, 2097152});
167   test_pool_options({1073741824, 1073741824}, {1048576, 1073741824});
168   test_pool_options({1073741824, 2147483648}, {1048576, 1073741824});
169   test_pool_options({2147483648, 0}, {1048576, 1048576});
170   test_pool_options({2147483648, 1}, {1048576, 8});
171   test_pool_options({2147483648, 2}, {1048576, 8});
172   test_pool_options({2147483648, 4}, {1048576, 8});
173   test_pool_options({2147483648, 8}, {1048576, 8});
174   test_pool_options({2147483648, 16}, {1048576, 16});
175   test_pool_options({2147483648, 32}, {1048576, 32});
176   test_pool_options({2147483648, 1024}, {1048576, 1024});
177   test_pool_options({2147483648, 1048576}, {1048576, 1048576});
178   test_pool_options({2147483648, 2097152}, {1048576, 2097152});
179   test_pool_options({2147483648, 1073741824}, {1048576, 1073741824});
180   test_pool_options({2147483648, 2147483648}, {1048576, 1073741824});
181 
182 #if SIZE_MAX > UINT32_MAX
183   test_pool_options({0, 8589934592}, {1048576, 1073741824});
184   test_pool_options({1, 8589934592}, {16, 1073741824});
185   test_pool_options({2, 8589934592}, {16, 1073741824});
186   test_pool_options({4, 8589934592}, {16, 1073741824});
187   test_pool_options({8, 8589934592}, {16, 1073741824});
188   test_pool_options({16, 8589934592}, {16, 1073741824});
189   test_pool_options({32, 8589934592}, {32, 1073741824});
190   test_pool_options({1024, 8589934592}, {1024, 1073741824});
191   test_pool_options({1048576, 8589934592}, {1048576, 1073741824});
192   test_pool_options({2097152, 8589934592}, {1048576, 1073741824});
193   test_pool_options({1073741824, 8589934592}, {1048576, 1073741824});
194   test_pool_options({2147483648, 8589934592}, {1048576, 1073741824});
195   test_pool_options({8589934592, 0}, {1048576, 1048576});
196   test_pool_options({8589934592, 1}, {1048576, 8});
197   test_pool_options({8589934592, 2}, {1048576, 8});
198   test_pool_options({8589934592, 4}, {1048576, 8});
199   test_pool_options({8589934592, 8}, {1048576, 8});
200   test_pool_options({8589934592, 16}, {1048576, 16});
201   test_pool_options({8589934592, 32}, {1048576, 32});
202   test_pool_options({8589934592, 1024}, {1048576, 1024});
203   test_pool_options({8589934592, 1048576}, {1048576, 1048576});
204   test_pool_options({8589934592, 2097152}, {1048576, 2097152});
205   test_pool_options({8589934592, 1073741824}, {1048576, 1073741824});
206   test_pool_options({8589934592, 2147483648}, {1048576, 1073741824});
207   test_pool_options({8589934592, 8589934592}, {1048576, 1073741824});
208 #endif
209 
210   return 0;
211 }
212