mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-20 13:11:34 +08:00
Initial commit
Change-Id: I4bf1707bd3dfeadf2c17b0a7daff372b1925ebbd
This commit is contained in:
34
unit_tests/linux/CMakeLists.txt
Normal file
34
unit_tests/linux/CMakeLists.txt
Normal file
@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2017, Intel Corporation
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the "Software"),
|
||||
# to deal in the Software without restriction, including without limitation
|
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
# and/or sell copies of the Software, and to permit persons to whom the
|
||||
# Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included
|
||||
# in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
# OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)
|
||||
|
||||
project(igdrcl_linux_dll_tests)
|
||||
|
||||
if(UNIX)
|
||||
set(IGDRCL_SRCS_linux_dll_tests
|
||||
"${IGDRCL_SRCS_linux_dll_tests}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/main_linux_dll.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/drm_null_device_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/mock_os_layer.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/mock_os_layer.h"
|
||||
"${IGDRCL_SOURCE_DIR}/runtime/os_interface/debug_settings_manager.cpp"
|
||||
PARENT_SCOPE)
|
||||
endif()
|
119
unit_tests/linux/drm_null_device_tests.cpp
Normal file
119
unit_tests/linux/drm_null_device_tests.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "mock_os_layer.h"
|
||||
#include "runtime/os_interface/linux/drm_null_device.h"
|
||||
#include "test.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
class DrmWrap : public Drm {
|
||||
public:
|
||||
static Drm *createDrm(int32_t deviceOrdinal) {
|
||||
return Drm::create(deviceOrdinal);
|
||||
}
|
||||
|
||||
static void closeDevice(int32_t deviceOrdinal) {
|
||||
Drm::closeDevice(deviceOrdinal);
|
||||
};
|
||||
};
|
||||
|
||||
class DrmNullDeviceTestsFixture {
|
||||
public:
|
||||
void SetUp() {
|
||||
oldFlag = DebugManager.flags.EnableNullHardware.get();
|
||||
|
||||
// Make global staff into init state
|
||||
DrmWrap::closeDevice(0);
|
||||
resetOSMockGlobalState();
|
||||
|
||||
// Create nullDevice drm
|
||||
DebugManager.flags.EnableNullHardware.set(true);
|
||||
DrmWrap::createDrm(0);
|
||||
|
||||
// Obtain nullDevice drm
|
||||
drmNullDevice = DrmWrap::get(0);
|
||||
ASSERT_NE(drmNullDevice, nullptr);
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
// Close drm
|
||||
DrmWrap::closeDevice(0);
|
||||
DebugManager.flags.EnableNullHardware.set(oldFlag);
|
||||
}
|
||||
|
||||
Drm *drmNullDevice;
|
||||
|
||||
protected:
|
||||
bool oldFlag;
|
||||
};
|
||||
|
||||
typedef Test<DrmNullDeviceTestsFixture> DrmNullDeviceTests;
|
||||
|
||||
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENcallGetDeviceIdTHENreturnProperDeviceId) {
|
||||
int deviceId = 0;
|
||||
int ret = drmNullDevice->getDeviceID(deviceId);
|
||||
EXPECT_EQ(0, ret);
|
||||
EXPECT_EQ(0x1916, deviceId);
|
||||
}
|
||||
|
||||
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENpeekAndObtainCoherencyDisablePatchActiveTHENreturnNullDeviceValues) {
|
||||
EXPECT_EQ(drmNullDevice->peekCoherencyDisablePatchActive(), false);
|
||||
|
||||
drmNullDevice->obtainCoherencyDisablePatchActive();
|
||||
EXPECT_EQ(drmNullDevice->peekCoherencyDisablePatchActive(), true);
|
||||
}
|
||||
|
||||
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENcallIoctlTHENalwaysSuccess) {
|
||||
EXPECT_EQ(drmNullDevice->ioctl(0, nullptr), 0);
|
||||
}
|
||||
|
||||
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENregReadOtherThenTimestampReadTHENalwaysSuccess) {
|
||||
struct drm_i915_reg_read arg;
|
||||
|
||||
arg.offset = 0;
|
||||
ASSERT_EQ(drmNullDevice->ioctl(DRM_IOCTL_I915_REG_READ, &arg), 0);
|
||||
}
|
||||
|
||||
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENgetGpuTimestamp32bOr64bTHENerror) {
|
||||
struct drm_i915_reg_read arg;
|
||||
|
||||
arg.offset = TIMESTAMP_LOW_REG;
|
||||
ASSERT_EQ(drmNullDevice->ioctl(DRM_IOCTL_I915_REG_READ, &arg), -1);
|
||||
|
||||
arg.offset = TIMESTAMP_HIGH_REG;
|
||||
ASSERT_EQ(drmNullDevice->ioctl(DRM_IOCTL_I915_REG_READ, &arg), -1);
|
||||
}
|
||||
|
||||
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENgetGpuTimestamp36bTHENproperValues) {
|
||||
struct drm_i915_reg_read arg;
|
||||
|
||||
arg.offset = TIMESTAMP_LOW_REG | 1;
|
||||
ASSERT_EQ(drmNullDevice->ioctl(DRM_IOCTL_I915_REG_READ, &arg), 0);
|
||||
EXPECT_EQ(arg.val, 1000ULL);
|
||||
|
||||
ASSERT_EQ(drmNullDevice->ioctl(DRM_IOCTL_I915_REG_READ, &arg), 0);
|
||||
EXPECT_EQ(arg.val, 2000ULL);
|
||||
|
||||
ASSERT_EQ(drmNullDevice->ioctl(DRM_IOCTL_I915_REG_READ, &arg), 0);
|
||||
EXPECT_EQ(arg.val, 3000ULL);
|
||||
}
|
291
unit_tests/linux/main_linux_dll.cpp
Normal file
291
unit_tests/linux/main_linux_dll.cpp
Normal file
@ -0,0 +1,291 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "mock_os_layer.h"
|
||||
#include "unit_tests/custom_event_listener.h"
|
||||
#include "test.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
class DrmWrap : public Drm {
|
||||
public:
|
||||
static Drm *createDrm(int32_t deviceOrdinal) {
|
||||
return Drm::create(deviceOrdinal);
|
||||
}
|
||||
static void closeDevice(int32_t deviceOrdinal) {
|
||||
Drm::closeDevice(deviceOrdinal);
|
||||
};
|
||||
};
|
||||
|
||||
class DrmTestsFixture {
|
||||
public:
|
||||
void SetUp() {
|
||||
//make static things into initial state
|
||||
DrmWrap::closeDevice(0);
|
||||
resetOSMockGlobalState();
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
}
|
||||
};
|
||||
|
||||
typedef Test<DrmTestsFixture> DrmTests;
|
||||
|
||||
TEST_F(DrmTests, getReturnsNull) {
|
||||
auto ptr = Drm::get(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, getNoOverrun) {
|
||||
//negative device ordinal
|
||||
auto ptr = Drm::get(-1);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
|
||||
//some high value
|
||||
ptr = Drm::get(1 << (sizeof(int32_t) * 8 - 2));
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, closeNotOpened) {
|
||||
auto ptr = DrmWrap::get(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
|
||||
DrmWrap::closeDevice(0);
|
||||
|
||||
DrmWrap::get(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, openClose) {
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_NE(ptr, nullptr);
|
||||
|
||||
DrmWrap::closeDevice(0);
|
||||
|
||||
ptr = DrmWrap::get(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, closeNoOverrun) {
|
||||
//negative device ordinal
|
||||
DrmWrap::closeDevice(-1);
|
||||
|
||||
//some high value
|
||||
DrmWrap::closeDevice(1 << (sizeof(int32_t) * 8 - 2));
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, createReturnsDrm) {
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_NE(ptr, nullptr);
|
||||
|
||||
drm_i915_getparam_t getParam;
|
||||
int lDeviceId;
|
||||
|
||||
ioctlCnt = 0;
|
||||
ioctlSeq[0] = -1;
|
||||
errno = EINTR;
|
||||
// check if device works, although there was EINTR error from KMD
|
||||
getParam.param = I915_PARAM_CHIPSET_ID;
|
||||
getParam.value = &lDeviceId;
|
||||
auto ret = ptr->ioctl(DRM_IOCTL_I915_GETPARAM, &getParam);
|
||||
EXPECT_EQ(0, ret);
|
||||
EXPECT_EQ(deviceId, lDeviceId);
|
||||
|
||||
ioctlCnt = 0;
|
||||
ioctlSeq[0] = -1;
|
||||
errno = EAGAIN;
|
||||
// check if device works, although there was EAGAIN error from KMD
|
||||
getParam.param = I915_PARAM_CHIPSET_ID;
|
||||
getParam.value = &lDeviceId;
|
||||
ret = ptr->ioctl(DRM_IOCTL_I915_GETPARAM, &getParam);
|
||||
EXPECT_EQ(0, ret);
|
||||
EXPECT_EQ(deviceId, lDeviceId);
|
||||
|
||||
ioctlCnt = 0;
|
||||
ioctlSeq[0] = -1;
|
||||
errno = 0;
|
||||
// we failed with any other error code
|
||||
getParam.param = I915_PARAM_CHIPSET_ID;
|
||||
getParam.value = &lDeviceId;
|
||||
ret = ptr->ioctl(DRM_IOCTL_I915_GETPARAM, &getParam);
|
||||
EXPECT_EQ(-1, ret);
|
||||
EXPECT_EQ(deviceId, lDeviceId);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, createTwiceReturnsSameDrm) {
|
||||
auto ptr1 = DrmWrap::createDrm(0);
|
||||
EXPECT_NE(ptr1, nullptr);
|
||||
auto ptr2 = DrmWrap::createDrm(0);
|
||||
EXPECT_NE(ptr2, nullptr);
|
||||
EXPECT_EQ(ptr1, ptr2);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, createDriFallback) {
|
||||
haveDri = 1;
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_NE(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, createNoDevice) {
|
||||
haveDri = -1;
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, createNoOverrun) {
|
||||
auto ptr = DrmWrap::createDrm(-1);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
|
||||
ptr = DrmWrap::createDrm(1 << (sizeof(int32_t) * 8 - 2));
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, createUnknownDevice) {
|
||||
deviceId = -1;
|
||||
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, createNoSoftPin) {
|
||||
haveSoftPin = 0;
|
||||
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, failOnDeviceId) {
|
||||
failOnDeviceId = -1;
|
||||
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, failOnRevisionId) {
|
||||
failOnRevisionId = -1;
|
||||
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, failOnSoftPin) {
|
||||
failOnSoftPin = -1;
|
||||
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, failOnParamBoost) {
|
||||
failOnParamBoost = -1;
|
||||
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
//non-fatal error - issue warning only
|
||||
EXPECT_NE(ptr, nullptr);
|
||||
}
|
||||
|
||||
#if defined(I915_PARAM_HAS_PREEMPTION)
|
||||
TEST_F(DrmTests, checkPreemption) {
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_NE(ptr, nullptr);
|
||||
bool ret = ptr->hasPreemption();
|
||||
EXPECT_EQ(ret, true);
|
||||
DrmWrap::closeDevice(0);
|
||||
|
||||
ptr = DrmWrap::get(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(DrmTests, failOnContextCreate) {
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_NE(ptr, nullptr);
|
||||
failOnContextCreate = -1;
|
||||
bool ret = ptr->hasPreemption();
|
||||
EXPECT_EQ(ret, false);
|
||||
failOnContextCreate = 0;
|
||||
DrmWrap::closeDevice(0);
|
||||
|
||||
ptr = DrmWrap::get(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, failOnSetPriority) {
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_NE(ptr, nullptr);
|
||||
failOnSetPriority = -1;
|
||||
bool ret = ptr->hasPreemption();
|
||||
EXPECT_EQ(ret, false);
|
||||
failOnSetPriority = 0;
|
||||
DrmWrap::closeDevice(0);
|
||||
|
||||
ptr = DrmWrap::get(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, failOnDrmGetVersion) {
|
||||
failOnDrmVersion = -1;
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
failOnDrmVersion = 0;
|
||||
DrmWrap::closeDevice(0);
|
||||
|
||||
ptr = DrmWrap::get(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, failOnInvalidDeviceName) {
|
||||
strcpy(providedDrmVersion, "NA");
|
||||
auto ptr = DrmWrap::createDrm(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
failOnDrmVersion = 0;
|
||||
strcpy(providedDrmVersion, "i915");
|
||||
DrmWrap::closeDevice(0);
|
||||
|
||||
ptr = DrmWrap::get(0);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
bool useDefaultListener = true;
|
||||
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
// parse remaining args assuming they're mine
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (!strcmp("--disable_default_listener", argv[i])) {
|
||||
useDefaultListener = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (useDefaultListener == false) {
|
||||
auto &listeners = ::testing::UnitTest::GetInstance()->listeners();
|
||||
auto defaultListener = listeners.default_result_printer();
|
||||
auto customEventListener = new CCustomEventListener(defaultListener);
|
||||
|
||||
listeners.Release(defaultListener);
|
||||
listeners.Append(customEventListener);
|
||||
}
|
||||
|
||||
auto retVal = RUN_ALL_TESTS();
|
||||
|
||||
return retVal;
|
||||
}
|
171
unit_tests/linux/mock_os_layer.cpp
Normal file
171
unit_tests/linux/mock_os_layer.cpp
Normal file
@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "mock_os_layer.h"
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
const char *devDri[2] = {"/dev/dri/renderD128", "/dev/dri/card0"};
|
||||
|
||||
int (*c_open)(const char *pathname, int flags, ...) = nullptr;
|
||||
int (*c_ioctl)(int fd, unsigned long int request, ...) = nullptr;
|
||||
|
||||
int fakeFd = 1023;
|
||||
int haveDri = 0; // index of dri to serve, -1 - none
|
||||
int deviceId = 0x1916; // known DeviceID
|
||||
int haveSoftPin = 1;
|
||||
int havePreemption = 1;
|
||||
int failOnDeviceId = 0;
|
||||
int failOnRevisionId = 0;
|
||||
int failOnSoftPin = 0;
|
||||
int failOnParamBoost = 0;
|
||||
int failOnContextCreate = 0;
|
||||
int failOnSetPriority = 0;
|
||||
int failOnPreemption = 0;
|
||||
int failOnDrmVersion = 0;
|
||||
char providedDrmVersion[5] = {'i', '9', '1', '5', '\0'};
|
||||
uint64_t gpuTimestamp = 0;
|
||||
int ioctlSeq[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
size_t ioctlCnt = 0;
|
||||
|
||||
int open(const char *pathname, int flags, ...) {
|
||||
if (c_open == nullptr) {
|
||||
c_open = (int (*)(const char *, int, ...))dlsym(RTLD_NEXT, "open");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (strcmp(devDri[i], pathname) == 0) {
|
||||
if (i == haveDri) {
|
||||
return fakeFd;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return c_open(pathname, flags);
|
||||
}
|
||||
|
||||
int drmGetParam(drm_i915_getparam_t *param) {
|
||||
assert(param);
|
||||
int ret = 0;
|
||||
|
||||
switch (param->param) {
|
||||
case I915_PARAM_CHIPSET_ID:
|
||||
*param->value = deviceId;
|
||||
ret = failOnDeviceId;
|
||||
break;
|
||||
case I915_PARAM_REVISION:
|
||||
*param->value = 0x0;
|
||||
ret = failOnRevisionId;
|
||||
break;
|
||||
case I915_PARAM_HAS_EXEC_SOFTPIN:
|
||||
*param->value = haveSoftPin;
|
||||
ret = failOnSoftPin;
|
||||
break;
|
||||
#if defined(I915_PARAM_HAS_PREEMPTION)
|
||||
case I915_PARAM_HAS_PREEMPTION:
|
||||
*param->value = havePreemption;
|
||||
ret = failOnPreemption;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ret = -1;
|
||||
std::cerr << "drm.getParam: " << std::dec << param->param << std::endl;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int drmSetContextParam(drm_i915_gem_context_param *param) {
|
||||
assert(param);
|
||||
int ret = 0;
|
||||
|
||||
switch (param->param) {
|
||||
case I915_CONTEXT_PRIVATE_PARAM_BOOST:
|
||||
ret = failOnParamBoost;
|
||||
break;
|
||||
#if defined(I915_PARAM_HAS_PREEMPTION)
|
||||
case I915_CONTEXT_PARAM_PRIORITY:
|
||||
ret = failOnSetPriority;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ret = -1;
|
||||
std::cerr << "drm.setContextParam: " << std::dec << param->param << std::endl;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int drmContextCreate(drm_i915_gem_context_create *create) {
|
||||
assert(create);
|
||||
|
||||
create->ctx_id = 1;
|
||||
return failOnContextCreate;
|
||||
}
|
||||
|
||||
int drmContextDestroy(drm_i915_gem_context_destroy *destroy) {
|
||||
assert(destroy);
|
||||
|
||||
if (destroy->ctx_id == 1)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
int drmVersion(drm_version_t *version) {
|
||||
strcpy(version->name, providedDrmVersion);
|
||||
|
||||
return failOnDrmVersion;
|
||||
}
|
||||
|
||||
int ioctl(int fd, unsigned long int request, ...) throw() {
|
||||
if (c_ioctl == nullptr)
|
||||
c_ioctl = (int (*)(int, unsigned long int, ...))dlsym(RTLD_NEXT, "ioctl");
|
||||
|
||||
va_list vl;
|
||||
va_start(vl, request);
|
||||
|
||||
if (fd == fakeFd) {
|
||||
auto res = ioctlSeq[ioctlCnt % (sizeof(ioctlSeq) / sizeof(int))];
|
||||
ioctlCnt++;
|
||||
|
||||
if (res == 0) {
|
||||
switch (request) {
|
||||
case DRM_IOCTL_I915_GETPARAM:
|
||||
return drmGetParam(va_arg(vl, drm_i915_getparam_t *));
|
||||
case DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM:
|
||||
return drmSetContextParam(va_arg(vl, drm_i915_gem_context_param *));
|
||||
case DRM_IOCTL_I915_GEM_CONTEXT_CREATE:
|
||||
return drmContextCreate(va_arg(vl, drm_i915_gem_context_create *));
|
||||
case DRM_IOCTL_I915_GEM_CONTEXT_DESTROY:
|
||||
return drmContextDestroy(va_arg(vl, drm_i915_gem_context_destroy *));
|
||||
case DRM_IOCTL_VERSION:
|
||||
return drmVersion(va_arg(vl, drm_version_t *));
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return c_ioctl(fd, request, vl);
|
||||
}
|
74
unit_tests/linux/mock_os_layer.h
Normal file
74
unit_tests/linux/mock_os_layer.h
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "runtime/os_interface/linux/drm_neo.h"
|
||||
#include "drm/i915_drm.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <array>
|
||||
|
||||
extern const char *devDri[2];
|
||||
|
||||
extern "C" {
|
||||
int open(const char *pathname, int flags, ...);
|
||||
int ioctl(int fd, unsigned long int request, ...) throw();
|
||||
}
|
||||
|
||||
extern int (*c_open)(const char *pathname, int flags, ...);
|
||||
extern int (*c_ioctl)(int __fd, unsigned long int __request, ...);
|
||||
|
||||
extern int fakeFd;
|
||||
extern int haveDri; // index of dri to serve, -1 - none
|
||||
extern int deviceId; // known DeviceID
|
||||
extern int haveSoftPin;
|
||||
extern int failOnDeviceId;
|
||||
extern int failOnRevisionId;
|
||||
extern int failOnSoftPin;
|
||||
extern int failOnParamBoost;
|
||||
extern int failOnContextCreate;
|
||||
extern int failOnSetPriority;
|
||||
extern int failOnDrmVersion;
|
||||
extern char providedDrmVersion[5];
|
||||
extern int ioctlSeq[8];
|
||||
extern size_t ioctlCnt;
|
||||
|
||||
extern std::array<OCLRT::Drm *, 1> drms;
|
||||
|
||||
inline void resetOSMockGlobalState() {
|
||||
fakeFd = 1023;
|
||||
haveDri = 0;
|
||||
deviceId = 0x1916;
|
||||
haveSoftPin = 1;
|
||||
failOnDeviceId = 0;
|
||||
failOnRevisionId = 0;
|
||||
failOnSoftPin = 0;
|
||||
failOnParamBoost = 0;
|
||||
std::memset(ioctlSeq, 0, sizeof(ioctlSeq));
|
||||
ioctlCnt = 0;
|
||||
}
|
Reference in New Issue
Block a user