Add SA UT test case

Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IALR3L
Signed-off-by: ChenYC009 <chenyongchun5@huawei.com>
Change-Id: Icbf71990a43c320fee8468b29e3bab73f017a988
This commit is contained in:
ChenYC009 2024-09-02 10:09:16 +08:00
parent b77ed0e804
commit 4f5e099948
13 changed files with 1490 additions and 29 deletions

View File

@ -50,6 +50,9 @@ int32_t AotCompilerImpl::FindArgsIdxToInteger(const std::unordered_map<std::stri
if (argsMap.find(keyName) == argsMap.end()) {
return ERR_AOT_COMPILER_PARAM_FAILED;
}
if (argsMap.at(keyName).empty() || !isdigit(argsMap.at(keyName).at(0))) {
return ERR_AOT_COMPILER_PARAM_FAILED;
}
size_t sz;
bundleID = static_cast<int32_t>(std::stoi(argsMap.at(keyName), &sz));
if (sz < static_cast<size_t>(argsMap.at(keyName).size())) {
@ -223,6 +226,7 @@ int32_t AotCompilerImpl::EcmascriptAotCompiler(const std::unordered_map<std::str
{
#ifdef CODE_SIGN_ENABLE
if (!allowAotCompiler_) {
LOG_SA(ERROR) << "aot compiler is not allowed now";
return ERR_AOT_COMPILER_CONNECT_FAILED;
}
if (argsMap.empty() || (PrepareArgs(argsMap) != ERR_OK)) {

View File

@ -15,8 +15,11 @@ group("compiler_service_unittest") {
testonly = true
deps = [
"unittest/aotcompilerclient_unit:AotCompilerClientUnitTest",
"unittest/aotcompilererrorutils_unit:AotCompilerErrorUtilsUnitTest",
"unittest/aotcompilerimpl_unit:AotCompilerImplUnitTest",
"unittest/aotcompilerproxy_unit:AotCompilerProxyUnitTest",
"unittest/aotcompilerservice_unit:AotCompilerServiceUnitTest",
"unittest/aotcompilerstub_unit:AotCompilerStubUnitTest",
]
}

View File

@ -31,6 +31,6 @@ enum Level {
ERROR,
FATAL,
};
std::ostringstream LOG_SA(const Level level);
std::ostringstream LOG_SA([[maybe_unused]] const Level level);
} // namespace OHOS::ArkCompiler
#endif // MOCK_ECMASCRIPT_LOG_WRAPPER_H

View File

@ -19,7 +19,13 @@
#include "ecmascript/log_wrapper.h"
namespace OHOS::ArkCompiler {
std::ostringstream LOG_SA(const Level level)
int waitpid(const pid_t childPid, int* status, [[maybe_unused]] int option)
{
*status = childPid;
return 0;
}
std::ostringstream LOG_SA([[maybe_unused]] const Level level)
{
std::ostringstream stream_;
return stream_;

View File

@ -67,7 +67,6 @@ sptr<IRemoteObject> AotCompilerClientTest::GetAotRemoteObject(AotCompilerClient
* @tc.name: AotCompilerClientTest_001
* @tc.desc: AotCompilerClient::GetInstance()
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_001, TestSize.Level0)
{
@ -84,7 +83,6 @@ HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_001, TestSize.Level0)
* @tc.name: AotCompilerClientTest_002
* @tc.desc: invoke aot_compiler service in client program.
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_002, TestSize.Level0)
{
@ -101,7 +99,6 @@ HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_002, TestSize.Level0)
* @tc.name: AotCompilerClientTest_003
* @tc.desc: LoadSystemAbility(AOT_COMPILER_SERVICE_ID, loadCallback)
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_003, TestSize.Level0)
{
@ -119,7 +116,6 @@ HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_003, TestSize.Level0)
* @tc.name: AotCompilerClientTest_004
* @tc.desc: aotClient.LoadAotCompilerService()
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_004, TestSize.Level0)
{
@ -136,7 +132,6 @@ HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_004, TestSize.Level0)
* @tc.name: AotCompilerClientTest_005
* @tc.desc: aotClient.GetAotCompilerProxy()
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_005, TestSize.Level0)
{
@ -152,7 +147,6 @@ HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_005, TestSize.Level0)
* @tc.name: AotCompilerClientTest_006
* @tc.desc: aotClient.StopAotCompiler()
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_006, TestSize.Level0)
{
@ -165,7 +159,6 @@ HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_006, TestSize.Level0)
* @tc.name: AotCompilerClientTest_007
* @tc.desc: aotClient.loadSaFinished_
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_007, TestSize.Level0)
{
@ -179,7 +172,6 @@ HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_007, TestSize.Level0)
* @tc.name: AotCompilerClientTest_008
* @tc.desc: aotClient.AotCompilerOnRemoteDied()
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_008, TestSize.Level0)
{
@ -196,7 +188,6 @@ HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_008, TestSize.Level0)
* @tc.name: AotCompilerClientTest_009
* @tc.desc: callback.OnLoadSystemAbilitySuccess()
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_009, TestSize.Level0)
{
@ -222,7 +213,6 @@ HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_009, TestSize.Level0)
* @tc.name: AotCompilerClientTest_010
* @tc.desc: callback.OnLoadSystemAbilityFail()
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_010, TestSize.Level0)
{
@ -240,4 +230,49 @@ HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_010, TestSize.Level0)
callback.OnLoadSystemAbilityFail(AOT_COMPILER_SERVICE_ID);
EXPECT_EQ(aotClient.GetAotCompiler(), nullptr);
}
/**
* @tc.name: AotCompilerClientTest_011
* @tc.desc: aotClient.NeedReCompile(oldVersion, sigData)
* @tc.type: Func
*/
HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_011, TestSize.Level0)
{
AotCompilerClient &aotClient = AotCompilerClient::GetInstance();
std::string oldVersion = "4.0.0.0";
bool sigData = false;
int32_t ret = aotClient.NeedReCompile(oldVersion, sigData);
EXPECT_EQ(ret, ERR_OK);
}
/**
* @tc.name: AotCompilerClientTest_012
* @tc.desc: aotClient.GetAOTVersion(sigData)
* @tc.type: Func
*/
HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_012, TestSize.Level0)
{
AotCompilerClient &aotClient = AotCompilerClient::GetInstance();
std::string sigData = "test_string";
int32_t ret = aotClient.GetAOTVersion(sigData);
EXPECT_EQ(ret, ERR_OK);
EXPECT_STRNE(sigData.c_str(), "test_string");
}
/**
* @tc.name: AotCompilerClientTest_013
* @tc.desc: aotClient.OnRemoteDied(const wptr<IRemoteObject> &remote)
* @tc.type: Func
*/
HWTEST_F(AotCompilerClientTest, AotCompilerClientTest_013, TestSize.Level0)
{
AotCompilerClient &aotClient = AotCompilerClient::GetInstance();
aotClient.aotCompilerDiedRecipient_->OnRemoteDied(nullptr);
EXPECT_EQ(aotClient.GetAotCompiler(), nullptr);
wptr<IRemoteObject> remoteObject_weak = GetAotRemoteObject(aotClient);
EXPECT_NE(remoteObject_weak, nullptr);
aotClient.aotCompilerDiedRecipient_->OnRemoteDied(remoteObject_weak);
EXPECT_EQ(aotClient.GetAotCompiler(), nullptr);
}
} // namespace OHOS::ArkCompiler

View File

