diff --git a/compiler_service/BUILD.gn b/compiler_service/BUILD.gn index ede1a95506913caef3023ee2730f0480a09d3cde..87e41d11c44ea9191953ecdb38a72a904bbaf75a 100644 --- a/compiler_service/BUILD.gn +++ b/compiler_service/BUILD.gn @@ -41,6 +41,7 @@ ohos_shared_library("libcompiler_service") { "${js_root}/ecmascript/log.cpp", "interface/aot_compiler_interface_proxy.cpp", "interface/aot_compiler_interface_stub.cpp", + "src/aot_args_handler.cpp", "src/aot_compiler_client.cpp", "src/aot_compiler_error_utils.cpp", "src/aot_compiler_impl.cpp", diff --git a/compiler_service/include/aot_args_handler.h b/compiler_service/include/aot_args_handler.h new file mode 100644 index 0000000000000000000000000000000000000000..47dfdd466e32386941c9382a2e5098debce00c21 --- /dev/null +++ b/compiler_service/include/aot_args_handler.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2025 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. + */ + +#ifndef OHOS_ARKCOMPILER_AOT_ARGS_HANDLER_H +#define OHOS_ARKCOMPILER_AOT_ARGS_HANDLER_H + +#include +#include +#include +#include + +namespace OHOS::ArkCompiler { +struct HapArgs { + std::vector argVector; + std::string fileName; + std::string signature; + int32_t bundleUid {0}; + int32_t bundleGid {0}; +}; + +class AOTArgsParserBase; + +class AOTArgsHandler { +public: + AOTArgsHandler(const std::unordered_map &argsMap); + + AOTArgsHandler() = default; + ~AOTArgsHandler() = default; + + int32_t Handle(int32_t thermalLevel = 0); + + std::vector GetAotArgs() const; + + void GetBundleId(int32_t &bundleUid, int32_t &bundleGid) const; + + std::string GetFileName() const; + + std::string GetCodeSignArgs() const; + +private: + std::unique_ptr parser_; + const std::unordered_map argsMap_; + HapArgs hapArgs_; + mutable std::mutex hapArgsMutex_; +}; + +class AOTArgsParserBase { +public: + virtual ~AOTArgsParserBase() = default; + + virtual int32_t Parse(const std::unordered_map &argsMap, HapArgs &hapArgs, + int32_t thermalLevel) = 0; + + static int32_t FindArgsIdxToInteger(const std::unordered_map &argsMap, + const std::string &keyName, int32_t &bundleID); + + static int32_t FindArgsIdxToString(const std::unordered_map &argsMap, + const std::string &keyName, std::string &bundleArg); +}; + +class AOTArgsParser final : public AOTArgsParserBase { +public: + int32_t Parse(const std::unordered_map &argsMap, HapArgs &hapArgs, + int32_t thermalLevel) override; + + void AddExpandArgs(std::vector &argVector, int32_t thermalLevel); +}; + +class StaticAOTArgsParser final : public AOTArgsParserBase { +public: + int32_t Parse(const std::unordered_map &argsMap, HapArgs &hapArgs, + int32_t thermalLevel) override; +}; + +enum class LanguageVersion { + DEFAULT = 0, // JS, TS, dynamic ArkTS + STATIC = 1 // static ArkTS +}; + +class AOTArgsParserFactory { +public: + static std::unique_ptr GetParser(const std::unordered_map &argsMap); +}; +} // namespace OHOS::ArkCompiler +#endif // OHOS_ARKCOMPILER_AOT_ARGS_HANDLER_H diff --git a/compiler_service/include/aot_args_list.h b/compiler_service/include/aot_args_list.h new file mode 100644 index 0000000000000000000000000000000000000000..092c9f376dfd9610c0c00abee667177827c52422 --- /dev/null +++ b/compiler_service/include/aot_args_list.h @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2025 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. + */ + +#ifndef OHOS_ARKCOMPILER_AOT_ARGS_LIST_H +#define OHOS_ARKCOMPILER_AOT_ARGS_LIST_H + +#include +#include + +namespace OHOS::ArkCompiler { + +constexpr const char* AOT_EXE = "/system/bin/ark_aot_compiler"; +constexpr const char* STATIC_AOT_EXE = "/system/bin/ark_aot"; + +std::unordered_set AotArgsList { + "aot-file", + "ark-properties", + "ark-bundleName", + "asm-interpreter", + "asm-opcode-disable-range", + "builtins-lazy", + "compiler-log", + "compiler-log-methods", + "compiler-log-snapshot", + "compiler-log-time", + "compiler-type-threshold", + "enable-ark-tools", + "compiler-trace-bc", + "compiler-trace-deopt", + "compiler-trace-inline", + "compiler-trace-value-numbering", + "compiler-trace-instruction-combine", + "compiler-max-inline-bytecodes", + "compiler-deopt-threshold", + "compiler-device-state", + "compiler-thermal-level", + "compiler-stress-deopt", + "compiler-opt-code-profiler", + "compiler-opt-bc-range", + "compiler-opt-bc-range-help", + "enable-force-gc", + "enable-ic", + "enable-runtime-stat", + "compiler-opt-constant-folding", + "compiler-opt-array-bounds-check-elimination", + "compiler-opt-type-lowering", + "compiler-opt-early-elimination", + "compiler-opt-later-elimination", + "compiler-opt-instr-combine", + "compiler-opt-string", + "compiler-opt-value-numbering", + "compiler-opt-new-value-numbering", + "compiler-opt-inlining", + "compiler-opt-pgotype", + "compiler-opt-track-field", + "entry-point", + "force-full-gc", + "force-shared-gc-frequency", + "gc-thread-num", + "heap-size-limit", + "icu-data-path", + "enable-worker", + "log-components", + "log-debug", + "log-error", + "log-fatal", + "log-info", + "log-level", + "log-warning", + "gc-long-paused-time", + "compiler-opt-max-method", + "compiler-module-methods", + "max-unmovable-space", + "merge-abc", + "enable-context", + "compiler-opt-level", + "reloc-mode", + "serializer-buffer-size-limit", + "startup-time", + "stub-file", + "compiler-target-triple", + "enable-print-execute-time", + "enable-pgo-profiler", + "enable-elements-kind", + "compiler-pgo-profiler-path", + "compiler-pgo-hotness-threshold", + "compiler-pgo-save-min-interval", + "compiler-verify-vtable", + "compiler-select-methods", + "compiler-skip-methods", + "target-compiler-mode", + "hap-path", + "hap-abc-offset", + "hap-abc-size", + "compiler-no-check", + "compiler-pipeline-host-aot", + "compiler-fast-compile", + "compiler-opt-loop-peeling", + "compiler-opt-array-onheap-check", + "compiler-pkg-info", + "compiler-external-pkg-info", + "compiler-enable-external-pkg", + "compiler-framework-abc-path", + "compiler-enable-lexenv-specialization", + "compiler-enable-native-inline", + "compiler-enable-lowering-builtin", + "compiler-enable-litecg", + "compiler-enable-jit", + "compiler-enable-osr", + "compiler-trace-jit", + "compiler-jit-hotness-threshold", + "compiler-osr-hotness-threshold", + "compiler-force-jit-compile-main", + "compiler-enable-jit-pgo", + "compiler-enable-aot-pgo", + "compiler-enable-framework-aot", + "compiler-enable-profile-dump", + "compiler-typed-op-profiler", + "compiler-opt-branch-profiling", + "test-assert", + "compiler-methods-range", + "compiler-codegen-options", + "compiler-opt-escape-analysis", + "compiler-trace-escape-analysis", + "compiler-opt-induction-variable", + "compiler-trace-induction-variable", + "compiler-memory-analysis", + "compiler-check-pgo-version", + "compiler-enable-baselinejit", + "compiler-baselinejit-hotness-threshold", + "compiler-force-baselinejit-compile-main", + "compiler-baseline-pgo", +}; + +std::unordered_set StaicAotArgsList { + "boot-panda-files", + "paoc-panda-files", + "paoc-output", + "load-runtimes", + "paoc-use-cha", +}; +} // namespace OHOS::ArkCompiler +#endif // OHOS_ARKCOMPILER_AOT_ARGS_LIST_H diff --git a/compiler_service/include/aot_compiler_constants.h b/compiler_service/include/aot_compiler_constants.h index a53a766140d3579426033166647cc507463d37bc..8b888a71845f5b9e5b0abc327079ce8e83b85925 100644 --- a/compiler_service/include/aot_compiler_constants.h +++ b/compiler_service/include/aot_compiler_constants.h @@ -18,15 +18,10 @@ #include #include -#include #include "aot_compiler_error_utils.h" namespace OHOS::ArkCompiler { -namespace Cmds { -constexpr const char* ARK_AOT_COMPILER = "/system/bin/ark_aot_compiler"; -} // namespace Cmds - namespace ArgsIdx { const std::string BUNDLE_UID = "BundleUid"; const std::string BUNDLE_GID = "BundleGid"; @@ -37,7 +32,7 @@ const std::string TARGET_COMPILER_MODE = "target-compiler-mode"; const std::string COMPILER_PKG_INFO = "compiler-pkg-info"; const std::string COMPILER_ENABLE_AOT_CODE_COMMENT = "compiler-enable-aot-code-comment"; const std::string COMPILER_LOG_OPT = "compiler-log"; - +const std::string LANGUAGE_VERSION = "language-version"; } // namespace ArgsIdx namespace Symbols { @@ -45,126 +40,6 @@ constexpr const char* PREFIX = "--"; constexpr const char* EQ = "="; } // namespace Symbols -std::unordered_set AotArgsSet { - "aot-file", - "ark-properties", - "ark-bundleName", - "asm-interpreter", - "asm-opcode-disable-range", - "builtins-lazy", - "compiler-log", - "compiler-log-methods", - "compiler-log-snapshot", - "compiler-log-time", - "compiler-type-threshold", - "enable-ark-tools", - "compiler-trace-bc", - "compiler-trace-deopt", - "compiler-trace-inline", - "compiler-trace-value-numbering", - "compiler-trace-instruction-combine", - "compiler-max-inline-bytecodes", - "compiler-deopt-threshold", - "compiler-device-state", - "compiler-thermal-level", - "compiler-stress-deopt", - "compiler-opt-code-profiler", - "compiler-opt-bc-range", - "compiler-opt-bc-range-help", - "enable-force-gc", - "enable-ic", - "enable-runtime-stat", - "compiler-opt-constant-folding", - "compiler-opt-array-bounds-check-elimination", - "compiler-opt-type-lowering", - "compiler-opt-early-elimination", - "compiler-opt-later-elimination", - "compiler-opt-instr-combine", - "compiler-opt-string", - "compiler-opt-value-numbering", - "compiler-opt-new-value-numbering", - "compiler-opt-inlining", - "compiler-opt-pgotype", - "compiler-opt-track-field", - "entry-point", - "force-full-gc", - "force-shared-gc-frequency", - "gc-thread-num", - "heap-size-limit", - "icu-data-path", - "enable-worker", - "log-components", - "log-debug", - "log-error", - "log-fatal", - "log-info", - "log-level", - "log-warning", - "gc-long-paused-time", - "compiler-opt-max-method", - "compiler-module-methods", - "max-unmovable-space", - "merge-abc", - "enable-context", - "compiler-opt-level", - "reloc-mode", - "serializer-buffer-size-limit", - "startup-time", - "stub-file", - "compiler-target-triple", - "enable-print-execute-time", - "enable-pgo-profiler", - "enable-elements-kind", - "compiler-pgo-profiler-path", - "compiler-pgo-hotness-threshold", - "compiler-pgo-save-min-interval", - "compiler-verify-vtable", - "compiler-select-methods", - "compiler-skip-methods", - "target-compiler-mode", - "hap-path", - "hap-abc-offset", - "hap-abc-size", - "compiler-no-check", - "compiler-pipeline-host-aot", - "compiler-fast-compile", - "compiler-opt-loop-peeling", - "compiler-opt-array-onheap-check", - "compiler-pkg-info", - "compiler-external-pkg-info", - "compiler-enable-external-pkg", - "compiler-framework-abc-path", - "compiler-enable-lexenv-specialization", - "compiler-enable-native-inline", - "compiler-enable-lowering-builtin", - "compiler-enable-litecg", - "compiler-enable-jit", - "compiler-enable-osr", - "compiler-trace-jit", - "compiler-jit-hotness-threshold", - "compiler-osr-hotness-threshold", - "compiler-force-jit-compile-main", - "compiler-enable-jit-pgo", - "compiler-enable-aot-pgo", - "compiler-enable-framework-aot", - "compiler-enable-profile-dump", - "compiler-typed-op-profiler", - "compiler-opt-branch-profiling", - "test-assert", - "compiler-methods-range", - "compiler-codegen-options", - "compiler-opt-escape-analysis", - "compiler-trace-escape-analysis", - "compiler-opt-induction-variable", - "compiler-trace-induction-variable", - "compiler-memory-analysis", - "compiler-check-pgo-version", - "compiler-enable-baselinejit", - "compiler-baselinejit-hotness-threshold", - "compiler-force-baselinejit-compile-main", - "compiler-baseline-pgo", -}; - /** * @param RetStatusOfCompiler return code of ark_aot_compiler * @attention it must sync with ErrCode of "ets_runtime/ecmascript/aot_compiler.cpp" diff --git a/compiler_service/include/aot_compiler_impl.h b/compiler_service/include/aot_compiler_impl.h index 9494b9c89537e6ab74bc2207f42b9da059fc4d56..c10ab1f72f3a35cd3684b3912b28b81f60f8540e 100644 --- a/compiler_service/include/aot_compiler_impl.h +++ b/compiler_service/include/aot_compiler_impl.h @@ -21,6 +21,7 @@ #include #include #include +#include "aot_args_handler.h" #include "ecmascript/compiler/aot_file/aot_version.h" namespace OHOS::ArkCompiler { @@ -44,22 +45,13 @@ public: void HandleThermalLevelChanged(const int32_t level); protected: - int32_t FindArgsIdxToInteger(const std::unordered_map &argsMap, - const std::string &keyName, int32_t &bundleID); - int32_t FindArgsIdxToString(const std::unordered_map &argsMap, - const std::string &keyName, std::string &bundleArg); - int32_t PrepareArgs(const std::unordered_map &argsMap); - void GetBundleId(int32_t &bundleUid, int32_t &bundleGid) const; void DropCapabilities() const; - void GetAotArgsVector(std::vector &argv) const; void ExecuteInChildProcess() const; int32_t PrintAOTCompilerResult(const int compilerStatus) const; void ExecuteInParentProcess(pid_t childPid, int32_t &ret); - void GetCodeSignArgs(std::string &appSignature, std::string &fileName) const; int32_t AOTLocalCodeSign(std::vector &sigData) const; int32_t RemoveAotFiles() const; void InitState(const pid_t childPid); - void AddExpandArgs(std::vector &argVector); void ResetState(); void PauseAotCompiler(); void AllowAotCompiler(); @@ -73,15 +65,8 @@ protected: AotCompilerImpl& operator=(AotCompilerImpl&&) = delete; protected: std::atomic allowAotCompiler_ {true}; - mutable std::mutex hapArgsMutex_; mutable std::mutex stateMutex_; - struct HapArgs { - std::vector argVector; - std::string fileName; - std::string signature; - int32_t bundleUid {0}; - int32_t bundleGid {0}; - } hapArgs_; + std::unique_ptr argsHandler_; struct AOTState { bool running {false}; pid_t childPid {-1}; diff --git a/compiler_service/src/aot_args_handler.cpp b/compiler_service/src/aot_args_handler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bef23c956c5765078504383758d6d0a245d8e492 --- /dev/null +++ b/compiler_service/src/aot_args_handler.cpp @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2025 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 "aot_args_handler.h" +#include "aot_args_list.h" +#include "aot_compiler_constants.h" +#include "ecmascript/log_wrapper.h" + +#ifdef ENABLE_COMPILER_SERVICE_GET_PARAMETER +#include "base/startup/init/interfaces/innerkits/include/syspara/parameters.h" +#endif + +namespace OHOS::ArkCompiler { +AOTArgsHandler::AOTArgsHandler(const std::unordered_map &argsMap) : argsMap_(argsMap) +{ + parser_ = AOTArgsParserFactory::GetParser(argsMap); +} + +int32_t AOTArgsHandler::Handle(int32_t thermalLevel) +{ + if (argsMap_.empty()) { + LOG_SA(ERROR) << "pass empty args to aot sa"; + return ERR_AOT_COMPILER_PARAM_FAILED; + } + + std::lock_guard lock(hapArgsMutex_); + int32_t ret = parser_->Parse(argsMap_, hapArgs_, thermalLevel); + return ret; +} + +std::vector AOTArgsHandler::GetAotArgs() const +{ + std::lock_guard lock(hapArgsMutex_); + std::vector argv; + argv.reserve(hapArgs_.argVector.size() + 1); // 1: for nullptr + for (auto &arg : hapArgs_.argVector) { + argv.emplace_back(arg.c_str()); + } + + return argv; +} + +void AOTArgsHandler::GetBundleId(int32_t &bundleUid, int32_t &bundleGid) const +{ + std::lock_guard lock(hapArgsMutex_); + bundleUid = hapArgs_.bundleUid; + bundleGid = hapArgs_.bundleGid; +} + +std::string AOTArgsHandler::GetFileName() const +{ + std::lock_guard lock(hapArgsMutex_); + return hapArgs_.fileName; +} + +std::string AOTArgsHandler::GetCodeSignArgs() const +{ + std::lock_guard lock(hapArgsMutex_); + return hapArgs_.signature; +} + +int32_t AOTArgsParserBase::FindArgsIdxToInteger(const std::unordered_map &argsMap, + const std::string &keyName, int32_t &bundleID) +{ + 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(std::stoi(argsMap.at(keyName), &sz)); + if (sz < static_cast(argsMap.at(keyName).size())) { + LOG_SA(ERROR) << "trigger exception as converting string to integer"; + return ERR_AOT_COMPILER_PARAM_FAILED; + } + return ERR_OK; +} + +int32_t AOTArgsParserBase::FindArgsIdxToString(const std::unordered_map &argsMap, + const std::string &keyName, std::string &bundleArg) +{ + if (argsMap.find(keyName) == argsMap.end()) { + return ERR_AOT_COMPILER_PARAM_FAILED; + } + + bundleArg = argsMap.at(keyName); + return ERR_OK; +} + +int32_t AOTArgsParser::Parse(const std::unordered_map &argsMap, HapArgs &hapArgs, + int32_t thermalLevel) +{ + 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) || + (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(AOT_EXE); + + // service process add aot compile args here + AddExpandArgs(hapArgs.argVector, thermalLevel); + + for (auto &argPair : argsMap) { + if (AotArgsList.find(argPair.first) != AotArgsList.end()) { + hapArgs.argVector.emplace_back(Symbols::PREFIX + argPair.first + Symbols::EQ + argPair.second); + } + } + + #ifdef ENABLE_COMPILER_SERVICE_GET_PARAMETER + bool enableAotCodeComment = OHOS::system::GetBoolParameter("ark.aot.code_comment.enable", false); + if (enableAotCodeComment) { + hapArgs.argVector.emplace_back(Symbols::PREFIX + ArgsIdx::COMPILER_ENABLE_AOT_CODE_COMMENT + + Symbols::EQ + "true"); + hapArgs.argVector.emplace_back(Symbols::PREFIX + ArgsIdx::COMPILER_LOG_OPT + + Symbols::EQ + "allasm"); + } + #endif + + hapArgs.argVector.emplace_back(abcPath); + return ERR_OK; +} + +void AOTArgsParser::AddExpandArgs(std::vector &argVector, int32_t thermalLevel) +{ + std::string thermalLevelArg = "--compiler-thermal-level=" + std::to_string(thermalLevel); + argVector.emplace_back(thermalLevelArg); +} + +int32_t StaticAOTArgsParser::Parse(const std::unordered_map &argsMap, + HapArgs &hapArgs, [[maybe_unused]] int32_t thermalLevel) +{ + 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) || + (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(STATIC_AOT_EXE); + + for (auto &argPair : argsMap) { + if (StaicAotArgsList.find(argPair.first) != AotArgsList.end()) { + hapArgs.argVector.emplace_back(Symbols::PREFIX + argPair.first + Symbols::EQ + argPair.second); + } + } + + hapArgs.argVector.emplace_back(abcPath); + return ERR_OK; +} + +std::unique_ptr AOTArgsParserFactory::GetParser( + const std::unordered_map &argsMap) +{ + int32_t languageVersion = 0; + if (AOTArgsParserBase::FindArgsIdxToInteger(argsMap, ArgsIdx::LANGUAGE_VERSION, languageVersion) != ERR_OK) { + LOG_SA(INFO) << "aot sa failed to get language version"; + } + + switch (static_cast(languageVersion)) { + case LanguageVersion::DEFAULT: + LOG_SA(INFO) << "aot sa use default compiler"; + return std::make_unique(); + case LanguageVersion::STATIC: + LOG_SA(INFO) << "aot sa use static compiler"; + return std::make_unique(); + default: + LOG_SA(FATAL) << "aot sa get invalid language version"; + } +} +} // namespace OHOS::ArkCompiler diff --git a/compiler_service/src/aot_compiler_impl.cpp b/compiler_service/src/aot_compiler_impl.cpp index 2ce721d91ded8efa93ff195f1e7f159dc8ddc5a2..cc7014a122e15d3ed6123ae918aa670e76b54e7c 100644 --- a/compiler_service/src/aot_compiler_impl.cpp +++ b/compiler_service/src/aot_compiler_impl.cpp @@ -35,9 +35,6 @@ #ifdef CODE_SIGN_ENABLE #include "local_code_sign_kit.h" #endif -#ifdef ENABLE_COMPILER_SERVICE_GET_PARAMETER -#include "base/startup/init/interfaces/innerkits/include/syspara/parameters.h" -#endif #include "system_ability_definition.h" namespace OHOS::ArkCompiler { @@ -47,84 +44,12 @@ AotCompilerImpl& AotCompilerImpl::GetInstance() return aotCompiler; } -int32_t AotCompilerImpl::FindArgsIdxToInteger(const std::unordered_map &argsMap, - const std::string &keyName, int32_t &bundleID) -{ - 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(std::stoi(argsMap.at(keyName), &sz)); - if (sz < static_cast(argsMap.at(keyName).size())) { - LOG_SA(ERROR) << "trigger exception as converting string to integer"; - return ERR_AOT_COMPILER_PARAM_FAILED; - } - return ERR_OK; -} - -int32_t AotCompilerImpl::FindArgsIdxToString(const std::unordered_map &argsMap, - const std::string &keyName, std::string &bundleArg) -{ - if (argsMap.find(keyName) == argsMap.end()) { - return ERR_AOT_COMPILER_PARAM_FAILED; - } - bundleArg = argsMap.at(keyName); - return ERR_OK; -} - -int32_t AotCompilerImpl::PrepareArgs(const std::unordered_map &argsMap) -{ - for (const auto &arg : argsMap) { - LOG_SA(DEBUG) << arg.first << ": " << arg.second; - } - std::lock_guard 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) || - (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); - // service process add aot compile args here - 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); - } - } -#ifdef ENABLE_COMPILER_SERVICE_GET_PARAMETER - bool enableAotCodeComment = OHOS::system::GetBoolParameter("ark.aot.code_comment.enable", false); - if (enableAotCodeComment) { - hapArgs_.argVector.emplace_back(Symbols::PREFIX + ArgsIdx::COMPILER_ENABLE_AOT_CODE_COMMENT + - Symbols::EQ + "true"); - hapArgs_.argVector.emplace_back(Symbols::PREFIX + ArgsIdx::COMPILER_LOG_OPT + - Symbols::EQ + "allasm"); - } -#endif - hapArgs_.argVector.emplace_back(abcPath); - return ERR_OK; -} - -void AotCompilerImpl::GetBundleId(int32_t &bundleUid, int32_t &bundleGid) const -{ - std::lock_guard 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); + argsHandler_->GetBundleId(bundleUid, bundleGid); if (setgid(bundleGid)) { LOG_SA(ERROR) << "dropCapabilities setgid failed : " << strerror(errno); exit(-1); @@ -152,20 +77,9 @@ void AotCompilerImpl::DropCapabilities() const LOG_SA(INFO) << "drop capabilities success"; } -void AotCompilerImpl::GetAotArgsVector(std::vector &argv) const -{ - std::lock_guard lock(hapArgsMutex_); - const std::vector &aotVector = hapArgs_.argVector; - argv.reserve(aotVector.size() + 1); - for (auto &arg : aotVector) { - argv.emplace_back(arg.c_str()); - } -} - void AotCompilerImpl::ExecuteInChildProcess() const { - std::vector argv; - GetAotArgsVector(argv); + std::vector argv = argsHandler_->GetAotArgs(); LOG_SA(INFO) << "ark_aot_compiler argv size : " << argv.size(); for (const auto &arg : argv) { LOG_SA(INFO) << arg; @@ -177,12 +91,6 @@ void AotCompilerImpl::ExecuteInChildProcess() const exit(-1); } -void AotCompilerImpl::AddExpandArgs(std::vector &argVector) -{ - std::string thermalLevelArg = "--compiler-thermal-level=" + std::to_string(thermalLevel_); - argVector.emplace_back(thermalLevelArg); -} - int32_t AotCompilerImpl::PrintAOTCompilerResult(const int compilerStatus) const { if (RetInfoOfCompiler.find(compilerStatus) == RetInfoOfCompiler.end()) { @@ -258,10 +166,12 @@ int32_t AotCompilerImpl::EcmascriptAotCompiler(const std::unordered_map(argsMap); + if (argsHandler_->Handle(thermalLevel_) != ERR_OK) { return ERR_AOT_COMPILER_PARAM_FAILED; } + int32_t ret = ERR_OK; LOG_SA(INFO) << "begin to fork"; pid_t pid = fork(); @@ -299,19 +209,11 @@ int32_t AotCompilerImpl::NeedReCompile(const std::string& args, bool& sigData) return ERR_OK; } -void AotCompilerImpl::GetCodeSignArgs(std::string &appSignature, std::string &fileName) const -{ - std::lock_guard lock(hapArgsMutex_); - appSignature = hapArgs_.signature; - fileName = hapArgs_.fileName; -} - int32_t AotCompilerImpl::AOTLocalCodeSign(std::vector &sigData) const { #ifdef CODE_SIGN_ENABLE - std::string appSignature; - std::string fileName; - GetCodeSignArgs(appSignature, fileName); + std::string appSignature = argsHandler_->GetCodeSignArgs(); + std::string fileName = argsHandler_->GetFileName(); Security::CodeSign::ByteBuffer sig; if (Security::CodeSign::LocalCodeSignKit::SignLocalCode(appSignature, fileName, sig) != CommonErrCode::CS_SUCCESS) { @@ -357,9 +259,9 @@ int32_t AotCompilerImpl::StopAotCompiler() int32_t AotCompilerImpl::RemoveAotFiles() const { - std::lock_guard lock(hapArgsMutex_); - if (access(hapArgs_.fileName.c_str(), ERR_OK) != ERR_FAIL) { - auto delRes = std::remove(hapArgs_.fileName.c_str()); + std::string fileName = argsHandler_->GetFileName(); + if (access(fileName.c_str(), ERR_OK) != ERR_FAIL) { + auto delRes = std::remove(fileName.c_str()); if (delRes != ERR_OK) { LOG_SA(INFO) << "delete invalid aot file failed: " << delRes; return ERR_AOT_COMPILER_STOP_FAILED; @@ -437,4 +339,4 @@ void AotCompilerImpl::ResetState() state_.running = false; state_.childPid = -1; } -} // namespace OHOS::ArkCompiler \ No newline at end of file +} // namespace OHOS::ArkCompiler diff --git a/compiler_service/test/BUILD.gn b/compiler_service/test/BUILD.gn index f02cd9b3ca86687cd4af7c50dab625ad8522d8c1..f457e8ad7fd3d4e61415608bab2a886310f3c423 100644 --- a/compiler_service/test/BUILD.gn +++ b/compiler_service/test/BUILD.gn @@ -14,6 +14,7 @@ group("compiler_service_unittest") { testonly = true deps = [ + "unittest/aotcompilerargshandler_unit:AotCompilerArgsHandlerUnitTest", "unittest/aotcompilerclient_unit:AotCompilerClientUnitTest", "unittest/aotcompilererrorutils_unit:AotCompilerErrorUtilsUnitTest", "unittest/aotcompilerimpl_unit:AotCompilerImplUnitTest", diff --git a/compiler_service/test/compiler_service_test.gni b/compiler_service/test/compiler_service_test.gni index 2a9af2269ff73d8ba04476641b95f61858854b4d..b07eed7185cf937d89bec518f468eb8c3904305b 100644 --- a/compiler_service/test/compiler_service_test.gni +++ b/compiler_service/test/compiler_service_test.gni @@ -34,6 +34,7 @@ compiler_service_include_dirs = [ aot_compiler_service_sources = [ "${compiler_service_root}/interface/aot_compiler_interface_proxy.cpp", "${compiler_service_root}/interface/aot_compiler_interface_stub.cpp", + "${compiler_service_root}/src/aot_args_handler.cpp", "${compiler_service_root}/src/aot_compiler_client.cpp", "${compiler_service_root}/src/aot_compiler_error_utils.cpp", "${compiler_service_root}/src/aot_compiler_impl.cpp", diff --git a/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e83bad2f5d50cb9b64c9eabee2e9374707cd5a75 --- /dev/null +++ b/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2025 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("../../../test/compiler_service_test.gni") + +config("module_private_config") { + visibility = [ ":*" ] + include_dirs = compiler_service_include_dirs + cflags = [ "-Wno-error=keyword-macro" ] +} + +ohos_unittest("AotCompilerArgsHandlerUnitTest") { + 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 = [ + "ability_base:want", + "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 (code_sign_enable_test) { + external_deps += [ "code_signature:liblocal_code_sign_sdk" ] + defines += [ "CODE_SIGN_ENABLE" ] + } + sources += [ "aotcompilerargshandler_unit.cpp" ] +} diff --git a/compiler_service/test/unittest/aotcompilerargshandler_unit/aotcompilerargshandler_unit.cpp b/compiler_service/test/unittest/aotcompilerargshandler_unit/aotcompilerargshandler_unit.cpp new file mode 100644 index 0000000000000000000000000000000000000000..66de26c5f96b2874248614d794fe76dddf1989f0 --- /dev/null +++ b/compiler_service/test/unittest/aotcompilerargshandler_unit/aotcompilerargshandler_unit.cpp @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2025 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 +#include +#include +#include + +#include "aot_args_handler.h" +#include "aot_compiler_constants.h" +#include "aot_compiler_error_utils.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + +using namespace testing::ext; + +namespace OHOS::ArkCompiler { + +class AotArgsHandlerTest : public testing::Test { +public: + AotArgsHandlerTest() {} + virtual ~AotArgsHandlerTest() {} + + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() override {} + void TearDown() override {}; +}; + +/** + * @tc.name: AotArgsHandlerTest_001 + * @tc.desc: AOTArgsParserBase::FindArgsIdxToInteger(argsMap, keyName, bundleID) + * @tc.type: Func +*/ +HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_001, TestSize.Level0) +{ + std::unordered_map argsMap; + std::string keyName = "compiler-pkg-info"; + int32_t bundleID = 0; + int32_t ret = AOTArgsParserBase::FindArgsIdxToInteger(argsMap, keyName, bundleID); + EXPECT_EQ(ret, ERR_AOT_COMPILER_PARAM_FAILED); +} + +/** + * @tc.name: AotArgsHandlerTest_002 + * @tc.desc: AOTArgsParserBase::FindArgsIdxToInteger(argsMap, keyName, bundleID) + * @tc.type: Func +*/ +HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_002, TestSize.Level0) +{ + std::unordered_map argsMap; + argsMap.emplace("argKey", "argValueNotInteger"); + std::string keyName = "argKey"; + int32_t bundleID = 0; + int32_t ret = AOTArgsParserBase::FindArgsIdxToInteger(argsMap, keyName, bundleID); + EXPECT_EQ(ret, ERR_AOT_COMPILER_PARAM_FAILED); +} + +/** + * @tc.name: AotArgsHandlerTest_003 + * @tc.desc: AOTArgsParserBase::FindArgsIdxToInteger(argsMap, keyName, bundleID) + * @tc.type: Func +*/ +HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_003, TestSize.Level0) +{ + std::unordered_map argsMap; + argsMap.emplace("argKey", "123456_argValueNotInteger"); + std::string keyName = "argKey"; + int32_t bundleID = 0; + int32_t ret = AOTArgsParserBase::FindArgsIdxToInteger(argsMap, keyName, bundleID); + EXPECT_EQ(ret, ERR_AOT_COMPILER_PARAM_FAILED); +} + +/** + * @tc.name: AotArgsHandlerTest_004 + * @tc.desc: AOTArgsParserBase::FindArgsIdxToInteger(argsMap, keyName, bundleID) + * @tc.type: Func +*/ +HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_004, TestSize.Level0) +{ + std::unordered_map argsMap; + argsMap.emplace("argKey", "20020079"); + std::string keyName = "argKey"; + int32_t bundleID = 0; + int32_t ret = AOTArgsParserBase::FindArgsIdxToInteger(argsMap, keyName, bundleID); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(bundleID, 20020079); +} + +/** + * @tc.name: AotArgsHandlerTest_005 + * @tc.desc: AOTArgsParserBase::FindArgsIdxToString(argsMap, keyName, bundleArg) + * @tc.type: Func +*/ +HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_005, TestSize.Level0) +{ + std::unordered_map argsMap; + std::string keyName = "argKey"; + std::string bundleArg = ""; + int32_t ret = AOTArgsParserBase::FindArgsIdxToString(argsMap, keyName, bundleArg); + EXPECT_EQ(ret, ERR_AOT_COMPILER_PARAM_FAILED); +} + +/** + * @tc.name: AotArgsHandlerTest_006 + * @tc.desc: AOTArgsParserBase::FindArgsIdxToString(argsMap, keyName, bundleArg) + * @tc.type: Func +*/ +HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_006, TestSize.Level0) +{ + std::unordered_map argsMap; + argsMap.emplace("argKey", "com.ohos.contacts"); + std::string keyName = "argKey"; + std::string bundleArg = ""; + int32_t ret = AOTArgsParserBase::FindArgsIdxToString(argsMap, keyName, bundleArg); + EXPECT_EQ(ret, ERR_OK); + EXPECT_STREQ(bundleArg.c_str(), "com.ohos.contacts"); +} + +const std::string COMPILER_PKG_INFO_VALUE = + "{\"abcName\":\"ets/modules.abc\"," + "\"abcOffset\":\"0x1000\"," + "\"abcSize\":\"0x60b058\"," + "\"appIdentifier\":\"5765880207853624761\"," + "\"bundleName\":\"com.ohos.contacts\"," + "\"BundleUid\":\"0x1317b6f\"," + "\"isEncryptedBundle\":\"0x0\"," + "\"isScreenOff\":\"0x1\"," + "\"moduleName\":\"entry\"," + "\"pgoDir\":\"/data/local/ark-profile/100/com.ohos.contacts\"," + "\"pkgPath\":\"/system/app/Contacts/Contacts.hap\"," + "\"processUid\":\"0xbf4\"}"; + +const std::unordered_map argsMapForTest { + {"target-compiler-mode", "partial"}, + {"aot-file", "/data/local/ark-cache/com.ohos.contacts/arm64/entry"}, + {"compiler-pkg-info", COMPILER_PKG_INFO_VALUE}, + {"compiler-external-pkg-info", "[]"}, + {"compiler-opt-bc-range", ""}, + {"compiler-device-state", "1"}, + {"compiler-baseline-pgo", "0"}, + {"ABC-Path", "/system/app/Contacts/Contacts.hap/ets/modules.abc"}, + {"BundleUid", "20020079"}, + {"BundleGid", "20020079"}, + {"anFileName", "/data/local/ark-cache/com.ohos.contacts/arm64/entry.an"}, + {"appIdentifier", "5765880207853624761"}, +}; + +/** + * @tc.name: AotArgsHandlerTest_007 + * @tc.desc: AOTArgsHandler::Handle(argsMap) + * @tc.type: Func +*/ +HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_007, TestSize.Level0) +{ + std::unordered_map argsMap(argsMapForTest); + argsMap.emplace("language-version", "0"); + std::unique_ptr argsHandler = std::make_unique(argsMap); + int32_t ret = argsHandler->Handle(0); + EXPECT_EQ(ret, ERR_OK); + std::vector argv = argsHandler->GetAotArgs(); + EXPECT_STREQ(argv[0], "/system/bin/ark_aot_compiler"); +} + +/** + * @tc.name: AotArgsHandlerTest_008 + * @tc.desc: AOTArgsHandler::Handle(argsMap) + * @tc.type: Func +*/ +HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_008, TestSize.Level0) +{ + std::unordered_map argsMap(argsMapForTest); + argsMap.emplace("language-version", "1"); + std::unique_ptr argsHandler = std::make_unique(argsMap); + int32_t ret = argsHandler->Handle(0); + EXPECT_EQ(ret, ERR_OK); + std::vector argv = argsHandler->GetAotArgs(); + EXPECT_STREQ(argv[0], "/system/bin/ark_aot"); +} + +/** + * @tc.name: AotArgsHandlerTest_009 + * @tc.desc: AOTArgsParser::AddExpandArgs(aotVector, thermalLevel) + * @tc.type: Func +*/ +HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_009, TestSize.Level0) +{ + std::unique_ptr parser = std::make_unique(); + std::vector aotVector; + parser->AddExpandArgs(aotVector, 0); + std::string arg = aotVector[0]; + EXPECT_STREQ(arg.c_str(), "--compiler-thermal-level=0"); +} +} // namespace OHOS::ArkCompiler \ No newline at end of file diff --git a/compiler_service/test/unittest/aotcompilerimpl_unit/aotcompilerimpl_unit.cpp b/compiler_service/test/unittest/aotcompilerimpl_unit/aotcompilerimpl_unit.cpp index fd7b069b26fc77ae292b93f5c7af2d4d365e8d17..257db6f97d10486000c1a2781a67aa27c085b55e 100644 --- a/compiler_service/test/unittest/aotcompilerimpl_unit/aotcompilerimpl_unit.cpp +++ b/compiler_service/test/unittest/aotcompilerimpl_unit/aotcompilerimpl_unit.cpp @@ -79,33 +79,11 @@ public: AotCompilerImplMock& operator=(const AotCompilerImplMock&) = delete; AotCompilerImplMock& operator=(AotCompilerImplMock&&) = delete; - int32_t FindArgsIdxToIntegerMock(const std::unordered_map &argsMap, - const std::string &keyName, int32_t &bundleID) - { - return FindArgsIdxToInteger(argsMap, keyName, bundleID); - } - - int32_t FindArgsIdxToStringMock(const std::unordered_map &argsMap, - const std::string &keyName, std::string &bundleArg) - { - return FindArgsIdxToString(argsMap, keyName, bundleArg); - } - - int32_t PrepareArgsMock(const std::unordered_map &argsMap) - { - return PrepareArgs(argsMap); - } - int32_t PrintAOTCompilerResultMock(const int compilerStatus) const { return PrintAOTCompilerResult(compilerStatus); } - void AddExpandArgsMock(std::vector &argVector) - { - AddExpandArgs(argVector); - } - int32_t EcmascriptAotCompilerMock(const std::unordered_map &argsMap, std::vector &sigData) { @@ -113,9 +91,12 @@ public: if (!allowAotCompiler_) { return ERR_AOT_COMPILER_CALL_CANCELLED; } - if (argsMap.empty() || (PrepareArgs(argsMap) != ERR_OK)) { + + std::unique_ptr argsHandler = std::make_unique(argsMap); + if (argsHandler->Handle(0) != ERR_OK) { return ERR_AOT_COMPILER_PARAM_FAILED; } + int32_t ret = ERR_OK; pid_t pid = fork(); if (pid == -1) { @@ -167,6 +148,11 @@ public: return mockChildPid_; } + void SetAOTArgsHandler(std::unique_ptr argsHandler) + { + argsHandler_ = std::move(argsHandler); + } + private: pid_t mockChildPid_ = -1; }; @@ -404,135 +390,10 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_012, TestSize.Level0) /** * @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 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 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 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 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 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 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 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 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) +HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_013, TestSize.Level0) { AotCompilerImplMock aotImplMock; int32_t ret = aotImplMock.PrintAOTCompilerResultMock(TEST_ERR_OTHERS); @@ -544,11 +405,11 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_021, TestSize.Level0) } /** - * @tc.name: AotCompilerImplTest_022 + * @tc.name: AotCompilerImplTest_014 * @tc.desc: AotCompilerImpl::EcmascriptAotCompiler(argsMap, sigData) * @tc.type: Func */ -HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_022, TestSize.Level0) +HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_014, TestSize.Level0) { AotCompilerImplMock aotImplMock; std::unordered_map argsMap; @@ -574,18 +435,20 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_022, TestSize.Level0) } /** - * @tc.name: AotCompilerImplTest_023 + * @tc.name: AotCompilerImplTest_015 * @tc.desc: AotCompilerImpl::AOTLocalCodeSign(sigData) * @tc.type: Func */ -HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_023, TestSize.Level0) +HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_015, TestSize.Level0) { AotCompilerImplMock aotImplMock; std::string fileName = "/data/local/ark-cache/com.ohos.contacts/arm64/entry.an"; std::string appSignature = "5765880207853624761"; std::vector sigData; - int32_t ret = aotImplMock.PrepareArgsMock(argsMapForTest); + std::unique_ptr argsHandler = std::make_unique(argsMapForTest); + int32_t ret = argsHandler->Handle(0); EXPECT_EQ(ret, ERR_OK); + aotImplMock.SetAOTArgsHandler(std::move(argsHandler)); ret = aotImplMock.AOTLocalCodeSignMock(sigData); #ifdef CODE_SIGN_ENABLE EXPECT_NE(ret, ERR_AOT_COMPILER_SIGNATURE_DISABLE); @@ -595,13 +458,17 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_023, TestSize.Level0) } /** - * @tc.name: AotCompilerImplTest_024 + * @tc.name: AotCompilerImplTest_016 * @tc.desc: AotCompilerImpl::StopAotCompiler() * @tc.type: Func */ -HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_024, TestSize.Level0) +HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_016, TestSize.Level0) { AotCompilerImplMock aotImplMock; + std::unique_ptr argsHandler = std::make_unique(argsMapForTest); + int32_t retHandle = argsHandler->Handle(0); + EXPECT_EQ(retHandle, ERR_OK); + aotImplMock.SetAOTArgsHandler(std::move(argsHandler)); aotImplMock.ResetStateMock(); int32_t ret = aotImplMock.StopAotCompiler(); EXPECT_EQ(ret, ERR_AOT_COMPILER_STOP_FAILED); @@ -616,11 +483,11 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_024, TestSize.Level0) } /** - * @tc.name: AotCompilerImplTest_025 + * @tc.name: AotCompilerImplTest_017 * @tc.desc: AotCompilerImpl::HandlePowerDisconnected() * @tc.type: Func */ -HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_025, TestSize.Level0) +HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_017, TestSize.Level0) { bool viewData = true; AotCompilerImplMock aotImplMock; @@ -629,11 +496,11 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_025, TestSize.Level0) } /** - * @tc.name: AotCompilerImplTest_026 + * @tc.name: AotCompilerImplTest_018 * @tc.desc: AotCompilerImpl::HandleScreenOn() * @tc.type: Func */ -HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_026, TestSize.Level0) +HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_018, TestSize.Level0) { bool viewData = true; AotCompilerImplMock aotImplMock; @@ -642,11 +509,11 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_026, TestSize.Level0) } /** - * @tc.name: AotCompilerImplTest_027 + * @tc.name: AotCompilerImplTest_019 * @tc.desc: AotCompilerImpl::HandleThermalLevelChanged(aotImpl.AOT_COMPILE_STOP_LEVEL) * @tc.type: Func */ -HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_027, TestSize.Level0) +HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_019, TestSize.Level0) { bool viewData = true; AotCompilerImplMock aotImplMock; @@ -656,7 +523,7 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_027, TestSize.Level0) } /** - * @tc.name: AotCompilerImplTest_028 + * @tc.name: AotCompilerImplTest_020 * @tc.desc: AotCompilerImpl::ExecuteInParentProcess(const pid_t childPid, int32_t &ret) * child process terminate with signal SIGKILL; * parent process receive SIGKILL signal; @@ -671,6 +538,10 @@ void RunAotCompilerTask(void) std::vector sigData; { std::lock_guard lock(aotCompilerMutex_); + std::unique_ptr argsHandler = std::make_unique(argsMapForTest); + int32_t retHandle = argsHandler->Handle(0); + EXPECT_EQ(retHandle, ERR_OK); + g_aotImplMock.SetAOTArgsHandler(std::move(argsHandler)); int32_t aotRet = g_aotImplMock.EcmascriptAotCompilerMock(argsMap, sigData); if (aotRet == ERR_AOT_COMPILER_CALL_CRASH || aotRet == ERR_AOT_COMPILER_CALL_CANCELLED || @@ -701,7 +572,7 @@ void TestCancelAotCompilerTask() sleep(3); // 3: delay 3s } -HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_028, TestSize.Level0) +HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_020, TestSize.Level0) { g_aotRet = INVALID_ERR_CODE; TestCancelAotCompilerTask();