Skip to content

Commit

Permalink
refactor: add mock_aubstream
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com>
Source: cbc868c
  • Loading branch information
ArturHarasimiuk authored and Compute-Runtime-Automation committed May 2, 2024
1 parent 3f7f48d commit 6b0ffc5
Show file tree
Hide file tree
Showing 22 changed files with 102 additions and 48 deletions.
3 changes: 2 additions & 1 deletion level_zero/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,11 @@ if(BUILD_WITH_L0)
PRIVATE
${NEO_SHARED_DIRECTORY}/aub/aub_stream_interface.cpp
)
target_link_libraries(${TARGET_NAME_L0} PRIVATE ${AUB_STREAM_PROJECT_NAME})
else()
target_sources(${TARGET_NAME_L0}
PRIVATE
${NEO_SHARED_DIRECTORY}/aub/aub_stream_interface_stub.cpp
$<TARGET_OBJECTS:aub_stream_stubs>
)

endif()
Expand Down
1 change: 1 addition & 0 deletions level_zero/core/test/aub_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ if(NOT NEO_SKIP_AUB_TESTS AND DEFINED AUB_STREAM_PROJECT_NAME)
target_link_libraries(${TARGET_NAME} ${HW_LIBS_ULT})
target_link_libraries(${TARGET_NAME} gmock-gtest)
target_link_libraries(${TARGET_NAME} ${NEO_EXTRA_LIBS})
target_link_libraries(${TARGET_NAME} ${AUB_STREAM_PROJECT_NAME})

if(UNIX)
target_link_libraries(${TARGET_NAME} rt)
Expand Down
1 change: 1 addition & 0 deletions level_zero/core/test/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ target_link_libraries(${TARGET_NAME}
)

