refactor: add mock_aubstream

Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com>
This commit is contained in:
Artur Harasimiuk
2024-04-25 13:47:06 +00:00
committed by Compute-Runtime-Automation
parent 4aa7c6c99e
commit cbc868c4ed
22 changed files with 102 additions and 48 deletions

View File

@@ -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})

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "aubstream/aubstream.h"
namespace aub_stream_stubs {
uint16_t tbxServerPort = 4321;
std::string tbxServerIp = "127.0.0.1";
bool tbxFrontdoorMode = false;
aub_stream::MMIOList mmioListInjected;
} // namespace aub_stream_stubs
namespace aub_stream {
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) {
aub_stream_stubs::tbxServerIp = server;
}
}
void setTbxFrontdoorMode(bool frontdoor) {
aub_stream_stubs::tbxFrontdoorMode = frontdoor;
}
void setAubStreamCaller(uint32_t caller) {
}
} // namespace aub_stream

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2020-2021 Intel Corporation
# Copyright (C) 2020-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@@ -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)

View File

@@ -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>

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2018-2022 Intel Corporation
# Copyright (C) 2018-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@@ -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()

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -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);
}
@@ -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);
}