From d184fad36f41210310b457a2195e77685ca02639 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Tue, 26 Aug 2025 21:30:38 +0800 Subject: [PATCH] fix appspawn diff Signed-off-by: nianyuu --- appspawn.cfg | 6 +- interfaces/innerkits/client/appspawn_msg.c | 9 +- modules/common/appspawn_begetctl.c | 2 +- modules/common/appspawn_cgroup.c | 2 +- modules/sandbox/modern/sandbox_debug_mode.c | 4 +- modules/sandbox/normal/sandbox_common.cpp | 5 +- modules/sandbox/normal/sandbox_core.cpp | 2 +- standard/appspawn_service.c | 7 +- test/BUILD.gn | 1 + ...sub_startup_appspawn_atomservice_0100.json | 14 --- .../sub_startup_appspawn_atomservice_0100.py | 104 ------------------ ...sub_startup_appspawn_atomservice_0300.json | 14 --- .../sub_startup_appspawn_atomservice_0300.py | 66 ----------- test/unittest/app_spawn_client_test/BUILD.gn | 1 - .../unittest/app_spawn_standard_test/BUILD.gn | 102 ++++++++++++++++- .../app_spawn_appmgr_test.cpp | 8 -- .../app_spawn_common_test.cpp | 3 +- .../app_spawn_kickdog_test.cpp | 2 +- .../app_spawn_sandbox_new_debug_mode.cpp | 4 +- util/include/appspawn_error.h | 6 +- 20 files changed, 128 insertions(+), 234 deletions(-) delete mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.json delete mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.py delete mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.json delete mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.py diff --git a/appspawn.cfg b/appspawn.cfg index 989ab65f..9759e7e8 100644 --- a/appspawn.cfg +++ b/appspawn.cfg @@ -17,9 +17,9 @@ "chown root appspawn /dev/pids", "chown root appspawn /dev/pids/tasks", "chown root appspawn /dev/pids/cgroup.procs", - "chmod 0750 /dev/pids", - "chmod 0750 /dev/pids/tasks", - "chmod 0750 /dev/pids/cgroup.procs" + "chmod 0755 /dev/pids", + "chmod 0755 /dev/pids/tasks", + "chmod 0755 /dev/pids/cgroup.procs" ] } ], diff --git a/interfaces/innerkits/client/appspawn_msg.c b/interfaces/innerkits/client/appspawn_msg.c index ab871cb7..3b7332af 100644 --- a/interfaces/innerkits/client/appspawn_msg.c +++ b/interfaces/innerkits/client/appspawn_msg.c @@ -19,7 +19,7 @@ #include "appspawn_utils.h" #include "parameter.h" #include "securec.h" - +#define OHOS_PERMISSION_FOWNER "ohos.permission.FOWNER" static inline int CalcFlagsUnits(uint32_t maxIndex) { return ((maxIndex / 32) + ((maxIndex % 32 == 0) ? 0 : 1)); // 32 max bit in uint32_t @@ -552,10 +552,17 @@ int AppSpawnClientAddPermission(AppSpawnClientHandle handle, AppSpawnReqMsgHandl APPSPAWN_CHECK(permission != NULL, return APPSPAWN_ARG_INVALID, "Invalid permission "); APPSPAWN_CHECK(reqNode->permissionFlags != NULL, return APPSPAWN_ARG_INVALID, "No permission tlv "); + if (strcmp(permission, OHOS_PERMISSION_FOWNER) == 0) { + APPSPAWN_LOGI("AppSpawnClientAddPermission %{public}s", permission); + return AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_SET_CAPS_FOWNER); + } + +#ifdef APPSPAWN_SANDBOX_NEW // Don't need to transmit sandbox permission in nwebspawn mode if (reqMgr->type == CLIENT_FOR_NWEBSPAWN) { return 0; } +#endif int32_t maxIndex = GetMaxPermissionIndex(handle); int index = GetPermissionIndex(handle, permission); diff --git a/modules/common/appspawn_begetctl.c b/modules/common/appspawn_begetctl.c index c813e839..3696bb8f 100755 --- a/modules/common/appspawn_begetctl.c +++ b/modules/common/appspawn_begetctl.c @@ -48,7 +48,7 @@ APPSPAWN_STATIC void RunAppSandbox(const char *ptyName) } APPSPAWN_CHECK(realPath != NULL, _exit(1), "Failed get realpath, err=%{public}d", errno); int n = strncmp(realPath, "/dev/pts/", strlen("/dev/pts/")); - APPSPAWN_CHECK(n == 0, free(realPath); _exit(1), "pts path %{public}s is invaild", realPath); + APPSPAWN_CHECK(n == 0, free(realPath); _exit(1), "pts path %{public}s is invalid", realPath); int fd = open(realPath, O_RDWR); free(realPath); APPSPAWN_CHECK(fd >= 0, _exit(1), "Failed open %{public}s, err=%{public}d", ptyName, errno); diff --git a/modules/common/appspawn_cgroup.c b/modules/common/appspawn_cgroup.c index eaf73279..4f6043a6 100644 --- a/modules/common/appspawn_cgroup.c +++ b/modules/common/appspawn_cgroup.c @@ -151,7 +151,7 @@ APPSPAWN_STATIC int ProcessMgrAddApp(const AppSpawnMgr *content, const AppSpawne APPSPAWN_LOGV("ProcessMgrAddApp %{public}d %{public}d to cgroup ", appInfo->pid, appInfo->uid); int ret = GetCgroupPath(appInfo, path, sizeof(path)); APPSPAWN_CHECK(ret == 0, return -1, "Failed to get real path errno: %{public}d", errno); - (void)CreateSandboxDir(path, 0750); // 0750 default mode + (void)CreateSandboxDir(path, 0755); // 0755 default mode ret = strcat_s(path, sizeof(path), "cgroup.procs"); APPSPAWN_CHECK(ret == 0, return ret, "Failed to strcat_s errno: %{public}d", errno); ret = WriteToFile(path, 0, (pid_t *)&appInfo->pid, 1); diff --git a/modules/sandbox/modern/sandbox_debug_mode.c b/modules/sandbox/modern/sandbox_debug_mode.c index 7953b34a..54b9b945 100644 --- a/modules/sandbox/modern/sandbox_debug_mode.c +++ b/modules/sandbox/modern/sandbox_debug_mode.c @@ -384,7 +384,7 @@ static int MountDebugDirBySharefs(const SandboxContext *context, const AppSpawnS return 0; } -static int InstallDebugSandbox(AppSpawnMgr *content, AppSpawningCtx *property) +APPSPAWN_STATIC int InstallDebugSandbox(AppSpawnMgr *content, AppSpawningCtx *property) { APPSPAWN_CHECK(property != NULL && content != NULL, return APPSPAWN_ARG_INVALID, "Invalid appspawn client or property"); @@ -410,6 +410,8 @@ static int InstallDebugSandbox(AppSpawnMgr *content, AppSpawningCtx *property) APPSPAWN_CHECK_ONLY_EXPER(ret == 0, DeleteSandboxContext(&context); return ret); + APPSPAWN_LOGI("Set sandbox config %{public}s sandboxNsFlags 0x%{public}x", + context->rootPath, context->sandboxNsFlags); do { ret = MountDebugTmpConfig(context, sandboxCfg); APPSPAWN_CHECK_ONLY_EXPER(ret == 0, break); diff --git a/modules/sandbox/normal/sandbox_common.cpp b/modules/sandbox/normal/sandbox_common.cpp index df0cedf3..0503c71a 100644 --- a/modules/sandbox/normal/sandbox_common.cpp +++ b/modules/sandbox/normal/sandbox_common.cpp @@ -905,9 +905,8 @@ std::string SandboxCommon::ConvertToRealPathWithPermission(const AppSpawningCtx AppSpawnMsgBundleInfo *info = reinterpret_cast(GetAppProperty(appProperty, TLV_BUNDLE_INFO)); AppSpawnMsgDacInfo *dacInfo = reinterpret_cast(GetAppProperty(appProperty, TLV_DAC_INFO)); - if (info == nullptr || dacInfo == nullptr) { - return ""; - } + APPSPAWN_CHECK((info != nullptr && dacInfo != nullptr), return "", "Invalid params"); + if (path.find(SandboxCommonDef::g_packageNameIndex) != std::string::npos) { std::string bundleNameWithIndex = info->bundleName; if (info->bundleIndex != 0) { diff --git a/modules/sandbox/normal/sandbox_core.cpp b/modules/sandbox/normal/sandbox_core.cpp index 076abf38..ea47460d 100644 --- a/modules/sandbox/normal/sandbox_core.cpp +++ b/modules/sandbox/normal/sandbox_core.cpp @@ -1032,7 +1032,7 @@ int32_t SandboxCore::SetAppSandboxPropertyNweb(AppSpawningCtx *appProperty, uint } APPSPAWN_CHECK(rc == 0, return rc, "DoSandboxRootFolderCreate failed, %{public}s", bundleName.c_str()); - // rendering process can be created by different apps, and the bundle names of these apps are different + // rendering process can be created by different apps, and the bundle names of these apps are different, // so we can't use the method SetPrivateAppSandboxProperty which mount dirs by using bundle name. rc = SetRenderSandboxPropertyNweb(appProperty, sandboxPackagePath); APPSPAWN_CHECK(rc == 0, return rc, "SetRenderSandboxPropertyNweb for %{public}s failed", bundleName.c_str()); diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 274fe9a5..51eeec66 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -446,8 +446,7 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer, connection->receiverCtx.incompleteMsg = NULL; int ret = 0; do { - APPSPAWN_LOGI("connectionId:%{public}u buffLen:%{public}d", - connection->connectionId, buffLen - currLen); + APPSPAWN_LOGI("connectionId:%{public}u buffLen:%{public}d", connection->connectionId, buffLen - currLen); ret = GetAppSpawnMsgFromBuffer(buffer + currLen, buffLen - currLen, &message, &connection->receiverCtx.msgRecvLen, &reminder); @@ -1611,7 +1610,7 @@ APPSPAWN_STATIC int AppspawpnDevicedebugKill(int pid, cJSON *args) "appspawn devicedebug process is not debuggable, pid=%{public}d", pid); APPSPAWN_LOGI("appspawn devicedebug debugable=%{public}d, pid=%{public}d, signal=%{public}d", - appInfo->isDebuggable, pid, (int)signal->valueint); + appInfo->isDebuggable, pid, signal->valueint); if (kill(pid, signal->valueint) != 0) { APPSPAWN_LOGE("appspawn devicedebug unable to kill process, pid: %{public}d ret %{public}d", pid, errno); @@ -1626,7 +1625,7 @@ APPSPAWN_STATIC int AppspawnDevicedebugDeal(const char* op, int pid, cJSON *args if (strcmp(op, "kill") == 0) { return AppspawpnDevicedebugKill(pid, args); } - APPSPAWN_LOGE("appspawn devicedebug op:%{public}s invaild", op); + APPSPAWN_LOGE("appspawn devicedebug op:%{public}s invalid", op); return -1; } diff --git a/test/BUILD.gn b/test/BUILD.gn index 7e399ae1..22e12e97 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -29,6 +29,7 @@ group("unittest") { deps += [ "unittest/app_spawn_standard_test:AppSpawn_ut" ] deps += [ "unittest/app_spawn_standard_test:AppSpawn_common_ut" ] deps += [ "unittest/app_spawn_standard_test:AppSpawn_coldrun_ut" ] + deps += [ "unittest/app_spawn_standard_test:AppSpawnDebugSandbox" ] } deps += [ "unittest/hnp_test:HnpTest" ] deps += [ "unittest/single_test/hnp_installer:hnp_installer_test" ] diff --git a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.json b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.json deleted file mode 100644 index a69713ef..00000000 --- a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.py b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.py deleted file mode 100644 index 8ed54e46..00000000 --- a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# 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 time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from aw import Common - - -class SubStartupAppspawnAtomservice0100(TestCase): - def __init__(self, controllers): - self.tag = self.__class__.__name__ - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step(self.devices[0].device_id) - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - Step(device) - # 解锁屏幕 - wake = self.driver.Screen.is_on() - time.sleep(0.5) - if wake: - self.driver.ScreenLock.unlock() - else: - self.driver.Screen.wake_up() - self.driver.ScreenLock.unlock() - self.driver.Screen.enable_stay_awake() - - def process(self): - hap_info01, hap_info02 = [], [] - bundle_name = "com.atomicservice.5765880207854649689" - bundle_name_start = "+auid-ohosAnonymousUid+com.atomicservice.5765880207854649689" - hap_path = Common.sourcepath('atomicservice.hap', "sub_startup_appspawn_atomservice") - hap = self.driver.AppManager.has_app(bundle_name) - if hap: - self.driver.AppManager.clear_app_data(bundle_name) - self.driver.AppManager.uninstall_app(bundle_name) - self.driver.AppManager.install_app(hap_path) - else: - self.driver.AppManager.install_app(hap_path) - - for path in ["base", "database"]: - for i in range(1, 5): - has_dir = self.driver.Storage.has_dir("/data/app/el%d/100/%s/%s" % (i, path, bundle_name)) - has_dir_login = self.driver.Storage.has_dir("/data/app/el%d/100/%s/%s" % (i, path, bundle_name_start)) - self.driver.Assert.equal(has_dir, True) - self.driver.Assert.equal(has_dir_login, False) - - log_has_dir = self.driver.Storage.has_dir("/data/app/el2/100/log/%s" % bundle_name) - log_has_dir_login = self.driver.Storage.has_dir("/data/app/el2/100/log/%s" % bundle_name_start) - self.driver.Assert.equal(log_has_dir, True) - self.driver.Assert.equal(log_has_dir_login, False) - - mnt_has_dir = self.driver.Storage.has_dir("/mnt/share/100/%s" % bundle_name) - mnt_has_dir_login = self.driver.Storage.has_dir("/mnt/share/100/%s" % bundle_name_start) - self.driver.Assert.equal(mnt_has_dir, True) - self.driver.Assert.equal(mnt_has_dir_login, False) - - self.driver.shell("aa start -a EntryAbility -b %s" % bundle_name) - for path in ["base", "database"]: - for i in range(1, 5): - has_dir_login = self.driver.Storage.has_dir("/data/app/el%d/100/%s/%s" % (i, path, bundle_name_start)) - self.driver.Assert.equal(has_dir_login, True) - - mnt_has_dir_login = self.driver.Storage.has_dir("/mnt/share/100/%s" % bundle_name_start) - self.driver.Assert.equal(mnt_has_dir_login, True) - - for i in range(1, 5): - hap_detail = self.driver.shell("ls -lZ ../data/app/el%d/100/%s" % (i, "base")).split("\n") - for hap in hap_detail[1:-2]: - if hap.split()[-1] == bundle_name: - hap_info01 = hap - if hap.split()[-1] == bundle_name_start: - hap_info02 = hap - for index in range(2, 5): - self.driver.Assert.equal(hap_info01.split()[index], hap_info02.split()[index]) - - hap_detail = self.driver.shell("ls -lZ ../mnt/share/100").split("\n") - for hap in hap_detail[1:-2]: - if hap.split()[-1] == bundle_name: - hap_info01 = hap - if hap.split()[-1] == bundle_name_start: - hap_info02 = hap - for index in range(2, 5): - self.driver.Assert.equal(hap_info01.split()[index], hap_info02.split()[index]) - - def teardown(self): - Step("收尾工作.................") - self.driver.AppManager.uninstall_app("com.atomicservice.5765880207854649689") diff --git a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.json b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.json deleted file mode 100644 index c5a1372f..00000000 --- a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.py b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.py deleted file mode 100644 index 9001688a..00000000 --- a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# 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 time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from aw import Common - - -class SubStartupAppspawnAtomservice0300(TestCase): - def __init__(self, controllers): - self.tag = self.__class__.__name__ - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step(self.devices[0].device_id) - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - Step(device) - # 解锁屏幕 - wake = self.driver.Screen.is_on() - time.sleep(0.5) - if wake: - self.driver.ScreenLock.unlock() - else: - self.driver.Screen.wake_up() - self.driver.ScreenLock.unlock() - self.driver.Screen.enable_stay_awake() - - def process(self): - bundle_name = "com.atomicservice.5765880207854649689" - bundle_name_start = "+auid-ohosAnonymousUid+com.atomicservice.5765880207854649689" - hap_path = Common.sourcepath('atomicservice.hap', "sub_startup_appspawn_atomservice") - hap = self.driver.AppManager.has_app(bundle_name) - if hap: - self.driver.AppManager.clear_app_data(bundle_name) - self.driver.AppManager.uninstall_app(bundle_name) - self.driver.AppManager.install_app(hap_path) - else: - self.driver.AppManager.install_app(hap_path) - self.driver.shell("aa start -a EntryAbility -b %s" % bundle_name) - pid = self.driver.System.get_pid(bundle_name) - - for path in ["base", "database"]: - for i in range(1, 5): - result1 = self.driver.shell("ls ../proc/%d/root/data/storage/el%d/%s" % (pid, i, path)) - result2 = self.driver.shell("ls ../data/app/el%d/100/%s/%s" % (i, path, bundle_name_start)) - self.driver.Assert.equal(result1, result2) - - def teardown(self): - Step("收尾工作.................") - self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/unittest/app_spawn_client_test/BUILD.gn b/test/unittest/app_spawn_client_test/BUILD.gn index 3b3932f6..dd62ab13 100644 --- a/test/unittest/app_spawn_client_test/BUILD.gn +++ b/test/unittest/app_spawn_client_test/BUILD.gn @@ -40,7 +40,6 @@ ohos_unittest("AppSpawn_client_ut") { "${appspawn_path}/modules/common", "${appspawn_path}/modules/sandbox", "${appspawn_path}/modules/sandbox/normal", - "${appspawn_path}/modules/sandbox/modern", "${appspawn_path}/modules/module_engine/include", "${appspawn_path}/modules/sysevent", "${appspawn_innerkits_path}/client", diff --git a/test/unittest/app_spawn_standard_test/BUILD.gn b/test/unittest/app_spawn_standard_test/BUILD.gn index 5bfa7924..024c3d97 100644 --- a/test/unittest/app_spawn_standard_test/BUILD.gn +++ b/test/unittest/app_spawn_standard_test/BUILD.gn @@ -137,6 +137,7 @@ ohos_unittest("AppSpawn_ut") { "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_mount_test.cpp", "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_test.cpp", "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandboxmgr_test.cpp", + "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_debug_mode.cpp", ] defines += [ "APPSPAWN_SANDBOX_NEW" ] } else { @@ -217,6 +218,103 @@ ohos_unittest("AppSpawn_ut") { } } +ohos_unittest("AppSpawnDebugSandbox") { + module_out_path = "appspawn/appspawn" + cflags = [ "-Dprivate=public" ] + if (appspawn_unittest_coverage) { + cflags += [ "--coverage" ] + ldflags = [ "--coverage" ] + cflags_cc = [ "--coverage" ] + } + deps = [] + defines = [ + "APPSPAWN_BASE_DIR=\"/data/appspawn_ut\"", + "APPSPAWN_LABEL=\"APPSPAWN_UT\"", + "APPSPAWN_TEST", + "APPSPAWN_CLIENT", + "APPSPAWN_DEBUG", + "DEBUG_BEGETCTL_BOOT", + "USER_TIMER_TO_CHECK", + "OHOS_DEBUG", + ] + + include_dirs = [ + "${appspawn_path}", + "${appspawn_path}/common", + "${appspawn_path}/standard", + "${appspawn_innerkits_path}/client", + "${appspawn_innerkits_path}/permission", + "${appspawn_path}/test/mock", + "${appspawn_path}/test/unittest", + "${appspawn_path}/util/include", + "${appspawn_path}/modules/module_engine/include", + "${appspawn_path}/modules/sandbox", + "${appspawn_path}/modules/sandbox/normal" + ] + + sources = [ + "${appspawn_path}/util/src/appspawn_utils.c", + "${appspawn_path}/modules/modulemgr/appspawn_modulemgr.c", + "${appspawn_path}/standard/appspawn_msgmgr.c", + "${appspawn_path}/common/appspawn_trace.cpp", + "${appspawn_innerkits_path}/permission/appspawn_mount_permission.c", + ] + + if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) { + defines += [ "APPSPAWN_SANDBOX_NEW" ] + } else { + sources += [ + "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_debug_mode.cpp", + "${appspawn_path}/test/mock/lib_func_mock/lib_func_mock.cpp", + "${appspawn_path}/modules/sandbox/sandbox_dec.c", + "${appspawn_path}/modules/sandbox/appspawn_permission.c", + "${appspawn_path}/modules/sandbox/normal/sandbox_shared_mount.cpp", + "${appspawn_path}/modules/sandbox/normal/appspawn_sandbox_manager.cpp", + "${appspawn_path}/modules/sandbox/normal/sandbox_common.cpp", + ] + include_dirs += [ "${appspawn_path}/test/mock/lib_func_mock" ] + } + + configs = [ "${appspawn_path}:appspawn_config" ] + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "config_policy:configpolicy_util", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "googletest:gmock_main", + ] + + if (target_cpu == "arm64" || target_cpu == "x86_64" || + target_cpu == "riscv64") { + defines += [ "APPSPAWN_64" ] + } + + if (build_selinux) { + defines += [ "WITH_SELINUX" ] + external_deps += [ + "selinux:libselinux", + "selinux_adapter:libhap_restorecon", + ] + } + + if (appspawn_report_event) { + defines += [ "REPORT_EVENT" ] + external_deps += [ "hisysevent:libhisysevent" ] + sources += [ + "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp", + "${appspawn_path}/modules/sysevent/event_reporter.cpp", + "${appspawn_path}/modules/sysevent/hisysevent_adapter.cpp", + ] + } + + if (dlp_permission_enable) { + cflags_cc = [ "-DWITH_DLP" ] + external_deps += [ "dlp_permission_service:libdlp_fuse" ] + } +} + ohos_unittest("AppSpawn_coldrun_ut") { module_out_path = "appspawn/appspawn" cflags = [ "-Dprivate=public" ] @@ -311,10 +409,6 @@ ohos_unittest("AppSpawn_coldrun_ut") { ] sources += appspawn_sandbox_src - if (appspawn_use_encaps == true) { - sources += [ "${appspawn_path}/modules/common/appspawn_encaps.c" ] - } - # add stub include_dirs += [ "${appspawn_path}/test/mock" ] sources += [ diff --git a/test/unittest/app_spawn_standard_test/app_spawn_appmgr_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_appmgr_test.cpp index fa672280..f648c1d1 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_appmgr_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_appmgr_test.cpp @@ -956,14 +956,6 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawningCtx_Msg_003, TestSize.Level0) ret = CheckAppPermissionFlagSet(nullptr, j); EXPECT_EQ(0, ret); } - uint32_t result[MAX_FLAGS_INDEX] = {0}; - result[0] = 0; - result[1] = 1; - result[3] = 1; - for (int j = 0; j < MAX_FLAGS_INDEX; j++) { - ret = CheckAppMsgFlagsSet(appCtx, j); - EXPECT_EQ(result[j], ret); - } DeleteAppSpawningCtx(appCtx); DeleteAppSpawnMgr(mgr); } diff --git a/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp index 5fb39ebf..6f028823 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp @@ -1483,7 +1483,7 @@ HWTEST_F(AppSpawnCommonTest, App_Spawn_SetCapabilities, TestSize.Level0) // create msg ret = AppSpawnClientInit(NWEBSPAWN_SERVER_NAME, &clientHandle); APPSPAWN_CHECK(ret == 0, break, "Failed to create reqMgr %{public}s", NWEBSPAWN_SERVER_NAME); - reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_APP_SPAWN, 0); + reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_SPAWN_NATIVE_PROCESS, 0); APPSPAWN_CHECK(reqHandle != INVALID_REQ_HANDLE, break, "Failed to create req %{public}s", NWEBSPAWN_SERVER_NAME); property = g_testHelper.GetAppProperty(clientHandle, reqHandle); @@ -1495,5 +1495,4 @@ HWTEST_F(AppSpawnCommonTest, App_Spawn_SetCapabilities, TestSize.Level0) DeleteAppSpawnMgr(mgr); ASSERT_EQ(ret, 0); } - } // namespace OHOS diff --git a/test/unittest/app_spawn_standard_test/app_spawn_kickdog_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_kickdog_test.cpp index 7b7760b3..5706afbf 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_kickdog_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_kickdog_test.cpp @@ -43,7 +43,7 @@ static int CheckFileContent(const char *filePath, const char *targetStr) char buf[100]; if (filePath == nullptr) { - printf("para invaild\n"); + printf("para invalid\n"); return -1; } diff --git a/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_debug_mode.cpp b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_debug_mode.cpp index 05f94524..396d0855 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_debug_mode.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_debug_mode.cpp @@ -104,7 +104,7 @@ static SandboxContext *AppSpawnDebugSandboxTestGetSandboxContext(const AppSpawni /** * @tc.name: InstallDebugSandbox_ShouldReturnInvalidArg_WhenPropertyIsNull - * @tc.desc: 测试当 property 为 NULL 时,函数应返回 APPSPAWN_ARG_INVAILD. + * @tc.desc: 测试当 property 为 NULL 时,函数应返回 APPSPAWN_ARG_INVALID. * @tc.number: InstallDebugSandboxTest_001 */ HWTEST_F(AppSpawnDebugSandboxTest, ATC_InstallDebugSandbox_ShouldReturnInvalidArg_WhenPropertyIsNull, TestSize.Level0) @@ -119,7 +119,7 @@ HWTEST_F(AppSpawnDebugSandboxTest, ATC_InstallDebugSandbox_ShouldReturnInvalidAr /** * @tc.name: InstallDebugSandbox_ShouldReturnInvalidArg_WhenContentIsNull - * @tc.desc: 测试当 content 为 NULL 时,函数应返回 APPSPAWN_ARG_INVAILD. + * @tc.desc: 测试当 content 为 NULL 时,函数应返回 APPSPAWN_ARG_INVALID. * @tc.number: InstallDebugSandboxTest_002 */ HWTEST_F(AppSpawnDebugSandboxTest, ATC_InstallDebugSandbox_ShouldReturnInvalidArg_WhenContentIsNull, TestSize.Level0) diff --git a/util/include/appspawn_error.h b/util/include/appspawn_error.h index ba0c7350..f3258678 100644 --- a/util/include/appspawn_error.h +++ b/util/include/appspawn_error.h @@ -84,12 +84,12 @@ typedef enum { typedef enum { APPSPAWN_ERROR_MSG_TO_LONG = DECLARE_APPSPAWN_ERRORCODE(APPSPAWN_SPAWNER, APPSPAWN_UTILS_COMMON, 0x0000), - APPSPAWN_ERROR_MSG_INVAILD, + APPSPAWN_ERROR_MSG_INVALID, } SpawnerErrorCode; typedef enum { - SANDBOX_ERROR_ARGS_INVAILD = DECLARE_APPSPAWN_ERRORCODE(APPSPAWN_SANDBOX, APPSPAWN_SANDBOX_COMMON, 0x0000), - SANDBOX_ERROR_MSG_INVAILD, + SANDBOX_ERROR_ARGS_INVALID = DECLARE_APPSPAWN_ERRORCODE(APPSPAWN_SANDBOX, APPSPAWN_SANDBOX_COMMON, 0x0000), + SANDBOX_ERROR_MSG_INVALID, } SandboxErrorCode; #ifdef __cplusplus -- Gitee