27
27
using namespace OCLRT ;
28
28
29
29
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); }
35
31
36
32
static void initThreadFunc (Platform *pP) {
37
33
pP->initialize ();
@@ -42,7 +38,7 @@ struct PlatformTestMt : public ::testing::Test {
42
38
}
43
39
44
40
cl_int retVal = CL_SUCCESS;
45
- Platform * pPlatform = nullptr ;
41
+ std::unique_ptr< Platform> pPlatform;
46
42
};
47
43
48
44
static void callinitPlatform (Platform *plt, bool *ret) {
@@ -53,7 +49,7 @@ TEST_F(PlatformTestMt, initialize) {
53
49
std::thread threads[10 ];
54
50
bool ret[10 ];
55
51
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]);
57
53
}
58
54
59
55
for (auto &th : threads)
@@ -67,7 +63,7 @@ TEST_F(PlatformTestMt, initialize) {
67
63
pPlatform->shutdown ();
68
64
69
65
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]);
71
67
}
72
68
73
69
for (auto &th : threads)
@@ -84,15 +80,15 @@ TEST_F(PlatformTestMt, mtSafeTest) {
84
80
EXPECT_EQ (0u , devNum);
85
81
86
82
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 () );
89
85
EXPECT_TRUE (ret);
90
86
91
87
t1.join ();
92
88
t2.join ();
93
89
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 () );
96
92
97
93
t3.join ();
98
94
t4.join ();
0 commit comments