diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e6c98aaeb..2db31b7d81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -854,7 +854,6 @@ set(BUILTINS_VME_LIB_NAME "builtins_vme") set(SCHEDULER_BINARY_LIB_NAME "scheduler_binary") add_subdirectory_unique(shared/source) -add_subdirectory_unique(shared/test/unit_test) macro(generate_runtime_lib LIB_NAME MOCKABLE GENERATE_EXEC) set(NEO_STATIC_LIB_NAME ${LIB_NAME}) @@ -908,6 +907,12 @@ endif() set(NEO_STATICALLY_LINKED_LIBRARIES ${NEO_RELEASE_LIB_NAME} ${NEO_SHARED_RELEASE_LIB_NAME} ${NEO_RELEASE_LIB_NAME} ${NEO_SHARED_RELEASE_LIB_NAME}) set(NEO_STATICALLY_LINKED_LIBRARIES_MOCKABLE ${NEO_MOCKABLE_LIB_NAME} ${NEO_SHARED_MOCKABLE_LIB_NAME} ${NEO_MOCKABLE_LIB_NAME} ${NEO_SHARED_MOCKABLE_LIB_NAME}) +if(NOT SKIP_UNIT_TESTS) + include(${CMAKE_CURRENT_SOURCE_DIR}/level_zero/cmake/${BRANCH_TYPE}/l0_tests.cmake) +endif() + +add_subdirectory_unique(shared/test/unit_test) + if(DEFAULT_TESTED_PLATFORM AND NOT SKIP_NEO_UNIT_TESTS) add_subdirectory_unique(${NEO_RUNTIME_TESTS_SUB_DIR} ${NEO_BUILD_DIR}/${NEO_RUNTIME_TESTS_SUB_DIR}) else() diff --git a/level_zero/CMakeLists.txt b/level_zero/CMakeLists.txt index 6413b1daba..5be3047a49 100644 --- a/level_zero/CMakeLists.txt +++ b/level_zero/CMakeLists.txt @@ -77,10 +77,6 @@ if(BUILD_WITH_L0 AND "${NEO_BITS}" STREQUAL "64") set(SKIP_L0_UNIT_TESTS TRUE) endif() - if(NOT SKIP_L0_UNIT_TESTS) - include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${BRANCH_TYPE}/l0_tests.cmake) - endif() - # Copy third_party_binaries to output BIN folder add_custom_target(copy_third_party_files) set_target_properties(copy_third_party_files PROPERTIES FOLDER ${TARGET_NAME_L0}) diff --git a/level_zero/cmake/l0_tests.cmake b/level_zero/cmake/l0_tests.cmake index e7d4d2d4a6..3b4c74cfea 100644 --- a/level_zero/cmake/l0_tests.cmake +++ b/level_zero/cmake/l0_tests.cmake @@ -8,8 +8,6 @@ ## L0 tests settings ## - -if(NOT SKIP_L0_UNIT_TESTS) # These need to be added to a project to enable platform support in ULTs if(TESTS_GEN8) set(COMPUTE_RUNTIME_ULT_GEN8 @@ -43,12 +41,10 @@ endif() ## ULT related settings #Extract compute runtime COMPILE_DEFINITIONS -if(NOT SKIP_L0_UNIT_TESTS) - get_property(COMPUTE_RUNTIME_MOCKABLE_DEFINITIONS - TARGET ${NEO_MOCKABLE_LIB_NAME} +get_property(COMPUTE_RUNTIME_MOCKABLE_DEFINITIONS +TARGET ${NEO_MOCKABLE_LIB_NAME} PROPERTY COMPILE_DEFINITIONS ) -endif() #Append additional definitions set(COMPUTE_RUNTIME_MOCKABLE_DEFINITIONS @@ -82,39 +78,38 @@ add_library(compute_runtime_mockable_extra ${NEO_SHARED_TEST_DIRECTORY}/unit_test/helpers/test_files.cpp ${NEO_SHARED_TEST_DIRECTORY}/unit_test/mocks/mock_compiler_interface.cpp ${NEO_SHARED_TEST_DIRECTORY}/unit_test/mocks/mock_compiler_interface.h - ${COMPUTE_RUNTIME_DIR}/opencl/source/aub/aub_stream_interface.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/abort.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/helpers/built_ins_helper.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/helpers/debug_helpers.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/libult/os_interface.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/libult/source_level_debugger_ult.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/libult/source_level_debugger_library.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks/mock_cif.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks/mock_compilers.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks/mock_csr.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks/mock_gmm_page_table_mngr.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/libult/create_tbx_sockets.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks/mock_deferred_deleter.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks${BRANCH_SUFIX_DIR}/mock_gmm_client_context.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks/mock_gmm_client_context_base.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks/mock_memory_manager.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks/mock_program.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks/mock_sip.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/utilities/debug_settings_reader_creator.cpp - ${COMPUTE_RUNTIME_DIR}/shared/source/debug_settings/debug_settings_manager.cpp - ${COMPUTE_RUNTIME_DIR}/shared/test/unit_test/mocks/mock_device.cpp + ${NEO_SOURCE_DIR}/opencl/source/aub/aub_stream_interface.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/abort.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/helpers/built_ins_helper.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/helpers/debug_helpers.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/libult/os_interface.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/libult/source_level_debugger_ult.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/libult/source_level_debugger_library.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_cif.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_compilers.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_csr.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_gmm_page_table_mngr.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/libult/create_tbx_sockets.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_deferred_deleter.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks${BRANCH_SUFIX_DIR}/mock_gmm_client_context.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_gmm_client_context_base.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_gmm_resource_info.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_memory_manager.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_program.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_sip.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/utilities/debug_settings_reader_creator.cpp + ${NEO_SOURCE_DIR}/shared/source/debug_settings/debug_settings_manager.cpp + ${NEO_SOURCE_DIR}/shared/test/unit_test/mocks/mock_device.cpp ) set_property(TARGET compute_runtime_mockable_extra APPEND_STRING PROPERTY COMPILE_FLAGS ${ASAN_FLAGS} ${TSAN_FLAGS}) -set_target_properties(compute_runtime_mockable_extra PROPERTIES FOLDER ${TARGET_NAME_L0}) # These need to be added to a project to enable platform support in ULTs - #Additional includes for ULT builds target_include_directories(compute_runtime_mockable_extra PUBLIC ${COMPUTE_RUNTIME_MOCKABLE_INCLUDES} - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks/gmm_memory + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/gmm_memory ${SOURCE_LEVEL_DEBUGGER_HEADERS_DIR} ) @@ -131,10 +126,10 @@ target_link_libraries(compute_runtime_mockable_extra if(WIN32) target_sources(compute_runtime_mockable_extra PRIVATE - ${COMPUTE_RUNTIME_DIR}/shared/source/dll/windows/environment_variables.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks/mock_gmm_memory_base.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks/mock_wddm.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mocks/mock_compilers_windows.cpp + ${NEO_SOURCE_DIR}/shared/source/dll/windows/environment_variables.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_gmm_memory_base.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_wddm.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_compilers_windows.cpp ) target_link_libraries(compute_runtime_mockable_extra @@ -145,14 +140,12 @@ endif() if(UNIX) target_sources(compute_runtime_mockable_extra PRIVATE - ${COMPUTE_RUNTIME_DIR}/opencl/source/dll/linux/allocator_helper.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/source/tbx/tbx_sockets_imp.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/linux/drm_mock.cpp + ${NEO_SOURCE_DIR}/opencl/source/dll/linux/allocator_helper.cpp + ${NEO_SOURCE_DIR}/opencl/source/tbx/tbx_sockets_imp.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/drm_mock.cpp ) target_link_libraries(compute_runtime_mockable_extra dl ) endif() set_target_properties(compute_runtime_mockable_extra PROPERTIES POSITION_INDEPENDENT_CODE ON) -endif() - diff --git a/level_zero/core/test/unit_tests/CMakeLists.txt b/level_zero/core/test/unit_tests/CMakeLists.txt index fc939cb906..c7fa302bb2 100644 --- a/level_zero/core/test/unit_tests/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/CMakeLists.txt @@ -113,7 +113,7 @@ target_link_libraries(${TARGET_NAME} ) if(SKIP_NEO_UNIT_TESTS) - add_subdirectory(${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mock_gmm ${CMAKE_BINARY_DIR}/mock_gmm) + add_subdirectory(${NEO_SOURCE_DIR}/opencl/test/unit_test/mock_gmm ${CMAKE_BINARY_DIR}/mock_gmm) endif() target_sources(${TARGET_NAME} PRIVATE diff --git a/shared/test/unit_test/CMakeLists.txt b/shared/test/unit_test/CMakeLists.txt index 6ed28a7367..c524131c2c 100644 --- a/shared/test/unit_test/CMakeLists.txt +++ b/shared/test/unit_test/CMakeLists.txt @@ -4,4 +4,104 @@ # SPDX-License-Identifier: MIT # +if(NOT SKIP_NEO_UNIT_TESTS AND NOT SKIP_UNIT_TESTS) + +set(TARGET_NAME neo_shared_test) + +# disable optimizations for ults +if(UNIX) + string(REPLACE "-O2" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + #disable fortify source as this requires optimization to be on + string(REPLACE "-Wp,-D_FORTIFY_SOURCE=2" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + string(REPLACE "-D_FORTIFY_SOURCE=2" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O0") + set(CMAKE_CXX_FLAGS_RELEASEINTERNAL "${CMAKE_CXX_FLAGS_RELEASEINTERNAL} -O0") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O0") + set(CMAKE_C_FLAGS_RELEASEINTERNAL "${CMAKE_C_FLAGS_RELEASEINTERNAL} -O0") +endif() + +if(WIN32) + string(REPLACE "/O2" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + string(REPLACE "/O2" "/Od" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}) + string(REPLACE "/O2" "/Od" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE}) + string(REPLACE "/O2" "/Od" CMAKE_CXX_FLAGS_RELEASEINTERNAL ${CMAKE_CXX_FLAGS_RELEASEINTERNAL}) + string(REPLACE "/O2" "/Od" CMAKE_C_FLAGS_RELEASEINTERNAL ${CMAKE_C_FLAGS_RELEASEINTERNAL}) +endif() + +function(ADD_SUPPORTED_TEST_PRODUCT_FAMILIES_DEFINITION) + set(NEO_SUPPORTED_PRODUCT_FAMILIES ${ALL_PRODUCT_FAMILY_LIST}) + string(REPLACE ";" "," NEO_SUPPORTED_PRODUCT_FAMILIES "${NEO_SUPPORTED_PRODUCT_FAMILIES}") + add_definitions(-DSUPPORTED_TEST_PRODUCT_FAMILIES=${NEO_SUPPORTED_PRODUCT_FAMILIES}) +endfunction() + +ADD_SUPPORTED_TEST_PRODUCT_FAMILIES_DEFINITION() +link_libraries(${ASAN_LIBS} ${TSAN_LIBS}) + +append_sources_from_properties(CORE_ENABLERS NEO_CORE_SRCS_LINK) + +add_executable(${TARGET_NAME} + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_mode.h + ${CMAKE_CURRENT_SOURCE_DIR}/tests_configuration.h + ${CORE_ENABLERS} + ${NEO_SOURCE_DIR}/opencl/source/compiler_interface/default_cache_config.cpp + ${NEO_SOURCE_DIR}/opencl/source/dll/debugger.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/global_environment.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/helpers/kernel_binary_helper_hash_value.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/libult/create_command_stream.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/libult/io_functions.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/mocks/mock_platform.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/ult_configuration.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/ult_config_listener.cpp + ${NEO_SOURCE_DIR}/shared/offline_compiler/source/offline_compiler_helper.cpp + ${NEO_SOURCE_DIR}/shared/source/helpers/allow_deferred_deleter.cpp + ${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_management.cpp + ${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_leak_listener.cpp + $ +) + +if (UNIX) + target_sources(${TARGET_NAME} PRIVATE + ${NEO_SOURCE_DIR}/opencl/source/dll/linux/os_interface.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/create_drm_memory_manager.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/drm_neo_create.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/options.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/sys_calls_linux_ult.cpp + ) +else() + target_sources(${TARGET_NAME} PRIVATE + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/create_wddm_memory_manager.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/options.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/sys_calls.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/wddm_create.cpp + ) +endif() + +set_property(TARGET ${TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${ASAN_FLAGS}) + +target_include_directories(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${ENGINE_NODE_DIR} + ${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} + gmock-gtest + ${NEO_STATICALLY_LINKED_LIBRARIES_MOCKABLE} + compute_runtime_mockable_extra +) + +create_project_source_tree(${TARGET_NAME}) + +endif() + add_subdirectories() diff --git a/shared/test/unit_test/command_container/CMakeLists.txt b/shared/test/unit_test/command_container/CMakeLists.txt index 8d0a763084..e37bf8dd21 100644 --- a/shared/test/unit_test/command_container/CMakeLists.txt +++ b/shared/test/unit_test/command_container/CMakeLists.txt @@ -9,5 +9,6 @@ set(NEO_CORE_COMMAND_CONTAINER_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/command_container_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/command_encoder_tests.cpp ) + set_property(GLOBAL PROPERTY NEO_CORE_COMMAND_CONTAINER_TESTS ${NEO_CORE_COMMAND_CONTAINER_TESTS}) -add_subdirectories() \ No newline at end of file +add_subdirectories() diff --git a/shared/test/unit_test/main.cpp b/shared/test/unit_test/main.cpp new file mode 100644 index 0000000000..ef0f39fc05 --- /dev/null +++ b/shared/test/unit_test/main.cpp @@ -0,0 +1,420 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/gmm_helper/gmm_helper.h" +#include "shared/source/gmm_helper/gmm_interface.h" +#include "shared/source/gmm_helper/resource_info.h" +#include "shared/source/os_interface/hw_info_config.h" +#include "shared/source/utilities/debug_settings_reader.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/test_files.h" +#include "shared/test/unit_test/helpers/ult_hw_config.inl" +#include "shared/test/unit_test/tests_configuration.h" + +#include "opencl/source/os_interface/ocl_reg_path.h" +#include "opencl/test/unit_test/custom_event_listener.h" +#include "opencl/test/unit_test/global_environment.h" +#include "opencl/test/unit_test/helpers/kernel_binary_helper.h" +#include "opencl/test/unit_test/mocks/mock_gmm.h" +#include "opencl/test/unit_test/mocks/mock_gmm_client_context.h" +#include "opencl/test/unit_test/mocks/mock_program.h" +#include "opencl/test/unit_test/mocks/mock_sip.h" +#include "opencl/test/unit_test/ult_config_listener.h" + +#include "gmock/gmock.h" + +#include +#include +#include +#include +#include +#include + +#ifdef WIN32 +const char *fSeparator = "\\"; +#else +const char *fSeparator = "/"; +#endif + +TEST(Should, pass) { EXPECT_TRUE(true); } + +namespace NEO { +extern const char *hardwarePrefix[]; +extern const HardwareInfo *hardwareInfoTable[IGFX_MAX_PRODUCT]; + +extern const unsigned int ultIterationMaxTime; +extern bool useMockGmm; +extern TestMode testMode; +extern const char *executionDirectorySuffix; + +std::thread::id tempThreadID; + +namespace MockSipData { +extern std::unique_ptr mockSipKernel; +} + +namespace PagaFaultManagerTestConfig { +bool disabled = false; +} +} // namespace NEO + +using namespace NEO; +TestEnvironment *gEnvironment; + +PRODUCT_FAMILY productFamily = DEFAULT_TEST_PLATFORM::hwInfo.platform.eProductFamily; +GFXCORE_FAMILY renderCoreFamily = DEFAULT_TEST_PLATFORM::hwInfo.platform.eRenderCoreFamily; + +extern std::string lastTest; +bool generateRandomInput = false; + +void applyWorkarounds() { + 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(); + } +} +#ifdef __linux__ +void handle_SIGALRM(int signal) { + std::cout << "Tests timeout on: " << lastTest << std::endl; + abort(); +} +void handle_SIGSEGV(int signal) { + std::cout << "SIGSEGV on: " << lastTest << std::endl; + abort(); +} +struct sigaction oldSigAbrt; +void handle_SIGABRT(int signal) { + std::cout << "SIGABRT on: " << lastTest << std::endl; + // restore signal handler to abort + if (sigaction(SIGABRT, &oldSigAbrt, nullptr) == -1) { + std::cout << "FATAL: cannot fatal SIGABRT handler" << std::endl; + std::cout << "FATAL: try SEGV" << std::endl; + uint8_t *ptr = nullptr; + *ptr = 0; + std::cout << "FATAL: still alive, call exit()" << std::endl; + exit(-1); + } + raise(signal); +} +#else +LONG WINAPI UltExceptionFilter( + _In_ struct _EXCEPTION_POINTERS *exceptionInfo) { + std::cout << "UnhandledException: 0x" << std::hex << exceptionInfo->ExceptionRecord->ExceptionCode << std::dec + << " on test: " << lastTest + << std::endl; + return EXCEPTION_CONTINUE_SEARCH; +} +#endif + +std::string getHardwarePrefix() { + std::string s = hardwarePrefix[defaultHwInfo->platform.eProductFamily]; + return s; +} + +std::string getRunPath(char *argv0) { + std::string res(argv0); + + auto pos = res.rfind(fSeparator); + if (pos != std::string::npos) + res = res.substr(0, pos); + + if (res == "." || pos == std::string::npos) { +#if defined(__linux__) + res = getcwd(nullptr, 0); +#else + res = _getcwd(nullptr, 0); +#endif + } + + return res; +} + +int main(int argc, char **argv) { + int retVal = 0; + bool useDefaultListener = false; + bool enable_alarm = true; + bool setupFeatureTableAndWorkaroundTable = testMode == TestMode::AubTests ? true : false; + + applyWorkarounds(); + +#if defined(__linux__) + bool enable_segv = true; + bool enable_abrt = true; + if (getenv("IGDRCL_TEST_SELF_EXEC") == nullptr) { + std::string wd = getRunPath(argv[0]); + setenv("LD_LIBRARY_PATH", wd.c_str(), 1); + setenv("IGDRCL_TEST_SELF_EXEC", wd.c_str(), 1); + execv(argv[0], argv); + printf("FATAL ERROR: cannot self-exec test: %s!, errno: %d\n", argv[0], errno); + return -1; + } else { + } +#endif + + ::testing::InitGoogleMock(&argc, argv); + HardwareInfo hwInfoForTests = DEFAULT_TEST_PLATFORM::hwInfo; + + uint32_t euPerSubSlice = 0; + uint32_t sliceCount = 0; + uint32_t subSlicePerSliceCount = 0; + int32_t revId = -1; + int dieRecovery = 0; + + for (int i = 1; i < argc; ++i) { + if (!strcmp("--disable_default_listener", argv[i])) { + useDefaultListener = false; + } else if (!strcmp("--enable_default_listener", argv[i])) { + useDefaultListener = true; + } else if (!strcmp("--disable_alarm", argv[i])) { + enable_alarm = false; + } else if (!strcmp("--disable_pagefaulting_tests", argv[i])) { //disable tests which raise page fault signal during execution + NEO::PagaFaultManagerTestConfig::disabled = true; + } else if (!strcmp("--tbx", argv[i])) { + if (testMode == TestMode::AubTests) { + testMode = TestMode::AubTestsWithTbx; + } + initialHardwareTag = 0; + } else if (!strcmp("--rev_id", argv[i])) { + ++i; + if (i < argc) { + revId = atoi(argv[i]); + } + } else if (!strcmp("--product", argv[i])) { + ++i; + if (i < argc) { + if (::isdigit(argv[i][0])) { + int productValue = atoi(argv[i]); + if (productValue > 0 && productValue < IGFX_MAX_PRODUCT && hardwarePrefix[productValue] != nullptr) { + productFamily = static_cast(productValue); + } else { + productFamily = IGFX_UNKNOWN; + } + } else { + productFamily = IGFX_UNKNOWN; + for (int j = 0; j < IGFX_MAX_PRODUCT; j++) { + if (hardwarePrefix[j] == nullptr) + continue; + if (strcmp(hardwarePrefix[j], argv[i]) == 0) { + productFamily = static_cast(j); + break; + } + } + } + if (productFamily == IGFX_UNKNOWN) { + std::cout << "unknown or unsupported product family has been set: " << argv[i] << std::endl; + return -1; + } else { + std::cout << "product family: " << hardwarePrefix[productFamily] << " (" << productFamily << ")" << std::endl; + } + hwInfoForTests = *hardwareInfoTable[productFamily]; + } + } else if (!strcmp("--slices", argv[i])) { + ++i; + if (i < argc) { + sliceCount = atoi(argv[i]); + } + } else if (!strcmp("--subslices", argv[i])) { + ++i; + if (i < argc) { + subSlicePerSliceCount = atoi(argv[i]); + } + } else if (!strcmp("--eu_per_ss", argv[i])) { + ++i; + if (i < argc) { + euPerSubSlice = atoi(argv[i]); + } + } else if (!strcmp("--die_recovery", argv[i])) { + ++i; + if (i < argc) { + dieRecovery = atoi(argv[i]) ? 1 : 0; + } + } else if (!strcmp("--generate_random_inputs", argv[i])) { + generateRandomInput = true; + } else if (!strcmp("--read-config", argv[i]) && (testMode == TestMode::AubTests || testMode == TestMode::AubTestsWithTbx)) { + if (DebugManager.registryReadAvailable()) { + DebugManager.setReaderImpl(SettingsReader::create(oclRegPath)); + DebugManager.injectSettingsFromReader(); + } + } else if (!strcmp("--dump_buffer_format", argv[i]) && testMode == TestMode::AubTests) { + ++i; + std::string dumpBufferFormat(argv[i]); + std::transform(dumpBufferFormat.begin(), dumpBufferFormat.end(), dumpBufferFormat.begin(), ::toupper); + DebugManager.flags.AUBDumpBufferFormat.set(dumpBufferFormat); + } else if (!strcmp("--dump_image_format", argv[i]) && testMode == TestMode::AubTests) { + ++i; + std::string dumpImageFormat(argv[i]); + std::transform(dumpImageFormat.begin(), dumpImageFormat.end(), dumpImageFormat.begin(), ::toupper); + DebugManager.flags.AUBDumpImageFormat.set(dumpImageFormat); + } + } + + productFamily = hwInfoForTests.platform.eProductFamily; + renderCoreFamily = hwInfoForTests.platform.eRenderCoreFamily; + uint32_t threadsPerEu = hwInfoConfigFactory[productFamily]->threadsPerEu; + PLATFORM &platform = hwInfoForTests.platform; + + if (revId != -1) { + platform.usRevId = revId; + } + + uint64_t hwInfoConfig = defaultHardwareInfoConfigTable[productFamily]; + setHwInfoValuesFromConfig(hwInfoConfig, hwInfoForTests); + + // set Gt and FeatureTable to initial state + hardwareInfoSetup[productFamily](&hwInfoForTests, setupFeatureTableAndWorkaroundTable, hwInfoConfig); + GT_SYSTEM_INFO >SystemInfo = hwInfoForTests.gtSystemInfo; + + // and adjust dynamic values if not secified + sliceCount = sliceCount > 0 ? sliceCount : gtSystemInfo.SliceCount; + subSlicePerSliceCount = subSlicePerSliceCount > 0 ? subSlicePerSliceCount : (gtSystemInfo.SubSliceCount / sliceCount); + euPerSubSlice = euPerSubSlice > 0 ? euPerSubSlice : gtSystemInfo.MaxEuPerSubSlice; + // clang-format off + gtSystemInfo.SliceCount = sliceCount; + gtSystemInfo.SubSliceCount = gtSystemInfo.SliceCount * subSlicePerSliceCount; + gtSystemInfo.EUCount = gtSystemInfo.SubSliceCount * euPerSubSlice - dieRecovery; + gtSystemInfo.ThreadCount = gtSystemInfo.EUCount * threadsPerEu; + gtSystemInfo.MaxEuPerSubSlice = std::max(gtSystemInfo.MaxEuPerSubSlice, euPerSubSlice); + gtSystemInfo.MaxSlicesSupported = std::max(gtSystemInfo.MaxSlicesSupported, gtSystemInfo.SliceCount); + gtSystemInfo.MaxSubSlicesSupported = std::max(gtSystemInfo.MaxSubSlicesSupported, gtSystemInfo.SubSliceCount); + gtSystemInfo.IsDynamicallyPopulated = false; + // clang-format on + + std::string executionDirectory(hardwarePrefix[productFamily]); + executionDirectory += NEO::executionDirectorySuffix; // _aub for aub_tests, empty otherwise + +#ifdef WIN32 +#include + if (_chdir(executionDirectory.c_str())) { + std::cout << "chdir into " << executionDirectory << " directory failed.\nThis might cause test failures." << std::endl; + } +#elif defined(__linux__) +#include + if (chdir(executionDirectory.c_str()) != 0) { + std::cout << "chdir into " << executionDirectory << " directory failed.\nThis might cause test failures." << std::endl; + } +#endif + + defaultHwInfo = std::make_unique(); + *defaultHwInfo = hwInfoForTests; + + auto &listeners = ::testing::UnitTest::GetInstance()->listeners(); + if (useDefaultListener == false) { + auto defaultListener = listeners.default_result_printer(); + + auto customEventListener = new CCustomEventListener(defaultListener, hardwarePrefix[productFamily]); + + listeners.Release(defaultListener); + listeners.Append(customEventListener); + } + + listeners.Append(new MemoryLeakListener); + listeners.Append(new UltConfigListener); + + gEnvironment = reinterpret_cast(::testing::AddGlobalTestEnvironment(new TestEnvironment)); + + MockCompilerDebugVars fclDebugVars; + MockCompilerDebugVars igcDebugVars; + + retrieveBinaryKernelFilename(fclDebugVars.fileName, KernelBinaryHelper::BUILT_INS + "_", ".bc"); + retrieveBinaryKernelFilename(igcDebugVars.fileName, KernelBinaryHelper::BUILT_INS + "_", ".gen"); + + gEnvironment->setMockFileNames(fclDebugVars.fileName, igcDebugVars.fileName); + gEnvironment->setDefaultDebugVars(fclDebugVars, igcDebugVars, hwInfoForTests); + +#if defined(__linux__) + //ULTs timeout + if (enable_alarm) { + unsigned int alarmTime = NEO::ultIterationMaxTime * ::testing::GTEST_FLAG(repeat); + + struct sigaction sa; + sa.sa_handler = &handle_SIGALRM; + sa.sa_flags = SA_RESTART; + sigfillset(&sa.sa_mask); + if (sigaction(SIGALRM, &sa, NULL) == -1) { + printf("FATAL ERROR: cannot intercept SIGALRM\n"); + return -2; + } + alarm(alarmTime); + std::cout << "set timeout to: " << alarmTime << std::endl; + } + + if (enable_segv) { + struct sigaction sa; + sa.sa_handler = &handle_SIGSEGV; + sa.sa_flags = SA_RESTART; + sigfillset(&sa.sa_mask); + if (sigaction(SIGSEGV, &sa, NULL) == -1) { + printf("FATAL ERROR: cannot intercept SIGSEGV\n"); + return -2; + } + } + + if (enable_abrt) { + struct sigaction sa; + sa.sa_handler = &handle_SIGABRT; + sa.sa_flags = SA_RESTART; + sigfillset(&sa.sa_mask); + if (sigaction(SIGABRT, &sa, &oldSigAbrt) == -1) { + printf("FATAL ERROR: cannot intercept SIGABRT\n"); + return -2; + } + } +#else + SetUnhandledExceptionFilter(&UltExceptionFilter); +#endif + if (useMockGmm) { + GmmHelper::createGmmContextWrapperFunc = GmmClientContextBase::create; + } else { + GmmInterface::initialize(nullptr, nullptr); + } + + retVal = RUN_ALL_TESTS(); + + return retVal; +} diff --git a/shared/test/unit_test/test_mode.h b/shared/test/unit_test/test_mode.h new file mode 100644 index 0000000000..9be8903fdc --- /dev/null +++ b/shared/test/unit_test/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