From 5426b34ea97a6990c1ea3337917d20ba6a42609e Mon Sep 17 00:00:00 2001 From: Mraghuwa Date: Mon, 20 Apr 2020 18:27:57 +0530 Subject: [PATCH] Add Tools ULT for level zero Change-Id: Id4625b9c3fdadfb164d51a96a94af2dc0b49fa4b Signed-off-by: Mraghuwa --- level_zero/CMakeLists.txt | 2 + level_zero/tools/test/CMakeLists.txt | 7 + .../tools/test/unit_tests/CMakeLists.txt | 83 ++++++++++++ level_zero/tools/test/unit_tests/main.cpp | 125 ++++++++++++++++++ level_zero/tools/test/unit_tests/test_mode.h | 14 ++ .../test/unit_tests/ult_configuration.cpp | 12 ++ 6 files changed, 243 insertions(+) create mode 100644 level_zero/tools/test/CMakeLists.txt create mode 100644 level_zero/tools/test/unit_tests/CMakeLists.txt create mode 100644 level_zero/tools/test/unit_tests/main.cpp create mode 100644 level_zero/tools/test/unit_tests/test_mode.h create mode 100644 level_zero/tools/test/unit_tests/ult_configuration.cpp diff --git a/level_zero/CMakeLists.txt b/level_zero/CMakeLists.txt index cbf08c4bc2..6413b1daba 100644 --- a/level_zero/CMakeLists.txt +++ b/level_zero/CMakeLists.txt @@ -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() diff --git a/level_zero/tools/test/CMakeLists.txt b/level_zero/tools/test/CMakeLists.txt new file mode 100644 index 0000000000..1e8ca6b45a --- /dev/null +++ b/level_zero/tools/test/CMakeLists.txt @@ -0,0 +1,7 @@ +# +# Copyright (C) 2020 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +add_subdirectories() diff --git a/level_zero/tools/test/unit_tests/CMakeLists.txt b/level_zero/tools/test/unit_tests/CMakeLists.txt new file mode 100644 index 0000000000..90004615fe --- /dev/null +++ b/level_zero/tools/test/unit_tests/CMakeLists.txt @@ -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 + $ +) + +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_include_directories(${TARGET_NAME} + BEFORE + PRIVATE + $/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 + $ + $ +) + +create_source_tree(${TARGET_NAME} ${L0_ROOT_DIR}/..) diff --git a/level_zero/tools/test/unit_tests/main.cpp b/level_zero/tools/test/unit_tests/main.cpp new file mode 100644 index 0000000000..0634bf772a --- /dev/null +++ b/level_zero/tools/test/unit_tests/main.cpp @@ -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 +#include +#include +#include + +#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 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 mockObj; + EXPECT_CALL(mockObj, method(::testing::_)) + .Times(1); + mockObj.method(2); + } + + //intialize rand + srand(static_cast(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 diff --git a/level_zero/tools/test/unit_tests/test_mode.h b/level_zero/tools/test/unit_tests/test_mode.h new file mode 100644 index 0000000000..b8a5b72982 --- /dev/null +++ b/level_zero/tools/test/unit_tests/test_mode.h @@ -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 diff --git a/level_zero/tools/test/unit_tests/ult_configuration.cpp b/level_zero/tools/test/unit_tests/ult_configuration.cpp new file mode 100644 index 0000000000..7da9a27131 --- /dev/null +++ b/level_zero/tools/test/unit_tests/ult_configuration.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "test_mode.h" + +namespace NEO { +TestMode testMode = defaultTestMode; +} // namespace NEO