Skip to content

Commit fc8d3d9

Browse files
Use locally allocated platform in platform tests.
Change-Id: If69d1d9d09a9bcd1f215dc562d1c15681bef3f41
1 parent 6862098 commit fc8d3d9

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

unit_tests/platform/platform_tests_mt.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@
2727
using namespace OCLRT;
2828

2929
struct PlatformTestMt : public ::testing::Test {
30-
PlatformTestMt() {}
31-
32-
void SetUp() override { pPlatform = platform(); }
33-
34-
void TearDown() override {}
30+
void SetUp() override { pPlatform.reset(new Platform); }
3531

3632
static void initThreadFunc(Platform *pP) {
3733
pP->initialize();
@@ -42,7 +38,7 @@ struct PlatformTestMt : public ::testing::Test {
4238
}
4339

4440
cl_int retVal = CL_SUCCESS;
45-
Platform *pPlatform = nullptr;
41+
std::unique_ptr<Platform> pPlatform;
4642
};
4743

4844
static void callinitPlatform(Platform *plt, bool *ret) {
@@ -53,7 +49,7 @@ TEST_F(PlatformTestMt, initialize) {
5349
std::thread threads[10];
5450
bool ret[10];
5551
for (int i = 0; i < 10; ++i) {
56-
threads[i] = std::thread(callinitPlatform, pPlatform, &ret[i]);
52+
threads[i] = std::thread(callinitPlatform, pPlatform.get(), &ret[i]);
5753
}
5854

5955
for (auto &th : threads)
@@ -67,7 +63,7 @@ TEST_F(PlatformTestMt, initialize) {
6763
pPlatform->shutdown();
6864

6965
for (int i = 0; i < 10; ++i) {
70-
threads[i] = std::thread(callinitPlatform, pPlatform, &ret[i]);
66+
threads[i] = std::thread(callinitPlatform, pPlatform.get(), &ret[i]);
7167
}
7268

7369
for (auto &th : threads)
@@ -84,15 +80,15 @@ TEST_F(PlatformTestMt, mtSafeTest) {
8480
EXPECT_EQ(0u, devNum);
8581

8682
bool ret = pPlatform->initialize();
87-
std::thread t1(PlatformTestMt::initThreadFunc, pPlatform);
88-
std::thread t2(PlatformTestMt::shutdownThreadFunc, pPlatform);
83+
std::thread t1(PlatformTestMt::initThreadFunc, pPlatform.get());
84+
std::thread t2(PlatformTestMt::shutdownThreadFunc, pPlatform.get());
8985
EXPECT_TRUE(ret);
9086

9187
t1.join();
9288
t2.join();
9389

94-
std::thread t3(PlatformTestMt::initThreadFunc, pPlatform);
95-
std::thread t4(PlatformTestMt::initThreadFunc, pPlatform);
90+
std::thread t3(PlatformTestMt::initThreadFunc, pPlatform.get());
91+
std::thread t4(PlatformTestMt::initThreadFunc, pPlatform.get());
9692

9793
t3.join();
9894
t4.join();

0 commit comments

Comments
 (0)