diff --git a/standard/BUILD.gn b/standard/BUILD.gn index 779676dc5a73a6876ea528c2268bc181d750252c..f04763ddff415df47065d4578ef38d6d9afd488a 100644 --- a/standard/BUILD.gn +++ b/standard/BUILD.gn @@ -49,7 +49,6 @@ ohos_executable("appspawn") { "${appspawn_path}/standard/appspawn_main.c", "${appspawn_path}/standard/appspawn_msgmgr.c", "${appspawn_path}/standard/appspawn_service.c", - "${appspawn_path}/standard/nwebspawn_launcher.c", ] defines = [] @@ -169,7 +168,6 @@ ohos_executable("cjappspawn") { "${appspawn_path}/standard/appspawn_main.c", "${appspawn_path}/standard/appspawn_msgmgr.c", "${appspawn_path}/standard/appspawn_service.c", - "${appspawn_path}/standard/nwebspawn_launcher.c", ] defines = [ "CJAPP_SPAWN" ] @@ -237,7 +235,6 @@ ohos_executable("nativespawn") { "${appspawn_path}/standard/appspawn_main.c", "${appspawn_path}/standard/appspawn_msgmgr.c", "${appspawn_path}/standard/appspawn_service.c", - "${appspawn_path}/standard/nwebspawn_launcher.c", ] defines = [ "NATIVE_SPAWN" ] @@ -320,7 +317,6 @@ ohos_executable("nwebspawn") { "${appspawn_path}/standard/appspawn_main.c", "${appspawn_path}/standard/appspawn_msgmgr.c", "${appspawn_path}/standard/appspawn_service.c", - "${appspawn_path}/standard/nwebspawn_launcher.c", ] defines = ["NWEB_SPAWN"] diff --git a/standard/appspawn_service.h b/standard/appspawn_service.h index 5bc324e7a47db1309a6ba19c4a5fcfe59b8b9af6..92dbbe135e3ede4ab01996d32d785eb6bb56e201 100644 --- a/standard/appspawn_service.h +++ b/standard/appspawn_service.h @@ -75,8 +75,6 @@ typedef struct { AppSpawnStartArg arg; } AppSpawnStartArgTemplate; -pid_t NWebSpawnLaunch(void); -void NWebSpawnInit(void); AppSpawnContent *StartSpawnService(const AppSpawnStartArg *arg, uint32_t argvSize, int argc, char *const argv[]); void AppSpawnDestroyContent(AppSpawnContent *content); diff --git a/standard/nwebspawn_launcher.c b/standard/nwebspawn_launcher.c deleted file mode 100644 index 58c337c88098f2cb92c4513cac33952b94c92ad1..0000000000000000000000000000000000000000 --- a/standard/nwebspawn_launcher.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "appspawn.h" -#include "appspawn_modulemgr.h" -#include "appspawn_msg.h" -#include "appspawn_server.h" -#include "appspawn_service.h" -#include "appspawn_utils.h" -#include "parameter.h" -#include "securec.h" - -#ifdef CODE_SIGNATURE_ENABLE -#include "code_sign_attr_utils.h" -#endif -#ifdef WITH_SELINUX -#include "selinux/selinux.h" -#endif - -#define NWEB_UID 3081 -#define NWEB_GID 3081 -#define NWEB_NAME "nwebspawn" -#define NATIVE_NAME "nativespawn" -#define CAP_NUM 2 -#define BITLEN32 32 - -void NWebSpawnInit(void) -{ - APPSPAWN_LOGI("NWebSpawnInit"); -#ifdef CODE_SIGNATURE_ENABLE - // ownerId must been set before setcon & setuid - (void)SetXpmOwnerId(PROCESS_OWNERID_NWEB, NULL); -#endif -#ifdef WITH_SELINUX - setcon("u:r:nwebspawn:s0"); -#endif - pid_t pid = getpid(); - setpriority(PRIO_PROCESS, pid, 0); - struct __user_cap_header_struct capHeader; - capHeader.version = _LINUX_CAPABILITY_VERSION_3; - capHeader.pid = 0; - // old CAP_SYS_ADMIN | CAP_SETGID | CAP_SETUID - const uint64_t inheriTable = CAP_TO_MASK(CAP_SYS_ADMIN) | CAP_TO_MASK(CAP_SETGID) | - CAP_TO_MASK(CAP_SETUID) | CAP_TO_MASK(CAP_KILL); - const uint64_t permitted = inheriTable; - const uint64_t effective = inheriTable; - struct __user_cap_data_struct capData[CAP_NUM] = {}; - for (int j = 0; j < CAP_NUM; ++j) { - capData[0].inheritable = (__u32)(inheriTable); - capData[1].inheritable = (__u32)(inheriTable >> BITLEN32); - capData[0].permitted = (__u32)(permitted); - capData[1].permitted = (__u32)(permitted >> BITLEN32); - capData[0].effective = (__u32)(effective); - capData[1].effective = (__u32)(effective >> BITLEN32); - } - capset(&capHeader, capData); - for (int i = 0; i <= CAP_LAST_CAP; ++i) { - prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, i, 0, 0); - } -#ifndef APPSPAWN_TEST - (void)prctl(PR_SET_NAME, NWEB_NAME); -#endif - setuid(NWEB_UID); - setgid(NWEB_GID); -} - -pid_t NWebSpawnLaunch(void) -{ - enum fdsan_error_level errorLevel = fdsan_get_error_level(); - pid_t ret = fork(); - if (ret == 0) { - // Inherit the error level of the original process - (void)fdsan_set_error_level(errorLevel); - NWebSpawnInit(); - } - APPSPAWN_LOGI("nwebspawn fork success pid: %{public}d", ret); - return ret; -} \ No newline at end of file diff --git a/test/BUILD.gn b/test/BUILD.gn index faf729d9c56f1840fdcbd2fe15711d336a872169..6444a25e7c192e0ad512f29b3a37019eeb025bcb 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -32,6 +32,7 @@ group("unittest") { } deps += [ "unittest/hnp_test:HnpTest" ] deps += [ "unittest/devicedebug_test:DevicedebugTest" ] + deps += [ "unittest/app_spawn_hisysevent_test:AppSpawn_HisysEvent_ut" ] } else { testonly = true deps = [ "unittest/app_spawn_lite_test:unittest" ] diff --git a/test/unittest/app_spawn_client_test/BUILD.gn b/test/unittest/app_spawn_client_test/BUILD.gn index 136553b5883c70d9cc27338ebb161da15993308e..4f14ddb2858843c3fd73a1b6831d96a05353f2f8 100644 --- a/test/unittest/app_spawn_client_test/BUILD.gn +++ b/test/unittest/app_spawn_client_test/BUILD.gn @@ -66,7 +66,6 @@ ohos_unittest("AppSpawn_client_ut") { "${appspawn_path}/standard/appspawn_appmgr.c", "${appspawn_path}/standard/appspawn_msgmgr.c", "${appspawn_path}/standard/appspawn_service.c", - "${appspawn_path}/standard/nwebspawn_launcher.c", "${appspawn_path}/util/src/appspawn_utils.c", ] diff --git a/test/unittest/app_spawn_client_test/app_spawn_interface_test.cpp b/test/unittest/app_spawn_client_test/app_spawn_interface_test.cpp index 60386f6b8cb7f8c2f7657dfb2ee375431d333c25..005db33db56ffdc94d118f2a1dfc404c3891373d 100644 --- a/test/unittest/app_spawn_client_test/app_spawn_interface_test.cpp +++ b/test/unittest/app_spawn_client_test/app_spawn_interface_test.cpp @@ -603,12 +603,6 @@ HWTEST_F(AppSpawnInterfaceTest, App_Spawn_Interface_GetSpawnTimeout_001, TestSiz EXPECT_EQ(timeout >= 2, 1); // 2 test } -HWTEST_F(AppSpawnInterfaceTest, App_Spawn_Interface_NWeb, TestSize.Level0) -{ - pid_t pid = NWebSpawnLaunch(); - EXPECT_GE(pid, 0); -} - /** * @brief 测试接口:SpawnListenFdSet * diff --git a/test/unittest/app_spawn_hisysevent_test/BUILD.gn b/test/unittest/app_spawn_hisysevent_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e3ef281fd1f16da8d6159e0399cedd0daa238b59 --- /dev/null +++ b/test/unittest/app_spawn_hisysevent_test/BUILD.gn @@ -0,0 +1,47 @@ +# 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("//base/startup/appspawn/appspawn.gni") +import("//build/test.gni") + +ohos_unittest("AppSpawn_HisysEvent_ut") { + module_out_path = "appspawn/appspawn" + deps = [] + if (appspawn_unittest_coverage) { + cflags = [ "--coverage" ] + ldflags = [ "--coverage" ] + cflags_cc = [ "--coverage" ] + } + defines = [ + "APPSPAWN_TEST", + ] + + include_dirs = [ + "${appspawn_path}/modules/sysevent", + "${appspawn_path}/util/include", + "${appspawn_path}/test/unittest/app_spawn_hisysevent_test", + ] + + sources = [ + "${appspawn_path}/modules/sysevent/hisysevent_adapter.cpp", + "${appspawn_path}/test/unittest/app_spawn_hisysevent_test/app_spawn_hisysevent_test.cpp", + "${appspawn_path}/test/unittest/app_spawn_hisysevent_test/app_spawn_hisysevent_stub.c", + ] + + external_deps = [ + "hisysevent:libhisysevent", + "hilog:libhilog", + "init:libbegetutil", + "c_utils:utils", + ] +} \ No newline at end of file diff --git a/test/unittest/app_spawn_hisysevent_test/app_spawn_hisysevent_stub.c b/test/unittest/app_spawn_hisysevent_test/app_spawn_hisysevent_stub.c new file mode 100644 index 0000000000000000000000000000000000000000..f3716f0ee0a167bcbce129d6cb7a93625b554c1c --- /dev/null +++ b/test/unittest/app_spawn_hisysevent_test/app_spawn_hisysevent_stub.c @@ -0,0 +1,41 @@ +/* + * 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 "app_spawn_hisysevent_stub.h" +#include "appspawn_utils.h" + +#ifdef __cplusplus +extern "C" { +#endif + +bool g_CreateTimerStatus = true; + +void SetCreateTimerStatus(bool status) +{ + if (status) { + g_CreateTimerStatus = true; + } else { + g_CreateTimerStatus = false; + } +} + +int CreateHisysTimerLoop(AppSpawnHisyseventInfo *hisyseventInfo) +{ + return 0; +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/test/unittest/app_spawn_hisysevent_test/app_spawn_hisysevent_stub.h b/test/unittest/app_spawn_hisysevent_test/app_spawn_hisysevent_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..b0c2606bc72484160586dd036ef73509d9137767 --- /dev/null +++ b/test/unittest/app_spawn_hisysevent_test/app_spawn_hisysevent_stub.h @@ -0,0 +1,32 @@ +/* + * 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 APP_SPAWN_HISYSEVENT_STUB_H +#define APP_SPAWN_HISYSEVENT_STUB_H + +#include "hisysevent_adapter.h" +#include "hisysevent.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void SetCreateTimerStatus(bool status); +int CreateHisysTimerLoop(AppSpawnHisyseventInfo *hisyseventInfo); + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/test/unittest/app_spawn_hisysevent_test/app_spawn_hisysevent_test.cpp b/test/unittest/app_spawn_hisysevent_test/app_spawn_hisysevent_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..abba0b6a4b804246a7cb34459efb640a5743ba93 --- /dev/null +++ b/test/unittest/app_spawn_hisysevent_test/app_spawn_hisysevent_test.cpp @@ -0,0 +1,156 @@ +/* + * 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 "app_spawn_hisysevent_stub.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +class AppSpawnHisysEventTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void AppSpawnHisysEventTest::SetUpTestCase() +{ + GTEST_LOG_(INFO) << "AppSpawn_HisysEvent_TEST SetUpTestCase"; +} + +void AppSpawnHisysEventTest::TearDownTestCase() +{ + GTEST_LOG_(INFO) << "AppSpawn_HisysEvent_TEST TearDownTestCase"; +} + +void AppSpawnHisysEventTest::SetUp() +{ + GTEST_LOG_(INFO) << "AppSpawn_HisysEvent_TEST SetUp"; +} + +void AppSpawnHisysEventTest::TearDown() +{ + GTEST_LOG_(INFO) << "AppSpawn_HisysEvent_TEST TearDown"; +} + +/** +* @tc.name: AppSpawnHisysEvent_001 +* @tc.desc: Verify InitHisyseventTimer success. +* @tc.type: FUNC +*/ +HWTEST_F(AppSpawnHisysEventTest, AppSpawnHisysEvent_001, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "AppSpawnHisysEvent_001 test...."; + SetCreateTimerStatus(true); + AppSpawnHisyseventInfo * hisyseventInfo = InitHisyseventTimer(); + EXPECT_NE(hisyseventInfo, NULL); + DeleteHisyseventInfo(hisyseventInfo); + hisyseventInfo = NULL; +} + +/** +* @tc.name: AppSpawnHisysEvent_002 +* @tc.desc: Verify InitHisyseventTimer fail. +* @tc.type: FUNC +*/ +HWTEST_F(AppSpawnHisysEventTest, AppSpawnHisysEvent_002, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "AppSpawnHisysEvent_002 test...."; + SetCreateTimerStatus(false); + AppSpawnHisyseventInfo * hisyseventInfo = InitHisyseventTimer(); + EXPECT_NE(hisyseventInfo, NULL); + DeleteHisyseventInfo(hisyseventInfo); + hisyseventInfo = NULL; +} + +/** +* @tc.name: AppSpawnHisysEvent_003 +* @tc.desc: Verify Add bootevent count success. +* @tc.type: FUNC +*/ +HWTEST_F(AppSpawnHisysEventTest, AppSpawnHisysEvent_003, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "AppSpawnHisysEvent_003 test...."; + SetCreateTimerStatus(true); + AppSpawnHisyseventInfo * hisyseventInfo = InitHisyseventTimer(); + EXPECT_NE(hisyseventInfo, NULL); + AddStatisticEventInfo(hisyseventInfo, 20, true); + int count = hisyseventInfo->bootEvent.eventCount; + EXPECT_EQ(count, 1); + DeleteHisyseventInfo(hisyseventInfo); + hisyseventInfo = NULL; +} + +/** +* @tc.name: AppSpawnHisysEvent_004 +* @tc.desc: Verify Add bootevent duration success. +* @tc.type: FUNC +*/ +HWTEST_F(AppSpawnHisysEventTest, AppSpawnHisysEvent_004, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "AppSpawnHisysEvent_004 test...."; + SetCreateTimerStatus(true); + AppSpawnHisyseventInfo * hisyseventInfo = InitHisyseventTimer(); + EXPECT_NE(hisyseventInfo, NULL); + AddStatisticEventInfo(hisyseventInfo, 20, true); + int duration = hisyseventInfo->bootEvent.totalDuration; + EXPECT_EQ(duration, 20); + DeleteHisyseventInfo(hisyseventInfo); + hisyseventInfo = NULL; +} + +/** +* @tc.name: AppSpawnHisysEvent_005 +* @tc.desc: Verify Add manualevent duration success. +* @tc.type: FUNC +*/ +HWTEST_F(AppSpawnHisysEventTest, AppSpawnHisysEvent_005, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "AppSpawnHisysEvent_005 test...."; + SetCreateTimerStatus(true); + AppSpawnHisyseventInfo * hisyseventInfo = InitHisyseventTimer(); + EXPECT_NE(hisyseventInfo, NULL); + AddStatisticEventInfo(hisyseventInfo, 20, false); + int duration = hisyseventInfo->manualEvent.totalDuration; + EXPECT_EQ(duration, 20); + DeleteHisyseventInfo(hisyseventInfo); + hisyseventInfo = NULL; +} + +/** +* @tc.name: AppSpawnHisysEvent_006 +* @tc.desc: Verify manualevent maxduration and minduration success. +* @tc.type: FUNC +*/ +HWTEST_F(AppSpawnHisysEventTest, AppSpawnHisysEvent_006, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "AppSpawnHisysEvent_006 test...."; + SetCreateTimerStatus(true); + AppSpawnHisyseventInfo * hisyseventInfo = InitHisyseventTimer(); + EXPECT_NE(hisyseventInfo, NULL); + AddStatisticEventInfo(hisyseventInfo, 10, true); + AddStatisticEventInfo(hisyseventInfo, 20, true); + AddStatisticEventInfo(hisyseventInfo, 30, true); + int maxduration = hisyseventInfo->bootEvent.maxDuration; + int minduration = hisyseventInfo->bootEvent.minDuration; + EXPECT_EQ(maxduration, 30); + EXPECT_EQ(minduration, 10); + DeleteHisyseventInfo(hisyseventInfo); + hisyseventInfo = NULL; +} +} // namespace OHOS diff --git a/test/unittest/app_spawn_standard_test/BUILD.gn b/test/unittest/app_spawn_standard_test/BUILD.gn index 15a882f557c5fe69357c92810960bc5c6f254180..e34b42e50f914ced8e8edf2e7a9a34526ca09fd1 100644 --- a/test/unittest/app_spawn_standard_test/BUILD.gn +++ b/test/unittest/app_spawn_standard_test/BUILD.gn @@ -81,7 +81,6 @@ ohos_unittest("AppSpawn_ut") { "${appspawn_path}/standard/appspawn_kickdog.c", "${appspawn_path}/standard/appspawn_msgmgr.c", "${appspawn_path}/standard/appspawn_service.c", - "${appspawn_path}/standard/nwebspawn_launcher.c", "${appspawn_path}/util/src/appspawn_utils.c", ] @@ -289,7 +288,6 @@ ohos_unittest("AppSpawn_coldrun_ut") { "${appspawn_path}/standard/appspawn_kickdog.c", "${appspawn_path}/standard/appspawn_msgmgr.c", "${appspawn_path}/standard/appspawn_service.c", - "${appspawn_path}/standard/nwebspawn_launcher.c", "${appspawn_path}/util/src/appspawn_utils.c", ] @@ -480,7 +478,6 @@ ohos_unittest("AppSpawn_common_ut") { "${appspawn_path}/standard/appspawn_kickdog.c", "${appspawn_path}/standard/appspawn_msgmgr.c", "${appspawn_path}/standard/appspawn_service.c", - "${appspawn_path}/standard/nwebspawn_launcher.c", "${appspawn_path}/util/src/appspawn_utils.c", ]