diff --git a/ets_environment/frameworks/ets_environment/src/ets_environment.cpp b/ets_environment/frameworks/ets_environment/src/ets_environment.cpp index 4b4f96d79acef594fec7e80e2a0143ac8e5e073b..266971441308a5d90b11ba37f6ac2a10bf375285 100644 --- a/ets_environment/frameworks/ets_environment/src/ets_environment.cpp +++ b/ets_environment/frameworks/ets_environment/src/ets_environment.cpp @@ -517,16 +517,17 @@ bool ETSEnvironment::LoadModule(const std::string &modulePath, const std::string return true; } -void ETSEnvironment::FinishPreload() { +bool ETSEnvironment::FinishPreload() { ani_env *env = GetAniEnv(); if (env == nullptr) { TAG_LOGE(AAFwkTag::ETSRUNTIME, "Failed: ANI env nullptr"); - return; + return false; } ark::ets::ETSAni::Prefork(env); + return true; } -void ETSEnvironment::PostFork(void *napiEnv, const std::string &aotPath, +bool ETSEnvironment::PostFork(void *napiEnv, const std::string &aotPath, const std::vector &appInnerHspPathList, const std::vector &commonHspBundleInfos) { @@ -544,26 +545,28 @@ void ETSEnvironment::PostFork(void *napiEnv, const std::string &aotPath, ani_env *env = GetAniEnv(); if (env == nullptr) { TAG_LOGE(AAFwkTag::ETSRUNTIME, "Failed: ANI env nullptr"); - return; + return false; } ark::ets::ETSAni::Postfork(env, options); appInnerHspPathList_ = appInnerHspPathList; commonHspBundleInfos_ = commonHspBundleInfos; + return true; } -void ETSEnvironment::PreloadSystemClass(const char *className) +bool ETSEnvironment::PreloadSystemClass(const char *className) { ani_env* env = GetAniEnv(); if (env == nullptr) { TAG_LOGE(AAFwkTag::ETSRUNTIME, "GetAniEnv failed"); - return; + return false; } ani_class cls = nullptr; if (env->FindClass(className, &cls) != ANI_OK) { TAG_LOGE(AAFwkTag::ETSRUNTIME, "Find preload class failed"); - return; + return false; } + return true; } ETSEnvFuncs *ETSEnvironment::RegisterFuncs() diff --git a/ets_environment/interfaces/inner_api/ets_environment.h b/ets_environment/interfaces/inner_api/ets_environment.h index 2e9a19aea07ed8c825d04da7808054b8b9344233..54ce7956b8ed7822e908dccdd9a78be58b9b0c84 100644 --- a/ets_environment/interfaces/inner_api/ets_environment.h +++ b/ets_environment/interfaces/inner_api/ets_environment.h @@ -59,10 +59,10 @@ public: bool PreloadModule(const std::string &modulePath); bool LoadModule(const std::string &modulePath, const std::string &srcEntrance, void *&cls, void *&obj, void *&ref); - void FinishPreload(); - void PostFork(void *napiEnv, const std::string &aotPath, const std::vector& appInnerHspPathList, + bool FinishPreload(); + bool PostFork(void *napiEnv, const std::string &aotPath, const std::vector& appInnerHspPathList, const std::vector &commonHspBundleInfos); - void PreloadSystemClass(const char *className); + bool PreloadSystemClass(const char *className); void RemoveInstance(uint32_t instanceId); void StopDebugMode(void *jsVm); diff --git a/ets_environment/test/unittest/ets_environment_test/ets_environment_test.cpp b/ets_environment/test/unittest/ets_environment_test/ets_environment_test.cpp index 63ab15878ebebbdf05e33807ab407cbc55daf86f..58503fd7a09f866fca024c36cccc586c3f5aaddd 100644 --- a/ets_environment/test/unittest/ets_environment_test/ets_environment_test.cpp +++ b/ets_environment/test/unittest/ets_environment_test/ets_environment_test.cpp @@ -324,5 +324,55 @@ HWTEST_F(EtsEnvironmentTest, GetDebuggerPostTask_0100, TestSize.Level0) auto task = etsEnv->GetDebuggerPostTask(); ASSERT_NE(task, nullptr); } + +/** + * @tc.name: FinishPreload_0100 + * @tc.desc: Sts environment FinishPreload. + * @tc.type: FUNC + */ +HWTEST_F(EtsEnvironmentTest, FinishPreload_0100, TestSize.Level0) +{ + auto etsEnv = std::make_shared(); + ASSERT_NE(etsEnv, nullptr); + auto result = etsEnv->FinishPreload(); + EXPECT_FALSE(result); +} + +/** + * @tc.name: PostFork_0100 + * @tc.desc: Sts environment PostFork. + * @tc.type: FUNC + */ +HWTEST_F(EtsEnvironmentTest, PostFork_0100, TestSize.Level0) +{ + auto etsEnv = std::make_shared(); + ASSERT_NE(etsEnv, nullptr); + auto result = etsEnv->PostFork(); + EXPECT_FALSE(result); +} + +/** + * @tc.name: PreloadSystemClass_0100 + * @tc.desc: Sts environment PreloadSystemClass. + * @tc.type: FUNC + */ +HWTEST_F(EtsEnvironmentTest, PreloadSystemClass_0100, TestSize.Level0) +{ + auto etsEnv = std::make_shared(); + ASSERT_NE(etsEnv, nullptr); + auto result = etsEnv->FinishPreload(); + EXPECT_FALSE(result); +} + +/** + * @tc.name: RegisterFuncs_0100 + * @tc.desc: Sts environment RegisterFuncs. + * @tc.type: FUNC + */ +HWTEST_F(EtsEnvironmentTest, RegisterFuncs_0100, TestSize.Level0) +{ + auto envFuncs = RegisterFuncs(); + ASSERT_NE(envFuncs, nullptr); +} } // namespace StsEnv } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/runtime_test/ets_runtime_test.cpp b/test/unittest/runtime_test/ets_runtime_test.cpp index dd55ffecb215a9eba4fa12b083a7fc8cbb4f23cd..870062c20f14fb278c04da67b2dbdc3e59a0b01d 100644 --- a/test/unittest/runtime_test/ets_runtime_test.cpp +++ b/test/unittest/runtime_test/ets_runtime_test.cpp @@ -253,5 +253,76 @@ HWTEST_F(EtsRuntimeTest, GetLanguage_100, TestSize.Level1) auto language = etsRuntime->GetLanguage(); EXPECT_EQ(language, Runtime::Language::ETS); } + +/** + * @tc.name: FinishPreload_100 + * @tc.desc: EtsRuntime test for FinishPreload. + * @tc.type: FUNC + */ +HWTEST_F(EtsRuntimeTest, FinishPreload_100, TestSize.Level1) +{ + std::unique_ptr etsRuntime = std::make_unique(); + EXPECT_EQ(RegisterETSEnvFuncs(), true); + etsRuntime->FinishPreload(); + EXPECT_NE(etsRuntime->g_etsEnvFuncs->FinishPreload, nullptr); +} + +/** + * @tc.name: PreloadModule_100 + * @tc.desc: EtsRuntime test for PreloadModule. + * @tc.type: FUNC + */ +HWTEST_F(EtsRuntimeTest, PreloadModule_100, TestSize.Level1) +{ + std::unique_ptr etsRuntime = std::make_unique(); + EXPECT_EQ(RegisterETSEnvFuncs(), true); + std::string moduleName = TEST_MODULE_NAME; + std::string hapPath = ""; + bool isEsMode = true; + bool useCommonTrunk = false; + etsRuntime->PreloadModule(moduleName, hapPath, isEsMode, useCommonTrunk); + EXPECT_NE(etsRuntime->g_etsEnvFuncs->PreloadModule, nullptr); +} + +/** + * @tc.name: HandleUncaughtError_100 + * @tc.desc: EtsRuntime test for HandleUncaughtError. + * @tc.type: FUNC + */ +HWTEST_F(EtsRuntimeTest, HandleUncaughtError_100, TestSize.Level1) +{ + std::unique_ptr etsRuntime = std::make_unique(); + EXPECT_EQ(RegisterETSEnvFuncs(), true); + etsRuntime->HandleUncaughtError(); + EXPECT_NE(etsRuntime->g_etsEnvFuncs->HandleUncaughtError, nullptr); +} + +/** + * @tc.name: PreloadSystemModule_100 + * @tc.desc: EtsRuntime test for PreloadSystemModule. + * @tc.type: FUNC + */ +HWTEST_F(EtsRuntimeTest, PreloadSystemModule_100, TestSize.Level1) +{ + std::unique_ptr etsRuntime = std::make_unique(); + EXPECT_EQ(RegisterETSEnvFuncs(), true); + std::string moduleName = TEST_MODULE_NAME; + etsRuntime->PreloadSystemModule(moduleName); + EXPECT_EQ(etsRuntime->jsRuntime_, nullptr); +} + +/** + * @tc.name: PreloadSystemClass_100 + * @tc.desc: EtsRuntime test for PreloadSystemClass. + * @tc.type: FUNC + */ +HWTEST_F(EtsRuntimeTest, PreloadSystemClass_100, TestSize.Level1) +{ + std::unique_ptr etsRuntime = std::make_unique(); + EXPECT_EQ(RegisterETSEnvFuncs(), true); + std::string className = ""; + etsRuntime->PreloadSystemClass(className); + EXPECT_NE(etsRuntime->g_etsEnvFuncs->PreloadSystemClass, nullptr); +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file