mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Initial commit
Change-Id: I4bf1707bd3dfeadf2c17b0a7daff372b1925ebbd
This commit is contained in:
33
unit_tests/sharings/CMakeLists.txt
Normal file
33
unit_tests/sharings/CMakeLists.txt
Normal file
@ -0,0 +1,33 @@
|
||||
# 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.
|
||||
|
||||
# We are setting all of the source/OpenCL/tests/program files here and
|
||||
# sending the variable up to the parent scope
|
||||
|
||||
set(IGDRCL_SRCS_tests_sharings
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sharing_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sharing_factory_tests.cpp"
|
||||
)
|
||||
|
||||
add_subdirectory(d3d)
|
||||
add_subdirectory(va)
|
||||
|
||||
set(IGDRCL_SRCS_tests_sharings "${IGDRCL_SRCS_tests_sharings}" PARENT_SCOPE)
|
27
unit_tests/sharings/d3d/CMakeLists.txt
Normal file
27
unit_tests/sharings/d3d/CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
||||
# 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.
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND IGDRCL_SRCS_tests_sharings
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/context_d3d_tests.cpp"
|
||||
)
|
||||
set(IGDRCL_SRCS_tests_sharings "${IGDRCL_SRCS_tests_sharings}" PARENT_SCOPE)
|
||||
endif(WIN32)
|
47
unit_tests/sharings/d3d/context_d3d_tests.cpp
Normal file
47
unit_tests/sharings/d3d/context_d3d_tests.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 "runtime/sharings/d3d/cl_d3d_api.h"
|
||||
#include "runtime/os_interface/windows/d3d_sharing_functions.h"
|
||||
#include "unit_tests/mocks/mock_context.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
TEST(D3DContextTest, sharingAreNotPresentByDefault) {
|
||||
MockContext context;
|
||||
|
||||
EXPECT_EQ(nullptr, context.getSharing<D3DSharingFunctions<D3DTypesHelper::D3D9>>());
|
||||
EXPECT_EQ(nullptr, context.getSharing<D3DSharingFunctions<D3DTypesHelper::D3D10>>());
|
||||
EXPECT_EQ(nullptr, context.getSharing<D3DSharingFunctions<D3DTypesHelper::D3D11>>());
|
||||
}
|
||||
|
||||
TEST(D3DContextTest, giveDispatchtableContainsValidEntries) {
|
||||
sharingFactory.fillGlobalDispatchTable();
|
||||
|
||||
MockContext context;
|
||||
|
||||
EXPECT_EQ(&clGetDeviceIDsFromDX9INTEL, context.dispatch.crtDispatch->clGetDeviceIDsFromDX9INTEL);
|
||||
EXPECT_EQ(&clCreateFromDX9MediaSurfaceINTEL, context.dispatch.crtDispatch->clCreateFromDX9MediaSurfaceINTEL);
|
||||
EXPECT_EQ(&clEnqueueAcquireDX9ObjectsINTEL, context.dispatch.crtDispatch->clEnqueueAcquireDX9ObjectsINTEL);
|
||||
EXPECT_EQ(&clEnqueueReleaseDX9ObjectsINTEL, context.dispatch.crtDispatch->clEnqueueReleaseDX9ObjectsINTEL);
|
||||
}
|
145
unit_tests/sharings/sharing_factory_tests.cpp
Normal file
145
unit_tests/sharings/sharing_factory_tests.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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 "runtime/sharings/sharing_factory.h"
|
||||
#include "unit_tests/fixtures/memory_management_fixture.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "runtime/helpers/string.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
class SharingFactoryStateRestore : public SharingFactory {
|
||||
public:
|
||||
SharingFactoryStateRestore() {
|
||||
memcpy_s(savedState, sizeof(savedState), sharingContextBuilder, sizeof(sharingContextBuilder));
|
||||
}
|
||||
~SharingFactoryStateRestore() {
|
||||
memcpy_s(sharingContextBuilder, sizeof(sharingContextBuilder), savedState, sizeof(savedState));
|
||||
}
|
||||
|
||||
void clearCurrentState() {
|
||||
for (size_t i = 0; i < sizeof(sharingContextBuilder) / sizeof(*sharingContextBuilder); i++) {
|
||||
sharingContextBuilder[i] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void registerSharing(SharingType type) {
|
||||
auto object = std::unique_ptr<F>(new F);
|
||||
sharingContextBuilder[type] = object.get();
|
||||
sharings.push_back(std::move(object));
|
||||
}
|
||||
|
||||
template <typename Sharing>
|
||||
Sharing *getSharing();
|
||||
|
||||
protected:
|
||||
decltype(SharingFactory::sharingContextBuilder) savedState;
|
||||
std::vector<std::unique_ptr<SharingBuilderFactory>> sharings;
|
||||
};
|
||||
|
||||
class SharingFactoryTests : public MemoryManagementFixture,
|
||||
public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {
|
||||
MemoryManagementFixture::SetUp();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
MemoryManagementFixture::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
class TestedSharingBuilderFactory : public SharingBuilderFactory {
|
||||
public:
|
||||
std::unique_ptr<SharingContextBuilder> createContextBuilder() override {
|
||||
return nullptr;
|
||||
}
|
||||
std::string getExtensions() override {
|
||||
return extension;
|
||||
};
|
||||
void fillGlobalDispatchTable() override {
|
||||
invocationCount++;
|
||||
};
|
||||
void *getExtensionFunctionAddress(const std::string &functionName) override {
|
||||
if (functionName == "someFunction")
|
||||
invocationCount++;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static const std::string extension;
|
||||
uint32_t invocationCount = 0u;
|
||||
};
|
||||
const std::string TestedSharingBuilderFactory::extension("--extensions--");
|
||||
|
||||
template <>
|
||||
TestedSharingBuilderFactory *SharingFactoryStateRestore::getSharing() {
|
||||
return reinterpret_cast<TestedSharingBuilderFactory *>(sharingContextBuilder[SharingType::CLGL_SHARING]);
|
||||
}
|
||||
|
||||
TEST_F(SharingFactoryTests, givenFactoryWithEmptyTableWhenAskedForExtensionThenEmptyStringIsReturned) {
|
||||
SharingFactoryStateRestore stateRestore;
|
||||
|
||||
stateRestore.clearCurrentState();
|
||||
auto ext = stateRestore.getExtensions();
|
||||
EXPECT_EQ(0u, ext.length());
|
||||
EXPECT_STREQ("", ext.c_str());
|
||||
}
|
||||
|
||||
TEST_F(SharingFactoryTests, givenFactoryWithSharingWhenAskedForExtensionThenStringIsReturned) {
|
||||
SharingFactoryStateRestore stateRestore;
|
||||
|
||||
stateRestore.clearCurrentState();
|
||||
stateRestore.registerSharing<TestedSharingBuilderFactory>(SharingType::CLGL_SHARING);
|
||||
|
||||
auto ext = stateRestore.getExtensions();
|
||||
EXPECT_EQ(TestedSharingBuilderFactory::extension.length(), ext.length());
|
||||
EXPECT_STREQ(TestedSharingBuilderFactory::extension.c_str(), ext.c_str());
|
||||
}
|
||||
|
||||
TEST_F(SharingFactoryTests, givenFactoryWithSharingWhenDispatchFillRequestedThenMethodsAreInvoked) {
|
||||
SharingFactoryStateRestore stateRestore;
|
||||
|
||||
stateRestore.clearCurrentState();
|
||||
stateRestore.registerSharing<TestedSharingBuilderFactory>(SharingType::CLGL_SHARING);
|
||||
auto sharing = stateRestore.getSharing<TestedSharingBuilderFactory>();
|
||||
ASSERT_EQ(0u, sharing->invocationCount);
|
||||
|
||||
stateRestore.fillGlobalDispatchTable();
|
||||
|
||||
EXPECT_EQ(1u, sharing->invocationCount);
|
||||
}
|
||||
|
||||
TEST_F(SharingFactoryTests, givenFactoryWithSharingWhenAskedThenAddressIsReturned) {
|
||||
SharingFactoryStateRestore stateRestore;
|
||||
|
||||
stateRestore.clearCurrentState();
|
||||
stateRestore.registerSharing<TestedSharingBuilderFactory>(SharingType::CLGL_SHARING);
|
||||
auto sharing = stateRestore.getSharing<TestedSharingBuilderFactory>();
|
||||
ASSERT_EQ(0u, sharing->invocationCount);
|
||||
|
||||
auto ptr = stateRestore.getExtensionFunctionAddress("someFunction");
|
||||
EXPECT_EQ(nullptr, ptr);
|
||||
|
||||
EXPECT_EQ(1u, sharing->invocationCount);
|
||||
}
|
44
unit_tests/sharings/sharing_tests.cpp
Normal file
44
unit_tests/sharings/sharing_tests.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 "runtime/sharings/sharing.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
TEST(sharingHandler, givenBasicSharingHandlerWhenSynchronizeObjectThenErrorIsReturned) {
|
||||
struct SH : SharingHandler {
|
||||
void synchronizeObjectMock(UpdateData *updateData) { return synchronizeObject(updateData); }
|
||||
|
||||
} sharingHandler;
|
||||
|
||||
UpdateData updateData;
|
||||
sharingHandler.synchronizeObjectMock(&updateData);
|
||||
EXPECT_EQ(SynchronizeStatus::SYNCHRONIZE_ERROR, updateData.synchronizationStatus);
|
||||
|
||||
size_t paramSize = 0;
|
||||
void *paramValue = nullptr;
|
||||
// there is no default implementation. parameters should be unchanged.
|
||||
sharingHandler.getMemObjectInfo(paramSize, paramValue);
|
||||
EXPECT_EQ(paramSize, 0u);
|
||||
EXPECT_EQ(paramValue, nullptr);
|
||||
}
|
37
unit_tests/sharings/va/CMakeLists.txt
Normal file
37
unit_tests/sharings/va/CMakeLists.txt
Normal file
@ -0,0 +1,37 @@
|
||||
# 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.
|
||||
|
||||
if(LIBVA_FOUND)
|
||||
list(APPEND IGDRCL_SRCS_tests_sharings
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cl_create_from_va_media_surface_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cl_enqueue_acquire_va_media_surfaces_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cl_enqueue_release_va_media_surfaces_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cl_get_extension_function_address_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/context_va_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/kernel_va_image_arg_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/mock_va_sharing.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/va_base_object_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/va_sharing_enable_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/va_sharing_linux_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/va_sharing_tests.cpp"
|
||||
)
|
||||
set(IGDRCL_SRCS_tests_sharings "${IGDRCL_SRCS_tests_sharings}" PARENT_SCOPE)
|
||||
endif(LIBVA_FOUND)
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 "unit_tests/api/cl_api_tests.h"
|
||||
#include <CL/cl_va_api_media_sharing_intel.h>
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
typedef api_tests clCreateFromVaMediaSurfaceTests;
|
||||
|
||||
namespace ULT {
|
||||
|
||||
TEST_F(clCreateFromVaMediaSurfaceTests, givenNullContextWhenCreateIsCalledThenErrorIsReturned) {
|
||||
auto memObj = clCreateFromVA_APIMediaSurfaceINTEL(nullptr, CL_MEM_READ_WRITE, nullptr, 0, &retVal);
|
||||
EXPECT_EQ(nullptr, memObj);
|
||||
EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
|
||||
}
|
||||
} // namespace ULT
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 "unit_tests/api/cl_api_tests.h"
|
||||
#include <CL/cl_va_api_media_sharing_intel.h>
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
typedef api_tests clEnqueueAcquireVaMediaSurfacesTests;
|
||||
|
||||
namespace ULT {
|
||||
|
||||
TEST_F(clEnqueueAcquireVaMediaSurfacesTests, givenNullCommandQueueWhenAcquireIsCalledThenInvalidCommandQueueIsReturned) {
|
||||
retVal = clEnqueueAcquireVA_APIMediaSurfacesINTEL(nullptr, 0, nullptr, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(retVal, CL_INVALID_COMMAND_QUEUE);
|
||||
}
|
||||
} // namespace ULT
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 "unit_tests/api/cl_api_tests.h"
|
||||
#include <CL/cl_va_api_media_sharing_intel.h>
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
typedef api_tests clEnqueueReleaseVaMediaSurfacesTests;
|
||||
|
||||
namespace ULT {
|
||||
|
||||
TEST_F(clEnqueueReleaseVaMediaSurfacesTests, givenNullCommandQueueWhenReleaseObjectsIsCalledThenInvalidCommandQueueIsReturned) {
|
||||
retVal = clEnqueueReleaseVA_APIMediaSurfacesINTEL(nullptr, 0, nullptr, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(retVal, CL_INVALID_COMMAND_QUEUE);
|
||||
}
|
||||
} // namespace ULT
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 "unit_tests/api/cl_api_tests.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
typedef api_tests clGetExtensionFunctionAddressTests;
|
||||
|
||||
namespace ULT {
|
||||
|
||||
TEST_F(clGetExtensionFunctionAddressTests, clCreateFromVaMediaSurfaceINTEL) {
|
||||
auto retVal = clGetExtensionFunctionAddress("clCreateFromVA_APIMediaSurfaceINTEL");
|
||||
EXPECT_EQ(retVal, reinterpret_cast<void *>(clCreateFromVA_APIMediaSurfaceINTEL));
|
||||
}
|
||||
|
||||
TEST_F(clGetExtensionFunctionAddressTests, clEnqueueAcquireVA_APIMediaSurfacesINTEL) {
|
||||
auto retVal = clGetExtensionFunctionAddress("clEnqueueAcquireVA_APIMediaSurfacesINTEL");
|
||||
EXPECT_EQ(retVal, reinterpret_cast<void *>(clEnqueueAcquireVA_APIMediaSurfacesINTEL));
|
||||
}
|
||||
|
||||
TEST_F(clGetExtensionFunctionAddressTests, clEnqueueReleaseVA_APIMediaSurfacesINTEL) {
|
||||
auto retVal = clGetExtensionFunctionAddress("clEnqueueReleaseVA_APIMediaSurfacesINTEL");
|
||||
EXPECT_EQ(retVal, reinterpret_cast<void *>(clEnqueueReleaseVA_APIMediaSurfacesINTEL));
|
||||
}
|
||||
} // namespace ULT
|
85
unit_tests/sharings/va/context_va_tests.cpp
Normal file
85
unit_tests/sharings/va/context_va_tests.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 "runtime/helpers/options.h"
|
||||
#include "unit_tests/fixtures/platform_fixture.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "runtime/sharings/va/va_sharing.h"
|
||||
#include "unit_tests/helpers/debug_manager_state_restore.h"
|
||||
#include "unit_tests/mocks/mock_context.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
struct VAContextTest : public PlatformFixture,
|
||||
public ::testing::Test {
|
||||
|
||||
using PlatformFixture::SetUp;
|
||||
|
||||
VAContextTest() {
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
PlatformFixture::SetUp(numPlatformDevices, platformDevices);
|
||||
|
||||
cl_platform_id platform = pPlatform;
|
||||
properties = new cl_context_properties[3];
|
||||
properties[0] = CL_CONTEXT_PLATFORM;
|
||||
properties[1] = (cl_context_properties)platform;
|
||||
properties[2] = 0;
|
||||
|
||||
context = Context::create<Context>(properties, DeviceVector(devices, num_devices), nullptr, nullptr, retVal);
|
||||
ASSERT_NE(nullptr, context);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
delete[] properties;
|
||||
delete context;
|
||||
PlatformFixture::TearDown();
|
||||
}
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
Context *context = nullptr;
|
||||
cl_context_properties *properties = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(VAContextTest, sharingAreNotPresentByDefault) {
|
||||
ASSERT_EQ(context->getSharing<VASharingFunctions>(), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(VAContextTest, GivenVaContextParamWhenCreateContextThenReturnError) {
|
||||
cl_device_id deviceID = devices[0];
|
||||
auto pPlatform = OCLRT::platform();
|
||||
cl_platform_id pid[1];
|
||||
pid[0] = pPlatform;
|
||||
DebugManagerStateRestore dbgRestorer;
|
||||
DebugManager.flags.EnableVaLibCalls.set(false); // avoid libva calls on initialization
|
||||
|
||||
cl_context_properties validProperties[5] = {CL_CONTEXT_PLATFORM, (cl_context_properties)pid[0],
|
||||
CL_CONTEXT_VA_API_DISPLAY_INTEL, 0x10000, 0};
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
auto ctx = Context::create<Context>(validProperties, DeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
|
||||
|
||||
// not supported by default
|
||||
// use MockVaSharing to test va-sharing functionality
|
||||
EXPECT_EQ(CL_INVALID_VA_API_MEDIA_ADAPTER_INTEL, retVal);
|
||||
EXPECT_EQ(nullptr, ctx);
|
||||
}
|
125
unit_tests/sharings/va/kernel_va_image_arg_tests.cpp
Normal file
125
unit_tests/sharings/va/kernel_va_image_arg_tests.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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 "runtime/sharings/va/va_surface.h"
|
||||
#include "unit_tests/fixtures/device_fixture.h"
|
||||
#include "test.h"
|
||||
#include "unit_tests/fixtures/image_fixture.h"
|
||||
#include "unit_tests/mocks/mock_kernel.h"
|
||||
#include "unit_tests/mocks/mock_program.h"
|
||||
#include "unit_tests/sharings/va/mock_va_sharing.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
class KernelImageArgTest : public Test<DeviceFixture> {
|
||||
public:
|
||||
KernelImageArgTest() {
|
||||
}
|
||||
|
||||
protected:
|
||||
void SetUp() override {
|
||||
pKernelInfo = KernelInfo::create();
|
||||
KernelArgPatchInfo kernelArgPatchInfo;
|
||||
|
||||
kernelHeader.SurfaceStateHeapSize = sizeof(surfaceStateHeap);
|
||||
pKernelInfo->heapInfo.pSsh = surfaceStateHeap;
|
||||
pKernelInfo->heapInfo.pKernelHeader = &kernelHeader;
|
||||
pKernelInfo->usesSsh = true;
|
||||
|
||||
pKernelInfo->kernelArgInfo.resize(5);
|
||||
pKernelInfo->kernelArgInfo[4].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
|
||||
pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
|
||||
pKernelInfo->kernelArgInfo[2].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
|
||||
pKernelInfo->kernelArgInfo[1].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
|
||||
pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
|
||||
|
||||
pKernelInfo->kernelArgInfo[0].offsetImgWidth = 0x4;
|
||||
pKernelInfo->kernelArgInfo[0].offsetNumSamples = 0x3c;
|
||||
pKernelInfo->kernelArgInfo[1].offsetImgHeight = 0xc;
|
||||
pKernelInfo->kernelArgInfo[2].kernelArgPatchInfoVector[0].crossthreadOffset = 0x20;
|
||||
pKernelInfo->kernelArgInfo[2].kernelArgPatchInfoVector[0].size = sizeof(void *);
|
||||
pKernelInfo->kernelArgInfo[3].offsetImgDepth = 0x30;
|
||||
pKernelInfo->kernelArgInfo[4].offsetHeap = 0x20;
|
||||
pKernelInfo->kernelArgInfo[4].offsetObjectId = 0x0;
|
||||
|
||||
pKernelInfo->kernelArgInfo[4].isImage = true;
|
||||
pKernelInfo->kernelArgInfo[3].isImage = true;
|
||||
pKernelInfo->kernelArgInfo[2].isImage = true;
|
||||
pKernelInfo->kernelArgInfo[1].isImage = true;
|
||||
pKernelInfo->kernelArgInfo[0].isImage = true;
|
||||
|
||||
DeviceFixture::SetUp();
|
||||
pKernel = new MockKernel(&program, *pKernelInfo, *pDevice);
|
||||
ASSERT_EQ(CL_SUCCESS, pKernel->initialize());
|
||||
|
||||
pKernel->setKernelArgHandler(0, &Kernel::setArgImage);
|
||||
pKernel->setKernelArgHandler(1, &Kernel::setArgImage);
|
||||
pKernel->setKernelArgHandler(2, &Kernel::setArgImmediate);
|
||||
pKernel->setKernelArgHandler(3, &Kernel::setArgImage);
|
||||
pKernel->setKernelArgHandler(4, &Kernel::setArgImage);
|
||||
|
||||
uint32_t crossThreadData[0x40] = {};
|
||||
crossThreadData[0x20 / sizeof(uint32_t)] = 0x12344321;
|
||||
pKernel->setCrossThreadData(crossThreadData, sizeof(crossThreadData));
|
||||
|
||||
context = new MockContext(pDevice);
|
||||
image = Image2dHelper<>::create(context);
|
||||
ASSERT_NE(nullptr, image);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
delete pKernelInfo;
|
||||
delete pKernel;
|
||||
delete image;
|
||||
delete context;
|
||||
DeviceFixture::TearDown();
|
||||
}
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
MockProgram program;
|
||||
MockKernel *pKernel = nullptr;
|
||||
KernelInfo *pKernelInfo;
|
||||
|
||||
MockContext *context;
|
||||
Image *image;
|
||||
SKernelBinaryHeaderCommon kernelHeader;
|
||||
char surfaceStateHeap[0x80];
|
||||
};
|
||||
|
||||
TEST_F(KernelImageArgTest, givenSharedImageWhenSetArgIsCalledThenReportSharedObjUsage) {
|
||||
MockVaSharing vaSharing;
|
||||
VASurfaceID vaSurfaceId = 0u;
|
||||
vaSharing.updateAcquiredHandle(1u);
|
||||
std::unique_ptr<Image> sharedImage(VASurface::createSharedVaSurface(context, &vaSharing.m_sharingFunctions,
|
||||
CL_MEM_READ_WRITE, &vaSurfaceId, 0, nullptr));
|
||||
|
||||
auto sharedMem = static_cast<cl_mem>(sharedImage.get());
|
||||
auto nonSharedMem = static_cast<cl_mem>(image);
|
||||
|
||||
EXPECT_FALSE(pKernel->isUsingSharedObjArgs());
|
||||
this->pKernel->setArg(0, sizeof(cl_mem *), &nonSharedMem);
|
||||
EXPECT_FALSE(pKernel->isUsingSharedObjArgs());
|
||||
|
||||
this->pKernel->setArg(0, sizeof(cl_mem *), &sharedMem);
|
||||
EXPECT_TRUE(pKernel->isUsingSharedObjArgs());
|
||||
}
|
54
unit_tests/sharings/va/mock_va_sharing.cpp
Normal file
54
unit_tests/sharings/va/mock_va_sharing.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 "unit_tests/sharings/va/mock_va_sharing.h"
|
||||
|
||||
namespace OCLRT {
|
||||
int vaDisplayIsValidCalled = 0;
|
||||
int vaDeriveImageCalled = 0;
|
||||
int vaDestroyImageCalled = 0;
|
||||
int vaSyncSurfaceCalled = 0;
|
||||
int vaGetLibFuncCalled = 0;
|
||||
int vaExtGetSurfaceHandleCalled = 0;
|
||||
osHandle acquiredVaHandle = 0;
|
||||
VAImage mockVaImage = {};
|
||||
|
||||
void VASharingFunctionsMock::initMembers() {
|
||||
vaDisplayIsValidPFN = mockVaDisplayIsValid;
|
||||
vaDeriveImagePFN = mockVaDeriveImage;
|
||||
vaDestroyImagePFN = mockVaDestroyImage;
|
||||
vaSyncSurfacePFN = mockVaSyncSurface;
|
||||
vaGetLibFuncPFN = mockVaGetLibFunc;
|
||||
vaExtGetSurfaceHandlePFN = mockExtGetSurfaceHandle;
|
||||
|
||||
vaDisplayIsValidCalled = 0;
|
||||
vaDeriveImageCalled = 0;
|
||||
vaDestroyImageCalled = 0;
|
||||
vaSyncSurfaceCalled = 0;
|
||||
vaGetLibFuncCalled = 0;
|
||||
vaExtGetSurfaceHandleCalled = 0;
|
||||
|
||||
mockVaImage = {};
|
||||
|
||||
acquiredVaHandle = 0;
|
||||
}
|
||||
}
|
96
unit_tests/sharings/va/mock_va_sharing.h
Normal file
96
unit_tests/sharings/va/mock_va_sharing.h
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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/sharings/va/va_sharing.h"
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
extern int vaDisplayIsValidCalled;
|
||||
extern int vaDeriveImageCalled;
|
||||
extern int vaDestroyImageCalled;
|
||||
extern int vaSyncSurfaceCalled;
|
||||
extern int vaGetLibFuncCalled;
|
||||
extern int vaExtGetSurfaceHandleCalled;
|
||||
extern osHandle acquiredVaHandle;
|
||||
extern VAImage mockVaImage;
|
||||
|
||||
class VASharingFunctionsMock : public VASharingFunctions {
|
||||
|
||||
static int mockVaDisplayIsValid(VADisplay vaDisplay) {
|
||||
vaDisplayIsValidCalled++;
|
||||
return 1; // success
|
||||
};
|
||||
|
||||
static VAStatus mockVaDeriveImage(VADisplay vaDisplay, VASurfaceID vaSurface, VAImage *vaImage) {
|
||||
vaDeriveImageCalled++;
|
||||
vaImage->height = 256u;
|
||||
vaImage->width = 256u;
|
||||
mockVaImage.width = vaImage->width;
|
||||
mockVaImage.height = vaImage->height;
|
||||
return (VAStatus)0; // success
|
||||
};
|
||||
|
||||
static VAStatus mockVaDestroyImage(VADisplay vaDisplay, VAImageID vaImageId) {
|
||||
vaDestroyImageCalled++;
|
||||
return (VAStatus)0; // success
|
||||
};
|
||||
|
||||
static VAStatus mockVaSyncSurface(VADisplay vaDisplay, VASurfaceID vaSurface) {
|
||||
vaSyncSurfaceCalled++;
|
||||
return (VAStatus)0; // success
|
||||
};
|
||||
|
||||
static VAPrivFunc mockVaGetLibFunc(VADisplay vaDisplay, const char *func) {
|
||||
vaGetLibFuncCalled++;
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
static VAStatus mockExtGetSurfaceHandle(VADisplay vaDisplay, VASurfaceID *vaSurface, unsigned int *handleId) {
|
||||
vaExtGetSurfaceHandleCalled++;
|
||||
*handleId = acquiredVaHandle;
|
||||
return (VAStatus)0; // success
|
||||
};
|
||||
|
||||
void initMembers();
|
||||
|
||||
public:
|
||||
VASharingFunctionsMock(VADisplay vaDisplay) : VASharingFunctions(vaDisplay) {
|
||||
initMembers();
|
||||
}
|
||||
VASharingFunctionsMock() : VASharingFunctionsMock(nullptr){};
|
||||
};
|
||||
|
||||
class MockVaSharing {
|
||||
public:
|
||||
void updateAcquiredHandle() {
|
||||
acquiredVaHandle = sharingHandle;
|
||||
}
|
||||
void updateAcquiredHandle(unsigned int handle) {
|
||||
sharingHandle = handle;
|
||||
acquiredVaHandle = sharingHandle;
|
||||
}
|
||||
|
||||
VASharingFunctionsMock m_sharingFunctions;
|
||||
osHandle sharingHandle = 0;
|
||||
};
|
||||
}
|
75
unit_tests/sharings/va/va_base_object_tests.cpp
Normal file
75
unit_tests/sharings/va/va_base_object_tests.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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 "runtime/accelerators/intel_accelerator.h"
|
||||
#include "runtime/command_queue/command_queue.h"
|
||||
#include "runtime/device_queue/device_queue.h"
|
||||
#include "runtime/helpers/base_object.h"
|
||||
#include "runtime/platform/platform.h"
|
||||
#include "runtime/sharings/sharing_factory.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
template <typename TypeParam>
|
||||
struct VABaseObjectTests : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
}
|
||||
};
|
||||
|
||||
typedef ::testing::Types<
|
||||
Platform,
|
||||
IntelAccelerator,
|
||||
//Context,
|
||||
//Program,
|
||||
//Kernel,
|
||||
//Sampler
|
||||
//others...
|
||||
CommandQueue,
|
||||
DeviceQueue>
|
||||
BaseObjectTypes;
|
||||
|
||||
TYPED_TEST_CASE(VABaseObjectTests, BaseObjectTypes);
|
||||
|
||||
TYPED_TEST(VABaseObjectTests, commonRuntimeExpectsDispatchTableAtFirstPointerInObject) {
|
||||
TypeParam objectDrv;
|
||||
|
||||
// Automatic downcasting to _cl_type *.
|
||||
typename TypeParam::BaseType *objectCL = &objectDrv;
|
||||
sharingFactory.fillGlobalDispatchTable();
|
||||
|
||||
// Common runtime casts to generic type assuming
|
||||
// the dispatch table is the first ptr in the structure
|
||||
auto genericObject = reinterpret_cast<ClDispatch *>(objectCL);
|
||||
EXPECT_EQ(reinterpret_cast<void *>(clCreateFromVA_APIMediaSurfaceINTEL),
|
||||
genericObject->dispatch.crtDispatch->clCreateFromVA_APIMediaSurfaceINTEL);
|
||||
|
||||
EXPECT_EQ(reinterpret_cast<void *>(clEnqueueAcquireVA_APIMediaSurfacesINTEL),
|
||||
genericObject->dispatch.crtDispatch->clEnqueueAcquireVA_APIMediaSurfacesINTEL);
|
||||
|
||||
EXPECT_EQ(reinterpret_cast<void *>(clEnqueueReleaseVA_APIMediaSurfacesINTEL),
|
||||
genericObject->dispatch.crtDispatch->clEnqueueReleaseVA_APIMediaSurfacesINTEL);
|
||||
}
|
||||
} // namespace OCLRT
|
207
unit_tests/sharings/va/va_sharing_enable_tests.cpp
Normal file
207
unit_tests/sharings/va/va_sharing_enable_tests.cpp
Normal file
@ -0,0 +1,207 @@
|
||||
/*
|
||||
* 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 "runtime/sharings/va/enable_va.h"
|
||||
#include "runtime/sharings/va/va_sharing_functions.h"
|
||||
#include "unit_tests/fixtures/memory_management_fixture.h"
|
||||
#include "unit_tests/mocks/mock_context.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "variable_backup.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
static int vaDisplayIsValidRet = 1;
|
||||
extern "C" int vaDisplayIsValid(VADisplay vaDisplay) {
|
||||
return vaDisplayIsValidRet;
|
||||
}
|
||||
|
||||
class VaSharingEnablerTests : public MemoryManagementFixture,
|
||||
public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {
|
||||
MemoryManagementFixture::SetUp();
|
||||
factory.reset(new VaSharingBuilderFactory());
|
||||
ASSERT_NE(nullptr, factory.get());
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
factory.reset(nullptr);
|
||||
MemoryManagementFixture::TearDown();
|
||||
}
|
||||
std::unique_ptr<VaSharingBuilderFactory> factory;
|
||||
};
|
||||
|
||||
TEST_F(VaSharingEnablerTests, givenVaFactoryWhenNoLibVaThenNoExtensionIsReturned) {
|
||||
// hijack dlopen function
|
||||
VariableBackup<std::function<void *(const char *, int)>> bkp(&VASharingFunctions::fdlopen);
|
||||
bkp = [&](const char *filename, int flag) -> void * {
|
||||
// no libva in system
|
||||
return nullptr;
|
||||
};
|
||||
auto ext = factory->getExtensions();
|
||||
EXPECT_EQ(0u, ext.length());
|
||||
EXPECT_STREQ("", ext.c_str());
|
||||
}
|
||||
|
||||
TEST_F(VaSharingEnablerTests, givenVaFactoryWhenLibVaAvailableThenExtensionIsReturned) {
|
||||
VariableBackup<std::function<void *(const char *, int)>> bkpOpen(&VASharingFunctions::fdlopen);
|
||||
bkpOpen = [&](const char *filename, int flag) -> void * {
|
||||
return this;
|
||||
};
|
||||
VariableBackup<std::function<int(void *)>> bkpClose(&VASharingFunctions::fdlclose);
|
||||
bkpClose = [&](void *handle) -> int {
|
||||
return 0;
|
||||
};
|
||||
VariableBackup<std::function<void *(void *, const char *)>> bkpSym(&VASharingFunctions::fdlsym);
|
||||
bkpSym = [&](void *handle, const char *symbol) -> void * {
|
||||
return nullptr;
|
||||
};
|
||||
auto ext = factory->getExtensions();
|
||||
EXPECT_STREQ("cl_intel_va_api_media_sharing ", ext.c_str());
|
||||
}
|
||||
|
||||
TEST_F(VaSharingEnablerTests, givenVaFactoryWhenAskedThenGlobalIcdIsConfigured) {
|
||||
class CrtRestore {
|
||||
public:
|
||||
CrtRestore() {
|
||||
crtSnapshot = crtGlobalDispatchTable;
|
||||
}
|
||||
~CrtRestore() {
|
||||
crtGlobalDispatchTable = crtSnapshot;
|
||||
}
|
||||
decltype(crtGlobalDispatchTable) crtSnapshot;
|
||||
};
|
||||
|
||||
// we play with global table, so first save state then restore it with use of RAII
|
||||
CrtRestore crtRestore;
|
||||
crtGlobalDispatchTable.clCreateFromVA_APIMediaSurfaceINTEL = nullptr;
|
||||
crtGlobalDispatchTable.clEnqueueReleaseVA_APIMediaSurfacesINTEL = nullptr;
|
||||
crtGlobalDispatchTable.clEnqueueAcquireVA_APIMediaSurfacesINTEL = nullptr;
|
||||
factory->fillGlobalDispatchTable();
|
||||
EXPECT_NE(nullptr, crtGlobalDispatchTable.clCreateFromVA_APIMediaSurfaceINTEL);
|
||||
EXPECT_NE(nullptr, crtGlobalDispatchTable.clEnqueueAcquireVA_APIMediaSurfacesINTEL);
|
||||
EXPECT_NE(nullptr, crtGlobalDispatchTable.clEnqueueAcquireVA_APIMediaSurfacesINTEL);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingEnablerTests, givenVaFactoryWhenAskedThenBuilderIsCreated) {
|
||||
auto builder = factory->createContextBuilder();
|
||||
EXPECT_NE(nullptr, builder);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingEnablerTests, givenVaBuilderWhenUnknownPropertyThenFalseIsReturnedAndErrcodeUnchanged) {
|
||||
auto builder = factory->createContextBuilder();
|
||||
ASSERT_NE(nullptr, builder);
|
||||
|
||||
cl_context_properties property = CL_CONTEXT_PLATFORM;
|
||||
cl_context_properties value;
|
||||
int32_t errcodeRet = CL_SUCCESS;
|
||||
auto res = builder->processProperties(property, value, errcodeRet);
|
||||
EXPECT_FALSE(res);
|
||||
EXPECT_EQ(CL_SUCCESS, errcodeRet);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingEnablerTests, givenVaBuilderWhenValidPropertyThenTrueIsReturnedAndErrcodeUnchanged) {
|
||||
auto builder = factory->createContextBuilder();
|
||||
ASSERT_NE(nullptr, builder);
|
||||
|
||||
cl_context_properties property = CL_CONTEXT_VA_API_DISPLAY_INTEL;
|
||||
cl_context_properties value = 0x1243;
|
||||
int32_t errcodeRet = CL_SUCCESS;
|
||||
auto res = builder->processProperties(property, value, errcodeRet);
|
||||
EXPECT_TRUE(res);
|
||||
EXPECT_EQ(CL_SUCCESS, errcodeRet);
|
||||
|
||||
//repeat to check if we don't allocate twice
|
||||
auto prevAllocations = MemoryManagement::numAllocations.load();
|
||||
res = builder->processProperties(property, value, errcodeRet);
|
||||
EXPECT_TRUE(res);
|
||||
EXPECT_EQ(CL_SUCCESS, errcodeRet);
|
||||
auto currAllocations = MemoryManagement::numAllocations.load();
|
||||
EXPECT_EQ(prevAllocations, currAllocations);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingEnablerTests, givenVaBuilderWhenNoPropertiesThenFinalizerReturnsTrue) {
|
||||
auto builder = factory->createContextBuilder();
|
||||
ASSERT_NE(nullptr, builder);
|
||||
|
||||
MockContext context;
|
||||
int32_t errcodeRet = CL_SUCCESS;
|
||||
auto res = builder->finalizeProperties(context, errcodeRet);
|
||||
EXPECT_TRUE(res);
|
||||
EXPECT_EQ(CL_SUCCESS, errcodeRet);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingEnablerTests, givenVaBuilderWhenInvalidPropertiesThenFinalizerReturnsTrue) {
|
||||
auto builder = factory->createContextBuilder();
|
||||
ASSERT_NE(nullptr, builder);
|
||||
|
||||
cl_context_properties property = CL_CONTEXT_PLATFORM;
|
||||
cl_context_properties value;
|
||||
int32_t errcodeRet = CL_SUCCESS;
|
||||
auto res = builder->processProperties(property, value, errcodeRet);
|
||||
EXPECT_FALSE(res);
|
||||
EXPECT_EQ(CL_SUCCESS, errcodeRet);
|
||||
|
||||
MockContext context;
|
||||
errcodeRet = CL_SUCCESS;
|
||||
res = builder->finalizeProperties(context, errcodeRet);
|
||||
EXPECT_TRUE(res);
|
||||
EXPECT_EQ(CL_SUCCESS, errcodeRet);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingEnablerTests, givenVaBuilderWhenValidPropertyButInvalidDisplayThenFinalizerReturnsFalseAndErrcode) {
|
||||
auto builder = factory->createContextBuilder();
|
||||
ASSERT_NE(nullptr, builder);
|
||||
|
||||
vaDisplayIsValidRet = 0;
|
||||
cl_context_properties property = CL_CONTEXT_VA_API_DISPLAY_INTEL;
|
||||
cl_context_properties value = 0x10000;
|
||||
int32_t errcodeRet = CL_SUCCESS;
|
||||
auto res = builder->processProperties(property, value, errcodeRet);
|
||||
EXPECT_TRUE(res);
|
||||
EXPECT_EQ(CL_SUCCESS, errcodeRet);
|
||||
|
||||
MockContext context;
|
||||
errcodeRet = CL_SUCCESS;
|
||||
res = builder->finalizeProperties(context, errcodeRet);
|
||||
EXPECT_FALSE(res);
|
||||
EXPECT_EQ(CL_INVALID_VA_API_MEDIA_ADAPTER_INTEL, errcodeRet);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingEnablerTests, givenVaBuilderWhenValidPropertyButValidDisplayThenFinalizerReturnsTrue) {
|
||||
auto builder = factory->createContextBuilder();
|
||||
ASSERT_NE(nullptr, builder);
|
||||
|
||||
vaDisplayIsValidRet = 1;
|
||||
cl_context_properties property = CL_CONTEXT_VA_API_DISPLAY_INTEL;
|
||||
cl_context_properties value = 0x10000;
|
||||
int32_t errcodeRet = CL_SUCCESS;
|
||||
auto res = builder->processProperties(property, value, errcodeRet);
|
||||
EXPECT_TRUE(res);
|
||||
EXPECT_EQ(CL_SUCCESS, errcodeRet);
|
||||
|
||||
MockContext context;
|
||||
errcodeRet = CL_SUCCESS;
|
||||
res = builder->finalizeProperties(context, errcodeRet);
|
||||
EXPECT_TRUE(res);
|
||||
EXPECT_EQ(CL_SUCCESS, errcodeRet);
|
||||
}
|
169
unit_tests/sharings/va/va_sharing_linux_tests.cpp
Normal file
169
unit_tests/sharings/va/va_sharing_linux_tests.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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 "runtime/sharings/va/va_sharing_functions.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "variable_backup.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
class VASharingFunctionsTested : public VASharingFunctions {
|
||||
public:
|
||||
VASharingFunctionsTested() : VASharingFunctions(nullptr) {}
|
||||
|
||||
bool wereFunctionsAssigned() {
|
||||
if (
|
||||
vaDisplayIsValidPFN != nullptr &&
|
||||
vaDeriveImagePFN != nullptr &&
|
||||
vaDestroyImagePFN != nullptr &&
|
||||
vaSyncSurfacePFN != nullptr &&
|
||||
vaGetLibFuncPFN != nullptr &&
|
||||
vaExtGetSurfaceHandlePFN != nullptr) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wereFunctionsAssignedNull() {
|
||||
if (
|
||||
vaDisplayIsValidPFN == nullptr &&
|
||||
vaDeriveImagePFN == nullptr &&
|
||||
vaDestroyImagePFN == nullptr &&
|
||||
vaSyncSurfacePFN == nullptr &&
|
||||
vaGetLibFuncPFN == nullptr &&
|
||||
vaExtGetSurfaceHandlePFN == nullptr) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
TEST(VASharingFunctions, GivenInitFunctionsWhenDLOpenFailsThenFunctionsAreNull) {
|
||||
VariableBackup<decltype(VASharingFunctions::fdlopen)> dlopenBackup(&VASharingFunctions::fdlopen);
|
||||
VariableBackup<decltype(VASharingFunctions::fdlsym)> dlsymBackup(&VASharingFunctions::fdlsym);
|
||||
VariableBackup<decltype(VASharingFunctions::fdlclose)> dlcloseBackup(&VASharingFunctions::fdlclose);
|
||||
|
||||
VASharingFunctions::fdlopen = [&](const char *filename, int flag) -> void * {
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
VASharingFunctions::fdlsym = [&](void *handle, const char *symbol) -> void * {
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
VASharingFunctions::fdlclose = [&](void *handle) -> int {
|
||||
return 0;
|
||||
};
|
||||
|
||||
VASharingFunctionsTested functions;
|
||||
EXPECT_TRUE(functions.wereFunctionsAssignedNull());
|
||||
}
|
||||
|
||||
VAPrivFunc GetLibFunc(VADisplay vaDisplay, const char *func) {
|
||||
return (VAPrivFunc)0xdeadbeef;
|
||||
}
|
||||
|
||||
TEST(VASharingFunctions, GivenInitFunctionsWhenDLOpenSuccedsThenFunctionsAreNotNull) {
|
||||
VariableBackup<decltype(VASharingFunctions::fdlopen)> dlopenBackup(&VASharingFunctions::fdlopen);
|
||||
VariableBackup<decltype(VASharingFunctions::fdlsym)> dlsymBackup(&VASharingFunctions::fdlsym);
|
||||
VariableBackup<decltype(VASharingFunctions::fdlclose)> dlcloseBackup(&VASharingFunctions::fdlclose);
|
||||
|
||||
std::unique_ptr<uint32_t> valib(new uint32_t);
|
||||
ASSERT_NE(nullptr, valib.get());
|
||||
|
||||
VASharingFunctions::fdlopen = [&](const char *filename, int flag) -> void * {
|
||||
return valib.get();
|
||||
};
|
||||
|
||||
VASharingFunctions::fdlsym = [&](void *handle, const char *symbol) -> void * {
|
||||
return (void *)GetLibFunc;
|
||||
};
|
||||
|
||||
VASharingFunctions::fdlclose = [&](void *handle) -> int {
|
||||
return 0;
|
||||
};
|
||||
|
||||
VASharingFunctionsTested functions;
|
||||
EXPECT_TRUE(functions.wereFunctionsAssigned());
|
||||
}
|
||||
|
||||
TEST(VASharingFunctions, GivenFunctionsWhenNoLibvaThenDlcloseNotCalled) {
|
||||
VariableBackup<decltype(VASharingFunctions::fdlopen)> dlopenBackup(&VASharingFunctions::fdlopen);
|
||||
VariableBackup<decltype(VASharingFunctions::fdlsym)> dlsymBackup(&VASharingFunctions::fdlsym);
|
||||
VariableBackup<decltype(VASharingFunctions::fdlclose)> dlcloseBackup(&VASharingFunctions::fdlclose);
|
||||
|
||||
uint32_t closeCalls = 0;
|
||||
|
||||
VASharingFunctions::fdlopen = [&](const char *filename, int flag) -> void * {
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
VASharingFunctions::fdlsym = [&](void *handle, const char *symbol) -> void * {
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
VASharingFunctions::fdlclose = [&](void *handle) -> int {
|
||||
closeCalls++;
|
||||
return 0;
|
||||
};
|
||||
|
||||
{
|
||||
// we need this to properly track closeCalls
|
||||
VASharingFunctionsTested functions;
|
||||
}
|
||||
EXPECT_EQ(0u, closeCalls);
|
||||
}
|
||||
|
||||
TEST(VASharingFunctions, GivenFunctionsWhenLibvaLoadedThenDlcloseIsCalled) {
|
||||
VariableBackup<decltype(VASharingFunctions::fdlopen)> dlopenBackup(&VASharingFunctions::fdlopen);
|
||||
VariableBackup<decltype(VASharingFunctions::fdlsym)> dlsymBackup(&VASharingFunctions::fdlsym);
|
||||
VariableBackup<decltype(VASharingFunctions::fdlclose)> dlcloseBackup(&VASharingFunctions::fdlclose);
|
||||
|
||||
std::unique_ptr<uint32_t> valib(new uint32_t);
|
||||
ASSERT_NE(nullptr, valib.get());
|
||||
|
||||
uint32_t closeCalls = 0;
|
||||
|
||||
VASharingFunctions::fdlopen = [&](const char *filename, int flag) -> void * {
|
||||
return valib.get();
|
||||
};
|
||||
|
||||
VASharingFunctions::fdlsym = [&](void *handle, const char *symbol) -> void * {
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
VASharingFunctions::fdlclose = [&](void *handle) -> int {
|
||||
if (handle == valib.get()) {
|
||||
closeCalls++;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
{
|
||||
// we need this to properly track closeCalls
|
||||
VASharingFunctionsTested functions;
|
||||
}
|
||||
EXPECT_EQ(1u, closeCalls);
|
||||
}
|
400
unit_tests/sharings/va/va_sharing_tests.cpp
Normal file
400
unit_tests/sharings/va/va_sharing_tests.cpp
Normal file
@ -0,0 +1,400 @@
|
||||
/*
|
||||
* 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 "unit_tests/libult/ult_command_stream_receiver.h"
|
||||
#include "runtime/device/device.h"
|
||||
#include "runtime/sharings/va/va_sharing.h"
|
||||
#include "unit_tests/mocks/mock_context.h"
|
||||
#include "unit_tests/sharings/va/mock_va_sharing.h"
|
||||
#include "runtime/sharings/va/va_surface.h"
|
||||
#include "runtime/api/api.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
class VaSharingTests : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {
|
||||
vaSharing = new MockVaSharing;
|
||||
context.setSharingFunctions(&vaSharing->m_sharingFunctions);
|
||||
vaSharing->updateAcquiredHandle(sharingHandle);
|
||||
sharedImg = nullptr;
|
||||
sharedClMem = nullptr;
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
if (sharedImg) {
|
||||
delete sharedImg;
|
||||
}
|
||||
context.releaseSharingFunctions(SharingType::VA_SHARING);
|
||||
delete vaSharing;
|
||||
}
|
||||
|
||||
void updateAcquiredHandle(unsigned int handle) {
|
||||
sharingHandle = handle;
|
||||
vaSharing->updateAcquiredHandle(sharingHandle);
|
||||
}
|
||||
|
||||
void createMediaSurface(cl_uint plane = 0, cl_mem_flags flags = CL_MEM_READ_WRITE) {
|
||||
sharedClMem = clCreateFromVA_APIMediaSurfaceINTEL(&context, flags, &vaSurfaceId, plane, &errCode);
|
||||
ASSERT_NE(nullptr, sharedClMem);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
sharedImg = castToObject<Image>(sharedClMem);
|
||||
ASSERT_NE(sharedImg, nullptr);
|
||||
}
|
||||
|
||||
Image *sharedImg;
|
||||
cl_mem sharedClMem;
|
||||
MockContext context;
|
||||
MockVaSharing *vaSharing;
|
||||
VASurfaceID vaSurfaceId = 0u;
|
||||
VAImage vaImage = {};
|
||||
cl_int errCode;
|
||||
unsigned int sharingHandle = 1u;
|
||||
};
|
||||
|
||||
TEST_F(VaSharingTests, givenMockVAWhenFunctionsAreCalledThenCallsAreReceived) {
|
||||
unsigned int handle = 0u;
|
||||
|
||||
EXPECT_TRUE(vaSharing->m_sharingFunctions.isValidVaDisplay());
|
||||
EXPECT_EQ(0, vaSharing->m_sharingFunctions.deriveImage(vaSurfaceId, &vaImage));
|
||||
EXPECT_EQ(0, vaSharing->m_sharingFunctions.destroyImage(vaImage.image_id));
|
||||
EXPECT_EQ(0, vaSharing->m_sharingFunctions.syncSurface(vaSurfaceId));
|
||||
EXPECT_TRUE(nullptr == vaSharing->m_sharingFunctions.getLibFunc("funcName"));
|
||||
EXPECT_EQ(0, vaSharing->m_sharingFunctions.extGetSurfaceHandle(&vaSurfaceId, &handle));
|
||||
|
||||
EXPECT_EQ(sharingHandle, handle);
|
||||
|
||||
EXPECT_EQ(1, vaDisplayIsValidCalled);
|
||||
EXPECT_EQ(1, vaDeriveImageCalled);
|
||||
EXPECT_EQ(1, vaDestroyImageCalled);
|
||||
EXPECT_EQ(1, vaSyncSurfaceCalled);
|
||||
EXPECT_EQ(1, vaGetLibFuncCalled);
|
||||
EXPECT_EQ(1, vaExtGetSurfaceHandleCalled);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenMockVaWhenVaSurfaceIsCreatedThenMemObjectHasVaHandler) {
|
||||
// this will create OS specific memory Manager
|
||||
//overrideCommandStreamReceiverCreation = true;
|
||||
ASSERT_FALSE(overrideCommandStreamReceiverCreation);
|
||||
|
||||
auto vaSurface = VASurface::createSharedVaSurface(&context, &vaSharing->m_sharingFunctions,
|
||||
CL_MEM_READ_WRITE, &vaSurfaceId, 0, &errCode);
|
||||
EXPECT_NE(nullptr, vaSurface);
|
||||
EXPECT_NE(nullptr, vaSurface->getGraphicsAllocation());
|
||||
EXPECT_EQ(4096u, vaSurface->getGraphicsAllocation()->getUnderlyingBufferSize());
|
||||
EXPECT_EQ(1u, vaSurface->getGraphicsAllocation()->peekSharedHandle());
|
||||
|
||||
EXPECT_EQ(4096u, vaSurface->getSize());
|
||||
|
||||
auto handler = vaSurface->peekSharingHandler();
|
||||
ASSERT_NE(nullptr, handler);
|
||||
|
||||
auto vaHandler = static_cast<VASharing *>(handler);
|
||||
EXPECT_EQ(vaHandler->peekFunctionsHandler(), &vaSharing->m_sharingFunctions);
|
||||
|
||||
EXPECT_EQ(1u, acquiredVaHandle);
|
||||
|
||||
EXPECT_EQ(1, vaDeriveImageCalled);
|
||||
EXPECT_EQ(1, vaDestroyImageCalled);
|
||||
EXPECT_EQ(1, vaExtGetSurfaceHandleCalled);
|
||||
|
||||
size_t paramSize = 0;
|
||||
void *paramValue = nullptr;
|
||||
handler->getMemObjectInfo(paramSize, paramValue);
|
||||
EXPECT_EQ(sizeof(VASurfaceID *), paramSize);
|
||||
VASurfaceID **paramSurfaceId = reinterpret_cast<VASurfaceID **>(paramValue);
|
||||
EXPECT_EQ(vaSurfaceId, **paramSurfaceId);
|
||||
|
||||
delete vaSurface;
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenContextWhenClCreateFromVaApiMediaSurfaceIsCalledThenSurfaceIsReturned) {
|
||||
sharedClMem = clCreateFromVA_APIMediaSurfaceINTEL(&context, CL_MEM_READ_WRITE, &vaSurfaceId, 0, &errCode);
|
||||
ASSERT_EQ(CL_SUCCESS, errCode);
|
||||
ASSERT_NE(nullptr, sharedClMem);
|
||||
|
||||
errCode = clReleaseMemObject(sharedClMem);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenVASurfaceWhenItIsAcquiredTwiceThenAcquireIsNotCalled) {
|
||||
createMediaSurface();
|
||||
|
||||
sharedImg->peekSharingHandler()->acquire(sharedImg);
|
||||
EXPECT_EQ(1, vaExtGetSurfaceHandleCalled);
|
||||
|
||||
sharedImg->peekSharingHandler()->acquire(sharedImg);
|
||||
EXPECT_EQ(1, vaExtGetSurfaceHandleCalled);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenHwCommandQueueWhenAcquireIsCalledThenAcquireCountIsNotIncremented) {
|
||||
auto commandQueue = clCreateCommandQueue(&context, context.getDevice(0), 0, &errCode);
|
||||
ASSERT_EQ(CL_SUCCESS, errCode);
|
||||
|
||||
createMediaSurface();
|
||||
|
||||
EXPECT_EQ(1, vaExtGetSurfaceHandleCalled);
|
||||
errCode = clEnqueueAcquireVA_APIMediaSurfacesINTEL(commandQueue, 1, &sharedClMem, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
EXPECT_EQ(1, vaExtGetSurfaceHandleCalled);
|
||||
|
||||
errCode = clEnqueueReleaseVA_APIMediaSurfacesINTEL(commandQueue, 1, &sharedClMem, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
|
||||
errCode = clEnqueueAcquireVA_APIMediaSurfacesINTEL(commandQueue, 1, &sharedClMem, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
EXPECT_EQ(1, vaExtGetSurfaceHandleCalled);
|
||||
|
||||
errCode = clReleaseCommandQueue(commandQueue);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenHwCommandQueueWhenAcquireAndReleaseCallsAreMadeWithEventsThenProperCmdTypeIsReturned) {
|
||||
cl_event retEvent = nullptr;
|
||||
cl_command_type cmdType = 0;
|
||||
size_t sizeReturned = 0;
|
||||
|
||||
createMediaSurface();
|
||||
|
||||
auto commandQueue = clCreateCommandQueue(&context, context.getDevice(0), 0, &errCode);
|
||||
errCode = clEnqueueAcquireVA_APIMediaSurfacesINTEL(commandQueue, 1, &sharedClMem, 0, nullptr, &retEvent);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
ASSERT_NE(retEvent, nullptr);
|
||||
|
||||
errCode = clGetEventInfo(retEvent, CL_EVENT_COMMAND_TYPE, sizeof(cmdType), &cmdType, &sizeReturned);
|
||||
ASSERT_EQ(CL_SUCCESS, errCode);
|
||||
EXPECT_EQ(static_cast<cl_command_type>(CL_COMMAND_ACQUIRE_VA_API_MEDIA_SURFACES_INTEL), cmdType);
|
||||
EXPECT_EQ(sizeof(cl_command_type), sizeReturned);
|
||||
|
||||
errCode = clReleaseEvent(retEvent);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
|
||||
errCode = clEnqueueReleaseVA_APIMediaSurfacesINTEL(commandQueue, 1, &sharedClMem, 0, nullptr, &retEvent);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
|
||||
errCode = clGetEventInfo(retEvent, CL_EVENT_COMMAND_TYPE, sizeof(cmdType), &cmdType, &sizeReturned);
|
||||
ASSERT_EQ(CL_SUCCESS, errCode);
|
||||
EXPECT_EQ(static_cast<cl_command_type>(CL_COMMAND_RELEASE_VA_API_MEDIA_SURFACES_INTEL), cmdType);
|
||||
EXPECT_EQ(sizeof(cl_command_type), sizeReturned);
|
||||
|
||||
errCode = clReleaseEvent(retEvent);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
errCode = clReleaseCommandQueue(commandQueue);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenVaMediaSurfaceWhenGetMemObjectInfoIsCalledThenSurfaceIdIsReturned) {
|
||||
createMediaSurface();
|
||||
|
||||
VASurfaceID *retVaSurfaceId = nullptr;
|
||||
size_t retSize = 0;
|
||||
errCode = clGetMemObjectInfo(sharedClMem, CL_MEM_VA_API_MEDIA_SURFACE_INTEL,
|
||||
sizeof(VASurfaceID *), &retVaSurfaceId, &retSize);
|
||||
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
EXPECT_EQ(sizeof(VASurfaceID *), retSize);
|
||||
EXPECT_EQ(vaSurfaceId, *retVaSurfaceId);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenVaMediaSurfaceWhenGetImageInfoIsCalledThenPlaneIsReturned) {
|
||||
cl_uint plane = 1u;
|
||||
createMediaSurface(plane);
|
||||
|
||||
cl_uint retPlane = 0u;
|
||||
size_t retSize = 0;
|
||||
errCode = clGetImageInfo(sharedClMem, CL_IMAGE_VA_API_PLANE_INTEL, sizeof(cl_uint), &retPlane, &retSize);
|
||||
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
EXPECT_EQ(sizeof(cl_uint), retSize);
|
||||
EXPECT_EQ(plane, retPlane);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenPlaneWhenCreateSurfaceIsCalledThenSetPlaneFields) {
|
||||
cl_uint planes[4] = {0, 1, 2, 3};
|
||||
updateAcquiredHandle(2);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
createMediaSurface(planes[i]);
|
||||
|
||||
EXPECT_TRUE(sharedImg->getSurfaceFormatInfo().OCLImageFormat.image_channel_data_type == CL_UNORM_INT8);
|
||||
|
||||
EXPECT_EQ(planes[i], sharedImg->getMediaPlaneType());
|
||||
if (planes[i] == 0u) {
|
||||
EXPECT_TRUE(sharedImg->getSurfaceFormatInfo().OCLImageFormat.image_channel_order == CL_R);
|
||||
} else if (planes[i] == 1) {
|
||||
EXPECT_TRUE(sharedImg->getSurfaceFormatInfo().OCLImageFormat.image_channel_order == CL_RG);
|
||||
} else {
|
||||
EXPECT_TRUE(sharedImg->getSurfaceFormatInfo().OCLImageFormat.image_channel_order == CL_NV12_INTEL);
|
||||
}
|
||||
|
||||
delete sharedImg;
|
||||
sharedImg = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenSimpleParamsWhenCreateSurfaceIsCalledThenSetImgObject) {
|
||||
updateAcquiredHandle(2);
|
||||
|
||||
createMediaSurface(3u);
|
||||
|
||||
EXPECT_TRUE(sharedImg->getImageDesc().buffer == nullptr);
|
||||
EXPECT_EQ(0u, sharedImg->getImageDesc().image_array_size);
|
||||
EXPECT_EQ(0u, sharedImg->getImageDesc().image_depth);
|
||||
EXPECT_EQ(mockVaImage.height, static_cast<unsigned short>(sharedImg->getImageDesc().image_height));
|
||||
EXPECT_EQ(mockVaImage.width, static_cast<unsigned short>(sharedImg->getImageDesc().image_width));
|
||||
EXPECT_TRUE(CL_MEM_OBJECT_IMAGE2D == sharedImg->getImageDesc().image_type);
|
||||
EXPECT_EQ(0u, sharedImg->getImageDesc().image_slice_pitch);
|
||||
EXPECT_NE(0u, sharedImg->getImageDesc().image_row_pitch);
|
||||
EXPECT_EQ(0u, sharedImg->getHostPtrSlicePitch());
|
||||
EXPECT_NE(0u, sharedImg->getHostPtrRowPitch());
|
||||
EXPECT_TRUE(sharedImg->getFlags() == CL_MEM_READ_WRITE);
|
||||
EXPECT_TRUE(sharedImg->getCubeFaceIndex() == __GMM_NO_CUBE_MAP);
|
||||
|
||||
EXPECT_EQ(vaSharing->sharingHandle, sharedImg->getGraphicsAllocation()->peekSharedHandle());
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenNonInteropUserSyncContextWhenAcquireIsCalledThenSyncSurface) {
|
||||
context.setInteropUserSyncEnabled(false);
|
||||
|
||||
createMediaSurface();
|
||||
|
||||
auto memObj = castToObject<MemObj>(sharedClMem);
|
||||
|
||||
EXPECT_EQ(0, vaSyncSurfaceCalled);
|
||||
memObj->peekSharingHandler()->acquire(sharedImg);
|
||||
EXPECT_EQ(1, vaSyncSurfaceCalled);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenInteropUserSyncContextWhenAcquireIsCalledThenDontSyncSurface) {
|
||||
context.setInteropUserSyncEnabled(true);
|
||||
|
||||
createMediaSurface();
|
||||
|
||||
EXPECT_EQ(0, vaSyncSurfaceCalled);
|
||||
sharedImg->peekSharingHandler()->acquire(sharedImg);
|
||||
EXPECT_EQ(0, vaSyncSurfaceCalled);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenYuvPlaneWhenCreateIsCalledThenChangeWidthAndHeight) {
|
||||
cl_uint planeTypes[4] = {
|
||||
0, //Y
|
||||
1, //U
|
||||
2, //no-plane
|
||||
};
|
||||
|
||||
context.setInteropUserSyncEnabled(true);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
createMediaSurface(planeTypes[i]);
|
||||
size_t retParam;
|
||||
|
||||
errCode = clGetImageInfo(sharedClMem, CL_IMAGE_WIDTH, sizeof(size_t), &retParam, nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
if (planeTypes[i] == 1) {
|
||||
EXPECT_EQ(128u, retParam);
|
||||
} else {
|
||||
EXPECT_EQ(256u, retParam);
|
||||
}
|
||||
|
||||
errCode = clGetImageInfo(sharedClMem, CL_IMAGE_HEIGHT, sizeof(size_t), &retParam, nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
if (planeTypes[i] == 1) {
|
||||
EXPECT_EQ(128u, retParam);
|
||||
} else {
|
||||
EXPECT_EQ(256u, retParam);
|
||||
}
|
||||
delete sharedImg;
|
||||
sharedImg = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenVaSurfaceWhenCreateImageFromParentThenShareHandler) {
|
||||
context.setInteropUserSyncEnabled(true);
|
||||
|
||||
createMediaSurface(2u);
|
||||
EXPECT_TRUE(sharedImg->getSurfaceFormatInfo().OCLImageFormat.image_channel_order == CL_NV12_INTEL);
|
||||
|
||||
cl_image_desc imgDesc = {};
|
||||
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
imgDesc.image_width = 256;
|
||||
imgDesc.image_height = 256;
|
||||
imgDesc.mem_object = sharedClMem;
|
||||
|
||||
cl_image_format imgFormat = {CL_R, CL_UNORM_INT8};
|
||||
|
||||
auto childImg = clCreateImage(&context, CL_MEM_READ_WRITE, &imgFormat, &imgDesc, nullptr, &errCode);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
|
||||
auto childImgObj = castToObject<Image>(childImg);
|
||||
EXPECT_FALSE(childImgObj->getIsObjectRedescribed());
|
||||
|
||||
EXPECT_EQ(sharedImg->peekSharingHandler(), childImgObj->peekSharingHandler());
|
||||
|
||||
errCode = clReleaseMemObject(childImg);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenVaSurfaceWhenCreateImageFromParentThenSetMediaPlaneType) {
|
||||
context.setInteropUserSyncEnabled(true);
|
||||
|
||||
createMediaSurface(2u);
|
||||
EXPECT_TRUE(sharedImg->getSurfaceFormatInfo().OCLImageFormat.image_channel_order == CL_NV12_INTEL);
|
||||
|
||||
cl_image_desc imgDesc = {};
|
||||
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
imgDesc.image_width = 256;
|
||||
imgDesc.image_height = 256;
|
||||
imgDesc.image_depth = 0; // Y plane
|
||||
imgDesc.mem_object = sharedClMem;
|
||||
|
||||
cl_image_format imgFormat = {CL_R, CL_UNORM_INT8};
|
||||
|
||||
auto childImg = clCreateImage(&context, CL_MEM_READ_WRITE, &imgFormat, &imgDesc, nullptr, &errCode);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
|
||||
auto childImgObj = castToObject<Image>(childImg);
|
||||
|
||||
EXPECT_EQ(childImgObj->getMediaPlaneType(), 0u);
|
||||
|
||||
errCode = clReleaseMemObject(childImg);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
|
||||
imgDesc.image_depth = 1; // U plane
|
||||
imgFormat.image_channel_order = CL_RG;
|
||||
childImg = clCreateImage(&context, CL_MEM_READ_WRITE, &imgFormat, &imgDesc, nullptr, &errCode);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
|
||||
childImgObj = castToObject<Image>(childImg);
|
||||
|
||||
EXPECT_EQ(childImgObj->getMediaPlaneType(), 1u);
|
||||
|
||||
errCode = clReleaseMemObject(childImg);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenContextWhenEmptySharingTableEmptyThenReturnsNullptr) {
|
||||
MockContext context;
|
||||
context.clearSharingFunctions();
|
||||
VASharingFunctions *sharingF = context.getSharing<VASharingFunctions>();
|
||||
EXPECT_EQ(sharingF, nullptr);
|
||||
}
|
41
unit_tests/sharings/va/variable_backup.h
Normal file
41
unit_tests/sharings/va/variable_backup.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
template <typename T>
|
||||
class VariableBackup {
|
||||
public:
|
||||
VariableBackup(T *ptr) : pValue(ptr) {
|
||||
oldValue = *ptr;
|
||||
}
|
||||
~VariableBackup() {
|
||||
*pValue = oldValue;
|
||||
}
|
||||
void operator=(const T &val) {
|
||||
*pValue = val;
|
||||
}
|
||||
|
||||
private:
|
||||
T oldValue;
|
||||
T *pValue;
|
||||
};
|
Reference in New Issue
Block a user