Files
compute-runtime/unit_tests/platform/platform_tests_mt.cpp
Mateusz Jablonski 66754c4849 Remove platformDevices from runtime
Related-To: NEO-4207

Change-Id: I70781b44e7d14360a581808049baf8b61fd1b4e4
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
2020-02-05 09:59:13 +01:00

71 lines
1.6 KiB
C++

/*
* Copyright (C) 2017-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "core/unit_tests/helpers/default_hw_info.h"
#include "unit_tests/fixtures/platform_fixture.h"
#include "gtest/gtest.h"
using namespace NEO;
struct PlatformTestMt : public ::testing::Test {
void SetUp() override { pPlatform.reset(new Platform); }
static void initThreadFunc(Platform *pP) {
pP->initialize();
}
cl_int retVal = CL_SUCCESS;
std::unique_ptr<Platform> pPlatform;
};
static void callinitPlatform(Platform *plt, bool *ret) {
*ret = plt->initialize();
}
TEST_F(PlatformTestMt, initialize) {
std::thread threads[10];
bool ret[10];
for (int i = 0; i < 10; ++i) {
threads[i] = std::thread(callinitPlatform, pPlatform.get(), &ret[i]);
}
for (auto &th : threads)
th.join();
for (int i = 0; i < 10; ++i)
EXPECT_TRUE(ret[i]);
EXPECT_TRUE(pPlatform->isInitialized());
pPlatform.reset(new Platform());
for (int i = 0; i < 10; ++i) {
threads[i] = std::thread(callinitPlatform, pPlatform.get(), &ret[i]);
}
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);
std::thread t1(PlatformTestMt::initThreadFunc, pPlatform.get());
std::thread t2(PlatformTestMt::initThreadFunc, pPlatform.get());
t1.join();
t2.join();
devNum = pPlatform->getNumDevices();
EXPECT_EQ(numPlatformDevices, devNum);
}