target_sources(${TARGET_NAME} PRIVATE
$<TARGET_OBJECTS:mock_aubstream>
$<TARGET_OBJECTS:mock_gmm>
$<TARGET_OBJECTS:${TARGET_NAME_L0}_fixtures>
$<TARGET_OBJECTS:${TARGET_NAME_L0}_mocks>
Expand Down
1 change: 1 addition & 0 deletions level_zero/sysman/test/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ target_link_libraries(${TARGET_NAME}
)

target_sources(${TARGET_NAME} PRIVATE
$<TARGET_OBJECTS:mock_aubstream>
$<TARGET_OBJECTS:mock_gmm>
$<TARGET_OBJECTS:${TARGET_NAME_L0}_fixtures>
$<TARGET_OBJECTS:${TARGET_NAME_L0}_mocks>
Expand Down
1 change: 1 addition & 0 deletions level_zero/tools/test/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ target_link_libraries(${TARGET_NAME}
)

target_sources(${TARGET_NAME} PRIVATE
$<TARGET_OBJECTS:mock_aubstream>
$<TARGET_OBJECTS:mock_gmm>
$<TARGET_OBJECTS:${TARGET_NAME_L0}_fixtures>
$<TARGET_OBJECTS:${TARGET_NAME_L0}_mocks>
Expand Down
4 changes: 2 additions & 2 deletions opencl/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ if(${GENERATE_EXECUTABLE})
$<TARGET_OBJECTS:${AUB_STREAM_PROJECT_NAME}_all_hw>
${NEO_SOURCE_DIR}/shared/source/aub/aub_stream_interface.cpp
)
target_link_libraries(${NEO_DYNAMIC_LIB_NAME} PRIVATE ${AUB_STREAM_PROJECT_NAME})
else()
target_sources(${NEO_DYNAMIC_LIB_NAME}
PRIVATE
${NEO_SOURCE_DIR}/shared/source/aub/aub_stream_interface_stub.cpp
$<TARGET_OBJECTS:aub_stream_stubs>
)

endif()

if(UNIX)
Expand Down
1 change: 1 addition & 0 deletions opencl/test/unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ set(NEO_IGDRCL_TESTS__TARGET_OBJECTS
$<TARGET_OBJECTS:neo_libult_cs>
$<TARGET_OBJECTS:neo_libult>
$<TARGET_OBJECTS:igdrcl_libult_env>
$<TARGET_OBJECTS:mock_aubstream>
$<TARGET_OBJECTS:mock_gmm>
$<TARGET_OBJECTS:${SHARINGS_ENABLE_LIB_NAME}>
$<TARGET_OBJECTS:${BUILTINS_SOURCES_LIB_NAME}>
Expand Down
2 changes: 2 additions & 0 deletions opencl/test/unit_test/aub_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ if(NOT NEO_SKIP_AUB_TESTS AND DEFINED AUB_STREAM_PROJECT_NAME)
target_link_libraries(igdrcl_aub_tests ${NEO_MOCKABLE_LIB_NAME} ${NEO_SHARED_MOCKABLE_LIB_NAME})
target_link_libraries(igdrcl_aub_tests igdrcl_mocks)
target_link_libraries(igdrcl_aub_tests gmock-gtest ${NEO_EXTRA_LIBS})
target_link_libraries(igdrcl_aub_tests ${AUB_STREAM_PROJECT_NAME})

if(UNIX)
target_link_libraries(igdrcl_aub_tests ${GMM_LINK_NAME})
else()
Expand Down
1 change: 1 addition & 0 deletions opencl/test/unit_test/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_executable(igdrcl_${target_name}
$<TARGET_OBJECTS:neo_libult_cs>
$<TARGET_OBJECTS:neo_shared_mocks>
$<TARGET_OBJECTS:neo_unit_tests_config>
$<TARGET_OBJECTS:mock_aubstream>
$<TARGET_OBJECTS:mock_gmm>
${CMAKE_CURRENT_SOURCE_DIR}/drm_wrap.h
${CMAKE_CURRENT_SOURCE_DIR}/main_linux_dll.cpp
Expand Down
3 changes: 2 additions & 1 deletion opencl/test/unit_test/mt_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2018-2023 Intel Corporation
# Copyright (C) 2018-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
Expand All @@ -19,6 +19,7 @@ add_executable(igdrcl_mt_tests EXCLUDE_FROM_ALL
$<TARGET_OBJECTS:neo_shared_mocks>
$<TARGET_OBJECTS:neo_mt_tests_config>
$<TARGET_OBJECTS:igdrcl_libult_env>
$<TARGET_OBJECTS:mock_aubstream>
$<TARGET_OBJECTS:mock_gmm>
$<TARGET_OBJECTS:${BUILTINS_SOURCES_LIB_NAME}>
)
Expand Down
1 change: 1 addition & 0 deletions opencl/test/unit_test/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if(WIN32)
$<TARGET_OBJECTS:neo_unit_tests_config>
$<TARGET_OBJECTS:igdrcl_libult>
$<TARGET_OBJECTS:igdrcl_libult_env>
$<TARGET_OBJECTS:mock_aubstream>
$<TARGET_OBJECTS:mock_gmm>
)

Expand Down
4 changes: 0 additions & 4 deletions shared/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ function(generate_shared_lib LIB_NAME MOCKABLE)
endif()
endif()

if(DEFINED AUB_STREAM_PROJECT_NAME)
target_link_libraries(${LIB_NAME} ${AUB_STREAM_PROJECT_NAME})
endif()

endfunction()

set(NEO_CORE_COMPILE_DEFS "")
Expand Down
15 changes: 1 addition & 14 deletions shared/source/aub_mem_dump/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2020-2023 Intel Corporation
# Copyright (C) 2020-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
Expand All @@ -17,19 +17,6 @@ set(NEO_CORE_AUB_MEM_DUMP
${CMAKE_CURRENT_SOURCE_DIR}/page_table_entry_bits.h
)

if(NOT DEFINED AUB_STREAM_PROJECT_NAME)
list(APPEND NEO_CORE_AUB_MEM_DUMP
${CMAKE_CURRENT_SOURCE_DIR}/aub_stream_stubs.cpp
)
else()
add_library(aub_stream_stubs STATIC
${CMAKE_CURRENT_SOURCE_DIR}/aub_stream_stubs.cpp
)
target_include_directories(aub_stream_stubs PRIVATE
${AUB_STREAM_HEADERS_DIR}
)
endif()

if(SUPPORT_XEHP_AND_LATER)
list(APPEND NEO_CORE_AUB_MEM_DUMP
${CMAKE_CURRENT_SOURCE_DIR}/aub_mem_dump_xehp_and_later.inl
Expand Down
15 changes: 15 additions & 0 deletions shared/source/aub_stream_stubs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright (C) 2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#

if(NOT DEFINED AUB_STREAM_PROJECT_NAME)
add_library(aub_stream_stubs OBJECT EXCLUDE_FROM_ALL
${CMAKE_CURRENT_SOURCE_DIR}/aub_stream_interface_stub.cpp
${CMAKE_CURRENT_SOURCE_DIR}/aub_stream_stubs.cpp
)
target_include_directories(aub_stream_stubs PRIVATE
${AUB_STREAM_HEADERS_DIR}
)
endif()
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2022 Intel Corporation
* Copyright (C) 2022-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/

#include "shared/source/aub/aub_center.h"
#include "aubstream/aub_manager.h"

namespace NEO {
aub_stream::AubManager *createAubManager(const aub_stream::AubManagerOptions &options) {
Expand Down
22 changes: 22 additions & 0 deletions shared/source/aub_stream_stubs/aub_stream_stubs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/

#include "aubstream/aubstream.h"

#include <limits>

namespace aub_stream {

extern "C" {
void injectMMIOList(MMIOList mmioList){};
void setTbxServerPort(uint16_t port){};
void setTbxServerIp(std::string server){};
void setTbxFrontdoorMode(bool frontdoor){};
void setAubStreamCaller(uint32_t caller){};
}

} // namespace aub_stream
17 changes: 17 additions & 0 deletions shared/test/common/mock_aubstream/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (C) 2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#

project(mock_aubstream)

add_library(
mock_aubstream EXCLUDE_FROM_ALL OBJECT
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/mock_aubstream.cpp
)

create_project_source_tree(mock_aubstream)
set_target_properties(mock_aubstream PROPERTIES FOLDER "test mocks")
target_include_directories(mock_aubstream PRIVATE ${AUB_STREAM_HEADERS_DIR})
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/

#include "aubstream/aubstream.h"

#include <limits>

namespace aub_stream_stubs {
uint16_t tbxServerPort = 4321;
std::string tbxServerIp = "127.0.0.1";
bool tbxFrontdoorMode = false;
uint32_t aubStreamCaller = std::numeric_limits<uint32_t>::max();
aub_stream::MMIOList mmioListInjected;
} // namespace aub_stream_stubs

namespace aub_stream {

extern "C" {
void injectMMIOList(MMIOList mmioList){};
void setTbxServerPort(uint16_t port) { aub_stream_stubs::tbxServerPort = port; };
void injectMMIOList(MMIOList mmioList) {
aub_stream_stubs::mmioListInjected = mmioList;
aub_stream_stubs::mmioListInjected.shrink_to_fit();
}
void setTbxServerPort(uint16_t port) {
aub_stream_stubs::tbxServerPort = port;
}
void setTbxServerIp(std::string server) {
// better to avoid reassigning global variables which assume memory allocations since
// we could step into false-positive memory leak detection with embedded leak check helper
if (aub_stream_stubs::tbxServerIp != server)
if (aub_stream_stubs::tbxServerIp != server) {
aub_stream_stubs::tbxServerIp = server;
};
void setTbxFrontdoorMode(bool frontdoor) { aub_stream_stubs::tbxFrontdoorMode = frontdoor; };
void setAubStreamCaller(uint32_t caller) { aub_stream_stubs::aubStreamCaller = caller; };
}
}
void setTbxFrontdoorMode(bool frontdoor) {
aub_stream_stubs::tbxFrontdoorMode = frontdoor;
}
void setAubStreamCaller(uint32_t caller) {
}

} // namespace aub_stream
4 changes: 1 addition & 3 deletions shared/test/common/mock_gmm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2020-2021 Intel Corporation
# Copyright (C) 2020-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
Expand All @@ -21,5 +21,3 @@ target_include_directories(${target_name} PRIVATE

create_project_source_tree(${target_name})
set_target_properties(${target_name} PROPERTIES FOLDER "test mocks")
target_compile_definitions(${target_name} PUBLIC)

1 change: 1 addition & 0 deletions shared/test/unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_executable(neo_shared_tests
${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
$<TARGET_OBJECTS:mock_aubstream>
$<TARGET_OBJECTS:mock_gmm>
$<TARGET_OBJECTS:neo_libult_common>
$<TARGET_OBJECTS:neo_libult_cs>
Expand Down
6 changes: 2 additions & 4 deletions shared/test/unit_test/aub/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2018-2022 Intel Corporation
# Copyright (C) 2018-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
Expand All @@ -10,8 +10,6 @@ target_sources(neo_shared_tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/aub_helper_tests.cpp
)

if(NOT DEFINED AUB_STREAM_PROJECT_NAME)
target_sources(neo_shared_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/aub_center_using_aubstream_stubs_tests.cpp)
endif()
target_sources(neo_shared_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/aub_center_using_aubstream_stubs_tests.cpp)

add_subdirectories()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -30,28 +30,31 @@ TEST(AubCenter, GivenUseAubStreamAndTbxServerIpDebugVariableSetWhenAubCenterIsCr
debugManager.flags.TbxServer.set("10.10.10.10");
VariableBackup<std::string> backup(&aub_stream_stubs::tbxServerIp);

ASSERT_STRNE("10.10.10.10", aub_stream_stubs::tbxServerIp.c_str());

MockExecutionEnvironment executionEnvironment{};
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[0];

MockAubCenter aubCenter(rootDeviceEnvironment, false, "", CommandStreamReceiverType::CSR_TBX);
MockAubCenter aubCenter(rootDeviceEnvironment, false, "", CommandStreamReceiverType::tbx);

EXPECT_STREQ("10.10.10.10", aub_stream_stubs::tbxServerIp.c_str());
}

TEST(AubCenter, GivenUseAubStreamAndTbxServerPortDebugVariableSetWhenAubCenterIsCreatedThenServerIpIsModified) {
TEST(AubCenter, GivenUseAubStreamAndTbxServerPortDebugVariableSetWhenAubCenterIsCreatedThenServerPortIsModified) {
DebugManagerStateRestore restorer;
debugManager.flags.UseAubStream.set(true);
debugManager.flags.TbxPort.set(1234);

VariableBackup<uint16_t> backup(&aub_stream_stubs::tbxServerPort);

aub_stream_stubs::tbxServerPort = 4321u;
uint16_t port = 1234u;
EXPECT_NE(port, aub_stream_stubs::tbxServerPort);
ASSERT_NE(port, aub_stream_stubs::tbxServerPort);

MockExecutionEnvironment executionEnvironment{};
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[0];

MockAubCenter aubCenter(rootDeviceEnvironment, false, "", CommandStreamReceiverType::CSR_TBX);
MockAubCenter aubCenter(rootDeviceEnvironment, false, "", CommandStreamReceiverType::tbx);
EXPECT_EQ(port, aub_stream_stubs::tbxServerPort);
}

Expand All @@ -62,11 +65,12 @@ TEST(AubCenter, GivenUseAubStreamAndTbxFrontdoorModeDebugVariableSetWhenAubCente

VariableBackup<bool> backup(&aub_stream_stubs::tbxFrontdoorMode);

aub_stream_stubs::tbxFrontdoorMode = false;
EXPECT_FALSE(aub_stream_stubs::tbxFrontdoorMode);

MockExecutionEnvironment executionEnvironment{};
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[0];

MockAubCenter aubCenter(rootDeviceEnvironment, false, "", CommandStreamReceiverType::CSR_TBX);
MockAubCenter aubCenter(rootDeviceEnvironment, false, "", CommandStreamReceiverType::tbx);
EXPECT_TRUE(aub_stream_stubs::tbxFrontdoorMode);
}

0 comments on commit 6b0ffc5

Please sign in to comment.