Extract tests to windows directory

Related-To: NEO-3599
Change-Id: Ibb5be80ae0e1096e21de2e08d900e0e7f15666bc
Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
This commit is contained in:
Maciej Dziuban
2020-01-20 11:44:59 +01:00
committed by sys_ocldev
parent 807a52f3cf
commit 6464fda1b2
5 changed files with 111 additions and 116 deletions

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2017-2018 Intel Corporation
# Copyright (C) 2017-2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@@ -8,6 +8,8 @@ if(WIN32)
set(IGDRCL_SRCS_tests_context_gl
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/context_gl_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/context_gl_tests.h
)
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_context_gl})
endif()
add_subdirectories()

View File

@@ -5,125 +5,17 @@
*
*/
#include "core/helpers/options.h"
#include "core/unit_tests/helpers/debug_manager_state_restore.h"
#include "runtime/context/context.h"
#include "runtime/device/device.h"
#include "runtime/device_queue/device_queue.h"
#include "runtime/os_interface/windows/gl/gl_sharing_os.h"
#include "runtime/sharings/gl/windows/gl_sharing.h"
#include "unit_tests/fixtures/platform_fixture.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_deferred_deleter.h"
#include "unit_tests/mocks/mock_device.h"
#include "unit_tests/mocks/mock_memory_manager.h"
#include "unit_tests/context/gl/context_gl_tests.h"
#include "gtest/gtest.h"
#include <GL/gl.h>
#include "runtime/sharings/gl/gl_sharing.h"
using namespace NEO;
namespace NEO {
// use mockGlSharing class for cl-gl sharing tests
typedef bool (*MockGlIoctlFcn)();
struct ContextTest : public PlatformFixture, public ::testing::Test {
using PlatformFixture::SetUp;
void SetUp() override {
PlatformFixture::SetUp();
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<MockContext>(properties, ClDeviceVector(devices, num_devices), nullptr, nullptr, retVal);
ASSERT_NE(nullptr, context);
}
void TearDown() override {
delete[] properties;
delete context;
PlatformFixture::TearDown();
}
cl_int retVal = CL_SUCCESS;
MockContext *context = nullptr;
cl_context_properties *properties = nullptr;
};
TEST_F(ContextTest, GlSharingAreIstPresentByDefault) { ASSERT_EQ(context->getSharing<GLSharingFunctions>(), nullptr); }
TEST_F(ContextTest, GivenPropertiesWhenContextIsCreatedThenSuccess) {
cl_device_id deviceID = devices[0];
auto pPlatform = NEO::platform();
cl_platform_id pid[1];
pid[0] = pPlatform;
cl_context_properties validProperties[] = {CL_CONTEXT_PLATFORM, (cl_context_properties)pid[0], CL_GL_CONTEXT_KHR, 0x10000, 0};
auto context = Context::create<Context>(validProperties, ClDeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
validProperties[2] = CL_EGL_DISPLAY_KHR;
context = Context::create<Context>(validProperties, ClDeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
validProperties[2] = CL_GLX_DISPLAY_KHR;
context = Context::create<Context>(validProperties, ClDeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
validProperties[2] = CL_WGL_HDC_KHR;
context = Context::create<Context>(validProperties, ClDeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
TEST_F(GlContextTest, GivenDefaultContextThenGlSharingIsDisabled) {
ASSERT_EQ(context->getSharing<GLSharingFunctions>(), nullptr);
}
TEST_F(ContextTest, GivenTwoGlPropertiesWhenContextIsCreatedThenSuccess) {
cl_device_id deviceID = devices[0];
auto pPlatform = NEO::platform();
cl_platform_id pid[1];
pid[0] = pPlatform;
cl_context_properties validProperties[] = {
CL_CONTEXT_PLATFORM, (cl_context_properties)pid[0], CL_GL_CONTEXT_KHR, 0x10000, CL_GL_CONTEXT_KHR, 0x10000, 0};
validProperties[4] = CL_EGL_DISPLAY_KHR;
auto context = Context::create<Context>(validProperties, ClDeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
validProperties[4] = CL_GLX_DISPLAY_KHR;
context = Context::create<Context>(validProperties, ClDeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
validProperties[4] = CL_WGL_HDC_KHR;
context = Context::create<Context>(validProperties, ClDeviceVector(&deviceID, 1), nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, context);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete context;
}
TEST_F(ContextTest, GivenGlContextParamWhenCreateContextThenInitSharingFunctions) {
TEST_F(GlContextTest, GivenGlContextParamWhenCreateContextThenInitSharingFunctions) {
cl_device_id deviceID = devices[0];
auto pPlatform = NEO::platform();
cl_platform_id pid[1];
@@ -135,10 +27,10 @@ TEST_F(ContextTest, GivenGlContextParamWhenCreateContextThenInitSharingFunctions
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, ctx);
//
auto sharing = ctx->getSharing<GLSharingFunctions>();
ASSERT_NE(nullptr, sharing);
EXPECT_FALSE(context->getInteropUserSyncEnabled());
delete ctx;
}
} // namespace NEO

View File

@@ -0,0 +1,60 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "unit_tests/fixtures/platform_fixture.h"
#include "unit_tests/mocks/mock_context.h"
#include "gtest/gtest.h"
#include <GL/gl.h>
namespace NEO {
struct GlContextTest : public PlatformFixture, public ::testing::Test {
using PlatformFixture::SetUp;
void SetUp() override {
PlatformFixture::SetUp();
properties[0] = CL_CONTEXT_PLATFORM;
properties[1] = reinterpret_cast<cl_context_properties>(static_cast<cl_platform_id>(pPlatform));
properties[2] = 0;
context = Context::create<MockContext>(properties, ClDeviceVector(devices, num_devices), nullptr, nullptr, retVal);
ASSERT_NE(nullptr, context);
}
void TearDown() override {
delete context;
PlatformFixture::TearDown();
}
void testContextCreation(cl_context_properties contextType) {
const cl_device_id deviceID = devices[0];
const auto platformId = reinterpret_cast<cl_context_properties>(static_cast<cl_platform_id>(platform()));
const cl_context_properties propertiesOneContext[] = {CL_CONTEXT_PLATFORM, platformId, contextType, 0x10000, 0};
auto context = std::unique_ptr<Context>(Context::create<Context>(propertiesOneContext, ClDeviceVector(&deviceID, 1), nullptr, nullptr, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, context.get());
EXPECT_FALSE(context->getInteropUserSyncEnabled());
const cl_context_properties propertiesTwoContexts[] = {CL_CONTEXT_PLATFORM, platformId, contextType, 0x10000, contextType, 0x10000, 0};
context = std::unique_ptr<Context>(Context::create<Context>(propertiesTwoContexts, ClDeviceVector(&deviceID, 1), nullptr, nullptr, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, context.get());
EXPECT_FALSE(context->getInteropUserSyncEnabled());
}
cl_int retVal = CL_SUCCESS;
MockContext *context = nullptr;
cl_context_properties properties[3] = {};
};
} // namespace NEO

View File

@@ -0,0 +1,13 @@
#
# Copyright (C) 2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(WIN32)
set(IGDRCL_SRCS_tests_context_gl_windows
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/context_gl_tests_windows.cpp
)
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_context_gl_windows})
endif()

View File

@@ -0,0 +1,28 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "unit_tests/context/gl/context_gl_tests.h"
namespace NEO {
TEST_F(GlContextTest, GivenClGlContextWhenContextIsCreatedThenSuccess) {
testContextCreation(CL_GL_CONTEXT_KHR);
}
TEST_F(GlContextTest, GivenEglContextWhenContextIsCreatedThenSuccess) {
testContextCreation(CL_EGL_DISPLAY_KHR);
}
TEST_F(GlContextTest, GivenGlxContextWhenContextIsCreatedThenSuccess) {
testContextCreation(CL_GLX_DISPLAY_KHR);
}
TEST_F(GlContextTest, GivenWglContextWhenContextIsCreatedThenSuccess) {
testContextCreation(CL_WGL_HDC_KHR);
}
} // namespace NEO