Skip to content

Commit 10e7b9d

Browse files
Test prelim buffer object ext
Signed-off-by: Daniel Chabrowski [email protected] Related-To: NEO-6591
1 parent 3e8a668 commit 10e7b9d

File tree

6 files changed

+167
-1
lines changed

6 files changed

+167
-1
lines changed

opencl/test/unit_test/os_interface/linux/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ set(IGDRCL_SRCS_tests_os_interface_linux
3838
${CMAKE_CURRENT_SOURCE_DIR}/self_lib_lin.cpp
3939
)
4040

41+
if(NEO_ENABLE_i915_PRELIM_DETECTION)
42+
list(APPEND IGDRCL_SRCS_tests_os_interface_linux
43+
${CMAKE_CURRENT_SOURCE_DIR}/device_command_stream_fixture_context.cpp
44+
${CMAKE_CURRENT_SOURCE_DIR}/device_command_stream_fixture_context.h
45+
${CMAKE_CURRENT_SOURCE_DIR}/device_command_stream_fixture_prelim.h
46+
${CMAKE_CURRENT_SOURCE_DIR}/drm_buffer_object_tests_prelim.cpp
47+
)
48+
endif()
49+
4150
if(NEO__LIBVA_FOUND)
4251
list(APPEND IGDRCL_SRCS_tests_os_interface_linux
4352
${CMAKE_CURRENT_SOURCE_DIR}/drm_va_sharing_tests.cpp
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "opencl/test/unit_test/os_interface/linux/device_command_stream_fixture_context.h"
9+
10+
#include "third_party/uapi/prelim/drm/i915_drm.h"
11+
12+
int DrmMockCustomPrelimContext::ioctlExtra(unsigned long request, void *arg) {
13+
switch (request) {
14+
case PRELIM_DRM_IOCTL_I915_GEM_CREATE_EXT: {
15+
auto createExtParams = reinterpret_cast<prelim_drm_i915_gem_create_ext *>(arg);
16+
createExtSize = createExtParams->size;
17+
createExtHandle = createExtParams->handle;
18+
createExtExtensions = createExtParams->extensions;
19+
} break;
20+
case PRELIM_DRM_IOCTL_I915_GEM_VM_BIND: {
21+
} break;
22+
case PRELIM_DRM_IOCTL_I915_GEM_VM_UNBIND: {
23+
} break;
24+
case PRELIM_DRM_IOCTL_I915_GEM_WAIT_USER_FENCE: {
25+
const auto wait = reinterpret_cast<prelim_drm_i915_gem_wait_user_fence *>(arg);
26+
receivedGemWaitUserFence = WaitUserFence{
27+
wait->extensions,
28+
wait->addr,
29+
wait->ctx_id,
30+
wait->op,
31+
wait->flags,
32+
wait->value,
33+
wait->mask,
34+
wait->timeout,
35+
};
36+
gemWaitUserFenceCalled++;
37+
} break;
38+
default: {
39+
std::cout << std::hex << DRM_IOCTL_I915_GEM_WAIT << std::endl;
40+
std::cout << "unexpected IOCTL: " << std::hex << request << std::endl;
41+
UNRECOVERABLE_IF(true);
42+
} break;
43+
}
44+
return 0;
45+
}
46+
47+
void DrmMockCustomPrelimContext::execBufferExtensions(void *arg) {
48+
const auto execbuf = reinterpret_cast<drm_i915_gem_execbuffer2 *>(arg);
49+
if ((execbuf->flags | I915_EXEC_USE_EXTENSIONS) &&
50+
(execbuf->cliprects_ptr != 0)) {
51+
i915_user_extension *base = reinterpret_cast<i915_user_extension *>(execbuf->cliprects_ptr);
52+
if (base->name == PRELIM_DRM_I915_GEM_EXECBUFFER_EXT_USER_FENCE) {
53+
prelim_drm_i915_gem_execbuffer_ext_user_fence *userFenceExt =
54+
reinterpret_cast<prelim_drm_i915_gem_execbuffer_ext_user_fence *>(execbuf->cliprects_ptr);
55+
this->completionAddress = userFenceExt->addr;
56+
this->completionValue = userFenceExt->value;
57+
}
58+
}
59+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
10+
#include "shared/test/common/libult/linux/drm_mock_prelim_context.h"
11+
12+
struct DrmMockCustomPrelimContext {
13+
//PRELIM_DRM_IOCTL_I915_GEM_CREATE_EXT
14+
uint64_t createExtSize = 0;
15+
uint32_t createExtHandle = 0;
16+
uint64_t createExtExtensions = 0;
17+
18+
//PRELIM_DRM_IOCTL_I915_GEM_WAIT_USER_FENCE
19+
WaitUserFence receivedGemWaitUserFence{};
20+
uint32_t gemWaitUserFenceCalled = 0;
21+
22+
//PRELIM_DRM_I915_GEM_EXECBUFFER_EXT_USER_FENCE
23+
uint64_t completionAddress = 0;
24+
uint64_t completionValue = 0;
25+
26+
int ioctlExtra(unsigned long request, void *arg);
27+
void execBufferExtensions(void *arg);
28+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
10+
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
11+
12+
#include "opencl/test/unit_test/os_interface/linux/device_command_stream_fixture_context.h"
13+
14+
class DrmMockCustomPrelim : public DrmMockCustom {
15+
public:
16+
using Drm::cacheInfo;
17+
using Drm::ioctlHelper;
18+
using Drm::memoryInfo;
19+
20+
DrmMockCustomPrelim(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMockCustom(rootDeviceEnvironment) {
21+
setupIoctlHelper(IGFX_UNKNOWN);
22+
}
23+
24+
void getPrelimVersion(std::string &prelimVersion) override {
25+
prelimVersion = "2.0";
26+
}
27+
28+
int ioctlExtra(unsigned long request, void *arg) override {
29+
return context.ioctlExtra(request, arg);
30+
}
31+
32+
void execBufferExtensions(void *arg) override {
33+
return context.execBufferExtensions(arg);
34+
}
35+
36+
DrmMockCustomPrelimContext context{};
37+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/os_interface.h"
9+
#include "shared/test/common/libult/linux/drm_mock.h"
10+
#include "shared/test/common/os_interface/linux/drm_buffer_object_fixture.h"
11+
#include "shared/test/common/test_macros/test.h"
12+
13+
#include "opencl/test/unit_test/os_interface/linux/device_command_stream_fixture_prelim.h"
14+
15+
using namespace NEO;
16+
17+
using DrmBufferObjectPrelimFixture = DrmBufferObjectFixture<DrmMockCustomPrelim>;
18+
using DrmBufferObjectPrelimTest = Test<DrmBufferObjectPrelimFixture>;
19+
20+
TEST_F(DrmBufferObjectPrelimTest, GivenCompletionAddressWhenCallingExecThenReturnIsCorrect) {
21+
mock->ioctl_expected.total = 1;
22+
mock->ioctl_res = 0;
23+
24+
constexpr uint64_t completionAddress = 0x1230;
25+
constexpr uint32_t completionValue = 33;
26+
constexpr uint64_t expectedCompletionValue = completionValue;
27+
28+
drm_i915_gem_exec_object2 execObjectsStorage = {};
29+
auto ret = bo->exec(0, 0, 0, false, osContext.get(), 0, 1, nullptr, 0u, &execObjectsStorage, completionAddress, completionValue);
30+
EXPECT_EQ(0, ret);
31+
EXPECT_EQ(completionAddress, mock->context.completionAddress);
32+
EXPECT_EQ(expectedCompletionValue, mock->context.completionValue);
33+
}

shared/test/common/os_interface/linux/device_command_stream_fixture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class DrmMockCustom : public Drm {
151151
ioctl_res_ext = &NONE;
152152
}
153153

154-
virtual void execBufferExtensions(drm_i915_gem_execbuffer2 *execbuf) {
154+
virtual void execBufferExtensions(void *execbuf) {
155155
}
156156

157157
Ioctls ioctl_cnt;

0 commit comments

Comments
 (0)