@ -0,0 +1,55 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("../../compiler_service_test.gni")
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = compiler_service_include_dirs
cflags = [ "-Wno-error=keyword-macro" ]
}
ohos_unittest("AotCompilerErrorUtilsUnitTest") {
module_out_path = module_output_path
sources = aot_compiler_service_sources
configs = [ ":module_private_config" ]
deps = [
"${compiler_service_root}:libcompiler_service",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"icu:shared_icui18n",
"icu:shared_icuuc",
"ipc:ipc_core",
"power_manager:powermgr_client",
"runtime_core:libarkfile_static",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = []
if (defined(global_parts_info) &&
!defined(global_parts_info.security_code_signature)) {
external_deps += [ "code_signature:liblocal_code_sign_sdk" ]
defines += [ "CODE_SIGN_ENABLE" ]
}
sources += [ "aotcompilererrorutils_unit.cpp" ]
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdint>
#include <gtest/gtest.h>
#include <string>
#include <vector>
#include "aot_compiler_client.h"
#include "aot_compiler_service.h"
#include "aot_compiler_error_utils.h"
#include "aot_compiler_load_callback.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
using namespace testing::ext;
namespace OHOS::ArkCompiler {
class AotCompilerErrorUtilsTest : public testing::Test {
public:
AotCompilerErrorUtilsTest() {}
virtual ~AotCompilerErrorUtilsTest() {}
static void SetUpTestCase() {}
static void TearDownTestCase() {}
void SetUp() override {}
void TearDown() override {}
};
/**
* @tc.name: AotCompilerErrorUtilsTest_001
* @tc.desc: AotCompilerErrorUtil::GetErrorMessage(errCode)
* @tc.type: Func
*/
HWTEST_F(AotCompilerErrorUtilsTest, AotCompilerErrorUtilsTest_001, TestSize.Level0)
{
AotCompilerErrorUtil aotErrorUtils;
std::string errMsg1;
std::string errMsg2;
errMsg1 = aotErrorUtils.GetErrorMessage(ERR_OK);
errMsg2 = aotErrorUtils.GetErrorMessage(INVALID_ERR_CODE);
EXPECT_STREQ(errMsg1.c_str(), "success");
EXPECT_STREQ(errMsg2.c_str(), "invalid errCode");
}
} // namespace OHOS::ArkCompiler

View File

@ -14,9 +14,11 @@
*/
#include <cstdint>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <gtest/hwext/gtest-multithread.h>
#include <mutex>
#include <securec.h>
#include <string>
#include <thread>
#include <vector>
@ -35,6 +37,9 @@ using namespace testing::mt;
namespace OHOS::ArkCompiler {
namespace {
constexpr int TEST_ERR_OK = 0;
constexpr int TEST_ERR_AN_EMPTY = 5;
constexpr int TEST_ERR_OTHERS = 100;
const std::string compilerPkgInfoValue =
"{\"abcName\":\"ets/modules.abc\","
"\"abcOffset\":\"0x1000\","
@ -73,6 +78,58 @@ public:
AotCompilerImplMock(AotCompilerImplMock&&) = delete;
AotCompilerImplMock& operator=(const AotCompilerImplMock&) = delete;
AotCompilerImplMock& operator=(AotCompilerImplMock&&) = delete;
int32_t FindArgsIdxToIntegerMock(const std::unordered_map<std::string, std::string> &argsMap,
const std::string &keyName, int32_t &bundleID)
{
return FindArgsIdxToInteger(argsMap, keyName, bundleID);
}
int32_t FindArgsIdxToStringMock(const std::unordered_map<std::string, std::string> &argsMap,
const std::string &keyName, std::string &bundleArg)
{
return FindArgsIdxToString(argsMap, keyName, bundleArg);
}
int32_t PrepareArgsMock(const std::unordered_map<std::string, std::string> &argsMap)
{
return PrepareArgs(argsMap);
}
int32_t PrintAOTCompilerResultMock(const int compilerStatus) const
{
return PrintAOTCompilerResult(compilerStatus);
}
void AddExpandArgsMock(std::vector<std::string> &argVector)
{
AddExpandArgs(argVector);
}
int32_t AOTLocalCodeSignMock(std::vector<int16_t> &sigData) const
{
return AOTLocalCodeSign(sigData);
}
void InitStateMock(const pid_t childPid)
{
InitState(childPid);
}
void ResetStateMock()
{
ResetState();
}
void PauseAotCompilerMock()
{
PauseAotCompiler();
}
void AllowAotCompilerMock()
{
AllowAotCompiler();
}
};
class AotCompilerImplTest : public testing::Test {
@ -90,7 +147,6 @@ public:
* @tc.name: AotCompilerImplTest_001
* @tc.desc: AotCompilerImpl::GetInstance()
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_001, TestSize.Level0)
{
@ -103,7 +159,6 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_001, TestSize.Level0)
* @tc.name: AotCompilerImplTest_002
* @tc.desc: AotCompilerImpl::EcmascriptAotCompiler() when compiler-check-pgo-version
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_002, TestSize.Level0)
{
@ -126,7 +181,6 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_002, TestSize.Level0)
* @tc.name: AotCompilerImplTest_003
* @tc.desc: AotCompilerImpl::EcmascriptAotCompiler() when compile not any method
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_003, TestSize.Level0)
{
@ -149,7 +203,6 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_003, TestSize.Level0)
* @tc.name: AotCompilerImplTest_004
* @tc.desc: AotCompilerImpl::StopAotCompiler()
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_004, TestSize.Level0)
{
@ -162,7 +215,6 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_004, TestSize.Level0)
* @tc.name: AotCompilerImplTest_005
* @tc.desc: AotCompilerImpl::GetAOTVersion(std::string& sigData)
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_005, TestSize.Level0)
{
@ -177,7 +229,6 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_005, TestSize.Level0)
* @tc.name: AotCompilerImplTest_006
* @tc.desc: AotCompilerImpl::NeedReCompile(const std::string& args, bool& sigData)
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_006, TestSize.Level0)
{
@ -193,7 +244,6 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_006, TestSize.Level0)
* @tc.name: AotCompilerImplTest_007
* @tc.desc: AotCompilerImpl::HandlePowerDisconnected()
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_007, TestSize.Level0)
{
@ -211,7 +261,6 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_007, TestSize.Level0)
* @tc.name: AotCompilerImplTest_008
* @tc.desc: AotCompilerImpl::HandleScreenOn()
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_008, TestSize.Level0)
{
@ -229,7 +278,6 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_008, TestSize.Level0)
* @tc.name: AotCompilerImplTest_009
* @tc.desc: AotCompilerImpl::HandleThermalLevelChanged()
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_009, TestSize.Level0)
{
@ -247,7 +295,6 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_009, TestSize.Level0)
* @tc.name: AotCompilerImplTest_010
* @tc.desc: AotCompilerImpl::EcmascriptAotCompiler() when multi thread run
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
AotCompilerImpl &gtAotImpl = AotCompilerImplMock::GetInstance();
std::mutex aotCompilerMutex_;
@ -295,7 +342,6 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_010, TestSize.Level0)
* @tc.desc: AotCompilerImpl::StopAotCompiler() while EcmascriptAotCompiler() is
* running regarding multi threads.
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_011, TestSize.Level0)
{
@ -316,4 +362,257 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_012, TestSize.Level0)
EXPECT_TRUE(g_retGlobal);
#endif
}
/**
* @tc.name: AotCompilerImplTest_013
* @tc.desc: AotCompilerImpl::FindArgsIdxToInteger(argsMap, keyName, bundleID)
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_013, TestSize.Level0)
{
AotCompilerImplMock aotImplMock;
std::unordered_map<std::string, std::string> argsMap;
std::string keyName = "compiler-pkg-info";
int32_t bundleID = 0;
int32_t ret = aotImplMock.FindArgsIdxToIntegerMock(argsMap, keyName, bundleID);
EXPECT_EQ(ret, ERR_AOT_COMPILER_PARAM_FAILED);
}
/**
* @tc.name: AotCompilerImplTest_014
* @tc.desc: AotCompilerImpl::FindArgsIdxToInteger(argsMap, keyName, bundleID)
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_014, TestSize.Level0)
{
AotCompilerImplMock aotImplMock;
std::unordered_map<std::string, std::string> argsMap;
argsMap.emplace("argKey", "argValueNotInteger");
std::string keyName = "argKey";
int32_t bundleID = 0;
int32_t ret = aotImplMock.FindArgsIdxToIntegerMock(argsMap, keyName, bundleID);
EXPECT_EQ(ret, ERR_AOT_COMPILER_PARAM_FAILED);
}
/**
* @tc.name: AotCompilerImplTest_015
* @tc.desc: AotCompilerImpl::FindArgsIdxToInteger(argsMap, keyName, bundleID)
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_015, TestSize.Level0)
{
AotCompilerImplMock aotImplMock;
std::unordered_map<std::string, std::string> argsMap;
argsMap.emplace("argKey", "123456_argValueNotInteger");
std::string keyName = "argKey";
int32_t bundleID = 0;
int32_t ret = aotImplMock.FindArgsIdxToIntegerMock(argsMap, keyName, bundleID);
EXPECT_EQ(ret, ERR_AOT_COMPILER_PARAM_FAILED);
}
/**
* @tc.name: AotCompilerImplTest_016
* @tc.desc: AotCompilerImpl::FindArgsIdxToInteger(argsMap, keyName, bundleID)
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_016, TestSize.Level0)
{
AotCompilerImplMock aotImplMock;
std::unordered_map<std::string, std::string> argsMap;
argsMap.emplace("argKey", "20020079");
std::string keyName = "argKey";
int32_t bundleID = 0;
int32_t ret = aotImplMock.FindArgsIdxToIntegerMock(argsMap, keyName, bundleID);
EXPECT_EQ(ret, ERR_OK);
EXPECT_EQ(bundleID, 20020079);
}
/**
* @tc.name: AotCompilerImplTest_017
* @tc.desc: AotCompilerImpl::FindArgsIdxToString(argsMap, keyName, bundleArg)
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_017, TestSize.Level0)
{
AotCompilerImplMock aotImplMock;
std::unordered_map<std::string, std::string> argsMap;
std::string keyName = "argKey";
std::string bundleArg = "";
int32_t ret = aotImplMock.FindArgsIdxToStringMock(argsMap, keyName, bundleArg);
EXPECT_EQ(ret, ERR_AOT_COMPILER_PARAM_FAILED);
}
/**
* @tc.name: AotCompilerImplTest_018
* @tc.desc: AotCompilerImpl::FindArgsIdxToString(argsMap, keyName, bundleArg)
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_018, TestSize.Level0)
{
AotCompilerImplMock aotImplMock;
std::unordered_map<std::string, std::string> argsMap;
argsMap.emplace("argKey", "com.ohos.contacts");
std::string keyName = "argKey";
std::string bundleArg = "";
int32_t ret = aotImplMock.FindArgsIdxToStringMock(argsMap, keyName, bundleArg);
EXPECT_EQ(ret, ERR_OK);
EXPECT_STREQ(bundleArg.c_str(), "com.ohos.contacts");
}
/**
* @tc.name: AotCompilerImplTest_019
* @tc.desc: AotCompilerImpl::PrepareArgs(argsMapForTest)
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_019, TestSize.Level0)
{
AotCompilerImplMock aotImplMock;
std::unordered_map<std::string, std::string> argsMap;
int32_t ret = aotImplMock.PrepareArgsMock(argsMap);
EXPECT_EQ(ret, ERR_AOT_COMPILER_PARAM_FAILED);
ret = aotImplMock.PrepareArgsMock(argsMapForTest);
EXPECT_EQ(ret, ERR_OK);
}
/**
* @tc.name: AotCompilerImplTest_020
* @tc.desc: AotCompilerImpl::AddExpandArgs(aotVector)
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_020, TestSize.Level0)
{
bool viewData = true;
AotCompilerImplMock aotImplMock;
std::vector<std::string> aotVector;
aotImplMock.AddExpandArgsMock(aotVector);
EXPECT_TRUE(viewData);
}
/**
* @tc.name: AotCompilerImplTest_021
* @tc.desc: AotCompilerImpl::PrintAOTCompilerResult(TEST_ERR_AN_EMPTY)
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_021, TestSize.Level0)
{
AotCompilerImplMock aotImplMock;
int32_t ret = aotImplMock.PrintAOTCompilerResultMock(TEST_ERR_OTHERS);
EXPECT_EQ(ret, ERR_AOT_COMPILER_CALL_FAILED);
ret = aotImplMock.PrintAOTCompilerResultMock(TEST_ERR_AN_EMPTY);
EXPECT_EQ(ret, ERR_AOT_COMPILER_CALL_FAILED);
ret = aotImplMock.PrintAOTCompilerResultMock(TEST_ERR_OK);
EXPECT_EQ(ret, ERR_OK);
}
/**
* @tc.name: AotCompilerImplTest_022
* @tc.desc: AotCompilerImpl::EcmascriptAotCompiler(argsMap, sigData)
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_022, TestSize.Level0)
{
AotCompilerImplMock aotImplMock;
std::unordered_map<std::string, std::string> argsMap;
std::vector<int16_t> sigData;
int32_t ret = ERR_FAIL;
#ifdef CODE_SIGN_ENABLE
aotImplMock.PauseAotCompilerMock();
ret = aotImplMock.EcmascriptAotCompiler(argsMap, sigData);
EXPECT_EQ(ret, ERR_AOT_COMPILER_CONNECT_FAILED);
aotImplMock.AllowAotCompilerMock();
ret = aotImplMock.EcmascriptAotCompiler(argsMap, sigData);
EXPECT_EQ(ret, ERR_AOT_COMPILER_PARAM_FAILED);
aotImplMock.AllowAotCompilerMock();
ret = aotImplMock.EcmascriptAotCompiler(argsMapForTest, sigData);
EXPECT_NE(ret, ERR_AOT_COMPILER_SIGNATURE_DISABLE);
#else
ret = aotImplMock.EcmascriptAotCompiler(argsMapForTest, sigData);
EXPECT_EQ(ret, ERR_AOT_COMPILER_SIGNATURE_DISABLE);
#endif
EXPECT_TRUE(sigData.empty());
}
/**
* @tc.name: AotCompilerImplTest_023
* @tc.desc: AotCompilerImpl::AOTLocalCodeSign(sigData)
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_023, TestSize.Level0)
{
AotCompilerImplMock aotImplMock;
std::string fileName = "/data/local/ark-cache/com.ohos.contacts/arm64/entry.an";
std::string appSignature = "5765880207853624761";
std::vector<int16_t> sigData;
int32_t ret = aotImplMock.PrepareArgsMock(argsMapForTest);
EXPECT_EQ(ret, ERR_OK);
ret = aotImplMock.AOTLocalCodeSignMock(sigData);
#ifdef CODE_SIGN_ENABLE
EXPECT_NE(ret, ERR_AOT_COMPILER_SIGNATURE_DISABLE);
#else
EXPECT_EQ(ret, ERR_AOT_COMPILER_SIGNATURE_DISABLE);
#endif
}
/**
* @tc.name: AotCompilerImplTest_024
* @tc.desc: AotCompilerImpl::StopAotCompiler()
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_024, TestSize.Level0)
{
AotCompilerImplMock aotImplMock;
aotImplMock.ResetStateMock();
int32_t ret = aotImplMock.StopAotCompiler();
EXPECT_EQ(ret, ERR_AOT_COMPILER_STOP_FAILED);
aotImplMock.InitStateMock(-1);
ret = aotImplMock.StopAotCompiler();
EXPECT_EQ(ret, ERR_AOT_COMPILER_STOP_FAILED);
aotImplMock.InitStateMock(123456789); // test_childPid = 123456789
ret = aotImplMock.StopAotCompiler();
EXPECT_EQ(ret, ERR_AOT_COMPILER_STOP_FAILED);
}
/**
* @tc.name: AotCompilerImplTest_025
* @tc.desc: AotCompilerImpl::HandlePowerDisconnected()
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_025, TestSize.Level0)
{
bool viewData = true;
AotCompilerImplMock aotImplMock;
aotImplMock.HandlePowerDisconnected();
EXPECT_TRUE(viewData);
}
/**
* @tc.name: AotCompilerImplTest_026
* @tc.desc: AotCompilerImpl::HandleScreenOn()
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_026, TestSize.Level0)
{
bool viewData = true;
AotCompilerImplMock aotImplMock;
aotImplMock.HandleScreenOn();
EXPECT_TRUE(viewData);
}
/**
* @tc.name: AotCompilerImplTest_027
* @tc.desc: AotCompilerImpl::HandleThermalLevelChanged(aotImpl.AOT_COMPILE_STOP_LEVEL)
* @tc.type: Func
*/
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_027, TestSize.Level0)
{
bool viewData = true;
AotCompilerImplMock aotImplMock;
aotImplMock.HandleThermalLevelChanged(aotImplMock.AOT_COMPILE_STOP_LEVEL);
aotImplMock.HandleThermalLevelChanged(aotImplMock.AOT_COMPILE_STOP_LEVEL - 1);
EXPECT_TRUE(viewData);
}
} // namespace OHOS::ArkCompiler

