!9297 Modify idle compile strategy

Merge pull request !9297 from ChenYC009/crash_dev
This commit is contained in:
openharmony_ci 2024-09-16 01:38:47 +00:00 committed by Gitee
commit 07349ae6b0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
13 changed files with 113 additions and 18 deletions

View File

@ -46,7 +46,6 @@
"icu", "icu",
"access_token", "access_token",
"eventhandler", "eventhandler",
"hisysevent",
"ipc", "ipc",
"safwk", "safwk",
"samgr", "samgr",

View File

@ -31,6 +31,8 @@ enum {
ERR_AOT_COMPILER_SIGNATURE_DISABLE = 10005, ERR_AOT_COMPILER_SIGNATURE_DISABLE = 10005,
ERR_AOT_COMPILER_CALL_FAILED = 10006, ERR_AOT_COMPILER_CALL_FAILED = 10006,
ERR_AOT_COMPILER_STOP_FAILED = 10007, ERR_AOT_COMPILER_STOP_FAILED = 10007,
ERR_AOT_COMPILER_CALL_CRASH = 10008,
ERR_AOT_COMPILER_CALL_CANCELLED = 10009,
INVALID_ERR_CODE = 99999, INVALID_ERR_CODE = 99999,
}; };

View File

@ -113,14 +113,14 @@ void AotCompilerImpl::DropCapabilities() const
int32_t bundleUid = 0; int32_t bundleUid = 0;
int32_t bundleGid = 0; int32_t bundleGid = 0;
GetBundleId(bundleUid, bundleGid); GetBundleId(bundleUid, bundleGid);
if (setuid(bundleUid)) {
LOG_SA(ERROR) << "dropCapabilities setuid failed : " << strerror(errno);
exit(-1);
}
if (setgid(bundleGid)) { if (setgid(bundleGid)) {
LOG_SA(ERROR) << "dropCapabilities setgid failed : " << strerror(errno); LOG_SA(ERROR) << "dropCapabilities setgid failed : " << strerror(errno);
exit(-1); exit(-1);
} }
if (setuid(bundleUid)) {
LOG_SA(ERROR) << "dropCapabilities setuid failed : " << strerror(errno);
exit(-1);
}
struct __user_cap_header_struct capHeader; struct __user_cap_header_struct capHeader;
if (memset_s(&capHeader, sizeof(capHeader), 0, sizeof(capHeader)) != EOK) { if (memset_s(&capHeader, sizeof(capHeader), 0, sizeof(capHeader)) != EOK) {
LOG_SA(ERROR) << "memset_s capHeader failed : " << strerror(errno); LOG_SA(ERROR) << "memset_s capHeader failed : " << strerror(errno);
@ -203,7 +203,7 @@ void AotCompilerImpl::ExecuteInParentProcess(const pid_t childPid, int32_t &ret)
} else if (WIFSIGNALED(status)) { } else if (WIFSIGNALED(status)) {
int signalNumber = WTERMSIG(status); int signalNumber = WTERMSIG(status);
LOG_SA(WARN) << "child process terminated by signal: " << signalNumber; LOG_SA(WARN) << "child process terminated by signal: " << signalNumber;
ret = ERR_AOT_COMPILER_CALL_FAILED; ret = signalNumber == SIGKILL ? ERR_AOT_COMPILER_CALL_CANCELLED : ERR_AOT_COMPILER_CALL_CRASH;
} else if (WIFSTOPPED(status)) { } else if (WIFSTOPPED(status)) {
int signalNumber = WSTOPSIG(status); int signalNumber = WSTOPSIG(status);
LOG_SA(WARN) << "child process was stopped by signal: " << signalNumber; LOG_SA(WARN) << "child process was stopped by signal: " << signalNumber;
@ -248,7 +248,7 @@ int32_t AotCompilerImpl::EcmascriptAotCompiler(const std::unordered_map<std::str
if (ret == ERR_OK_NO_AOT_FILE) { if (ret == ERR_OK_NO_AOT_FILE) {
return ERR_OK; return ERR_OK;
} }
return ret != ERR_OK ? ERR_AOT_COMPILER_CALL_FAILED : AOTLocalCodeSign(sigData); return ret != ERR_OK ? ret : AOTLocalCodeSign(sigData);
#else #else
LOG_SA(ERROR) << "no need to AOT compile when code signature disable"; LOG_SA(ERROR) << "no need to AOT compile when code signature disable";
return ERR_AOT_COMPILER_SIGNATURE_DISABLE; return ERR_AOT_COMPILER_SIGNATURE_DISABLE;

View File

@ -19,12 +19,6 @@
#include "ecmascript/log_wrapper.h" #include "ecmascript/log_wrapper.h"
namespace OHOS::ArkCompiler { namespace OHOS::ArkCompiler {
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 LOG_SA([[maybe_unused]] const Level level)
{ {
std::ostringstream stream_; std::ostringstream stream_;

View File

@ -30,6 +30,7 @@ ohos_unittest("AotCompilerClientUnitTest") {
"//third_party/googletest:gtest_main", "//third_party/googletest:gtest_main",
] ]
external_deps = [ external_deps = [
"ability_base:want",
"access_token:libaccesstoken_sdk", "access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk", "access_token:libtokenid_sdk",
"c_utils:utils", "c_utils:utils",

View File

@ -29,6 +29,7 @@ ohos_unittest("AotCompilerErrorUtilsUnitTest") {
"//third_party/googletest:gtest_main", "//third_party/googletest:gtest_main",
] ]
external_deps = [ external_deps = [
"ability_base:want",
"access_token:libaccesstoken_sdk", "access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk", "access_token:libtokenid_sdk",
"c_utils:utils", "c_utils:utils",
@ -40,7 +41,6 @@ ohos_unittest("AotCompilerErrorUtilsUnitTest") {
"icu:shared_icui18n", "icu:shared_icui18n",
"icu:shared_icuuc", "icu:shared_icuuc",
"ipc:ipc_core", "ipc:ipc_core",
"power_manager:powermgr_client",
"runtime_core:libarkfile_static", "runtime_core:libarkfile_static",
"safwk:system_ability_fwk", "safwk:system_ability_fwk",
"samgr:samgr_proxy", "samgr:samgr_proxy",

View File

@ -30,6 +30,7 @@ ohos_unittest("AotCompilerImplUnitTest") {
"//third_party/googletest:gtest_main", "//third_party/googletest:gtest_main",
] ]
external_deps = [ external_deps = [
"ability_base:want",
"access_token:libaccesstoken_sdk", "access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk", "access_token:libtokenid_sdk",
"c_utils:utils", "c_utils:utils",

View File

@ -106,6 +106,37 @@ public:
AddExpandArgs(argVector); AddExpandArgs(argVector);
} }
int32_t EcmascriptAotCompilerMock(const std::unordered_map<std::string, std::string> &argsMap,
std::vector<int16_t> &sigData)
{
#ifdef CODE_SIGN_ENABLE
if (!allowAotCompiler_) {
return ERR_AOT_COMPILER_CONNECT_FAILED;
}
if (argsMap.empty() || (PrepareArgs(argsMap) != ERR_OK)) {
return ERR_AOT_COMPILER_PARAM_FAILED;
}
int32_t ret = ERR_OK;
pid_t pid = fork();
if (pid == -1) {
return ERR_AOT_COMPILER_CALL_FAILED;
} else if (pid == 0) {
DropCapabilities();
sleep(2); // 2: mock ark aot compiler run time with 2s
ExecuteInChildProcess();
} else {
mockChildPid_ = pid;
ExecuteInParentProcess(pid, ret);
}
if (ret == ERR_OK_NO_AOT_FILE) {
return ERR_OK;
}
return ret != ERR_OK ? ret : AOTLocalCodeSign(sigData);
#else
return ERR_AOT_COMPILER_SIGNATURE_DISABLE;
#endif
}
int32_t AOTLocalCodeSignMock(std::vector<int16_t> &sigData) const int32_t AOTLocalCodeSignMock(std::vector<int16_t> &sigData) const
{ {
return AOTLocalCodeSign(sigData); return AOTLocalCodeSign(sigData);
@ -130,6 +161,14 @@ public:
{ {
AllowAotCompiler(); AllowAotCompiler();
} }
pid_t GetChildPidMock()
{
return mockChildPid_;
}
private:
pid_t mockChildPid_ = -1;
}; };
class AotCompilerImplTest : public testing::Test { class AotCompilerImplTest : public testing::Test {
@ -615,4 +654,61 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_027, TestSize.Level0)
aotImplMock.HandleThermalLevelChanged(aotImplMock.AOT_COMPILE_STOP_LEVEL - 1); aotImplMock.HandleThermalLevelChanged(aotImplMock.AOT_COMPILE_STOP_LEVEL - 1);
EXPECT_TRUE(viewData); EXPECT_TRUE(viewData);
} }
/**
* @tc.name: AotCompilerImplTest_028
* @tc.desc: AotCompilerImpl::ExecuteInParentProcess(const pid_t childPid, int32_t &ret)
* child process terminate with signal SIGKILL;
* parent process receive SIGKILL signal;
* @tc.type: Func
*/
AotCompilerImplMock g_aotImplMock;
int32_t g_aotRet = INVALID_ERR_CODE;
void RunAotCompilerTask(void)
{
std::unordered_map<std::string, std::string> argsMap(argsMapForTest);
std::vector<int16_t> sigData;
{
std::lock_guard<std::mutex> lock(aotCompilerMutex_);
int32_t aotRet = g_aotImplMock.EcmascriptAotCompilerMock(argsMap, sigData);
if (aotRet == ERR_AOT_COMPILER_CALL_CRASH ||
aotRet == ERR_AOT_COMPILER_CALL_CANCELLED ||
aotRet == ERR_AOT_COMPILER_SIGNATURE_DISABLE) {
g_aotRet = aotRet;
}
}
}
void CancelAotCompilerTask(void)
{
sleep(1); // 1: delay 1s
pid_t childPid = g_aotImplMock.GetChildPidMock();
if (childPid > 0) {
g_aotImplMock.InitStateMock(childPid);
(void)g_aotImplMock.StopAotCompiler();
}
}
void TestCancelAotCompilerTask()
{
std::thread([]() {
RunAotCompilerTask();
}).detach();
std::thread([]() {
CancelAotCompilerTask();
}).detach();
sleep(3); // 3: delay 3s
}
HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_028, TestSize.Level0)
{
g_aotRet = INVALID_ERR_CODE;
TestCancelAotCompilerTask();
#ifdef CODE_SIGN_ENABLE
EXPECT_EQ(g_aotRet, ERR_AOT_COMPILER_CALL_CANCELLED);
#else
EXPECT_EQ(g_aotRet, ERR_AOT_COMPILER_SIGNATURE_DISABLE);
#endif
}
} // namespace OHOS::ArkCompiler } // namespace OHOS::ArkCompiler

View File

@ -29,6 +29,7 @@ ohos_unittest("AotCompilerProxyUnitTest") {
"//third_party/googletest:gtest_main", "//third_party/googletest:gtest_main",
] ]
external_deps = [ external_deps = [
"ability_base:want",
"access_token:libaccesstoken_sdk", "access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk", "access_token:libtokenid_sdk",
"c_utils:utils", "c_utils:utils",

View File

@ -331,7 +331,7 @@ HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_014, TestSize.Level0)
{ {
std::string sigData; std::string sigData;
std::string testData = "test"; std::string testData = "test";
auto func = [&](MessageParcel &reply) -> int32_t { auto func = [testData](MessageParcel &reply) -> int32_t {
reply.WriteInt32(ERR_OK); reply.WriteInt32(ERR_OK);
reply.WriteString16(Str8ToStr16(testData)); reply.WriteString16(Str8ToStr16(testData));
return ERR_OK; return ERR_OK;
@ -389,7 +389,7 @@ HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_017, TestSize.Level0)
std::string args; std::string args;
bool sigData = false; bool sigData = false;
bool testData = true; bool testData = true;
auto func = [=](MessageParcel &data, MessageParcel &reply) -> int32_t { auto func = [testData](MessageParcel &data, MessageParcel &reply) -> int32_t {
reply.WriteInt32(ERR_OK); reply.WriteInt32(ERR_OK);
reply.WriteBool(testData); reply.WriteBool(testData);
return ERR_OK; return ERR_OK;

View File

@ -29,6 +29,7 @@ ohos_unittest("AotCompilerServiceUnitTest") {
"//third_party/googletest:gtest_main", "//third_party/googletest:gtest_main",
] ]
external_deps = [ external_deps = [
"ability_base:want",
"access_token:libaccesstoken_sdk", "access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk", "access_token:libtokenid_sdk",
"c_utils:utils", "c_utils:utils",

View File

@ -29,6 +29,7 @@ ohos_unittest("AotCompilerStubUnitTest") {
"//third_party/googletest:gtest_main", "//third_party/googletest:gtest_main",
] ]
external_deps = [ external_deps = [
"ability_base:want",
"access_token:libaccesstoken_sdk", "access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk", "access_token:libtokenid_sdk",
"c_utils:utils", "c_utils:utils",
@ -40,7 +41,6 @@ ohos_unittest("AotCompilerStubUnitTest") {
"icu:shared_icui18n", "icu:shared_icui18n",
"icu:shared_icuuc", "icu:shared_icuuc",
"ipc:ipc_core", "ipc:ipc_core",
"power_manager:powermgr_client",
"runtime_core:libarkfile_static", "runtime_core:libarkfile_static",
"safwk:system_ability_fwk", "safwk:system_ability_fwk",
"samgr:samgr_proxy", "samgr:samgr_proxy",

View File

@ -83,7 +83,7 @@ void BindMidCpuCore()
cpu_set_t cpuset; cpu_set_t cpuset;
CPU_ZERO(&cpuset); CPU_ZERO(&cpuset);
for (int i = 0; i < 7; i++) { // 7: 0-3 little core, 4-6 mid core for (size_t i = 0; i < 7; i++) { // 7: 0-3 little core, 4-6 mid core
CPU_SET(i, &cpuset); CPU_SET(i, &cpuset);
} }