]>
git.proxmox.com Git - ceph.git/blob - ceph/src/zstd/contrib/pzstd/utils/test/ResourcePoolTest.cpp
2 * Copyright (c) 2016-present, Facebook, Inc.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
9 #include "utils/ResourcePool.h"
11 #include <gtest/gtest.h>
15 using namespace pzstd
;
17 TEST(ResourcePool
, FullTest
) {
18 unsigned numCreated
= 0;
19 unsigned numDeleted
= 0;
21 ResourcePool
<int> pool(
22 [&numCreated
] { ++numCreated
; return new int{5}; },
23 [&numDeleted
](int *x
) { ++numDeleted
; delete x
; });
44 EXPECT_EQ(2, numCreated
);
45 EXPECT_EQ(numCreated
, numDeleted
);
48 TEST(ResourcePool
, ThreadSafe
) {
49 std::atomic
<unsigned> numCreated
{0};
50 std::atomic
<unsigned> numDeleted
{0};
52 ResourcePool
<int> pool(
53 [&numCreated
] { ++numCreated
; return new int{0}; },
54 [&numDeleted
](int *x
) { ++numDeleted
; delete x
; });
56 for (int i
= 0; i
< 100; ++i
) {
68 EXPECT_EQ(200, *x
+ *y
);
70 EXPECT_GE(2, numCreated
);
71 EXPECT_EQ(numCreated
, numDeleted
);