View File

@ -0,0 +1,54 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("../../compiler_service_test.gni")
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = compiler_service_include_dirs
cflags = [ "-Wno-error=keyword-macro" ]
}
ohos_unittest("AotCompilerProxyUnitTest") {
module_out_path = module_output_path
sources = aot_compiler_service_sources
configs = [ ":module_private_config" ]
deps = [
"${compiler_service_root}:libcompiler_service",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"icu:shared_icui18n",
"icu:shared_icuuc",
"ipc:ipc_core",
"runtime_core:libarkfile_static",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = []
if (defined(global_parts_info) &&
!defined(global_parts_info.security_code_signature)) {
external_deps += [ "code_signature:liblocal_code_sign_sdk" ]
defines += [ "CODE_SIGN_ENABLE" ]
}
sources += [ "aotcompilerproxy_unit.cpp" ]
}

View File

@ -0,0 +1,403 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdint>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <string>
#include <vector>
#include "aot_compiler_client.h"
#include "aot_compiler_service.h"
#include "aot_compiler_error_utils.h"
#include "aot_compiler_interface_proxy.h"
#include "aot_compiler_interface_stub.h"
#include "aot_compiler_load_callback.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
using namespace testing::ext;
namespace OHOS::ArkCompiler {
namespace {
constexpr int32_t TEST_COMMAND_AOT_COMPILER = MIN_TRANSACTION_ID + 0;
constexpr int32_t TEST_COMMAND_STOP_AOT_COMPILER = MIN_TRANSACTION_ID + 1;
constexpr int32_t TEST_COMMAND_GET_AOT_VERSION = MIN_TRANSACTION_ID + 2;
constexpr int32_t TEST_COMMAND_NEED_RE_COMPILE = MIN_TRANSACTION_ID + 3;
constexpr int32_t TEST_COMMAND_INVALID = MIN_TRANSACTION_ID + 1000;
const unsigned long VECTOR_MAX_SIZE = 102400;
}
class MockAotCompilerStub : public IRemoteStub<IAotCompilerInterface> {
public:
MockAotCompilerStub() = default;
virtual ~MockAotCompilerStub() = default;
MOCK_METHOD(int32_t, CommandAOTCompiler, (MessageParcel &data, MessageParcel &reply));
MOCK_METHOD(int32_t, CommandStopAOTCompiler, (MessageParcel &reply));
MOCK_METHOD(int32_t, CommandGetAOTVersion, (MessageParcel& reply));
MOCK_METHOD(int32_t, CommandNeedReCompile, (MessageParcel& data, MessageParcel& reply));
MOCK_METHOD(ErrCode, AotCompiler, ((const std::unordered_map<std::string, std::string> &argsMap),
std::vector<int16_t> &sigData), (override));
MOCK_METHOD(ErrCode, StopAotCompiler, (), (override));
MOCK_METHOD(ErrCode, GetAOTVersion, (std::string& sigData), (override));
MOCK_METHOD(ErrCode, NeedReCompile, (const std::string& args, bool& sigData), (override));
int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
{
std::u16string localDescriptor = GetDescriptor();
std::u16string remoteDescriptor = data.ReadInterfaceToken();
if (localDescriptor != remoteDescriptor) {
return TEST_COMMAND_INVALID;
}
switch (code) {
case TEST_COMMAND_AOT_COMPILER:
return CommandAOTCompiler(data, reply);
case TEST_COMMAND_STOP_AOT_COMPILER:
return CommandStopAOTCompiler(reply);
case TEST_COMMAND_GET_AOT_VERSION:
return CommandGetAOTVersion(reply);
case TEST_COMMAND_NEED_RE_COMPILE:
return CommandNeedReCompile(data, reply);
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
return TEST_COMMAND_INVALID;
}
};
class AotCompilerProxyMock : public AotCompilerInterfaceProxy {
public:
explicit AotCompilerProxyMock(const sptr<IRemoteObject>& remote): AotCompilerInterfaceProxy(remote) {}
virtual ~AotCompilerProxyMock() = default;
IRemoteObject* Remote()
{
return nullptr;
}
};
class AotCompilerProxyTest : public testing::Test {
public:
AotCompilerProxyTest() {}
virtual ~AotCompilerProxyTest() {}
static void SetUpTestCase() {}
static void TearDownTestCase() {}
void SetUp() override;
void TearDown() override {}
sptr<MockAotCompilerStub> mockStub_ = nullptr;
sptr<AotCompilerInterfaceProxy> proxy_ = nullptr;
};
void AotCompilerProxyTest::SetUp()
{
mockStub_ = new (std::nothrow) MockAotCompilerStub();
proxy_ = new (std::nothrow) AotCompilerInterfaceProxy(mockStub_->AsObject());
}
/**
* @tc.name: AotCompilerProxyTest_001
* @tc.desc: AotCompilerProxy::AotCompiler(argsMap, sigData) when SendRequest fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_001, TestSize.Level0)
{
sptr<IRemoteObject> remote = nullptr;
sptr<AotCompilerProxyMock> mockProxy_ = new AotCompilerProxyMock(remote);
std::unordered_map<std::string, std::string> argsMap;
std::vector<int16_t> sigData;
int32_t result = mockProxy_->AotCompiler(argsMap, sigData);
EXPECT_EQ(result, ERR_INVALID_DATA);
}
/**
* @tc.name: AotCompilerProxyTest_002
* @tc.desc: AotCompilerProxy::StopAotCompiler() when SendRequest fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_002, TestSize.Level0)
{
sptr<IRemoteObject> remote = nullptr;
sptr<AotCompilerProxyMock> mockProxy_ = new AotCompilerProxyMock(remote);
int32_t result = mockProxy_->StopAotCompiler();
EXPECT_EQ(result, ERR_INVALID_DATA);
}
/**
* @tc.name: AotCompilerProxyTest_003
* @tc.desc: AotCompilerProxy::GetAOTVersion(sigData) when SendRequest fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_003, TestSize.Level0)
{
sptr<IRemoteObject> remote = nullptr;
sptr<AotCompilerProxyMock> mockProxy_ = new AotCompilerProxyMock(remote);
std::string sigData = "===";
int32_t result = mockProxy_->GetAOTVersion(sigData);
EXPECT_EQ(result, ERR_INVALID_DATA);
}
/**
* @tc.name: AotCompilerProxyTest_004
* @tc.desc: AotCompilerProxy::NeedReCompile(args, sigData) when SendRequest fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_004, TestSize.Level0)
{
sptr<IRemoteObject> remote = nullptr;
sptr<AotCompilerProxyMock> mockProxy_ = new AotCompilerProxyMock(remote);
std::string args = "--aot";
bool sigData = false;
int32_t result = mockProxy_->NeedReCompile(args, sigData);
EXPECT_EQ(result, ERR_INVALID_DATA);
}
/**
* @tc.name: AotCompilerProxyTest_005
* @tc.desc: AotCompilerProxy::AotCompiler(argsMap, sigData) when connect fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_005, TestSize.Level0)
{
std::unordered_map<std::string, std::string> argsMap;
std::vector<int16_t> sigData;
EXPECT_CALL(*mockStub_, CommandAOTCompiler(testing::_, testing::_)).
Times(1).WillOnce(testing::Return(ERR_AOT_COMPILER_CONNECT_FAILED));
int32_t result = proxy_->AotCompiler(argsMap, sigData);
EXPECT_EQ(result, ERR_AOT_COMPILER_CONNECT_FAILED);
}
/**
* @tc.name: AotCompilerProxyTest_006
* @tc.desc: AotCompilerProxy::AotCompiler(argsMap, sigData) when compile fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_006, TestSize.Level0)
{
std::unordered_map<std::string, std::string> argsMap;
std::vector<int16_t> sigData;
auto func = [](MessageParcel &data, MessageParcel &reply) -> int32_t {
reply.WriteInt32(ERR_AOT_COMPILER_CALL_FAILED);
return ERR_OK;
};
EXPECT_CALL(*mockStub_, CommandAOTCompiler(testing::_, testing::_)).
Times(1).WillOnce(testing::Invoke(func));
int32_t result = proxy_->AotCompiler(argsMap, sigData);
EXPECT_EQ(result, ERR_AOT_COMPILER_CALL_FAILED);
}
/**
* @tc.name: AotCompilerProxyTest_007
* @tc.desc: AotCompilerProxy::AotCompiler(argsMap, sigData) when VECTOR_MAX_SIZE invalid
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_007, TestSize.Level0)
{
std::unordered_map<std::string, std::string> argsMap;
std::vector<int16_t> sigData;
auto func = [](MessageParcel &data, MessageParcel &reply) -> int32_t {
reply.WriteInt32(ERR_OK);
reply.WriteInt32(VECTOR_MAX_SIZE + 1);
return ERR_OK;
};
EXPECT_CALL(*mockStub_, CommandAOTCompiler(testing::_, testing::_)).
Times(1).WillOnce(testing::Invoke(func));
int32_t result = proxy_->AotCompiler(argsMap, sigData);
EXPECT_EQ(result, ERR_INVALID_DATA);
}
/**
* @tc.name: AotCompilerProxyTest_008
* @tc.desc: AotCompilerProxy::AotCompiler(argsMap, sigData) success
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_008, TestSize.Level0)
{
std::unordered_map<std::string, std::string> argsMap;
std::vector<int16_t> sigData;
auto func = [](MessageParcel &data, MessageParcel &reply) -> int32_t {
reply.WriteInt32(ERR_OK);
reply.WriteInt32(0);
return ERR_OK;
};
EXPECT_CALL(*mockStub_, CommandAOTCompiler(testing::_, testing::_)).
Times(1).WillOnce(testing::Invoke(func));
int32_t result = proxy_->AotCompiler(argsMap, sigData);
EXPECT_EQ(result, ERR_OK);
}
/**
* @tc.name: AotCompilerProxyTest_009
* @tc.desc: AotCompilerProxy::StopAotCompiler() when connect fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_009, TestSize.Level0)
{
EXPECT_CALL(*mockStub_, CommandStopAOTCompiler(testing::_)).
Times(1).WillOnce(testing::Return(ERR_AOT_COMPILER_CONNECT_FAILED));
int32_t result = proxy_->StopAotCompiler();
EXPECT_EQ(result, ERR_AOT_COMPILER_CONNECT_FAILED);
}
/**
* @tc.name: AotCompilerProxyTest_010
* @tc.desc: AotCompilerProxy::StopAotCompiler() when stop fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_010, TestSize.Level0)
{
auto func = [](MessageParcel &reply) -> int32_t {
reply.WriteInt32(ERR_AOT_COMPILER_CALL_FAILED);
return ERR_OK;
};
EXPECT_CALL(*mockStub_, CommandStopAOTCompiler(testing::_)).
Times(1).WillOnce(testing::Invoke(func));
int32_t result = proxy_->StopAotCompiler();
EXPECT_EQ(result, ERR_AOT_COMPILER_CALL_FAILED);
}
/**
* @tc.name: AotCompilerProxyTest_011
* @tc.desc: AotCompilerProxy::StopAotCompiler() when stop success
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_011, TestSize.Level0)
{
auto func = [](MessageParcel &reply) -> int32_t {
reply.WriteInt32(ERR_OK);
return ERR_OK;
};
EXPECT_CALL(*mockStub_, CommandStopAOTCompiler(testing::_)).
Times(1).WillOnce(testing::Invoke(func));
int32_t result = proxy_->StopAotCompiler();
EXPECT_EQ(result, ERR_OK);
}
/**
* @tc.name: AotCompilerProxyTest_012
* @tc.desc: AotCompilerProxy::GetAOTVersion(sigData) when connect fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_012, TestSize.Level0)
{
std::string sigData;
EXPECT_CALL(*mockStub_, CommandGetAOTVersion(testing::_)).
Times(1).WillOnce(testing::Return(ERR_AOT_COMPILER_CONNECT_FAILED));
int32_t result = proxy_->GetAOTVersion(sigData);
EXPECT_EQ(result, ERR_AOT_COMPILER_CONNECT_FAILED);
}
/**
* @tc.name: AotCompilerProxyTest_013
* @tc.desc: AotCompilerProxy::GetAOTVersion(sigData) when get error
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_013, TestSize.Level0)
{
std::string sigData;
auto func = [](MessageParcel &reply) -> int32_t {
reply.WriteInt32(ERR_AOT_COMPILER_CALL_FAILED);
return ERR_OK;
};
EXPECT_CALL(*mockStub_, CommandGetAOTVersion(testing::_)).
Times(1).WillOnce(testing::Invoke(func));
int32_t result = proxy_->GetAOTVersion(sigData);
EXPECT_EQ(result, ERR_AOT_COMPILER_CALL_FAILED);
}
/**
* @tc.name: AotCompilerProxyTest_014
* @tc.desc: AotCompilerProxy::GetAOTVersion(sigData) when get success
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_014, TestSize.Level0)
{
std::string sigData;
std::string testData = "test";
auto func = [&](MessageParcel &reply) -> int32_t {
reply.WriteInt32(ERR_OK);
reply.WriteString16(Str8ToStr16(testData));
return ERR_OK;
};
EXPECT_CALL(*mockStub_, CommandGetAOTVersion(testing::_)).
Times(1).WillOnce(testing::Invoke(func));
int32_t result = proxy_->GetAOTVersion(sigData);
EXPECT_EQ(result, ERR_OK);
EXPECT_STREQ(sigData.c_str(), testData.c_str());
}
/**
* @tc.name: AotCompilerProxyTest_015
* @tc.desc: AotCompilerProxy::NeedReCompile(args, sigData) when connect fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_015, TestSize.Level0)
{
std::string args;
bool sigData = false;
EXPECT_CALL(*mockStub_, CommandNeedReCompile(testing::_, testing::_)).
Times(1).WillOnce(testing::Return(ERR_AOT_COMPILER_CONNECT_FAILED));
int32_t result = proxy_->NeedReCompile(args, sigData);
EXPECT_EQ(result, ERR_AOT_COMPILER_CONNECT_FAILED);
}
/**
* @tc.name: AotCompilerProxyTest_016
* @tc.desc: AotCompilerProxy::NeedReCompile(args, sigData) when run fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_016, TestSize.Level0)
{
std::string args;
bool sigData = false;
auto func = [](MessageParcel &data, MessageParcel &reply) -> int32_t {
reply.WriteInt32(ERR_AOT_COMPILER_CALL_FAILED);
return ERR_OK;
};
EXPECT_CALL(*mockStub_, CommandNeedReCompile(testing::_, testing::_)).
Times(1).WillOnce(testing::Invoke(func));
int32_t result = proxy_->NeedReCompile(args, sigData);
EXPECT_EQ(result, ERR_AOT_COMPILER_CALL_FAILED);
}
/**
* @tc.name: AotCompilerProxyTest_017
* @tc.desc: AotCompilerProxy::NeedReCompile(args, sigData) when success
* @tc.type: Func
*/
HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_017, TestSize.Level0)
{
std::string args;
bool sigData = false;
bool testData = true;
auto func = [=](MessageParcel &data, MessageParcel &reply) -> int32_t {
reply.WriteInt32(ERR_OK);
reply.WriteBool(testData);
return ERR_OK;
};
EXPECT_CALL(*mockStub_, CommandNeedReCompile(testing::_, testing::_)).
Times(1).WillOnce(testing::Invoke(func));
int32_t result = proxy_->NeedReCompile(args, sigData);
EXPECT_EQ(result, ERR_OK);
EXPECT_TRUE(sigData);
}
} // namespace OHOS::ArkCompiler

View File

@ -26,7 +26,12 @@
#include "aot_compiler_load_callback.h"
#undef protected
#undef private
#include "common_event_data.h"
#include "common_event_manager.h"
#include "common_event_support.h"
#include "common_event_subscriber.h"
#include "iservice_registry.h"
#include "power_disconnected_listener.h"
#include "system_ability_definition.h"
using namespace testing::ext;
@ -60,13 +65,14 @@ void AotCompilerServiceTest::OnStart(AotCompilerService &aotService)
}
aotService.state_ = ServiceRunningState::STATE_RUNNING;
aotService.RegisterPowerDisconnectedListener();
aotService.RegisterScreenStatusSubscriber();
aotService.RegisterThermalMgrListener();
}
/**
* @tc.name: AotCompilerServiceTest_001
* @tc.desc: AotCompilerService instance initialization
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_001, TestSize.Level0)
{
@ -78,7 +84,6 @@ HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_001, TestSize.Level0)
* @tc.name: AotCompilerServiceTest_002
* @tc.desc: Init() in AotCompilerService
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_002, TestSize.Level0)
{
@ -91,7 +96,6 @@ HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_002, TestSize.Level0)
* @tc.name: AotCompilerServiceTest_003
* @tc.desc: RegisterPowerDisconnectedListener() && UnRegisterPowerDisconnectedListener()
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_003, TestSize.Level0)
{
@ -107,7 +111,6 @@ HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_003, TestSize.Level0)
* @tc.name: AotCompilerServiceTest_004
* @tc.desc: OnStart()/OnStop() in AotCompilerService
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_004, TestSize.Level0)
{
@ -123,7 +126,6 @@ HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_004, TestSize.Level0)
* @tc.name: AotCompilerServiceTest_005
* @tc.desc: DelayUnloadTask(TASK_ID, DELAY_TIME)
* @tc.type: Func
* @tc.require: IR/AR/SR
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_005, TestSize.Level0)
{
@ -141,6 +143,187 @@ HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_005, TestSize.Level0)
aotService.DelayUnloadTask(TASK_ID, NO_DELAY_TIME);
usleep(SLEEP_TIME_FOR_WAITTING_UNLOAD_SA);
aotService.OnStop();
EXPECT_EQ(aotClient.GetAotCompiler(), nullptr);
EXPECT_EQ(aotService.state_, ServiceRunningState::STATE_NOT_START);
}
/**
* @tc.name: AotCompilerServiceTest_006
* @tc.desc: AotCompilerService::AotCompiler(argsMap, fileData)
* @tc.type: Func
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_006, TestSize.Level0)
{
AotCompilerService aotService;
std::unordered_map<std::string, std::string> argsMap;
std::vector<int16_t> fileData;
int32_t ret = aotService.AotCompiler(argsMap, fileData);
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.name: AotCompilerServiceTest_007
* @tc.desc: AotCompilerService::StopAotCompiler()
* @tc.type: Func
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_007, TestSize.Level0)
{
AotCompilerService aotService;
int32_t ret = aotService.StopAotCompiler();
EXPECT_EQ(ret, ERR_AOT_COMPILER_STOP_FAILED);
}
/**
* @tc.name: AotCompilerServiceTest_008
* @tc.desc: AotCompilerService::GetAOTVersion(sigData)
* @tc.type: Func
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_008, TestSize.Level0)
{
AotCompilerService aotService;
std::string sigData = "test_string";
int32_t ret = aotService.GetAOTVersion(sigData);
EXPECT_EQ(ret, ERR_OK);
EXPECT_STRNE(sigData.c_str(), "test_string");
}
/**
* @tc.name: AotCompilerServiceTest_009
* @tc.desc: AotCompilerService::NeedReCompile(oldVersion, sigData)
* @tc.type: Func
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_009, TestSize.Level0)
{
AotCompilerService aotService;
std::string oldVersion = "4.0.0.0";
bool sigData = true;
int32_t ret = aotService.NeedReCompile(oldVersion, sigData);
EXPECT_EQ(ret, ERR_OK);
EXPECT_STREQ(oldVersion.c_str(), "4.0.0.0");
EXPECT_FALSE(sigData);
}
/**
* @tc.name: AotCompilerServiceTest_010
* @tc.desc: AotCompilerService::RemoveUnloadTask(TASK_ID)
* @tc.type: Func
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_010, TestSize.Level0)
{
AotCompilerService aotService;
aotService.unLoadHandler_ = nullptr;
aotService.RemoveUnloadTask(TASK_ID);
aotService.DelayUnloadTask(TASK_ID, NO_DELAY_TIME);
bool ret = aotService.Init();
EXPECT_TRUE(ret);
aotService.RemoveUnloadTask(TASK_ID);
EXPECT_NE(aotService.unLoadHandler_, nullptr);
}
/**
* @tc.name: AotCompilerServiceTest_011
* @tc.desc: AotCompilerService::RegisterPowerDisconnectedListener()
* @tc.type: Func
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_011, TestSize.Level0)
{
AotCompilerService aotService;
bool viewData1 = true;
int32_t viewData2 = 101010;
std::string viewData3 = "101010";
aotService.RegisterPowerDisconnectedListener();
aotService.UnRegisterPowerDisconnectedListener();
aotService.UnRegisterPowerDisconnectedListener();
EXPECT_TRUE(viewData1);
EXPECT_EQ(viewData2, 101010);
EXPECT_STREQ(viewData3.c_str(), "101010");
}
/**
* @tc.name: AotCompilerServiceTest_012
* @tc.desc: AotCompilerService::RegisterScreenStatusSubscriber()
* @tc.type: Func
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_012, TestSize.Level0)
{
AotCompilerService aotService;
bool viewData1 = true;
int32_t viewData2 = 101010;
std::string viewData3 = "101010";
aotService.RegisterScreenStatusSubscriber();
aotService.UnRegisterScreenStatusSubscriber();
aotService.UnRegisterScreenStatusSubscriber();
EXPECT_TRUE(viewData1);
EXPECT_EQ(viewData2, 101010);
EXPECT_STREQ(viewData3.c_str(), "101010");
}
/**
* @tc.name: AotCompilerServiceTest_013
* @tc.desc: AotCompilerService::RegisterThermalMgrListener()
* @tc.type: Func
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_013, TestSize.Level0)
{
AotCompilerService aotService;
bool viewData1 = true;
int32_t viewData2 = 101010;
std::string viewData3 = "101010";
aotService.RegisterThermalMgrListener();
aotService.UnRegisterThermalMgrListener();
aotService.UnRegisterThermalMgrListener();
EXPECT_TRUE(viewData1);
EXPECT_EQ(viewData2, 101010);
EXPECT_STREQ(viewData3.c_str(), "101010");
}
/**
* @tc.name: AotCompilerServiceTest_014
* @tc.desc: PowerDisconnectedListener::OnReceiveEvent(data)
* @tc.type: Func
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_014, TestSize.Level0)
{
bool viewData = true;
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_POWER_DISCONNECTED);
EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
auto powerDisconnectedListener_ = std::make_shared<PowerDisconnectedListener>(subscribeInfo);
EventFwk::CommonEventData data;
powerDisconnectedListener_->OnReceiveEvent(data);
EXPECT_TRUE(viewData);
}
/**
* @tc.name: AotCompilerServiceTest_015
* @tc.desc: ScreenStatusSubscriber::OnReceiveEvent(data)
* @tc.type: Func
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_015, TestSize.Level0)
{
bool viewData = true;
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON);
EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
auto screenStatusSubscriber_ = std::make_shared<ScreenStatusSubscriber>(subscribeInfo);
EventFwk::CommonEventData data;
screenStatusSubscriber_->OnReceiveEvent(data);
EXPECT_TRUE(viewData);
}
/**
* @tc.name: AotCompilerServiceTest_016
* @tc.desc: ThermalMgrListener::OnReceiveEvent(data)
* @tc.type: Func
*/
HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_016, TestSize.Level0)
{
bool viewData = true;
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_THERMAL_LEVEL_CHANGED);
EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
auto thermalMgrListener_ = std::make_shared<ThermalMgrListener>(subscribeInfo);
EventFwk::CommonEventData data;
thermalMgrListener_->OnReceiveEvent(data);
EXPECT_TRUE(viewData);
}
} // namespace OHOS::ArkCompiler

