mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-06 23:54:03 +00:00
Adding mutex lock to hapArgs in AotCompilerImpl
Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IANGVX Signed-off-by: ChenYC009 <chenyongchun5@huawei.com> Change-Id: I10c93f436d8ced13df5049b04aac5162b961445e
This commit is contained in:
parent
cb89926fde
commit
8f62bfcc87
@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_ARKCOMPILER_AOTCOMPILER_IMPL_H
|
||||
#define OHOS_ARKCOMPILER_AOTCOMPILER_IMPL_H
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@ -36,29 +37,27 @@ public:
|
||||
int32_t EcmascriptAotCompiler(const std::unordered_map<std::string, std::string> &argsMap,
|
||||
std::vector<int16_t> &sigData);
|
||||
int32_t StopAotCompiler();
|
||||
|
||||
int32_t GetAOTVersion(std::string& sigData);
|
||||
|
||||
int32_t NeedReCompile(const std::string& args, bool& sigData);
|
||||
|
||||
void HandlePowerDisconnected();
|
||||
|
||||
void HandleScreenOn();
|
||||
|
||||
void HandleThermalLevelChanged(const int32_t level);
|
||||
|
||||
private:
|
||||
inline int32_t FindArgsIdxToInteger(const std::unordered_map<std::string, std::string> &argsMap,
|
||||
const std::string &keyName, int32_t &bundleID);
|
||||
inline int32_t FindArgsIdxToString(const std::unordered_map<std::string, std::string> &argsMap,
|
||||
const std::string &keyName, std::string &bundleArg);
|
||||
protected:
|
||||
int32_t FindArgsIdxToInteger(const std::unordered_map<std::string, std::string> &argsMap,
|
||||
const std::string &keyName, int32_t &bundleID);
|
||||
int32_t FindArgsIdxToString(const std::unordered_map<std::string, std::string> &argsMap,
|
||||
const std::string &keyName, std::string &bundleArg);
|
||||
int32_t PrepareArgs(const std::unordered_map<std::string, std::string> &argsMap);
|
||||
void DropCapabilities(const int32_t &bundleUid, const int32_t &bundleGid) const;
|
||||
void ExecuteInChildProcess(const std::vector<std::string> &aotVector) const;
|
||||
int32_t PrintAOTCompilerResult(const int compilerStatus);
|
||||
void GetBundleId(int32_t &bundleUid, int32_t &bundleGid) const;
|
||||
void DropCapabilities() const;
|
||||
void GetAotArgsVector(std::vector<const char*> &argv) const;
|
||||
void ExecuteInChildProcess() const;
|
||||
int32_t PrintAOTCompilerResult(const int compilerStatus) const;
|
||||
void ExecuteInParentProcess(pid_t childPid, int32_t &ret);
|
||||
int32_t AOTLocalCodeSign(const std::string &fileName, const std::string &appSignature,
|
||||
std::vector<int16_t> &sigData);
|
||||
void GetCodeSignArgs(std::string &appSignature, std::string &fileName) const;
|
||||
int32_t AOTLocalCodeSign(std::vector<int16_t> &sigData) const;
|
||||
int32_t RemoveAotFiles() const;
|
||||
void InitState(const pid_t childPid);
|
||||
void AddExpandArgs(std::vector<std::string> &argVector);
|
||||
void ResetState();
|
||||
@ -67,26 +66,25 @@ private:
|
||||
|
||||
AotCompilerImpl() = default;
|
||||
~AotCompilerImpl() = default;
|
||||
|
||||
AotCompilerImpl(const AotCompilerImpl&) = delete;
|
||||
AotCompilerImpl(AotCompilerImpl&&) = delete;
|
||||
AotCompilerImpl& operator=(const AotCompilerImpl&) = delete;
|
||||
AotCompilerImpl& operator=(AotCompilerImpl&&) = delete;
|
||||
private:
|
||||
mutable std::mutex mutex_;
|
||||
protected:
|
||||
std::atomic<bool> allowAotCompiler_ {true};
|
||||
mutable std::mutex hapArgsMutex_;
|
||||
mutable std::mutex stateMutex_;
|
||||
struct HapArgs {
|
||||
std::vector<std::string> argVector;
|
||||
std::string fileName;
|
||||
std::string signature;
|
||||
int32_t bundleUid;
|
||||
int32_t bundleGid;
|
||||
} hapArgs;
|
||||
int32_t bundleUid {0};
|
||||
int32_t bundleGid {0};
|
||||
} hapArgs_;
|
||||
struct AOTState {
|
||||
bool running = false;
|
||||
pid_t childPid = -1;
|
||||
bool running {false};
|
||||
pid_t childPid {-1};
|
||||
} state_;
|
||||
bool allowAotCompiler_ {true};
|
||||
int32_t thermalLevel_ {0};
|
||||
};
|
||||
} // namespace OHOS::ArkCompiler
|
||||
|
@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_ARKCOMPILER_AOTCOMPILER_SERVICE_H
|
||||
#define OHOS_ARKCOMPILER_AOTCOMPILER_SERVICE_H
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
@ -59,6 +60,7 @@ private:
|
||||
void UnRegisterScreenStatusSubscriber();
|
||||
void UnRegisterThermalMgrListener();
|
||||
|
||||
mutable std::mutex aotCompilerMutex_;
|
||||
std::shared_ptr<AppExecFwk::EventHandler> unLoadHandler_ { nullptr };
|
||||
ServiceRunningState state_;
|
||||
std::shared_ptr<PowerDisconnectedListener> powerDisconnectedListener_ { nullptr };
|
||||
|
@ -44,8 +44,8 @@ AotCompilerImpl& AotCompilerImpl::GetInstance()
|
||||
return aotCompiler;
|
||||
}
|
||||
|
||||
inline int32_t AotCompilerImpl::FindArgsIdxToInteger(const std::unordered_map<std::string, std::string> &argsMap,
|
||||
const std::string &keyName, int32_t &bundleID)
|
||||
int32_t AotCompilerImpl::FindArgsIdxToInteger(const std::unordered_map<std::string, std::string> &argsMap,
|
||||
const std::string &keyName, int32_t &bundleID)
|
||||
{
|
||||
if (argsMap.find(keyName) == argsMap.end()) {
|
||||
return ERR_AOT_COMPILER_PARAM_FAILED;
|
||||
@ -59,8 +59,8 @@ inline int32_t AotCompilerImpl::FindArgsIdxToInteger(const std::unordered_map<st
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
inline int32_t AotCompilerImpl::FindArgsIdxToString(const std::unordered_map<std::string, std::string> &argsMap,
|
||||
const std::string &keyName, std::string &bundleArg)
|
||||
int32_t AotCompilerImpl::FindArgsIdxToString(const std::unordered_map<std::string, std::string> &argsMap,
|
||||
const std::string &keyName, std::string &bundleArg)
|
||||
{
|
||||
if (argsMap.find(keyName) == argsMap.end()) {
|
||||
return ERR_AOT_COMPILER_PARAM_FAILED;
|
||||
@ -74,31 +74,42 @@ int32_t AotCompilerImpl::PrepareArgs(const std::unordered_map<std::string, std::
|
||||
for (const auto &arg : argsMap) {
|
||||
LOG_SA(DEBUG) << arg.first << ": " << arg.second;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(hapArgsMutex_);
|
||||
std::string abcPath;
|
||||
if ((FindArgsIdxToInteger(argsMap, ArgsIdx::BUNDLE_UID, hapArgs.bundleUid) != ERR_OK) ||
|
||||
(FindArgsIdxToInteger(argsMap, ArgsIdx::BUNDLE_GID, hapArgs.bundleGid) != ERR_OK) ||
|
||||
(FindArgsIdxToString(argsMap, ArgsIdx::AN_FILE_NAME, hapArgs.fileName) != ERR_OK) ||
|
||||
(FindArgsIdxToString(argsMap, ArgsIdx::APP_SIGNATURE, hapArgs.signature) != ERR_OK) ||
|
||||
if ((FindArgsIdxToInteger(argsMap, ArgsIdx::BUNDLE_UID, hapArgs_.bundleUid) != ERR_OK) ||
|
||||
(FindArgsIdxToInteger(argsMap, ArgsIdx::BUNDLE_GID, hapArgs_.bundleGid) != ERR_OK) ||
|
||||
(FindArgsIdxToString(argsMap, ArgsIdx::AN_FILE_NAME, hapArgs_.fileName) != ERR_OK) ||
|
||||
(FindArgsIdxToString(argsMap, ArgsIdx::APP_SIGNATURE, hapArgs_.signature) != ERR_OK) ||
|
||||
(FindArgsIdxToString(argsMap, ArgsIdx::ABC_PATH, abcPath) != ERR_OK)) {
|
||||
LOG_SA(ERROR) << "aot compiler Args parsing error";
|
||||
return ERR_AOT_COMPILER_PARAM_FAILED;
|
||||
}
|
||||
hapArgs.argVector.clear();
|
||||
hapArgs.argVector.emplace_back(Cmds::ARK_AOT_COMPILER);
|
||||
hapArgs_.argVector.clear();
|
||||
hapArgs_.argVector.emplace_back(Cmds::ARK_AOT_COMPILER);
|
||||
// service process add aot compile args here
|
||||
AddExpandArgs(hapArgs.argVector);
|
||||
AddExpandArgs(hapArgs_.argVector);
|
||||
for (auto &argPair : argsMap) {
|
||||
if (AotArgsSet.find(argPair.first) != AotArgsSet.end()) {
|
||||
hapArgs.argVector.emplace_back(Symbols::PREFIX + argPair.first + Symbols::EQ + argPair.second);
|
||||
hapArgs_.argVector.emplace_back(Symbols::PREFIX + argPair.first + Symbols::EQ + argPair.second);
|
||||
}
|
||||
}
|
||||
hapArgs.argVector.emplace_back(abcPath);
|
||||
hapArgs_.argVector.emplace_back(abcPath);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void AotCompilerImpl::DropCapabilities(const int32_t &bundleUid, const int32_t &bundleGid) const
|
||||
void AotCompilerImpl::GetBundleId(int32_t &bundleUid, int32_t &bundleGid) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(hapArgsMutex_);
|
||||
bundleUid = hapArgs_.bundleUid;
|
||||
bundleGid = hapArgs_.bundleGid;
|
||||
}
|
||||
|
||||
void AotCompilerImpl::DropCapabilities() const
|
||||
{
|
||||
LOG_SA(INFO) << "begin to drop capabilities";
|
||||
int32_t bundleUid = 0;
|
||||
int32_t bundleGid = 0;
|
||||
GetBundleId(bundleUid, bundleGid);
|
||||
if (setuid(bundleUid)) {
|
||||
LOG_SA(ERROR) << "dropCapabilities setuid failed : " << strerror(errno);
|
||||
exit(-1);
|
||||
@ -114,7 +125,6 @@ void AotCompilerImpl::DropCapabilities(const int32_t &bundleUid, const int32_t &
|
||||
}
|
||||
capHeader.version = _LINUX_CAPABILITY_VERSION_3;
|
||||
capHeader.pid = 0;
|
||||
|
||||
struct __user_cap_data_struct capData[2];
|
||||
if (memset_s(&capData, sizeof(capData), 0, sizeof(capData)) != EOK) {
|
||||
LOG_SA(ERROR) << "memset_s capData failed : " << strerror(errno);
|
||||
@ -127,13 +137,20 @@ void AotCompilerImpl::DropCapabilities(const int32_t &bundleUid, const int32_t &
|
||||
LOG_SA(INFO) << "drop capabilities success";
|
||||
}
|
||||
|
||||
void AotCompilerImpl::ExecuteInChildProcess(const std::vector<std::string> &aotVector) const
|
||||
void AotCompilerImpl::GetAotArgsVector(std::vector<const char*> &argv) const
|
||||
{
|
||||
std::vector<const char*> argv;
|
||||
std::lock_guard<std::mutex> lock(hapArgsMutex_);
|
||||
const std::vector<std::string> &aotVector = hapArgs_.argVector;
|
||||
argv.reserve(aotVector.size() + 1);
|
||||
for (auto &arg : aotVector) {
|
||||
argv.emplace_back(arg.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void AotCompilerImpl::ExecuteInChildProcess() const
|
||||
{
|
||||
std::vector<const char*> argv;
|
||||
GetAotArgsVector(argv);
|
||||
LOG_SA(INFO) << "ark_aot_compiler argv size : " << argv.size();
|
||||
for (const auto &arg : argv) {
|
||||
LOG_SA(INFO) << arg;
|
||||
@ -151,7 +168,7 @@ void AotCompilerImpl::AddExpandArgs(std::vector<std::string> &argVector)
|
||||
argVector.emplace_back(thermalLevelArg);
|
||||
}
|
||||
|
||||
int32_t AotCompilerImpl::PrintAOTCompilerResult(const int compilerStatus)
|
||||
int32_t AotCompilerImpl::PrintAOTCompilerResult(const int compilerStatus) const
|
||||
{
|
||||
if (RetInfoOfCompiler.find(compilerStatus) == RetInfoOfCompiler.end()) {
|
||||
LOG_SA(ERROR) << OtherInfoOfCompiler.mesg;
|
||||
@ -213,22 +230,21 @@ int32_t AotCompilerImpl::EcmascriptAotCompiler(const std::unordered_map<std::str
|
||||
return ERR_AOT_COMPILER_PARAM_FAILED;
|
||||
}
|
||||
int32_t ret = ERR_OK;
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
LOG_SA(INFO) << "begin to fork";
|
||||
pid_t pid = fork();
|
||||
if (pid == -1) {
|
||||
LOG_SA(ERROR) << "fork process failed : " << strerror(errno);
|
||||
return ERR_AOT_COMPILER_CALL_FAILED;
|
||||
} else if (pid == 0) {
|
||||
DropCapabilities(hapArgs.bundleUid, hapArgs.bundleGid);
|
||||
ExecuteInChildProcess(hapArgs.argVector);
|
||||
DropCapabilities();
|
||||
ExecuteInChildProcess();
|
||||
} else {
|
||||
ExecuteInParentProcess(pid, ret);
|
||||
}
|
||||
if (ret == ERR_OK_NO_AOT_FILE) {
|
||||
return ERR_OK;
|
||||
}
|
||||
return ret ? ERR_AOT_COMPILER_CALL_FAILED : AOTLocalCodeSign(hapArgs.fileName, hapArgs.signature, sigData);
|
||||
return ret != ERR_OK ? ERR_AOT_COMPILER_CALL_FAILED : AOTLocalCodeSign(sigData);
|
||||
#else
|
||||
LOG_SA(ERROR) << "no need to AOT compile when code signature disable";
|
||||
return ERR_AOT_COMPILER_SIGNATURE_DISABLE;
|
||||
@ -250,10 +266,19 @@ int32_t AotCompilerImpl::NeedReCompile(const std::string& args, bool& sigData)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AotCompilerImpl::AOTLocalCodeSign(const std::string &fileName, const std::string &appSignature,
|
||||
std::vector<int16_t> &sigData)
|
||||
void AotCompilerImpl::GetCodeSignArgs(std::string &appSignature, std::string &fileName) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(hapArgsMutex_);
|
||||
appSignature = hapArgs_.signature;
|
||||
fileName = hapArgs_.fileName;
|
||||
}
|
||||
|
||||
int32_t AotCompilerImpl::AOTLocalCodeSign(std::vector<int16_t> &sigData) const
|
||||
{
|
||||
#ifdef CODE_SIGN_ENABLE
|
||||
std::string appSignature;
|
||||
std::string fileName;
|
||||
GetCodeSignArgs(appSignature, fileName);
|
||||
Security::CodeSign::ByteBuffer sig;
|
||||
if (Security::CodeSign::LocalCodeSignKit::SignLocalCode(appSignature, fileName, sig)
|
||||
!= CommonErrCode::CS_SUCCESS) {
|
||||
@ -286,16 +311,7 @@ int32_t AotCompilerImpl::StopAotCompiler()
|
||||
}
|
||||
LOG_SA(INFO) << "begin to kill child process : " << state_.childPid;
|
||||
auto result = kill(state_.childPid, SIGKILL);
|
||||
int32_t ret = ERR_OK;
|
||||
if (access(hapArgs.fileName.c_str(), ERR_OK) != ERR_FAIL) {
|
||||
auto delRes = std::remove(hapArgs.fileName.c_str());
|
||||
if (delRes != ERR_OK) {
|
||||
LOG_SA(INFO) << "delete invalid aot file failed: " << delRes;
|
||||
ret = ERR_AOT_COMPILER_STOP_FAILED;
|
||||
} else {
|
||||
LOG_SA(INFO) << "delete invalid aot file success";
|
||||
}
|
||||
}
|
||||
int32_t ret = RemoveAotFiles();
|
||||
if (result != 0) {
|
||||
LOG_SA(INFO) << "kill child process failed: " << result;
|
||||
ret = ERR_AOT_COMPILER_STOP_FAILED;
|
||||
@ -306,6 +322,21 @@ int32_t AotCompilerImpl::StopAotCompiler()
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t AotCompilerImpl::RemoveAotFiles() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(hapArgsMutex_);
|
||||
if (access(hapArgs_.fileName.c_str(), ERR_OK) != ERR_FAIL) {
|
||||
auto delRes = std::remove(hapArgs_.fileName.c_str());
|
||||
if (delRes != ERR_OK) {
|
||||
LOG_SA(INFO) << "delete invalid aot file failed: " << delRes;
|
||||
return ERR_AOT_COMPILER_STOP_FAILED;
|
||||
} else {
|
||||
LOG_SA(INFO) << "delete invalid aot file success";
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void AotCompilerImpl::HandlePowerDisconnected()
|
||||
{
|
||||
LOG_SA(INFO) << "AotCompilerImpl::HandlePowerDisconnected";
|
||||
|
@ -127,7 +127,11 @@ int32_t AotCompilerService::AotCompiler(const std::unordered_map<std::string, st
|
||||
{
|
||||
LOG_SA(DEBUG) << "begin to call aot compiler";
|
||||
RemoveUnloadTask(TASK_ID);
|
||||
int32_t ret = AotCompilerImpl::GetInstance().EcmascriptAotCompiler(argsMap, sigData);
|
||||
int32_t ret = ERR_FAIL;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(aotCompilerMutex_);
|
||||
ret = AotCompilerImpl::GetInstance().EcmascriptAotCompiler(argsMap, sigData);
|
||||
}
|
||||
LOG_SA(DEBUG) << "finish aot compiler";
|
||||
DelayUnloadTask(TASK_ID, DELAY_TIME);
|
||||
return ret;
|
||||
|
@ -17,6 +17,14 @@ import("//build/test.gni")
|
||||
compiler_service_root = "//arkcompiler/ets_runtime/compiler_service"
|
||||
module_output_path = "arkcompiler/ets_runtime/compiler_service"
|
||||
|
||||
declare_args() {
|
||||
code_sign_enable_test = true
|
||||
if (defined(global_parts_info) &&
|
||||
!defined(global_parts_info.security_code_signature)) {
|
||||
code_sign_enable_test = false
|
||||
}
|
||||
}
|
||||
|
||||
compiler_service_include_dirs = [
|
||||
"${compiler_service_root}/test/mock/include",
|
||||
"${compiler_service_root}/include",
|
||||
|
@ -46,8 +46,7 @@ ohos_unittest("AotCompilerClientUnitTest") {
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
defines = []
|
||||
if (defined(global_parts_info) &&
|
||||
!defined(global_parts_info.security_code_signature)) {
|
||||
if (code_sign_enable_test) {
|
||||
external_deps += [ "code_signature:liblocal_code_sign_sdk" ]
|
||||
defines += [ "CODE_SIGN_ENABLE" ]
|
||||
}
|
||||
|
@ -46,8 +46,7 @@ ohos_unittest("AotCompilerImplUnitTest") {
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
defines = []
|
||||
if (defined(global_parts_info) &&
|
||||
!defined(global_parts_info.security_code_signature)) {
|
||||
if (code_sign_enable_test) {
|
||||
external_deps += [ "code_signature:liblocal_code_sign_sdk" ]
|
||||
defines += [ "CODE_SIGN_ENABLE" ]
|
||||
}
|
||||
|
@ -15,7 +15,10 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <gtest/gtest.h>
|
||||
#include <gtest/hwext/gtest-multithread.h>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
@ -28,6 +31,7 @@
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace testing::mt;
|
||||
|
||||
namespace OHOS::ArkCompiler {
|
||||
namespace {
|
||||
@ -61,6 +65,16 @@ const std::unordered_map<std::string, std::string> argsMapForTest {
|
||||
};
|
||||
} // namespace ark_aot_compiler arguments
|
||||
|
||||
class AotCompilerImplMock : public AotCompilerImpl {
|
||||
public:
|
||||
AotCompilerImplMock() = default;
|
||||
~AotCompilerImplMock() = default;
|
||||
AotCompilerImplMock(const AotCompilerImplMock&) = delete;
|
||||
AotCompilerImplMock(AotCompilerImplMock&&) = delete;
|
||||
AotCompilerImplMock& operator=(const AotCompilerImplMock&) = delete;
|
||||
AotCompilerImplMock& operator=(AotCompilerImplMock&&) = delete;
|
||||
};
|
||||
|
||||
class AotCompilerImplTest : public testing::Test {
|
||||
public:
|
||||
AotCompilerImplTest() {}
|
||||
@ -81,7 +95,7 @@ public:
|
||||
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_001, TestSize.Level0)
|
||||
{
|
||||
AotCompilerImpl *aotImplPtr = nullptr;
|
||||
aotImplPtr = &AotCompilerImpl::GetInstance();
|
||||
aotImplPtr = &AotCompilerImplMock::GetInstance();
|
||||
EXPECT_NE(aotImplPtr, nullptr);
|
||||
}
|
||||
|
||||
@ -93,7 +107,7 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_001, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_002, TestSize.Level0)
|
||||
{
|
||||
AotCompilerImpl &aotImpl = AotCompilerImpl::GetInstance();
|
||||
AotCompilerImpl &aotImpl = AotCompilerImplMock::GetInstance();
|
||||
std::unordered_map<std::string, std::string> argsMap(argsMapForTest);
|
||||
std::string keyCheckPgoVersion = "compiler-check-pgo-version";
|
||||
std::string valueCheckPgoVersion = "true";
|
||||
@ -116,14 +130,18 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_002, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_003, TestSize.Level0)
|
||||
{
|
||||
AotCompilerImpl &aotImpl = AotCompilerImpl::GetInstance();
|
||||
AotCompilerImpl &aotImpl = AotCompilerImplMock::GetInstance();
|
||||
std::unordered_map<std::string, std::string> argsMap(argsMapForTest);
|
||||
std::string keyCompileNoMethod = "compiler-methods-range";
|
||||
std::string valueCompileNoMethod = "0:0";
|
||||
argsMap.emplace(keyCompileNoMethod, valueCompileNoMethod);
|
||||
std::vector<int16_t> sigData { 0, 1, 2, 3, 4, 5 };
|
||||
int32_t ret = aotImpl.EcmascriptAotCompiler(argsMap, sigData);
|
||||
EXPECT_NE(ret, ERR_OK);
|
||||
#ifdef CODE_SIGN_ENABLE
|
||||
EXPECT_NE(ret, ERR_AOT_COMPILER_SIGNATURE_DISABLE);
|
||||
#else
|
||||
EXPECT_EQ(ret, ERR_AOT_COMPILER_SIGNATURE_DISABLE);
|
||||
#endif
|
||||
EXPECT_FALSE(sigData.empty());
|
||||
}
|
||||
|
||||
@ -135,7 +153,7 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_003, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_004, TestSize.Level0)
|
||||
{
|
||||
AotCompilerImpl &aotImpl = AotCompilerImpl::GetInstance();
|
||||
AotCompilerImpl &aotImpl = AotCompilerImplMock::GetInstance();
|
||||
int32_t ret = aotImpl.StopAotCompiler();
|
||||
EXPECT_EQ(ret, ERR_AOT_COMPILER_STOP_FAILED);
|
||||
}
|
||||
@ -148,7 +166,7 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_004, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_005, TestSize.Level0)
|
||||
{
|
||||
AotCompilerImpl &aotImpl = AotCompilerImpl::GetInstance();
|
||||
AotCompilerImpl &aotImpl = AotCompilerImplMock::GetInstance();
|
||||
std::string sigData = "sig_data_for_test";
|
||||
int32_t ret = aotImpl.GetAOTVersion(sigData);
|
||||
EXPECT_EQ(sigData.size(), 0);
|
||||
@ -163,7 +181,7 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_005, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_006, TestSize.Level0)
|
||||
{
|
||||
AotCompilerImpl &aotImpl = AotCompilerImpl::GetInstance();
|
||||
AotCompilerImpl &aotImpl = AotCompilerImplMock::GetInstance();
|
||||
std::string args = "args_for_test";
|
||||
bool sigData = true;
|
||||
int32_t ret = aotImpl.NeedReCompile(args, sigData);
|
||||
@ -179,7 +197,7 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_006, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_007, TestSize.Level0)
|
||||
{
|
||||
AotCompilerImpl &aotImpl = AotCompilerImpl::GetInstance();
|
||||
AotCompilerImpl &aotImpl = AotCompilerImplMock::GetInstance();
|
||||
bool viewData1 = true;
|
||||
int32_t viewData2 = 101010;
|
||||
std::string viewData3 = "101010";
|
||||
@ -197,7 +215,7 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_007, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_008, TestSize.Level0)
|
||||
{
|
||||
AotCompilerImpl &aotImpl = AotCompilerImpl::GetInstance();
|
||||
AotCompilerImpl &aotImpl = AotCompilerImplMock::GetInstance();
|
||||
bool viewData1 = true;
|
||||
int32_t viewData2 = 010101;
|
||||
std::string viewData3 = "010101";
|
||||
@ -215,7 +233,7 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_008, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_009, TestSize.Level0)
|
||||
{
|
||||
AotCompilerImpl &aotImpl = AotCompilerImpl::GetInstance();
|
||||
AotCompilerImpl &aotImpl = AotCompilerImplMock::GetInstance();
|
||||
bool viewData1 = true;
|
||||
int32_t viewData2 = 010101;
|
||||
std::string viewData3 = "010101";
|
||||
@ -224,4 +242,78 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_009, TestSize.Level0)
|
||||
EXPECT_EQ(viewData2, 010101);
|
||||
EXPECT_STREQ(viewData3.c_str(), "010101");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AotCompilerImplTest_010
|
||||
* @tc.desc: AotCompilerImpl::EcmascriptAotCompiler() when multi thread run
|
||||
* @tc.type: Func
|
||||
* @tc.require: IR/AR/SR
|
||||
*/
|
||||
AotCompilerImpl >AotImpl = AotCompilerImplMock::GetInstance();
|
||||
std::mutex aotCompilerMutex_;
|
||||
bool g_retGlobal = true;
|
||||
|
||||
void ExecuteAotCompilerTask(void)
|
||||
{
|
||||
std::unordered_map<std::string, std::string> argsMap(argsMapForTest);
|
||||
std::string keyCompileNoMethod = "compiler-methods-range";
|
||||
std::string valueCompileNoMethod = "0:0";
|
||||
std::string keyCheckPgoVersion = "compiler-check-pgo-version";
|
||||
std::string valueCheckPgoVersion = "true";
|
||||
argsMap.emplace(keyCompileNoMethod, valueCompileNoMethod);
|
||||
argsMap.emplace(keyCheckPgoVersion, valueCheckPgoVersion);
|
||||
std::vector<int16_t> sigData { 0, 1, 2, 3, 4, 5 };
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(aotCompilerMutex_);
|
||||
if (gtAotImpl.EcmascriptAotCompiler(argsMap, sigData) !=
|
||||
ERR_AOT_COMPILER_SIGNATURE_DISABLE) {
|
||||
g_retGlobal = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StopAotCompilerTask(void)
|
||||
{
|
||||
(void)gtAotImpl.StopAotCompiler();
|
||||
}
|
||||
|
||||
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_010, TestSize.Level0)
|
||||
{
|
||||
g_retGlobal = true;
|
||||
SET_THREAD_NUM(20); // THREAD_NUM = 20
|
||||
GTEST_RUN_TASK(ExecuteAotCompilerTask);
|
||||
GTEST_RUN_TASK(StopAotCompilerTask);
|
||||
#ifdef CODE_SIGN_ENABLE
|
||||
EXPECT_FALSE(g_retGlobal);
|
||||
#else
|
||||
EXPECT_TRUE(g_retGlobal);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AotCompilerImplTest_011
|
||||
* @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)
|
||||
{
|
||||
g_retGlobal = true;
|
||||
SET_THREAD_NUM(40); // THREAD_NUM = 40
|
||||
MTEST_ADD_TASK(RANDOM_THREAD_ID, ExecuteAotCompilerTask);
|
||||
MTEST_ADD_TASK(RANDOM_THREAD_ID, StopAotCompilerTask);
|
||||
EXPECT_TRUE(g_retGlobal);
|
||||
}
|
||||
|
||||
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_012, TestSize.Level0)
|
||||
{
|
||||
g_retGlobal = true;
|
||||
MTEST_POST_RUN();
|
||||
#ifdef CODE_SIGN_ENABLE
|
||||
EXPECT_FALSE(g_retGlobal);
|
||||
#else
|
||||
EXPECT_TRUE(g_retGlobal);
|
||||
#endif
|
||||
}
|
||||
} // namespace OHOS::ArkCompiler
|
@ -45,8 +45,7 @@ ohos_unittest("AotCompilerServiceUnitTest") {
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
defines = []
|
||||
if (defined(global_parts_info) &&
|
||||
!defined(global_parts_info.security_code_signature)) {
|
||||
if (code_sign_enable_test) {
|
||||
external_deps += [ "code_signature:liblocal_code_sign_sdk" ]
|
||||
defines += [ "CODE_SIGN_ENABLE" ]
|
||||
}
|
||||
|
@ -81,10 +81,9 @@ void BindMidCpuCore()
|
||||
cpu_set_t cpuset;
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(4, &cpuset); // 4: bind this process to cpu4
|
||||
CPU_SET(5, &cpuset); // 5: bind this process to cpu5
|
||||
CPU_SET(6, &cpuset); // 6: bind this process to cpu6
|
||||
CPU_SET(7, &cpuset); // 7: bind this process to cpu7
|
||||
for (int i = 0; i < 7; i++) { // 7: 0-3 little core, 4-6 mid core
|
||||
CPU_SET(i, &cpuset);
|
||||
}
|
||||
|
||||
if (sched_setaffinity(0, sizeof(cpuset), &cpuset) == -1) {
|
||||
LOG_ECMA(ERROR) << "Set CPU affinity failed";
|
||||
|
Loading…
Reference in New Issue
Block a user