Debian Codegraph @

opencl/test/unit_test/sharings/gl/linux/gl_sharing_tests.cpp

raw
1 /*
2 * Copyright (C) 2018-2023 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "shared/source/device/device.h"
9 #include "shared/source/gmm_helper/gmm.h"
10 #include "shared/source/helpers/array_count.h"
11 #include "shared/source/os_interface/os_interface.h"
12 #include "shared/test/common/helpers/debug_manager_state_restore.h"
13 #include "shared/test/common/libult/ult_command_stream_receiver.h"
14 #include "shared/test/common/mocks/mock_device.h"
15 #include "shared/test/common/mocks/mock_gmm.h"
16 #include "shared/test/common/mocks/mock_gmm_resource_info.h"
17 #include "shared/test/common/mocks/mock_memory_manager.h"
18 #include "shared/test/common/test_macros/test.h"
19
20 #include "opencl/source/command_queue/command_queue.h"
21 #include "opencl/source/event/user_event.h"
22 #include "opencl/source/mem_obj/buffer.h"
23 #include "opencl/source/mem_obj/image.h"
24 #include "opencl/source/sharings/gl/cl_gl_api_intel.h"
25 #include "opencl/source/sharings/gl/gl_arb_sync_event.h"
26 #include "opencl/source/sharings/gl/gl_buffer.h"
27 #include "opencl/source/sharings/gl/gl_context_guard.h"
28 #include "opencl/source/sharings/gl/gl_sync_event.h"
29 #include "opencl/source/sharings/gl/gl_texture.h"
30 #include "opencl/source/sharings/gl/linux/gl_sharing_linux.h"
31 #include "opencl/source/sharings/gl/linux/include/gl_types.h"
32 #include "opencl/source/sharings/sharing.h"
33 #include "opencl/test/unit_test/mocks/gl/linux/mock_gl_arb_sync_event_linux.h"
34 #include "opencl/test/unit_test/mocks/gl/linux/mock_gl_sharing_linux.h"
35 #include "opencl/test/unit_test/mocks/mock_async_event_handler.h"
36 #include "opencl/test/unit_test/mocks/mock_cl_device.h"
37 #include "opencl/test/unit_test/mocks/mock_command_queue.h"
38 #include "opencl/test/unit_test/mocks/mock_context.h"
39 #include "opencl/test/unit_test/mocks/mock_event.h"
40
41 using namespace NEO;
42
43 class GlSharingTests : public ::testing::Test {
44 public:
45 void SetUp() override {
46 rootDeviceIndex = context.getDevice(0)->getRootDeviceIndex();
47 mockGlSharingFunctions = mockGlSharing->sharingFunctions.release();
48 context.setSharingFunctions(mockGlSharingFunctions);
49
50 mockGlSharing->bufferInfoOutput.globalShareHandle = bufferId;
51 mockGlSharing->bufferInfoOutput.bufferSize = 4096u;
52 mockGlSharing->uploadDataToBufferInfo();
53 }
54
55 uint32_t rootDeviceIndex;
56 MockContext context;
57 std::unique_ptr<MockGlSharing> mockGlSharing = std::make_unique<MockGlSharing>();
58 GlSharingFunctionsMock *mockGlSharingFunctions;
59 unsigned int bufferId = 1u;
60 };
61
62 TEST(APIclCreateEventFromGLsyncKHR, givenInvalidContexWhenCreateThenReturnError) {
63 cl_int retVal = CL_SUCCESS;
64 cl_GLsync sync = {0};
65
66 auto event = clCreateEventFromGLsyncKHR(nullptr, sync, &retVal);
67 EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
68 EXPECT_EQ(nullptr, event);
69 }
70
71 using clGetSupportedGLTextureFormatsINTELTests = GlSharingTests;
72
73 TEST_F(clGetSupportedGLTextureFormatsINTELTests, givenContextWithoutGlSharingWhenGettingFormatsThenInvalidContextErrorIsReturned) {
74 MockContext context;
75
76 auto retVal = clGetSupportedGLTextureFormatsINTEL(&context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 0, nullptr, nullptr);
77 EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
78 }
79
80 TEST_F(clGetSupportedGLTextureFormatsINTELTests, givenValidInputsWhenGettingFormatsThenSuccesAndValidFormatsAreReturned) {
81 cl_uint numFormats = 0;
82 cl_GLenum glFormats[2] = {};
83 auto glFormatsCount = static_cast<cl_uint>(arrayCount(glFormats));
84
85 auto retVal = clGetSupportedGLTextureFormatsINTEL(&context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D,
86 glFormatsCount, glFormats, &numFormats);
87 EXPECT_EQ(CL_SUCCESS, retVal);
88
89 EXPECT_NE(0u, numFormats);
90
91 for (uint32_t i = 0; i < glFormatsCount; i++) {
92 EXPECT_NE(GlSharing::glToCLFormats.end(), GlSharing::glToCLFormats.find(glFormats[i]));
93 }
94 }