View File

@ -0,0 +1,55 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("../../compiler_service_test.gni")
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = compiler_service_include_dirs
cflags = [ "-Wno-error=keyword-macro" ]
}
ohos_unittest("AotCompilerStubUnitTest") {
module_out_path = module_output_path
sources = aot_compiler_service_sources
configs = [ ":module_private_config" ]
deps = [
"${compiler_service_root}:libcompiler_service",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"icu:shared_icui18n",
"icu:shared_icuuc",
"ipc:ipc_core",
"power_manager:powermgr_client",
"runtime_core:libarkfile_static",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = []
if (defined(global_parts_info) &&
!defined(global_parts_info.security_code_signature)) {
external_deps += [ "code_signature:liblocal_code_sign_sdk" ]
defines += [ "CODE_SIGN_ENABLE" ]
}
sources += [ "aotcompilerstub_unit.cpp" ]
}

View File

@ -0,0 +1,307 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdint>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <string>
#include <vector>
#include "aot_compiler_client.h"
#include "aot_compiler_service.h"
#include "aot_compiler_error_utils.h"
#include "aot_compiler_interface_proxy.h"
#include "aot_compiler_interface_stub.h"
#include "aot_compiler_load_callback.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
using namespace testing::ext;
namespace OHOS::ArkCompiler {
namespace {
constexpr int32_t TEST_COMMAND_AOT_COMPILER = MIN_TRANSACTION_ID + 0;
constexpr int32_t TEST_COMMAND_STOP_AOT_COMPILER = MIN_TRANSACTION_ID + 1;
constexpr int32_t TEST_COMMAND_GET_AOT_VERSION = MIN_TRANSACTION_ID + 2;
constexpr int32_t TEST_COMMAND_NEED_RE_COMPILE = MIN_TRANSACTION_ID + 3;
constexpr int32_t TEST_COMMAND_INVALID = MIN_TRANSACTION_ID + 1000;
const unsigned long MAP_MAX_SIZE = 102400;
}
class AotCompilerStubMock : public AotCompilerInterfaceStub {
public:
AotCompilerStubMock() = default;
virtual ~AotCompilerStubMock() = default;
MOCK_METHOD(ErrCode, AotCompiler, ((const std::unordered_map<std::string, std::string> &argsMap),
std::vector<int16_t> &sigData), (override));
MOCK_METHOD(ErrCode, StopAotCompiler, (), (override));
MOCK_METHOD(ErrCode, GetAOTVersion, (std::string& sigData), (override));
MOCK_METHOD(ErrCode, NeedReCompile, (const std::string& args, bool& sigData), (override));
};
class AotCompilerStubTest : public testing::Test {
public:
AotCompilerStubTest() {}
virtual ~AotCompilerStubTest() {}
static void SetUpTestCase() {}
static void TearDownTestCase() {}
void SetUp() override;
void TearDown() override {}
sptr<AotCompilerStubMock> aotCompilerStub_ = nullptr;
};
void AotCompilerStubTest::SetUp()
{
aotCompilerStub_ = new (std::nothrow) AotCompilerStubMock();
}
/**
* @tc.name: AotCompilerStubTest_001
* @tc.desc: AotCompilerInterfaceStub::CommandAOTCompiler()
* @tc.type: Func
*/
HWTEST_F(AotCompilerStubTest, AotCompilerStubTest_001, TestSize.Level0)
{
uint32_t code = static_cast<uint32_t>(TEST_COMMAND_AOT_COMPILER);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
data.WriteInterfaceToken(AotCompilerInterfaceStub::GetDescriptor());
AotCompilerService aotService(AOT_COMPILER_SERVICE_ID, false);
int32_t ret = aotService.OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(ret, ERR_NONE);
}
/**
* @tc.name: AotCompilerStubTest_002
* @tc.desc: AotCompilerInterfaceStub::CommandStopAOTCompiler()
* @tc.type: Func
*/
HWTEST_F(AotCompilerStubTest, AotCompilerStubTest_002, TestSize.Level0)
{
uint32_t code = static_cast<uint32_t>(TEST_COMMAND_STOP_AOT_COMPILER);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
data.WriteInterfaceToken(AotCompilerInterfaceStub::GetDescriptor());
AotCompilerService aotService(AOT_COMPILER_SERVICE_ID, false);
int32_t ret = aotService.OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(ret, ERR_NONE);
}
/**
* @tc.name: AotCompilerStubTest_003
* @tc.desc: AotCompilerInterfaceStub::CommandGetAOTVersion()
* @tc.type: Func
*/
HWTEST_F(AotCompilerStubTest, AotCompilerStubTest_003, TestSize.Level0)
{
uint32_t code = static_cast<uint32_t>(TEST_COMMAND_GET_AOT_VERSION);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
data.WriteInterfaceToken(AotCompilerInterfaceStub::GetDescriptor());
AotCompilerService aotService(AOT_COMPILER_SERVICE_ID, false);
int32_t ret = aotService.OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(ret, ERR_NONE);
}
/**
* @tc.name: AotCompilerStubTest_004
* @tc.desc: AotCompilerInterfaceStub::CommandNeedReCompile()
* @tc.type: Func
*/
HWTEST_F(AotCompilerStubTest, AotCompilerStubTest_004, TestSize.Level0)
{
uint32_t code = static_cast<uint32_t>(TEST_COMMAND_NEED_RE_COMPILE);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
data.WriteInterfaceToken(AotCompilerInterfaceStub::GetDescriptor());
AotCompilerService aotService(AOT_COMPILER_SERVICE_ID, false);
int32_t ret = aotService.OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(ret, ERR_NONE);
}
/**
* @tc.name: AotCompilerStubTest_005
* @tc.desc: AotCompilerInterfaceStub::OnRemoteRequest() when code is invalid
* @tc.type: Func
*/
HWTEST_F(AotCompilerStubTest, AotCompilerStubTest_005, TestSize.Level0)
{
uint32_t code = static_cast<uint32_t>(TEST_COMMAND_INVALID);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
data.WriteInterfaceToken(AotCompilerInterfaceStub::GetDescriptor());
AotCompilerService aotService(AOT_COMPILER_SERVICE_ID, false);
int32_t ret = aotService.OnRemoteRequest(code, data, reply, option);
EXPECT_NE(ret, ERR_NONE);
}
/**
* @tc.name: AotCompilerStubTest_006
* @tc.desc: AotCompilerInterfaceStub::OnRemoteRequest() when descriptor mismatches
* @tc.type: Func
*/
HWTEST_F(AotCompilerStubTest, AotCompilerStubTest_006, TestSize.Level0)
{
uint32_t code = static_cast<uint32_t>(TEST_COMMAND_AOT_COMPILER);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
data.WriteInterfaceToken(u"incorrect descriptor");
AotCompilerService aotService(AOT_COMPILER_SERVICE_ID, false);
int32_t ret = aotService.OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(ret, ERR_TRANSACTION_FAILED);
}
/**
* @tc.name: AotCompilerStubTest_007
* @tc.desc: AotCompilerInterfaceStub::OnRemoteRequest() when MAP_MAX_SIZE invalid
* @tc.type: Func
*/
HWTEST_F(AotCompilerStubTest, AotCompilerStubTest_007, TestSize.Level0)
{
uint32_t code = static_cast<uint32_t>(TEST_COMMAND_AOT_COMPILER);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
data.WriteInterfaceToken(AotCompilerInterfaceStub::GetDescriptor());
data.WriteInt32(MAP_MAX_SIZE + 1);
AotCompilerService aotService(AOT_COMPILER_SERVICE_ID, false);
int32_t ret = aotService.OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(ret, ERR_INVALID_DATA);
}
/**
* @tc.name: AotCompilerStubTest_008
* @tc.desc: AotCompilerInterfaceStub::OnRemoteRequest() when AotCompiler success
* @tc.type: Func
*/
HWTEST_F(AotCompilerStubTest, AotCompilerStubTest_008, TestSize.Level0)
{
uint32_t code = static_cast<uint32_t>(TEST_COMMAND_AOT_COMPILER);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
data.WriteInterfaceToken(AotCompilerInterfaceStub::GetDescriptor());
EXPECT_CALL(*aotCompilerStub_, AotCompiler(testing::_, testing::_)).
Times(1).WillOnce(testing::Return(ERR_OK));
int32_t result = aotCompilerStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
}
/**
* @tc.name: AotCompilerStubTest_009
* @tc.desc: AotCompilerInterfaceStub::OnRemoteRequest() when AotCompiler fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerStubTest, AotCompilerStubTest_009, TestSize.Level0)
{
uint32_t code = static_cast<uint32_t>(TEST_COMMAND_AOT_COMPILER);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
data.WriteInterfaceToken(AotCompilerInterfaceStub::GetDescriptor());
EXPECT_CALL(*aotCompilerStub_, AotCompiler(testing::_, testing::_)).
Times(1).WillOnce(testing::Return(ERR_FAIL));
int32_t result = aotCompilerStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
}
/**
* @tc.name: AotCompilerStubTest_010
* @tc.desc: AotCompilerInterfaceStub::OnRemoteRequest() when GetAOTVersion success
* @tc.type: Func
*/
HWTEST_F(AotCompilerStubTest, AotCompilerStubTest_010, TestSize.Level0)
{
uint32_t code = static_cast<uint32_t>(TEST_COMMAND_GET_AOT_VERSION);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
data.WriteInterfaceToken(AotCompilerInterfaceStub::GetDescriptor());
EXPECT_CALL(*aotCompilerStub_, GetAOTVersion(testing::_)).
Times(1).WillOnce(testing::Return(ERR_OK));
int32_t result = aotCompilerStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
}
/**
* @tc.name: AotCompilerStubTest_011
* @tc.desc: AotCompilerInterfaceStub::OnRemoteRequest() when GetAOTVersion fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerStubTest, AotCompilerStubTest_011, TestSize.Level0)
{
uint32_t code = static_cast<uint32_t>(TEST_COMMAND_GET_AOT_VERSION);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
data.WriteInterfaceToken(AotCompilerInterfaceStub::GetDescriptor());
EXPECT_CALL(*aotCompilerStub_, GetAOTVersion(testing::_)).
Times(1).WillOnce(testing::Return(ERR_FAIL));
int32_t result = aotCompilerStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
}
/**
* @tc.name: AotCompilerStubTest_012
* @tc.desc: AotCompilerInterfaceStub::OnRemoteRequest() when NeedReCompile success
* @tc.type: Func
*/
HWTEST_F(AotCompilerStubTest, AotCompilerStubTest_012, TestSize.Level0)
{
uint32_t code = static_cast<uint32_t>(TEST_COMMAND_NEED_RE_COMPILE);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
data.WriteInterfaceToken(AotCompilerInterfaceStub::GetDescriptor());
EXPECT_CALL(*aotCompilerStub_, NeedReCompile(testing::_, testing::_)).
Times(1).WillOnce(testing::Return(ERR_OK));
int32_t result = aotCompilerStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
}
/**
* @tc.name: AotCompilerStubTest_013
* @tc.desc: AotCompilerInterfaceStub::OnRemoteRequest() when NeedReCompile fail
* @tc.type: Func
*/
HWTEST_F(AotCompilerStubTest, AotCompilerStubTest_013, TestSize.Level0)
{
uint32_t code = static_cast<uint32_t>(TEST_COMMAND_NEED_RE_COMPILE);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
data.WriteInterfaceToken(AotCompilerInterfaceStub::GetDescriptor());
EXPECT_CALL(*aotCompilerStub_, NeedReCompile(testing::_, testing::_)).
Times(1).WillOnce(testing::Return(ERR_FAIL));
int32_t result = aotCompilerStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
}
} // namespace OHOS::ArkCompiler