Add Tools ULT for level zero

Change-Id: Id4625b9c3fdadfb164d51a96a94af2dc0b49fa4b
Signed-off-by: Mraghuwa <mayank.raghuwanshi@intel.com>
This commit is contained in:
Mraghuwa
2020-04-20 18:27:57 +05:30
committed by sys_ocldev
parent a8269f55f9
commit 5426b34ea9
6 changed files with 243 additions and 0 deletions

View File

@ -436,8 +436,10 @@ else()
endif()
if(NOT SKIP_L0_UNIT_TESTS)
add_subdirectory_unique(core/test)
add_subdirectory_unique(tools/test)
else()
hide_subdir(core/test)
hide_subdir(tools/test)
endif()
add_subdirectories()

View File

@ -0,0 +1,7 @@
#
# Copyright (C) 2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
add_subdirectories()

View File

@ -0,0 +1,83 @@
#
# Copyright (C) 2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(TARGET_NAME ${TARGET_NAME_L0}_tools_tests)
append_sources_from_properties(L0_CORE_ENABLERS NEO_CORE_SRCS_LINK)
add_executable(${TARGET_NAME}
${NEO_SOURCE_DIR}/level_zero/core/source/dll/disallow_deferred_deleter.cpp
${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_management.h
${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_management.cpp
${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_leak_listener.h
${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_leak_listener.cpp
${L0_CORE_ENABLERS}
)
target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_mode.h
${CMAKE_CURRENT_SOURCE_DIR}/ult_configuration.cpp
${NEO_SHARED_TEST_DIRECTORY}/unit_test/tests_configuration.h
)
target_sources(${TARGET_NAME} PRIVATE
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/libult/create_command_stream.cpp
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/libult/io_functions.cpp
$<TARGET_OBJECTS:${L0_MOCKABLE_LIB_NAME}>
)
if (UNIX)
target_sources(${TARGET_NAME} PRIVATE
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/linux/create_drm_memory_manager.cpp
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/linux/drm_neo_create.cpp
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/linux/options.cpp
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/linux/sys_calls_linux_ult.cpp
)
else()
target_sources(${TARGET_NAME} PRIVATE
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/create_wddm_memory_manager.cpp
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/options.cpp
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/sys_calls.cpp
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/wddm_create.cpp
)
endif()
set_target_properties(${TARGET_NAME} PROPERTIES FOLDER ${TARGET_NAME_L0})
add_subdirectoriesL0(${CMAKE_CURRENT_SOURCE_DIR} "*")
target_compile_definitions(${TARGET_NAME} PRIVATE $<TARGET_PROPERTY:${L0_MOCKABLE_LIB_NAME},INTERFACE_COMPILE_DEFINITIONS>)
target_include_directories(${TARGET_NAME}
BEFORE
PRIVATE
$<TARGET_PROPERTY:${TARGET_NAME_L0},SOURCE_DIR>/tools
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros${BRANCH_DIR_SUFFIX}
)
if (UNIX)
target_link_libraries(${TARGET_NAME} pthread rt)
else()
target_link_libraries(${TARGET_NAME} dbghelp)
endif()
target_link_libraries(${TARGET_NAME}
${NEO_STATICALLY_LINKED_LIBRARIES_MOCKABLE}
compute_runtime_mockable_extra
${HW_LIBS_ULT}
gmock-gtest
)
target_sources(${TARGET_NAME} PRIVATE
$<TARGET_OBJECTS:mock_gmm>
$<TARGET_OBJECTS:${TARGET_NAME_L0}_mocks>
)
create_source_tree(${TARGET_NAME} ${L0_ROOT_DIR}/..)

View File

@ -0,0 +1,125 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/hw_info.h"
#include "shared/test/unit_test/helpers/default_hw_info.inl"
#include "shared/test/unit_test/helpers/memory_leak_listener.h"
#include "shared/test/unit_test/helpers/ult_hw_config.inl"
#include "opencl/source/utilities/logger.h"
#include "opencl/test/unit_test/custom_event_listener.h"
#include "opencl/test/unit_test/mocks/mock_gmm_client_context.h"
#include "opencl/test/unit_test/mocks/mock_sip.h"
#include "gmock/gmock.h"
#include <fstream>
#include <mutex>
#include <sstream>
#include <thread>
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
#endif
#ifdef WIN32
const char *fSeparator = "\\";
#else
const char *fSeparator = "/";
#endif
TEST(Should, pass) { EXPECT_TRUE(true); }
namespace L0 {
namespace ult {
::testing::Environment *environment = nullptr;
}
} // namespace L0
std::thread::id tempThreadID;
void applyWorkarounds() {
NEO::platformsImpl.reserve(1);
{
std::ofstream f;
const std::string fileName("_tmp_");
f.open(fileName, std::ofstream::binary);
f.close();
}
{
std::mutex mtx;
std::unique_lock<std::mutex> stateLock(mtx);
}
{
std::stringstream ss("1");
int val;
ss >> val;
}
{
class BaseClass {
public:
int method(int param) { return 1; }
};
class MockClass : public BaseClass {
public:
MOCK_METHOD1(method, int(int param));
};
::testing::NiceMock<MockClass> mockObj;
EXPECT_CALL(mockObj, method(::testing::_))
.Times(1);
mockObj.method(2);
}
//intialize rand
srand(static_cast<unsigned int>(time(nullptr)));
//Create at least on thread to prevent false memory leaks in tests using threads
std::thread t([&]() {
});
tempThreadID = t.get_id();
t.join();
//Create FileLogger to prevent false memory leaks
{
NEO::FileLoggerInstance();
}
}
int main(int argc, char **argv) {
bool useDefaultListener = false;
applyWorkarounds();
testing::InitGoogleMock(&argc, argv);
auto &listeners = ::testing::UnitTest::GetInstance()->listeners();
if (useDefaultListener == false) {
::testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
::testing::TestEventListener *defaultListener = listeners.default_result_printer();
auto customEventListener = new CCustomEventListener(defaultListener);
listeners.Release(listeners.default_result_printer());
listeners.Append(customEventListener);
}
listeners.Append(new NEO::MemoryLeakListener);
if (L0::ult::environment) {
::testing::AddGlobalTestEnvironment(L0::ult::environment);
}
auto retVal = RUN_ALL_TESTS();
return retVal;
}
#if defined(__clang__)
#pragma clang diagnostic pop
#endif

View File

@ -0,0 +1,14 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/test/unit_test/tests_configuration.h"
namespace NEO {
constexpr TestMode defaultTestMode = TestMode::UnitTests;
} // namespace NEO

View File

@ -0,0 +1,12 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "test_mode.h"
namespace NEO {
TestMode testMode = defaultTestMode;
} // namespace NEO