| 1 | /* |
| 2 | * Copyright (C) 2018-2023 Intel Corporation |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include "shared/test/common/helpers/debug_manager_state_restore.h" |
| 9 | |
| 10 | #include "opencl/source/sharings/va/va_sharing.h" |
| 11 | #include "opencl/test/unit_test/fixtures/platform_fixture.h" |
| 12 | #include "opencl/test/unit_test/mocks/mock_context.h" |
| 13 | #include "opencl/test/unit_test/mocks/mock_platform.h" |
| 14 | |
| 15 | #include "gtest/gtest.h" |
| 16 | |
| 17 | using namespace NEO; |
| 18 | |
| 19 | struct VAContextTest : public PlatformFixture, |
| 20 | public ::testing::Test { |
| 21 | |
| 22 | using PlatformFixture::setUp; |
| 23 | |
| 24 | VAContextTest() { |
| 25 | } |
| 26 | |
| 27 | void SetUp() override { |
| 28 | PlatformFixture::setUp(); |
| 29 | |
| 30 | cl_platform_id platform = pPlatform; |
| 31 | properties = new cl_context_properties[3]; |
| 32 | properties[0] = CL_CONTEXT_PLATFORM; |
| 33 | properties[1] = (cl_context_properties)platform; |
| 34 | properties[2] = 0; |
| 35 | |
| 36 | context = Context::create<Context>(properties, ClDeviceVector(devices, numDevices), nullptr, nullptr, retVal); |
| 37 | ASSERT_NE(nullptr, context); |
| 38 | } |
| 39 | |
| 40 | void TearDown() override { |
| 41 | delete[] properties; |
| 42 | delete context; |
| 43 | PlatformFixture::tearDown(); |
| 44 | } |
| 45 | |
| 46 | cl_int retVal = CL_SUCCESS; |
| 47 | Context *context = nullptr; |
| 48 | cl_context_properties *properties = nullptr; |
| 49 | }; |
| 50 | |
| 51 | TEST_F(VAContextTest, GivenDefaultThenSharingNotPresent) { |
| 52 | ASSERT_EQ(context->getSharing<VASharingFunctions>(), nullptr); |
| 53 | } |
| 54 | |
| 55 | TEST_F(VAContextTest, GivenVaContextParamWhenCreateContextThenReturnError) { |
| 56 | cl_device_id deviceID = devices[0]; |
| 57 | auto pPlatform = NEO::platform(); |
| 58 | cl_platform_id pid[1]; |
| 59 | pid[0] = pPlatform; |
| 60 | DebugManagerStateRestore dbgRestorer; |
| 61 | debugManager.flags.EnableVaLibCalls.set(false); // avoid libva calls on initialization |
| 62 | |
| 63 | cl_context_properties validProperties[5] = {CL_CONTEXT_PLATFORM, (cl_context_properties)pid[0], |
| 64 | CL_CONTEXT_VA_API_DISPLAY_INTEL, 0x10000, 0}; |
| 65 | cl_int retVal = CL_SUCCESS; |
| 66 | auto ctx = Context::create<Context>(validProperties, ClDeviceVector(&deviceID, 1), nullptr, nullptr, retVal); |
| 67 | |
| 68 | // not supported by default |
| 69 | // use MockVaSharing to test va-sharing functionality |
| 70 | EXPECT_EQ(CL_INVALID_VA_API_MEDIA_ADAPTER_INTEL, retVal); |
| 71 | EXPECT_EQ(nullptr, ctx); |
| 72 | } |