Move GMM_INIT_IN_ARGS initialization to dll tests

Change-Id: I8f647c0ecf737492995d34ba6c0344325fdad48a
Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com>
This commit is contained in:
Bartosz Dunajski 2020-03-16 16:58:04 +01:00 committed by sys_ocldev
parent d07e5563f5
commit 265b0c9aa0
13 changed files with 90 additions and 84 deletions

View File

@ -7,8 +7,15 @@
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/source/gmm_helper/gmm_interface.h"
#include "shared/source/os_interface/linux/drm_neo.h"
namespace NEO {
bool OSInterface::osEnableLocalMemory = true;
} // namespace NEO
void OSInterface::setGmmInputArgs(void *args) {
reinterpret_cast<GMM_INIT_IN_ARGS *>(args)->FileDescriptor = this->get()->getDrm()->getFileDescriptor();
}
} // namespace NEO

View File

@ -8,8 +8,14 @@
#include "shared/source/os_interface/windows/os_interface.h"
#include "shared/source/memory_manager/memory_constants.h"
#include "shared/source/os_interface/windows/wddm/wddm.h"
namespace NEO {
bool OSInterface::osEnableLocalMemory = true;
void OSInterface::setGmmInputArgs(void *args) {
this->get()->getWddm()->setGmmInputArg(args);
}
} // namespace NEO

View File

@ -24,7 +24,6 @@ if(WIN32)
else()
append_sources_from_properties(NEO_CORE_UNIT_TESTS_SOURCES
NEO_CORE_DIRECT_SUBMISSION_LINUX_TESTS
NEO_CORE_OS_INTERFACE_TESTS_LINUX
)
endif()

View File

@ -13,4 +13,6 @@ namespace NEO {
bool OSInterface::osEnableLocalMemory = true;
void OSInterface::setGmmInputArgs(void *args) {}
} // namespace NEO

View File

@ -18,6 +18,7 @@ add_executable(igdrcl_${target_name}
${CMAKE_CURRENT_SOURCE_DIR}/main_linux_dll.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_os_layer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_os_layer.h
${CMAKE_CURRENT_SOURCE_DIR}/os_interface_linux_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_mode.h
${NEO_SHARED_DIRECTORY}/os_interface/linux/sys_calls_linux.cpp
${NEO_SOURCE_DIR}/opencl/source/dll/linux/allocator_helper.cpp

View File

@ -0,0 +1,49 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/test/unit_test/helpers/default_hw_info.h"
#include "opencl/test/unit_test/helpers/variable_backup.h"
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"
#include "opencl/test/unit_test/os_interface/linux/drm_mock.h"
#include "test.h"
namespace NEO {
extern GMM_INIT_IN_ARGS passedInputArgs;
extern bool copyInputArgs;
TEST(OsInterfaceTest, whenOsInterfaceSetupsGmmInputArgsThenProperFileDescriptorIsSet) {
MockExecutionEnvironment executionEnvironment;
auto rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[0].get();
auto osInterface = new OSInterface();
rootDeviceEnvironment->osInterface.reset(osInterface);
auto drm = new DrmMock(*rootDeviceEnvironment);
osInterface->get()->setDrm(drm);
GMM_INIT_IN_ARGS gmmInputArgs = {};
EXPECT_EQ(0u, gmmInputArgs.FileDescriptor);
osInterface->setGmmInputArgs(&gmmInputArgs);
EXPECT_NE(0u, gmmInputArgs.FileDescriptor);
auto expectedFileDescriptor = drm->getFileDescriptor();
EXPECT_EQ(static_cast<uint32_t>(expectedFileDescriptor), gmmInputArgs.FileDescriptor);
}
TEST(GmmHelperTest, whenCreateGmmHelperWithoutOsInterfaceThenPassedFileDescriptorIsZeroed) {
std::unique_ptr<GmmHelper> gmmHelper;
VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs);
VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(&copyInputArgs, true);
uint32_t expectedFileDescriptor = 0u;
gmmHelper.reset(new GmmHelper(nullptr, platformDevices[0]));
EXPECT_EQ(expectedFileDescriptor, passedInputArgs.FileDescriptor);
}
} // namespace NEO

View File

@ -27,19 +27,4 @@ TEST(OsInterfaceTest, GivenLinuxOsInterfaceWhenDeviceHandleQueriedthenZeroIsRetu
EXPECT_EQ(0u, osInterface.getDeviceHandle());
}
TEST(OsInterfaceTest, whenOsInterfaceSetupsGmmInputArgsThenProperFileDescriptorIsSet) {
MockExecutionEnvironment executionEnvironment;
auto rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[0].get();
auto osInterface = new OSInterface();
rootDeviceEnvironment->osInterface.reset(osInterface);
auto drm = Drm::create(nullptr, *rootDeviceEnvironment);
osInterface->get()->setDrm(drm);
GMM_INIT_IN_ARGS gmmInputArgs = {};
EXPECT_EQ(0u, gmmInputArgs.FileDescriptor);
osInterface->setGmmInputArgs(&gmmInputArgs);
EXPECT_NE(0u, gmmInputArgs.FileDescriptor);
uint32_t expectedFileDescriptor = drm->getFileDescriptor();
EXPECT_EQ(expectedFileDescriptor, gmmInputArgs.FileDescriptor);
}
} // namespace NEO

