FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
marl/src/pool_test.cpp at main · google/marl · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Apr 27, 2026. It is now read-only.
google
/
marl
Public archive
Notifications
You must be signed in to change notification settings
Fork
204
Star
2k
Code
Issues
10
Pull requests
3
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
marl
/
src
/
pool_test.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
206 lines (187 loc) · 5.92 KB
Breadcrumbs
marl
/
src
/
pool_test.cpp
Copy path
File metadata and controls
206 lines (187 loc) · 5.92 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//
Copyright 2019 The Marl Authors.
//
//
Licensed under the Apache License, Version 2.0 (the "License");
//
you may not use this file except in compliance with the License.
//
You may obtain a copy of the License at
//
//
https://www.apache.org/licenses/LICENSE-2.0
//
//
Unless required by applicable law or agreed to in writing, software
//
distributed under the License is distributed on an "AS IS" BASIS,
//
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
See the License for the specific language governing permissions and
//
limitations under the License.
#
include
"
marl_test.h
"
#
include
"
marl/memory.h
"
#
include
"
marl/pool.h
"
#
include
"
marl/waitgroup.h
"
TEST_P
(WithBoundScheduler, UnboundedPool_ConstructDestruct) {
marl::UnboundedPool<
int
> pool;
}
TEST_P
(WithBoundScheduler, BoundedPool_ConstructDestruct) {
marl::BoundedPool<
int
,
10
> pool;
}
TEST_P
(WithBoundScheduler, UnboundedPoolLoan_GetNull) {
marl::UnboundedPool<
int
>::Loan loan;
ASSERT_EQ
(loan.
get
(),
nullptr
);
}
TEST_P
(WithBoundScheduler, BoundedPoolLoan_GetNull) {
marl::BoundedPool<
int
,
10
>::Loan loan;
ASSERT_EQ
(loan.
get
(),
nullptr
);
}
TEST_P
(WithBoundScheduler, UnboundedPool_Borrow) {
marl::UnboundedPool<
int
> pool;
for
(
int
i =
0
; i <
100
; i++) {
pool.
borrow
();
}
}
TEST_P
(WithBoundScheduler, UnboundedPool_ConcurrentBorrow) {
marl::UnboundedPool<
int
> pool;
constexpr
int
iterations =
10000
;
marl::WaitGroup
wg
(iterations);
for
(
int
i =
0
; i < iterations; i++) {
marl::schedule
([=] {
pool.
borrow
();
wg.
done
();
});
}
wg.
wait
();
}
TEST_P
(WithBoundScheduler, BoundedPool_Borrow) {
marl::BoundedPool<
int
,
100
> pool;
for
(
int
i =
0
; i <
100
; i++) {
pool.
borrow
();
}
}
TEST_P
(WithBoundScheduler, BoundedPool_ConcurrentBorrow) {
marl::BoundedPool<
int
,
10
> pool;
constexpr
int
iterations =
10000
;
marl::WaitGroup
wg
(iterations);
for
(
int
i =
0
; i < iterations; i++) {
marl::schedule
([=] {
pool.
borrow
();
wg.
done
();
});
}
wg.
wait
();
}
struct
CtorDtorCounter
{
CtorDtorCounter
() { ctor_count++; }
~CtorDtorCounter
() { dtor_count++; }
static
void
reset
() {
ctor_count =
0
;
dtor_count =
0
;
}
static
int
ctor_count;
static
int
dtor_count;
};
int
CtorDtorCounter::ctor_count = -
1
;
int
CtorDtorCounter::dtor_count = -
1
;
TEST_P
(WithBoundScheduler, UnboundedPool_PolicyReconstruct) {
CtorDtorCounter::reset
();
marl::UnboundedPool<CtorDtorCounter, marl::PoolPolicy::Reconstruct> pool;
ASSERT_EQ
(CtorDtorCounter::ctor_count,
0
);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
0
);
{
auto
loan = pool.
borrow
();
ASSERT_EQ
(CtorDtorCounter::ctor_count,
1
);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
0
);
}
ASSERT_EQ
(CtorDtorCounter::ctor_count,
1
);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
1
);
{
auto
loan = pool.
borrow
();
ASSERT_EQ
(CtorDtorCounter::ctor_count,
2
);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
1
);
}
ASSERT_EQ
(CtorDtorCounter::ctor_count,
2
);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
2
);
}
TEST_P
(WithBoundScheduler, BoundedPool_PolicyReconstruct) {
CtorDtorCounter::reset
();
marl::BoundedPool<CtorDtorCounter,
10
, marl::PoolPolicy::Reconstruct> pool;
ASSERT_EQ
(CtorDtorCounter::ctor_count,
0
);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
0
);
{
auto
loan = pool.
borrow
();
ASSERT_EQ
(CtorDtorCounter::ctor_count,
1
);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
0
);
}
ASSERT_EQ
(CtorDtorCounter::ctor_count,
1
);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
1
);
{
auto
loan = pool.
borrow
();
ASSERT_EQ
(CtorDtorCounter::ctor_count,
2
);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
1
);
}
ASSERT_EQ
(CtorDtorCounter::ctor_count,
2
);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
2
);
}
TEST_P
(WithBoundScheduler, UnboundedPool_PolicyPreserve) {
CtorDtorCounter::reset
();
{
marl::UnboundedPool<CtorDtorCounter, marl::PoolPolicy::Preserve> pool;
int
ctor_count;
{
auto
loan = pool.
borrow
();
ASSERT_NE
(CtorDtorCounter::ctor_count,
0
);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
0
);
ctor_count = CtorDtorCounter::ctor_count;
}
ASSERT_EQ
(CtorDtorCounter::ctor_count, ctor_count);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
0
);
{
auto
loan = pool.
borrow
();
ASSERT_EQ
(CtorDtorCounter::ctor_count, ctor_count);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
0
);
}
ASSERT_EQ
(CtorDtorCounter::ctor_count, ctor_count);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
0
);
}
ASSERT_EQ
(CtorDtorCounter::ctor_count, CtorDtorCounter::dtor_count);
}
TEST_P
(WithBoundScheduler, BoundedPool_PolicyPreserve) {
CtorDtorCounter::reset
();
{
marl::BoundedPool<CtorDtorCounter,
10
, marl::PoolPolicy::Preserve> pool;
int
ctor_count;
{
auto
loan = pool.
borrow
();
ASSERT_NE
(CtorDtorCounter::ctor_count,
0
);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
0
);
ctor_count = CtorDtorCounter::ctor_count;
}
ASSERT_EQ
(CtorDtorCounter::ctor_count, ctor_count);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
0
);
{
auto
loan = pool.
borrow
();
ASSERT_EQ
(CtorDtorCounter::ctor_count, ctor_count);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
0
);
}
ASSERT_EQ
(CtorDtorCounter::ctor_count, ctor_count);
ASSERT_EQ
(CtorDtorCounter::dtor_count,
0
);
}
ASSERT_EQ
(CtorDtorCounter::ctor_count, CtorDtorCounter::dtor_count);
}
struct
alignas
(
64
) StructWithAlignment {
uint8_t
i;
uint8_t
padding[
63
];
};
TEST_P
(WithBoundScheduler, BoundedPool_AlignedTypes) {
marl::BoundedPool<StructWithAlignment,
100
> pool;
for
(
int
i =
0
; i <
100
; i++) {
auto
loan = pool.
borrow
();
ASSERT_EQ
(
reinterpret_cast
<
uintptr_t
>(&loan->
i
) &
(
alignof
(StructWithAlignment) -
1
),
0U
);
}
}
TEST_P
(WithBoundScheduler, UnboundedPool_AlignedTypes) {
marl::UnboundedPool<StructWithAlignment> pool;
for
(
int
i =
0
; i <
100
; i++) {
auto
loan = pool.
borrow
();
ASSERT_EQ
(
reinterpret_cast
<
uintptr_t
>(&loan->
i
) &
(
alignof
(StructWithAlignment) -
1
),
0U
);
}
}
Back
|
FazBrowse Home
|
New Git URL