2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2022-02-01 14:49:57 +00:00
|
|
|
* Copyright (C) 2018-2022 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
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
2022-02-01 14:49:57 +00:00
|
|
|
#include "shared/source/helpers/register_offsets.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/linux/drm_null_device.h"
|
2021-01-21 13:10:13 +01:00
|
|
|
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
2021-12-14 17:40:08 +00:00
|
|
|
#include "shared/test/common/test_macros/test.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2020-02-23 15:20:22 +01:00
|
|
|
#include "opencl/test/unit_test/linux/drm_wrap.h"
|
|
|
|
|
#include "opencl/test/unit_test/linux/mock_os_layer.h"
|
2020-02-22 22:50:57 +01:00
|
|
|
|
2019-03-28 12:53:48 +01:00
|
|
|
#include <memory>
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
using namespace NEO;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2021-07-20 10:13:23 +00:00
|
|
|
extern const DeviceDescriptor NEO::deviceDescriptorTable[];
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
class DrmNullDeviceTestsFixture {
|
|
|
|
|
public:
|
2022-05-09 17:40:30 +00:00
|
|
|
void SetUp() { // NOLINT(readability-identifier-naming)
|
2021-07-20 10:13:23 +00:00
|
|
|
if (deviceDescriptorTable[0].deviceId == 0) {
|
|
|
|
|
GTEST_SKIP();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
// Create nullDevice drm
|
|
|
|
|
DebugManager.flags.EnableNullHardware.set(true);
|
2020-01-29 19:10:49 +01:00
|
|
|
executionEnvironment.prepareRootDeviceEnvironments(1);
|
|
|
|
|
|
2020-02-11 17:48:40 +01:00
|
|
|
drmNullDevice = DrmWrap::createDrm(*executionEnvironment.rootDeviceEnvironments[0]);
|
2017-12-21 00:45:38 +01:00
|
|
|
ASSERT_NE(drmNullDevice, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-09 17:40:30 +00:00
|
|
|
void TearDown() { // NOLINT(readability-identifier-naming)
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-20 23:01:05 +02:00
|
|
|
std::unique_ptr<Drm> drmNullDevice;
|
2020-01-29 19:10:49 +01:00
|
|
|
ExecutionEnvironment executionEnvironment;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
protected:
|
2019-03-28 12:53:48 +01:00
|
|
|
DebugManagerStateRestore dbgRestorer;
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef Test<DrmNullDeviceTestsFixture> DrmNullDeviceTests;
|
|
|
|
|
|
|
|
|
|
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENcallGetDeviceIdTHENreturnProperDeviceId) {
|
2019-03-27 12:44:49 +01:00
|
|
|
int deviceIdQueried = 0;
|
|
|
|
|
int ret = drmNullDevice->getDeviceID(deviceIdQueried);
|
2017-12-21 00:45:38 +01:00
|
|
|
EXPECT_EQ(0, ret);
|
2019-03-27 12:44:49 +01:00
|
|
|
EXPECT_EQ(deviceId, deviceIdQueried);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENcallIoctlTHENalwaysSuccess) {
|
|
|
|
|
EXPECT_EQ(drmNullDevice->ioctl(0, nullptr), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENregReadOtherThenTimestampReadTHENalwaysSuccess) {
|
2022-05-12 13:46:22 +00:00
|
|
|
RegisterRead arg;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
arg.offset = 0;
|
|
|
|
|
ASSERT_EQ(drmNullDevice->ioctl(DRM_IOCTL_I915_REG_READ, &arg), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENgetGpuTimestamp32bOr64bTHENerror) {
|
2022-05-12 13:46:22 +00:00
|
|
|
RegisterRead arg;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2022-02-01 14:49:57 +00:00
|
|
|
arg.offset = REG_GLOBAL_TIMESTAMP_LDW;
|
2017-12-21 00:45:38 +01:00
|
|
|
ASSERT_EQ(drmNullDevice->ioctl(DRM_IOCTL_I915_REG_READ, &arg), -1);
|
|
|
|
|
|
2022-02-01 14:49:57 +00:00
|
|
|
arg.offset = REG_GLOBAL_TIMESTAMP_UN;
|
2017-12-21 00:45:38 +01:00
|
|
|
ASSERT_EQ(drmNullDevice->ioctl(DRM_IOCTL_I915_REG_READ, &arg), -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DrmNullDeviceTests, GIVENdrmNullDeviceWHENgetGpuTimestamp36bTHENproperValues) {
|
2022-05-12 13:46:22 +00:00
|
|
|
RegisterRead arg;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2022-02-01 14:49:57 +00:00
|
|
|
arg.offset = REG_GLOBAL_TIMESTAMP_LDW | 1;
|
2017-12-21 00:45:38 +01:00
|
|
|
ASSERT_EQ(drmNullDevice->ioctl(DRM_IOCTL_I915_REG_READ, &arg), 0);
|
2022-05-12 13:46:22 +00:00
|
|
|
EXPECT_EQ(arg.value, 1000ULL);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
ASSERT_EQ(drmNullDevice->ioctl(DRM_IOCTL_I915_REG_READ, &arg), 0);
|
2022-05-12 13:46:22 +00:00
|
|
|
EXPECT_EQ(arg.value, 2000ULL);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
ASSERT_EQ(drmNullDevice->ioctl(DRM_IOCTL_I915_REG_READ, &arg), 0);
|
2022-05-12 13:46:22 +00:00
|
|
|
EXPECT_EQ(arg.value, 3000ULL);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|