* This file is part of the MindStudio project.
* Copyright (c) 2025 Huawei Technologies Co.,Ltd.
*
* MindStudio is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* ------------------------------------------------------------------------- */
#include <gtest/gtest.h>
#include <string>
#include <algorithm>
#include <cstdlib>
#include "mockcpp/mockcpp.hpp"
#define private public
#define protected public
#include "runtime/inject_helpers/ProfConfig.h"
#include "acl_rt_impl/HijackedFunc.h"
#undef private
#undef protected
#include "acl_rt_impl/AscendclImplOrigin.h"
#include "injectors/ContextMockHelper.h"
#include "runtime/inject_helpers/ProfConfig.h"
#include "core/FuncSelector.h"
#include "runtime/inject_helpers/DBITask.h"
#include "runtime/inject_helpers/IPCMemManager.h"
using namespace std;
class HijackedFuncOfAclrtIpcMemCloseImplTest : public ::testing::Test {
protected:
void SetUp() override {}
void TearDown() override {}
};
TEST_F(HijackedFuncOfAclrtIpcMemCloseImplTest, TestPostWithSanitizerAndKeyIsNull)
{
HijackedFuncOfAclrtIpcMemCloseImpl func;
func.Pre(nullptr);
MOCKER(IsSanitizer).stubs().will(returnValue(true));
aclError ret = func.Post(ACL_SUCCESS);
EXPECT_EQ(ret, ACL_SUCCESS);
GlobalMockObject::verify();
}
TEST_F(HijackedFuncOfAclrtIpcMemCloseImplTest, TestPostWithSanitizer)
{
HijackedFuncOfAclrtIpcMemCloseImpl func;
func.Pre(nullptr);
MOCKER(IsSanitizer).stubs().will(returnValue(true));
aclError ret = func.Post(ACL_SUCCESS);
EXPECT_EQ(ret, ACL_SUCCESS);
GlobalMockObject::verify();
}
TEST_F(HijackedFuncOfAclrtIpcMemCloseImplTest, TestPostWithSanitizerAndKeyNotFound)
{
HijackedFuncOfAclrtIpcMemCloseImpl func;
const char* key = "test_key";
const char* keyInsert = "test_key_insert";
func.Pre(key);
MOCKER(IsSanitizer).stubs().will(returnValue(true));
IPCMemManager::IPCMemInfo ipcMemInfo{IPCMemManager::IPCMemActor::SHAREE, nullptr};
IPCMemManager::Instance().ipcMemInfoMap.insert({keyInsert, ipcMemInfo});
aclError ret = func.Post(ACL_ERROR_NONE);
EXPECT_EQ(ret, ACL_ERROR_NONE);
GlobalMockObject::verify();
}
TEST_F(HijackedFuncOfAclrtIpcMemCloseImplTest, TestPostWithSanitizerAndKeyFoundAsSharer)
{
HijackedFuncOfAclrtIpcMemCloseImpl func;
const char* key = "test_key";
func.Pre(key);
MOCKER(IsSanitizer).stubs().will(returnValue(true));
IPCMemManager::IPCMemInfo ipcMemInfo{IPCMemManager::IPCMemActor::SHARER, nullptr};
IPCMemManager::Instance().ipcMemInfoMap.insert({key, ipcMemInfo});
aclError ret = func.Post(ACL_SUCCESS);
EXPECT_EQ(ret, ACL_SUCCESS);
GlobalMockObject::verify();
}
TEST_F(HijackedFuncOfAclrtIpcMemCloseImplTest, TestPostWithSanitizerAndKeyFoundAsSharee)
{
HijackedFuncOfAclrtIpcMemCloseImpl func;
const char* key = "test_key";
func.Pre(key);
MOCKER(IsSanitizer).stubs().will(returnValue(true));
IPCMemManager::IPCMemInfo ipcMemInfo{IPCMemManager::IPCMemActor::SHAREE, nullptr};
IPCMemManager::Instance().ipcMemInfoMap.insert({key, ipcMemInfo});
aclError ret = func.Post(ACL_SUCCESS);
EXPECT_EQ(ret, ACL_SUCCESS);
GlobalMockObject::verify();
}