View File

@ -40,19 +40,3 @@ TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInit
EXPECT_EQ(osContext->getWddm(), wddm);
EXPECT_EQ(1u, wddm->registerTrimCallbackResult.called);
}
TEST_F(OsInterfaceTest, whenOsInterfaceSetupGmmInputArgsThenProperAdapterBDFIsSet) {
MockExecutionEnvironment executionEnvironment;
RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment);
auto wddm = new WddmMock(rootDeviceEnvironment);
osInterface->get()->setWddm(wddm);
wddm->init();
auto &adapterBDF = wddm->adapterBDF;
adapterBDF.Bus = 0x12;
adapterBDF.Device = 0x34;
adapterBDF.Function = 0x56;
GMM_INIT_IN_ARGS gmmInputArgs = {};
EXPECT_NE(0, memcmp(&adapterBDF, &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF)));
osInterface->setGmmInputArgs(&gmmInputArgs);
EXPECT_EQ(0, memcmp(&adapterBDF, &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF)));
}

View File

@ -8,8 +8,31 @@
#include "shared/source/memory_manager/memory_constants.h"
#include "shared/source/os_interface/windows/os_interface.h"
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"
#include "opencl/test/unit_test/mocks/mock_wddm.h"
#include "test.h"
using namespace NEO;
TEST(osInterfaceTests, osInterfaceLocalMemoryEnabledByDefault) {
EXPECT_TRUE(NEO::OSInterface::osEnableLocalMemory);
EXPECT_TRUE(OSInterface::osEnableLocalMemory);
}
TEST(osInterfaceTests, whenOsInterfaceSetupGmmInputArgsThenProperAdapterBDFIsSet) {
MockExecutionEnvironment executionEnvironment;
RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment);
auto wddm = new WddmMock(rootDeviceEnvironment);
OSInterface osInterface;
osInterface.get()->setWddm(wddm);
wddm->init();
auto &adapterBDF = wddm->adapterBDF;
adapterBDF.Bus = 0x12;
adapterBDF.Device = 0x34;
adapterBDF.Function = 0x56;
GMM_INIT_IN_ARGS gmmInputArgs = {};
EXPECT_NE(0, memcmp(&adapterBDF, &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF)));
osInterface.setGmmInputArgs(&gmmInputArgs);
EXPECT_EQ(0, memcmp(&adapterBDF, &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF)));
}

View File

@ -40,10 +40,6 @@ uint32_t OSInterface::getDeviceHandle() const {
return 0;
}
void OSInterface::setGmmInputArgs(void *args) {
reinterpret_cast<GMM_INIT_IN_ARGS *>(args)->FileDescriptor = this->get()->getDrm()->getFileDescriptor();
}
bool RootDeviceEnvironment::initOsInterface(std::unique_ptr<HwDeviceId> &&hwDeviceId) {
Drm *drm = Drm::create(std::move(hwDeviceId), *this);
if (!drm) {

View File

@ -28,10 +28,6 @@ uint32_t OSInterface::getDeviceHandle() const {
return static_cast<uint32_t>(osInterfaceImpl->getDeviceHandle());
}
void OSInterface::setGmmInputArgs(void *args) {
this->get()->getWddm()->setGmmInputArg(args);
}
OSInterface::OSInterfaceImpl::OSInterfaceImpl() = default;
D3DKMT_HANDLE OSInterface::OSInterfaceImpl::getAdapterHandle() const {

View File

@ -1,11 +0,0 @@
#
# Copyright (C) 2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(NEO_CORE_OS_INTERFACE_TESTS_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/gmm_helper_tests_linux.cpp
)
set_property(GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_TESTS_LINUX ${NEO_CORE_OS_INTERFACE_TESTS_LINUX})

View File

@ -1,31 +0,0 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/test/unit_test/helpers/default_hw_info.h"
#include "opencl/test/unit_test/helpers/variable_backup.h"
#include "gtest/gtest.h"
namespace NEO {
extern GMM_INIT_IN_ARGS passedInputArgs;
extern bool copyInputArgs;
TEST(GmmHelperTest, whenCreateGmmHelperWithoutOsInterfaceThenPassedFileDescriptorIsZeroed) {
std::unique_ptr<GmmHelper> gmmHelper;
VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs);
VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(&copyInputArgs, true);
uint32_t expectedFileDescriptor = 0u;
gmmHelper.reset(new GmmHelper(nullptr, platformDevices[0]));
EXPECT_EQ(expectedFileDescriptor, passedInputArgs.FileDescriptor);
}
} // namespace NEO