2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2019-02-27 11:39:32 +01:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-12-09 15:29:30 +01:00
|
|
|
#include "core/helpers/options.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "unit_tests/fixtures/platform_fixture.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
using namespace NEO;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-03-29 21:26:25 +02:00
|
|
|
struct PlatformTestMt : public ::testing::Test {
|
2018-06-26 13:24:02 +02:00
|
|
|
void SetUp() override { pPlatform.reset(new Platform); }
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
static void initThreadFunc(Platform *pP) {
|
2018-06-20 18:25:40 +02:00
|
|
|
pP->initialize();
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cl_int retVal = CL_SUCCESS;
|
2018-06-26 13:24:02 +02:00
|
|
|
std::unique_ptr<Platform> pPlatform;
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void callinitPlatform(Platform *plt, bool *ret) {
|
2018-06-20 18:25:40 +02:00
|
|
|
*ret = plt->initialize();
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(PlatformTestMt, initialize) {
|
|
|
|
|
std::thread threads[10];
|
|
|
|
|
bool ret[10];
|
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
2018-06-26 13:24:02 +02:00
|
|
|
threads[i] = std::thread(callinitPlatform, pPlatform.get(), &ret[i]);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto &th : threads)
|
|
|
|
|
th.join();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
|
EXPECT_TRUE(ret[i]);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(pPlatform->isInitialized());
|
|
|
|
|
|
2018-06-28 08:51:44 +02:00
|
|
|
pPlatform.reset(new Platform());
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
2018-06-26 13:24:02 +02:00
|
|
|
threads[i] = std::thread(callinitPlatform, pPlatform.get(), &ret[i]);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto &th : threads)
|
|
|
|
|
th.join();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
|
EXPECT_TRUE(ret[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(PlatformTestMt, mtSafeTest) {
|
|
|
|
|
size_t devNum = pPlatform->getNumDevices();
|
|
|
|
|
EXPECT_EQ(0u, devNum);
|
|
|
|
|
|
2018-06-26 13:24:02 +02:00
|
|
|
std::thread t1(PlatformTestMt::initThreadFunc, pPlatform.get());
|
2018-06-28 08:51:44 +02:00
|
|
|
std::thread t2(PlatformTestMt::initThreadFunc, pPlatform.get());
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
t1.join();
|
|
|
|
|
t2.join();
|
|
|
|
|
|
|
|
|
|
devNum = pPlatform->getNumDevices();
|
|
|
|
|
EXPECT_EQ(numPlatformDevices, devNum);
|
|
|
|
|
}
|