Extract HwDeviceId from Drm

Related-To: NEO-4208
Change-Id: I1678ad92cab2a369769b93da69dc46a1d515f261
Signed-off-by: Jablonski, Mateusz <mateusz.jablonski@intel.com>
This commit is contained in:
Jablonski, Mateusz
2020-02-05 17:43:02 +01:00
committed by sys_ocldev
parent 8560b2b262
commit 018e585eb1
21 changed files with 142 additions and 25 deletions

View File

@@ -111,9 +111,10 @@ set(IGDRCL_SRCS_LIB_ULT_ENV_WINDOWS
)
set(IGDRCL_SRCS_LIB_ULT_ENV_LINUX
${NEO_SOURCE_DIR}/unit_tests/os_interface/linux/allocator_helper.cpp
${NEO_SOURCE_DIR}/unit_tests/os_interface/linux/create_drm_memory_manager.cpp
${NEO_SOURCE_DIR}/unit_tests/os_interface/linux/options.cpp
${NEO_SOURCE_DIR}/unit_tests/os_interface/linux/allocator_helper.cpp
${NEO_SOURCE_DIR}/unit_tests/os_interface/linux/sys_calls_linux_ult.cpp
)
if(WIN32)

View File

@@ -38,6 +38,7 @@ endif(NEO__LIBVA_FOUND)
foreach(target_name linux_tests linux_dll_tests)
add_executable(igdrcl_${target_name}
${NEO_SOURCE_DIR}/core/os_interface/linux/sys_calls_linux.cpp
${IGDRCL_SRCS_${target_name}}
$<TARGET_OBJECTS:igdrcl_libult>
$<TARGET_OBJECTS:igdrcl_libult_cs>

View File

@@ -24,7 +24,7 @@ using namespace std;
TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFromMultipleThreadsThenSingleBoIsReused) {
class MockDrm : public Drm {
public:
MockDrm(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(fd, rootDeviceEnvironment) {}
MockDrm(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(fd), rootDeviceEnvironment) {}
int ioctl(unsigned long request, void *arg) override {
if (request == DRM_IOCTL_PRIME_FD_TO_HANDLE) {
@@ -71,7 +71,7 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro
TEST(DrmMemoryManagerTest, givenMultipleThreadsWhenSharedAllocationIsCreatedThenPrimeFdToHandleDoesNotRaceWithClose) {
class MockDrm : public Drm {
public:
MockDrm(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(fd, rootDeviceEnvironment) {
MockDrm(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(fd), rootDeviceEnvironment) {
primeFdHandle = 1;
closeHandle = 1;
}

View File

@@ -27,27 +27,28 @@
using NEO::constructPlatform;
using NEO::Drm;
using NEO::HwDeviceId;
using NEO::RootDeviceEnvironment;
static const int mockFd = 33;
class DrmMockImpl : public Drm {
public:
DrmMockImpl(int fd) : Drm(fd, *constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]){};
DrmMockImpl(int fd) : Drm(std::make_unique<HwDeviceId>(fd), *constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]){};
MOCK_METHOD2(ioctl, int(unsigned long request, void *arg));
};
class DrmMockSuccess : public Drm {
public:
DrmMockSuccess() : DrmMockSuccess(*constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {}
DrmMockSuccess(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(mockFd, rootDeviceEnvironment) {}
DrmMockSuccess(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(mockFd), rootDeviceEnvironment) {}
int ioctl(unsigned long request, void *arg) override { return 0; };
};
class DrmMockFail : public Drm {
public:
DrmMockFail() : Drm(mockFd, *constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {}
DrmMockFail() : Drm(std::make_unique<HwDeviceId>(mockFd), *constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {}
int ioctl(unsigned long request, void *arg) override { return -1; };
};
@@ -327,7 +328,7 @@ class DrmMockCustom : public Drm {
ioctl_res_ext = &NONE;
}
DrmMockCustom() : Drm(mockFd, *constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {
DrmMockCustom() : Drm(std::make_unique<HwDeviceId>(mockFd), *constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {
reset();
ioctl_expected.contextCreate = static_cast<int>(NEO::HwHelper::get(NEO::platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances().size());
ioctl_expected.contextDestroy = ioctl_expected.contextCreate.load();

View File

@@ -73,7 +73,6 @@ TEST_F(DeviceFactoryLinuxTest, ReleaseDevices) {
mockDeviceFactory.releaseDevices();
EXPECT_TRUE(mockDeviceFactory.getNumDevices() == 0);
EXPECT_TRUE(pDrm->getFileDescriptor() == -1);
}
TEST_F(DeviceFactoryLinuxTest, givenGetDeviceCallWhenItIsDoneThenOsInterfaceIsAllocatedAndItContainDrm) {
@@ -82,5 +81,6 @@ TEST_F(DeviceFactoryLinuxTest, givenGetDeviceCallWhenItIsDoneThenOsInterfaceIsAl
bool success = mockDeviceFactory.getDevices(numDevices, executionEnvironment);
EXPECT_TRUE(success);
EXPECT_NE(nullptr, executionEnvironment.rootDeviceEnvironments[0]->osInterface);
EXPECT_NE(nullptr, pDrm);
EXPECT_EQ(pDrm, executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->getDrm());
}

View File

@@ -36,7 +36,7 @@ class DrmMockForWorker : public Drm {
std::atomic<int> gem_close_cnt;
std::atomic<int> gem_close_expected;
std::atomic<std::thread::id> ioctl_caller_thread_id;
DrmMockForWorker() : Drm(33, *platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {
DrmMockForWorker() : Drm(std::make_unique<HwDeviceId>(33), *platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {
}
int ioctl(unsigned long request, void *arg) override {
if (_IOC_TYPE(request) == DRM_IOCTL_BASE) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 Intel Corporation
* Copyright (C) 2019-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -7,6 +7,8 @@
#include "unit_tests/os_interface/linux/drm_mock.h"
const int DrmMock::mockFd;
int DrmMock::ioctl(unsigned long request, void *arg) {
ioctlCallsCount++;

View File

@@ -32,7 +32,7 @@ class DrmMock : public Drm {
using Drm::query;
using Drm::sliceCountChangeSupported;
DrmMock(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(mockFd, rootDeviceEnvironment) {
DrmMock(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(mockFd), rootDeviceEnvironment) {
sliceCountChangeSupported = true;
}
DrmMock() : DrmMock(*platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {}
@@ -69,7 +69,7 @@ class DrmMock : public Drm {
}
void setFileDescriptor(int fd) {
this->fd = fd;
hwDeviceId = std::make_unique<HwDeviceId>(fd);
}
void setDeviceID(int deviceId) { this->deviceId = deviceId; }

View File

@@ -45,7 +45,7 @@ void pushDrmMock(Drm *mock) { drmMockStack.push_back(mock); }
void popDrmMock() { drmMockStack.pop_back(); }
Drm::~Drm() { fd = -1; }
Drm::~Drm() = default;
Drm *Drm::get(int32_t deviceOrdinal) {
// We silently skip deviceOrdinal
@@ -61,5 +61,5 @@ Drm *Drm::create(int32_t deviceOrdinal, RootDeviceEnvironment &rootDeviceEnviron
return drmMockStack[drmMockStack.size() - 1];
}
void Drm::closeDevice(int32_t deviceOrdinal) { drmMockStack[drmMockStack.size() - 1]->fd = -1; }
void Drm::closeDevice(int32_t deviceOrdinal) {}
} // namespace NEO

View File

@@ -388,3 +388,19 @@ TEST(DrmTest, givenPlatformWithSupportToChangeSliceCountWhenCallSetQueueSliceCou
EXPECT_EQ(0, drm->getQueueSliceCount(&sseu));
EXPECT_EQ(drm->getSliceMask(newSliceCount), sseu.slice_mask);
}
namespace NEO {
namespace SysCalls {
extern uint32_t closeFuncCalled;
extern int closeFuncArgPassed;
} // namespace SysCalls
} // namespace NEO
TEST(HwDeviceId, whenHwDeviceIdIsDestroyedThenFileDescriptorIsClosed) {
SysCalls::closeFuncCalled = 0;
int fileDescriptor = 0x1234;
{
HwDeviceId hwDeviceId(fileDescriptor);
}
EXPECT_EQ(1u, SysCalls::closeFuncCalled);
EXPECT_EQ(fileDescriptor, SysCalls::closeFuncArgPassed);
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "core/os_interface/linux/sys_calls.h"
#include <cstdint>
namespace NEO {
namespace SysCalls {
uint32_t closeFuncCalled = 0u;
int closeFuncArgPassed = 0;
int close(int fileDescriptor) {
closeFuncCalled++;
closeFuncArgPassed = fileDescriptor;
return 0;
}
} // namespace SysCalls
} // namespace NEO