From 5e15543b14c2b1c60b8ce08c0d1a1b0e6ad25965 Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Fri, 8 Mar 2024 09:48:00 +0000 Subject: [PATCH] test: improve unit tests - use virtual file system - use virtualFileSystem in ULTs, writeDataToFile() does not create file but instead saves filename. Call to fileExists() checks if file was previously written Related-To: NEO-7006 Signed-off-by: Mateusz Hoppe --- level_zero/CMakeLists.txt | 1 + level_zero/core/source/dll/CMakeLists.txt | 3 ++- level_zero/core/test/aub_tests/CMakeLists.txt | 1 + level_zero/core/test/unit_tests/CMakeLists.txt | 1 + .../sources/debugger/test_module_with_debug.cpp | 10 +++++----- .../unit_tests/sources/module/test_module.cpp | 13 ++++++------- level_zero/sysman/test/unit_tests/CMakeLists.txt | 1 + level_zero/tools/test/unit_tests/CMakeLists.txt | 1 + opencl/source/dll/CMakeLists.txt | 1 + opencl/test/unit_test/libult/CMakeLists.txt | 1 + opencl/test/unit_test/linux/CMakeLists.txt | 3 ++- shared/source/built_ins/built_ins.cpp | 3 ++- shared/source/helpers/CMakeLists.txt | 1 - shared/source/helpers/file_io.cpp | 13 +------------ shared/source/helpers/file_io_load.cpp | 12 +++++++++++- shared/test/common/common_main.cpp | 2 ++ shared/test/common/helpers/file_io.cpp | 13 ++++++++++++- shared/test/common/helpers/mock_file_io.h | 11 +++++++++++ .../helpers/virtual_file_system_listener.cpp | 4 +++- shared/test/common/libult/CMakeLists.txt | 3 ++- shared/test/unit_test/CMakeLists.txt | 1 + shared/test/unit_test/built_ins/sip_tests.cpp | 7 ++++++- .../debug_settings_manager_tests.cpp | 15 +++++++++++---- .../linux/debug_settings_manager_linux_tests.cpp | 9 ++++++--- .../device_binary_format_zebin_tests.cpp | 11 ++++++----- .../utilities/debug_settings_reader_tests.cpp | 12 +++++++++++- 26 files changed, 107 insertions(+), 46 deletions(-) create mode 100644 shared/test/common/helpers/mock_file_io.h diff --git a/level_zero/CMakeLists.txt b/level_zero/CMakeLists.txt index 3fa36b44ce..97afe677bb 100644 --- a/level_zero/CMakeLists.txt +++ b/level_zero/CMakeLists.txt @@ -221,6 +221,7 @@ if(BUILD_WITH_L0) ${NEO_SHARED_DIRECTORY}/gmm_helper/resource_info.cpp ${NEO_SHARED_DIRECTORY}/helpers/abort.cpp ${NEO_SHARED_DIRECTORY}/helpers/debug_helpers.cpp + ${NEO_SHARED_DIRECTORY}/helpers/file_io.cpp ${NEO_SHARED_DIRECTORY}/utilities/cpuintrinsics.cpp ${NEO_SHARED_DIRECTORY}/utilities/debug_settings_reader_creator.cpp ${NEO_SHARED_DIRECTORY}/utilities/io_functions.cpp diff --git a/level_zero/core/source/dll/CMakeLists.txt b/level_zero/core/source/dll/CMakeLists.txt index b3ec88918d..f86f7fd4ad 100644 --- a/level_zero/core/source/dll/CMakeLists.txt +++ b/level_zero/core/source/dll/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2020-2023 Intel Corporation +# Copyright (C) 2020-2024 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -9,6 +9,7 @@ target_sources(${TARGET_NAME_L0} ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/disallow_deferred_deleter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/create_builtin_functions_lib.cpp + ${NEO_SHARED_DIRECTORY}/helpers/file_io.cpp ) add_subdirectories() diff --git a/level_zero/core/test/aub_tests/CMakeLists.txt b/level_zero/core/test/aub_tests/CMakeLists.txt index d8a2354637..8f0b96ad56 100644 --- a/level_zero/core/test/aub_tests/CMakeLists.txt +++ b/level_zero/core/test/aub_tests/CMakeLists.txt @@ -13,6 +13,7 @@ if(DEFINED AUB_STREAM_PROJECT_NAME) list(APPEND L0_AUB_TESTS__TARGET_OBJECTS ${CMAKE_CURRENT_SOURCE_DIR}/aub_hello_world_test.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/common_main.cpp + ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/virtual_file_system_listener.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/tests_configuration.h ) diff --git a/level_zero/core/test/unit_tests/CMakeLists.txt b/level_zero/core/test/unit_tests/CMakeLists.txt index f6a2c8c8ce..1d0d5b7773 100644 --- a/level_zero/core/test/unit_tests/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/CMakeLists.txt @@ -28,6 +28,7 @@ target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/mock.h ${CMAKE_CURRENT_SOURCE_DIR}/white_box.h ${NEO_SHARED_TEST_DIRECTORY}/common/common_main.cpp + ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/virtual_file_system_listener.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/tests_configuration.h ${NEO_SOURCE_DIR}/level_zero/core/test/common/test_modules/gen_kernel.cmake ${NEO_SOURCE_DIR}/level_zero/core/test/common/ult_specific_config_l0.cpp diff --git a/level_zero/core/test/unit_tests/sources/debugger/test_module_with_debug.cpp b/level_zero/core/test/unit_tests/sources/debugger/test_module_with_debug.cpp index 6a833ba155..396db50f13 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/test_module_with_debug.cpp +++ b/level_zero/core/test/unit_tests/sources/debugger/test_module_with_debug.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,12 +7,12 @@ #include "shared/source/compiler_interface/external_functions.h" #include "shared/source/device_binary_format/patchtokens_decoder.h" -#include "shared/source/helpers/file_io.h" #include "shared/source/kernel/kernel_descriptor_from_patchtokens.h" #include "shared/source/os_interface/os_interface.h" #include "shared/source/program/kernel_info.h" #include "shared/source/program/kernel_info_from_patchtokens.h" #include "shared/test/common/compiler_interface/linker_mock.h" +#include "shared/test/common/helpers/mock_file_io.h" #include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/mocks/mock_compilers.h" #include "shared/test/common/mocks/mock_elf.h" @@ -393,11 +393,11 @@ HWTEST_F(ModuleWithZebinAndL0DebuggerTest, GivenDumpElfFlagAndZebinWhenInitializ zebin.storage.data(), zebin.storage.size()); std::string fileName = "dumped_debug_module.elf"; - EXPECT_FALSE(fileExists(fileName)); + EXPECT_FALSE(virtualFileExists(fileName)); EXPECT_EQ(moduleMock->initialize(&moduleDesc, neoDevice), ZE_RESULT_SUCCESS); - EXPECT_TRUE(fileExists(fileName)); - std::remove(fileName.c_str()); + EXPECT_TRUE(virtualFileExists(fileName)); + removeVirtualFile(fileName.c_str()); } HWTEST_F(ModuleWithZebinAndL0DebuggerTest, GivenZebinNoDebugDataWhenInitializingModuleThenDoNotRegisterElfAndDoNotNotifyModuleCreate) { diff --git a/level_zero/core/test/unit_tests/sources/module/test_module.cpp b/level_zero/core/test/unit_tests/sources/module/test_module.cpp index 6e3ab66af9..6685e6fb03 100644 --- a/level_zero/core/test/unit_tests/sources/module/test_module.cpp +++ b/level_zero/core/test/unit_tests/sources/module/test_module.cpp @@ -16,7 +16,6 @@ #include "shared/source/helpers/addressing_mode_helper.h" #include "shared/source/helpers/blit_helper.h" #include "shared/source/helpers/compiler_product_helper.h" -#include "shared/source/helpers/file_io.h" #include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/kernel/implicit_args_helper.h" #include "shared/source/os_interface/os_inc_base.h" @@ -24,6 +23,7 @@ #include "shared/test/common/compiler_interface/linker_mock.h" #include "shared/test/common/device_binary_format/patchtokens_tests.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/mock_file_io.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_elf.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" @@ -3369,13 +3369,13 @@ HWTEST_F(ModuleTranslationUnitTest, givenDumpZebinWhenBuildingFromSpirvThenZebin ze_result_t result = ZE_RESULT_ERROR_MODULE_BUILD_FAILURE; std::string fileName = "dumped_zebin_module.elf"; - EXPECT_FALSE(fileExists(fileName)); + EXPECT_FALSE(virtualFileExists(fileName)); result = moduleTu.buildFromSpirV(binary, sizeof(binary), nullptr, "", nullptr); EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_TRUE(fileExistsHasSize(fileName)); - std::remove(fileName.c_str()); + EXPECT_TRUE(virtualFileExists(fileName)); + removeVirtualFile(fileName); PatchTokensTestData::ValidEmptyProgram programTokens; mockCompilerInterface->output.intermediateRepresentation.size = programTokens.storage.size(); @@ -3389,9 +3389,8 @@ HWTEST_F(ModuleTranslationUnitTest, givenDumpZebinWhenBuildingFromSpirvThenZebin result = moduleTu2.buildFromSpirV(binary, sizeof(binary), nullptr, "", nullptr); - EXPECT_FALSE(fileExists(fileName)); - EXPECT_FALSE(fileExistsHasSize(fileName)); - std::remove(fileName.c_str()); + EXPECT_FALSE(virtualFileExists(fileName)); + removeVirtualFile(fileName); } HWTEST2_F(ModuleTranslationUnitTest, givenDebugFlagSetForceAllResourcesUncachedWhenGetInternalOptionsThenCorrectBuildOptionIsSet, IsAtLeastXeHpgCore) { diff --git a/level_zero/sysman/test/unit_tests/CMakeLists.txt b/level_zero/sysman/test/unit_tests/CMakeLists.txt index 30deb94625..7ab34e2d6c 100644 --- a/level_zero/sysman/test/unit_tests/CMakeLists.txt +++ b/level_zero/sysman/test/unit_tests/CMakeLists.txt @@ -32,6 +32,7 @@ target_sources(${TARGET_NAME} PRIVATE ${NEO_SOURCE_DIR}/level_zero/core/source/dll/create_builtin_functions_lib.cpp ${NEO_SOURCE_DIR}/level_zero/tools/test/unit_tests/sources/debug/debug_session_helper.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/common_main.cpp + ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/virtual_file_system_listener.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/tests_configuration.h ) diff --git a/level_zero/tools/test/unit_tests/CMakeLists.txt b/level_zero/tools/test/unit_tests/CMakeLists.txt index 97e2292ce1..67114252b6 100644 --- a/level_zero/tools/test/unit_tests/CMakeLists.txt +++ b/level_zero/tools/test/unit_tests/CMakeLists.txt @@ -32,6 +32,7 @@ target_sources(${TARGET_NAME} PRIVATE ${NEO_SOURCE_DIR}/level_zero/core/test/unit_tests/sources/builtin/create_ult_builtin_functions_lib.cpp ${NEO_SOURCE_DIR}/level_zero/tools/test/unit_tests/sources/debug/debug_session_helper.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/common_main.cpp + ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/virtual_file_system_listener.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/tests_configuration.h ) diff --git a/opencl/source/dll/CMakeLists.txt b/opencl/source/dll/CMakeLists.txt index 826ecad35e..8a61580d2a 100644 --- a/opencl/source/dll/CMakeLists.txt +++ b/opencl/source/dll/CMakeLists.txt @@ -27,6 +27,7 @@ set(RUNTIME_SRCS_DLL_BASE ${NEO_SHARED_DIRECTORY}/helpers/abort.cpp ${NEO_SHARED_DIRECTORY}/helpers/allow_deferred_deleter.cpp ${NEO_SHARED_DIRECTORY}/helpers/debug_helpers.cpp + ${NEO_SHARED_DIRECTORY}/helpers/file_io.cpp ${NEO_SHARED_DIRECTORY}/utilities/cpuintrinsics.cpp ${NEO_SHARED_DIRECTORY}/utilities/debug_settings_reader_creator.cpp ${NEO_SHARED_DIRECTORY}/utilities/io_functions.cpp diff --git a/opencl/test/unit_test/libult/CMakeLists.txt b/opencl/test/unit_test/libult/CMakeLists.txt index d65d80f1a2..442de4c7b1 100644 --- a/opencl/test/unit_test/libult/CMakeLists.txt +++ b/opencl/test/unit_test/libult/CMakeLists.txt @@ -37,6 +37,7 @@ set(IGDRCL_SRCS_LIB_ULT_ENV ${CMAKE_CURRENT_SOURCE_DIR}/command_queue_ult.cpp ${NEO_SOURCE_DIR}/shared/test/common/helpers/custom_event_listener.h ${NEO_SOURCE_DIR}/shared/test/common/common_main.cpp + ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/virtual_file_system_listener.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/command_queue/command_queue_fixture.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/command_queue/command_queue_fixture.h ${NEO_SOURCE_DIR}/opencl/test/unit_test/fixtures/built_in_fixture.cpp diff --git a/opencl/test/unit_test/linux/CMakeLists.txt b/opencl/test/unit_test/linux/CMakeLists.txt index fa0aaa3d84..30c4067c61 100644 --- a/opencl/test/unit_test/linux/CMakeLists.txt +++ b/opencl/test/unit_test/linux/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2018-2023 Intel Corporation +# Copyright (C) 2018-2024 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -20,6 +20,7 @@ add_executable(igdrcl_${target_name} ${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 + ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/virtual_file_system_listener.cpp ${NEO_SHARED_DIRECTORY}/os_interface/linux/sys_calls_linux.cpp ${NEO_SHARED_DIRECTORY}/dll/create_memory_manager_drm.cpp ${NEO_SHARED_DIRECTORY}/dll/device_dll.cpp diff --git a/shared/source/built_ins/built_ins.cpp b/shared/source/built_ins/built_ins.cpp index 5752e38b58..ef31229a11 100644 --- a/shared/source/built_ins/built_ins.cpp +++ b/shared/source/built_ins/built_ins.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -14,6 +14,7 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/aligned_memory.h" #include "shared/source/helpers/debug_helpers.h" +#include "shared/source/helpers/file_io.h" #include "shared/source/memory_manager/allocation_properties.h" #include "shared/source/memory_manager/memory_manager.h" #include "shared/source/os_interface/os_context.h" diff --git a/shared/source/helpers/CMakeLists.txt b/shared/source/helpers/CMakeLists.txt index d0b10b03a5..ef380c3456 100644 --- a/shared/source/helpers/CMakeLists.txt +++ b/shared/source/helpers/CMakeLists.txt @@ -68,7 +68,6 @@ set(NEO_CORE_HELPERS ${CMAKE_CURRENT_SOURCE_DIR}/engine_node_helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/engine_node_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/extendable_enum.h - ${CMAKE_CURRENT_SOURCE_DIR}/file_io.cpp ${CMAKE_CURRENT_SOURCE_DIR}/file_io_load.cpp ${CMAKE_CURRENT_SOURCE_DIR}/file_io.h ${CMAKE_CURRENT_SOURCE_DIR}/flat_batch_buffer_helper.h diff --git a/shared/source/helpers/file_io.cpp b/shared/source/helpers/file_io.cpp index 1bca7afdd0..9c3e83aa62 100644 --- a/shared/source/helpers/file_io.cpp +++ b/shared/source/helpers/file_io.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -61,14 +61,3 @@ bool fileExistsHasSize(const std::string &fileName) { } return pFile != nullptr && nsize > 0; } - -void dumpFileIncrement(const char *data, size_t dataSize, const std::string &filename, const std::string &extension) { - std::ofstream fstream; - auto filenameWithExt = filename + extension; - int suffix = 0; - while (fileExists(filenameWithExt)) { - filenameWithExt = filename + "_" + std::to_string(suffix) + extension; - suffix++; - } - writeDataToFile(filenameWithExt.c_str(), data, dataSize); -} diff --git a/shared/source/helpers/file_io_load.cpp b/shared/source/helpers/file_io_load.cpp index 1e23fd0847..87db1f0d83 100644 --- a/shared/source/helpers/file_io_load.cpp +++ b/shared/source/helpers/file_io_load.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -48,3 +48,13 @@ std::unique_ptr loadDataFromFile( retSize = nsize; return ret; } + +void dumpFileIncrement(const char *data, size_t dataSize, const std::string &filename, const std::string &extension) { + auto filenameWithExt = filename + extension; + int suffix = 0; + while (fileExists(filenameWithExt)) { + filenameWithExt = filename + "_" + std::to_string(suffix) + extension; + suffix++; + } + writeDataToFile(filenameWithExt.c_str(), data, dataSize); +} diff --git a/shared/test/common/common_main.cpp b/shared/test/common/common_main.cpp index ce0f22e72f..fc57ccaabc 100644 --- a/shared/test/common/common_main.cpp +++ b/shared/test/common/common_main.cpp @@ -18,6 +18,7 @@ #include "shared/test/common/helpers/memory_leak_listener.h" #include "shared/test/common/helpers/test_files.h" #include "shared/test/common/helpers/ult_hw_config.inl" +#include "shared/test/common/helpers/virtual_file_system_listener.h" #include "shared/test/common/libult/global_environment.h" #include "shared/test/common/libult/signal_utils.h" #include "shared/test/common/mocks/mock_gmm_client_context.h" @@ -365,6 +366,7 @@ int main(int argc, char **argv) { } listeners.Append(new MemoryLeakListener); + listeners.Append(new NEO::VirtualFileSystemListener); addUltListener(listeners); ultListenersInitialized = true; diff --git a/shared/test/common/helpers/file_io.cpp b/shared/test/common/helpers/file_io.cpp index 1b3f753331..915a060435 100644 --- a/shared/test/common/helpers/file_io.cpp +++ b/shared/test/common/helpers/file_io.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -63,3 +63,14 @@ bool fileExistsHasSize(const std::string &fileName) { } return pFile != nullptr && nsize > 0; } + +void removeVirtualFile(const std::string &fileName) { + NEO::virtualFileList.erase(fileName); +} + +bool virtualFileExists(const std::string &fileName) { + if (NEO::virtualFileList.count(fileName) > 0) { + return true; + } + return false; +} diff --git a/shared/test/common/helpers/mock_file_io.h b/shared/test/common/helpers/mock_file_io.h new file mode 100644 index 0000000000..44aeff1886 --- /dev/null +++ b/shared/test/common/helpers/mock_file_io.h @@ -0,0 +1,11 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/helpers/file_io.h" + +bool virtualFileExists(const std::string &fileName); +void removeVirtualFile(const std::string &fileName); diff --git a/shared/test/common/helpers/virtual_file_system_listener.cpp b/shared/test/common/helpers/virtual_file_system_listener.cpp index 8d637e2ad2..e20b70b4b4 100644 --- a/shared/test/common/helpers/virtual_file_system_listener.cpp +++ b/shared/test/common/helpers/virtual_file_system_listener.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,8 @@ #include "shared/test/common/helpers/virtual_file_system_listener.h" +#include "shared/test/common/helpers/mock_file_io.h" + namespace NEO { std::set virtualFileList; diff --git a/shared/test/common/libult/CMakeLists.txt b/shared/test/common/libult/CMakeLists.txt index 4446d3c6ef..728b5c89f2 100644 --- a/shared/test/common/libult/CMakeLists.txt +++ b/shared/test/common/libult/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2021-2023 Intel Corporation +# Copyright (C) 2021-2024 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -110,6 +110,7 @@ set(neo_libult_common_SRCS_LIB_ULT ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/unit_test_helper.h ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/unit_test_helper.inl ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/unit_test_helper_bdw_and_later.inl + ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/file_io.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/libult/abort.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/libult/create_tbx_sockets.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/libult/debug_settings_reader_creator.cpp diff --git a/shared/test/unit_test/CMakeLists.txt b/shared/test/unit_test/CMakeLists.txt index 75c5e0c1fc..0664261038 100644 --- a/shared/test/unit_test/CMakeLists.txt +++ b/shared/test/unit_test/CMakeLists.txt @@ -21,6 +21,7 @@ add_executable(neo_shared_tests ${CMAKE_CURRENT_SOURCE_DIR}/ult_specific_config.cpp ${NEO_SHARED_DIRECTORY}/helpers/allow_deferred_deleter.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/common_main.cpp + ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/virtual_file_system_listener.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/tests_configuration.h $ $ diff --git a/shared/test/unit_test/built_ins/sip_tests.cpp b/shared/test/unit_test/built_ins/sip_tests.cpp index 9135819326..2fc561d52b 100644 --- a/shared/test/unit_test/built_ins/sip_tests.cpp +++ b/shared/test/unit_test/built_ins/sip_tests.cpp @@ -26,7 +26,12 @@ #include "common/StateSaveAreaHeader.h" +#include + using namespace NEO; +namespace NEO { +extern std::set virtualFileList; +} struct RawBinarySipFixture : public DeviceFixture { void setUp() { @@ -746,4 +751,4 @@ TEST_F(DebugBuiltinSipTest, givenDebuggerWhenInitSipKernelThenDbgSipIsLoadedFrom auto sipAllocation = SipKernel::getSipKernel(*pDevice, nullptr).getSipAllocation(); EXPECT_NE(nullptr, sipAllocation); EXPECT_EQ(SipKernelMock::classType, SipClassType::builtins); -} \ No newline at end of file +} diff --git a/shared/test/unit_test/debug_settings/debug_settings_manager_tests.cpp b/shared/test/unit_test/debug_settings/debug_settings_manager_tests.cpp index 07d5ea7bdf..6a37934b8c 100644 --- a/shared/test/unit_test/debug_settings/debug_settings_manager_tests.cpp +++ b/shared/test/unit_test/debug_settings/debug_settings_manager_tests.cpp @@ -18,6 +18,7 @@ #include "shared/test/common/utilities/base_object_utils.h" #include +#include #include #include #include @@ -341,7 +342,10 @@ TEST(DebugSettingsManager, givenDisabledDebugManagerWhenCreateThenOnlyReleaseVar bool settingsFileExists = fileExists(SettingsReader::settingsFileName); if (!settingsFileExists) { const char data[] = "LogApiCalls = 1\nMakeAllBuffersResident = 1"; - writeDataToFile(SettingsReader::settingsFileName, &data, sizeof(data)); + std::ofstream file; + file.open(SettingsReader::settingsFileName); + file << data; + file.close(); } SettingsReader *reader = SettingsReader::createFileReader(); @@ -355,7 +359,7 @@ TEST(DebugSettingsManager, givenDisabledDebugManagerWhenCreateThenOnlyReleaseVar EXPECT_EQ(0, debugManager.flags.LogApiCalls.get()); if (!settingsFileExists) { - remove(SettingsReader::settingsFileName); + std::remove(SettingsReader::settingsFileName); } } @@ -363,7 +367,10 @@ TEST(DebugSettingsManager, givenEnabledDebugManagerWhenCreateThenAllVariablesAre bool settingsFileExists = fileExists(SettingsReader::settingsFileName); if (!settingsFileExists) { const char data[] = "LogApiCalls = 1\nMakeAllBuffersResident = 1"; - writeDataToFile(SettingsReader::settingsFileName, &data, sizeof(data)); + std::ofstream file; + file.open(SettingsReader::settingsFileName); + file << data; + file.close(); } SettingsReader *reader = SettingsReader::createFileReader(); @@ -377,7 +384,7 @@ TEST(DebugSettingsManager, givenEnabledDebugManagerWhenCreateThenAllVariablesAre EXPECT_EQ(1, debugManager.flags.LogApiCalls.get()); if (!settingsFileExists) { - remove(SettingsReader::settingsFileName); + std::remove(SettingsReader::settingsFileName); } } diff --git a/shared/test/unit_test/debug_settings/linux/debug_settings_manager_linux_tests.cpp b/shared/test/unit_test/debug_settings/linux/debug_settings_manager_linux_tests.cpp index ca243699b3..f6a9d9ab43 100644 --- a/shared/test/unit_test/debug_settings/linux/debug_settings_manager_linux_tests.cpp +++ b/shared/test/unit_test/debug_settings/linux/debug_settings_manager_linux_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -12,6 +12,7 @@ #include "shared/test/common/mocks/mock_io_functions.h" #include "shared/test/common/test_macros/test.h" +#include #include namespace NEO { @@ -20,9 +21,11 @@ TEST(DebugSettingsManager, givenDisabledDebugManagerAndMockEnvVariableWhenCreate bool settingsFileExists = fileExists(SettingsReader::settingsFileName); if (!settingsFileExists) { const char data[] = "LogApiCalls = 1\nMakeAllBuffersResident = 1"; - writeDataToFile(SettingsReader::settingsFileName, &data, sizeof(data)); + std::ofstream file; + file.open(SettingsReader::settingsFileName); + file << data; + file.close(); } - SettingsReader *reader = SettingsReader::createFileReader(); EXPECT_NE(nullptr, reader); diff --git a/shared/test/unit_test/device_binary_format/device_binary_format_zebin_tests.cpp b/shared/test/unit_test/device_binary_format/device_binary_format_zebin_tests.cpp index fb19910c38..62151b7023 100644 --- a/shared/test/unit_test/device_binary_format/device_binary_format_zebin_tests.cpp +++ b/shared/test/unit_test/device_binary_format/device_binary_format_zebin_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -14,6 +14,7 @@ #include "shared/source/helpers/string.h" #include "shared/source/program/program_info.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/mock_file_io.h" #include "shared/test/common/mocks/mock_modules_zebin.h" #include "shared/test/common/test_macros/test.h" @@ -138,12 +139,12 @@ TEST(UnpackSingleDeviceBinaryZebin, givenDumpZEBinFlagSetWhenUnpackingZebinBinar EXPECT_FALSE(fileExists(fileNameInc)); NEO::unpackSingleDeviceBinary(ArrayRef::fromAny(&zebin, 1U), "", targetDevice, unpackErrors, unpackWarnings); - EXPECT_TRUE(fileExistsHasSize(fileName)); + EXPECT_TRUE(virtualFileExists(fileName)); NEO::unpackSingleDeviceBinary(ArrayRef::fromAny(&zebin, 1U), "", targetDevice, unpackErrors, unpackWarnings); - EXPECT_TRUE(fileExistsHasSize(fileNameInc)); + EXPECT_TRUE(virtualFileExists(fileNameInc)); - std::remove(fileName.c_str()); - std::remove(fileNameInc.c_str()); + removeVirtualFile(fileName); + removeVirtualFile(fileNameInc); } TEST(UnpackSingleDeviceBinaryZebin, WhenValidBinaryForDifferentDeviceThenUnpackingFails) { diff --git a/shared/test/unit_test/utilities/debug_settings_reader_tests.cpp b/shared/test/unit_test/utilities/debug_settings_reader_tests.cpp index e91488e785..675db92379 100644 --- a/shared/test/unit_test/utilities/debug_settings_reader_tests.cpp +++ b/shared/test/unit_test/utilities/debug_settings_reader_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -36,6 +36,15 @@ class MockSettingsReader : public SettingsReader { const char *appSpecificLocation(const std::string &name) override { return name.c_str(); }; }; +namespace SettingsReaderTests { + +void writeDataToFile(const char *filename, const void *pData, size_t dataSize) { + std::ofstream file; + file.open(filename); + file.write(static_cast(pData), dataSize); + file.close(); +} + TEST(SettingsReader, WhenCreatingSettingsReaderThenReaderIsCreated) { auto reader = std::unique_ptr(SettingsReader::create(ApiSpecificConfig::getRegistryPath())); EXPECT_NE(nullptr, reader.get()); @@ -114,3 +123,4 @@ TEST(SettingsReader, GivenFalseWhenPrintingDebugStringThenNoOutput) { std::string output = testing::internal::GetCapturedStdout(); EXPECT_STREQ(output.c_str(), ""); } +} // namespace SettingsReaderTests \ No newline at end of file