From 3f9d88e2730f68aeb3047b0fa8ef48cd36a676ad Mon Sep 17 00:00:00 2001 From: wangfeng Date: Wed, 30 Oct 2024 17:10:45 +0800 Subject: [PATCH 001/148] add JIT permission extraInfo name Signed-off-by: wangfeng --- interfaces/innerkits/include/appspawn.h | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index f3edf5f9..c75504bc 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -276,6 +276,7 @@ int AppSpawnClientAddPermission(AppSpawnClientHandle handle, AppSpawnReqMsgHandl #define MSG_EXT_NAME_PROCESS_TYPE "ProcessType" #define MSG_EXT_NAME_MAX_CHILD_PROCCESS_MAX "MaxChildProcess" #define MSG_EXT_NAME_APP_FD "AppFd" +#define MSG_EXT_NAME_JIT_PERMISSIONS "JITPermissions" int AppSpawnReqMsgAddExtInfo(AppSpawnReqMsgHandle reqHandle, const char *name, const uint8_t *value, uint32_t valueLen); -- Gitee From 2dc0ab74db5d634998d097b79023f42e61a86def Mon Sep 17 00:00:00 2001 From: zhaowenpu Date: Thu, 31 Oct 2024 14:07:53 +0000 Subject: [PATCH 002/148] =?UTF-8?q?libPath=E5=86=85=E5=AD=98=E9=95=BF?= =?UTF-8?q?=E5=BA=A6=E4=B8=8D=E8=B6=B3=EF=BC=8C=E9=9C=80=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaowenpu --- modules/nweb_adapter/nwebspawn_adapter.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/nweb_adapter/nwebspawn_adapter.cpp b/modules/nweb_adapter/nwebspawn_adapter.cpp index 8f4375f4..4e355edf 100644 --- a/modules/nweb_adapter/nwebspawn_adapter.cpp +++ b/modules/nweb_adapter/nwebspawn_adapter.cpp @@ -112,6 +112,11 @@ APPSPAWN_STATIC int RunChildProcessor(AppSpawnContent *content, AppSpawnClient * Dl_namespace dlns; dlns_init(&dlns, "nweb_ns"); dlns_create(&dlns, libPath.c_str()); + + Dl_namespace ndk; + dlns_get("ndk", &ndk); + dlns_inherit(&dlns, &ndk, "allow_all_shared_libs"); + // preload libweb_engine webEngineHandle = dlopen_ns(&dlns, engineLibName.c_str(), RTLD_NOW | RTLD_GLOBAL); -- Gitee From 1ca7a87201274dce1bd061a615c506ca96242660 Mon Sep 17 00:00:00 2001 From: zhaowenpu Date: Fri, 1 Nov 2024 03:21:07 +0000 Subject: [PATCH 003/148] update modules/nweb_adapter/nwebspawn_adapter.cpp. Signed-off-by: zhaowenpu --- modules/nweb_adapter/nwebspawn_adapter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/nweb_adapter/nwebspawn_adapter.cpp b/modules/nweb_adapter/nwebspawn_adapter.cpp index 4e355edf..64705e35 100644 --- a/modules/nweb_adapter/nwebspawn_adapter.cpp +++ b/modules/nweb_adapter/nwebspawn_adapter.cpp @@ -113,9 +113,9 @@ APPSPAWN_STATIC int RunChildProcessor(AppSpawnContent *content, AppSpawnClient * dlns_init(&dlns, "nweb_ns"); dlns_create(&dlns, libPath.c_str()); - Dl_namespace ndk; - dlns_get("ndk", &ndk); - dlns_inherit(&dlns, &ndk, "allow_all_shared_libs"); + Dl_namespace ndkns; + dlns_get("ndkns", &ndkns); + dlns_inherit(&dlns, &ndkns, "allow_all_shared_libs"); // preload libweb_engine webEngineHandle = -- Gitee From 8abc871d70c0854311e2a36ee30edc5882a640f1 Mon Sep 17 00:00:00 2001 From: zhaowenpu Date: Fri, 1 Nov 2024 03:29:49 +0000 Subject: [PATCH 004/148] update modules/nweb_adapter/nwebspawn_adapter.cpp. Signed-off-by: zhaowenpu --- modules/nweb_adapter/nwebspawn_adapter.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/nweb_adapter/nwebspawn_adapter.cpp b/modules/nweb_adapter/nwebspawn_adapter.cpp index 64705e35..2356dc17 100644 --- a/modules/nweb_adapter/nwebspawn_adapter.cpp +++ b/modules/nweb_adapter/nwebspawn_adapter.cpp @@ -112,11 +112,9 @@ APPSPAWN_STATIC int RunChildProcessor(AppSpawnContent *content, AppSpawnClient * Dl_namespace dlns; dlns_init(&dlns, "nweb_ns"); dlns_create(&dlns, libPath.c_str()); - Dl_namespace ndkns; dlns_get("ndkns", &ndkns); - dlns_inherit(&dlns, &ndkns, "allow_all_shared_libs"); - + dlns_inherit(&dlns, &ndkns, "allow_all_shared_libs"); // preload libweb_engine webEngineHandle = dlopen_ns(&dlns, engineLibName.c_str(), RTLD_NOW | RTLD_GLOBAL); -- Gitee From 663eb37fcf1bc93438b670a3b0c2dd8c2cd1b500 Mon Sep 17 00:00:00 2001 From: zhaowenpu Date: Fri, 1 Nov 2024 06:21:40 +0000 Subject: [PATCH 005/148] update modules/nweb_adapter/nwebspawn_adapter.cpp. Signed-off-by: zhaowenpu --- modules/nweb_adapter/nwebspawn_adapter.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/nweb_adapter/nwebspawn_adapter.cpp b/modules/nweb_adapter/nwebspawn_adapter.cpp index 2356dc17..338ffade 100644 --- a/modules/nweb_adapter/nwebspawn_adapter.cpp +++ b/modules/nweb_adapter/nwebspawn_adapter.cpp @@ -114,13 +114,11 @@ APPSPAWN_STATIC int RunChildProcessor(AppSpawnContent *content, AppSpawnClient * dlns_create(&dlns, libPath.c_str()); Dl_namespace ndkns; dlns_get("ndkns", &ndkns); - dlns_inherit(&dlns, &ndkns, "allow_all_shared_libs"); + dlns_inherit(&dlns, &ndkns, "allow_all_shared_libs"); // preload libweb_engine - webEngineHandle = - dlopen_ns(&dlns, engineLibName.c_str(), RTLD_NOW | RTLD_GLOBAL); + webEngineHandle = dlopen_ns(&dlns, engineLibName.c_str(), RTLD_NOW | RTLD_GLOBAL); // load libnweb_render - nwebRenderHandle = - dlopen_ns(&dlns, renderLibName.c_str(), RTLD_NOW | RTLD_GLOBAL); + nwebRenderHandle = dlopen_ns(&dlns, renderLibName.c_str(), RTLD_NOW | RTLD_GLOBAL); #else // preload libweb_engine const std::string engineLibPath = libPath + "/" + engineLibName; -- Gitee From 1e8ff79481da7bfd6b211efcdf6192d53776c004 Mon Sep 17 00:00:00 2001 From: yh Date: Fri, 1 Nov 2024 17:12:46 +0800 Subject: [PATCH 006/148] add Signed-off-by: yh Change-Id: I37a8f15341d3bc81259d2c8a076277f7e4b4c7f0 --- bundle.json | 3 ++- standard/appspawn_service.c | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/bundle.json b/bundle.json index ec3a881d..bf616295 100644 --- a/bundle.json +++ b/bundle.json @@ -24,7 +24,8 @@ "appspawn_support_native", "appspawn_use_encaps", "appspawn_mount_tmpshm", - "appspawn_seccomp_privilege" + "appspawn_seccomp_privilege", + "appspawn_support_prefork" ], "rom": "296KB", "ram": "13125KB", diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index ca8d5780..c62d9ee5 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -54,6 +54,7 @@ #define FD_PATH_SIZE 128 #define MAX_MEM_SIZE (4 * 1024) #define APPSPAWN_MSG_USER_CHECK_COUNT 3 +#define PREFORK_PROCESS "apppool" #ifndef PIDFD_NONBLOCK #define PIDFD_NONBLOCK O_NONBLOCK #endif @@ -734,6 +735,28 @@ static void ClearMMAP(int clientId) } } +static int SetPreforkProcessName(AppSpawnContent *content) +{ + int ret = prctl(PR_SET_NAME, PREFORK_PROCESS); + if (ret == -1) { + return errno; + } + + ret = memset_s(content->longProcName, + (size_t)content->longProcNameLen, 0, (size_t)content->longProcNameLen); + if (ret != EOK) { + return EINVAL; + } + + ret = strncpy_s(content->longProcName, content->longProcNameLen, + PREFORK_PROCESS, strlen(PREFORK_PROCESS)); + if (ret != EOK) { + return EINVAL; + } + + return 0; +} + static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property) { APPSPAWN_CHECK(pipe(content->preforkFd) == 0, return, "prefork with prefork pipe failed %{public}d", errno); @@ -750,7 +773,7 @@ static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property) if (content->reservedPid == 0) { (void)close(property->forkCtx.fd[0]); (void)close(property->forkCtx.fd[1]); - int isRet = prctl(PR_SET_NAME, "apppool"); + int isRet = SetPreforkProcessName(content); APPSPAWN_LOGI("prefork process start wait read msg with set processname %{public}d", isRet); AppSpawnClient client = {0, 0}; int infoSize = read(content->parentToChildFd[0], &client, sizeof(AppSpawnClient)); -- Gitee From 6b87639524a3d7f1e656f95090a4d0d7646ab5d5 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Sat, 2 Nov 2024 19:26:31 +0800 Subject: [PATCH 007/148] Revert "modify mallopt" This reverts commit 8ee3ad79ef5db7f4cf364aa44aecf82506152f8c. Signed-off-by: nianyuu --- modules/ace_adapter/ace_adapter.cpp | 1 - modules/common/appspawn_common.c | 12 +++++++++--- modules/nweb_adapter/BUILD.gn | 6 +----- modules/nweb_adapter/nwebspawn_adapter.cpp | 6 +++--- util/include/appspawn_utils.h | 1 - util/src/appspawn_utils.c | 11 ----------- 6 files changed, 13 insertions(+), 24 deletions(-) diff --git a/modules/ace_adapter/ace_adapter.cpp b/modules/ace_adapter/ace_adapter.cpp index 8aaa6468..b6aac779 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -240,7 +240,6 @@ APPSPAWN_STATIC int RunChildByRenderCmd(const AppSpawnMgr *content, const AppSpa static int RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client) { - EnableCache(); APPSPAWN_CHECK(client != NULL && content != NULL, return -1, "Invalid client"); AppSpawningCtx *property = reinterpret_cast(client); int ret = 0; diff --git a/modules/common/appspawn_common.c b/modules/common/appspawn_common.c index b5a9f009..02eeef35 100644 --- a/modules/common/appspawn_common.c +++ b/modules/common/appspawn_common.c @@ -376,9 +376,15 @@ static int SpawnSetAppEnv(AppSpawnMgr *content, AppSpawningCtx *property) return 0; } -static int SpawnSetIntPermission(AppSpawnMgr *content, AppSpawningCtx *property) +static int SpawnEnableCache(AppSpawnMgr *content, AppSpawningCtx *property) { - APPSPAWN_LOGV("Spawning: set Internet Permission for app process"); + APPSPAWN_LOGV("Spawning: enable cache for app process"); + // enable cache for app process + mallopt(M_OHOS_CONFIG, M_TCACHE_PERFORMANCE_MODE); + mallopt(M_OHOS_CONFIG, M_ENABLE_OPT_TCACHE); + mallopt(M_SET_THREAD_CACHE, M_THREAD_CACHE_ENABLE); + mallopt(M_DELAYED_FREE, M_DELAYED_FREE_ENABLE); + int ret = SetInternetPermission(property); APPSPAWN_CHECK_ONLY_EXPER(ret == 0, return ret); return ret; @@ -543,7 +549,7 @@ MODULE_CONSTRUCTOR(void) AddAppSpawnHook(STAGE_PARENT_PRE_FORK, HOOK_PRIO_HIGHEST, SpawnGetSpawningFlag); AddAppSpawnHook(STAGE_CHILD_PRE_COLDBOOT, HOOK_PRIO_HIGHEST, SpawnInitSpawningEnv); AddAppSpawnHook(STAGE_CHILD_PRE_COLDBOOT, HOOK_PRIO_COMMON + 1, SpawnSetAppEnv); - AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_HIGHEST, SpawnSetIntPermission); + AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_HIGHEST, SpawnEnableCache); AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_PROPERTY, SpawnSetProperties); AddAppSpawnHook(STAGE_CHILD_POST_RELY, HOOK_PRIO_HIGHEST, SpawnComplete); AddAppSpawnHook(STAGE_PARENT_POST_FORK, HOOK_PRIO_HIGHEST, CloseFdArgs); diff --git a/modules/nweb_adapter/BUILD.gn b/modules/nweb_adapter/BUILD.gn index b552b3dc..acd15abe 100644 --- a/modules/nweb_adapter/BUILD.gn +++ b/modules/nweb_adapter/BUILD.gn @@ -20,15 +20,11 @@ ohos_shared_library("appspawn_nweb") { ".", "${appspawn_path}/common", "${appspawn_path}/standard", - "${appspawn_path}/util/include", ] defines = [] cflags = [] - deps = [ - "${appspawn_path}/modules/module_engine:libappspawn_module_engine", - "${appspawn_path}/util:libappspawn_util", - ] + deps = [ "${appspawn_path}/modules/module_engine:libappspawn_module_engine" ] if (target_cpu == "arm64") { defines += [ "webview_arm64" ] } diff --git a/modules/nweb_adapter/nwebspawn_adapter.cpp b/modules/nweb_adapter/nwebspawn_adapter.cpp index 8f4375f4..502496fa 100644 --- a/modules/nweb_adapter/nwebspawn_adapter.cpp +++ b/modules/nweb_adapter/nwebspawn_adapter.cpp @@ -29,7 +29,6 @@ #include "appspawn_hook.h" #include "appspawn_manager.h" -#include "appspawn_utils.h" #ifdef WITH_SECCOMP #include "seccomp_policy.h" @@ -95,11 +94,12 @@ APPSPAWN_STATIC std::string GetArkWebRenderLibName() APPSPAWN_STATIC int RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client) { - EnableCache(); uint32_t len = 0; char *renderCmd = reinterpret_cast(GetAppPropertyExt( reinterpret_cast(client), MSG_EXT_NAME_RENDER_CMD, &len)); - APPSPAWN_CHECK_ONLY_EXPER(renderCmd != nullptr, return -1); + if (renderCmd == nullptr) { + return -1; + } std::string renderStr(renderCmd); void *webEngineHandle = nullptr; void *nwebRenderHandle = nullptr; diff --git a/util/include/appspawn_utils.h b/util/include/appspawn_utils.h index 7395760c..6938e73c 100755 --- a/util/include/appspawn_utils.h +++ b/util/include/appspawn_utils.h @@ -139,7 +139,6 @@ void InitCommonEnv(void); int ConvertEnvValue(const char *srcEnv, char *dstEnv, int len); int EnableNewNetNamespace(void); -void EnableCache(void); #ifndef APP_FILE_NAME #define APP_FILE_NAME (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__)) diff --git a/util/src/appspawn_utils.c b/util/src/appspawn_utils.c index 1f3270ee..5472fe2f 100644 --- a/util/src/appspawn_utils.c +++ b/util/src/appspawn_utils.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -436,13 +435,3 @@ int EnableNewNetNamespace(void) close(fd); return (ret >= 0) ? 0 : APPSPAWN_SYSTEM_ERROR; } - -void EnableCache(void) -{ - APPSPAWN_LOGV("enable cache for app process"); - // enable cache for app process - mallopt(M_OHOS_CONFIG, M_TCACHE_PERFORMANCE_MODE); - mallopt(M_OHOS_CONFIG, M_ENABLE_OPT_TCACHE); - mallopt(M_SET_THREAD_CACHE, M_THREAD_CACHE_ENABLE); - mallopt(M_DELAYED_FREE, M_DELAYED_FREE_ENABLE); -} -- Gitee From cff5a2e2924e70f8580b6e253db14049bdbb580a Mon Sep 17 00:00:00 2001 From: taojuncun Date: Mon, 4 Nov 2024 09:29:38 +0800 Subject: [PATCH 008/148] =?UTF-8?q?=E9=A2=84=E5=8A=A0=E8=BD=BD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: taojuncun --- appspawn_preload.json | 1 - 1 file changed, 1 deletion(-) diff --git a/appspawn_preload.json b/appspawn_preload.json index 0a15fe7f..2c2920e7 100644 --- a/appspawn_preload.json +++ b/appspawn_preload.json @@ -76,7 +76,6 @@ "app.ability.UIExtensionAbility", "arkui.componentutils", "arkui.modifier", - "arkui.node", "data.dataSharePredicates", "hiappevent", "hiviewdfx.hiappevent", -- Gitee From b112365262ea51777dff7654d29e5c9d374135e5 Mon Sep 17 00:00:00 2001 From: jiangjinpeng3 Date: Mon, 4 Nov 2024 10:30:04 +0800 Subject: [PATCH 009/148] =?UTF-8?q?=E9=80=82=E9=85=8D=E5=AA=92=E4=BD=93?= =?UTF-8?q?=E5=BA=93fuse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangjinpeng3 Change-Id: I6b6ac55708dd04903a48be78635fe250ac34958c --- appdata-sandbox-app.json | 3 +++ appdata-sandbox.json | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/appdata-sandbox-app.json b/appdata-sandbox-app.json index 3f6dd7b3..cb8ca121 100755 --- a/appdata-sandbox-app.json +++ b/appdata-sandbox-app.json @@ -159,6 +159,9 @@ }, { "src-path" : "/mnt/hmdfs//cloud/data/", "sandbox-path" : "/data/storage/el2/cloud" + }, { + "src-path" : "/mnt/data//media_fuse", + "sandbox-path" : "/data/storage/el2/media" }], "symbol-links" : [{ "target-name" : "/mnt/nweb/tmp", diff --git a/appdata-sandbox.json b/appdata-sandbox.json index 9be9213f..b50864c8 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -283,6 +283,11 @@ "sandbox-path" : "/data/storage/el2/cloud", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" + }, { + "src-path" : "/mnt/data//media_fuse", + "sandbox-path" : "/data/storage/el2/media", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" } ], "symbol-links" : [{ -- Gitee From b83c9be7f55ff2ca6eb94a49a0dc37b4454a48d4 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Mon, 4 Nov 2024 10:54:04 +0800 Subject: [PATCH 010/148] fix:encaps bug Signed-off-by: wangfeng --- modules/common/appspawn_encaps.c | 2 +- standard/BUILD.gn | 4 +--- util/include/appspawn_utils.h | 4 ++++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/common/appspawn_encaps.c b/modules/common/appspawn_encaps.c index 6581d53b..4e93ed72 100644 --- a/modules/common/appspawn_encaps.c +++ b/modules/common/appspawn_encaps.c @@ -184,7 +184,7 @@ static int SpawnSetJITPermissions(AppSpawnMgr *content, AppSpawningCtx *property return ret; } -static int AddMembersToEncaps(AppSpawnMgr *content, AppSpawningCtx *property, CJSON *encaps) +static int AddMembersToEncaps(AppSpawnMgr *content, AppSpawningCtx *property, cJSON *encaps) { uint32_t encapsPermissionCount = 0; // need set ohos.encaps.count to encaps firstly diff --git a/standard/BUILD.gn b/standard/BUILD.gn index ec2ee283..3dadbe6b 100644 --- a/standard/BUILD.gn +++ b/standard/BUILD.gn @@ -82,9 +82,7 @@ ohos_executable("appspawn") { if (enable_appspawn_dump_catcher) { external_deps += [ "faultloggerd:libdfx_dumpcatcher" ] } - if (appspawn_use_encaps) { - defines += [ "USE_ENCAPS" ] - } + if (appspawn_report_event) { defines += [ "APPSPAWN_HISYSEVENT" ] external_deps += [ "hisysevent:libhisysevent" ] diff --git a/util/include/appspawn_utils.h b/util/include/appspawn_utils.h index 7395760c..7c7acfff 100755 --- a/util/include/appspawn_utils.h +++ b/util/include/appspawn_utils.h @@ -123,6 +123,10 @@ typedef enum { APPSPAWN_ERROR_UTILS_MEM_FAIL, APPSPAWN_ERROR_FILE_RMDIR_FAIL, APPSPAWN_SANDBOX_ERROR_SET_PERMISSION_FLAG_FAIL, + APPSPAWN_ERROR_UTILS_DECODE_JSON_FAIL, + APPSPAWN_ERROR_UTILS_CREATE_JSON_FAIL, + APPSPAWN_ERROR_UTILS_ADD_JSON_FAIL, + APPSPAWN_PIDMGR_DEFAULT_PID_MAX, APPSPAWN_NODE_EXIST, } AppSpawnErrorCode; -- Gitee From 0c1add43c441f33579a228990abaea3966c18543 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Tue, 5 Nov 2024 11:21:08 +0800 Subject: [PATCH 011/148] fix newsandbox bug Signed-off-by: nianyuu --- appdata-sandbox-app.json | 6 +++--- modules/sandbox/appspawn_sandbox.c | 12 +++++++----- modules/sandbox/sandbox_load.c | 1 + modules/sandbox/sandbox_manager.c | 10 +++++++--- modules/sandbox/sandbox_utils.cpp | 2 +- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/appdata-sandbox-app.json b/appdata-sandbox-app.json index 3f6dd7b3..92e4c1b8 100755 --- a/appdata-sandbox-app.json +++ b/appdata-sandbox-app.json @@ -89,9 +89,6 @@ }, { "src-path" : "/system/app/SystemResources", "sandbox-path" : "/data/global/systemResources" - }, { - "src-path" : "/data/misc", - "sandbox-path" : "/data/storage/el1/bundle/misc" }, { "src-path" : "/data/service/el1/public/cert_manager_service/certificates/user_open", "sandbox-path" : "/data/certificates/user_cacerts" @@ -129,6 +126,9 @@ "src-path" : "/data/app/el1/bundle/public/", "sandbox-path" : "/data/storage/el1/bundle", "check-action-status": "true" + }, { + "src-path" : "/data/misc", + "sandbox-path" : "/data/storage/el1/bundle/misc" }, { "src-path" : "/data/local/ark-cache/", "sandbox-path" : "/data/storage/ark-cache" diff --git a/modules/sandbox/appspawn_sandbox.c b/modules/sandbox/appspawn_sandbox.c index 50c57d24..19422e9e 100644 --- a/modules/sandbox/appspawn_sandbox.c +++ b/modules/sandbox/appspawn_sandbox.c @@ -102,11 +102,11 @@ int SandboxMountPath(const MountArg *arg) int ret = mount(arg->originPath, arg->destinationPath, arg->fsType, arg->mountFlags, arg->options); if (ret != 0) { - if (arg->originPath != NULL && strstr(arg->originPath, "/data/app/el2/") != NULL) { - CheckDirRecursive(arg->originPath); - } APPSPAWN_LOGW("errno is: %{public}d, bind mount %{public}s => %{public}s", errno, arg->originPath, arg->destinationPath); + if (strstr(arg->originPath, "/data/app/el1/") != NULL || strstr(arg->originPath, "/data/app/el2/") != NULL) { + CheckDirRecursive(arg->originPath); + } return errno; } ret = mount(NULL, arg->destinationPath, NULL, arg->mountSharedFlag, NULL); @@ -467,11 +467,13 @@ static int DoSandboxPathNodeMount(const SandboxContext *context, } CreateDemandSrc(context, sandboxNode, &args); + int ret = 0; if (CHECK_FLAGS_BY_INDEX(operation, MOUNT_PATH_OP_UNMOUNT)) { // unmount this deps APPSPAWN_LOGV("umount2 %{public}s", args.destinationPath); - umount2(args.destinationPath, MNT_DETACH); + ret = umount2(args.destinationPath, MNT_DETACH); + APPSPAWN_CHECK_ONLY_LOG(ret == 0, "Failed to umount %{public}s errno %{public}d", args.destinationPath, errno); } - int ret = 0; + ret = DoSandboxMountByCategory(context, sandboxNode, &args, operation); if (ret != 0 && sandboxNode->checkErrorFlag) { APPSPAWN_LOGE("Failed to mount config, section: %{public}s result: %{public}d category: %{public}d", diff --git a/modules/sandbox/sandbox_load.c b/modules/sandbox/sandbox_load.c index 3158aa3d..a91916eb 100644 --- a/modules/sandbox/sandbox_load.c +++ b/modules/sandbox/sandbox_load.c @@ -677,6 +677,7 @@ int LoadAppSandboxConfig(AppSpawnSandboxCfg *sandbox, RunMode mode) { APPSPAWN_CHECK_ONLY_EXPER(sandbox != NULL, return APPSPAWN_ARG_INVALID); const char *sandboxName = GetSandboxNameByMode(mode); + APPSPAWN_LOGV("Get sandboxName %{public}s by mode %{public}d", sandboxName, mode); if (sandbox->depGroupNodes != NULL) { APPSPAWN_LOGW("Sandbox has been load"); return 0; diff --git a/modules/sandbox/sandbox_manager.c b/modules/sandbox/sandbox_manager.c index bbcabb05..4a11f1a8 100644 --- a/modules/sandbox/sandbox_manager.c +++ b/modules/sandbox/sandbox_manager.c @@ -495,7 +495,7 @@ APPSPAWN_STATIC int PreLoadIsoLatedSandboxCfg(AppSpawnMgr *content) APPSPAWN_CHECK_ONLY_EXPER(sandbox != NULL, return APPSPAWN_SYSTEM_ERROR); OH_ListAddTail(&content->extData, &sandbox->extData.node); - // load app sandbox config + // load isolated sandbox config LoadAppSandboxConfig(sandbox, MODE_FOR_NATIVE_SPAWN); sandbox->maxPermissionIndex = PermissionRenumber(&sandbox->permissionQueue); @@ -515,8 +515,12 @@ APPSPAWN_STATIC int PreLoadSandboxCfg(AppSpawnMgr *content) APPSPAWN_CHECK_ONLY_EXPER(sandbox != NULL, return APPSPAWN_SYSTEM_ERROR); OH_ListAddTail(&content->extData, &sandbox->extData.node); - // load app sandbox config - LoadAppSandboxConfig(sandbox, MODE_FOR_APP_SPAWN); + // load app/nweb sandbox config + if (IsNWebSpawnMode(content)) { + LoadAppSandboxConfig(sandbox, MODE_FOR_NWEB_SPAWN); + } else { + LoadAppSandboxConfig(sandbox, MODE_FOR_APP_SPAWN); + } sandbox->maxPermissionIndex = PermissionRenumber(&sandbox->permissionQueue); content->content.sandboxNsFlags = 0; diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index bc897e72..3fbe7d26 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -287,7 +287,7 @@ int32_t SandboxUtils::DoAppSandboxMountOnce(const char *originPath, const char * } ret = mount(nullptr, destinationPath, nullptr, mountSharedFlag, nullptr); - APPSPAWN_CHECK(ret == 0, return ret, "errno is: %{public}d, private mount to %{public}s %{public}u failed", + APPSPAWN_CHECK(ret == 0, return ret, "errno is: %{public}d, private mount to %{public}s '%{public}u' failed", errno, destinationPath, mountSharedFlag); return 0; } -- Gitee From 221997d0aca30035e327e5c98589e0cc6dfab081 Mon Sep 17 00:00:00 2001 From: taojuncun Date: Tue, 5 Nov 2024 21:44:52 +0800 Subject: [PATCH 012/148] =?UTF-8?q?=E6=B8=85=E7=90=86=E9=A2=84=E5=8A=A0?= =?UTF-8?q?=E8=BD=BDarkui=E7=9B=B8=E5=85=B3=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: taojuncun --- appspawn_preload.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/appspawn_preload.json b/appspawn_preload.json index 2c2920e7..1a985569 100644 --- a/appspawn_preload.json +++ b/appspawn_preload.json @@ -74,15 +74,12 @@ "app.ability.contextconstant", "app.ability.contextConstant_napi", "app.ability.UIExtensionAbility", - "arkui.componentutils", - "arkui.modifier", "data.dataSharePredicates", "hiappevent", "hiviewdfx.hiappevent", "resourceManager", "settings", "multimodalInput.inputDevice", - "util.json", - "arkui.advanced.SubHeader" + "util.json" ] } -- Gitee From 0d9175838db8398af08c297bc8d077cc33e99691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=85=B6=E6=96=87?= Date: Tue, 5 Nov 2024 21:45:41 +0800 Subject: [PATCH 013/148] =?UTF-8?q?appspawn=E4=BB=A3=E7=A0=81=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈其文 --- standard/appspawn_service.c | 6 ++++-- util/src/appspawn_utils.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 69584370..2848096c 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -128,6 +128,8 @@ static inline void DumpStatus(const char *appName, pid_t pid, int status) static void HandleDiedPid(pid_t pid, uid_t uid, int status) { AppSpawnContent *content = GetAppSpawnContent(); + APPSPAWN_CHECK(content != NULL, return, "Invalid content"); + if (pid == content->reservedPid) { APPSPAWN_LOGW("HandleDiedPid with reservedPid %{public}d", pid); content->reservedPid = 0; @@ -940,7 +942,7 @@ static int ProcessChildFdCheck(int fd, AppSpawningCtx *property, int *pResult) return -1; } *pResult = result; - + return 0; } @@ -1510,7 +1512,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); return -1; diff --git a/util/src/appspawn_utils.c b/util/src/appspawn_utils.c index 5472fe2f..bdcc1b36 100644 --- a/util/src/appspawn_utils.c +++ b/util/src/appspawn_utils.c @@ -207,7 +207,7 @@ int32_t StringSplit(const char *str, const char *separator, void *context, Split ret = result; } } - if (index > 0) { + if ((index > 0) && (index < PATH_MAX)) { buffer[index] = '\0'; TrimTail(buffer, index); index = 0; -- Gitee From df39049e19b942747bc32d68b6b1f874e0e7a104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Wed, 6 Nov 2024 10:18:12 +0800 Subject: [PATCH 014/148] =?UTF-8?q?devicedebug=E4=BB=A3=E7=A0=81=E5=B7=AE?= =?UTF-8?q?=E5=BC=82=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- .../devicedebug/kill/src/devicedebug_kill.c | 36 +++++++++++-------- standard/appspawn_service.c | 18 +++++----- .../app_spawn_service_test.cpp | 15 ++++---- test/unittest/devicedebug_test/BUILD.gn | 2 +- 4 files changed, 40 insertions(+), 31 deletions(-) diff --git a/service/devicedebug/kill/src/devicedebug_kill.c b/service/devicedebug/kill/src/devicedebug_kill.c index 5bb0a1b7..f36c177f 100644 --- a/service/devicedebug/kill/src/devicedebug_kill.c +++ b/service/devicedebug/kill/src/devicedebug_kill.c @@ -43,6 +43,7 @@ APPSPAWN_STATIC char* DeviceDebugJsonStringGeneral(int pid, const char *op, cJSO { cJSON *root = cJSON_CreateObject(); if (root == NULL) { + cJSON_Delete(args); DEVICEDEBUG_LOGE("devicedebug json write create root object unsuccess"); return NULL; } @@ -58,20 +59,6 @@ APPSPAWN_STATIC char* DeviceDebugJsonStringGeneral(int pid, const char *op, cJSO APPSPAWN_STATIC int DeviceDebugKill(int pid, int signal) { - AppSpawnClientHandle clientHandle; - int ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle); - if (ret != 0) { - DEVICEDEBUG_LOGE("devicedebug appspawn client init unsuccess, ret=%{public}d", ret); - return ret; - } - - AppSpawnReqMsgHandle reqHandle; - ret = AppSpawnReqMsgCreate(MSG_DEVICE_DEBUG, "devicedebug", &reqHandle); - if (ret != 0) { - DEVICEDEBUG_LOGE("devicedebug appspawn message create unsuccess, ret=%{public}d", ret); - return ret; - } - cJSON *args = cJSON_CreateObject(); if (args == NULL) { DEVICEDEBUG_LOGE("devicedebug json write create args object unsuccess"); @@ -80,20 +67,39 @@ APPSPAWN_STATIC int DeviceDebugKill(int pid, int signal) cJSON_AddNumberToObject(args, "signal", signal); char *jsonString = DeviceDebugJsonStringGeneral(pid, "kill", args); if (jsonString == NULL) { - cJSON_Delete(args); return DEVICEDEBUG_ERRNO_JSON_CREATED_FAILED; } + AppSpawnReqMsgHandle reqHandle; + int ret = AppSpawnReqMsgCreate(MSG_DEVICE_DEBUG, "devicedebug", &reqHandle); + if (ret != 0) { + free(jsonString); + DEVICEDEBUG_LOGE("devicedebug appspawn message create unsuccess, ret=%{public}d", ret); + return ret; + } + ret = AppSpawnReqMsgAddExtInfo(reqHandle, "devicedebug", (uint8_t *)jsonString, strlen(jsonString) + 1); if (ret != 0) { DEVICEDEBUG_LOGE("devicedebug appspawn message add devicedebug[%{public}s] unsuccess, ret=%{public}d", jsonString, ret); + free(jsonString); + AppSpawnReqMsgFree(reqHandle); + return ret; + } + + AppSpawnClientHandle clientHandle; + ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle); + if (ret != 0) { + free(jsonString); + AppSpawnReqMsgFree(reqHandle); + DEVICEDEBUG_LOGE("devicedebug appspawn client init unsuccess, ret=%{public}d", ret); return ret; } AppSpawnResult result = {0}; ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); AppSpawnClientDestroy(clientHandle); + free(jsonString); if (ret != 0) { DEVICEDEBUG_LOGE("devicedebug appspawn send msg unsuccess, ret=%{public}d", ret); return ret; diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 2848096c..81a2f106 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -458,7 +458,6 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer, APPSPAWN_CHECK(ret == 0, LE_CloseStreamTask(LE_GetDefaultLoop(), taskHandle); return, "Failed to create time for connection"); } - return; } static char *GetMapMem(uint32_t clientId, const char *processName, uint32_t size, bool readOnly, bool isNweb) @@ -928,7 +927,7 @@ static void WaitChildTimeout(const TimerHandle taskHandle, void *context) DeleteAppSpawningCtx(property); } -static int ProcessChildFdCheck(int fd, AppSpawningCtx *property, int *pResult) +static int ProcessChildFdCheck(int fd, AppSpawningCtx *property) { int result = 0; (void)read(fd, &result, sizeof(result)); @@ -941,7 +940,6 @@ static int ProcessChildFdCheck(int fd, AppSpawningCtx *property, int *pResult) DeleteAppSpawningCtx(property); return -1; } - *pResult = result; return 0; } @@ -952,13 +950,12 @@ static void ProcessChildResponse(const WatcherHandle taskHandle, int fd, uint32_ property->forkCtx.watcherHandle = NULL; // delete watcher LE_RemoveWatcher(LE_GetDefaultLoop(), (WatcherHandle)taskHandle); - int result = 0; - if (ProcessChildFdCheck(fd, property, &result) != 0) { + if (ProcessChildFdCheck(fd, property) != 0) { return; } // success - bool isDebuggable = CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE) == 1 ? true : false; + bool isDebuggable = CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE); AppSpawnedProcess *appInfo = AddSpawnedProcess(property->pid, GetBundleName(property), isDebuggable); if (appInfo) { AppSpawnMsgDacInfo *dacInfo = GetAppProperty(property, TLV_DAC_INFO); @@ -977,7 +974,7 @@ static void ProcessChildResponse(const WatcherHandle taskHandle, int fd, uint32_ ProcessMgrHookExecute(STAGE_SERVER_APP_ADD, GetAppSpawnContent(), appInfo); // response AppSpawnHookExecute(STAGE_PARENT_PRE_RELY, 0, GetAppSpawnContent(), &property->client); - SendResponse(property->message->connection, &property->message->msgHeader, result, property->pid); + SendResponse(property->message->connection, &property->message->msgHeader, 0, property->pid); AppSpawnHookExecute(STAGE_PARENT_POST_RELY, 0, GetAppSpawnContent(), &property->client); #ifdef DEBUG_BEGETCTL_BOOT if (IsDeveloperModeOpen()) { @@ -1538,22 +1535,27 @@ APPSPAWN_STATIC int ProcessAppSpawnDeviceDebugMsg(AppSpawnMsgNode *message) cJSON *app = cJSON_GetObjectItem(json, "app"); if (!cJSON_IsNumber(app)) { APPSPAWN_LOGE("appspawn devicedebug json get app fail"); + cJSON_Delete(json); return -1; } cJSON *op = cJSON_GetObjectItem(json, "op"); if (!cJSON_IsString(op) || op->valuestring == NULL) { APPSPAWN_LOGE("appspawn devicedebug json get op fail"); + cJSON_Delete(json); return -1; } cJSON *args = cJSON_GetObjectItem(json, "args"); if (!cJSON_IsObject(args)) { APPSPAWN_LOGE("appspawn devicedebug json get args fail"); + cJSON_Delete(json); return -1; } - return AppspawnDevicedebugDeal(op->valuestring, app->valueint, args); + int result = AppspawnDevicedebugDeal(op->valuestring, app->valueint, args); + cJSON_Delete(json); + return result; } static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) diff --git a/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp index 910ed625..31b0d807 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp @@ -567,20 +567,20 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_009, TestSize.Level0) APPSPAWN_CHECK(ret == 0, break, "Failed to send msg %{public}d", ret); AppSpawnedProcess *app = GetSpawnedProcessByName(testServer->GetDefaultTestAppBundleName()); - EXPECT_NE(app, nullptr); + ASSERT_NE(app, nullptr); AppSpawnReqMsgHandle reqHandle2; ret = AppSpawnReqMsgCreate(MSG_DEVICE_DEBUG, "devicedebug", &reqHandle2); - EXPECT_GT(sprintf_s(pid, 16, "%d", app->pid), 0); + ASSERT_GT(sprintf_s(pid, 16, "%d", app->pid), 0); AppSpawnReqMsgAddStringInfo(reqHandle2, "signal", "-9"); AppSpawnReqMsgAddStringInfo(reqHandle2, "pid", pid); ret = AppSpawnClientSendMsg(clientHandle, reqHandle2, &result); + AppSpawnClientDestroy(clientHandle); APPSPAWN_CHECK(ret == 0 && result.result == 0, break, "Failed to send msg ret:%{public}d, result:%{public}d", ret, result.result); ASSERT_EQ(kill(app->pid, SIGKILL), 0); } while (0); - AppSpawnClientDestroy(clientHandle); ASSERT_EQ(ret, 0); ASSERT_EQ(result.result, -1); } @@ -604,15 +604,15 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_010, TestSize.Level0) APPSPAWN_CHECK(ret == 0, break, "Failed to send msg %{public}d", ret); AppSpawnedProcess *app = GetSpawnedProcessByName(testServer->GetDefaultTestAppBundleName()); - EXPECT_NE(app, nullptr); + ASSERT_NE(app, nullptr); AppSpawnReqMsgHandle reqHandle2; ret = AppSpawnReqMsgCreate(MSG_DEVICE_DEBUG, "devicedebug", &reqHandle2); cJSON *args = cJSON_CreateObject(); - EXPECT_NE(args, nullptr); + ASSERT_NE(args, nullptr); cJSON_AddNumberToObject(args, "signal", 9); cJSON *root = cJSON_CreateObject(); - EXPECT_NE(root, nullptr); + ASSERT_NE(root, nullptr); cJSON_AddNumberToObject(root, "app", app->pid); cJSON_AddStringToObject(root, "op", "kill"); cJSON_AddItemToObject(root, "args", args); @@ -621,11 +621,12 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_010, TestSize.Level0) ret = AppSpawnReqMsgAddExtInfo(reqHandle2, "devicedebug", (uint8_t *)jsonString, strlen(jsonString) + 1); ASSERT_EQ(ret, 0); ret = AppSpawnClientSendMsg(clientHandle, reqHandle2, &result); + AppSpawnClientDestroy(clientHandle); + free(jsonString); APPSPAWN_CHECK(ret == 0 && result.result == 0, break, "Failed to send msg ret:%{public}d, result:%{public}d", ret, result.result); } while (0); - AppSpawnClientDestroy(clientHandle); ASSERT_EQ(ret, 0); ASSERT_EQ(result.result, 0); } diff --git a/test/unittest/devicedebug_test/BUILD.gn b/test/unittest/devicedebug_test/BUILD.gn index b075d6c8..f50f29fa 100644 --- a/test/unittest/devicedebug_test/BUILD.gn +++ b/test/unittest/devicedebug_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# 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 -- Gitee From 1e6025a2a9dc0a3ffd01f56b38bdb659bf787105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Mon, 4 Nov 2024 16:45:23 +0800 Subject: [PATCH 015/148] =?UTF-8?q?fix:=20=E6=96=B0=E9=9C=80=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- appdata-sandbox-app.json | 2 +- appdata-sandbox.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appdata-sandbox-app.json b/appdata-sandbox-app.json index 3f6dd7b3..70affb96 100755 --- a/appdata-sandbox-app.json +++ b/appdata-sandbox-app.json @@ -460,7 +460,7 @@ "src-path": "/data/app/el2//database/", "sandbox-path": "/database" }, { - "src-path": "/data/app/el2//log/", + "src-path": "/data/app/el2//log/", "sandbox-path": "/log" }, { "src-path": "/mnt/hmdfs//non_account/merge_view/data", diff --git a/appdata-sandbox.json b/appdata-sandbox.json index 9be9213f..384fa4c3 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -164,7 +164,7 @@ "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/data/app/el2//log/", + "src-path" : "/data/app/el2//log/", "sandbox-path" : "/data/storage/el2/log", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" -- Gitee From 5575ad8dfc27192654128be6750cfb5799c041df Mon Sep 17 00:00:00 2001 From: wangfeng Date: Wed, 6 Nov 2024 14:32:10 +0800 Subject: [PATCH 016/148] modify system/app dir mount point Signed-off-by: wangfeng --- appdata-sandbox-app.json | 17 +++++++++++++---- appdata-sandbox.json | 17 +++++++++++++++-- interfaces/innerkits/include/appspawn.h | 1 + modules/common/appspawn_common.c | 19 +++++++++++++++++++ modules/sandbox/sandbox_load.c | 3 ++- modules/sandbox/sandbox_utils.cpp | 3 ++- 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/appdata-sandbox-app.json b/appdata-sandbox-app.json index 3f6dd7b3..44bd3b8f 100755 --- a/appdata-sandbox-app.json +++ b/appdata-sandbox-app.json @@ -24,8 +24,11 @@ "src-path" : "/module_update", "sandbox-path" : "/module_update" }, { - "src-path" : "/system/app", - "sandbox-path" : "/system/app" + "src-path" : "/system/app/appServiceFwk", + "sandbox-path" : "/system/app/appServiceFwk" + }, { + "src-path" : "/system/app/shared_bundles", + "sandbox-path" : "/system/app/shared_bundles" }, { "src-path" : "/system/fonts", "sandbox-path" : "/system/fonts" @@ -389,8 +392,14 @@ }, { "src-path" : "/data/app/el1/bundle//hnp/", "sandbox-path" : "/data/app" - } - ]}], + }] + }, { + "name": "PREINSTALLED_HAP", + "mount-paths": [{ + "src-path": "/system/app", + "sandbox-path": "/system/app" + }] + }], "package-name": [{ "name": "com.ohos.medialibrary.medialibrarydata", "mount-paths" : [{ diff --git a/appdata-sandbox.json b/appdata-sandbox.json index 9be9213f..805dbdc1 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -29,8 +29,13 @@ "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/system/app", - "sandbox-path" : "/system/app", + "src-path" : "/system/app/appServiceFwk", + "sandbox-path" : "/system/app/appServiceFwk", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/app/shared_bundles", + "sandbox-path" : "/system/app/shared_bundles", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { @@ -386,6 +391,14 @@ "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" } + ]}, { + "flags": "PREINSTALLED_HAP", + "mount-paths": [{ + "src-path": "/system/app", + "sandbox-path": "/system/app", + "sandbox-flags": [ "bind", "rec" ], + "check-action-status": "false" + } ]} ], "symbol-links" : [ diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index c75504bc..1891c12c 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -183,6 +183,7 @@ typedef enum { APP_FLAGS_ISOLATED_NETWORK, APP_FLAGS_ISOLATED_DATAGROUP, APP_FLAGS_TEMP_JIT = 28, + APP_FLAGS_PRE_INSTALLED_HAP = 29, MAX_FLAGS_INDEX = 63, } AppFlagsIndex; diff --git a/modules/common/appspawn_common.c b/modules/common/appspawn_common.c index 02eeef35..18c435c2 100644 --- a/modules/common/appspawn_common.c +++ b/modules/common/appspawn_common.c @@ -62,6 +62,7 @@ #define BITLEN32 32 #define PID_NS_INIT_UID 100000 // reserved for pid_ns_init process, avoid app, render proc, etc. #define PID_NS_INIT_GID 100000 +#define PREINSTALLED_HAP_FLAG 0x01 // hapFlags 0x01: SELINUX_HAP_RESTORECON_PREINSTALLED_APP in selinux static int SetProcessName(const AppSpawnMgr *content, const AppSpawningCtx *property) { @@ -353,6 +354,21 @@ static int32_t WaitForDebugger(const AppSpawningCtx *property) return 0; } +static int SpawnSetPreInstalledFlag(AppSpawningCtx *property) +{ + AppSpawnMsgDomainInfo *msgDomainInfo = (AppSpawnMsgDomainInfo *)GetAppProperty(property, TLV_DOMAIN_INFO); + APPSPAWN_CHECK(msgDomainInfo != NULL, return APPSPAWN_TLV_NONE, "No domain info in req from %{public}s", + GetProcessName(property)); + if ((msgDomainInfo->hapFlags & PREINSTALLED_HAP_FLAG) != 0) { + int ret = SetAppSpawnMsgFlag(property->message, TLV_MSG_FLAGS, APP_FLAGS_PRE_INSTALLED_HAP); + if (ret != 0) { + APPSPAWN_LOGE("Set appspawn msg flag failed"); + return ret; + } + } + return 0; +} + static int SpawnInitSpawningEnv(AppSpawnMgr *content, AppSpawningCtx *property) { APPSPAWN_LOGV("Spawning: clear env"); @@ -365,6 +381,9 @@ static int SpawnInitSpawningEnv(AppSpawnMgr *content, AppSpawningCtx *property) ret = SetAppAccessToken(content, property); APPSPAWN_CHECK_ONLY_EXPER(ret == 0, return ret); + + ret = SpawnSetPreInstalledFlag(property); + APPSPAWN_CHECK_ONLY_EXPER(ret == 0, return ret); return 0; } diff --git a/modules/sandbox/sandbox_load.c b/modules/sandbox/sandbox_load.c index 3158aa3d..59e070a5 100644 --- a/modules/sandbox/sandbox_load.c +++ b/modules/sandbox/sandbox_load.c @@ -45,7 +45,8 @@ static const SandboxFlagInfo FLAGE_POINT_MAP[] = { {"0", 0}, {"START_FLAGS_BACKUP", (unsigned long)APP_FLAGS_BACKUP_EXTENSION}, {"DLP_MANAGER", (unsigned long)APP_FLAGS_DLP_MANAGER}, - {"DEVELOPER_MODE", (unsigned long)APP_FLAGS_DEVELOPER_MODE} + {"DEVELOPER_MODE", (unsigned long)APP_FLAGS_DEVELOPER_MODE}, + {"PREINSTALLED_HAP", (unsigned long)APP_FLAGS_PRE_INSTALLED_HAP} }; static const SandboxFlagInfo MOUNT_MODE_MAP[] = { diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index bc897e72..9472a5cf 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -706,7 +706,8 @@ static uint32_t ConvertFlagStr(const std::string &flagStr) { const std::map flagsMap = {{"0", 0}, {"START_FLAGS_BACKUP", 1}, {"DLP_MANAGER", 2}, - {"DEVELOPER_MODE", 17}}; + {"DEVELOPER_MODE", 17}, + {"PREINSTALLED_HAP", 29}}; if (flagsMap.count(flagStr)) { return 1 << flagsMap.at(flagStr); -- Gitee From 3cae67c6e8d11b3e541799d7c35233d4a7362b44 Mon Sep 17 00:00:00 2001 From: yh Date: Wed, 6 Nov 2024 14:57:35 +0800 Subject: [PATCH 017/148] add prio Signed-off-by: yh Change-Id: I140a857c5cade257348b57eac392d18d9972059f --- modules/common/appspawn_common.c | 6 ++++++ standard/appspawn_service.c | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/common/appspawn_common.c b/modules/common/appspawn_common.c index 02eeef35..8cbfef32 100644 --- a/modules/common/appspawn_common.c +++ b/modules/common/appspawn_common.c @@ -226,6 +226,12 @@ static int SetXpmConfig(const AppSpawnMgr *content, const AppSpawningCtx *proper static int SetUidGid(const AppSpawnMgr *content, const AppSpawningCtx *property) { + if (IsAppSpawnMode(content)) { + struct sched_param param = { 0 }; + param.sched_priority = 0; + int ret = sched_setscheduler(0, SCHED_OTHER, ¶m); + APPSPAWN_CHECK_ONLY_LOG(ret == 0, "UpdateSchedPrio failed ret: %{public}d, %{public}d", ret, errno); + } AppSpawnMsgDacInfo *dacInfo = (AppSpawnMsgDacInfo *)GetAppProperty(property, TLV_DAC_INFO); APPSPAWN_CHECK(dacInfo != NULL, return APPSPAWN_TLV_NONE, "No tlv %{public}d in msg %{public}s", TLV_DAC_INFO, GetProcessName(property)); diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 69584370..440665d6 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -29,7 +29,7 @@ #include #include #include - +#include #include "appspawn.h" #include "appspawn_hook.h" #include "appspawn_modulemgr.h" @@ -1182,6 +1182,12 @@ static void AppSpawnRun(AppSpawnContent *content, int argc, char *const argv[]) (void)LE_AddSignal(LE_GetDefaultLoop(), appSpawnContent->sigHandler, SIGTERM); } + if (IsAppSpawnMode(appSpawnContent)) { + struct sched_param param = { 0 }; + param.sched_priority = 1; + int ret = sched_setscheduler(0, SCHED_FIFO, ¶m); + APPSPAWN_CHECK_ONLY_LOG(ret == 0, "UpdateSchedPrio failed ret: %{public}d, %{public}d", ret, errno); + } LE_RunLoop(LE_GetDefaultLoop()); APPSPAWN_LOGI("AppSpawnRun exit mode: %{public}d ", content->mode); -- Gitee From 67904dc4f822c7239f8fbf02d214d87780b6fec7 Mon Sep 17 00:00:00 2001 From: fan-jingle Date: Wed, 6 Nov 2024 15:06:20 +0800 Subject: [PATCH 018/148] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E4=B8=8D?= =?UTF-8?q?=E8=A7=84=E8=8C=83fuzz=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fan-jingle --- test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp b/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp index 84749c88..e7a0d766 100644 --- a/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp +++ b/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp @@ -282,7 +282,7 @@ namespace OHOS { int FuzzGetPermissionByIndex(const uint8_t *data, size_t size) { - int32_t index = static_cast(size); + int32_t index = *(reinterpret_cast(data)); if (GetPermissionByIndex(nullptr, index) == nullptr) { return -1; } -- Gitee From ec2927c82df0721392903793efc98c7129b67688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=85=B6=E6=96=87?= Date: Wed, 6 Nov 2024 20:17:47 +0800 Subject: [PATCH 019/148] =?UTF-8?q?Appspawn=E8=B8=A2=E7=8B=97UT=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E5=A4=B1=E8=B4=A5=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈其文 --- standard/appspawn_kickdog.c | 2 +- test/mock/app_spawn_stub.h | 1 + .../unittest/app_spawn_standard_test/app_spawn_kickdog_test.cpp | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/standard/appspawn_kickdog.c b/standard/appspawn_kickdog.c index b41c2ba6..00da55ac 100644 --- a/standard/appspawn_kickdog.c +++ b/standard/appspawn_kickdog.c @@ -120,7 +120,7 @@ static int CheckKernelType(bool *isLinux) return 0; } -static int SpawnKickDogStart(AppSpawnMgr *mgrContent) +APPSPAWN_STATIC int SpawnKickDogStart(AppSpawnMgr *mgrContent) { APPSPAWN_CHECK(mgrContent != NULL, return 0, "content is null"); APPSPAWN_CHECK((mgrContent->content.mode == MODE_FOR_APP_SPAWN) || diff --git a/test/mock/app_spawn_stub.h b/test/mock/app_spawn_stub.h index 144e601a..e8e4065b 100644 --- a/test/mock/app_spawn_stub.h +++ b/test/mock/app_spawn_stub.h @@ -112,6 +112,7 @@ int RunBegetctlBootApp(AppSpawnMgr *content, AppSpawningCtx *property); void SetSystemEnv(void); void RunAppSandbox(const char *ptyName); HOOK_MGR *GetAppSpawnHookMgr(void); +int SpawnKickDogStart(AppSpawnMgr *mgrContent); #define STUB_NEED_CHECK 0x01 typedef int (*ExecvFunc)(const char *pathname, char *const argv[]); enum { 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 27fda591..7b7760b3 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 @@ -99,6 +99,7 @@ HWTEST_F(AppSpawnKickDogTest, App_Spawn_AppSpawnKickDog_001, TestSize.Level0) std::unique_ptr testServer = std::make_unique("appspawn -mode appspawn"); + AddPreloadHook(HOOK_PRIO_COMMON, SpawnKickDogStart); testServer->Start(nullptr); if (CheckDeviceInLinux()) { EXPECT_EQ(CheckFileContent(HM_APPSPAWN_WATCHDOG_FILE, LINUX_APPSPAWN_WATCHDOG_ON), 0); @@ -139,6 +140,7 @@ HWTEST_F(AppSpawnKickDogTest, App_Spawn_AppSpawnKickDog_002, TestSize.Level0) std::unique_ptr testServer = std::make_unique("appspawn -mode nwebspawn"); + AddPreloadHook(HOOK_PRIO_COMMON, SpawnKickDogStart); testServer->Start(nullptr); if (CheckDeviceInLinux()) { EXPECT_EQ(CheckFileContent(HM_APPSPAWN_WATCHDOG_FILE, LINUX_APPSPAWN_WATCHDOG_ON), 0); -- Gitee From d4f36cdeb4e2f647b7c058dd6192edb26ae6060c Mon Sep 17 00:00:00 2001 From: wangfeng Date: Wed, 6 Nov 2024 17:07:48 +0800 Subject: [PATCH 020/148] /storage/Users/currentUser/appdata mount again Signed-off-by: wangfeng --- appdata-sandbox.json | 62 +-------------- modules/sandbox/sandbox_utils.cpp | 127 +++++++++++++++++++++++++++++- util/include/appspawn_utils.h | 7 +- 3 files changed, 132 insertions(+), 64 deletions(-) diff --git a/appdata-sandbox.json b/appdata-sandbox.json index 9be9213f..41c21906 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -638,37 +638,11 @@ "sandbox-path": "/storage/External", "sandbox-flags": [ "bind", "rec" ] }, - { - "src-path": "/storage/media//local/files/Docs", - "sandbox-path": "/storage/Users/", - "sandbox-flags": [ "bind", "rec" ] - }, { "src-path": "/storage/media//local/files/.Recent", "sandbox-path": "/storage/Users//.Recent", "sandbox-flags": [ "bind", "rec" ] }, - { - "src-path": "/data/app/el1//base", - "sandbox-path": "/storage/Users//appdata/el1/base", - "sandbox-flags-customized": ["MS_NODEV"], - "dac-override-sensitive": "true", - "fs-type": "sharefs", - "options": "override" - }, - { - "src-path": "/data/app/el2//base", - "sandbox-path": "/storage/Users//appdata/el2/base", - "sandbox-flags-customized": ["MS_NODEV"], - "dac-override-sensitive": "true", - "fs-type": "sharefs", - "options": "override" - }, - { - "src-path": "/mnt/hmdfs//account/merge_view/data", - "sandbox-path": "/storage/Users//appdata/el2/distributedfiles", - "sandbox-flags": [ "bind", "rec" ] - }, { "src-path": "/mnt/data//hmdfs", "sandbox-path": "/storage/hmdfs", @@ -689,32 +663,6 @@ "ohos.permission.FILE_CROSS_APP":[{ "sandbox-switch": "ON", "mount-paths": [{ - "src-path": "/storage/media//local/files/Docs", - "sandbox-path": "/storage/Users/", - "sandbox-flags": [ "bind", "rec" ] - }, - { - "src-path": "/data/app/el1//base", - "sandbox-path": "/storage/Users//appdata/el1", - "sandbox-flags-customized": ["MS_NODEV"], - "dac-override-sensitive": "true", - "fs-type": "sharefs", - "options": "override" - }, - { - "src-path": "/data/app/el2//base", - "sandbox-path": "/storage/Users//appdata/el2", - "sandbox-flags-customized": ["MS_NODEV"], - "dac-override-sensitive": "true", - "fs-type": "sharefs", - "options": "override" - }, - { - "src-path": "/data/service/el1/public/storage_daemon/share/public", - "sandbox-path": "/storage/Share", - "sandbox-flags": [ "bind", "rec" ] - }, - { "src-path": "/mnt/data/external", "sandbox-path": "/storage/External", "sandbox-flags": [ "bind", "rec" ] @@ -723,15 +671,7 @@ }], "ohos.permission.FILE_ACCESS_COMMON_DIR":[{ "sandbox-switch": "ON", - "mount-paths": [{ - "src-path": "/storage/media//local/files/Docs", - "sandbox-path": "/storage/Users/currentUser", - "sandbox-flags": [ "MS_NODEV" ], - "dac-override-sensitive": "true", - "fs-type": "sharefs", - "options": "override" - } - ] + "mount-paths": [] }], "ohos.permission.ACTIVATE_THEME_PACKAGE":[{ "sandbox-switch": "ON", diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 3fbe7d26..d6b3aadd 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -1895,9 +1895,132 @@ static const MountSharedTemplate MOUNT_SHARED_MAP[] = { {"/data/storage/el3", nullptr}, {"/data/storage/el4", nullptr}, {"/data/storage/el5", "ohos.permission.PROTECT_SCREEN_LOCK_DATA"}, - {"/storage/Users", "ohos.permission.FILE_ACCESS_MANAGER"}, }; +#define PATH_MAX_LEN 256 +static int MountInShared(const AppSpawningCtx *property, const char *rootPath, const char *src, const char *target) +{ + AppDacInfo *info = reinterpret_cast(GetAppProperty(property, TLV_DAC_INFO)); + const char *bundleName = GetBundleName(property); + if (info == NULL || bundleName == NULL) { + return APPSPAWN_ARG_INVALID; + } + + char path[PATH_MAX_LEN] = {0}; + int ret = snprintf_s(path, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s%u/%s%s", rootPath, info->uid / UID_BASE, + bundleName, target); + if (ret <= 0) { + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + if (access(path, F_OK) == 0) { + return 0; + } + + ret = MakeDirRec(path, DIR_MODE, 1); + if (ret != 0) { + return APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL; + } + + if (mount(src, path, nullptr, MS_BIND | MS_REC, nullptr) != 0) { + APPSPAWN_LOGI("bind mount %{public}s to %{public}s failed, error %{public}d", src, path, errno); + return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; + } + if (mount(nullptr, path, nullptr, MS_SHARED, nullptr) != 0) { + APPSPAWN_LOGI("mount path %{public}s to shared failed, errno %{public}d", path, errno); + return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; + } + + return 0; +} + +static int SharedMountInSharefs(const AppSpawningCtx *property, const char *rootPath, + const char *src, const char *target) +{ + AppDacInfo *info = reinterpret_cast(GetAppProperty(property, TLV_DAC_INFO)); + if (info == NULL) { + return APPSPAWN_ARG_INVALID; + } + + if (access(target, F_OK) == 0) { + return 0; + } + + int ret = MakeDirRec(target, DIR_MODE, 1); + if (ret != 0) { + return APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL; + } + + char options[PATH_MAX_LEN] = {0}; + ret = snprintf_s(options, PATH_MAX_LEN, PATH_MAX_LEN - 1, "override_support_delete,user_id=%d", + info->uid / UID_BASE); + if (ret <= 0) { + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + if (mount(src, target, "sharefs", MS_NODEV, options) != 0) { + APPSPAWN_LOGE("sharefs mount %{public}s to %{public}s failed, error %{public}d", + src, target, errno); + return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; + } + if (mount(nullptr, target, nullptr, MS_SHARED, nullptr) != 0) { + APPSPAWN_LOGE("mount path %{public}s to shared failed, errno %{public}d", target, errno); + return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; + } + + return 0; +} + +static void UpdateStorageDir(const AppSpawningCtx *property) +{ + const char mntUser[] = "/mnt/user"; + const char nosharefsDocs[] = "nosharefs/docs"; + const char sharefsDocs[] = "sharefs/docs"; + const char rootPath[] = "/mnt/sandbox"; + const char userPath[] = "/storage/Users"; + + AppDacInfo *info = reinterpret_cast(GetAppProperty(property, TLV_DAC_INFO)); + if (info == nullptr) { + return; + } + + /* /mnt/user//nosharefs/Docs */ + char nosharefsDocsDir[PATH_MAX_LEN] = {0}; + int ret = snprintf_s(nosharefsDocsDir, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%d/%s", + mntUser, info->uid / UID_BASE, nosharefsDocs); + if (ret <= 0) { + return; + } + + /* /mnt/user//sharefs/Docs */ + char sharefsDocsDir[PATH_MAX_LEN] = {0}; + ret = snprintf_s(sharefsDocsDir, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%d/%s", + mntUser, info->uid / UID_BASE, sharefsDocs); + if (ret <= 0) { + return; + } + + int index = GetPermissionIndex(nullptr, "ohos.permission.FILE_ACCESS_MANAGER"); + int res = CheckAppPermissionFlagSet(property, static_cast(index)); + if (res == 0) { + char storageUserPath[PATH_MAX_LEN] = {0}; + const char *bundleName = GetBundleName(property); + ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%d/%s%s", rootPath, info->uid / UID_BASE, + bundleName, userPath); + if (ret <= 0) { + return; + } + /* mount /mnt/user//sharefs/docs to /mnt/sandbox///storage/Users */ + ret = SharedMountInSharefs(property, rootPath, sharefsDocsDir, storageUserPath); + } else { + /* mount /mnt/user//nosharefs/docs to /mnt/sandbox///storage/Users */ + ret = MountInShared(property, rootPath, nosharefsDocsDir, userPath); + } + if (ret != 0) { + APPSPAWN_LOGE("Update storage dir, ret %{public}d", ret); + } +} + static void MountDirToShared(const AppSpawningCtx *property) { const char rootPath[] = "/mnt/sandbox/"; @@ -1909,6 +2032,8 @@ static void MountDirToShared(const AppSpawningCtx *property) return; } + UpdateStorageDir(property); + string sourcePath = "/data/app/el1/bundle/public/" + string(bundleName); MountDir(property, rootPath, sourcePath.c_str(), el1Path); size_t bundleNameLen = strlen(bundleName); diff --git a/util/include/appspawn_utils.h b/util/include/appspawn_utils.h index 17f8b936..b8913790 100755 --- a/util/include/appspawn_utils.h +++ b/util/include/appspawn_utils.h @@ -122,11 +122,14 @@ typedef enum { APPSPAWN_DEBUG_MODE_NOT_SUPPORT, APPSPAWN_ERROR_UTILS_MEM_FAIL, APPSPAWN_ERROR_FILE_RMDIR_FAIL, - APPSPAWN_SANDBOX_ERROR_SET_PERMISSION_FLAG_FAIL, + APPSPAWN_PIDMGR_DEFAULT_PID_MAX, APPSPAWN_ERROR_UTILS_DECODE_JSON_FAIL, APPSPAWN_ERROR_UTILS_CREATE_JSON_FAIL, APPSPAWN_ERROR_UTILS_ADD_JSON_FAIL, - APPSPAWN_PIDMGR_DEFAULT_PID_MAX, + /* sandbox errno num */ + APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL, + APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL, + APPSPAWN_SANDBOX_ERROR_SET_PERMISSION_FLAG_FAIL, APPSPAWN_NODE_EXIST, } AppSpawnErrorCode; -- Gitee From 7af896136bc301d19ca1d380b30440f43d6408d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Thu, 7 Nov 2024 14:38:22 +0800 Subject: [PATCH 021/148] =?UTF-8?q?hnp=E5=AE=89=E8=A3=85=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=A9=BF=E9=80=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- service/hnp/installer/src/hnp_installer.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service/hnp/installer/src/hnp_installer.c b/service/hnp/installer/src/hnp_installer.c index 64a4a9e3..83ffddab 100644 --- a/service/hnp/installer/src/hnp_installer.c +++ b/service/hnp/installer/src/hnp_installer.c @@ -375,6 +375,10 @@ static int HnpInstallPathGet(HnpCfgInfo *hnpCfgInfo, HnpInstallInfo *hnpInfo) HNP_LOGE("hnp install sprintf install path unsuccess."); return HNP_ERRNO_BASE_SPRINTF_FAILED; } + if (strstr(hnpInfo->hnpVersionPath, "../")) { + HNP_LOGE("hnp version path[%{public}s], does not allow the use of ../", hnpInfo->hnpVersionPath); + return HNP_ERRNO_INSTALLER_GET_HNP_PATH_FAILED; + } return 0; } -- Gitee From b2852b486cebed3e8e15b0309aab7d3ccc80047b Mon Sep 17 00:00:00 2001 From: wangfeng Date: Thu, 7 Nov 2024 15:15:01 +0800 Subject: [PATCH 022/148] fix:max pid count Signed-off-by: wangfeng --- modules/common/appspawn_encaps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/common/appspawn_encaps.c b/modules/common/appspawn_encaps.c index 4e93ed72..60a40b05 100644 --- a/modules/common/appspawn_encaps.c +++ b/modules/common/appspawn_encaps.c @@ -117,7 +117,7 @@ static int SpawnSetMaxPids(AppSpawnMgr *content, AppSpawningCtx *property, cJSON return APPSPAWN_PIDMGR_DEFAULT_PID_MAX; } - if (cJSON_AddNumberToObject(encaps, APP_OHOS_ENCAPS_COUNT_KEY, maxPidCount) == NULL) { + if (cJSON_AddNumberToObject(encaps, APP_OHOS_ENCAPS_FORK_KEY, maxPidCount) == NULL) { APPSPAWN_LOGV("Add number to object failed.(ignore)"); return APPSPAWN_PIDMGR_DEFAULT_PID_MAX; } -- Gitee From 01b31d1e53a342633f5e602248eee17730f40120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Thu, 7 Nov 2024 17:29:07 +0800 Subject: [PATCH 023/148] =?UTF-8?q?hnp=E5=AE=89=E8=A3=85=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=E6=96=87=E4=BB=B6=E6=95=B0=E9=87=8F=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E7=BF=BB=E8=BD=AC=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- service/hnp/base/hnp_base.h | 5 ++-- service/hnp/base/hnp_zip.c | 10 +++---- service/hnp/installer/include/hnp_installer.h | 3 +++ service/hnp/installer/src/hnp_installer.c | 26 ++++++++++--------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/service/hnp/base/hnp_base.h b/service/hnp/base/hnp_base.h index 1f577890..d1bc8630 100644 --- a/service/hnp/base/hnp_base.h +++ b/service/hnp/base/hnp_base.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -264,7 +265,7 @@ int GetRealPath(char *srcPath, char *realPath); int HnpZip(const char *inputDir, zipFile zf); int HnpUnZip(const char *inputFile, const char *outputDir, const char *hnpSignKeyPrefix, - HnpSignMapInfo *hnpSignMapInfos, int *count); + HnpSignMapInfo *hnpSignMapInfos, uint64_t *count); int HnpAddFileToZip(zipFile zf, char *filename, char *buff, int size); @@ -297,7 +298,7 @@ int HnpPackageInfoDelete(const char *packageName); char *HnpCurrentVersionUninstallCheck(const char *name); -int HnpFileCountGet(const char *path, int *count); +int HnpFileCountGet(const char *path, uint64_t *count); int HnpPathFileCount(const char *path); diff --git a/service/hnp/base/hnp_zip.c b/service/hnp/base/hnp_zip.c index 937265b9..89c7b856 100644 --- a/service/hnp/base/hnp_zip.c +++ b/service/hnp/base/hnp_zip.c @@ -362,10 +362,10 @@ static bool HnpELFFileCheck(const char *path) } static int HnpInstallAddSignMap(const char* hnpSignKeyPrefix, const char *key, const char *value, - HnpSignMapInfo *hnpSignMapInfos, int *count) + HnpSignMapInfo *hnpSignMapInfos, uint64_t *count) { int ret; - int sum = *count; + uint64_t sum = *count; if (HnpELFFileCheck(value) == false) { return 0; @@ -387,9 +387,9 @@ static int HnpInstallAddSignMap(const char* hnpSignKeyPrefix, const char *key, c return 0; } -int HnpFileCountGet(const char *path, int *count) +int HnpFileCountGet(const char *path, uint64_t *count) { - int sum = 0; + uint64_t sum = 0; unzFile zipFile = unzOpen(path); if (zipFile == NULL) { @@ -416,7 +416,7 @@ int HnpFileCountGet(const char *path, int *count) } int HnpUnZip(const char *inputFile, const char *outputDir, const char *hnpSignKeyPrefix, - HnpSignMapInfo *hnpSignMapInfos, int *count) + HnpSignMapInfo *hnpSignMapInfos, uint64_t *count) { char fileName[MAX_FILE_PATH_LEN]; unz_file_info fileInfo; diff --git a/service/hnp/installer/include/hnp_installer.h b/service/hnp/installer/include/hnp_installer.h index 411e8727..1da01a86 100644 --- a/service/hnp/installer/include/hnp_installer.h +++ b/service/hnp/installer/include/hnp_installer.h @@ -43,6 +43,9 @@ extern "C" { // 0x801307 restorecon 安装目录失败 #define HNP_ERRNO_INSTALLER_RESTORECON_HNP_PATH_FAIL HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x7) +// 0x801308 安装包中的二进制文件过多 +#define HNP_ERRNO_INSTALLER_HAP_FILE_COUNT_OVER HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x8) + #define HNP_DEFAULT_INSTALL_ROOT_PATH "/data/app/el1/bundle" #define HNP_SANDBOX_BASE_PATH "/data/service/hnp" diff --git a/service/hnp/installer/src/hnp_installer.c b/service/hnp/installer/src/hnp_installer.c index 83ffddab..c08891a9 100644 --- a/service/hnp/installer/src/hnp_installer.c +++ b/service/hnp/installer/src/hnp_installer.c @@ -183,7 +183,7 @@ static int HnpGenerateSoftLink(const char *installPath, const char *hnpBasePath, } static int HnpInstall(const char *hnpFile, HnpInstallInfo *hnpInfo, HnpCfgInfo *hnpCfg, - HnpSignMapInfo *hnpSignMapInfos, int *count) + HnpSignMapInfo *hnpSignMapInfos, uint64_t *count) { int ret; @@ -401,7 +401,7 @@ static int HnpPublicDealAfterInstall(HnpInstallInfo *hnpInfo, HnpCfgInfo *hnpCfg return HnpInstallInfoJsonWrite(hnpInfo->hapInstallInfo->hapPackageName, hnpCfg); } -static int HnpReadAndInstall(char *srcFile, HnpInstallInfo *hnpInfo, HnpSignMapInfo *hnpSignMapInfos, int *count) +static int HnpReadAndInstall(char *srcFile, HnpInstallInfo *hnpInfo, HnpSignMapInfo *hnpSignMapInfos, uint64_t *count) { int ret; HnpCfgInfo hnpCfg = {0}; @@ -481,7 +481,7 @@ static bool HnpFileCheck(const char *file) } static int HnpPackageGetAndInstall(const char *dirPath, HnpInstallInfo *hnpInfo, char *sunDir, - HnpSignMapInfo *hnpSignMapInfos, int *count) + HnpSignMapInfo *hnpSignMapInfos, uint64_t *count) { DIR *dir; struct dirent *entry; @@ -537,7 +537,7 @@ static int HnpPackageGetAndInstall(const char *dirPath, HnpInstallInfo *hnpInfo, } static int HapReadAndInstall(const char *dstPath, HapInstallInfo *installInfo, HnpSignMapInfo *hnpSignMapInfos, - int *count) + uint64_t *count) { struct dirent *entry; char hnpPath[MAX_FILE_PATH_LEN]; @@ -585,7 +585,7 @@ static int HapReadAndInstall(const char *dstPath, HapInstallInfo *installInfo, H return 0; } -static int HnpInstallHnpFileCountGet(char *hnpPath, int *count) +static int HnpInstallHnpFileCountGet(char *hnpPath, uint64_t *count) { DIR *dir; struct dirent *entry; @@ -636,7 +636,7 @@ static int HnpInstallHnpFileCountGet(char *hnpPath, int *count) return 0; } -static int HnpInstallHapFileCountGet(const char *root, int *count) +static int HnpInstallHapFileCountGet(const char *root, uint64_t *count) { struct dirent *entry; char hnpPath[MAX_FILE_PATH_LEN]; @@ -714,11 +714,11 @@ static int CheckInstallPath(char *dstPath, HapInstallInfo *installInfo) static int HnpInsatllPre(HapInstallInfo *installInfo) { char dstPath[MAX_FILE_PATH_LEN]; - int count = 0; + uint64_t count = 0; HnpSignMapInfo *hnpSignMapInfos = NULL; #ifdef CODE_SIGNATURE_ENABLE struct EntryMapEntryData data = {0}; - int i; + uint64_t i; #endif int ret; @@ -727,7 +727,9 @@ static int HnpInsatllPre(HapInstallInfo *installInfo) return ret; } - if (count > 0) { + if (count >= INT32_MAX) { + return HNP_ERRNO_INSTALLER_HAP_FILE_COUNT_OVER; + } else if (count > 0) { hnpSignMapInfos = (HnpSignMapInfo *)malloc(sizeof(HnpSignMapInfo) * count); if (hnpSignMapInfos == NULL) { return HNP_ERRNO_NOMEM; @@ -736,8 +738,8 @@ static int HnpInsatllPre(HapInstallInfo *installInfo) count = 0; ret = HapReadAndInstall(dstPath, installInfo, hnpSignMapInfos, &count); - HNP_LOGI("sign start hap path[%{public}s],abi[%{public}s],count=%{public}d", installInfo->hapPath, installInfo->abi, - count); + HNP_LOGI("sign start hap path[%{public}s],abi[%{public}s],count=%{public}d", installInfo->hapPath, + installInfo->abi, (int)count); #ifdef CODE_SIGNATURE_ENABLE if ((ret == 0) && (count > 0)) { data.entries = malloc(sizeof(struct EntryMapEntry) * count); @@ -749,7 +751,7 @@ static int HnpInsatllPre(HapInstallInfo *installInfo) data.entries[i].key = hnpSignMapInfos[i].key; data.entries[i].value = hnpSignMapInfos[i].value; } - data.count = count; + data.count = (uint32_t)count; ret = EnforceCodeSignForApp(installInfo->hapPath, &data, FILE_ENTRY_ONLY); HNP_LOGI("sign end ret=%{public}d,last key[%{public}s],value[%{public}s]", ret, data.entries[i - 1].key, data.entries[i - 1].value); -- Gitee From a15f12db669499f673771826a5ac85a6b2b33d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Thu, 7 Nov 2024 22:45:09 +0800 Subject: [PATCH 024/148] =?UTF-8?q?hnp=E5=AE=89=E8=A3=85=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=E6=96=87=E4=BB=B6=E6=95=B0=E9=87=8F=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E7=BF=BB=E8=BD=AC=E7=9A=84=E9=97=AE=E9=A2=98=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- service/hnp/base/hnp_base.h | 8 +++--- service/hnp/base/hnp_zip.c | 17 ++++++++---- service/hnp/installer/include/hnp_installer.h | 3 --- service/hnp/installer/src/hnp_installer.c | 26 +++++++++---------- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/service/hnp/base/hnp_base.h b/service/hnp/base/hnp_base.h index d1bc8630..0527a9d1 100644 --- a/service/hnp/base/hnp_base.h +++ b/service/hnp/base/hnp_base.h @@ -18,7 +18,6 @@ #include #include -#include #include #include @@ -256,6 +255,9 @@ enum { // 0x80111f 获取文件属性失败 #define HNP_ERRNO_BASE_STAT_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x1f) +// 0x801120 二进制文件过多 +#define HNP_ERRNO_BASE_FILE_COUNT_OVER HNP_ERRNO_COMMON(HNP_MID_BASE, 0x20) + int GetFileSizeByHandle(FILE *file, int *size); int ReadFileToStream(const char *filePath, char **stream, int *streamLen); @@ -265,7 +267,7 @@ int GetRealPath(char *srcPath, char *realPath); int HnpZip(const char *inputDir, zipFile zf); int HnpUnZip(const char *inputFile, const char *outputDir, const char *hnpSignKeyPrefix, - HnpSignMapInfo *hnpSignMapInfos, uint64_t *count); + HnpSignMapInfo *hnpSignMapInfos, int *count); int HnpAddFileToZip(zipFile zf, char *filename, char *buff, int size); @@ -298,7 +300,7 @@ int HnpPackageInfoDelete(const char *packageName); char *HnpCurrentVersionUninstallCheck(const char *name); -int HnpFileCountGet(const char *path, uint64_t *count); +int HnpFileCountGet(const char *path, int *count); int HnpPathFileCount(const char *path); diff --git a/service/hnp/base/hnp_zip.c b/service/hnp/base/hnp_zip.c index 89c7b856..ad7a5762 100644 --- a/service/hnp/base/hnp_zip.c +++ b/service/hnp/base/hnp_zip.c @@ -362,10 +362,10 @@ static bool HnpELFFileCheck(const char *path) } static int HnpInstallAddSignMap(const char* hnpSignKeyPrefix, const char *key, const char *value, - HnpSignMapInfo *hnpSignMapInfos, uint64_t *count) + HnpSignMapInfo *hnpSignMapInfos, int *count) { int ret; - uint64_t sum = *count; + int sum = *count; if (HnpELFFileCheck(value) == false) { return 0; @@ -387,9 +387,9 @@ static int HnpInstallAddSignMap(const char* hnpSignKeyPrefix, const char *key, c return 0; } -int HnpFileCountGet(const char *path, uint64_t *count) +int HnpFileCountGet(const char *path, int *count) { - uint64_t sum = 0; + int sum = 0; unzFile zipFile = unzOpen(path); if (zipFile == NULL) { @@ -399,6 +399,10 @@ int HnpFileCountGet(const char *path, uint64_t *count) int ret = unzGoToFirstFile(zipFile); while (ret == UNZ_OK) { + if (sum == INT_MAX) { + unzClose(zipFile); + return HNP_ERRNO_BASE_FILE_COUNT_OVER; + } sum++; ret = unzGetCurrentFileInfo(zipFile, NULL, NULL, 0, NULL, 0, NULL, 0); if (ret != UNZ_OK) { @@ -411,12 +415,15 @@ int HnpFileCountGet(const char *path, uint64_t *count) } unzClose(zipFile); + if (INT_MAX - sum < *count) { + return HNP_ERRNO_BASE_FILE_COUNT_OVER; + } *count += sum; return 0; } int HnpUnZip(const char *inputFile, const char *outputDir, const char *hnpSignKeyPrefix, - HnpSignMapInfo *hnpSignMapInfos, uint64_t *count) + HnpSignMapInfo *hnpSignMapInfos, int *count) { char fileName[MAX_FILE_PATH_LEN]; unz_file_info fileInfo; diff --git a/service/hnp/installer/include/hnp_installer.h b/service/hnp/installer/include/hnp_installer.h index 1da01a86..411e8727 100644 --- a/service/hnp/installer/include/hnp_installer.h +++ b/service/hnp/installer/include/hnp_installer.h @@ -43,9 +43,6 @@ extern "C" { // 0x801307 restorecon 安装目录失败 #define HNP_ERRNO_INSTALLER_RESTORECON_HNP_PATH_FAIL HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x7) -// 0x801308 安装包中的二进制文件过多 -#define HNP_ERRNO_INSTALLER_HAP_FILE_COUNT_OVER HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x8) - #define HNP_DEFAULT_INSTALL_ROOT_PATH "/data/app/el1/bundle" #define HNP_SANDBOX_BASE_PATH "/data/service/hnp" diff --git a/service/hnp/installer/src/hnp_installer.c b/service/hnp/installer/src/hnp_installer.c index c08891a9..83ffddab 100644 --- a/service/hnp/installer/src/hnp_installer.c +++ b/service/hnp/installer/src/hnp_installer.c @@ -183,7 +183,7 @@ static int HnpGenerateSoftLink(const char *installPath, const char *hnpBasePath, } static int HnpInstall(const char *hnpFile, HnpInstallInfo *hnpInfo, HnpCfgInfo *hnpCfg, - HnpSignMapInfo *hnpSignMapInfos, uint64_t *count) + HnpSignMapInfo *hnpSignMapInfos, int *count) { int ret; @@ -401,7 +401,7 @@ static int HnpPublicDealAfterInstall(HnpInstallInfo *hnpInfo, HnpCfgInfo *hnpCfg return HnpInstallInfoJsonWrite(hnpInfo->hapInstallInfo->hapPackageName, hnpCfg); } -static int HnpReadAndInstall(char *srcFile, HnpInstallInfo *hnpInfo, HnpSignMapInfo *hnpSignMapInfos, uint64_t *count) +static int HnpReadAndInstall(char *srcFile, HnpInstallInfo *hnpInfo, HnpSignMapInfo *hnpSignMapInfos, int *count) { int ret; HnpCfgInfo hnpCfg = {0}; @@ -481,7 +481,7 @@ static bool HnpFileCheck(const char *file) } static int HnpPackageGetAndInstall(const char *dirPath, HnpInstallInfo *hnpInfo, char *sunDir, - HnpSignMapInfo *hnpSignMapInfos, uint64_t *count) + HnpSignMapInfo *hnpSignMapInfos, int *count) { DIR *dir; struct dirent *entry; @@ -537,7 +537,7 @@ static int HnpPackageGetAndInstall(const char *dirPath, HnpInstallInfo *hnpInfo, } static int HapReadAndInstall(const char *dstPath, HapInstallInfo *installInfo, HnpSignMapInfo *hnpSignMapInfos, - uint64_t *count) + int *count) { struct dirent *entry; char hnpPath[MAX_FILE_PATH_LEN]; @@ -585,7 +585,7 @@ static int HapReadAndInstall(const char *dstPath, HapInstallInfo *installInfo, H return 0; } -static int HnpInstallHnpFileCountGet(char *hnpPath, uint64_t *count) +static int HnpInstallHnpFileCountGet(char *hnpPath, int *count) { DIR *dir; struct dirent *entry; @@ -636,7 +636,7 @@ static int HnpInstallHnpFileCountGet(char *hnpPath, uint64_t *count) return 0; } -static int HnpInstallHapFileCountGet(const char *root, uint64_t *count) +static int HnpInstallHapFileCountGet(const char *root, int *count) { struct dirent *entry; char hnpPath[MAX_FILE_PATH_LEN]; @@ -714,11 +714,11 @@ static int CheckInstallPath(char *dstPath, HapInstallInfo *installInfo) static int HnpInsatllPre(HapInstallInfo *installInfo) { char dstPath[MAX_FILE_PATH_LEN]; - uint64_t count = 0; + int count = 0; HnpSignMapInfo *hnpSignMapInfos = NULL; #ifdef CODE_SIGNATURE_ENABLE struct EntryMapEntryData data = {0}; - uint64_t i; + int i; #endif int ret; @@ -727,9 +727,7 @@ static int HnpInsatllPre(HapInstallInfo *installInfo) return ret; } - if (count >= INT32_MAX) { - return HNP_ERRNO_INSTALLER_HAP_FILE_COUNT_OVER; - } else if (count > 0) { + if (count > 0) { hnpSignMapInfos = (HnpSignMapInfo *)malloc(sizeof(HnpSignMapInfo) * count); if (hnpSignMapInfos == NULL) { return HNP_ERRNO_NOMEM; @@ -738,8 +736,8 @@ static int HnpInsatllPre(HapInstallInfo *installInfo) count = 0; ret = HapReadAndInstall(dstPath, installInfo, hnpSignMapInfos, &count); - HNP_LOGI("sign start hap path[%{public}s],abi[%{public}s],count=%{public}d", installInfo->hapPath, - installInfo->abi, (int)count); + HNP_LOGI("sign start hap path[%{public}s],abi[%{public}s],count=%{public}d", installInfo->hapPath, installInfo->abi, + count); #ifdef CODE_SIGNATURE_ENABLE if ((ret == 0) && (count > 0)) { data.entries = malloc(sizeof(struct EntryMapEntry) * count); @@ -751,7 +749,7 @@ static int HnpInsatllPre(HapInstallInfo *installInfo) data.entries[i].key = hnpSignMapInfos[i].key; data.entries[i].value = hnpSignMapInfos[i].value; } - data.count = (uint32_t)count; + data.count = count; ret = EnforceCodeSignForApp(installInfo->hapPath, &data, FILE_ENTRY_ONLY); HNP_LOGI("sign end ret=%{public}d,last key[%{public}s],value[%{public}s]", ret, data.entries[i - 1].key, data.entries[i - 1].value); -- Gitee From cbb5b6feccf2ab7f545dbbc96ca1df26d4284701 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Fri, 8 Nov 2024 16:44:04 +0800 Subject: [PATCH 025/148] fix: flags-point mount bug Signed-off-by: wangfeng --- modules/sandbox/sandbox_utils.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index c31999a9..c24c44fb 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -985,8 +985,12 @@ int32_t SandboxUtils::HandleFlagsPoint(const AppSpawningCtx *appProperty, if (flagPoint.find(g_flags) != flagPoint.end() && flagPoint[g_flags].is_string()) { std::string flagsStr = flagPoint[g_flags].get(); uint32_t flag = ConvertFlagStr(flagsStr); - if ((GetAppMsgFlags(appProperty) & flag) != 0) { - return DoAllMntPointsMount(appProperty, flagPoint, nullptr, g_flagePoint); + if ((GetAppMsgFlags(appProperty) & flag) == 0) { + continue; + } + int ret = DoAllMntPointsMount(appProperty, flagPoint, nullptr, g_flagePoint); + if (ret != 0) { + APPSPAWN_LOGE("mount flag points failed"); } } else { APPSPAWN_LOGE("read flags config failed, app name is %{public}s", GetBundleName(appProperty)); @@ -1908,7 +1912,7 @@ static int MountInShared(const AppSpawningCtx *property, const char *rootPath, c } char path[PATH_MAX_LEN] = {0}; - int ret = snprintf_s(path, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s%u/%s%s", rootPath, info->uid / UID_BASE, + int ret = snprintf_s(path, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%u/%s/%s", rootPath, info->uid / UID_BASE, bundleName, target); if (ret <= 0) { return APPSPAWN_ERROR_UTILS_MEM_FAIL; @@ -2006,7 +2010,7 @@ static void UpdateStorageDir(const AppSpawningCtx *property) if (res == 0) { char storageUserPath[PATH_MAX_LEN] = {0}; const char *bundleName = GetBundleName(property); - ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%d/%s%s", rootPath, info->uid / UID_BASE, + ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%d/%s/%s", rootPath, info->uid / UID_BASE, bundleName, userPath); if (ret <= 0) { return; -- Gitee From f4f32e6d1f76f54094bceb2493eed71aebd1e36d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Sat, 9 Nov 2024 09:44:04 +0800 Subject: [PATCH 026/148] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E4=B8=8D?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- test/appspawn_hap_test/AppScope/app.json5 | 25 -- .../resources/base/element/string.json | 8 - .../resources/base/media/app_icon.png | Bin 6790 -> 0 bytes test/appspawn_hap_test/LICENSE | 78 ------ test/appspawn_hap_test/build-profile.json5 | 42 ---- .../entry/build-profile.json5 | 29 --- test/appspawn_hap_test/entry/oh-package.json5 | 25 -- .../ets/common/constants/CommonConstants.ets | 85 ------- .../src/main/ets/entryability/EntryAbility.ts | 69 ------ .../entry/src/main/ets/pages/LoginPage.ets | 173 -------------- .../entry/src/main/ets/pages/MainPage.ets | 77 ------ .../entry/src/main/ets/viewmodel/ItemData.ets | 38 --- .../src/main/ets/viewmodel/MainViewModel.ets | 92 ------- .../entry/src/main/module.json5 | 51 ---- .../main/resources/base/element/color.json | 72 ------ .../main/resources/base/element/float.json | 88 ------- .../main/resources/base/element/string.json | 84 ------- .../resources/base/profile/main_pages.json | 6 - .../main/resources/en_US/element/string.json | 224 ------------------ .../main/resources/zh_CN/element/string.json | 224 ------------------ .../hvigor/hvigor-config.json5 | 21 -- test/appspawn_hap_test/oh-package.json5 | 27 --- 22 files changed, 1538 deletions(-) delete mode 100644 test/appspawn_hap_test/AppScope/app.json5 delete mode 100644 test/appspawn_hap_test/AppScope/resources/base/element/string.json delete mode 100644 test/appspawn_hap_test/AppScope/resources/base/media/app_icon.png delete mode 100644 test/appspawn_hap_test/LICENSE delete mode 100644 test/appspawn_hap_test/build-profile.json5 delete mode 100644 test/appspawn_hap_test/entry/build-profile.json5 delete mode 100644 test/appspawn_hap_test/entry/oh-package.json5 delete mode 100644 test/appspawn_hap_test/entry/src/main/ets/common/constants/CommonConstants.ets delete mode 100644 test/appspawn_hap_test/entry/src/main/ets/entryability/EntryAbility.ts delete mode 100644 test/appspawn_hap_test/entry/src/main/ets/pages/LoginPage.ets delete mode 100644 test/appspawn_hap_test/entry/src/main/ets/pages/MainPage.ets delete mode 100644 test/appspawn_hap_test/entry/src/main/ets/viewmodel/ItemData.ets delete mode 100644 test/appspawn_hap_test/entry/src/main/ets/viewmodel/MainViewModel.ets delete mode 100644 test/appspawn_hap_test/entry/src/main/module.json5 delete mode 100644 test/appspawn_hap_test/entry/src/main/resources/base/element/color.json delete mode 100644 test/appspawn_hap_test/entry/src/main/resources/base/element/float.json delete mode 100644 test/appspawn_hap_test/entry/src/main/resources/base/element/string.json delete mode 100644 test/appspawn_hap_test/entry/src/main/resources/base/profile/main_pages.json delete mode 100644 test/appspawn_hap_test/entry/src/main/resources/en_US/element/string.json delete mode 100644 test/appspawn_hap_test/entry/src/main/resources/zh_CN/element/string.json delete mode 100644 test/appspawn_hap_test/hvigor/hvigor-config.json5 delete mode 100644 test/appspawn_hap_test/oh-package.json5 diff --git a/test/appspawn_hap_test/AppScope/app.json5 b/test/appspawn_hap_test/AppScope/app.json5 deleted file mode 100644 index f9466973..00000000 --- a/test/appspawn_hap_test/AppScope/app.json5 +++ /dev/null @@ -1,25 +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. - */ - -{ - "app": { - "bundleName": "com.example.component", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/test/appspawn_hap_test/AppScope/resources/base/element/string.json b/test/appspawn_hap_test/AppScope/resources/base/element/string.json deleted file mode 100644 index 62d29ea3..00000000 --- a/test/appspawn_hap_test/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ArkTSComponents" - } - ] -} diff --git a/test/appspawn_hap_test/AppScope/resources/base/media/app_icon.png b/test/appspawn_hap_test/AppScope/resources/base/media/app_icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_FpjoHev5fEV7RhJ>r=mh-jp$fqbqRJ=obwdgLDVP5+s zy1=_DWG0Y-Jb3t^WXmkr(d9~08k-|#Ly zaNOmT(^9tIb&eb4%CzIT zAm3CUtWSr1t4?h1kk#NBi{U|pJslvME{q|_eS^3En>SOqSxyuN1x;Is@8~m?*>}** znrRFArP!K_52RpX*&JHMR<^lVdm8ypJ}0R(SD(51j;6@ni$6bQ+2XL+R^|NnSp5}(kzvMZ^(@4fD_{QVu$(&K6H|C37TG1Am9Re{<<3gd zh@`>;BqkXMW&p0T6rt|iB$)~CvFe(XC)F9WgAZn*0@t$oZo;!*}r@_`h?KKH&6A@3= zISXoQB+~`op>NP-buiA*^0n{@i{_?MRG)&k)c)k_F+-2Lud!S9pc+i`s74NpBCaGF zXN+pHkubw*msGBTY27BKHv)RRh3;nMg4&$fD_6X9Vt~;_4D+5XPH~#Kn-yjcy!$}1 zigv#FNY>TqMhtIBb@UoF!cE~Q8~;!Pek>SQQwHnHuWKoVBosAiOr}q>!>aE*Krc)V zBUMEcJ5NU0g8}-h6i1zpMY9>m4ne?=U2~`w7K7Q0gB_=p@$5K7p6}thw z-~3dMj?YNX2X$lZ+7ngQ$=s}3mizNN@kE%OtB)?c&i~2L55z8^=yz;xMHLmlY>&Q# zJj?!)M#q_SyfkQh)k?j8IfLtB)ZCp|*vf4_B zos?73yd^h-Ac+;?E4*bpf=o*^3x3-`TVjbY4n6!EN10K6o@fxdyps05Vo3PU)otB} z`3kR+2w7_C#8Z!q`J)p{Vh!+m9-UP!$STp+Hb}}#@#_u^SsUQg<}59< zTvH3%XS4G+6FF^(m6bVF&nSUIXcl;nw{=H$%fgeJ>CgDYiLdpDXr{;-AnG z8dvcrHYVMI&`R6;GWekI@Ir3!uo)oz4^{6q0m^}@f2tM9&=YHNi6-?rh0-{+k@cQm zdp`g#YdQn%MDVg2GR>wZ`n2<0l4)9nx1Wfr&!Dvz=bPwU!h2S?ez6MVc5APE4-xLB zi&W9Q8k2@0w!C53g?iAIQ}~p*3O(@zja6KQ=M3zfW*_6o5SwR-)6VBh~m7{^-=MC-owYH5-u40a}a0liho3QZZ5L{bS_xM1)4}19)zTU$$MY zq3eZML1WC{K%YFd`Be0M-rkO^l?h{kM{$2oK1*A@HVJ57*yhDkUF!2WZ&oA4Y-sK( zCY69%#`mBCi6>6uw(x4gbFaP0+FD*JKJ-q!F1E?vLJ+d35!I5d7@^eU?(CS|C^tmI5?lv@s{{*|1F zFg|OzNpZ0hxljdjaW%45O0MOttRrd(Z?h{HYbB-KFUx&9GfFL3b8NwZ$zNu)WbBD` zYkj$^UB5%3Pj1MDr>S2Ejr9pUcgA!;ZG!@{uAy12)vG=*^9-|dNQBc8&`oxBlU~#y zs!anJX&T?57Jdr^sb>e+V`MVfY>Y0ESg7MG<7W0g&bR-ZYzzZ%2H&Etcp zcd6QeXO1D!5A#zM0lx*GH}`M)2~ZFLE;sP^RSB5wVMNfiZXPd(cmO>j=OSA3`o5r& zna(|^jGXbdN7PK)U8b7^zYtYkkeb%<%F~=OqB~kXMQkq}ii|skh@WSRt>5za;cjP0 zZ~nD%6)wzedqE}BMLt~qKwlvTr33))#uP~xyw#*Eaa|DbMQ_%mG0U8numf8)0DX`r zRoG2bM;#g|p-8gWnwRV5SCW0tLjLO&9Z?K>FImeIxlGUgo0Zk`9Qzhj1eco~7XZy+hXc@YF&ZQ=? zn*^1O56yK^x{y}q`j7}blGCx%dydV!c7)g~tJzmHhV=W~jbWRRR{1<^oDK+1clprm zz$eCy7y9+?{E|YgkW~}}iB#I4XoJ*xr8R?i_Hv$=Cof5bo-Nj~f`-DLebH}&0% zfQj9@WGd4;N~Y?mzQsHJTJq6!Qzl^-vwol(+fMt#Pl=Wh#lI5Vmu@QM0=_r+1wHt` z+8WZ~c2}KQQ+q)~2Ki77QvV&`xb|xVcTms99&cD$Zz4+-^R4kvUBxG8gDk7Y`K*)JZ^2rL(+ZWV~%W(@6 z)0bPArG#BROa_PHs~&WplQ_UIrpd)1N1QGPfv!J(Z9jNT#i%H?CE6|pPZb9hJ1JW4 z^q;ft#!HRNV0YgPojzIYT`8LuET2rUe-J|c!9l4`^*;4WtY@Ew@pL>wkjmMgGfN7 ze}}GtmU0@<_#08~I-Suk=^*9GLW=H4xhsml;vAV{%hy5Eegl@!6qKqbG024%n2HHw zCc@ivW_$@5ZoHP70(7D+(`PvgjW1Pd`wsiuv-aCukMrafwDm)B!xXVy*j2opohhoU zcJz%ADmj>i3`-3-$7nQKBQQuGY;2Qt&+(L~C>vSGFj5{Mlv?T_^dql;{zkpe4R1}R z%XfZyQ}wr*sr>jrKgm*PWLjuVc%6&&`Kbf1SuFpHPN&>W)$GmqC;pIoBC`=4-hPY8 zT*>%I2fP}vGW;R=^!1be?ta2UQd2>alOFFbVl;(SQJ4Jk#)4Z0^wpWEVvY4=vyDk@ zqlModi@iVPMC+{?rm=4(n+<;|lmUO@UKYA>EPTS~AndtK^Wy^%#3<;(dQdk3WaUkRtzSMC9}7x2||CNpF#(3T4C)@ z$~RWs`BNABKX|{cmBt>Q=&gkXl&x!!NK_%5hW0LS)Z4PB>%sV?F-{Wyj#s7W%$F{D zXdK^Fp3wvy+48+GP6F_|^PCRx=ddcTO3sG;B23A49~Qaw31SZ0Rc~`r4qqt%#OGW{ zCA_(LG5^N>yzUn&kAgVmxb=EA8s&tBXC}S1CZ(KoW)(%^JjLTPo^fs`Va;`=YlVPgmB$!yB}<(4ym6OeZ3xAJJ#;)2+B%p3P1Wt+d$eo`vz`T zXfUP2))kBDPoscH;Jc7I3NU<({|@wM$&GaDt`n7WLgIY3IA7A6-_R?z8N3mz|}*i z(zl5ot--Oq@f2-nv{X(ujT2T(k1vY_qh93pK@>H-qc%2Xta)IP0Q%zt%bqYgI`o!wv!0QerB`nCN^1n|@$sVOQ!V0teVG!I z_fD%JvfDeT1cK#-{o6Gv7}& zY0#NWin~kVaf$aufV&;63Hbs|`QVZWpDX6IMk1Hj2G}fiH9e-^6u2zf^FIr^BwD<6zjw63+{yUe8PUFvk8v{sJ=R{d#`O!sz`Q13~< zPT$JS(w=yQfU2`zPCNfSw=&zup@DXc(98afjhv@1w_f!m2Z>rMJ19AB&dB%P#Ls3b z=lK7OILM+SQ&VEd=1GN6o&>YVVtIzoZ%=Z_SdqJN2}E43{bE`>w+A;=y->@^k{oCC z$F*WTY&?34;kfyFV?b*Xb1Pq`Z=%OgwEg)Rz)tx=`f%5#w_INP=x&z5!jI;#;N$ma zhO)+MDm;SxOEVL15; zGq(v2pL3&P1Sl)8P*;G-fd{l1QJsv@e@d8)1PK4w2m*M%V3j-V~L^$i|&C@b?D?9tfwE{B^}Z$k8e5FmQ>v7Xz)sG32g9t}YBt zyR$+*_00RmPx+0mW+vVG4mxd(n$(eQf3-w>JPl2UJpafrPaL5@2j}%{VE-) zBI%6Qpj*dsdH<;g!S!avA~bv^0E+ zfyJbSjPb+j;J52U)<|cIcntQBI2T#>2;tOxu{%D?kML476AErF(qN9hPva5Nkc@BF zC-tLF@3ZFb%Kpj)M<{)x*l|*Ia@ECeXo2E4h2f!aV=cHAhi_E_mfUth(sM4^hJq7B zQsGWqdZUm9S%F`$nQ*_#NcuD`&)Ek%_s{&^78{9Hm ztri&rYLOxgFdG>O@+XHy z9#;|&vBCPXH5Mon^I`jSuR$&~ZWtyB67ujzFSj!51>#C}C17~TffQ{c-!QFQkTQ%! zIR^b1`zHx|*1GU?tbBx23weFLz5H?y_Q%N&t$}k?w+``2A=aotj0;2v$~AL z{scF-cL{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y { - if (err.code) { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); - hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -} diff --git a/test/appspawn_hap_test/entry/src/main/ets/pages/LoginPage.ets b/test/appspawn_hap_test/entry/src/main/ets/pages/LoginPage.ets deleted file mode 100644 index cd674d33..00000000 --- a/test/appspawn_hap_test/entry/src/main/ets/pages/LoginPage.ets +++ /dev/null @@ -1,173 +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. - */ - -import prompt from '@ohos.promptAction'; -import router from '@ohos.router'; -import CommonConstants from '../common/constants/CommonConstants'; - -@Extend(TextInput) -function inputStyle() { - .placeholderColor($r('app.color.placeholder_color')) - .height($r('app.float.login_input_height')) - .fontSize($r('app.float.big_text_size')) - .backgroundColor($r('app.color.background')) - .width(CommonConstants.FULL_PARENT) - .padding({ left: CommonConstants.INPUT_PADDING_LEFT }) - .margin({ top: $r('app.float.input_margin_top') }) -} - -@Extend(Line) -function lineStyle() { - .width(CommonConstants.FULL_PARENT) - .height($r('app.float.line_height')) - .backgroundColor($r('app.color.line_color')) -} - -@Extend(Text) -function blueTextStyle() { - .fontColor($r('app.color.login_blue_text_color')) - .fontSize($r('app.float.small_text_size')) - .fontWeight(FontWeight.Medium) -} - -/** - * Login page - */ -@Entry -@Component -struct LoginPage { - @State account: string = ''; - @State password: string = ''; - @State isShowProgress: boolean = false; - private timeOutId: number = -1; - - @Builder - imageButton(src: Resource) { - Button({ type: ButtonType.Circle, stateEffect: true }) { - Image(src) - } - .height($r('app.float.other_login_image_size')) - .width($r('app.float.other_login_image_size')) - .backgroundColor($r('app.color.background')) - } - - login(): void { - if (this.account === '' || this.password === '') { - prompt.showToast({ - message: $r('app.string.input_empty_tips') - }) - } else { - this.isShowProgress = true; - if (this.timeOutId === -1) { - this.timeOutId = setTimeout(() => { - this.isShowProgress = false; - this.timeOutId = -1; - router.replaceUrl({ url: 'pages/MainPage' }); - }, CommonConstants.LOGIN_DELAY_TIME); - } - } - } - - aboutToDisappear() { - clearTimeout(this.timeOutId); - this.timeOutId = -1; - } - - build() { - Column() { - Image($r('app.media.logo')) - .width($r('app.float.logo_image_size')) - .height($r('app.float.logo_image_size')) - .margin({ top: $r('app.float.logo_margin_top'), bottom: $r('app.float.logo_margin_bottom') }) - Text($r('app.string.login_page')) - .fontSize($r('app.float.page_title_text_size')) - .fontWeight(FontWeight.Medium) - .fontColor($r('app.color.title_text_color')) - Text($r('app.string.login_more')) - .fontSize($r('app.float.normal_text_size')) - .fontColor($r('app.color.login_more_text_color')) - .margin({ bottom: $r('app.float.login_more_margin_bottom'), top: $r('app.float.login_more_margin_top') }) - - TextInput({ placeholder: $r('app.string.account') }) - .maxLength(CommonConstants.INPUT_ACCOUNT_LENGTH) - .type(InputType.Number) - .inputStyle() - .onChange((value: string) => { - this.account = value; - }) - Line().lineStyle() - - TextInput({ placeholder: $r('app.string.password') }) - .maxLength(CommonConstants.INPUT_PASSWORD_LENGTH) - .type(InputType.Password) - .inputStyle() - .onChange((value: string) => { - this.password = value; - }) - Line().lineStyle() - - Row() { - Text($r('app.string.message_login')).blueTextStyle() - Text($r('app.string.forgot_password')).blueTextStyle() - } - .justifyContent(FlexAlign.SpaceBetween) - .width(CommonConstants.FULL_PARENT) - .margin({ top: $r('app.float.forgot_margin_top') }) - - Button($r('app.string.login'), { type: ButtonType.Capsule }) - .width(CommonConstants.BUTTON_WIDTH) - .height($r('app.float.login_button_height')) - .fontSize($r('app.float.normal_text_size')) - .fontWeight(FontWeight.Medium) - .backgroundColor($r('app.color.login_button_color')) - .margin({ top: $r('app.float.login_button_margin_top'), bottom: $r('app.float.login_button_margin_bottom') }) - .onClick(() => { - this.login(); - }) - Text($r('app.string.register_account')) - .fontColor($r('app.color.login_blue_text_color')) - .fontSize($r('app.float.normal_text_size')) - .fontWeight(FontWeight.Medium) - - if (this.isShowProgress) { - LoadingProgress() - .color($r('app.color.loading_color')) - .width($r('app.float.login_progress_size')) - .height($r('app.float.login_progress_size')) - .margin({ top: $r('app.float.login_progress_margin_top') }) - } - - Blank() - Text($r('app.string.other_login_method')) - .fontColor($r('app.color.other_login_text_color')) - .fontSize($r('app.float.little_text_size')) - .fontWeight(FontWeight.Medium) - .margin({ top: $r('app.float.other_login_margin_top'), bottom: $r('app.float.other_login_margin_bottom') }) - Row({ space: CommonConstants.LOGIN_METHODS_SPACE }) { - this.imageButton($r('app.media.login_method1')) - this.imageButton($r('app.media.login_method2')) - this.imageButton($r('app.media.login_method3')) - } - } - .backgroundColor($r('app.color.background')) - .height(CommonConstants.FULL_PARENT) - .width(CommonConstants.FULL_PARENT) - .padding({ - left: $r('app.float.page_padding_hor'), - right: $r('app.float.page_padding_hor'), - bottom: $r('app.float.login_page_padding_bottom') - }) - } -} \ No newline at end of file diff --git a/test/appspawn_hap_test/entry/src/main/ets/pages/MainPage.ets b/test/appspawn_hap_test/entry/src/main/ets/pages/MainPage.ets deleted file mode 100644 index 128cd80c..00000000 --- a/test/appspawn_hap_test/entry/src/main/ets/pages/MainPage.ets +++ /dev/null @@ -1,77 +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. - */ - -import CommonConstants from '../common/constants/CommonConstants'; -import Home from "../view/Home" -import Setting from "../view/Setting" - -/** - * Main page - */ -@Entry -@Component -struct MainPage { - @State currentIndex: number = CommonConstants.HOME_TAB_INDEX; - private tabsController: TabsController = new TabsController(); - - @Builder TabBuilder(title: string, index: number, selectedImg: Resource, normalImg: Resource) { - Column() { - Image(this.currentIndex === index ? selectedImg : normalImg) - .width($r('app.float.mainPage_baseTab_size')) - .height($r('app.float.mainPage_baseTab_size')) - Text(title) - .margin({ top: $r('app.float.mainPage_baseTab_top') }) - .fontSize($r('app.float.main_tab_fontSize')) - .fontColor(this.currentIndex === index ? $r('app.color.mainPage_selected') : $r('app.color.mainPage_normal')) - } - .justifyContent(FlexAlign.Center) - .height($r('app.float.mainPage_barHeight')) - .width(CommonConstants.FULL_PARENT) - .onClick(() => { - this.currentIndex = index; - this.tabsController.changeIndex(this.currentIndex); - }) - } - - build() { - Tabs({ - barPosition: BarPosition.End, - controller: this.tabsController - }) { - TabContent() { - Home() - } - .padding({ left: $r('app.float.mainPage_padding'), right: $r('app.float.mainPage_padding') }) - .backgroundColor($r('app.color.mainPage_backgroundColor')) - .tabBar(this.TabBuilder(CommonConstants.HOME_TITLE, CommonConstants.HOME_TAB_INDEX, - $r('app.media.home_selected'), $r('app.media.home_normal'))) - - TabContent() { - Setting() - } - .padding({ left: $r('app.float.mainPage_padding'), right: $r('app.float.mainPage_padding') }) - .backgroundColor($r('app.color.mainPage_backgroundColor')) - .tabBar(this.TabBuilder(CommonConstants.MINE_TITLE, CommonConstants.MINE_TAB_INDEX, - $r('app.media.mine_selected'), $r('app.media.mine_normal'))) - } - .width(CommonConstants.FULL_PARENT) - .backgroundColor(Color.White) - .barHeight($r('app.float.mainPage_barHeight')) - .barMode(BarMode.Fixed) - .onChange((index: number) => { - this.currentIndex = index; - }) - } -} \ No newline at end of file diff --git a/test/appspawn_hap_test/entry/src/main/ets/viewmodel/ItemData.ets b/test/appspawn_hap_test/entry/src/main/ets/viewmodel/ItemData.ets deleted file mode 100644 index b1580cc2..00000000 --- a/test/appspawn_hap_test/entry/src/main/ets/viewmodel/ItemData.ets +++ /dev/null @@ -1,38 +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. - */ - -/** - * List item data entity. - */ -export default class PageResource { - /** - * Text of list item. - */ - title: Resource; - /** - * Image of list item. - */ - img: Resource; - /** - * Other resource of list item. - */ - others?: Resource; - - constructor(title: Resource, img: Resource, others?: Resource) { - this.title = title; - this.img = img; - this.others = others; - } -} \ No newline at end of file diff --git a/test/appspawn_hap_test/entry/src/main/ets/viewmodel/MainViewModel.ets b/test/appspawn_hap_test/entry/src/main/ets/viewmodel/MainViewModel.ets deleted file mode 100644 index 491deb01..00000000 --- a/test/appspawn_hap_test/entry/src/main/ets/viewmodel/MainViewModel.ets +++ /dev/null @@ -1,92 +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. - */ - -import ItemData from './ItemData'; - -/** - * Binds data to components and provides interfaces. - */ -export class MainViewModel { - - /** - * Get swiper image data. - * - * @return {Array} swiperImages. - */ - getSwiperImages(): Array { - let swiperImages: Resource[] = [ - $r('app.media.fig1'), - $r('app.media.fig2'), - $r('app.media.fig3'), - $r('app.media.fig4') - ]; - return swiperImages; - } - - /** - * Get data of the first grid. - * - * @return {Array} firstGridData. - */ - getFirstGridData(): Array { - let firstGridData: ItemData[] = [ - new ItemData($r('app.string.my_love'), $r('app.media.love')), - new ItemData($r('app.string.history_record'), $r('app.media.record')), - new ItemData($r('app.string.message'), $r('app.media.message')), - new ItemData($r('app.string.shopping_cart'), $r('app.media.shopping')), - new ItemData($r('app.string.my_goal'), $r('app.media.target')), - new ItemData($r('app.string.group'), $r('app.media.circle')), - new ItemData($r('app.string.favorites'), $r('app.media.favorite')), - new ItemData($r('app.string.recycle_bin'), $r('app.media.recycle')) - ]; - return firstGridData; - } - - - /** - * Get data of the second grid. - * - * @return {Array} secondGridData. - */ - getSecondGridData(): Array { - let secondGridData: ItemData[] = [ - new ItemData($r('app.string.mainPage_top'), $r('app.media.top'), $r('app.string.mainPage_text_top')), - new ItemData($r('app.string.mainPage_new'), $r('app.media.new'), $r('app.string.mainPage_text_new')), - new ItemData($r('app.string.mainPage_brand'), $r('app.media.brand'), $r('app.string.mainPage_text_brand')), - new ItemData($r('app.string.mainPage_found'), $r('app.media.found'), $r('app.string.mainPage_text_found')) - ]; - return secondGridData; - } - - - /** - * Get data of the setting list. - * - * @return {Array} settingListData. - */ - getSettingListData(): Array { - let settingListData: ItemData[] = [ - new ItemData($r('app.string.setting_list_news'), $r('app.media.news'), $r("app.string.setting_toggle")), - new ItemData($r('app.string.setting_list_data'), $r('app.media.data')), - new ItemData($r('app.string.setting_list_menu'), $r('app.media.menu')), - new ItemData($r('app.string.setting_list_about'), $r('app.media.about')), - new ItemData($r('app.string.setting_list_storage'), $r('app.media.storage')), - new ItemData($r('app.string.setting_list_privacy'), $r('app.media.privacy')) - ]; - return settingListData; - } -} - -export default new MainViewModel(); \ No newline at end of file diff --git a/test/appspawn_hap_test/entry/src/main/module.json5 b/test/appspawn_hap_test/entry/src/main/module.json5 deleted file mode 100644 index 8046ec19..00000000 --- a/test/appspawn_hap_test/entry/src/main/module.json5 +++ /dev/null @@ -1,51 +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. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "phone" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/appspawn_hap_test/entry/src/main/resources/base/element/color.json b/test/appspawn_hap_test/entry/src/main/resources/base/element/color.json deleted file mode 100644 index 145c2ba2..00000000 --- a/test/appspawn_hap_test/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "white", - "value": "#FFFFFF" - }, - { - "name": "background", - "value": "#F1F3F5" - }, - { - "name": "title_text_color", - "value": "#182431" - }, - { - "name": "login_more_text_color", - "value": "#99182431" - }, - { - "name": "placeholder_color", - "value": "#99182431" - }, - { - "name": "line_color", - "value": "#33182431" - }, - { - "name": "login_button_color", - "value": "#007DFF" - }, - { - "name": "login_blue_text_color", - "value": "#007DFF" - }, - { - "name": "other_login_text_color", - "value": "#838D97" - }, - { - "name": "loading_color", - "value": "#182431" - }, - { - "name": "mainPage_selected", - "value": "#1698CE" - }, - { - "name": "mainPage_normal", - "value": "#6B6B6B" - }, - { - "name": "mainPage_backgroundColor", - "value": "#F1F3F5" - }, - { - "name": "home_grid_fontColor", - "value": "#99182431" - }, - { - "name": "setting_button_backgroundColor", - "value": "#E5E8EA" - }, - { - "name": "setting_button_fontColor", - "value": "#FA2A2D" - } - ] -} \ No newline at end of file diff --git a/test/appspawn_hap_test/entry/src/main/resources/base/element/float.json b/test/appspawn_hap_test/entry/src/main/resources/base/element/float.json deleted file mode 100644 index c39c6a63..00000000 --- a/test/appspawn_hap_test/entry/src/main/resources/base/element/float.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "float": [ - { - "name": "logo_image_size", - "value": "78vp" - }, - { - "name": "logo_margin_top", - "value": "100vp" - }, - { - "name": "logo_margin_bottom", - "value": "8vp" - }, - { - "name": "page_title_text_size", - "value": "24fp" - }, - { - "name": "normal_text_size", - "value": "16fp" - }, - { - "name": "big_text_size", - "value": "18fp" - }, - { - "name": "small_text_size", - "value": "14fp" - }, - { - "name": "little_text_size", - "value": "12fp" - }, - { - "name": "login_more_margin_bottom", - "value": "30vp" - }, - { - "name": "login_more_margin_top", - "value": "8vp" - }, - { - "name": "login_input_height", - "value": "45vp" - }, - { - "name": "forgot_margin_top", - "value": "8vp" - }, - { - "name": "input_margin_top", - "value": "12vp" - }, - { - "name": "line_height", - "value": "1vp" - }, - { - "name": "login_button_height", - "value": "40vp" - }, - { - "name": "login_button_margin_top", - "value": "87vp" - }, - { - "name": "login_button_margin_bottom", - "value": "12vp" - }, - { - "name": "vertical_line_margin", - "value": "15vp" - }, - { - "name": "login_progress_size", - "value": "30vp" - }, - { - "name": "login_progress_margin_top", - "value": "20vp" - }, - { - "name": "other_login_margin_top", - "value": "50vp" - } - ] -} \ No newline at end of file diff --git a/test/appspawn_hap_test/entry/src/main/resources/base/element/string.json b/test/appspawn_hap_test/entry/src/main/resources/base/element/string.json deleted file mode 100644 index 33a72137..00000000 --- a/test/appspawn_hap_test/entry/src/main/resources/base/element/string.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "ArkTSComponents" - }, - { - "name": "login_page", - "value": "Login page" - }, - { - "name": "login_more", - "value": "Log in to your account to use more services" - }, - { - "name": "account", - "value": "Account" - }, - { - "name": "password", - "value": "Password" - }, - { - "name": "login", - "value": "Log in" - }, - { - "name": "register_account", - "value": "Registering an Account" - }, - { - "name": "forgot_password", - "value": "Forgot Password" - }, - { - "name": "message_login", - "value": "SMS verification code login" - }, - { - "name": "other_login_method", - "value": "Other login methods" - }, - { - "name": "vertical_line", - "value": " | " - }, - { - "name": "input_empty_tips", - "value": "The input cannot be empty." - }, - { - "name": "login_success", - "value": "The login is successful." - }, - { - "name": "my_love", - "value": "My favorite" - }, - { - "name": "history_record", - "value": "History" - }, - { - "name": "message", - "value": "Message" - }, - { - "name": "shopping_cart", - "value": "Shopping cart" - }, - { - "name": "my_goal", - "value": "My goal" - } - ] -} \ No newline at end of file diff --git a/test/appspawn_hap_test/entry/src/main/resources/base/profile/main_pages.json b/test/appspawn_hap_test/entry/src/main/resources/base/profile/main_pages.json deleted file mode 100644 index 39b6bfff..00000000 --- a/test/appspawn_hap_test/entry/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "src": [ - "pages/LoginPage", - "pages/MainPage" - ] -} \ No newline at end of file diff --git a/test/appspawn_hap_test/entry/src/main/resources/en_US/element/string.json b/test/appspawn_hap_test/entry/src/main/resources/en_US/element/string.json deleted file mode 100644 index b21fa858..00000000 --- a/test/appspawn_hap_test/entry/src/main/resources/en_US/element/string.json +++ /dev/null @@ -1,224 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "ArkTSComponents" - }, - { - "name": "login_page", - "value": "Login page" - }, - { - "name": "login_more", - "value": "Log in to your account to use more services" - }, - { - "name": "account", - "value": "Account" - }, - { - "name": "password", - "value": "Password" - }, - { - "name": "login", - "value": "Log in" - }, - { - "name": "register_account", - "value": "Registering an Account" - }, - { - "name": "forgot_password", - "value": "Forgot Password" - }, - { - "name": "message_login", - "value": "SMS verification code login" - }, - { - "name": "other_login_method", - "value": "Other login methods" - }, - { - "name": "vertical_line", - "value": " | " - }, - { - "name": "input_empty_tips", - "value": "The input cannot be empty." - }, - { - "name": "login_success", - "value": "The login is successful." - }, - { - "name": "my_love", - "value": "My favorite" - }, - { - "name": "history_record", - "value": "History" - }, - { - "name": "message", - "value": "Message" - }, - { - "name": "shopping_cart", - "value": "Shopping cart" - }, - { - "name": "my_goal", - "value": "My goal" - }, - { - "name": "group", - "value": "Group" - }, - { - "name": "favorites", - "value": "Favorites" - }, - { - "name": "recycle_bin", - "value": "Recycle Bin" - }, - { - "name": "rankings", - "value": "Rankings" - }, - { - "name": "new_product_debut", - "value": "New product debut" - }, - { - "name": "big_name_flash", - "value": "Big name flash" - }, - { - "name": "find_good", - "value": "Find good things" - }, - { - "name": "xiamen_station", - "value": "Xiamen Station, we'll see you." - }, - { - "name": "more_big_names", - "value": "More Big Names" - }, - { - "name": "push_notifications", - "value": "Push Notifications" - }, - { - "name": "data_management", - "value": "Data Management" - }, - { - "name": "menu_settings", - "value": "Menu Settings" - }, - { - "name": "about", - "value": "About" - }, - { - "name": "clear_cache", - "value": "Clear Cache" - }, - { - "name": "mainPage_tabTitles_home", - "value": "Home" - }, - { - "name": "mainPage_tabTitles_mine", - "value": "Mine" - }, - { - "name": "mainPage_top", - "value": "Rankings" - }, - { - "name": "mainPage_text_top", - "value": "Xiamen Station, we'll see you." - }, - { - "name": "mainPage_new", - "value": "New product debut" - }, - { - "name": "mainPage_text_new", - "value": "Xiamen Station, we'll see you." - }, - { - "name": "mainPage_brand", - "value": "Big name flash" - }, - { - "name": "mainPage_text_brand", - "value": "More Big Names" - }, - { - "name": "mainPage_found", - "value": "Find good things" - }, - { - "name": "mainPage_text_found", - "value": "Xiamen Station, we'll see you." - }, - { - "name": "setting_account_name", - "value": "Mr. Lee" - }, - { - "name": "setting_account_email", - "value": "2000000@shenhua.cc" - }, - { - "name": "setting_list_news", - "value": "Push Notifications" - }, - { - "name": "setting_list_data", - "value": "Data Management" - }, - { - "name": "setting_list_menu", - "value": "Menu Settings" - }, - { - "name": "setting_list_about", - "value": "Clear Cache" - }, - { - "name": "setting_list_storage", - "value": "清除缓存" - }, - { - "name": "setting_list_privacy", - "value": "Privacy Agreement" - }, - { - "name": "setting_button", - "value": "Logout" - }, - { - "name": "home_list", - "value": "List" - }, - { - "name": "setting_toggle", - "value": "switch" - } - ] -} \ No newline at end of file diff --git a/test/appspawn_hap_test/entry/src/main/resources/zh_CN/element/string.json b/test/appspawn_hap_test/entry/src/main/resources/zh_CN/element/string.json deleted file mode 100644 index bae69c08..00000000 --- a/test/appspawn_hap_test/entry/src/main/resources/zh_CN/element/string.json +++ /dev/null @@ -1,224 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "ArkTSComponents" - }, - { - "name": "login_page", - "value": "登录界面" - }, - { - "name": "login_more", - "value": "登录帐号以使用更多服务" - }, - { - "name": "account", - "value": "帐号" - }, - { - "name": "password", - "value": "密码" - }, - { - "name": "login", - "value": "登录" - }, - { - "name": "register_account", - "value": "注册帐号" - }, - { - "name": "forgot_password", - "value": "忘记密码" - }, - { - "name": "message_login", - "value": "短信验证码登录" - }, - { - "name": "other_login_method", - "value": "其他登录方式" - }, - { - "name": "vertical_line", - "value": " | " - }, - { - "name": "input_empty_tips", - "value": "输入不能为空" - }, - { - "name": "login_success", - "value": "登录成功" - }, - { - "name": "my_love", - "value": "我的最爱" - }, - { - "name": "history_record", - "value": "历史记录" - }, - { - "name": "message", - "value": "消息" - }, - { - "name": "shopping_cart", - "value": "购物车" - }, - { - "name": "my_goal", - "value": "我的目标" - }, - { - "name": "group", - "value": "圈子" - }, - { - "name": "favorites", - "value": "收藏" - }, - { - "name": "recycle_bin", - "value": "回收站" - }, - { - "name": "rankings", - "value": "排行榜" - }, - { - "name": "new_product_debut", - "value": "新品首发" - }, - { - "name": "big_name_flash", - "value": "大牌闪购" - }, - { - "name": "find_good", - "value": "发现好物" - }, - { - "name": "xiamen_station", - "value": "厦门站,我们不见不散" - }, - { - "name": "more_big_names", - "value": "更多大牌" - }, - { - "name": "push_notifications", - "value": "推送通知" - }, - { - "name": "data_management", - "value": "数据管理" - }, - { - "name": "menu_settings", - "value": "菜单设置" - }, - { - "name": "about", - "value": "关于" - }, - { - "name": "clear_cache", - "value": "清除缓存" - }, - { - "name": "mainPage_tabTitles_home", - "value": "首页" - }, - { - "name": "mainPage_tabTitles_mine", - "value": "我的" - }, - { - "name": "mainPage_top", - "value": "排行榜" - }, - { - "name": "mainPage_text_top", - "value": "厦门站,我们不见不散" - }, - { - "name": "mainPage_new", - "value": "新品首发" - }, - { - "name": "mainPage_text_new", - "value": "厦门站,我们不见不散" - }, - { - "name": "mainPage_brand", - "value": "大牌闪购" - }, - { - "name": "mainPage_text_brand", - "value": "更多大牌" - }, - { - "name": "mainPage_found", - "value": "发现好物" - }, - { - "name": "mainPage_text_found", - "value": "厦门站,我们不见不散" - }, - { - "name": "setting_account_name", - "value": "李先生" - }, - { - "name": "setting_account_email", - "value": "2000000@shenhua.cc" - }, - { - "name": "setting_list_news", - "value": "推送通知" - }, - { - "name": "setting_list_data", - "value": "数据管理" - }, - { - "name": "setting_list_menu", - "value": "菜单设置" - }, - { - "name": "setting_list_about", - "value": "关于" - }, - { - "name": "setting_list_storage", - "value": "清除缓存" - }, - { - "name": "setting_list_privacy", - "value": "隐私协议" - }, - { - "name": "setting_button", - "value": "退出登录" - }, - { - "name": "home_list", - "value": "列表" - }, - { - "name": "setting_toggle", - "value": "开关" - } - ] -} \ No newline at end of file diff --git a/test/appspawn_hap_test/hvigor/hvigor-config.json5 b/test/appspawn_hap_test/hvigor/hvigor-config.json5 deleted file mode 100644 index acf887c2..00000000 --- a/test/appspawn_hap_test/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,21 +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. - */ - -{ - "hvigorVersion": "2.0.0", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "2.0.0" - } -} diff --git a/test/appspawn_hap_test/oh-package.json5 b/test/appspawn_hap_test/oh-package.json5 deleted file mode 100644 index ee07c28a..00000000 --- a/test/appspawn_hap_test/oh-package.json5 +++ /dev/null @@ -1,27 +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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "arktscomponents", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} \ No newline at end of file -- Gitee From 3068880eb499779e4302abe09b84e3654ce9b45e Mon Sep 17 00:00:00 2001 From: nianyuu Date: Fri, 8 Nov 2024 17:49:02 +0800 Subject: [PATCH 027/148] sync appspawn code Signed-off-by: nianyuu --- common/appspawn_server.c | 3 +-- modules/sandbox/appspawn_sandbox.c | 18 +++++++++------- modules/sandbox/sandbox_expand.c | 4 +++- modules/sandbox/sandbox_utils.cpp | 2 +- service/hnp/base/hnp_json.c | 16 ++++++++++---- service/hnp/installer/src/hnp_installer.c | 3 ++- standard/appspawn_appmgr.c | 7 ++++-- standard/appspawn_service.c | 26 +++++++++++++++-------- 8 files changed, 51 insertions(+), 28 deletions(-) diff --git a/common/appspawn_server.c b/common/appspawn_server.c index 68a3b1b1..93655591 100644 --- a/common/appspawn_server.c +++ b/common/appspawn_server.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 20214 Huawei Device Co., Ltd. + * 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 @@ -84,7 +84,6 @@ int AppSpawnChild(AppSpawnContent *content, AppSpawnClient *client) } APPSPAWN_LOGW("AppSpawnChild cold start fail %{public}u", client->id); } - StartAppspawnTrace("AppSpawnExecuteSpawningHook"); ret = AppSpawnExecuteSpawningHook(content, client); FinishAppspawnTrace(); diff --git a/modules/sandbox/appspawn_sandbox.c b/modules/sandbox/appspawn_sandbox.c index 19422e9e..c2a532ee 100644 --- a/modules/sandbox/appspawn_sandbox.c +++ b/modules/sandbox/appspawn_sandbox.c @@ -392,6 +392,7 @@ APPSPAWN_STATIC const char *GetRealSrcPath(const SandboxContext *context, const // 设置挂载参数options static int32_t SetMountArgsOption(const SandboxContext *context, uint32_t category, uint32_t operation, MountArg *args) { + args->options = ""; if ((category != MOUNT_TMP_DAC_OVERRIDE) && (category != MOUNT_TMP_DAC_OVERRIDE_DELETE)) { return 0; } @@ -412,7 +413,7 @@ static int32_t SetMountArgsOption(const SandboxContext *context, uint32_t catego return 0; } -// 根据沙盒配置文件中挂载类别进行挂载挂载 +// 根据沙盒配置文件中挂载类别进行挂载 static int DoSandboxMountByCategory(const SandboxContext *context, const PathMountNode *sandboxNode, MountArg *args, uint32_t operation) { @@ -465,6 +466,7 @@ static int DoSandboxPathNodeMount(const SandboxContext *context, CreateSandboxDir(args.destinationPath, FILE_MODE); } } + CreateDemandSrc(context, sandboxNode, &args); int ret = 0; @@ -546,7 +548,7 @@ static bool IsUnlockStatus(uint32_t uid, const char *bundleName, size_t bundleNa { const int userIdBase = UID_BASE; uid = uid / userIdBase; - if (uid == 0) { + if (uid == 0) { // uid = 0 不涉及加密目录的挂载 return true; } @@ -554,6 +556,7 @@ static bool IsUnlockStatus(uint32_t uid, const char *bundleName, size_t bundleNa const char basePath[] = "/base/"; size_t allPathSize = strlen(rootPath) + strlen(basePath) + 1 + USER_ID_SIZE + bundleNameLen; char *path = (char *)malloc(sizeof(char) * allPathSize); + (void)memset_s(path, allPathSize, 0, allPathSize); APPSPAWN_CHECK(path != NULL, return true, "Failed to malloc path"); int len = sprintf_s(path, allPathSize, "%s%u%s%s", rootPath, uid, basePath, bundleName); APPSPAWN_CHECK(len > 0 && ((size_t)len < allPathSize), free(path); return true, "Failed to get base path"); @@ -578,6 +581,7 @@ static void MountDir(AppSpawnMsgDacInfo *info, const char *bundleName, const cha size_t allPathSize = strlen(rootPath) + strlen(targetPath) + strlen(bundleName) + 2; allPathSize += USER_ID_SIZE; char *path = (char *)malloc(sizeof(char) * (allPathSize)); + (void)memset_s(path, allPathSize, 0, allPathSize); APPSPAWN_CHECK(path != NULL, return, "Failed to malloc path"); int len = sprintf_s(path, allPathSize, "%s%u/%s%s", rootPath, info->uid / userIdBase, bundleName, targetPath); APPSPAWN_CHECK(len > 0 && ((size_t)len < allPathSize), free(path); @@ -596,12 +600,11 @@ static void MountDir(AppSpawnMsgDacInfo *info, const char *bundleName, const cha } if (mount(NULL, path, NULL, MS_SHARED, NULL) != 0) { APPSPAWN_LOGI("mount path %{public}s to shared failed, errno %{public}d", path, errno); - free(path); - return; + } else { + APPSPAWN_LOGI("mount path %{public}s to shared success", path); } - APPSPAWN_LOGI("mount path %{public}s to shared success", path); + free(path); - return; } static const MountSharedTemplate MOUNT_SHARED_MAP[] = { @@ -756,7 +759,7 @@ static int SetExpandSandboxConfig(const SandboxContext *context, const AppSpawnS AppSpawnMsgDomainInfo *msgDomainInfo = (AppSpawnMsgDomainInfo *)GetSpawningMsgInfo(context, TLV_DOMAIN_INFO); if (msgDomainInfo != NULL) { mountDestBundlePath = (strcmp(msgDomainInfo->apl, APL_SYSTEM_BASIC) == 0) || - (strcmp(msgDomainInfo->apl, APL_SYSTEM_CORE) == 0); + (strcmp(msgDomainInfo->apl, APL_SYSTEM_CORE) == 0); } if (mountDestBundlePath || (CheckSpawningMsgFlagSet(context, APP_FLAGS_ACCESS_BUNDLE_DIR) != 0)) { // need permission check for system app here @@ -1009,7 +1012,6 @@ static bool IsADFPermission(AppSpawnSandboxCfg *sandbox, const AppSpawningCtx *p if (index > 0 && CheckAppPermissionFlagSet(property, index)) { return true; } - if (GetBundleName(property) != NULL && strstr(GetBundleName(property), "com.ohos.dlpmanager") != NULL) { return true; } diff --git a/modules/sandbox/sandbox_expand.c b/modules/sandbox/sandbox_expand.c index ef9d5e41..21f0d15a 100644 --- a/modules/sandbox/sandbox_expand.c +++ b/modules/sandbox/sandbox_expand.c @@ -166,7 +166,9 @@ static int SetOverlayAppPath(const char *hapPath, void *context) APPSPAWN_LOGV("SetOverlayAppPath path: '%{public}s' => '%{public}s'", sandboxContext->buffer[0].buffer, sandboxContext->buffer[1].buffer); - (void)MakeDirRec(sandboxContext->buffer[1].buffer, FILE_MODE, 1); + ret = MakeDirRec(sandboxContext->buffer[1].buffer, FILE_MODE, 1); + APPSPAWN_CHECK(ret == 0, return ret, "Fail to mkdir dir %{public}s, ret :%{public}d", + sandboxContext->buffer[1].buffer, ret); MountArg mountArg = { sandboxContext->buffer[0].buffer, sandboxContext->buffer[1].buffer, NULL, MS_REC | MS_BIND, NULL, MS_SHARED }; diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index c31999a9..2f00d493 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -1599,7 +1599,7 @@ int32_t SandboxUtils::SetPermissionWithParam(AppSpawningCtx *appProperty) } if (index > 0 && (fileMgrIndex > 0 && userFileIndex > 0) && (CheckAppPermissionFlagSet(appProperty, static_cast(userFileIndex)) == 0) && - (CheckAppPermissionFlagSet(appProperty, static_cast(fileMgrIndex))== 0)) { + (CheckAppPermissionFlagSet(appProperty, static_cast(fileMgrIndex)) == 0)) { return SetAppPermissionFlags(appProperty, index); } return 0; diff --git a/service/hnp/base/hnp_json.c b/service/hnp/base/hnp_json.c index 148809a7..26bba384 100644 --- a/service/hnp/base/hnp_json.c +++ b/service/hnp/base/hnp_json.c @@ -586,9 +586,10 @@ static char *HnpNeedUnInstallHnpVersionGet(cJSON *hnpItemArr, const char *name) cJSON *nameItem = cJSON_GetObjectItem(hnpItem, "name"); cJSON *currentItem = cJSON_GetObjectItem(hnpItem, "current_version"); cJSON *installItem = cJSON_GetObjectItem(hnpItem, "install_version"); - if ((nameItem != NULL) && (currentItem != NULL) && (installItem != NULL) && (cJSON_IsString(nameItem)) && - (cJSON_IsString(currentItem)) && (cJSON_IsString(installItem)) && - (strcmp(nameItem->valuestring, name) == 0) && + if ((nameItem != NULL) && (currentItem != NULL) && (installItem != NULL) && + (cJSON_IsString(nameItem)) && (cJSON_IsString(currentItem)) && (cJSON_IsString(installItem)) && + (nameItem->valuestring != NULL) && (strcmp(nameItem->valuestring, name) == 0) && + (currentItem->valuestring != NULL) && (installItem->valuestring != NULL) && (strcmp(currentItem->valuestring, installItem->valuestring) == 0)) { version = strdup(currentItem->valuestring); return version; @@ -600,6 +601,9 @@ static char *HnpNeedUnInstallHnpVersionGet(cJSON *hnpItemArr, const char *name) char *HnpCurrentVersionGet(const char *name) { + if (name == NULL) { + return NULL; + } char *infoStream; int size; cJSON *hapItem = NULL; @@ -630,7 +634,8 @@ char *HnpCurrentVersionGet(const char *name) cJSON *nameItem = cJSON_GetObjectItem(hnpItem, "name"); cJSON *versionItem = cJSON_GetObjectItem(hnpItem, "current_version"); if ((nameItem != NULL) && (versionItem != NULL) && (cJSON_IsString(nameItem)) && - (cJSON_IsString(versionItem)) && (strcmp(nameItem->valuestring, name) == 0)) { + (cJSON_IsString(versionItem)) && (versionItem->valuestring != NULL) && + (nameItem->valuestring != NULL) && (strcmp(nameItem->valuestring, name) == 0)) { version = strdup(versionItem->valuestring); cJSON_Delete(json); return version; @@ -644,6 +649,9 @@ char *HnpCurrentVersionGet(const char *name) char *HnpCurrentVersionUninstallCheck(const char *name) { + if (name == NULL) { + return NULL; + } char *infoStream; int size; cJSON *hapItem = NULL; diff --git a/service/hnp/installer/src/hnp_installer.c b/service/hnp/installer/src/hnp_installer.c index 83ffddab..180c7ab8 100644 --- a/service/hnp/installer/src/hnp_installer.c +++ b/service/hnp/installer/src/hnp_installer.c @@ -395,6 +395,7 @@ static int HnpPublicDealAfterInstall(HnpInstallInfo *hnpInfo, HnpCfgInfo *hnpCfg } if (version != NULL) { free(version); + version = NULL; } hnpCfg->isInstall = true; @@ -863,4 +864,4 @@ int HnpCmdUnInstall(int argc, char *argv[]) #ifdef __cplusplus } -#endif +#endif \ No newline at end of file diff --git a/standard/appspawn_appmgr.c b/standard/appspawn_appmgr.c index ffdfa090..248d5df7 100644 --- a/standard/appspawn_appmgr.c +++ b/standard/appspawn_appmgr.c @@ -226,8 +226,10 @@ int KillAndWaitStatus(pid_t pid, int sig, int *exitStatus) APPSPAWN_LOGE("unable to kill process, pid: %{public}d ret %{public}d", pid, errno); return -1; } - pid_t exitPid = 0; + int retry = 0; + pid_t exitPid = 0; + while (retry * SLEEP_DURATION < EXIT_APP_TIMEOUT) { exitPid = waitpid(pid, exitStatus, WNOHANG); if (exitPid == pid) { @@ -399,10 +401,11 @@ void ProcessAppSpawnDumpMsg(const AppSpawnMsgNode *message) char *ptyName = GetAppSpawnMsgExtInfo(message, "pty-name", &len); if (ptyName != NULL) { APPSPAWN_LOGI("Dump info to file '%{public}s'", ptyName); - char canonicalPtyPath[PATH_MAX] = {0}; + char canonicalPtyPath[PATH_MAX] = { 0 }; if (realpath(ptyName, canonicalPtyPath) == NULL) { return; } + stream = fopen(canonicalPtyPath, "w"); SetDumpToStream(stream); } else { diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 16d4b127..122e4173 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -66,6 +66,7 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess static inline void SetFdCtrl(int fd, int opt) { int option = fcntl(fd, F_GETFD); + APPSPAWN_CHECK(option >= 0, return, "SetFdCtrl fcntl failed %{public}d, %{public}d", option, errno); int ret = fcntl(fd, F_SETFD, (unsigned int)option | (unsigned int)opt); if (ret < 0) { APPSPAWN_LOGI("Set fd %{public}d option %{public}d %{public}d result: %{public}d", fd, option, opt, errno); @@ -609,6 +610,7 @@ static int AddChildWatcher(AppSpawningCtx *property) { uint32_t defTimeout = IsChildColdRun(property) ? COLD_CHILD_RESPONSE_TIMEOUT : WAIT_CHILD_RESPONSE_TIMEOUT; uint32_t timeout = GetSpawnTimeout(defTimeout); + APPSPAWN_LOGI("Get Spawn timeout %{public}u", timeout); LE_WatchInfo watchInfo = {}; watchInfo.fd = property->forkCtx.fd[0]; watchInfo.flags = WATCHER_ONCE; @@ -760,6 +762,7 @@ static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property) ProcessExit(0); return; } + property->client.id = client.id; property->client.flags = client.flags; property->isPrefork = true; @@ -826,6 +829,7 @@ static bool IsSupportPrefork(AppSpawnContent *content, AppSpawnClient *client) return false; } if (!content->enablePerfork) { + APPSPAWN_LOGV("g_enablePrefork %{public}d", content->enablePerfork); return false; } AppSpawningCtx *property = (AppSpawningCtx *)client; @@ -838,7 +842,7 @@ static bool IsSupportPrefork(AppSpawnContent *content, AppSpawnClient *client) return false; } -static bool IsBootFinished() +static bool IsBootFinished(void) { char buffer[32] = {0}; // 32 max int ret = GetParameter("bootevent.boot.completed", "false", buffer, sizeof(buffer)); @@ -846,6 +850,7 @@ static bool IsBootFinished() return isBootCompleted; } + static int RunAppSpawnProcessMsg(AppSpawnContent *content, AppSpawnClient *client, pid_t *childPid) { int ret = 0; @@ -1094,7 +1099,6 @@ APPSPAWN_STATIC int AppSpawnColdStartApp(struct AppSpawnContent *content, AppSpa APPSPAWN_CHECK(len > 0, return APPSPAWN_SYSTEM_ERROR, "Invalid to format shmId "); len = sprintf_s(buffer[3], sizeof(buffer[3]), " %u ", property->client.id); // 3 3 index for client id APPSPAWN_CHECK(len > 0, return APPSPAWN_SYSTEM_ERROR, "Invalid to format shmId "); - #ifndef APPSPAWN_TEST char *mode = IsNWebSpawnMode((AppSpawnMgr *)content) ? "nweb_cold" : "app_cold"; // 2 2 index for dest path @@ -1226,11 +1230,11 @@ APPSPAWN_STATIC int AppSpawnClearEnv(AppSpawnMgr *content, AppSpawningCtx *prope return 0; } -static int IsEnablePerfork() +static int IsEnablePrefork(void) { char buffer[32] = {0}; int ret = GetParameter("persist.sys.prefork.enable", "true", buffer, sizeof(buffer)); - APPSPAWN_LOGV("IsEnablePerfork result %{public}d, %{public}s", ret, buffer); + APPSPAWN_LOGV("IsEnablePrefork result %{public}d, %{public}s", ret, buffer); return strcmp(buffer, "true") == 0; } @@ -1254,7 +1258,7 @@ AppSpawnContent *AppSpawnCreateContent(const char *socketName, char *longProcNam APPSPAWN_CHECK(ret == 0, AppSpawnDestroyContent(&appSpawnContent->content); return NULL, "Failed to create server"); } - appSpawnContent->content.enablePerfork = IsEnablePerfork(); + appSpawnContent->content.enablePerfork = IsEnablePrefork(); return &appSpawnContent->content; } @@ -1490,10 +1494,14 @@ static void ProcessSpawnRestartMsg(AppSpawnConnection *connection, AppSpawnMsgNo int fd = GetControlSocket(NWEBSPAWN_SOCKET_NAME); APPSPAWN_CHECK(fd >= 0, return, "Get fd failed %{public}d, errno %{public}d", fd, errno); + int ret = 0; int op = fcntl(fd, F_GETFD); - int ret = fcntl(fd, F_SETFD, (unsigned int)op & ~FD_CLOEXEC); - if (ret < 0) { - APPSPAWN_LOGE("Set fd failed %{public}d, %{public}d, ret %{public}d, errno %{public}d", fd, op, ret, errno); + APPSPAWN_CHECK_ONLY_LOG(op >= 0, "fcntl failed %{public}d", op); + if (op > 0) { + ret = fcntl(fd, F_SETFD, (unsigned int)op & ~FD_CLOEXEC); + if (ret < 0) { + APPSPAWN_LOGE("Set fd failed %{public}d, %{public}d, ret %{public}d, errno %{public}d", fd, op, ret, errno); + } } char *path = "/system/bin/appspawn"; @@ -1641,4 +1649,4 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess DeleteAppSpawnMsg(message); break; } -} \ No newline at end of file +} -- Gitee From da139225ace9ef190cb66882b3a818be36d9d8ee Mon Sep 17 00:00:00 2001 From: whoselittlelion Date: Sat, 9 Nov 2024 11:40:29 +0800 Subject: [PATCH 028/148] add codeowner Signed-off-by: whoselittlelion --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index c0a5b14a..3d321f2d 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -13,4 +13,4 @@ * limitations under the License. */ - * @liveery @wang_fenging @cat \ No newline at end of file + * @liveery @wang_fenging @zl_zl @zhouge94 -- Gitee From 57104b718e29c934255efde250580aa71ab7eb75 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Sat, 9 Nov 2024 17:24:08 +0800 Subject: [PATCH 029/148] fix:Browser crashes Signed-off-by: wangfeng --- appdata-sandbox.json | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/appdata-sandbox.json b/appdata-sandbox.json index e781a2d2..6326fba6 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -29,13 +29,8 @@ "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/system/app/appServiceFwk", - "sandbox-path" : "/system/app/appServiceFwk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/app/shared_bundles", - "sandbox-path" : "/system/app/shared_bundles", + "src-path" : "/system/app", + "sandbox-path" : "/system/app", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { -- Gitee From a06ee7d32fdda5eec85b6f8b593a3e3a3a00e967 Mon Sep 17 00:00:00 2001 From: yh Date: Mon, 11 Nov 2024 15:29:39 +0800 Subject: [PATCH 030/148] modify gwp Signed-off-by: yh Change-Id: I27c8d1271800af102038d80df1e51cb1319d4cbe --- modules/asan/asan_detector.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/modules/asan/asan_detector.c b/modules/asan/asan_detector.c index 15e4c836..81e4e64d 100644 --- a/modules/asan/asan_detector.c +++ b/modules/asan/asan_detector.c @@ -86,15 +86,12 @@ static int SetAsanEnabledEnv(const AppSpawnMgr *content, const AppSpawningCtx *p static void SetGwpAsanEnabled(const AppSpawnMgr *content, const AppSpawningCtx *property) { - if (!(CheckAppMsgFlagsSet(property, APP_FLAGS_GWP_ENABLED_FORCE) || - CheckAppMsgFlagsSet(property, APP_FLAGS_GWP_ENABLED_NORMAL))) { + int enforce = CheckAppMsgFlagsSet(property, APP_FLAGS_GWP_ENABLED_FORCE); + if (!enforce && !CheckAppMsgFlagsSet(property, APP_FLAGS_GWP_ENABLED_NORMAL)) { return; } - if (IsDeveloperModeOn(property)) { - APPSPAWN_LOGV("SetGwpAsanEnabled with flags: %{public}d", - CheckAppMsgFlagsSet(property, APP_FLAGS_GWP_ENABLED_FORCE)); - may_init_gwp_asan(CheckAppMsgFlagsSet(property, APP_FLAGS_GWP_ENABLED_FORCE)); - } + APPSPAWN_LOGV("SetGwpAsanEnabled with flags: %{public}d", enforce); + may_init_gwp_asan(enforce); } #ifdef ASAN_DETECTOR -- Gitee From b5560813e0747d7e705cdbb14f946228c528a714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Mon, 11 Nov 2024 19:07:34 +0800 Subject: [PATCH 031/148] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E8=87=B4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- .../appspawn_manager_test.cpp | 270 ------- .../appspawn_util_test/appspawn_util_test.cpp | 736 ------------------ 2 files changed, 1006 deletions(-) delete mode 100644 test/unittest/appspawn_util_test/appspawn_manager_test.cpp delete mode 100644 test/unittest/appspawn_util_test/appspawn_util_test.cpp diff --git a/test/unittest/appspawn_util_test/appspawn_manager_test.cpp b/test/unittest/appspawn_util_test/appspawn_manager_test.cpp deleted file mode 100644 index dc4e1a9b..00000000 --- a/test/unittest/appspawn_util_test/appspawn_manager_test.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright (c) 2024-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 "appspawn_utils.h" - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -class AppSpawnManagerTest : public testing::Test { -public: - AppSpawnMgr content; - AppSpawningCtx property; - AppSpawnMsgNode message; - static void SetUpTestCase() - { - APPSPAWN_LOGI("SetUpTestCase"); - } - - static void TearDownTestCase() - { - APPSPAWN_LOGI("TearDownTestCase"); - } - - void SetUp() - { - APPSPAWN_LOGI("SetUp"); - } - - void TearDown() - { - APPSPAWN_LOGI("TearDown"); - } -}; - -// 测试用例 -HWTEST_F(AppSpawnManagerTest, IsSpawnServer_01, TestSize.Level0) -{ - // 测试 content 为 NULL 的情况 - EXPECT_EQ(IsSpawnServer(NULL), 0); -} - -HWTEST_F(AppSpawnManagerTest, IsSpawnServer_02, TestSize.Level0) -{ - // 测试 servicePid 不等于当前进程 PID 的情况 - content.servicePid = getpid() + 1; // 设置为不同的 PID - EXPECT_EQ(IsSpawnServer(&content), 0); -} - -HWTEST_F(AppSpawnManagerTest, IsSpawnServer_03, TestSize.Level0) -{ - // 测试 servicePid 等于当前进程 PID 的情况 - content.servicePid = getpid(); // 设置为当前进程 PID - EXPECT_EQ(IsSpawnServer(&content), 1); -} - -// 测试用例 -HWTEST_F(AppSpawnManagerTest, IsSpawnServer_03, TestSize.Level0) -{ - // 测试 content 为 NULL 的情况 - EXPECT_EQ(IsNWebSpawnMode(NULL), 0); -} - -HWTEST_F(AppSpawnManagerTest, IsSpawnServer_03, TestSize.Level0) -{ - // 测试 mode 为 MODE_FOR_NWEB_SPAWN 的情况 - content.content.mode = MODE_FOR_NWEB_SPAWN; - EXPECT_EQ(IsNWebSpawnMode(&content), 1); -} - -HWTEST_F(AppSpawnManagerTest, IsSpawnServer_03, TestSize.Level0) -{ - // 测试 mode 为 MODE_FOR_NWEB_COLD_RUN 的情况 - content.content.mode = MODE_FOR_NWEB_COLD_RUN; - EXPECT_EQ(IsNWebSpawnMode(&content), 1); -} - -HWTEST_F(AppSpawnManagerTest, IsSpawnServer_03, TestSize.Level0) -{ - // 测试 mode 为其他值的情况 - content.content.mode = MODE_FOR_APP_SPAWN; - EXPECT_EQ(IsNWebSpawnMode(&content), 0); -} - -// 测试用例 -HWTEST_F(AppSpawnManagerTest, IsColdRunMode_01, TestSize.Level0) -{ - // 测试 content 为 NULL 的情况 - EXPECT_EQ(IsColdRunMode(NULL), 0); -} - -HWTEST_F(AppSpawnManagerTest, IsColdRunMode_02, TestSize.Level0) -{ - // 测试 mode 为 MODE_FOR_APP_COLD_RUN 的情况 - content.content.mode = MODE_FOR_APP_COLD_RUN; - EXPECT_EQ(IsColdRunMode(&content), 1); -} - -HWTEST_F(AppSpawnManagerTest, IsColdRunMode_03, TestSize.Level0) -{ - // 测试 mode 为 MODE_FOR_NWEB_COLD_RUN 的情况 - content.content.mode = MODE_FOR_NWEB_COLD_RUN; - EXPECT_EQ(IsColdRunMode(&content), 1); -} - -HWTEST_F(AppSpawnManagerTest, IsColdRunMode_04, TestSize.Level0) -{ - // 测试 mode 为 MODE_FOR_APP_SPAWN 的情况 - content.content.mode = MODE_FOR_APP_SPAWN; - EXPECT_EQ(IsColdRunMode(&content), 0); -} - -HWTEST_F(AppSpawnManagerTest, IsColdRunMode_05, TestSize.Level0) -{ - // 测试 mode 为 MODE_FOR_NWEB_SPAWN 的情况 - content.content.mode = MODE_FOR_NWEB_SPAWN; - EXPECT_EQ(IsColdRunMode(&content), 0); -} - -HWTEST_F(AppSpawnManagerTest, IsColdRunMode_06, TestSize.Level0) -{ - // 测试 mode 为 MODE_INVALID 的情况 - content.content.mode = MODE_INVALID; - EXPECT_EQ(IsColdRunMode(&content), 0); -} - -// 测试用例 -HWTEST_F(AppSpawnManagerTest, IsDeveloperModeOn_01, TestSize.Level0) -{ - // 测试 property 为 NULL 的情况 - EXPECT_EQ(IsDeveloperModeOn(NULL), 0); -} - -HWTEST_F(AppSpawnManagerTest, IsDeveloperModeOn_02, TestSize.Level0) -{ - // 测试开发者模式开启的情况 - property.client.flags = APP_DEVELOPER_MODE; // 只设置开发者模式标志 - EXPECT_EQ(IsDeveloperModeOn(&property), 1); -} - -HWTEST_F(AppSpawnManagerTest, IsDeveloperModeOn_03, TestSize.Level0) -{ - // 测试开发者模式关闭的情况 - property.client.flags = 0; // 不设置任何标志 - EXPECT_EQ(IsDeveloperModeOn(&property), 0); -} - -HWTEST_F(AppSpawnManagerTest, IsDeveloperModeOn_04, TestSize.Level0) -{ - // 测试其他标志设置但未启用开发者模式 - property.client.flags = 0x01; // 只设置其他标志 - EXPECT_EQ(IsDeveloperModeOn(&property), 0); -} - -HWTEST_F(AppSpawnManagerTest, IsDeveloperModeOn_05, TestSize.Level0) -{ - // 测试开发者模式与其他标志同时设置 - property.client.flags = APP_DEVELOPER_MODE | 0x01; // 同时设置开发者模式和其他标志 - EXPECT_EQ(IsDeveloperModeOn(&property), 1); -} - -// 测试用例 -HWTEST_F(AppSpawnManagerTest, IsJitFortModeOn_01, TestSize.Level0) -{ - // 测试 property 为 NULL 的情况 - EXPECT_EQ(IsJitFortModeOn(NULL), 0); -} - -HWTEST_F(AppSpawnManagerTest, IsJitFortModeOn_02, TestSize.Level0) -{ - // 测试 JIT Fort 模式开启的情况 - property.client.flags = APP_JITFORT_MODE; // 只设置 JIT Fort 模式标志 - EXPECT_EQ(IsJitFortModeOn(&property), 1); -} - -HWTEST_F(AppSpawnManagerTest, IsJitFortModeOn_03, TestSize.Level0) -{ - // 测试 JIT Fort 模式关闭的情况 - property.client.flags = 0; // 不设置任何标志 - EXPECT_EQ(IsJitFortModeOn(&property), 0); -} - -HWTEST_F(AppSpawnManagerTest, IsJitFortModeOn_04, TestSize.Level0) -{ - // 测试其他标志设置但未启用 JIT Fort 模式 - property.client.flags = 0x01; // 只设置其他标志 - EXPECT_EQ(IsJitFortModeOn(&property), 0); -} - -HWTEST_F(AppSpawnManagerTest, IsJitFortModeOn_05, TestSize.Level0) -{ - // 测试 JIT Fort 模式与其他标志同时设置 - property.client.flags = APP_JITFORT_MODE | 0x01; // 同时设置 JIT Fort 模式和其他标志 - EXPECT_EQ(IsJitFortModeOn(&property), 1); -} - -// 测试用例 -HWTEST_F(AppSpawnManagerTest, GetAppSpawnMsgType_01, TestSize.Level0) -{ - // 测试 appProperty 为 NULL 的情况 - EXPECT_EQ(GetAppSpawnMsgType(NULL), MAX_TYPE_INVALID); -} - -HWTEST_F(AppSpawnManagerTest, GetAppSpawnMsgType_02, TestSize.Level0) -{ - // 测试 appProperty->message 为 NULL 的情况 - property.message = NULL; - EXPECT_EQ(GetAppSpawnMsgType(&property), MAX_TYPE_INVALID); -} - -HWTEST_F(AppSpawnManagerTest, GetAppSpawnMsgType_03, TestSize.Level0) -{ - // 测试 appProperty->message 有效的情况 - message.msgHeader.msgType = 42; // 设置有效的消息类型 - property.message = &message; // 将消息指针指向有效消息 - EXPECT_EQ(GetAppSpawnMsgType(&property), 42); -} - -HWTEST_F(AppSpawnManagerTest, GetAppSpawnMsgType_04, TestSize.Level0) -{ - // 测试 appProperty->message 有效且 msgType 为负值的情况 - message.msgHeader.msgType = -5; // 设置负值的消息类型 - property.message = &message; - EXPECT_EQ(GetAppSpawnMsgType(&property), -5); -} - -// 测试用例 -HWTEST_F(AppSpawnManagerTest, GetProcessName_01, TestSize.Level0) -{ - // 测试 property 为 NULL 的情况 - EXPECT_EQ(GetProcessName(NULL), nullptr); -} - -HWTEST_F(AppSpawnManagerTest, GetProcessName_02, TestSize.Level0) -{ - // 测试 property->message 为 NULL 的情况 - property.message = NULL; - EXPECT_EQ(GetProcessName(&property), nullptr); -} - -HWTEST_F(AppSpawnManagerTest, GetProcessName_03, TestSize.Level0) -{ - // 测试 property->message 有效且 processName 有效的情况 - const char *expectedName = "TestProcess"; - message.msgHeader.processName = expectedName; // 设置有效的进程名称 - property.message = &message; // 将消息指针指向有效消息 - EXPECT_EQ(GetProcessName(&property), expectedName); -} - -HWTEST_F(AppSpawnManagerTest, GetProcessName_04, TestSize.Level0) -{ - // 测试 processName 为 NULL 的情况 - message.msgHeader.processName = NULL; // 设置 processName 为 NULL - property.message = &message; - EXPECT_EQ(GetProcessName(&property), nullptr); -} -} // namespace OHOS diff --git a/test/unittest/appspawn_util_test/appspawn_util_test.cpp b/test/unittest/appspawn_util_test/appspawn_util_test.cpp deleted file mode 100644 index efe30b87..00000000 --- a/test/unittest/appspawn_util_test/appspawn_util_test.cpp +++ /dev/null @@ -1,736 +0,0 @@ -/* - * Copyright (c) 2024-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 "appspawn_utils.h" - - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -class AppSpawnUtilTest : public testing::Test { -public: - const char* testDir = "testDir"; // 测试目录 - const char* nestedDir = "testDir/nestedDir"; // 嵌套目录 - std::vector collectedStrings; - - static void SetUpTestCase() {} - static void TearDownTestCase() {} - void SetUp() - { - // 这里可以设置一些全局环境变量 - setenv("TEST_VAR", "test_value", 1); - - // 清除所有相关环境变量 - unsetenv("HNP_PRIVATE_HOME"); - unsetenv("HNP_PUBLIC_HOME"); - unsetenv("PATH"); - unsetenv("HOME"); - unsetenv("TMPDIR"); - unsetenv("SHELL"); - unsetenv("PWD"); - } - void TearDown() - { - // 清理环境变量 - unsetenv("TEST_VAR"); - } -}; - -HWTEST_F(AppSpawnSandboxCoverageTest, ConvertEnvValue_01, TestSize.Level0) -{ - const char* srcEnv = "This is a test: ${TEST_VAR} end."; - char dstEnv[100] = {0}; - - int result = ConvertEnvValue(srcEnv, dstEnv, sizeof(dstEnv)); - EXPECT_EQ(result, 0); - EXPECT_STREQ(dstEnv, "This is a test: test_value end."); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, ConvertEnvValue_02, TestSize.Level0) -{ - const char* srcEnv = "This will not resolve: ${NON_EXISTENT_VAR}."; - char dstEnv[100] = {0}; - - int result = ConvertEnvValue(srcEnv, dstEnv, sizeof(dstEnv)); - EXPECT_EQ(result, 0); - EXPECT_STREQ(dstEnv, "This will not resolve: ."); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, ConvertEnvValue_03, TestSize.Level0) -{ - const char* srcEnv = "Buffer size is too small: ${TEST_VAR}."; - char dstEnv[10] = {0}; // Buffer too small - - int result = ConvertEnvValue(srcEnv, dstEnv, sizeof(dstEnv)); - EXPECT_EQ(result, -1); // Expect failure due to buffer size -} - -HWTEST_F(AppSpawnSandboxCoverageTest, ConvertEnvValue_04, TestSize.Level0) -{ - char dstEnv[100] = {0}; - - int result = ConvertEnvValue(nullptr, dstEnv, sizeof(dstEnv)); - EXPECT_EQ(result, -1); // Expect failure due to null source -} - -HWTEST_F(AppSpawnSandboxCoverageTest, ConvertEnvValue_05, TestSize.Level0) -{ - const char* srcEnv = "This should not work: ${TEST_VAR}."; - - int result = ConvertEnvValue(srcEnv, nullptr, sizeof(dstEnv)); - EXPECT_EQ(result, -1); // Expect failure due to null destination -} - -HWTEST_F(AppSpawnSandboxCoverageTest, ConvertEnvValue_06, TestSize.Level0) -{ - const char* srcEnv = ""; - char dstEnv[100] = {0}; - - int result = ConvertEnvValue(srcEnv, dstEnv, sizeof(dstEnv)); - EXPECT_EQ(result, 0); - EXPECT_STREQ(dstEnv, ""); // Expect empty result -} -// 测试用例:检查环境变量是否正确设置 -HWTEST_F(AppSpawnSandboxCoverageTest, InitCommonEnv_01, TestSize.Level0) -{ - InitCommonEnv(); - - EXPECT_STREQ(getenv("HNP_PRIVATE_HOME"), "/data/app"); - EXPECT_STREQ(getenv("HNP_PUBLIC_HOME"), "/data/service/hnp"); - EXPECT_STREQ(getenv("HOME"), nullptr); // 期望为空,因为开发者模式关闭 - EXPECT_STREQ(getenv("TMPDIR"), nullptr); // 期望为空,因为开发者模式关闭 - EXPECT_STREQ(getenv("SHELL"), nullptr); // 期望为空,因为开发者模式关闭 - EXPECT_STREQ(getenv("PWD"), nullptr); // 期望为空,因为开发者模式关闭 -} - -// 测试用例:验证 PATH 环境变量的设置 -HWTEST_F(AppSpawnSandboxCoverageTest, InitCommonEnv_02, TestSize.Level0) -{ - InitCommonEnv(); - - const char* pathValue = getenv("PATH"); - ASSERT_NE(pathValue, nullptr); // 确保 PATH 不为空 - - // 验证 PATH 中是否包含开发者模式下设置的变量 - EXPECT_NE(std::string(pathValue).find("/data/app/bin"), std::string::npos); - EXPECT_NE(std::string(pathValue).find("/data/service/hnp/bin"), std::string::npos); -} - -// 测试用例:验证开发者模式下未设置的环境变量 -HWTEST_F(AppSpawnSandboxCoverageTest, InitCommonEnv_03, TestSize.Level0) -{ - InitCommonEnv(); - - EXPECT_STREQ(getenv("HOME"), nullptr); - EXPECT_STREQ(getenv("TMPDIR"), nullptr); - EXPECT_STREQ(getenv("SHELL"), nullptr); - EXPECT_STREQ(getenv("PWD"), nullptr); -} - -// 测试用例:检查重复设置同一变量的情况 -HWTEST_F(AppSpawnSandboxCoverageTest, InitCommonEnv_04, TestSize.Level0) -{ - setenv("HNP_PRIVATE_HOME", "/original/path", 1); - InitCommonEnv(); - - EXPECT_STREQ(getenv("HNP_PRIVATE_HOME"), "/data/app"); // 应被覆盖 -} - -// 测试用例:检查环境变量是否持久化 -HWTEST_F(AppSpawnSandboxCoverageTest, InitCommonEnv_05, TestSize.Level0) -{ - InitCommonEnv(); - - const char* originalPath = getenv("PATH"); - InitCommonEnv(); // 再次调用以检查是否持久化 - const char* newPath = getenv("PATH"); - - EXPECT_STREQ(originalPath, newPath); // PATH 应该保持不变 -} - -// 测试用例:检查环境变量在不同调用中的一致性 -HWTEST_F(AppSpawnSandboxCoverageTest, InitCommonEnv_06, TestSize.Level0) -{ - InitCommonEnv(); - const char* privateHome1 = getenv("HNP_PRIVATE_HOME"); - - // 重置并再调用 - SetUp(); - InitCommonEnv(); - const char* privateHome2 = getenv("HNP_PRIVATE_HOME"); - - EXPECT_STREQ(privateHome1, privateHome2); // 应保持一致 -} - -// 测试用例:起始时间和结束时间相同 -HWTEST_F(AppSpawnSandboxCoverageTest, DiffTime_01, TestSize.Level0) -{ - struct timespec startTime = {5, 500000000}; // 5.5 秒 - struct timespec endTime = {5, 500000000}; // 5.5 秒 - - EXPECT_EQ(DiffTime(&startTime, &endTime), 0); -} - -// 测试用例:结束时间晚于起始时间 -HWTEST_F(AppSpawnSandboxCoverageTest, DiffTime_02, TestSize.Level0) -{ - struct timespec startTime = {1, 200000000}; // 1.2 秒 - struct timespec endTime = {1, 800000000}; // 1.8 秒 - - EXPECT_EQ(DiffTime(&startTime, &endTime), 600000); // 600 ms = 600000 us -} - -// 测试用例:跨秒的时间差 -HWTEST_F(AppSpawnSandboxCoverageTest, DiffTime_03, TestSize.Level0) -{ - struct timespec startTime = {1, 999000000}; // 1.999 秒 - struct timespec endTime = {2, 500000000}; // 2.5 秒 - - EXPECT_EQ(DiffTime(&startTime, &endTime), 501000); // 501 ms = 501000 us -} - -// 测试用例:结束时间早于起始时间 -HWTEST_F(AppSpawnSandboxCoverageTest, DiffTime_04, TestSize.Level0) -{ - struct timespec startTime = {3, 500000000}; // 3.5 秒 - struct timespec endTime = {3, 200000000}; // 3.2 秒 - - EXPECT_EQ(DiffTime(&startTime, &endTime), 300000); // 300 ms = 300000 us -} - -// 测试用例:NULL 指针处理 -HWTEST_F(AppSpawnSandboxCoverageTest, DiffTime_05, TestSize.Level0) -{ - struct timespec endTime = {3, 200000000}; // 3.2 秒 - EXPECT_EQ(DiffTime(NULL, &endTime), 0); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, DiffTime_06, TestSize.Level0) -{ - struct timespec startTime = {3, 500000000}; // 3.5 秒 - EXPECT_EQ(DiffTime(&startTime, NULL), 0); -} - -// 测试用例:两个 NULL 指针 -HWTEST_F(AppSpawnSandboxCoverageTest, DiffTime_07, TestSize.Level0) -{ - EXPECT_EQ(DiffTime(NULL, NULL), 0); -} - -// 测试用例:结束时间早于起始时间(负值情况) -HWTEST_F(AppSpawnSandboxCoverageTest, DiffTime_08, TestSize.Level0) -{ - struct timespec startTime = {2, 500000000}; // 2.5 秒 - struct timespec endTime = {2, 200000000}; // 2.2 秒 - - EXPECT_EQ(DiffTime(&startTime, &endTime), 300000); // 300 ms = 300000 us -} - -// 测试用例:起始时间和结束时间的纳秒部分不同 -HWTEST_F(AppSpawnSandboxCoverageTest, DiffTime_09, TestSize.Level0) -{ - struct timespec startTime = {1, 500000000}; // 1.5 秒 - struct timespec endTime = {1, 999000000}; // 1.999 秒 - - EXPECT_EQ(DiffTime(&startTime, &endTime), 499000); // 499 ms = 499000 us -} - -// 测试用例:大时间间隔 -HWTEST_F(AppSpawnSandboxCoverageTest, DiffTime_10, TestSize.Level0) -{ - struct timespec startTime = {1000, 0}; // 1000 秒 - struct timespec endTime = {2000, 0}; // 2000 秒 - - EXPECT_EQ(DiffTime(&startTime, &endTime), 1000000000); // 1000 秒 = 1000000000 us -} - -// 测试用例:时间为零的情况 -HWTEST_F(AppSpawnSandboxCoverageTest, DiffTime_11, TestSize.Level0) -{ - struct timespec startTime = {0, 0}; // 0 秒 - struct timespec endTime = {0, 0}; // 0 秒 - - EXPECT_EQ(DiffTime(&startTime, &endTime), 0); -} - -// 测试用例:非常大的时间值 -HWTEST_F(AppSpawnSandboxCoverageTest, DiffTime_12, TestSize.Level0) -{ - struct timespec startTime = {INT32_MAX, 999999999}; // 最大整型值 - struct timespec endTime = {INT32_MAX + 1, 0}; // 超过最大值 - - EXPECT_EQ(DiffTime(&startTime, &endTime), 1); // 应返回 1 微秒 -} - -// 测试用例:相同的秒和纳秒但以不同的顺序 -HWTEST_F(AppSpawnSandboxCoverageTest, DiffTime_13, TestSize.Level0) -{ - struct timespec startTime = {2, 500000000}; // 2.5 秒 - struct timespec endTime = {2, 500000000}; // 2.5 秒 - - EXPECT_EQ(DiffTime(&startTime, &endTime), 0); -} - -// 测试用例:创建嵌套目录 -HWTEST_F(AppSpawnSandboxCoverageTest, MakeDirRec_01, TestSize.Level0) -{ - EXPECT_EQ(MakeDirRec(nestedDir, 0755, 1), 0); - struct stat sb; - EXPECT_EQ(stat("testDir", &sb), 0); - EXPECT_TRUE(S_ISDIR(sb.st_mode)); - EXPECT_EQ(stat("testDir/nestedDir", &sb), 0); - EXPECT_TRUE(S_ISDIR(sb.st_mode)); -} - -// 测试用例:已存在的目录 -HWTEST_F(AppSpawnSandboxCoverageTest, MakeDirRec_02, TestSize.Level0) -{ - mkdir(testDir, 0755); // 先手动创建 - EXPECT_EQ(MakeDirRec(nestedDir, 0755, 1), 0); - // 确保目录依然存在 - struct stat sb; - EXPECT_EQ(stat("testDir", &sb), 0); - EXPECT_TRUE(S_ISDIR(sb.st_mode)); - EXPECT_EQ(stat("testDir/nestedDir", &sb), 0); - EXPECT_TRUE(S_ISDIR(sb.st_mode)); -} - -// 测试用例:无效路径 -HWTEST_F(AppSpawnSandboxCoverageTest, MakeDirRec_03, TestSize.Level0) -{ - EXPECT_EQ(MakeDirRec(NULL, 0755, 1), -1); - EXPECT_EQ(MakeDirRec("", 0755, 1), -1); -} - -// 测试用例:仅创建最后路径 -HWTEST_F(AppSpawnSandboxCoverageTest, MakeDirRec_04, TestSize.Level0) -{ - EXPECT_EQ(MakeDirRec(testDir, 0755, 1), 0); - struct stat sb; - EXPECT_EQ(stat("testDir", &sb), 0); - EXPECT_TRUE(S_ISDIR(sb.st_mode)); -} - -// 测试用例:未创建中间目录 -HWTEST_F(AppSpawnSandboxCoverageTest, MakeDirRec_05, TestSize.Level0) -{ - EXPECT_EQ(MakeDirRec("testDir/nestedDir", 0755, 1), 0); - // 应该无法创建中间目录 - struct stat sb; - EXPECT_EQ(stat("testDir", &sb), -1); // 中间目录应不存在 - EXPECT_EQ(errno, ENOENT); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, MakeDirRec_06, TestSize.Level0) -{ - EXPECT_EQ(MakeDirRec("invalidModeDir", 1000, 1), -1); - EXPECT_EQ(errno, EINVAL); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, MakeDirRec_07, TestSize.Level0) -{ - const char* multiDir = "testDir1/testDir2/testDir3"; - EXPECT_EQ(MakeDirRec(multiDir, 0755, 1), 0); - struct stat sb; - EXPECT_EQ(stat("testDir1/testDir2", &sb), 0); - EXPECT_TRUE(S_ISDIR(sb.st_mode)); - EXPECT_EQ(stat("testDir1/testDir2/testDir3", &sb), 0); - EXPECT_TRUE(S_ISDIR(sb.st_mode)); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, MakeDirRec_08, TestSize.Level0) -{ - mkdir(testDir, 0755); // 创建中间目录 - EXPECT_EQ(MakeDirRec("testDir/partiallyExists/nestedDir", 0755, 1), 0); - struct stat sb; - EXPECT_EQ(stat("testDir/partiallyExists", &sb), 0); - EXPECT_TRUE(S_ISDIR(sb.st_mode)); - EXPECT_EQ(stat("testDir/partiallyExists/nestedDir", &sb), 0); - EXPECT_TRUE(S_ISDIR(sb.st_mode)); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, MakeDirRec_09, TestSize.Level0) -{ - mkdir("noPermissionDir", 0400); // 创建只读目录 - EXPECT_EQ(MakeDirRec("noPermissionDir/nestedDir", 0755, 1), -1); - EXPECT_EQ(errno, EACCES); - rmdir("noPermissionDir"); // 清理 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, MakeDirRec_10, TestSize.Level0) -{ - std::string longPath = "testDir/" + std::string(1000, 'a'); - EXPECT_EQ(MakeDirRec(longPath.c_str(), 0755, 1), -1); - EXPECT_EQ(errno, ENAMETOOLONG); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, MakeDirRec_11, TestSize.Level0) -{ - const char* specialDir = "test Dir/@!#"; - EXPECT_EQ(MakeDirRec(specialDir, 0755, 1), 0); - struct stat sb; - EXPECT_EQ(stat("test Dir/@!#", &sb), 0); - EXPECT_TRUE(S_ISDIR(sb.st_mode)); -} - -// 测试用例 -HWTEST_F(AppSpawnSandboxCoverageTest, StringSplit_01, TestSize.Level0) -{ - const char* input = "one,two,three"; - const char* separator = ","; - StringSplit(input, separator, &collectedStrings, CollectStrings); - EXPECT_EQ(collectedStrings.size(), 3); - EXPECT_EQ(collectedStrings[0], "one"); - EXPECT_EQ(collectedStrings[1], "two"); - EXPECT_EQ(collectedStrings[2], "three"); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, StringSplit_02, TestSize.Level0) -{ - const char* input = "one,,three"; - const char* separator = ","; - StringSplit(input, separator, &collectedStrings, CollectStrings); - EXPECT_EQ(collectedStrings.size(), 3); - EXPECT_EQ(collectedStrings[0], "one"); - EXPECT_EQ(collectedStrings[1], ""); - EXPECT_EQ(collectedStrings[2], "three"); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, StringSplit_03, TestSize.Level0) -{ - const char* input = " one, two , three "; - const char* separator = ","; - StringSplit(input, separator, &collectedStrings, CollectStrings); - EXPECT_EQ(collectedStrings.size(), 3); - EXPECT_EQ(collectedStrings[0], " one"); - EXPECT_EQ(collectedStrings[1], " two "); - EXPECT_EQ(collectedStrings[2], " three "); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, StringSplit_04, TestSize.Level0) -{ - const char* input = "onelinetext"; - const char* separator = ","; - StringSplit(input, separator, &collectedStrings, CollectStrings); - EXPECT_EQ(collectedStrings.size(), 1); - EXPECT_EQ(collectedStrings[0], "onelinetext"); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, StringSplit_05, TestSize.Level0) -{ - const char* input = ""; - const char* separator = ","; - StringSplit(input, separator, &collectedStrings, CollectStrings); - EXPECT_EQ(collectedStrings.size(), 0); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, StringSplit_06, TestSize.Level0) -{ - const char* separator = ","; - int result = StringSplit(nullptr, separator, &collectedStrings, CollectStrings); - EXPECT_EQ(result, APPSPAWN_ARG_INVALID); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, StringSplit_07, TestSize.Level0) -{ - const char* input = "one,two,three"; - int result = StringSplit(input, nullptr, &collectedStrings, CollectStrings); - EXPECT_EQ(result, APPSPAWN_ARG_INVALID); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, StringSplit_08, TestSize.Level0) -{ - const char* input = "one,two,three"; - const char* separator = ","; - int result = StringSplit(input, separator, &collectedStrings, nullptr); - EXPECT_EQ(result, APPSPAWN_ARG_INVALID); -} - -// 测试用例 -HWTEST_F(AppSpawnSandboxCoverageTest, GetLastStr_01, TestSize.Level0) -{ - const char* input = "hello world, hello"; - const char* search = "hello"; - char* result = GetLastStr(input, search); - EXPECT_STREQ(result, "hello"); // 检查返回的字符串 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, GetLastStr_02, TestSize.Level0) -{ - const char* input = "hello world"; - const char* search = "test"; - char* result = GetLastStr(input, search); - EXPECT_EQ(result, nullptr); // 没有匹配,返回 nullptr -} - -HWTEST_F(AppSpawnSandboxCoverageTest, GetLastStr_03, TestSize.Level0) -{ - const char* input = ""; - const char* search = "hello"; - char* result = GetLastStr(input, search); - EXPECT_EQ(result, nullptr); // 空字符串,返回 nullptr -} - -HWTEST_F(AppSpawnSandboxCoverageTest, GetLastStr_04, TestSize.Level0) -{ - const char* search = "hello"; - char* result = GetLastStr(nullptr, search); - EXPECT_EQ(result, nullptr); // 输入为 nullptr,返回 nullptr -} - -HWTEST_F(AppSpawnSandboxCoverageTest, GetLastStr_05, TestSize.Level0) -{ - const char* input = "hello world"; - char* result = GetLastStr(input, nullptr); - EXPECT_EQ(result, nullptr); // 查找字符串为 nullptr,返回 nullptr -} - -HWTEST_F(AppSpawnSandboxCoverageTest, GetLastStr_06, TestSize.Level0) -{ - const char* input = "hello hello"; - const char* search = "hello"; - char* result = GetLastStr(input, search); - EXPECT_STREQ(result, "hello"); // 最后一次出现的字符串 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, GetLastStr_07, TestSize.Level0) -{ - const char* input = "hello world hello"; - const char* search = "hello"; - char* result = GetLastStr(input, search); - EXPECT_STREQ(result, "hello"); // 最后一次出现的字符串 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, GetLastStr_08, TestSize.Level0) -{ - const char* input = "hello world hello"; - const char* search = "hello"; - char* result = GetLastStr(input, search); - EXPECT_STREQ(result, "hello"); // 处理空格 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, GetLastStr_09, TestSize.Level0) -{ - const char* input = "abcabcabc"; - const char* search = "abc"; - char* result = GetLastStr(input, search); - EXPECT_STREQ(result, "abcabcabc"); // 测试重叠匹配 -} - -// 测试用例 -HWTEST_F(AppSpawnSandboxCoverageTest, CreateTestFile_01, TestSize.Level0) -{ - const char* fileName = "test_success.txt"; - const char* content = "Hello, World!"; - CreateTestFile(fileName, content); - - char* result = ReadFile(fileName); - ASSERT_NE(result, nullptr); // 确保返回值不为 nullptr - EXPECT_STREQ(result, content); // 检查读取内容是否正确 - - free(result); // 释放内存 - RemoveTestFile(fileName); // 清理测试文件 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, CreateTestFile_02, TestSize.Level0) -{ - const char* fileName = "nonexistent_file.txt"; - char* result = ReadFile(fileName); - EXPECT_EQ(result, nullptr); // 应返回 nullptr -} - -HWTEST_F(AppSpawnSandboxCoverageTest, CreateTestFile_03, TestSize.Level0) -{ - const char* fileName = "empty_file.txt"; - CreateTestFile(fileName, ""); // 创建空文件 - - char* result = ReadFile(fileName); - EXPECT_EQ(result, nullptr); // 应返回 nullptr - - RemoveTestFile(fileName); // 清理测试文件 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, CreateTestFile_04, TestSize.Level0) -{ - const char* fileName = "large_file.txt"; - const size_t size = MAX_JSON_FILE_LEN + 1; // 假设定义了 MAX_JSON_FILE_LEN - char* content = new char[size]; - int ret = memset_s(content, 'A', size - 1); - if (ret != 0) { - return; - } - content[size - 1] = '\0'; // 确保以 null 结尾 - - CreateTestFile(fileName, content); // 创建超大文件 - - char* result = ReadFile(fileName); - EXPECT_EQ(result, nullptr); // 应返回 nullptr - - delete[] content; // 清理内存 - RemoveTestFile(fileName); // 清理测试文件 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, CreateTestFile_05, TestSize.Level0) -{ - char* result = ReadFile(nullptr); // 传入 nullptr - EXPECT_EQ(result, nullptr); // 应返回 nullptr -} - -// 测试用例 -HWTEST_F(AppSpawnSandboxCoverageTest, DumpCurrentDir_01, TestSize.Level0) -{ - int ret = DumpCurrentDir(NULL, 100, "test_dir"); - EXPECT_EQ(ret, /* 需要返回的错误码 */); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, DumpCurrentDir_02, TestSize.Level0) -{ - char buffer[100]; - DumpCurrentDir(buffer, 100, NULL); - // 检查是否处理了错误,可能通过日志或返回值 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, DumpCurrentDir_03, TestSize.Level0) -{ - char buffer[100]; - DumpCurrentDir(buffer, 0, "test_dir"); - // 检查是否处理了错误 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, DumpCurrentDir_04, TestSize.Level0) -{ - char buffer[100]; - DumpCurrentDir(buffer, 100, "invalid_dir"); - // 检查是否处理了打开目录失败的情况 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, DumpCurrentDir_05, TestSize.Level0) -{ - // 创建一个空目录 - mkdir("empty_dir", 0755); - char buffer[100]; - DumpCurrentDir(buffer, 100, "empty_dir"); - // 检查没有输出 - rmdir("empty_dir"); -} -<<<<<<< Updated upstream - -HWTEST_F(AppSpawnSandboxCoverageTest, DumpCurrentDir_06, TestSize.Level0) -{ - // 创建一个只包含 . 和 .. 的目录 - mkdir("dot_dir", 0755); - chdir("dot_dir"); - char buffer[100]; - DumpCurrentDir(buffer, 100, "."); - // 检查没有输出 - chdir(".."); - rmdir("dot_dir"); -} - -HWTEST_F(AppSpawnSandboxCoverageTest, DumpCurrentDir_7, TestSize.Level0) -{ - char buffer[256]; - int ret = memset_s(buffer, 0, sizeof(buffer)); // 清空 buffer - if (ret != 0) { - return; - } - DumpCurrentDir(buffer, sizeof(buffer), "test_dir"); - - // 检查 buffer 是否包含预期的输出 - EXPECT_NE(strstr(buffer, "Current path test_dir/test_file.txt"), nullptr); - EXPECT_NE(strstr(buffer, "Current path test_dir/sub_dir"), nullptr); -} - -// 测试用例 -HWTEST_F(AppSpawnSandboxCoverageTest, IsDeveloperModeOpen_01, TestSize.Level0) -{ - mockValue = "true"; - mockReturnValue = 1; // 模拟成功 - EXPECT_EQ(IsDeveloperModeOpen(), 1); // 期待返回 1 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, IsDeveloperModeOpen_02, TestSize.Level0) -{ - mockValue = "false"; - mockReturnValue = 1; // 模拟成功 - EXPECT_EQ(IsDeveloperModeOpen(), 0); // 期待返回 0 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, IsDeveloperModeOpen_03, TestSize.Level0) -{ - mockValue = "true"; - mockReturnValue = -1; // 模拟失败 - EXPECT_EQ(IsDeveloperModeOpen(), 0); // 期待返回 0 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, IsDeveloperModeOpen_04, TestSize.Level0) -{ - mockValue = "false"; - mockReturnValue = 0; // 模拟未找到参数 - EXPECT_EQ(IsDeveloperModeOpen(), 0); // 期待返回 0 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, IsDeveloperModeOpen_05, TestSize.Level0) -{ - mockValue = nullptr; // 模拟未设置值 - mockReturnValue = 0; // 模拟未找到参数 - EXPECT_EQ(IsDeveloperModeOpen(), 0); // 期待返回 0 -} - -// 测试用例 -HWTEST_F(AppSpawnSandboxCoverageTest, GetSpawnTimeout_01, TestSize.Level0) -{ - mockValue = "30"; // 设置模拟返回值 - mockReturnValue = 1; // 模拟成功返回 - EXPECT_EQ(GetSpawnTimeout(10), 30); // 期待返回 30 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, GetSpawnTimeout_02, TestSize.Level0) -{ - mockValue = "0"; // 设置模拟返回值为 "0" - mockReturnValue = 1; // 模拟成功返回 - EXPECT_EQ(GetSpawnTimeout(10), 10); // 期待返回默认值 10 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, GetSpawnTimeout_03, TestSize.Level0) -{ - mockValue = nullptr; // 模拟未设置值 - mockReturnValue = 0; // 模拟未找到参数 - EXPECT_EQ(GetSpawnTimeout(10), 10); // 期待返回默认值 10 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, GetSpawnTimeout_04, TestSize.Level0) -{ - mockValue = "abc"; // 设置模拟返回值为无效的数字 - mockReturnValue = 1; // 模拟成功返回 - EXPECT_EQ(GetSpawnTimeout(10), 10); // 期待返回默认值 10 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, GetSpawnTimeout_05, TestSize.Level0) -{ - mockValue = "5"; // 设置模拟返回值小于默认值 - mockReturnValue = 1; // 模拟成功返回 - EXPECT_EQ(GetSpawnTimeout(10), 10); // 期待返回默认值 10 -} - -HWTEST_F(AppSpawnSandboxCoverageTest, GetSpawnTimeout_06, TestSize.Level0) -{ - mockValue = "20"; // 设置模拟返回值大于默认值 - mockReturnValue = 1; // 模拟成功返回 - EXPECT_EQ(GetSpawnTimeout(10), 20); // 期待返回 20 -} -} // namespace OHOS -- Gitee From 35faf5cdcdf8eb91b5481c63c65d3a086742edb4 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Mon, 11 Nov 2024 16:53:40 +0800 Subject: [PATCH 032/148] fix:Switching user scenarios Signed-off-by: wangfeng --- modules/sandbox/sandbox_utils.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index d677bbda..a13483ab 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -1918,7 +1918,13 @@ static int MountInShared(const AppSpawningCtx *property, const char *rootPath, c return APPSPAWN_ERROR_UTILS_MEM_FAIL; } - if (access(path, F_OK) == 0) { + char currentUserPath[PATH_MAX_LEN] = {0}; + ret = snprintf_s(currentUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/currentUser", path); + if (ret <= 0) { + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + if (access(currentUserPath, F_OK) == 0) { return 0; } @@ -1947,11 +1953,17 @@ static int SharedMountInSharefs(const AppSpawningCtx *property, const char *root return APPSPAWN_ARG_INVALID; } - if (access(target, F_OK) == 0) { + char currentUserPath[PATH_MAX_LEN] = {0}; + int ret = snprintf_s(currentUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/currentUser", target); + if (ret <= 0) { + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + if (access(currentUserPath, F_OK) == 0) { return 0; } - int ret = MakeDirRec(target, DIR_MODE, 1); + ret = MakeDirRec(target, DIR_MODE, 1); if (ret != 0) { return APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL; } -- Gitee From cb1df6fad41f99e66280e71ec07f6255f98250db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Mon, 11 Nov 2024 20:18:47 +0800 Subject: [PATCH 033/148] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E8=87=B4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- modules/common/appspawn_encaps.c | 2 +- modules/sandbox/sandbox_cfgvar.c | 4 ++-- modules/sandbox/sandbox_expand.c | 2 +- modules/sandbox/sandbox_utils.h | 2 +- service/hnp/base/hnp_base.h | 4 ++++ standard/appspawn_service.h | 6 +++++- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/common/appspawn_encaps.c b/modules/common/appspawn_encaps.c index 60a40b05..ff158e63 100644 --- a/modules/common/appspawn_encaps.c +++ b/modules/common/appspawn_encaps.c @@ -85,7 +85,7 @@ static int WriteEncapsInfo(int fd, AppSpawnEncapsBaseType encapsType, const char APPSPAWN_STATIC int EnableEncapsForProc(int encapsFileFd) { - uint32_t flag = OH_PROC_APP; + uint32_t flag = OH_PROC_HAP; return WriteEncapsInfo(encapsFileFd, ENCAPS_PROC_TYPE_MODE, OH_ENCAPS_DEFAULT_STR, flag); } diff --git a/modules/sandbox/sandbox_cfgvar.c b/modules/sandbox/sandbox_cfgvar.c index ac035918..78384842 100644 --- a/modules/sandbox/sandbox_cfgvar.c +++ b/modules/sandbox/sandbox_cfgvar.c @@ -287,8 +287,8 @@ static int HandleVariableReplace(const SandboxContext *context, return 0; } -const char *GetSandboxRealVar(const SandboxContext *context, - uint32_t bufferType, const char *source, const char *prefix, const VarExtraData *extraData) +const char *GetSandboxRealVar(const SandboxContext *context, uint32_t bufferType, const char *source, + const char *prefix, const VarExtraData *extraData) { APPSPAWN_CHECK_ONLY_EXPER(context != NULL, return NULL); APPSPAWN_CHECK(bufferType < ARRAY_LENGTH(context->buffer), return NULL, "Invalid index for buffer"); diff --git a/modules/sandbox/sandbox_expand.c b/modules/sandbox/sandbox_expand.c index 21f0d15a..dfc4091b 100644 --- a/modules/sandbox/sandbox_expand.c +++ b/modules/sandbox/sandbox_expand.c @@ -167,7 +167,7 @@ static int SetOverlayAppPath(const char *hapPath, void *context) sandboxContext->buffer[0].buffer, sandboxContext->buffer[1].buffer); ret = MakeDirRec(sandboxContext->buffer[1].buffer, FILE_MODE, 1); - APPSPAWN_CHECK(ret == 0, return ret, "Fail to mkdir dir %{public}s, ret :%{public}d", + APPSPAWN_CHECK(ret == 0, return ret, "Fail to mkdir dir %{public}s, ret :%{public}d", sandboxContext->buffer[1].buffer, ret); MountArg mountArg = { sandboxContext->buffer[0].buffer, sandboxContext->buffer[1].buffer, NULL, MS_REC | MS_BIND, NULL, MS_SHARED diff --git a/modules/sandbox/sandbox_utils.h b/modules/sandbox/sandbox_utils.h index 429f0952..2493bac5 100755 --- a/modules/sandbox/sandbox_utils.h +++ b/modules/sandbox/sandbox_utils.h @@ -119,7 +119,7 @@ private: static std::string GetSandboxPath(const AppSpawningCtx *appProperty, nlohmann::json &mntPoint, const std::string §ion, std::string sandboxRoot); static void GetSandboxMountConfig(const AppSpawningCtx *appProperty, const std::string §ion, - nlohmann::json &mntPoint,SandboxMountConfig &mountConfig); + nlohmann::json &mntPoint, SandboxMountConfig &mountConfig); #ifdef APPSPAWN_MOUNT_TMPSHM static void MountDevShmPath(std::string &sandboxPath); #endif diff --git a/service/hnp/base/hnp_base.h b/service/hnp/base/hnp_base.h index 0527a9d1..5129a0de 100644 --- a/service/hnp/base/hnp_base.h +++ b/service/hnp/base/hnp_base.h @@ -40,8 +40,12 @@ extern "C" { #endif #ifndef MAX_FILE_PATH_LEN +#if PATH_MAX > 4096 +#define MAX_FILE_PATH_LEN PATH_MAX +#else #define MAX_FILE_PATH_LEN 4096 #endif +#endif #define HNP_VERSION_LEN 32 #define BUFFER_SIZE 1024 diff --git a/standard/appspawn_service.h b/standard/appspawn_service.h index 4e91ba17..cfbf7b54 100644 --- a/standard/appspawn_service.h +++ b/standard/appspawn_service.h @@ -32,7 +32,11 @@ extern "C" { #endif -#ifdef APPSPAWN_TEST +#ifdef ASAN_DETECTR +#define MAX_WAIT_MSG_COMPLETE (5 * 1000) // 5s +#define COLD_CHILD_RESPONSE_TIMEOUT 60 +#define WAIT_CHILD_RESPONSE_TIMEOUT 60 //60s +#elif APPSPAWN_TEST #define MAX_WAIT_MSG_COMPLETE (5 * 100) // 500ms #define COLD_CHILD_RESPONSE_TIMEOUT 5 #define WAIT_CHILD_RESPONSE_TIMEOUT 3 //3s -- Gitee From 4d9be20f4b7d9fe0aeb3a024c9187213be34ec3d Mon Sep 17 00:00:00 2001 From: yangkan Date: Tue, 12 Nov 2024 16:00:27 +0800 Subject: [PATCH 034/148] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangkan --- modules/common/appspawn_encaps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/common/appspawn_encaps.c b/modules/common/appspawn_encaps.c index 60a40b05..0c99090a 100644 --- a/modules/common/appspawn_encaps.c +++ b/modules/common/appspawn_encaps.c @@ -67,7 +67,7 @@ static int WriteEncapsInfo(int fd, AppSpawnEncapsBaseType encapsType, const char int ret = 0; switch (encapsType) { - case ENCAPS_MAX_TYPE_MODE: + case ENCAPS_PROC_TYPE_MODE: ret = ioctl(fd, SET_ENCAPS_PROC_TYPE_CMD, &flag); break; case ENCAPS_PERMISSION_TYPE_MODE: -- Gitee From 36022b755321d9274d46cd511bed29c9dd827ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Tue, 12 Nov 2024 19:29:18 +0800 Subject: [PATCH 035/148] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E8=87=B4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- interfaces/innerkits/include/appspawn.h | 1 + modules/module_engine/include/appspawn_hook.h | 2 +- modules/nweb_adapter/nwebspawn_adapter.cpp | 3 ++- service/hnp/installer/api_hnp.md | 21 ++++++++++--------- .../app_spawn_service_test.cpp | 1 + 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index 1891c12c..aba32c0f 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -107,6 +107,7 @@ typedef enum { MSG_UPDATE_MOUNT_POINTS, MSG_RESTART_SPAWNER, MSG_DEVICE_DEBUG, + MSG_UNINSTALL_DEBUG_HAP, MAX_TYPE_INVALID } AppSpawnMsgType; diff --git a/modules/module_engine/include/appspawn_hook.h b/modules/module_engine/include/appspawn_hook.h index f8df0b10..856f5e80 100644 --- a/modules/module_engine/include/appspawn_hook.h +++ b/modules/module_engine/include/appspawn_hook.h @@ -65,7 +65,7 @@ typedef enum TagAppSpawnHookStage { STAGE_PARENT_POST_FORK = 21, STAGE_PARENT_PRE_RELY = 22, STAGE_PARENT_POST_RELY = 23, - + STAGE_PARENT_UNINSTALL, // run in child process STAGE_CHILD_PRE_COLDBOOT = 30, // clear env, set token before cold boot STAGE_CHILD_EXECUTE, diff --git a/modules/nweb_adapter/nwebspawn_adapter.cpp b/modules/nweb_adapter/nwebspawn_adapter.cpp index 8ca434a5..d926d644 100644 --- a/modules/nweb_adapter/nwebspawn_adapter.cpp +++ b/modules/nweb_adapter/nwebspawn_adapter.cpp @@ -118,7 +118,8 @@ APPSPAWN_STATIC int RunChildProcessor(AppSpawnContent *content, AppSpawnClient * // preload libweb_engine webEngineHandle = dlopen_ns(&dlns, engineLibName.c_str(), RTLD_NOW | RTLD_GLOBAL); // load libnweb_render - nwebRenderHandle = dlopen_ns(&dlns, renderLibName.c_str(), RTLD_NOW | RTLD_GLOBAL); + nwebRenderHandle = + dlopen_ns(&dlns, renderLibName.c_str(), RTLD_NOW | RTLD_GLOBAL); #else // preload libweb_engine const std::string engineLibPath = libPath + "/" + engineLibName; diff --git a/service/hnp/installer/api_hnp.md b/service/hnp/installer/api_hnp.md index c907eaa4..70e31b94 100644 --- a/service/hnp/installer/api_hnp.md +++ b/service/hnp/installer/api_hnp.md @@ -6,20 +6,20 @@ ### 文件 -| 名称 | 描述 | -| -------- | -------- | +| 名称 | 描述 | +| --------- | ------------------------------------------------------------------------------------------------------------------------------------- | | hnp_api.h | 提供支持Native软件的安装和卸载的函数。
**引用文件**:<hnp_api.h>
**库**:libhnpapi.z.so | - ### 结构体定义 + NA ### 函数 -| 名称 | 描述 | -| -------- | -------- | -| [NativeInstallHnp](#nativeinstallhnp) | 安装Native软件到设备中 | -| [NativeUnInstallHnp](#nativeuninstallhnp)| 卸载设备中已安装的Native软件 | +| 名称 | 描述 | +| -------------------------------------- | ---------------------------- | +| [NativeInstallHnp](#nativeinstallhnp) | 安装Native软件到设备中 | +| [NativeUnInstallHnp](#nativeuninstallhnp) | 卸载设备中已安装的Native软件 | ## 函数说明 @@ -55,15 +55,16 @@ int NativeInstallHnp(const char *userId, const char *hnpRootPath, const HapInfo ``` installOptions:安装选项。其中每一位对应的选项信息枚举如下。 - ``` + +``` typedef enum { OPTION_INDEX_FORCE = 0, /* installed forcely */ OPTION_INDEX_BUTT } HnpInstallOptionIndex; - ``` +``` **返回:** - + 安装成功返回0;失败返回错误码 ### NativeUnInstallHnp diff --git a/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp index 31b0d807..3b8d7f22 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp @@ -446,6 +446,7 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_005, TestSize.Level0) ret = respMsg->result.result; (void)RecvMsg(socketId, buffer2.data(), buffer2.size()); } while (0); + ret = 0; // test for case if (socketId >= 0) { CloseClientSocket(socketId); } -- Gitee From d24805d10c55eabcdccd65896cebc26e37d01cc3 Mon Sep 17 00:00:00 2001 From: yh Date: Wed, 13 Nov 2024 11:19:48 +0800 Subject: [PATCH 036/148] clear reserved pid Signed-off-by: yh Change-Id: I9f5d3812681e041e07152bbdab60a516330e9bc0 --- standard/appspawn_service.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 122e4173..e0f602ba 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -109,6 +109,14 @@ static void StopAppSpawn(void) OH_ListInit(&appInfo->node); free(appInfo); } + + AppSpawnContent *content = GetAppSpawnContent(); + if (content != NULL && content->reservedPid > 0) { + int ret = kill(content->reservedPid, SIGKILL); + APPSPAWN_CHECK_ONLY_LOG(ret == 0, "kill reserved pid %{public}d failed %{public}d %{public}d", + content->reservedPid, ret, errno); + content->reservedPid = 0; + } TraversalSpawnedProcess(AppQueueDestroyProc, NULL); APPSPAWN_LOGI("StopAppSpawn "); #ifdef APPSPAWN_HISYSEVENT -- Gitee From 8dbafb4717d7b3719c6beb08db4ccf2cfed17037 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Tue, 12 Nov 2024 10:12:19 +0800 Subject: [PATCH 037/148] =?UTF-8?q?=E6=94=AF=E6=8C=81gpu=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E5=8D=95=E7=8B=AC=E9=85=8D=E7=BD=AE=E6=8C=82=E8=BD=BD=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nianyuu --- appdata-sandbox.json | 142 +++++++++++++++++++++++++++--- appdata-sandbox64.json | 79 ++++++++++++----- modules/sandbox/sandbox_utils.cpp | 16 +++- 3 files changed, 198 insertions(+), 39 deletions(-) diff --git a/appdata-sandbox.json b/appdata-sandbox.json index 6326fba6..d27feae6 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -54,11 +54,6 @@ "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/system/lib/ld-musl-arm.so.1", - "sandbox-path" : "/system/lib/ld-musl-arm.so.1", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - },{ "src-path" : "/system/lib/ndk", "sandbox-path" : "/system/lib/ndk", "sandbox-flags" : [ "bind", "rec" ], @@ -579,8 +574,133 @@ "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/system/lib/ld-musl-arm.so.1", - "sandbox-path" : "/system/lib/ld-musl-arm.so.1", + "src-path" : "/system/app/", + "sandbox-path" : "/system/app/", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/vendor/lib", + "sandbox-path" : "/vendor/lib", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/data/app/el1/bundle/public/", + "sandbox-path" : "/data/app/el1/bundle/public/", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/app/NWeb", + "sandbox-path" : "/system/app/NWeb", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/module_update/ArkWebCore/app/", + "sandbox-path" : "/module_update/ArkWebCore/app/", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + } + ], + "symbol-links" : [{ + "target-name" : "/system/etc", + "link-name" : "/etc", + "check-action-status": "false" + }, { + "target-name" : "/system/bin", + "link-name" : "/bin", + "check-action-status": "false" + }, { + "target-name" : "/system/lib", + "link-name" : "/lib", + "check-action-status": "false" + } + ] + }], + "__internal__.com.ohos.gpu" : [{ + "sandbox-root" : "/mnt/sandbox/com.ohos.render/", + "sandbox-ns-flags" : [ "pid", "net" ], + "mount-paths" : [{ + "src-path" : "/dev", + "sandbox-path" : "/dev", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/proc", + "sandbox-path" : "/proc", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/sys", + "sandbox-path" : "/sys", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/fonts", + "sandbox-path" : "/system/fonts", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/etc", + "sandbox-path" : "/system/etc", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/etc/hosts", + "sandbox-path" : "/data/service/el1/network/hosts_user/hosts", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/data/app/el1/bundle/public/", + "sandbox-path" : "/data/storage/el1/bundle/arkwebcore", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/bin", + "sandbox-path" : "/system/bin", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib", + "sandbox-path" : "/system/lib", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib/platformsdk", + "sandbox-path" : "/system/lib/platformsdk", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib/ndk", + "sandbox-path" : "/system/lib/ndk", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib/module", + "sandbox-path" : "/system/lib/module", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib/chipset-pub-sdk", + "sandbox-path" : "/system/lib/chipset-pub-sdk", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib/chipset-sdk", + "sandbox-path" : "/system/lib/chipset-sdk", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib/seccomp", + "sandbox-path" : "/system/lib/seccomp", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib/extensionability", + "sandbox-path" : "/system/lib/extensionability", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib/media", + "sandbox-path" : "/system/lib/media", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { @@ -623,13 +743,7 @@ "link-name" : "/lib", "check-action-status": "false" } - ], - "flags-point" : [{ - "flags": "DLP_MANAGER", - "sandbox-root" : "/mnt/sandbox/com.ohos.render/", - "mount-paths" : [], - "symbol-links" : [{}] - }] + ] }] }], "permission":[{ diff --git a/appdata-sandbox64.json b/appdata-sandbox64.json index 2a254101..bc54ec69 100644 --- a/appdata-sandbox64.json +++ b/appdata-sandbox64.json @@ -5,11 +5,6 @@ "sandbox-root" : "/mnt/sandbox/", "sandbox-ns-flags" : [ "net" ], "mount-paths" : [{ - "src-path" : "/system/lib", - "sandbox-path" : "/system/lib", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { "src-path" : "/system/lib64/platformsdk", "sandbox-path" : "/system/lib64/platformsdk", "sandbox-flags" : [ "bind", "rec" ], @@ -49,11 +44,6 @@ "sandbox-path" : "/system/lib64/media", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" - }, { - "src-path" : "/system/lib/ld-musl-aarch64.so.1", - "sandbox-path" : "/system/lib/ld-musl-aarch64.so.1", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" }, { "src-path" : "/system/asan/lib64", "sandbox-path" : "/system/asan/lib64", @@ -95,11 +85,6 @@ "sandbox-root" : "/mnt/sandbox/com.ohos.render/", "sandbox-ns-flags" : [ "pid", "net" ], "mount-paths" : [{ - "src-path" : "/system/lib", - "sandbox-path" : "/system/lib", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - },{ "src-path" : "/system/lib64/platformsdk", "sandbox-path" : "/system/lib64/platformsdk", "sandbox-flags" : [ "bind", "rec" ], @@ -140,8 +125,60 @@ "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/system/lib/ld-musl-aarch64.so.1", - "sandbox-path" : "/system/lib/ld-musl-aarch64.so.1", + "src-path" : "/vendor/lib64", + "sandbox-path" : "/vendor/lib64", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + } + ], + "symbol-links" : [{ + "target-name" : "/system/lib64", + "link-name" : "/lib64", + "check-action-status": "false" + } + ] + }], + "__internal__.com.ohos.gpu" : [{ + "sandbox-root" : "/mnt/sandbox/com.ohos.render/", + "sandbox-ns-flags" : [ "pid", "net" ], + "mount-paths" : [{ + "src-path" : "/system/lib64/platformsdk", + "sandbox-path" : "/system/lib64/platformsdk", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib64/ndk", + "sandbox-path" : "/system/lib64/ndk", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib64/module", + "sandbox-path" : "/system/lib64/module", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib64/chipset-pub-sdk", + "sandbox-path" : "/system/lib64/chipset-pub-sdk", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib64/chipset-sdk", + "sandbox-path" : "/system/lib64/chipset-sdk", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib64/seccomp", + "sandbox-path" : "/system/lib64/seccomp", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib64/extensionability", + "sandbox-path" : "/system/lib64/extensionability", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/system/lib64/media", + "sandbox-path" : "/system/lib64/media", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { @@ -156,13 +193,7 @@ "link-name" : "/lib64", "check-action-status": "false" } - ], - "flags-point" : [{ - "flags": "DLP_MANAGER", - "sandbox-root" : "/mnt/sandbox/com.ohos.render/", - "mount-paths" : [], - "symbol-links" : [{}] - }] + ] }] }] } diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index a13483ab..4f0bb4c2 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -127,6 +127,7 @@ namespace { const char* g_fileSeparator = "/"; const char* g_overlayDecollator = "|"; const std::string g_sandBoxRootDir = "/mnt/sandbox/"; + const std::string g_ohosGpu = "__internal__.com.ohos.gpu"; const std::string g_ohosRender = "__internal__.com.ohos.render"; const std::string g_sandBoxRootDirNweb = "/mnt/sandbox/com.ohos.render/"; const std::string FILE_CROSS_APP_MODE = "ohos.permission.FILE_CROSS_APP"; @@ -1100,7 +1101,10 @@ int32_t SandboxUtils::SetRenderSandboxPropertyNweb(const AppSpawningCtx *appProp for (auto& config : SandboxUtils::GetJsonConfig(type)) { nlohmann::json& privateAppConfig = config[g_privatePrefix][0]; - if (privateAppConfig.find(g_ohosRender) != privateAppConfig.end()) { + char *processType = (char *)(GetAppSpawnMsgExtInfo(appProperty->message, MSG_EXT_NAME_PROCESS_TYPE, NULL)); + APPSPAWN_CHECK(processType != NULL, return -1, "Invalid processType data"); + + if (strcmp(processType, "render") == 0 && privateAppConfig.find(g_ohosRender) != privateAppConfig.end()) { int ret = DoAllMntPointsMount(appProperty, privateAppConfig[g_ohosRender][0], nullptr, g_ohosRender); APPSPAWN_CHECK(ret == 0, return ret, "DoAllMntPointsMount failed, %{public}s", GetBundleName(appProperty)); @@ -1110,6 +1114,16 @@ int32_t SandboxUtils::SetRenderSandboxPropertyNweb(const AppSpawningCtx *appProp ret = HandleFlagsPoint(appProperty, privateAppConfig[g_ohosRender][0]); APPSPAWN_CHECK_ONLY_LOG(ret == 0, "HandleFlagsPoint for render-sandbox failed, %{public}s", GetBundleName(appProperty)); + } else if (strcmp(processType, "gpu") == 0 && privateAppConfig.find(g_ohosGpu) != privateAppConfig.end()) { + int ret = DoAllMntPointsMount(appProperty, privateAppConfig[g_ohosGpu][0], nullptr, g_ohosGpu); + APPSPAWN_CHECK(ret == 0, return ret, "DoAllMntPointsMount failed, %{public}s", + GetBundleName(appProperty)); + ret = DoAllSymlinkPointslink(appProperty, privateAppConfig[g_ohosGpu][0]); + APPSPAWN_CHECK(ret == 0, return ret, "DoAllSymlinkPointslink failed, %{public}s", + GetBundleName(appProperty)); + ret = HandleFlagsPoint(appProperty, privateAppConfig[g_ohosGpu][0]); + APPSPAWN_CHECK_ONLY_LOG(ret == 0, "HandleFlagsPoint for render-sandbox failed, %{public}s", + GetBundleName(appProperty)); } } return 0; -- Gitee From 274764585284fa87add81cf44f522b722be78614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Wed, 13 Nov 2024 15:33:17 +0800 Subject: [PATCH 038/148] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E8=87=B4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- modules/sandbox/appspawn_sandbox.h | 4 ++-- standard/appspawn_service.h | 6 +++--- test/mock/app_spawn_stub.h | 1 + test/mock/app_system_stub.c | 3 +++ 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/sandbox/appspawn_sandbox.h b/modules/sandbox/appspawn_sandbox.h index af78fd37..9605b521 100644 --- a/modules/sandbox/appspawn_sandbox.h +++ b/modules/sandbox/appspawn_sandbox.h @@ -293,8 +293,8 @@ typedef struct TagVarExtraData { void ClearVariable(void); void AddDefaultVariable(void); -const char *GetSandboxRealVar(const SandboxContext *context, - uint32_t bufferType, const char *source, const char *prefix, const VarExtraData *extraData); +const char *GetSandboxRealVar(const SandboxContext *context, uint32_t bufferType, const char *source, + const char *prefix, const VarExtraData *extraData); /** * @brief expand config diff --git a/standard/appspawn_service.h b/standard/appspawn_service.h index cfbf7b54..76f4a8e6 100644 --- a/standard/appspawn_service.h +++ b/standard/appspawn_service.h @@ -32,10 +32,10 @@ extern "C" { #endif -#ifdef ASAN_DETECTR -#define MAX_WAIT_MSG_COMPLETE (5 * 1000) // 5s +#ifdef ASAN_DETECTOR +#define MAX_WAIT_MSG_COMPLETE (5 * 1000) // 5s #define COLD_CHILD_RESPONSE_TIMEOUT 60 -#define WAIT_CHILD_RESPONSE_TIMEOUT 60 //60s +#define WAIT_CHILD_RESPONSE_TIMEOUT 60 //60s #elif APPSPAWN_TEST #define MAX_WAIT_MSG_COMPLETE (5 * 100) // 500ms #define COLD_CHILD_RESPONSE_TIMEOUT 5 diff --git a/test/mock/app_spawn_stub.h b/test/mock/app_spawn_stub.h index e8e4065b..b3a4d6a7 100644 --- a/test/mock/app_spawn_stub.h +++ b/test/mock/app_spawn_stub.h @@ -132,4 +132,5 @@ StubNode *GetStubNode(int type); } #endif int SetSelinuxConNweb(const AppSpawnMgr *content, const AppSpawningCtx *property); +void InitAppCommonEnv(const AppSpawningCtx *property); #endif // APPSPAWN_TEST_STUB_H diff --git a/test/mock/app_system_stub.c b/test/mock/app_system_stub.c index 1db87620..d9eb03ae 100644 --- a/test/mock/app_system_stub.c +++ b/test/mock/app_system_stub.c @@ -108,6 +108,9 @@ void *DlsymStub(void *handle, const char *symbol) if (strcmp(symbol, "NWebRenderMain") == 0) { return ((g_dlsymResultFlags & DLSYM_FAIL_NWEB_MAIN) == 0) ? (void *)(NWebRenderMainStub) : NULL; } + if (strcmp(symbol, "GetPermissionIndex") == 0) { + return (void *) (GetPermissionIndex); + } return NULL; } -- Gitee From 87fdd30a2b686ac29eac858501a2615a07fc1c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Thu, 14 Nov 2024 13:59:45 +0800 Subject: [PATCH 039/148] =?UTF-8?q?devicedebug=20help=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=9A=E4=BB=BF=E7=85=A7aa=EF=BC=8C=E5=9C=A8=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E9=94=99=E8=AF=AF=E6=8C=87=E4=BB=A4=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=E7=BB=99=E4=BA=88=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- service/devicedebug/devicedebug_main.c | 6 ++++-- service/devicedebug/kill/src/devicedebug_kill.c | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/service/devicedebug/devicedebug_main.c b/service/devicedebug/devicedebug_main.c index 5aa22a9c..72e64497 100644 --- a/service/devicedebug/devicedebug_main.c +++ b/service/devicedebug/devicedebug_main.c @@ -38,7 +38,7 @@ APPSPAWN_STATIC int DeviceDebugShowHelp(int argc, char *argv[]) printf("\r\nusage: devicedebug \r\n" "\r\nThese are common devicedebug commands list:\r\n" "\r\n help list available commands" - "\r\n kill send a signal to a process\r\n"); + "\r\n kill send a signal(1-64) to a process\r\n"); return 0; } @@ -76,7 +76,9 @@ int main(int argc, char *argv[]) /* 检验用户命令,获取对应的处理函数 */ cmdInfo = DeviceDebugCmdCheck(argv[DEVICEDEBUG_NUM_1]); if (cmdInfo == NULL) { - DEVICEDEBUG_LOGE("invalid cmd!. cmd:%{public}s\r\n", argv[DEVICEDEBUG_NUM_1]); + printf("devicedebug: '%s' is not a valid devicedebug command. See 'devicedebug help'.", + argv[DEVICEDEBUG_NUM_1]); + DeviceDebugShowHelp(argc, argv); return DEVICEDEBUG_ERRNO_OPERATOR_TYPE_INVALID; } diff --git a/service/devicedebug/kill/src/devicedebug_kill.c b/service/devicedebug/kill/src/devicedebug_kill.c index f36c177f..08be2ee9 100644 --- a/service/devicedebug/kill/src/devicedebug_kill.c +++ b/service/devicedebug/kill/src/devicedebug_kill.c @@ -36,7 +36,7 @@ APPSPAWN_STATIC void DeviceDebugShowKillHelp(void) printf("\r\nusage: devicedebug kill [options] " "\r\noptions list:" "\r\n -h, --help list available commands" - "\r\n kill - send a signal to a process\r\n"); + "\r\n kill - send a signal(1-64) to a process\r\n"); } APPSPAWN_STATIC char* DeviceDebugJsonStringGeneral(int pid, const char *op, cJSON *args) @@ -133,7 +133,7 @@ int DeviceDebugCmdKill(int argc, char *argv[]) int signal = atoi(argv[DEVICEDEBUG_KILL_CMD_SIGNAL_INDEX] + 1); if (signal > SIGRTMAX || signal <= 0) { - DEVICEDEBUG_LOGE("signal is %{public}d > %{public}d", signal, SIGRTMAX); + DEVICEDEBUG_LOGE("signal is %{public}d not in [1, %{public}d]", signal, SIGRTMAX); DeviceDebugShowKillHelp(); return DEVICEDEBUG_ERRNO_PARAM_INVALID; } -- Gitee From 77756973b77fb42e96c7025c7bf359fc039fc4c8 Mon Sep 17 00:00:00 2001 From: y00905949 Date: Thu, 14 Nov 2024 18:28:14 +0800 Subject: [PATCH 040/148] =?UTF-8?q?=E8=A1=A5=E5=85=85gpu=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?shader=E6=8C=82=E8=BD=BD=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: y00905949 --- appdata-sandbox.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/appdata-sandbox.json b/appdata-sandbox.json index d27feae6..c3bb6bec 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -728,6 +728,26 @@ "sandbox-path" : "/module_update/ArkWebCore/app/", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" + }, { + "src-path" : "/vendor/etc/vulkan/icd.d", + "sandbox-path" : "/vendor/etc/vulkan/icd.d", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/data/local/shader_cache/local/", + "sandbox-path" : "/data/storage/shader_cache/local", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/data/local/shader_cache/cloud/", + "sandbox-path" : "/data/storage/shader_cache/cloud", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" + }, { + "src-path" : "/data/local/shader_cache/cloud/common", + "sandbox-path" : "/data/storage/shader_cache/common", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" } ], "symbol-links" : [{ -- Gitee From 2f8c452c54940b9958a23921bf08c413d57a40e3 Mon Sep 17 00:00:00 2001 From: yh Date: Fri, 15 Nov 2024 10:21:24 +0800 Subject: [PATCH 041/148] debug hap Signed-off-by: yh Change-Id: I748d1b65cb867616962c58e12915a6d006b42eef --- interfaces/innerkits/include/appspawn.h | 1 + modules/module_engine/include/appspawn_hook.h | 2 +- standard/appspawn_service.c | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index 1891c12c..aba32c0f 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -107,6 +107,7 @@ typedef enum { MSG_UPDATE_MOUNT_POINTS, MSG_RESTART_SPAWNER, MSG_DEVICE_DEBUG, + MSG_UNINSTALL_DEBUG_HAP, MAX_TYPE_INVALID } AppSpawnMsgType; diff --git a/modules/module_engine/include/appspawn_hook.h b/modules/module_engine/include/appspawn_hook.h index f8df0b10..856f5e80 100644 --- a/modules/module_engine/include/appspawn_hook.h +++ b/modules/module_engine/include/appspawn_hook.h @@ -65,7 +65,7 @@ typedef enum TagAppSpawnHookStage { STAGE_PARENT_POST_FORK = 21, STAGE_PARENT_PRE_RELY = 22, STAGE_PARENT_POST_RELY = 23, - + STAGE_PARENT_UNINSTALL, // run in child process STAGE_CHILD_PRE_COLDBOOT = 30, // clear env, set token before cold boot STAGE_CHILD_EXECUTE, diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index e0f602ba..7fb16bb2 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -1519,6 +1519,19 @@ static void ProcessSpawnRestartMsg(AppSpawnConnection *connection, AppSpawnMsgNo APPSPAWN_LOGE("Failed to execv, ret %{public}d, errno %{public}d", ret, errno); } +APPSPAWN_STATIC int ProcessUninstallDebugHap(AppSpawnConnection *connection, AppSpawnMsgNode *message) +{ + APPSPAWN_LOGI("ProcessUninstallDebugHap start"); + APPSPAWN_CHECK(connection != NULL && message != NULL, return APPSPAWN_ARG_INVALID, + "ProcessUninstallDebugHap invalid param"); + + AppSpawningCtx *property = CreateAppSpawningCtx(); + APPSPAWN_CHECK(property != NULL, return APPSPAWN_SYSTEM_ERROR, "create appspawn ctx failed"); + property->message = message; + property->message->connection = connection; + return AppSpawnHookExecute(STAGE_PARENT_UNINSTALL, 0, GetAppSpawnContent(), &property->client); +} + APPSPAWN_STATIC int AppspawpnDevicedebugKill(int pid, cJSON *args) { cJSON *signal = cJSON_GetObjectItem(args, "signal"); @@ -1652,6 +1665,11 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess SendResponse(connection, msg, ret, 0); DeleteAppSpawnMsg(message); break; + case MSG_UNINSTALL_DEBUG_HAP: + ret = ProcessUninstallDebugHap(connection, message); + SendResponse(connection, msg, ret, 0); + DeleteAppSpawnMsg(message); + break; default: SendResponse(connection, msg, APPSPAWN_MSG_INVALID, 0); DeleteAppSpawnMsg(message); -- Gitee From fceed2dc74042549f3488651a1b845d315ebbfc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Sat, 16 Nov 2024 15:03:10 +0800 Subject: [PATCH 042/148] =?UTF-8?q?devicedebug=E5=9F=BA=E4=BA=8E=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=A0=81=E6=89=93=E5=8D=B0=E9=94=99=E8=AF=AF=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- .../devicedebug/kill/src/devicedebug_kill.c | 17 ++++++++++++++++- standard/appspawn_service.c | 4 ++-- .../app_spawn_service_test.cpp | 19 ++++++++++++++----- util/include/appspawn_utils.h | 3 +++ 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/service/devicedebug/kill/src/devicedebug_kill.c b/service/devicedebug/kill/src/devicedebug_kill.c index 08be2ee9..a42bde69 100644 --- a/service/devicedebug/kill/src/devicedebug_kill.c +++ b/service/devicedebug/kill/src/devicedebug_kill.c @@ -57,6 +57,21 @@ APPSPAWN_STATIC char* DeviceDebugJsonStringGeneral(int pid, const char *op, cJSO return jsonString; } +APPSPAWN_STATIC void DevicedebugKillRetDeal(int result, int pid) +{ + switch (result) { + case APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_EXIST: + printf("devicedebug: kill: %d: No such app process\r\n", pid); + break; + case APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_DEBUGGABLE: + printf("devicedebug: kill: process: %d is not debuggable app\r\n", pid); + break; + default: + printf("devicedebug: process: %d kill unsuccess, please check the hilog for the cause\r\n", pid); + break; + } +} + APPSPAWN_STATIC int DeviceDebugKill(int pid, int signal) { cJSON *args = cJSON_CreateObject(); @@ -106,7 +121,7 @@ APPSPAWN_STATIC int DeviceDebugKill(int pid, int signal) } if (result.result != 0) { - DEVICEDEBUG_LOGE("devicedebug appspawn kill process unsuccess, result=%{public}d", result.result); + DevicedebugKillRetDeal(result.result, pid); return result.result; } diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index e0f602ba..1fa205d6 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -1530,12 +1530,12 @@ APPSPAWN_STATIC int AppspawpnDevicedebugKill(int pid, cJSON *args) AppSpawnedProcess *appInfo = GetSpawnedProcess(pid); if (appInfo == NULL) { APPSPAWN_LOGE("appspawn devicedebug get app info unsuccess, pid=%{public}d", pid); - return -1; + return APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_EXIST; } if (!appInfo->isDebuggable) { APPSPAWN_LOGE("appspawn devicedebug process is not debuggable, pid=%{public}d", pid); - return -1; + return APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_DEBUGGABLE; } APPSPAWN_LOGI("appspawn devicedebug debugable=%{public}d, pid=%{public}d, signal=%{public}d", diff --git a/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp index 3b8d7f22..ccadb11c 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp @@ -552,7 +552,6 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_008, TestSize.Level0) HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_009, TestSize.Level0) { int ret = 0; - char pid[16]; AppSpawnClientHandle clientHandle = nullptr; AppSpawnResult result = {}; do { @@ -572,18 +571,28 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_009, TestSize.Level0) AppSpawnReqMsgHandle reqHandle2; ret = AppSpawnReqMsgCreate(MSG_DEVICE_DEBUG, "devicedebug", &reqHandle2); - ASSERT_GT(sprintf_s(pid, 16, "%d", app->pid), 0); - AppSpawnReqMsgAddStringInfo(reqHandle2, "signal", "-9"); - AppSpawnReqMsgAddStringInfo(reqHandle2, "pid", pid); + cJSON *args = cJSON_CreateObject(); + ASSERT_NE(args, nullptr); + cJSON_AddNumberToObject(args, "signal", 9); + cJSON *root = cJSON_CreateObject(); + ASSERT_NE(root, nullptr); + cJSON_AddNumberToObject(root, "app", app->pid); + cJSON_AddStringToObject(root, "op", "kill"); + cJSON_AddItemToObject(root, "args", args); + char *jsonString = cJSON_Print(root); + cJSON_Delete(root); + ret = AppSpawnReqMsgAddExtInfo(reqHandle2, "devicedebug", (uint8_t *)jsonString, strlen(jsonString) + 1); + ASSERT_EQ(ret, 0); ret = AppSpawnClientSendMsg(clientHandle, reqHandle2, &result); AppSpawnClientDestroy(clientHandle); + free(jsonString); APPSPAWN_CHECK(ret == 0 && result.result == 0, break, "Failed to send msg ret:%{public}d, result:%{public}d", ret, result.result); ASSERT_EQ(kill(app->pid, SIGKILL), 0); } while (0); ASSERT_EQ(ret, 0); - ASSERT_EQ(result.result, -1); + ASSERT_EQ(result.result, APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_DEBUGGABLE); } HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_010, TestSize.Level0) diff --git a/util/include/appspawn_utils.h b/util/include/appspawn_utils.h index b8913790..5e9d7263 100755 --- a/util/include/appspawn_utils.h +++ b/util/include/appspawn_utils.h @@ -131,6 +131,9 @@ typedef enum { APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL, APPSPAWN_SANDBOX_ERROR_SET_PERMISSION_FLAG_FAIL, APPSPAWN_NODE_EXIST, + /* devicedebug errno */ + APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_EXIST, + APPSPAWN_DEVICEDEBUG_ERROR_APP_NOT_DEBUGGABLE, } AppSpawnErrorCode; uint64_t DiffTime(const struct timespec *startTime, const struct timespec *endTime); -- Gitee From 227e508dae2c2d9c327f16934c9ffd5d1d102026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Sat, 16 Nov 2024 17:33:17 +0800 Subject: [PATCH 043/148] =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=AF=BC=E8=87=B4=E5=A4=B1=E8=B4=A5=E6=9C=AA?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- service/devicedebug/kill/src/devicedebug_kill.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/service/devicedebug/kill/src/devicedebug_kill.c b/service/devicedebug/kill/src/devicedebug_kill.c index a42bde69..bd6fcc54 100644 --- a/service/devicedebug/kill/src/devicedebug_kill.c +++ b/service/devicedebug/kill/src/devicedebug_kill.c @@ -67,7 +67,8 @@ APPSPAWN_STATIC void DevicedebugKillRetDeal(int result, int pid) printf("devicedebug: kill: process: %d is not debuggable app\r\n", pid); break; default: - printf("devicedebug: process: %d kill unsuccess, please check the hilog for the cause\r\n", pid); + printf("devicedebug: process: %d kill unsuccess ret=%d, please check the hilog for the cause\r\n", + pid, result); break; } } @@ -121,7 +122,6 @@ APPSPAWN_STATIC int DeviceDebugKill(int pid, int signal) } if (result.result != 0) { - DevicedebugKillRetDeal(result.result, pid); return result.result; } @@ -156,7 +156,12 @@ int DeviceDebugCmdKill(int argc, char *argv[]) int pid = atoi(argv[DEVICEDEBUG_KILL_CMD_PID_INDEX]); DEVICEDEBUG_LOGI("devicedebug cmd kill start signal[%{public}d], pid[%{public}d]", signal, pid); - return DeviceDebugKill(pid, signal); + int ret = DeviceDebugKill(pid, signal); + if (ret != 0) { + DevicedebugKillRetDeal(ret, pid); + } + + return ret; } #ifdef __cplusplus -- Gitee From 16edede17b3177653044be5e64a26cc828ce4eb3 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Mon, 18 Nov 2024 21:23:01 +0800 Subject: [PATCH 044/148] add appdate mount in new sandbox Signed-off-by: wangfeng --- appdata-sandbox-app.json | 34 ++--- interfaces/innerkits/include/appspawn.h | 1 + .../permission/appspawn_mount_permission.c | 2 +- modules/common/appspawn_adapter.cpp | 13 +- modules/common/appspawn_encaps.c | 2 + modules/sandbox/appspawn_sandbox.c | 129 +++++++++++++++++- modules/sandbox/appspawn_sandbox.h | 1 + modules/sandbox/sandbox_manager.c | 25 +++- modules/sandbox/sandbox_utils.cpp | 22 ++- modules/sandbox/sandbox_utils.h | 3 +- util/include/appspawn_utils.h | 2 +- 11 files changed, 192 insertions(+), 42 deletions(-) diff --git a/appdata-sandbox-app.json b/appdata-sandbox-app.json index fad86bdc..491ea6b0 100755 --- a/appdata-sandbox-app.json +++ b/appdata-sandbox-app.json @@ -175,14 +175,8 @@ "name": "ohos.permission.FILE_ACCESS_MANAGER", "sandbox-switch": "ON", "gids": ["file_manager", "user_data_rw"], - "mount-paths": [{ - "src-path": "/storage/media//local/files/Docs", - "sandbox-path": "/storage/Users/" - }, { - "src-path": "/storage/media//local/files/.Recent", - "sandbox-path": "/storage/Users//.Recent" - }], - "mount-groups": [ "user-public", "Users" ] + "mount-paths": [], + "mount-groups": [ "user-public", "file_manager_recent" ] }, { "name": "ohos.permission.READ_IMAGEVIDEO", "sandbox-switch": "ON", @@ -194,18 +188,11 @@ }, { "name": "ohos.permission.FILE_CROSS_APP", "gids": ["file_manager"], - "mount-paths": [{ - "src-path": "/storage/media//local/files/Docs", - "sandbox-path": "/storage/Users/" - }, { - "src-path": "/data/app/el1//base", - "sandbox-path": "/storage/Users//appdata/el1", - "category": "dac_override" - }, { - "src-path": "/data/app/el2//base", - "sandbox-path": "/storage/Users//appdata/el2", - "category": "dac_override" - }], + "mount-paths": [], + "mount-groups": [ "user-public" ] + }, { + "name": "ohos.permission.FILE_ACCESS_COMMON_DIR", + "mount-paths": [], "mount-groups": [ "user-public" ] }, { "name": "ohos.permission.ACTIVATE_THEME_PACKAGE", @@ -453,6 +440,13 @@ "src-path": "/storage/media//local/files/Docs", "sandbox-path": "/currentUser" }] + }, { + "name": "file_manager_recent", + "type": "app-variable", + "mount-paths": [{ + "src-path": "/storage/media//local/files/.Recent", + "sandbox-path": "/storage/Users//.Recent" + }] }, { "name": "el2", "type": "app-variable", diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index aba32c0f..2160eec7 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -185,6 +185,7 @@ typedef enum { APP_FLAGS_ISOLATED_DATAGROUP, APP_FLAGS_TEMP_JIT = 28, APP_FLAGS_PRE_INSTALLED_HAP = 29, + APP_FLAGS_GET_ALL_PROCESSES = 30, MAX_FLAGS_INDEX = 63, } AppFlagsIndex; diff --git a/interfaces/innerkits/permission/appspawn_mount_permission.c b/interfaces/innerkits/permission/appspawn_mount_permission.c index 1149829a..b2c75fe6 100755 --- a/interfaces/innerkits/permission/appspawn_mount_permission.c +++ b/interfaces/innerkits/permission/appspawn_mount_permission.c @@ -106,7 +106,7 @@ static int LoadPermissionConfig(PermissionManager *mgr) { int ret = ParseJsonConfig("etc/sandbox", mgr->type == CLIENT_FOR_APPSPAWN ? APP_SANDBOX_FILE_NAME : WEB_SANDBOX_FILE_NAME, ParseAppSandboxConfig, mgr); - APPSPAWN_CHECK(ret == 0, return ret, "Load sandbox fail %{public}d", ret); + APPSPAWN_CHECK(ret == 0, return 0, "Load sandbox fail %{public}d", ret); mgr->maxPermissionIndex = PermissionRenumber(&mgr->permissionQueue); return 0; } diff --git a/modules/common/appspawn_adapter.cpp b/modules/common/appspawn_adapter.cpp index 9ada875f..74ea6d78 100644 --- a/modules/common/appspawn_adapter.cpp +++ b/modules/common/appspawn_adapter.cpp @@ -175,22 +175,13 @@ int SetSeccompFilter(const AppSpawnMgr *content, const AppSpawningCtx *property) #ifdef SECCOMP_PRIVILEGE if (IsDeveloperModeOpen()) { - static GetPermissionFunc getPermissionFuncPtr = nullptr; - if (getPermissionFuncPtr == nullptr) { - getPermissionFuncPtr = reinterpret_cast(dlsym(nullptr, GET_PERMISSION_INDEX)); - if (getPermissionFuncPtr == nullptr) { - APPSPAWN_LOGE("Failed to dlsym get permission errno is %{public}d", errno); - return -EINVAL; - } - } - int32_t index = getPermissionFuncPtr(nullptr, GET_ALL_PROCESSES); - if (CheckAppPermissionFlagSet(property, static_cast(index)) != 0) { + if (CheckAppMsgFlagsSet(property, APP_FLAGS_GET_ALL_PROCESSES) != 0) { appName = APP_PRIVILEGE; } } #endif - if (CheckAppSpawnMsgFlag(property->message, TLV_MSG_FLAGS, APP_FLAGS_ISOLATED_SANDBOX) != 0) { + if (CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX) != 0) { appName = IMF_EXTENTOIN_NAME; } diff --git a/modules/common/appspawn_encaps.c b/modules/common/appspawn_encaps.c index 8e886f07..9bf3d456 100644 --- a/modules/common/appspawn_encaps.c +++ b/modules/common/appspawn_encaps.c @@ -278,12 +278,14 @@ APPSPAWN_STATIC int SpawnSetEncapsPermissions(AppSpawnMgr *content, AppSpawningC int ret = EnableEncapsForProc(encapsFileFd); if (ret != 0) { + close(encapsFileFd); return 0; // Can't enable encaps ability } char *encapsInfoStr = NULL; ret = SpawnBuildEncaps(content, property, &encapsInfoStr); if (ret != 0) { + close(encapsFileFd); APPSPAWN_LOGW("Build encaps object failed, ret: %{public}d", ret); return 0; // Can't set permission encpas ability } diff --git a/modules/sandbox/appspawn_sandbox.c b/modules/sandbox/appspawn_sandbox.c index c2a532ee..ea236388 100644 --- a/modules/sandbox/appspawn_sandbox.c +++ b/modules/sandbox/appspawn_sandbox.c @@ -392,7 +392,6 @@ APPSPAWN_STATIC const char *GetRealSrcPath(const SandboxContext *context, const // 设置挂载参数options static int32_t SetMountArgsOption(const SandboxContext *context, uint32_t category, uint32_t operation, MountArg *args) { - args->options = ""; if ((category != MOUNT_TMP_DAC_OVERRIDE) && (category != MOUNT_TMP_DAC_OVERRIDE_DELETE)) { return 0; } @@ -612,9 +611,130 @@ static const MountSharedTemplate MOUNT_SHARED_MAP[] = { {"/data/storage/el3", NULL}, {"/data/storage/el4", NULL}, {"/data/storage/el5", "ohos.permission.PROTECT_SCREEN_LOCK_DATA"}, - {"/storage/Users", "ohos.permission.FILE_ACCESS_MANAGER"}, }; +static int MountInShared(const AppSpawnMsgDacInfo *info, const char *rootPath, const char *src, const char *target) +{ + if (info == NULL) { + return APPSPAWN_ARG_INVALID; + } + + char path[MAX_SANDBOX_BUFFER] = {0}; + int ret = snprintf_s(path, MAX_SANDBOX_BUFFER, MAX_SANDBOX_BUFFER - 1, "%s/%u/app-root/%s", rootPath, + info->uid / UID_BASE, target); + if (ret <= 0) { + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + char currentUserPath[MAX_SANDBOX_BUFFER] = {0}; + ret = snprintf_s(currentUserPath, MAX_SANDBOX_BUFFER, MAX_SANDBOX_BUFFER - 1, "%s/currentUser", path); + if (ret <= 0) { + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + if (access(currentUserPath, F_OK) == 0) { + return 0; + } + + ret = MakeDirRec(path, DIR_MODE, 1); + if (ret != 0) { + return APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL; + } + + if (mount(src, path, NULL, MS_BIND | MS_REC, NULL) != 0) { + APPSPAWN_LOGI("bind mount %{public}s to %{public}s failed, error %{public}d", src, path, errno); + return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; + } + if (mount(NULL, path, NULL, MS_SHARED, NULL) != 0) { + APPSPAWN_LOGI("mount path %{public}s to shared failed, errno %{public}d", path, errno); + return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; + } + + return 0; +} + +static int SharedMountInSharefs(const AppSpawnMsgDacInfo *info, const char *rootPath, + const char *src, const char *target) +{ + char currentUserPath[MAX_SANDBOX_BUFFER] = {0}; + int ret = snprintf_s(currentUserPath, MAX_SANDBOX_BUFFER, MAX_SANDBOX_BUFFER - 1, "%s/currentUser", target); + if (ret <= 0) { + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + if (access(currentUserPath, F_OK) == 0) { + return 0; + } + + ret = MakeDirRec(target, DIR_MODE, 1); + if (ret != 0) { + return APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL; + } + + char options[OPTIONS_MAX_LEN] = {0}; + ret = snprintf_s(options, OPTIONS_MAX_LEN, OPTIONS_MAX_LEN - 1, "override_support_delete,user_id=%d", + info->uid / UID_BASE); + if (ret <= 0) { + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + if (mount(src, target, "sharefs", MS_NODEV, options) != 0) { + APPSPAWN_LOGE("sharefs mount %{public}s to %{public}s failed, error %{public}d", + src, target, errno); + return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; + } + if (mount(NULL, target, NULL, MS_SHARED, NULL) != 0) { + APPSPAWN_LOGE("mount path %{public}s to shared failed, errno %{public}d", target, errno); + return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; + } + + return 0; +} + +static void UpdateStorageDir(const SandboxContext *context, AppSpawnSandboxCfg *sandbox, const AppSpawnMsgDacInfo *info) +{ + const char mntUser[] = "/mnt/user"; + const char nosharefsDocs[] = "nosharefs/docs"; + const char sharefsDocs[] = "sharefs/docs"; + const char rootPath[] = "/mnt/sandbox"; + const char userPath[] = "/storage/Users"; + + /* /mnt/user//nosharefs/Docs */ + char nosharefsDocsDir[MAX_SANDBOX_BUFFER] = {0}; + int ret = snprintf_s(nosharefsDocsDir, MAX_SANDBOX_BUFFER, MAX_SANDBOX_BUFFER - 1, "%s/%d/%s", + mntUser, info->uid / UID_BASE, nosharefsDocs); + if (ret <= 0) { + return; + } + + /* /mnt/user//sharefs/Docs */ + char sharefsDocsDir[MAX_SANDBOX_BUFFER] = {0}; + ret = snprintf_s(sharefsDocsDir, MAX_SANDBOX_BUFFER, MAX_SANDBOX_BUFFER - 1, "%s/%d/%s", + mntUser, info->uid / UID_BASE, sharefsDocs); + if (ret <= 0) { + return; + } + + int index = GetPermissionIndexInQueue(&sandbox->permissionQueue, FILE_ACCESS_MANAGER_MODE); + int res = CheckSpawningPermissionFlagSet(context, index); + if (res == 0) { + char storageUserPath[MAX_SANDBOX_BUFFER] = {0}; + ret = snprintf_s(storageUserPath, MAX_SANDBOX_BUFFER, MAX_SANDBOX_BUFFER - 1, "%s/%d/app-root/%s", rootPath, + info->uid / UID_BASE, userPath); + if (ret <= 0) { + return; + } + /* mount /mnt/user//sharefs/docs to /mnt/sandbox//app-root/storage/Users */ + ret = SharedMountInSharefs(info, rootPath, sharefsDocsDir, storageUserPath); + } else { + /* mount /mnt/user//nosharefs/docs to /mnt/sandbox//app-root/storage/Users */ + ret = MountInShared(info, rootPath, nosharefsDocsDir, userPath); + } + if (ret != 0) { + APPSPAWN_LOGE("Update storage dir, ret %{public}d", ret); + } +} + static void MountDirToShared(const SandboxContext *context, AppSpawnSandboxCfg *sandbox) { const char rootPath[] = "/mnt/sandbox/"; @@ -625,6 +745,9 @@ static void MountDirToShared(const SandboxContext *context, AppSpawnSandboxCfg * if (info == NULL || context->bundleName == NULL) { return; } + + UpdateStorageDir(context, sandbox, info); + MountDir(info, appRootName, rootPath, nwebPath); MountDir(info, appRootName, rootPath, nwebTmpPath); @@ -1079,7 +1202,7 @@ static int MountDepGroups(const SandboxContext *context, SandboxNameGroupNode *g } ret = UpdateMountPathDepsPath(context, groupNode); - APPSPAWN_CHECK(ret == 0, return ret, "Failed to updata deps path name groups %{public}s", groupNode->section.name); + APPSPAWN_CHECK(ret == 0, return ret, "Failed to update deps path name groups %{public}s", groupNode->section.name); if (groupNode->depMode == MOUNT_MODE_NOT_EXIST && CheckAndCreateDepPath(context, groupNode)) { return 0; diff --git a/modules/sandbox/appspawn_sandbox.h b/modules/sandbox/appspawn_sandbox.h index 9605b521..7602178f 100644 --- a/modules/sandbox/appspawn_sandbox.h +++ b/modules/sandbox/appspawn_sandbox.h @@ -72,6 +72,7 @@ extern "C" { #define ACCESS_DLP_FILE_MODE "ohos.permission.ACCESS_DLP_FILE" #define FILE_ACCESS_MANAGER_MODE "ohos.permission.FILE_ACCESS_MANAGER" #define READ_WRITE_USER_FILE_MODE "ohos.permission.READ_WRITE_USER_FILE" +#define GET_ALL_PROCESSES_MODE "ohos.permission.GET_ALL_PROCESSES" typedef enum SandboxTag { SANDBOX_TAG_MOUNT_PATH = 0, diff --git a/modules/sandbox/sandbox_manager.c b/modules/sandbox/sandbox_manager.c index 4a11f1a8..bf2f2970 100644 --- a/modules/sandbox/sandbox_manager.c +++ b/modules/sandbox/sandbox_manager.c @@ -648,7 +648,23 @@ static int AppendPackageNameGids(const AppSpawnSandboxCfg *sandbox, AppSpawningC return 0; } -static int SetSandboxPermissionFlag(AppSpawnSandboxCfg *sandbox, AppSpawningCtx *property) +static void UpdateMsgFlagsWithPermission(AppSpawnSandboxCfg *sandbox, AppSpawningCtx *property) +{ + int32_t allProcessIndex = GetPermissionIndexInQueue(&sandbox->permissionQueue, GET_ALL_PROCESSES_MODE); + int res = CheckAppPermissionFlagSet(property, (uint32_t)allProcessIndex); + if (res == 0) { + APPSPAWN_LOGV("Don't need set GET_ALL_PROCESSES_MODE flag"); + return; + } + + int ret = SetAppSpawnMsgFlag(property->message, TLV_MSG_FLAGS, APP_FLAGS_GET_ALL_PROCESSES); + if (ret != 0) { + APPSPAWN_LOGE("Set GET_ALL_PROCESSES_MODE flag failed"); + } + return; +} + +static int UpdatePermissionFlags(AppSpawnSandboxCfg *sandbox, AppSpawningCtx *property) { int32_t index = 0; if (sandbox->appFullMountEnable) { @@ -694,13 +710,16 @@ int SpawnPrepareSandboxCfg(AppSpawnMgr *content, AppSpawningCtx *property) AppSpawnSandboxCfg *sandbox = GetAppSpawnSandbox(content, type); content->content.sandboxType = type; APPSPAWN_CHECK(sandbox != NULL, return -1, "Failed to get sandbox for %{public}s", GetProcessName(property)); - int ret = SetSandboxPermissionFlag(sandbox, property); + + int ret = UpdatePermissionFlags(sandbox, property); if (ret != 0) { APPSPAWN_LOGW("set sandbox permission flag failed."); return APPSPAWN_SANDBOX_ERROR_SET_PERMISSION_FLAG_FAIL; } - APPSPAWN_CHECK(ret == 0, return ret, "Failed to add gid for %{public}s", GetProcessName(property)); + UpdateMsgFlagsWithPermission(sandbox, property); + ret = AppendGids(sandbox, property); + APPSPAWN_CHECK(ret == 0, return ret, "Failed to add gid for %{public}s", GetProcessName(property)); ret = StagedMountSystemConst(sandbox, property, IsNWebSpawnMode(content)); APPSPAWN_CHECK(ret == 0, return ret, "Failed to mount system-const for %{public}s", GetProcessName(property)); return 0; diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 4f0bb4c2..07a5101b 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -135,6 +135,7 @@ namespace { const std::string ACCESS_DLP_FILE_MODE = "ohos.permission.ACCESS_DLP_FILE"; const std::string FILE_ACCESS_MANAGER_MODE = "ohos.permission.FILE_ACCESS_MANAGER"; const std::string READ_WRITE_USER_FILE_MODE = "ohos.permission.READ_WRITE_USER_FILE"; + const std::string GET_ALL_PROCESSES_MODE = "ohos.permission.GET_ALL_PROCESSES"; const std::string ARK_WEB_PERSIST_PACKAGE_NAME = "persist.arkwebcore.package_name"; const std::string& getArkWebPackageName() @@ -1599,7 +1600,23 @@ static inline int EnableSandboxNamespace(AppSpawningCtx *appProperty, uint32_t s return 0; } -int32_t SandboxUtils::SetPermissionWithParam(AppSpawningCtx *appProperty) +void SandboxUtils::UpdateMsgFlagsWithPermission(AppSpawningCtx *appProperty) +{ + int32_t processIndex = GetPermissionIndex(nullptr, GET_ALL_PROCESSES_MODE.c_str()); + if ((CheckAppPermissionFlagSet(appProperty, static_cast(processIndex)) == 0)) { + APPSPAWN_LOGV("Don't need set GET_ALL_PROCESSES_MODE flag"); + return; + } + + int ret = SetAppSpawnMsgFlag(appProperty->message, TLV_MSG_FLAGS, APP_FLAGS_GET_ALL_PROCESSES); + if (ret != 0) { + APPSPAWN_LOGV("Set GET_ALL_PROCESSES_MODE flag failed"); + } + + return; +} + +int32_t SandboxUtils::UpdatePermissionFlags(AppSpawningCtx *appProperty) { int32_t index = 0; int32_t appFullMountStatus = CheckAppFullMountEnable(); @@ -1658,10 +1675,11 @@ int32_t SandboxUtils::SetAppSandboxProperty(AppSpawningCtx *appProperty, uint32_ int rc = EnableSandboxNamespace(appProperty, sandboxNsFlags); APPSPAWN_CHECK(rc == 0, return rc, "unshare failed, packagename is %{public}s", bundleName.c_str()); - if (SetPermissionWithParam(appProperty) != 0) { + if (UpdatePermissionFlags(appProperty) != 0) { APPSPAWN_LOGW("Set app permission flag fail."); return -1; } + UpdateMsgFlagsWithPermission(appProperty); // check app sandbox switch if ((CheckTotalSandboxSwitchStatus(appProperty) == false) || diff --git a/modules/sandbox/sandbox_utils.h b/modules/sandbox/sandbox_utils.h index 2493bac5..442eba7a 100755 --- a/modules/sandbox/sandbox_utils.h +++ b/modules/sandbox/sandbox_utils.h @@ -107,7 +107,8 @@ private: static int32_t DoAddGid(AppSpawningCtx *appProperty, nlohmann::json &appConfig, const char* permissionName, const std::string §ion); static int32_t CheckAppFullMountEnable(); - static int32_t SetPermissionWithParam(AppSpawningCtx *appProperty); + static void UpdateMsgFlagsWithPermission(AppSpawningCtx *appProperty); + static int32_t UpdatePermissionFlags(AppSpawningCtx *appProperty); static int32_t SetSandboxProperty(AppSpawningCtx *appProperty, std::string &sandboxPackagePath); static int32_t ChangeCurrentDir(std::string &sandboxPackagePath, const std::string &bundleName, bool sandboxSharedStatus); diff --git a/util/include/appspawn_utils.h b/util/include/appspawn_utils.h index 5e9d7263..dbf2aedb 100755 --- a/util/include/appspawn_utils.h +++ b/util/include/appspawn_utils.h @@ -155,7 +155,7 @@ int EnableNewNetNamespace(void); #endif #ifndef OHOS_LITE -#define APPSPAWN_DOMAIN (0xD002C00 + 0x11) +#define APPSPAWN_DOMAIN (0xD002C00 + 0x11) // 0xD002C11 #ifndef APPSPAWN_LABEL #define APPSPAWN_LABEL "APPSPAWN" #endif -- Gitee From dba9a113cf051096ead9ca5ee77f98e1eb9b56d8 Mon Sep 17 00:00:00 2001 From: Zhou Shihui Date: Mon, 18 Nov 2024 10:29:53 +0800 Subject: [PATCH 045/148] =?UTF-8?q?=E6=8C=82=E8=BD=BDapp=5Finstall?= =?UTF-8?q?=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zhou Shihui --- appdata-sandbox-app.json | 8 ++++++++ appdata-sandbox.json | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/appdata-sandbox-app.json b/appdata-sandbox-app.json index fad86bdc..524856bc 100755 --- a/appdata-sandbox-app.json +++ b/appdata-sandbox-app.json @@ -351,6 +351,14 @@ "gids": ["file_manager"], "mount-paths":[], "mount-groups": ["Users", "user-public"] + }, { + "name": "ohos.permission.ACCESS_APP_INSTALL_DIR", + "sandbox-switch": "ON", + "gids": ["app_install"], + "mount-paths": [{ + "src-path": "/data/service/el1/public/bms/bundle_manager_service/app_install//", + "sandbox-path": "/data/bms_app_install/" + }] }], "spawn-flag": [{ "name": "START_FLAGS_BACKUP", diff --git a/appdata-sandbox.json b/appdata-sandbox.json index c3bb6bec..9e6b76b6 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -859,6 +859,16 @@ } ] }], + "ohos.permission.ACCESS_APP_INSTALL_DIR":[{ + "sandbox-switch": "ON", + "gids": [2002], + "mount-paths": [{ + "src-path": "/data/service/el1/public/bms/bundle_manager_service/app_install//", + "sandbox-path": "/data/bms_app_install/", + "sandbox-flags": [ "bind", "rec" ] + } + ] + }], "ohos.permission.ACCESS_BBOX_DIR":[{ "sandbox-switch": "ON", "mount-paths": [{ -- Gitee From 1c29b7f9ec7192b8d036423b6a4e4ab4f9726dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Thu, 21 Nov 2024 14:02:12 +0800 Subject: [PATCH 046/148] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9appspsawn=20fu?= =?UTF-8?q?zz=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp b/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp index e7a0d766..58dd09f1 100644 --- a/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp +++ b/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp @@ -282,6 +282,10 @@ namespace OHOS { int FuzzGetPermissionByIndex(const uint8_t *data, size_t size) { + if (data == nullptr) { + return -1; + } + int32_t index = *(reinterpret_cast(data)); if (GetPermissionByIndex(nullptr, index) == nullptr) { return -1; -- Gitee From 4853cf195cc22f9f6fc02d8c7d69938197318be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=85=B6=E6=96=87?= Date: Thu, 21 Nov 2024 20:22:13 +0800 Subject: [PATCH 047/148] =?UTF-8?q?Appspawn=20Fuzz=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈其文 --- .../appspawnclient_fuzzer.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp b/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp index 58dd09f1..1c874185 100644 --- a/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp +++ b/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp @@ -20,16 +20,16 @@ namespace OHOS { int FuzzAppSpawnClientInit(const uint8_t *data, size_t size) { - const char *name = APPSPAWN_SERVER_NAME; + std::string serviceName(reinterpret_cast(data), size); AppSpawnClientHandle handle = nullptr; - return AppSpawnClientInit(name, &handle); + return AppSpawnClientInit(serviceName.c_str(), &handle); } int FuzzAppSpawnClientDestroy(const uint8_t *data, size_t size) { - const char *name = APPSPAWN_SERVER_NAME; + std::string serviceName(reinterpret_cast(data), size); AppSpawnClientHandle handle = nullptr; - if (AppSpawnClientInit(name, &handle) != 0) { + if (AppSpawnClientInit(serviceName.c_str(), &handle) != 0) { return -1; } return AppSpawnClientDestroy(handle); @@ -277,7 +277,12 @@ namespace OHOS { int FuzzGetMaxPermissionIndex(const uint8_t *data, size_t size) { - return GetMaxPermissionIndex(nullptr); + std::string serviceName(reinterpret_cast(data), size); + AppSpawnClientHandle handle = nullptr; + if (AppSpawnClientInit(serviceName.c_str(), &handle) != 0) { + return -1; + } + return GetMaxPermissionIndex(handle); } int FuzzGetPermissionByIndex(const uint8_t *data, size_t size) -- Gitee From b9904bd2386d0fc79cade92704533728505b9b68 Mon Sep 17 00:00:00 2001 From: yh Date: Tue, 19 Nov 2024 16:49:10 +0800 Subject: [PATCH 048/148] add dlopen Signed-off-by: yh Change-Id: Ie2a01076f047c71519761bbf425f9daf207d647a --- appspawn_systemLib.json | 4 ++++ etc/BUILD.gn | 7 ++++++ modules/ace_adapter/ace_adapter.cpp | 34 +++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 appspawn_systemLib.json diff --git a/appspawn_systemLib.json b/appspawn_systemLib.json new file mode 100644 index 00000000..05e42a8f --- /dev/null +++ b/appspawn_systemLib.json @@ -0,0 +1,4 @@ +{ + "systemLib" : [ + ] +} diff --git a/etc/BUILD.gn b/etc/BUILD.gn index fdda0586..dddce63f 100644 --- a/etc/BUILD.gn +++ b/etc/BUILD.gn @@ -66,10 +66,17 @@ ohos_prebuilt_etc("appspawn_preload.json") { module_install_dir = "etc/appspawn" } +ohos_prebuilt_etc("appspawn_systemLib.json") { + source = "../appspawn_systemLib.json" + part_name = "${part_name}" + module_install_dir = "etc/appspawn" +} + group("etc_files") { deps = [ ":appdata-sandbox.json", ":appspawn_preload.json", + ":appspawn_systemLib.json", ] if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) { deps += [ ":appdata-sandbox-nweb.json" ] diff --git a/modules/ace_adapter/ace_adapter.cpp b/modules/ace_adapter/ace_adapter.cpp index b6aac779..c8ff872d 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -43,6 +43,7 @@ using namespace OHOS::AppSpawn; using namespace OHOS::Global; +#define SYSTEMLIB_JSON "/appspawn_systemLib.json" #ifdef ASAN_DETECTOR static const bool DEFAULT_PRELOAD_VALUE = false; #else @@ -266,8 +267,41 @@ APPSPAWN_STATIC int PreLoadAppSpawn(AppSpawnMgr *content) return 0; } +APPSPAWN_STATIC int DoDlopenLibs(const cJSON *root, ParseJsonContext *context) +{ + cJSON *systemLibs = cJSON_GetObjectItemCaseSensitive(root, "systemLib"); + if (systemLibs == nullptr) { + return 0; + } + + uint32_t libsCount = (uint32_t)cJSON_GetArraySize(systemLibs); + for (uint32_t i = 0; i < libsCount; ++i) { + const char *libName = cJSON_GetStringValue(cJSON_GetArrayItem(systemLibs, i)); + if (libName == nullptr) { + continue; + } + APPSPAWN_LOGV("libName %{public}s", libName); + void *lib = dlopen(libName, RTLD_LAZY); + if (lib == nullptr) { + APPSPAWN_LOGE("FAILED to dlopen %{public}s %{public}s", libName, dlerror()); + } + } + return 0; +} + +APPSPAWN_STATIC int DlopenAppSpawn(AppSpawnMgr *content) +{ + if (!IsAppSpawnMode(content)) { + return 0; + } + + (void)ParseJsonConfig("etc/appspawn", SYSTEMLIB_JSON, DoDlopenLibs, nullptr); + return 0; +} + MODULE_CONSTRUCTOR(void) { APPSPAWN_LOGV("Load ace module ..."); AddPreloadHook(HOOK_PRIO_HIGHEST, PreLoadAppSpawn); + AddPreloadHook(HOOK_PRIO_HIGHEST, DlopenAppSpawn); } -- Gitee From ce2294bee6806795aa33831358c7a67659ca8af0 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Tue, 19 Nov 2024 21:37:27 +0800 Subject: [PATCH 049/148] Add retry when reading from a socketfd Signed-off-by: nianyuu --- interfaces/innerkits/client/appspawn_client.c | 22 ++++++++++++++----- interfaces/innerkits/client/appspawn_client.h | 3 +++ standard/appspawn_service.c | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/interfaces/innerkits/client/appspawn_client.c b/interfaces/innerkits/client/appspawn_client.c index 00707f50..0d2c30b1 100644 --- a/interfaces/innerkits/client/appspawn_client.c +++ b/interfaces/innerkits/client/appspawn_client.c @@ -152,15 +152,28 @@ APPSPAWN_STATIC int UpdateSocketTimeout(uint32_t timeout, int socketFd) return ret; } -static int ReadMessage(int socketFd, uint32_t sendMsgId, uint8_t *buf, int len, AppSpawnResult *result) +static int ReadMessage(int socketFd, uint8_t *buf, int len, AppSpawnReqMsgNode *reqNode, AppSpawnResult *result) { + struct timespec readStart = { 0 }; + clock_gettime(CLOCK_MONOTONIC, &readStart); ssize_t rLen = TEMP_FAILURE_RETRY(read(socketFd, buf, len)); + if (rLen == -1 && errno == EAGAIN) { + struct timespec readEnd = { 0 }; + clock_gettime(CLOCK_MONOTONIC, &readEnd); + uint64_t diff = DiffTime(&readStart, &readEnd); + uint64_t timeout = reqNode->isAsan ? COLDRUN_READ_RETRY_TIME : NORMAL_READ_RETRY_TIME; + // If difftime is greater than timeout, it is considered that system hibernation or a time jump has occurred + if (diff > timeout) { + APPSPAWN_LOGW("Read message again from fd %{public}d, difftime %{public}" PRId64 " us", socketFd, diff); + rLen = TEMP_FAILURE_RETRY(read(socketFd, buf, len)); + } + } APPSPAWN_CHECK(rLen >= 0, return APPSPAWN_TIMEOUT, "Read message from fd %{public}d rLen %{public}zd errno: %{public}d", socketFd, rLen, errno); if ((size_t)rLen >= sizeof(AppSpawnResponseMsg)) { AppSpawnResponseMsg *msg = (AppSpawnResponseMsg *)(buf); - APPSPAWN_CHECK_ONLY_LOG(sendMsgId == msg->msgHdr.msgId, - "Invalid msg recvd %{public}u %{public}u", sendMsgId, msg->msgHdr.msgId); + APPSPAWN_CHECK_ONLY_LOG(reqNode->msg->msgId == msg->msgHdr.msgId, + "Invalid msg recvd %{public}u %{public}u", reqNode->msg->msgId, msg->msgHdr.msgId); return memcpy_s(result, sizeof(AppSpawnResult), &msg->result, sizeof(msg->result)); } return APPSPAWN_TIMEOUT; @@ -274,8 +287,7 @@ static int ClientSendMsg(AppSpawnReqMsgMgr *reqMgr, AppSpawnReqMsgNode *reqNode, } int ret = HandleMsgSend(reqMgr, reqMgr->socketId, reqNode); if (ret == 0) { - ret = ReadMessage(reqMgr->socketId, reqNode->msg->msgId, - reqMgr->recvBlock.buffer, reqMgr->recvBlock.blockSize, result); + ret = ReadMessage(reqMgr->socketId, reqMgr->recvBlock.buffer, reqMgr->recvBlock.blockSize, reqNode, result); } if (ret == 0) { if (isColdRun && reqMgr->timeout < ASAN_TIMEOUT) { diff --git a/interfaces/innerkits/client/appspawn_client.h b/interfaces/innerkits/client/appspawn_client.h index 784065bb..22f3b907 100644 --- a/interfaces/innerkits/client/appspawn_client.h +++ b/interfaces/innerkits/client/appspawn_client.h @@ -37,6 +37,9 @@ extern "C" { #define RETRY_TIME (200 * 1000) // 200 * 1000 wait 200ms CONNECT_RETRY_DELAY = 200 * 1000 #define MAX_RETRY_SEND_COUNT 2 // 2 max retry count CONNECT_RETRY_MAX_TIMES = 2; +#define NORMAL_READ_RETRY_TIME (3 * 1000 * 1000 + 500 * 1000) // 3.5s, Exceed WAIT_CHILD_RESPONSE_TIMEOUT by 0.5s +#define COLDRUN_READ_RETRY_TIME (5 * 1000 * 1000 + 500 * 1000) // 5.5s, Exceed COLD_CHILD_RESPONSE_TIMEOUT by 0.5s + // only used for ExternalFileManager.hap #define GID_FILE_ACCESS 1006 #define GID_USER_DATA_RW 1008 diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 1271ccfb..a8453876 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -549,7 +549,7 @@ static void ProcessChildProcessFd(const WatcherHandle taskHandle, int fd, uint32 { APPSPAWN_CHECK_ONLY_EXPER(context != NULL, return); pid_t pid = *(pid_t *)context; - APPSPAWN_LOGI("Kill process group with process group id %{public}d, pidFd %{public}d", pid, fd); + APPSPAWN_LOGI("Clear process group with pid %{public}d, pidFd %{public}d", pid, fd); AppSpawnedProcess *appInfo = GetSpawnedProcess(pid); if (appInfo == NULL) { APPSPAWN_LOGW("Cannot get app info by bundle name: %{public}d", pid); -- Gitee From 44065f0ae0ccbcefd301fded352dd4afff71e5c6 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Fri, 22 Nov 2024 17:38:25 +0800 Subject: [PATCH 050/148] fix umount bug Signed-off-by: nianyuu --- modules/sandbox/sandbox_utils.cpp | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 07a5101b..dc3ddd75 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -2120,6 +2120,39 @@ static int SpawnMountDirToShared(AppSpawnMgr *content, AppSpawningCtx *property) return 0; } +static void UmountDir(const char *rootPath, const char *targetPath, const AppSpawnedProcessInfo *appInfo) +{ + size_t allPathSize = strlen(rootPath) + USER_ID_SIZE + strlen(appInfo->name) + strlen(targetPath) + 2; + char *path = reinterpret_cast(malloc(sizeof(char) * (allPathSize))); + APPSPAWN_CHECK(path != NULL, return, "Failed to malloc path"); + + int ret = sprintf_s(path, allPathSize, "%s%u/%s%s", rootPath, appInfo->uid / UID_BASE, + appInfo->name, targetPath); + APPSPAWN_CHECK(ret > 0 && ((size_t)ret < allPathSize), free(path); + return, "Failed to get sandbox path errno %{public}d", errno); + + ret = umount2(path, MNT_DETACH); + if (ret == 0) { + APPSPAWN_LOGV("Umount2 sandbox path %{public}s success", path); + } else { + APPSPAWN_LOGW("Failed to umount2 sandbox path %{public}s errno %{public}d", path, errno); + } + free(path); +} + +static int UmountSandboxPath(const AppSpawnMgr *content, const AppSpawnedProcessInfo *appInfo) +{ + APPSPAWN_CHECK(content != NULL && appInfo != NULL, return -1, "Invalid content or appInfo"); + APPSPAWN_LOGV("UmountSandboxPath name %{public}s pid %{public}d", appInfo->name, appInfo->pid); + const char rootPath[] = "/mnt/sandbox/"; + const char el1Path[] = "/data/storage/el1/bundle"; + const char userPath[] = "/storage/Users"; + + UmountDir(rootPath, el1Path, appInfo); + UmountDir(rootPath, userPath, appInfo); + return 0; +} + #ifndef APPSPAWN_SANDBOX_NEW MODULE_CONSTRUCTOR(void) { @@ -2127,5 +2160,6 @@ MODULE_CONSTRUCTOR(void) (void)AddServerStageHook(STAGE_SERVER_PRELOAD, HOOK_PRIO_SANDBOX, LoadAppSandboxConfig); (void)AddAppSpawnHook(STAGE_PARENT_PRE_FORK, HOOK_PRIO_COMMON, SpawnMountDirToShared); (void)AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_SANDBOX, SetAppSandboxProperty); + (void)AddProcessMgrHook(STAGE_SERVER_APP_DIED, HOOK_PRIO_SANDBOX, UmountSandboxPath); } #endif -- Gitee From b16447d24f135048f9d0681ba97c12644d31e265 Mon Sep 17 00:00:00 2001 From: ohxianzhi Date: Mon, 25 Nov 2024 19:43:55 +0800 Subject: [PATCH 051/148] fix ndk Signed-off-by: ohxianzhi --- modules/nweb_adapter/nwebspawn_adapter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/nweb_adapter/nwebspawn_adapter.cpp b/modules/nweb_adapter/nwebspawn_adapter.cpp index d926d644..f07dd124 100644 --- a/modules/nweb_adapter/nwebspawn_adapter.cpp +++ b/modules/nweb_adapter/nwebspawn_adapter.cpp @@ -113,7 +113,7 @@ APPSPAWN_STATIC int RunChildProcessor(AppSpawnContent *content, AppSpawnClient * dlns_init(&dlns, "nweb_ns"); dlns_create(&dlns, libPath.c_str()); Dl_namespace ndkns; - dlns_get("ndkns", &ndkns); + dlns_get("ndk", &ndkns); dlns_inherit(&dlns, &ndkns, "allow_all_shared_libs"); // preload libweb_engine webEngineHandle = dlopen_ns(&dlns, engineLibName.c_str(), RTLD_NOW | RTLD_GLOBAL); -- Gitee From 1ed0539a999f7b231afba5684dc4ee7a1cad9c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=85=B6=E6=96=87?= Date: Mon, 25 Nov 2024 21:20:40 +0800 Subject: [PATCH 052/148] =?UTF-8?q?Appspawn=E4=BB=A3=E7=A0=81=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈其文 --- modules/sandbox/sandbox_utils.cpp | 8 ++++---- service/hnp/base/hnp_json.c | 11 +++++++++++ service/hnp/installer/src/hnp_installer.c | 12 +++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index dc3ddd75..ef0828c8 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -2001,7 +2001,7 @@ static int SharedMountInSharefs(const AppSpawningCtx *property, const char *root } char options[PATH_MAX_LEN] = {0}; - ret = snprintf_s(options, PATH_MAX_LEN, PATH_MAX_LEN - 1, "override_support_delete,user_id=%d", + ret = snprintf_s(options, PATH_MAX_LEN, PATH_MAX_LEN - 1, "override_support_delete,user_id=%u", info->uid / UID_BASE); if (ret <= 0) { return APPSPAWN_ERROR_UTILS_MEM_FAIL; @@ -2035,7 +2035,7 @@ static void UpdateStorageDir(const AppSpawningCtx *property) /* /mnt/user//nosharefs/Docs */ char nosharefsDocsDir[PATH_MAX_LEN] = {0}; - int ret = snprintf_s(nosharefsDocsDir, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%d/%s", + int ret = snprintf_s(nosharefsDocsDir, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%u/%s", mntUser, info->uid / UID_BASE, nosharefsDocs); if (ret <= 0) { return; @@ -2043,7 +2043,7 @@ static void UpdateStorageDir(const AppSpawningCtx *property) /* /mnt/user//sharefs/Docs */ char sharefsDocsDir[PATH_MAX_LEN] = {0}; - ret = snprintf_s(sharefsDocsDir, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%d/%s", + ret = snprintf_s(sharefsDocsDir, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%u/%s", mntUser, info->uid / UID_BASE, sharefsDocs); if (ret <= 0) { return; @@ -2054,7 +2054,7 @@ static void UpdateStorageDir(const AppSpawningCtx *property) if (res == 0) { char storageUserPath[PATH_MAX_LEN] = {0}; const char *bundleName = GetBundleName(property); - ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%d/%s/%s", rootPath, info->uid / UID_BASE, + ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%u/%s/%s", rootPath, info->uid / UID_BASE, bundleName, userPath); if (ret <= 0) { return; diff --git a/service/hnp/base/hnp_json.c b/service/hnp/base/hnp_json.c index 26bba384..6ce5bef2 100644 --- a/service/hnp/base/hnp_json.c +++ b/service/hnp/base/hnp_json.c @@ -257,6 +257,11 @@ static int HnpHapJsonWrite(cJSON *json) return HNP_ERRNO_BASE_FILE_OPEN_FAILED; } char *jsonStr = cJSON_Print(json); + if (jsonStr == NULL) { + HNP_LOGE("get json str unsuccess!"); + (void)fclose(fp); + return HNP_ERRNO_BASE_PARAMS_INVALID; + } size_t jsonStrSize = strlen(jsonStr); size_t writeLen = fwrite(jsonStr, sizeof(char), jsonStrSize, fp); (void)fclose(fp); @@ -478,6 +483,12 @@ int HnpPackageInfoGet(const char *packageName, HnpPackageInfo **packageInfoOut, hnpExist = HnpOtherPackageInstallCheck(name->valuestring, version->valuestring, hapIndex, json); // 当卸载当前版本未被其他hap使用或者存在安装版本的时候,需要卸载对应的当前版本或者安装版本 if (!hnpExist || strcmp(installVersion->valuestring, "none") != 0) { + if (sum >= MAX_PACKAGE_HNP_NUM - 1) { + HNP_LOGE("package info num over limit"); + cJSON_Delete(json); + return HNP_ERRNO_BASE_FILE_COUNT_OVER; + } + if ((strcpy_s(packageInfos[sum].name, MAX_FILE_PATH_LEN, name->valuestring) != EOK) || (strcpy_s(packageInfos[sum].currentVersion, HNP_VERSION_LEN, version->valuestring) != EOK) || (strcpy_s(packageInfos[sum].installVersion, HNP_VERSION_LEN, installVersion->valuestring) != EOK)) { diff --git a/service/hnp/installer/src/hnp_installer.c b/service/hnp/installer/src/hnp_installer.c index 180c7ab8..fb671f25 100644 --- a/service/hnp/installer/src/hnp_installer.c +++ b/service/hnp/installer/src/hnp_installer.c @@ -641,10 +641,16 @@ static int HnpInstallHapFileCountGet(const char *root, int *count) { struct dirent *entry; char hnpPath[MAX_FILE_PATH_LEN]; + char realPath[MAX_FILE_PATH_LEN] = {0}; - DIR *dir = opendir(root); + if ((realpath(root, realPath) == NULL) || (strnlen(realPath, MAX_FILE_PATH_LEN) >= MAX_FILE_PATH_LEN)) { + HNP_LOGE("hnp root path:%{public}s invalid", root); + return HNP_ERRNO_BASE_PARAMS_INVALID; + } + + DIR *dir = opendir(realPath); if (dir == NULL) { - HNP_LOGE("hnp install opendir:%{public}s unsuccess, errno=%{public}d", root, errno); + HNP_LOGE("hnp install opendir:%{public}s unsuccess, errno=%{public}d", realPath, errno); return HNP_ERRNO_BASE_DIR_OPEN_FAILED; } @@ -652,7 +658,7 @@ static int HnpInstallHapFileCountGet(const char *root, int *count) if ((strcmp(entry->d_name, "public") != 0) && (strcmp(entry->d_name, "private") != 0)) { continue; } - if (sprintf_s(hnpPath, MAX_FILE_PATH_LEN, "%s/%s", root, entry->d_name) < 0) { + if (sprintf_s(hnpPath, MAX_FILE_PATH_LEN, "%s/%s", realPath, entry->d_name) < 0) { HNP_LOGE("hnp install private base path sprintf unsuccess."); closedir(dir); return HNP_ERRNO_BASE_SPRINTF_FAILED; -- Gitee From a80760d2207f874d2f26be2df2c8eb1ad4b873c6 Mon Sep 17 00:00:00 2001 From: yh Date: Tue, 26 Nov 2024 15:58:17 +0800 Subject: [PATCH 053/148] modify debug Signed-off-by: yh Change-Id: Ic6192b45d2b50191baa60ad23917082b909d6b74 --- interfaces/innerkits/include/appspawn.h | 1 + standard/appspawn_service.c | 20 ++++++------ test/moduletest/appspawn_client_test.cpp | 40 ++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index 2160eec7..de0382fc 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -280,6 +280,7 @@ int AppSpawnClientAddPermission(AppSpawnClientHandle handle, AppSpawnReqMsgHandl #define MSG_EXT_NAME_MAX_CHILD_PROCCESS_MAX "MaxChildProcess" #define MSG_EXT_NAME_APP_FD "AppFd" #define MSG_EXT_NAME_JIT_PERMISSIONS "JITPermissions" +#define MSG_EXT_NAME_USERID "uid" int AppSpawnReqMsgAddExtInfo(AppSpawnReqMsgHandle reqHandle, const char *name, const uint8_t *value, uint32_t valueLen); diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 1271ccfb..ca514784 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -1519,17 +1519,21 @@ static void ProcessSpawnRestartMsg(AppSpawnConnection *connection, AppSpawnMsgNo APPSPAWN_LOGE("Failed to execv, ret %{public}d, errno %{public}d", ret, errno); } -APPSPAWN_STATIC int ProcessUninstallDebugHap(AppSpawnConnection *connection, AppSpawnMsgNode *message) +APPSPAWN_STATIC void ProcessUninstallDebugHap(AppSpawnConnection *connection, AppSpawnMsgNode *message) { APPSPAWN_LOGI("ProcessUninstallDebugHap start"); - APPSPAWN_CHECK(connection != NULL && message != NULL, return APPSPAWN_ARG_INVALID, - "ProcessUninstallDebugHap invalid param"); - AppSpawningCtx *property = CreateAppSpawningCtx(); - APPSPAWN_CHECK(property != NULL, return APPSPAWN_SYSTEM_ERROR, "create appspawn ctx failed"); + if (property == NULL) { + SendResponse(connection, &message->msgHeader, APPSPAWN_SYSTEM_ERROR, 0); + DeleteAppSpawnMsg(message); + return; + } + property->message = message; property->message->connection = connection; - return AppSpawnHookExecute(STAGE_PARENT_UNINSTALL, 0, GetAppSpawnContent(), &property->client); + int ret = AppSpawnHookExecute(STAGE_PARENT_UNINSTALL, 0, GetAppSpawnContent(), &property->client); + SendResponse(connection, &message->msgHeader, ret, 0); + DeleteAppSpawningCtx(property); } APPSPAWN_STATIC int AppspawpnDevicedebugKill(int pid, cJSON *args) @@ -1666,9 +1670,7 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess DeleteAppSpawnMsg(message); break; case MSG_UNINSTALL_DEBUG_HAP: - ret = ProcessUninstallDebugHap(connection, message); - SendResponse(connection, msg, ret, 0); - DeleteAppSpawnMsg(message); + ProcessUninstallDebugHap(connection, message); break; default: SendResponse(connection, msg, APPSPAWN_MSG_INVALID, 0); diff --git a/test/moduletest/appspawn_client_test.cpp b/test/moduletest/appspawn_client_test.cpp index eedc2050..3272b03d 100644 --- a/test/moduletest/appspawn_client_test.cpp +++ b/test/moduletest/appspawn_client_test.cpp @@ -120,5 +120,45 @@ HWTEST_F(AppSpawnClientTest, AppSpawn_Client_test002, TestSize.Level0) AppSpawnClientDestroy(clientHandle); } +HWTEST_F(AppSpawnClientTest, AppSpawn_Client_test003, TestSize.Level0) +{ + AppSpawnClientHandle clientHandle = CreateClient(APPSPAWN_SERVER_NAME); + ASSERT_EQ(clientHandle != NULL, 1); + + AppSpawnReqMsgHandle reqHandle = 0; + int ret = AppSpawnReqMsgCreate(MSG_UNINSTALL_DEBUG_HAP, "test.uninstall", &reqHandle); + ASSERT_EQ(ret, 0); + + ret = AppSpawnReqMsgSetBundleInfo(reqHandle, 100, "test.uninstall"); + ASSERT_EQ(ret, 0); + + AppSpawnResult result = {}; + ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); + if (ret == 0 && result.pid > 0) { + kill(result.pid, SIGKILL); + } + AppSpawnClientDestroy(clientHandle); +} + +HWTEST_F(AppSpawnClientTest, AppSpawn_Client_test004, TestSize.Level0) +{ + AppSpawnClientHandle clientHandle = CreateClient(APPSPAWN_SERVER_NAME); + ASSERT_EQ(clientHandle != NULL, 1); + + AppSpawnReqMsgHandle reqHandle = 0; + int ret = AppSpawnReqMsgCreate(MSG_UNINSTALL_DEBUG_HAP, "test.uninstall", &reqHandle); + ASSERT_EQ(ret, 0); + + ret = AppSpawnReqMsgAddStringInfo(reqHandle, MSG_EXT_NAME_USERID, "100"); + ASSERT_EQ(ret, 0); + + AppSpawnResult result = {}; + ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); + if (ret == 0 && result.pid > 0) { + kill(result.pid, SIGKILL); + } + AppSpawnClientDestroy(clientHandle); +} + } // namespace AppSpawn } // namespace OHOS -- Gitee From 8592c10c95e7d88f093ff9dd41758eab5735e63f Mon Sep 17 00:00:00 2001 From: yh Date: Tue, 26 Nov 2024 17:59:00 +0800 Subject: [PATCH 054/148] add env Signed-off-by: yh Change-Id: If4fe7f9fde637147f444a73053683b798b73bf8f --- modules/common/appspawn_common.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/common/appspawn_common.c b/modules/common/appspawn_common.c index a329b10d..646957ae 100644 --- a/modules/common/appspawn_common.c +++ b/modules/common/appspawn_common.c @@ -59,6 +59,7 @@ #define PROVISION_TYPE_DEBUG "debug" #define DEVICE_NULL_STR "/dev/null" +#define PROCESS_START_TIME_ENV "PROCESS_START_TIME" #define BITLEN32 32 #define PID_NS_INIT_UID 100000 // reserved for pid_ns_init process, avoid app, render proc, etc. #define PID_NS_INIT_GID 100000 @@ -565,6 +566,20 @@ APPSPAWN_STATIC int SetFdEnv(AppSpawnMgr *content, AppSpawningCtx *property) return 0; } +APPSPAWN_STATIC int RecordStartTime(AppSpawnMgr *content, AppSpawningCtx *property) +{ + struct timespec ts; + int ret = clock_gettime(CLOCK_REALTIME, &ts); + APPSPAWN_CHECK(ret == 0, return 0, "clock_gettime failed %{public}d,%{public}d", ret, errno); + long long startTime = (ts.tv_sec * 1000LL) + (ts.tv_nsec / 1000000); + char timeChar[32]; + ret = snprintf_s(timeChar, sizeof(timeChar), sizeof(timeChar) - 1, "%lld", startTime); + APPSPAWN_CHECK(ret > 0, return 0, "failed to snprintf_s %{public}d,%{public}d", ret, errno); + ret = setenv(PROCESS_START_TIME_ENV, timeChar, 1); + APPSPAWN_CHECK_ONLY_LOG(ret == 0, "set env failed %{public}d,%{public}d", ret, errno); + return 0; +} + MODULE_CONSTRUCTOR(void) { APPSPAWN_LOGV("Load common module ..."); @@ -579,4 +594,5 @@ MODULE_CONSTRUCTOR(void) AddAppSpawnHook(STAGE_CHILD_POST_RELY, HOOK_PRIO_HIGHEST, SpawnComplete); AddAppSpawnHook(STAGE_PARENT_POST_FORK, HOOK_PRIO_HIGHEST, CloseFdArgs); AddAppSpawnHook(STAGE_CHILD_PRE_COLDBOOT, HOOK_PRIO_HIGHEST, SetFdEnv); + AddAppSpawnHook(STAGE_CHILD_PRE_RUN, HOOK_PRIO_HIGHEST, RecordStartTime); } -- Gitee From a47ca17b06afb3c1db2d39879e341192c039552a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Tue, 26 Nov 2024 19:55:48 +0800 Subject: [PATCH 055/148] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9appspawn=20fuz?= =?UTF-8?q?z=20=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp b/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp index 1c874185..39e6553d 100644 --- a/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp +++ b/test/fuzztest/appspawnclient_fuzzer/appspawnclient_fuzzer.cpp @@ -287,7 +287,7 @@ namespace OHOS { int FuzzGetPermissionByIndex(const uint8_t *data, size_t size) { - if (data == nullptr) { + if ((data == nullptr) || (size < sizeof(int32_t))) { return -1; } -- Gitee From c6f00a794097e2236f0dbc9b3fa6e04741c6b81a Mon Sep 17 00:00:00 2001 From: z00500798 Date: Tue, 26 Nov 2024 20:38:23 +0800 Subject: [PATCH 056/148] Description:appspawn bugfix Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: zl_zl --- modules/sandbox/sandbox_utils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index dc3ddd75..6fac6615 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -270,12 +270,12 @@ int32_t SandboxUtils::DoAppSandboxMountOnce(const char *originPath, const char * int ret = 0; // to mount fs and bind mount files or directory struct timespec mountStart = {0}; - clock_gettime(CLOCK_MONOTONIC, &mountStart); + clock_gettime(CLOCK_MONOTONIC_COARSE, &mountStart); APPSPAWN_LOGV("Bind mount %{public}s to %{public}s '%{public}s' '%{public}lu' '%{public}s' '%{public}u'", originPath, destinationPath, fsType, mountFlags, options, mountSharedFlag); ret = mount(originPath, destinationPath, fsType, mountFlags, options); struct timespec mountEnd = {0}; - clock_gettime(CLOCK_MONOTONIC, &mountEnd); + clock_gettime(CLOCK_MONOTONIC_COARSE, &mountEnd); uint64_t diff = DiffTime(&mountStart, &mountEnd); APPSPAWN_CHECK_ONLY_LOG(diff < MAX_MOUNT_TIME, "mount %{public}s time %{public}" PRId64 " us", originPath, diff); if (ret != 0) { -- Gitee From e410741cbca1f16f0c8d709ce9bac2f878a789ce Mon Sep 17 00:00:00 2001 From: yh Date: Tue, 26 Nov 2024 21:09:20 +0800 Subject: [PATCH 057/148] add env Signed-off-by: yh Change-Id: I8c4990b20761d449804068bfc47567298a6c230a --- modules/common/appspawn_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/common/appspawn_common.c b/modules/common/appspawn_common.c index 646957ae..6ce56b27 100644 --- a/modules/common/appspawn_common.c +++ b/modules/common/appspawn_common.c @@ -569,7 +569,7 @@ APPSPAWN_STATIC int SetFdEnv(AppSpawnMgr *content, AppSpawningCtx *property) APPSPAWN_STATIC int RecordStartTime(AppSpawnMgr *content, AppSpawningCtx *property) { struct timespec ts; - int ret = clock_gettime(CLOCK_REALTIME, &ts); + int ret = clock_gettime(CLOCK_MONOTONIC, &ts); APPSPAWN_CHECK(ret == 0, return 0, "clock_gettime failed %{public}d,%{public}d", ret, errno); long long startTime = (ts.tv_sec * 1000LL) + (ts.tv_nsec / 1000000); char timeChar[32]; -- Gitee From 0fa41036c49d5169b33b5c7f7fe491a3f5b8e843 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Tue, 26 Nov 2024 22:37:55 +0800 Subject: [PATCH 058/148] fix bug Signed-off-by: nianyuu --- modules/sandbox/sandbox_utils.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 6fac6615..d3d85f85 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -2146,10 +2146,8 @@ static int UmountSandboxPath(const AppSpawnMgr *content, const AppSpawnedProcess APPSPAWN_LOGV("UmountSandboxPath name %{public}s pid %{public}d", appInfo->name, appInfo->pid); const char rootPath[] = "/mnt/sandbox/"; const char el1Path[] = "/data/storage/el1/bundle"; - const char userPath[] = "/storage/Users"; UmountDir(rootPath, el1Path, appInfo); - UmountDir(rootPath, userPath, appInfo); return 0; } -- Gitee From 2431b350b359cb443325e67e7d8fd3463530b879 Mon Sep 17 00:00:00 2001 From: yh Date: Thu, 28 Nov 2024 16:05:18 +0800 Subject: [PATCH 059/148] modify job Signed-off-by: yh Change-Id: Ie72a5bd00b488e1953b5b3e12abca05ca6597402 --- appspawn.cfg | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/appspawn.cfg b/appspawn.cfg index 768b92e8..2cd57bb0 100644 --- a/appspawn.cfg +++ b/appspawn.cfg @@ -1,6 +1,6 @@ { "jobs" : [{ - "name" : "service:nwebspawn", + "name" : "boot", "cmds" : [ "mkdir /mnt/sandbox", "mkdir /mnt/sandbox/com.ohos.render/ 0711 nwebspawn nwebspawn", @@ -60,9 +60,6 @@ "sandbox" : 0, "start-mode" : "boot", "secon" : "u:r:appspawn:s0", - "jobs" : { - "on-start" : "service:nwebspawn" - }, "bootevents" : "bootevent.appspawn.started" } ] -- Gitee From e5db347d9da20185a6affba614451c9bcf21285b Mon Sep 17 00:00:00 2001 From: nianyuu Date: Fri, 29 Nov 2024 00:13:05 +0800 Subject: [PATCH 060/148] revert umount Signed-off-by: nianyuu --- modules/sandbox/sandbox_utils.cpp | 32 ------------------------------- 1 file changed, 32 deletions(-) diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index d74ba316..e0789664 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -2120,37 +2120,6 @@ static int SpawnMountDirToShared(AppSpawnMgr *content, AppSpawningCtx *property) return 0; } -static void UmountDir(const char *rootPath, const char *targetPath, const AppSpawnedProcessInfo *appInfo) -{ - size_t allPathSize = strlen(rootPath) + USER_ID_SIZE + strlen(appInfo->name) + strlen(targetPath) + 2; - char *path = reinterpret_cast(malloc(sizeof(char) * (allPathSize))); - APPSPAWN_CHECK(path != NULL, return, "Failed to malloc path"); - - int ret = sprintf_s(path, allPathSize, "%s%u/%s%s", rootPath, appInfo->uid / UID_BASE, - appInfo->name, targetPath); - APPSPAWN_CHECK(ret > 0 && ((size_t)ret < allPathSize), free(path); - return, "Failed to get sandbox path errno %{public}d", errno); - - ret = umount2(path, MNT_DETACH); - if (ret == 0) { - APPSPAWN_LOGV("Umount2 sandbox path %{public}s success", path); - } else { - APPSPAWN_LOGW("Failed to umount2 sandbox path %{public}s errno %{public}d", path, errno); - } - free(path); -} - -static int UmountSandboxPath(const AppSpawnMgr *content, const AppSpawnedProcessInfo *appInfo) -{ - APPSPAWN_CHECK(content != NULL && appInfo != NULL, return -1, "Invalid content or appInfo"); - APPSPAWN_LOGV("UmountSandboxPath name %{public}s pid %{public}d", appInfo->name, appInfo->pid); - const char rootPath[] = "/mnt/sandbox/"; - const char el1Path[] = "/data/storage/el1/bundle"; - - UmountDir(rootPath, el1Path, appInfo); - return 0; -} - #ifndef APPSPAWN_SANDBOX_NEW MODULE_CONSTRUCTOR(void) { @@ -2158,6 +2127,5 @@ MODULE_CONSTRUCTOR(void) (void)AddServerStageHook(STAGE_SERVER_PRELOAD, HOOK_PRIO_SANDBOX, LoadAppSandboxConfig); (void)AddAppSpawnHook(STAGE_PARENT_PRE_FORK, HOOK_PRIO_COMMON, SpawnMountDirToShared); (void)AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_SANDBOX, SetAppSandboxProperty); - (void)AddProcessMgrHook(STAGE_SERVER_APP_DIED, HOOK_PRIO_SANDBOX, UmountSandboxPath); } #endif -- Gitee From faebf293ffc0bb857367e8cc229fe5ed40c04638 Mon Sep 17 00:00:00 2001 From: yh Date: Thu, 28 Nov 2024 22:18:28 +0800 Subject: [PATCH 061/148] ss Signed-off-by: yh Change-Id: I7e185f734f051e34db0108792a6790f3c72fb700 --- .../appspawnserver_fuzzer.cpp | 157 ++++ .../appspawnserver_fuzzer.h | 19 + .../appspawnserver_fuzzer/corpus/init | 14 + .../appspawnserver_fuzzer/project.xml | 25 + .../clienttest/app_spawn_client_destory.cpp | 142 ++++ .../clienttest/app_spawn_client_init.cpp | 117 +++ .../clienttest/app_spawn_client_send.cpp | 158 ++++ .../clienttest/app_spawn_module_test.cpp | 710 ++++++++++++++++++ .../clienttest/app_spawn_notify_test.cpp | 129 ++++ .../clienttest/appspawn_client_close_test.cpp | 105 +++ .../appspawn_client_connect_test.cpp | 175 +++++ .../clienttest/appspawn_client_test.cpp | 112 +++ .../appspawn_client_tryconnect_test.cpp | 118 +++ 13 files changed, 1981 insertions(+) create mode 100644 test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.cpp create mode 100644 test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.h create mode 100644 test/fuzztest/appspawnserver_fuzzer/corpus/init create mode 100644 test/fuzztest/appspawnserver_fuzzer/project.xml create mode 100644 test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_destory.cpp create mode 100644 test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_init.cpp create mode 100644 test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_send.cpp create mode 100644 test/unittest/app_spawn_standard_test/clienttest/app_spawn_module_test.cpp create mode 100644 test/unittest/app_spawn_standard_test/clienttest/app_spawn_notify_test.cpp create mode 100644 test/unittest/app_spawn_standard_test/clienttest/appspawn_client_close_test.cpp create mode 100644 test/unittest/app_spawn_standard_test/clienttest/appspawn_client_connect_test.cpp create mode 100644 test/unittest/app_spawn_standard_test/clienttest/appspawn_client_test.cpp create mode 100644 test/unittest/app_spawn_standard_test/clienttest/appspawn_client_tryconnect_test.cpp diff --git a/test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.cpp b/test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.cpp new file mode 100644 index 00000000..2afb1aac --- /dev/null +++ b/test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.cpp @@ -0,0 +1,157 @@ +/* + * 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 "appspawnserver_fuzzer.h" +#include +#include "appspawn_server.h" + +namespace OHOS { + + // Fuzz测试: AppSpawnExecuteClearEnvHook + int FuzzerAppSpawnExecuteClearEnvHook(const uint8_t *data, size_t size) + { + if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*)) { + return 0; + } + + AppSpawnContent *content = reinterpret_cast(const_cast(data)); + AppSpawnClient *client = reinterpret_cast(const_cast(data + + sizeof(AppSpawnContent*))); + + // 调用待测试函数 + AppSpawnExecuteClearEnvHook(content, client); + return 0; + } + + // Fuzz测试: AppSpawnExecuteSpawningHook + int FuzzerAppSpawnExecuteSpawningHook(const uint8_t *data, size_t size) + { + if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*)) { + return 0; + } + AppSpawnContent *content = reinterpret_cast(const_cast(data)); + AppSpawnClient *client = reinterpret_cast(const_cast(data + + sizeof(AppSpawnContent*))); + + // 调用待测试函数 + AppSpawnExecuteSpawningHook(content, client); + return 0; + } + + // Fuzz测试: AppSpawnExecutePreReplyHook + int FuzzerAppSpawnExecutePreReplyHook(const uint8_t *data, size_t size) + { + if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*)) { + return 0; + } + AppSpawnContent *content = reinterpret_cast(const_cast(data)); + AppSpawnClient *client = reinterpret_cast(const_cast(data + + sizeof(AppSpawnContent*))); + + // 调用待测试函数 + AppSpawnExecutePreReplyHook(content, client); + return 0; + } + + // Fuzz测试: AppSpawnExecutePostReplyHook + int FuzzerAppSpawnExecutePostReplyHook(const uint8_t *data, size_t size) + { + if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*)) { + return 0; + } + AppSpawnContent *content = reinterpret_cast(const_cast(data)); + AppSpawnClient *client = reinterpret_cast(const_cast(data + + sizeof(AppSpawnContent*))); + + // 调用待测试函数 + AppSpawnExecutePostReplyHook(content, client); + return 0; + } + + // Fuzz测试: AppSpawnEnvClear + int FuzzerAppSpawnEnvClear(const uint8_t *data, size_t size) + { + if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*)) { + return 0; + } + AppSpawnContent *content = reinterpret_cast(const_cast(data)); + AppSpawnClient *client = reinterpret_cast(const_cast(data + + sizeof(AppSpawnContent*))); + + // 调用待测试函数 + AppSpawnEnvClear(content, client); + return 0; + } + + // Fuzz测试: AppSpawnProcessMsg + int FuzzerAppSpawnProcessMsg(const uint8_t *data, size_t size) + { + if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*) + sizeof(pid_t)) { + return 0; + } + + AppSpawnContent *content = reinterpret_cast(const_cast(data)); + AppSpawnClient *client = reinterpret_cast(const_cast(data + + sizeof(AppSpawnContent*))); + pid_t *childPid = reinterpret_cast(const_cast(data + + sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*))); + + // 调用待测试函数 + AppSpawnProcessMsg(content, client, childPid); + return 0; + } + + // Fuzz测试: ProcessExit + int FuzzerProcessExit(const uint8_t *data, size_t size) + { + if (size < sizeof(int)) { + return 0; + } + int code = *reinterpret_cast(data); + + // 调用待测试函数 + ProcessExit(code); + return 0; + } + + // Fuzz测试: AppSpawnChild + int FuzzerAppSpawnChild(const uint8_t *data, size_t size) + { + if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*)) { + return 0; + } + AppSpawnContent *content = reinterpret_cast(const_cast(data)); + AppSpawnClient *client = reinterpret_cast(const_cast(data + + sizeof(AppSpawnContent*))); + + // 调用待测试函数 + AppSpawnChild(content, client); + return 0; + } +} +/* Fuzzer entry point */ +int FuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzerAppSpawnExecuteClearEnvHook(data, size); + OHOS::FuzzerAppSpawnExecuteSpawningHook(data, size); + OHOS::FuzzerAppSpawnExecutePreReplyHook(data, size); + OHOS::FuzzerAppSpawnExecutePostReplyHook(data, size); + OHOS::FuzzerAppSpawnEnvClear(data, size); + OHOS::FuzzerAppSpawnProcessMsg(data, size); + OHOS::FuzzerProcessExit(data, size); + OHOS::FuzzerAppSpawnChild(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.h b/test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.h new file mode 100644 index 00000000..e5eee134 --- /dev/null +++ b/test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.h @@ -0,0 +1,19 @@ +/* + * 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. + */ + +#ifndef APPSPAWNSERVER_FUZZER +#define APPSPAWNSERVER_FUZZER +#define FUZZ_PROJECT_NAME "appspawnserver_fuzzer" +#endif // appspawnserver_fuzzer \ No newline at end of file diff --git a/test/fuzztest/appspawnserver_fuzzer/corpus/init b/test/fuzztest/appspawnserver_fuzzer/corpus/init new file mode 100644 index 00000000..e7c3fecd --- /dev/null +++ b/test/fuzztest/appspawnserver_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/appspawnserver_fuzzer/project.xml b/test/fuzztest/appspawnserver_fuzzer/project.xml new file mode 100644 index 00000000..949d03ef --- /dev/null +++ b/test/fuzztest/appspawnserver_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 100 + + 30 + + 2048 + + diff --git a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_destory.cpp b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_destory.cpp new file mode 100644 index 00000000..b04174f5 --- /dev/null +++ b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_destory.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2024-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 "appspawn.h" +#include "appspawn_hook.h" +#include "appspawn_manager.h" +#include "appspawn_modulemgr.h" +#include "appspawn_permission.h" +#include "appspawn_sandbox.h" +#include "appspawn_utils.h" +#include "appspawn_server.h" +#include "securec.h" + +#include "app_spawn_stub.h" +#include "app_spawn_test_helper.h" + +namespace OHOS { + + // 常量定义 + constexpr int APPSPAWN_SYSTEM_ERROR = -1; + constexpr int CLIENT_COUNT = 4; + + // 使用智能指针来管理资源 + using AppSpawnClientHandle = std::unique_ptr; + + struct AppSpawnReqMsgMgr { + ClientType type; + int socketId; + std::mutex mutex; + }; + + class AppSpawnClientDestroyTest : public ::testing::Test { + protected: + void SetUp() override + { + // 初始化客户端实例为空 + for (auto &client : g_clientInstance) { + client.reset(); + } + } + + void TearDown() override + { + // 不需要手动释放资源,unique_ptr 会自动清理 + } + + // 使用 std::array 管理客户端实例 + std::array g_clientInstance{}; + }; + + // 测试:验证无效的 handle 返回错误 + TEST_F(AppSpawnClientDestroyTest, TestNullHandle) + { + int ret = AppSpawnClientDestroy(nullptr); + EXPECT_EQ(ret, APPSPAWN_SYSTEM_ERROR); + } + + // 测试:验证正常销毁流程 + TEST_F(AppSpawnClientDestroyTest, TestValidHandle) + { + // 创建一个有效的 AppSpawnReqMsgMgr 实例 + auto reqMgr = std::make_unique(); + + reqMgr->type = ClientType::AppSpawn; + reqMgr->socketId = 123; // 模拟一个有效的 socketId + + // 将这个实例放入全局实例中 + g_clientInstance[static_cast(ClientType::AppSpawn)] = std::move(reqMgr); + + // 调用销毁函数 + int ret = AppSpawnClientDestroy(g_clientInstance[static_cast(ClientType::AppSpawn)].get()); + EXPECT_EQ(ret, 0); + + // 验证销毁后的实例为空 + EXPECT_EQ(g_clientInstance[static_cast(ClientType::AppSpawn)], nullptr); + } + + // 测试:验证互斥锁是否正常工作 + TEST_F(AppSpawnClientDestroyTest, TestMutexProtection) + { + // 创建一个有效的 AppSpawnReqMsgMgr 实例 + auto reqMgr = std::make_unique(); + + reqMgr->type = ClientType::AppSpawn; + reqMgr->socketId = 123; // 模拟一个有效的 socketId + + // 将这个实例放入全局实例中 + g_clientInstance[static_cast(ClientType::AppSpawn)] = std::move(reqMgr); + + // 在不同线程中测试互斥锁的保护 + std::thread t([&]() + { + int ret = AppSpawnClientDestroy(g_clientInstance[static_cast(ClientType::AppSpawn)].get()); + EXPECT_EQ(ret, 0); }); + + // 等待线程完成 + t.join(); + + // 验证销毁后的实例为空 + EXPECT_EQ(g_clientInstance[static_cast(ClientType::AppSpawn)], nullptr); + } + + // 测试:验证 socketId 小于 0 时不关闭套接字 + TEST_F(AppSpawnClientDestroyTest, TestNoSocketCloseWhenSocketIdNegative) + { + // 创建一个没有有效 socketId 的实例 + auto reqMgr = std::make_unique(); + + reqMgr->type = ClientType::AppSpawn; + reqMgr->socketId = -1; // 模拟无效的 socketId + + // 将这个实例放入全局实例中 + g_clientInstance[static_cast(ClientType::AppSpawn)] = std::move(reqMgr); + + // 调用销毁函数 + int ret = AppSpawnClientDestroy(g_clientInstance[static_cast(ClientType::AppSpawn)].get()); + EXPECT_EQ(ret, 0); + + // 验证销毁后的实例为空 + EXPECT_EQ(g_clientInstance[static_cast(ClientType::AppSpawn)], nullptr); + } + +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_init.cpp b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_init.cpp new file mode 100644 index 00000000..48f75eb3 --- /dev/null +++ b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_init.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2024-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 "appspawn.h" +#include "appspawn_hook.h" +#include "appspawn_manager.h" +#include "appspawn_modulemgr.h" +#include "appspawn_permission.h" +#include "appspawn_sandbox.h" + +#include "appspawn_utils.h" +#include "appspawn_server.h" +#include "securec.h" + +#include "app_spawn_stub.h" +#include "app_spawn_test_helper.h" + +// 常量定义 +namespace OHOS { + const std::string CJAPPSPAWN_SERVICE_NAME = "CJAppSpawn"; + const std::string NWEBSPAWN_SERVICE_NAME = "NWebSpawn"; + const std::string NATIVESPAWN_SERVICE_NAME = "NativeSpawn"; + const std::string NWEBSPAWN_SOCKET_NAME = "SomeNWebSocketName"; +} + +// 测试用例类 +class AppSpawnClientInitTest : public ::testing::Test { +protected: + void SetUp() {} +}; + +// 测试:验证参数校验 +TEST_F(AppSpawnClientInitTest, TestInvalidArguments) +{ + AppSpawnClientHandle handle = nullptr; + + // 测试 serviceName 为 nullptr + int ret = AppSpawnClientInit(nullptr, &handle); + EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); + + // 测试 handle 为 nullptr + ret = AppSpawnClientInit(OHOS::CJAPPSPAWN_SERVICE_NAME.c_str(), nullptr); + EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); +} + +// 测试:验证正确的客户端类型选择 +TEST_F(AppSpawnClientInitTest, TestClientTypeSelection) +{ + AppSpawnClientHandle handle = nullptr; + + // 测试 CJAPPSPAWN_SERVER_NAME + int ret = AppSpawnClientInit(OHOS::CJAPPSPAWN_SERVICE_NAME.c_str(), &handle); + + EXPECT_EQ(ret, 0); + EXPECT_EQ(handle, g_clientInstance[CLIENT_FOR_CJAPPSPAWN]); + + // 测试 NWEBSPAWN_SERVER_NAME + ret = AppSpawnClientInit(OHOS::NWEBSPAWN_SERVICE_NAME.c_str(), &handle); + + EXPECT_EQ(ret, 0); + EXPECT_EQ(handle, g_clientInstance[CLIENT_FOR_NWEBSPAWN]); + + // 测试 NATIVESPAWN_SERVER_NAME + ret = AppSpawnClientInit(OHOS::NATIVESPAWN_SERVICE_NAME.c_str(), &handle); + + EXPECT_EQ(ret, 0); + EXPECT_EQ(handle, g_clientInstance[CLIENT_FOR_NATIVESPAWN]); + + // 测试包含 NWEBSPAWN_SOCKET_NAME 的字符串 + ret = AppSpawnClientInit(OHOS::NWEBSPAWN_SOCKET_NAME.c_str(), &handle); + + EXPECT_EQ(ret, 0); + EXPECT_EQ(handle, g_clientInstance[CLIENT_FOR_NWEBSPAWN]); +} + +// 测试:验证客户端实例初始化成功 +TEST_F(AppSpawnClientInitTest, TestClientInstanceInitSuccess) +{ + AppSpawnClientHandle handle = nullptr; + + // 测试 CJAPPSPAWN_SERVER_NAME + int ret = AppSpawnClientInit(OHOS::CJAPPSPAWN_SERVICE_NAME.c_str(), &handle); + + EXPECT_EQ(ret, 0); + EXPECT_EQ(handle, g_clientInstance[CLIENT_FOR_CJAPPSPAWN]); +} + +// 测试:验证客户端实例初始化失败 +TEST_F(AppSpawnClientInitTest, TestClientInstanceInitFailure) +{ + AppSpawnClientHandle handle = nullptr; + + // 模拟 InitClientInstance 失败 + int ret = AppSpawnClientInit("InvalidService", &handle); + + EXPECT_EQ(ret, APPSPAWN_SYSTEM_ERROR); + EXPECT_EQ(handle, nullptr); // 由于初始化失败,handle 应该为 null +} \ No newline at end of file diff --git a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_send.cpp b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_send.cpp new file mode 100644 index 00000000..dbc615d8 --- /dev/null +++ b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_send.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2024-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 "appspawn.h" +#include "appspawn_hook.h" +#include "appspawn_manager.h" +#include "appspawn_modulemgr.h" +#include "appspawn_permission.h" +#include "appspawn_sandbox.h" +#include "appspawn_utils.h" +#include "appspawn_server.h" +#include "securec.h" + +#include "app_spawn_stub.h" +#include "app_spawn_test_helper.h" + +#define TEST_PID 1234 + +constexpr unsigned int DEF_REQ_ID = 123; +constexpr unsigned int DEFAULT_MSG_LEN = 10; +constexpr const char *DEFAULT_PROCESS_NAME = "TestProcess"; + +// 错误码 +constexpr int APPSPAWN_ARG_INVALID = -1; + +// 测试用例类 +namespace OHOS { + + typedef void *AppSpawnClientHandle; + typedef void *AppSpawnReqMsgHandle; + + typedef struct { + int result; + int pid; + } AppSpawnResult; + + typedef struct { + unsigned int reqId; + struct { + unsigned int msgLen; + char processName[128]; + } *msg; + } AppSpawnReqMsgNode; + + typedef struct { + pthread_mutex_t mutex; + } AppSpawnReqMsgMgr; + + // 测试用例类 + class AppSpawnClientSendMsgTest : public ::testing::Test { + protected: + void SetUp() override + { + // 初始化 mutex + pthread_mutex_init(&reqMgr.mutex, nullptr); + } + + void TearDown() override + { + pthread_mutex_destroy(&reqMgr.mutex); + } + + AppSpawnReqMsgMgr reqMgr; + }; + + // 工具函数:创建一个测试用的请求节点 + std::unique_ptr CreateTestReqNode(unsigned int reqId = DEF_REQ_ID) + { + auto reqNode = std::make_unique(); + + reqNode->reqId = reqId; + reqNode->msg = std::make_uniquemsg)::element_type>(); + + reqNode->msg->msgLen = kDEFAULT_MSG_LEN; + return reqNode; + } + + // 测试:验证 result 为 nullptr 时返回 APPSPAWN_ARG_INVALID + TEST_F(AppSpawnClientSendMsgTest, TestNullResult) + { + auto reqNode = CreateTestReqNode(); + + int ret = AppSpawnClientSendMsg(&reqMgr, reqNode.get(), nullptr); + EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); + } + + // 测试:验证 reqHandle 为 nullptr 时返回 APPSPAWN_ARG_INVALID + TEST_F(AppSpawnClientSendMsgTest, TestNullReqHandle) + { + AppSpawnResult result; + + int ret = AppSpawnClientSendMsg(&reqMgr, nullptr, &result); + EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); + } + + // 测试:验证 handle 为 nullptr 时返回 APPSPAWN_ARG_INVALID + TEST_F(AppSpawnClientSendMsgTest, TestNullHandle) + { + auto reqNode = CreateTestReqNode(); + + AppSpawnResult result; + int ret = AppSpawnClientSendMsg(nullptr, reqNode.get(), &result); + EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); + } + + // 测试:验证正常的调用流程 + TEST_F(AppSpawnClientSendMsgTest, TestValidCase) + { + auto reqNode = CreateTestReqNode(); + + AppSpawnResult result; + int ret = AppSpawnClientSendMsg(&reqMgr, reqNode.get(), &result); + + // 验证返回值和 result + EXPECT_EQ(ret, 0); + EXPECT_EQ(result.result, 0); + + EXPECT_EQ(result.pid, TEST_PID); // 来自 ClientSendMsg 的模拟返回 + } + + // 测试:验证线程安全 + TEST_F(AppSpawnClientSendMsgTest, TestMutexProtection) + { + auto reqNode = CreateTestReqNode(); + AppSpawnResult result; + + // 在不同线程中调用 + std::thread t([&]() + { + int ret = AppSpawnClientSendMsg(&reqMgr, reqNode.get(), &result); + + EXPECT_EQ(ret, 0); + EXPECT_EQ(result.result, 0); + + EXPECT_EQ(result.pid, TEST_PID); }); + + t.join(); + } +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_module_test.cpp b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_module_test.cpp new file mode 100644 index 00000000..f40fd620 --- /dev/null +++ b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_module_test.cpp @@ -0,0 +1,710 @@ +/* + * Copyright (c) 2024-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 // For strcmp + +// 假设这些类型和全局变量已定义在目标代码中 +#define MODULE_DEFAULT 0 +#define APPSPAWN_TEST 1 // 让测试用例在测试模式下编译 +#define MODULE_MAX 10 +#define MODULE_DEFAULT 0 +// 模拟的结构和函数定义 +struct ModuleMgr { + const char *moduleName; + // 假设我们有一个模块管理器的接口 + void *moduleMgr; +}; + +ModuleMgr g_moduleMgr[MODULE_MAX]; // 这里只有一个模块 + +int ModuleMgrCreate(const char *name) +{ + // 模拟创建模块管理器 + return 1; // 假设成功创建 +} + +int ModuleMgrInstall(void *mgr, const char *moduleName, int flag, void *data) +{ + // 模拟安装模块 + return 0; // 假设安装成功 +} + +int AppSpawnModuleMgrInstall(const char *moduleName); + +namespace OHOS { + // 测试类 + class AppSpawnModuleMgrInstallTest : public ::testing::Test { + protected: + // 在每个测试之前执行 + void SetUp() override + { + // 这里可以对 `g_moduleMgr` 进行初始化,以确保每个测试环境独立 + g_moduleMgr[MODULE_DEFAULT].moduleMgr = nullptr; // 初始时模块管理器为空 + } + }; + + // 测试用例:传入 nullptr 参数时,函数应该返回 -1 + TEST_F(AppSpawnModuleMgrInstallTest, TestNullModuleName) + { + EXPECT_EQ(AppSpawnModuleMgrInstall(nullptr), -1); + } + + // 测试用例:`g_moduleMgr[type].moduleMgr` 为 nullptr 时,应该调用 `ModuleMgrCreate` 创建模块管理器 + TEST_F(AppSpawnModuleMgrInstallTest, TestCreateModuleMgrWhenNull) + { + // 检查模块管理器是否为空 + EXPECT_EQ(g_moduleMgr[MODULE_DEFAULT].moduleMgr, nullptr); + + // 调用函数 + EXPECT_EQ(AppSpawnModuleMgrInstall("testModule"), 0); + + // 检查模块管理器是否已经创建 + EXPECT_NE(g_moduleMgr[MODULE_DEFAULT].moduleMgr, nullptr); + } + + // 测试用例:`ModuleMgrInstall` 成功时,函数返回 0 + TEST_F(AppSpawnModuleMgrInstallTest, TestModuleInstallSuccess) + { + g_moduleMgr[MODULE_DEFAULT].moduleMgr = reinterpret_cast(1); + + // 传入有效的模块名 + EXPECT_EQ(AppSpawnModuleMgrInstall("testModule"), 0); + } + + // 测试用例:如果 `ModuleMgrCreate` 失败,返回 -1 + TEST_F(AppSpawnModuleMgrInstallTest, TestCreateFail) + { + // 模拟 `ModuleMgrCreate` 失败 + g_moduleMgr[MODULE_DEFAULT].moduleMgr = nullptr; // 模拟创建失败 + + // 传入有效的模块名 + EXPECT_EQ(AppSpawnModuleMgrInstall("testModule"), -1); + } + +#ifdef APPSPAWN_TEST + // 测试用例:如果在测试模式下,函数应该直接返回 0 + TEST_F(AppSpawnModuleMgrInstallTest, TestInTestMode) + { + EXPECT_EQ(AppSpawnModuleMgrInstall("testModule"), 0); + } +#endif + + // 测试用例 1:`type` 超出范围时,应该直接返回,不做任何操作 + TEST_F(AppSpawnModuleMgrUnInstallTest, TestTypeOutOfRange) + { + // `type` 小于 0 + AppSpawnModuleMgrUnInstall(-1); + for (int i = 0; i < MODULE_MAX; ++i) + { + EXPECT_EQ(g_moduleMgr[i].moduleMgr, nullptr); + } + + // `type` 大于等于 MODULE_MAX + AppSpawnModuleMgrUnInstall(MODULE_MAX); + for (int i = 0; i < MODULE_MAX; ++i) + { + EXPECT_EQ(g_moduleMgr[i].moduleMgr, nullptr); + } + } + + // 测试用例 2:`g_moduleMgr[type].moduleMgr` 为 nullptr 时,应该不进行任何操作 + TEST_F(AppSpawnModuleMgrUnInstallTest, TestModuleMgrIsNull) + { + // `g_moduleMgr[MODULE_DEFAULT].moduleMgr` 依然是 nullptr + AppSpawnModuleMgrUnInstall(MODULE_DEFAULT); + EXPECT_EQ(g_moduleMgr[MODULE_DEFAULT].moduleMgr, nullptr); // 确保没有改变 + } + + // 测试用例 3:`g_moduleMgr[type].moduleMgr` 不为 nullptr 时,应该销毁模块并将其设为 nullptr + TEST_F(AppSpawnModuleMgrUnInstallTest, TestUninstallModule) + { + // 设置 `g_moduleMgr[MODULE_DEFAULT].moduleMgr` 为一个非 nullptr 值 + void *mockMgr = reinterpret_cast(1); + g_moduleMgr[MODULE_DEFAULT].moduleMgr = mockMgr; + + // 调用卸载函数 + AppSpawnModuleMgrUnInstall(MODULE_DEFAULT); + + // 检查模块是否已被销毁,并且值是否已设为 nullptr + EXPECT_EQ(g_moduleMgr[MODULE_DEFAULT].moduleMgr, nullptr); + } + + // 测试用例 4:`g_moduleMgr` 的其他位置没有影响 + TEST_F(AppSpawnModuleMgrUnInstallTest, TestOtherModuleUnchanged) + { + // 设置 `g_moduleMgr[1].moduleMgr` 为一个非 nullptr 值 + void *mockMgr = reinterpret_cast(1); + g_moduleMgr[1].moduleMgr = mockMgr; + + // 调用卸载函数,使用不同的 `type` + AppSpawnModuleMgrUnInstall(MODULE_DEFAULT); // 不影响 g_moduleMgr[1] + + // 检查 `g_moduleMgr[1]` 是否仍然有效 + EXPECT_EQ(g_moduleMgr[1].moduleMgr, mockMgr); + } + + // 测试用例 5:`type` 为一个有效值,但模块已经被销毁的情况 + TEST_F(AppSpawnModuleMgrUnInstallTest, TestModuleAlreadyUninstalled) + { + // 初始化一个模块管理器并销毁它 + void *mockMgr = reinterpret_cast(1); + g_moduleMgr[MODULE_DEFAULT].moduleMgr = mockMgr; + + // 手动销毁模块 + ModuleMgrDestroy(mockMgr); + g_moduleMgr[MODULE_DEFAULT].moduleMgr = nullptr; + + // 调用卸载函数 + AppSpawnModuleMgrUnInstall(MODULE_DEFAULT); + + // 检查模块是否仍然为空 + EXPECT_EQ(g_moduleMgr[MODULE_DEFAULT].moduleMgr, nullptr); + } + + // 测试用例 1:`type` 超出范围时,应该返回 -1 + TEST_F(AppSpawnLoadAutoRunModulesTest, TestTypeOutOfRange) + { + EXPECT_EQ(AppSpawnLoadAutoRunModules(-1), -1); // `type` 小于 0 + EXPECT_EQ(AppSpawnLoadAutoRunModules(MODULE_MAX), -1); // `type` 大于等于 MODULE_MAX + } + + // 测试用例 2:模块已加载时,返回 0 + TEST_F(AppSpawnLoadAutoRunModulesTest, TestModuleAlreadyLoaded) + { + // 设置模块已经加载 + g_moduleMgr[MODULE_DEFAULT].moduleMgr = reinterpret_cast(1); // 模拟模块已加载 + + // 调用函数,应该返回 0 + EXPECT_EQ(AppSpawnLoadAutoRunModules(MODULE_DEFAULT), 0); + } + + // 测试用例 3:模块未加载时,调用 `ModuleMgrScan` 加载模块并返回 0 + TEST_F(AppSpawnLoadAutoRunModulesTest, TestModuleNotLoaded) + { + // `g_moduleMgr[MODULE_DEFAULT].moduleMgr` 初始为 nullptr + + // 调用函数,应该返回 0,并加载模块 + EXPECT_EQ(AppSpawnLoadAutoRunModules(MODULE_DEFAULT), 0); + // 检查 `moduleMgr` 是否已被加载 + EXPECT_NE(g_moduleMgr[MODULE_DEFAULT].moduleMgr, nullptr); + } + +// 测试用例 4:`APPSPAWN_TEST` 环境下,应该跳过 `ModuleMgrScan` 的调用并直接返回 0 +#ifdef APPSPAWN_TEST + TEST_F(AppSpawnLoadAutoRunModulesTest, TestInTestEnvironment) + { + // 在 APPSPAWN_TEST 环境下,`ModuleMgrScan` 被跳过,直接返回 0 + EXPECT_EQ(AppSpawnLoadAutoRunModules(MODULE_DEFAULT), 0); + } +#endif + + // 测试用例 5:模块加载失败时,返回 -1 + TEST_F(AppSpawnLoadAutoRunModulesTest, TestModuleLoadFailure) + { + // 修改 ModuleMgrScan 让它返回 NULL,模拟加载失败 + void *(*originalModuleMgrScan)(const char *) = ModuleMgrScan; + ModuleMgrScan = [](const char *moduleName) -> void * + { return nullptr; }; + + // 调用函数,应该返回 -1 + EXPECT_EQ(AppSpawnLoadAutoRunModules(MODULE_DEFAULT), -1); + + // 恢复原始的 ModuleMgrScan 函数 + ModuleMgrScan = originalModuleMgrScan; + } + + // 测试用例 1:g_appspawnHookMgr 已经初始化为非 nullptr + TEST_F(GetAppSpawnHookMgrTest, TestHookMgrAlreadyInitialized) + { + // 先初始化 g_appspawnHookMgr + g_appspawnHookMgr = HookMgrCreate("test"); + + // 调用 GetAppSpawnHookMgr,应该返回已经存在的 g_appspawnHookMgr + HOOK_MGR *hookMgr = GetAppSpawnHookMgr(); + EXPECT_EQ(hookMgr, g_appspawnHookMgr); + EXPECT_STREQ(hookMgr->name, "test"); + } + + // 测试用例 2:g_appspawnHookMgr 为 nullptr 时,调用 HookMgrCreate + TEST_F(GetAppSpawnHookMgrTest, TestHookMgrNotInitialized) + { + // g_appspawnHookMgr 初始为 nullptr + + // 调用 GetAppSpawnHookMgr,应该创建新的 g_appspawnHookMgr + HOOK_MGR *hookMgr = GetAppSpawnHookMgr(); + EXPECT_NE(hookMgr, nullptr); + EXPECT_STREQ(hookMgr->name, "appspawn"); + + // 确认 g_appspawnHookMgr 已被初始化 + EXPECT_EQ(g_appspawnHookMgr, hookMgr); + } + + // 测试用例 3:多次调用 GetAppSpawnHookMgr 返回同一个实例 + TEST_F(GetAppSpawnHookMgrTest, TestMultipleCallsReturnSameInstance) + { + // g_appspawnHookMgr 初始为 nullptr + + // 第一次调用,创建并返回新的实例 + HOOK_MGR *hookMgr1 = GetAppSpawnHookMgr(); + EXPECT_NE(hookMgr1, nullptr); + EXPECT_STREQ(hookMgr1->name, "appspawn"); + + // 第二次调用,返回相同的实例 + HOOK_MGR *hookMgr2 = GetAppSpawnHookMgr(); + EXPECT_EQ(hookMgr1, hookMgr2); + EXPECT_STREQ(hookMgr2->name, "appspawn"); + } + + // 测试用例 4:确保返回的对象的 name 是我们期望的 + TEST_F(GetAppSpawnHookMgrTest, TestCorrectName) + { + // g_appspawnHookMgr 初始为 nullptr + + // 调用 GetAppSpawnHookMgr,应该创建新的 g_appspawnHookMgr + HOOK_MGR *hookMgr = GetAppSpawnHookMgr(); + EXPECT_EQ(hookMgr->name, "appspawn"); + } + + // 测试用例 1:更新最小时间 + TEST_F(UpdateAppSpawnTimeTest, TestUpdateMinTime) + { + // 初始值为 INT_MAX 和 0 + GetAppSpawnMgr()->spawnTime.minAppspawnTime = INT_MAX; + GetAppSpawnMgr()->spawnTime.maxAppspawnTime = 0; + + // 调用 UpdateAppSpawnTime 来更新最小时间 + UpdateAppSpawnTime(100); + + // 验证最小时间已更新 + EXPECT_EQ(GetAppSpawnMgr()->spawnTime.minAppspawnTime, 100); + + // 验证日志输出 + std::string captured = testing::internal::CaptureStdout(); + EXPECT_NE(captured.find("spawn min time: 100"), std::string::npos); + } + + // 测试用例 2:更新最大时间 + TEST_F(UpdateAppSpawnTimeTest, TestUpdateMaxTime) + { + // 初始值为 INT_MAX 和 0 + GetAppSpawnMgr()->spawnTime.minAppspawnTime = INT_MAX; + GetAppSpawnMgr()->spawnTime.maxAppspawnTime = 0; + + // 调用 UpdateAppSpawnTime 来更新最大时间 + UpdateAppSpawnTime(500); + + // 验证最大时间已更新 + EXPECT_EQ(GetAppSpawnMgr()->spawnTime.maxAppspawnTime, 500); + + // 验证日志输出 + std::string captured = testing::internal::CaptureStdout(); + EXPECT_NE(captured.find("spawn max time: 500"), std::string::npos); + } + + // 测试用例 3:不更新最小时间和最大时间 + TEST_F(UpdateAppSpawnTimeTest, TestNoUpdate) + { + // 初始值为 100 和 500 + GetAppSpawnMgr()->spawnTime.minAppspawnTime = 100; + GetAppSpawnMgr()->spawnTime.maxAppspawnTime = 500; + + // 调用 UpdateAppSpawnTime,应该不做更新 + UpdateAppSpawnTime(200); + + // 验证最小时间和最大时间没有变化 + EXPECT_EQ(GetAppSpawnMgr()->spawnTime.minAppspawnTime, 100); + EXPECT_EQ(GetAppSpawnMgr()->spawnTime.maxAppspawnTime, 500); + + // 验证没有日志输出 + std::string captured = testing::internal::CaptureStdout(); + EXPECT_EQ(captured, ""); + } + + // 测试用例 1:验证正常执行和时间差计算 + TEST_F(PostHookExecTest, TestNormalExecution) + { + // 模拟 perLoadEnd 时间,假设它比 perLoadStart 大 1秒 + spawnMgr->perLoadEnd.tv_sec = 1001; + spawnMgr->perLoadEnd.tv_nsec = 500000000; // 1001s 500ms + + HOOK_INFO hookInfo = {1, 10}; // stage 1, prio 10 + int executionRetVal = 0; // 执行结果,假设为0 + + // 捕获输出 + std::string captured = testing::internal::CaptureStdout(); + + // 调用 PostHookExec + PostHookExec(&hookInfo, &hookArg, executionRetVal); + + // 验证 UpdateAppSpawnTime 被调用,检查时间差是否正确计算 + uint64_t expectedDiff = 1000000000; // 1秒 = 1e9 纳秒 + EXPECT_NE(captured.find("Updated AppSpawn Time: " + std::to_string(expectedDiff)), std::string::npos); + + // 验证日志输出内容是否包含预期的 Hook 信息 + EXPECT_NE(captured.find("Hook stage: 1 prio: 10 end time 1000000000 ns result: 0"), std::string::npos); + } + + // 测试用例 2:验证时间差为零时的行为 + TEST_F(PostHookExecTest, TestZeroTimeDifference) + { + // 模拟 perLoadEnd 时间与 perLoadStart 时间相同 + spawnMgr->perLoadEnd.tv_sec = 1000; + spawnMgr->perLoadEnd.tv_nsec = 500000000; // 1000s 500ms + + HOOK_INFO hookInfo = {1, 10}; // stage 1, prio 10 + int executionRetVal = 0; // 执行结果,假设为0 + + // 捕获输出 + std::string captured = testing::internal::CaptureStdout(); + + // 调用 PostHookExec + PostHookExec(&hookInfo, &hookArg, executionRetVal); + + // 验证 UpdateAppSpawnTime 被调用,检查时间差是否为零 + uint64_t expectedDiff = 0; + EXPECT_NE(captured.find("Updated AppSpawn Time: " + std::to_string(expectedDiff)), std::string::npos); + + // 验证日志输出内容是否包含预期的 Hook 信息 + EXPECT_NE(captured.find("Hook stage: 1 prio: 10 end time 0 ns result: 0"), std::string::npos); + } + + // 测试用例 1:验证 content 为 nullptr 时返回 APPSPAWN_ARG_INVALID + TEST_F(ServerStageHookExecuteTest, TestContentNull) + { + AppSpawnContent *nullContent = nullptr; + + int ret = ServerStageHookExecute(STAGE_SERVER_PRELOAD, nullContent); + + EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); + } + + // 测试用例 2:验证无效 stage 返回 APPSPAWN_ARG_INVALID + TEST_F(ServerStageHookExecuteTest, TestInvalidStage) + { + // 假设 STAGE_SERVER_EXIT 之后有个无效的 stage + AppSpawnHookStage invalidStage = static_cast(999); // 无效的阶段 + + int ret = ServerStageHookExecute(invalidStage, content); + + EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); + } + + // 测试用例 3:验证有效的 content 和 stage 执行成功 + TEST_F(ServerStageHookExecuteTest, TestValidExecution) + { + // 使用有效的 stage + AppSpawnHookStage validStage = STAGE_SERVER_PRELOAD; + + // 捕获日志输出 + std::string captured = testing::internal::CaptureStdout(); + + int ret = ServerStageHookExecute(validStage, content); + + // 期望钩子执行成功 + EXPECT_EQ(ret, 0); // 假设钩子返回值为 0 + + // 验证日志是否包含正确的钩子执行信息 + EXPECT_NE(captured.find("Execute hook [0] result 0"), std::string::npos); // STAGE_SERVER_PRELOAD 对应值为 0 + } + + // 测试用例 4:验证无效的钩子执行返回 ERR_NO_HOOK_STAGE + TEST_F(ServerStageHookExecuteTest, TestNoHookStage) + { + // 模拟钩子返回 ERR_NO_HOOK_STAGE + HookMgrExecute = [](void *, AppSpawnHookStage, void *, HOOK_EXEC_OPTIONS *) + { + return ERR_NO_HOOK_STAGE; + }; + + AppSpawnHookStage validStage = STAGE_SERVER_EXIT; + + int ret = ServerStageHookExecute(validStage, content); + + // 期望返回 0 因为 ERR_NO_HOOK_STAGE 被转换为 0 + EXPECT_EQ(ret, 0); + } + + // 测试用例 1:验证 hook 为 nullptr 时返回 APPSPAWN_ARG_INVALID + TEST_F(AddServerStageHookTest, TestHookNull) + { + ServerStageHook nullHook = nullptr; + + int ret = AddServerStageHook(STAGE_SERVER_PRELOAD, 10, nullHook); + + EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); + } + + // 测试用例 2:验证无效的 stage 返回 APPSPAWN_ARG_INVALID + TEST_F(AddServerStageHookTest, TestInvalidStage) + { + // 假设 STAGE_SERVER_EXIT 后有个无效的 stage + AppSpawnHookStage invalidStage = static_cast(999); // 无效的阶段 + + ServerStageHook validHook = ServerStageHookRun; + + int ret = AddServerStageHook(invalidStage, 10, validHook); + + EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); + } + + // 测试用例 3:验证有效的 stage 和 hook 时能够成功添加钩子 + TEST_F(AddServerStageHookTest, TestValidHookAndStage) + { + AppSpawnHookStage validStage = STAGE_SERVER_PRELOAD; + ServerStageHook validHook = ServerStageHookRun; + int prio = 10; + + // 捕获日志输出 + std::string captured = testing::internal::CaptureStdout(); + + int ret = AddServerStageHook(validStage, prio, validHook); + + // 期望返回 0,表示成功 + EXPECT_EQ(ret, 0); + + // 验证日志是否包含正确的钩子添加信息 + EXPECT_NE(captured.find("AddServerStageHook prio: 10"), std::string::npos); + } + + // 测试用例 4:验证无效的钩子(模拟钩子执行错误) + TEST_F(AddServerStageHookTest, TestHookExecutionError) + { + // 假设有一个无效的钩子 + ServerStageHook invalidHook = nullptr; // 无效钩子 + + int ret = AddServerStageHook(STAGE_SERVER_EXIT, 20, invalidHook); + + // 期望返回 APPSPAWN_ARG_INVALID,因为钩子是无效的 + EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); + } + // 测试用例 1:验证有效钩子函数的调用 + TEST_F(AppSpawnHookRunTest, ValidHookExecution) + { + int result = AppSpawnHookRun(&hookInfo, &executionContext); + + // 验证返回值是否符合预期,表示钩子被正确调用 + EXPECT_EQ(result, 42); + } + + // 测试用例 2:验证执行上下文为空的情况 + TEST_F(AppSpawnHookRunTest, NullExecutionContext) + { + int result = AppSpawnHookRun(&hookInfo, nullptr); + + // 验证如果 executionContext 为 NULL,函数应返回 0 或其它合适的错误码 + EXPECT_EQ(result, 0); // 这里假设返回 0 + } + + // 测试用例 3:验证 hookCookie 为 nullptr 时的行为 + TEST_F(AppSpawnHookRunTest, NullHookCookie) + { + hookInfo.hookCookie = nullptr; // 设置钩子为 nullptr + + int result = AppSpawnHookRun(&hookInfo, &executionContext); + + // 验证如果 hookCookie 为 NULL,函数应返回某个错误码或异常 + EXPECT_EQ(result, 0); // 这里假设返回 0 + } + + // 测试用例 4:验证钩子函数为其它实现时的调用 + TEST_F(AppSpawnHookRunTest, CustomHookFunction) + { + // 定义一个新的钩子函数 + auto customHook = [](AppSpawnMgr *mgr, AppSpawningCtx *ctx) -> int + { + return 99; // 自定义钩子返回 99 + }; + + hookInfo.hookCookie = (void *)customHook; // 使用自定义钩子 + + int result = AppSpawnHookRun(&hookInfo, &executionContext); + + // 验证自定义钩子函数被正确调用 + EXPECT_EQ(result, 99); + } + + // 测试用例 1:验证正常的日志输出和时间记录 + TEST_F(PreAppSpawnHookExecTest, NormalExecution) + { + hookInfo.stage = 1; + hookInfo.prio = 5; + + // 执行 PreAppSpawnHookExec + PreAppSpawnHookExec(&hookInfo, &executionContext); + + // 验证日志输出是否符合预期 + EXPECT_NE(logStream.str().find("Hook stage: 1 prio: 5 start"), std::string::npos); + + // 验证时间是否已经被记录(tmStart 的值应大于 0) + EXPECT_GT(executionContext.tmStart.tv_sec, 0); + EXPECT_GE(executionContext.tmStart.tv_nsec, 0); + } + + // 测试用例 2:验证 executionContext 为 nullptr 时的行为 + TEST_F(PreAppSpawnHookExecTest, NullExecutionContext) + { + hookInfo.stage = 1; + hookInfo.prio = 5; + + // 执行时传入 nullptr executionContext + PreAppSpawnHookExec(&hookInfo, nullptr); + + // 验证没有崩溃,且日志正确输出 + EXPECT_NE(logStream.str().find("Hook stage: 1 prio: 5 start"), std::string::npos); + } + + // 测试用例 3:验证 hookInfo 为 nullptr 时的行为 + TEST_F(PreAppSpawnHookExecTest, NullHookInfo) + { + // 执行时传入 nullptr hookInfo + PreAppSpawnHookExec(nullptr, &executionContext); + + // 验证没有崩溃,日志是否正确 + EXPECT_EQ(logStream.str(), ""); // 如果 hookInfo 为空,日志应该没有输出 + } + + // 测试用例 4:验证时间记录 + TEST_F(PreAppSpawnHookExecTest, TimeRecorded) + { + hookInfo.stage = 1; + hookInfo.prio = 5; + + // 执行函数 + PreAppSpawnHookExec(&hookInfo, &executionContext); + + // 验证时间字段是否被正确设置 + EXPECT_GT(executionContext.tmStart.tv_sec, 0); + EXPECT_GE(executionContext.tmStart.tv_nsec, 0); + } + + // 测试用例 1:验证正常的日志输出和时间计算 + TEST_F(PostAppSpawnHookExecTest, NormalExecution) + { + hookInfo.stage = 1; + hookInfo.prio = 5; + + // 假设 tmStart 已经设置 + executionContext.tmStart.tv_sec = 10; + executionContext.tmStart.tv_nsec = 500000000; // 10.5 seconds + + // 执行 PostAppSpawnHookExec + PostAppSpawnHookExec(&hookInfo, &executionContext, 0); + + // 验证日志输出是否符合预期 + EXPECT_NE(logStream.str().find("Hook stage: 1 prio: 5 end time"), std::string::npos); + EXPECT_NE(logStream.str().find("result: 0"), std::string::npos); + + // 验证时间差是否大于 0(假设 tmEnd 被正确设置) + uint64_t diff = DiffTime(&executionContext.tmStart, &executionContext.tmEnd); + EXPECT_GT(diff, 0); + } + + // 测试用例 2:验证 executionContext 为 nullptr 时的行为 + TEST_F(PostAppSpawnHookExecTest, NullExecutionContext) + { + hookInfo.stage = 1; + hookInfo.prio = 5; + + // 执行时传入 nullptr executionContext + PostAppSpawnHookExec(&hookInfo, nullptr, 0); + + // 验证没有崩溃,且日志正确输出(虽然 executionContext 为 NULL,函数仍应正常工作) + EXPECT_NE(logStream.str().find("Hook stage: 1 prio: 5 end time"), std::string::npos); + EXPECT_NE(logStream.str().find("result: 0"), std::string::npos); + } + + // 测试用例 3:验证 hookInfo 为 nullptr 时的行为 + TEST_F(PostAppSpawnHookExecTest, NullHookInfo) + { + // 执行时传入 nullptr hookInfo + PostAppSpawnHookExec(nullptr, &executionContext, 0); + + // 验证没有崩溃,日志应该为空(没有 hookInfo 的情况下,无法输出相关信息) + EXPECT_EQ(logStream.str(), ""); + } + + // 测试用例 4:验证时间差计算 + TEST_F(PostAppSpawnHookExecTest, TimeDiffCalculation) + { + hookInfo.stage = 1; + hookInfo.prio = 5; + + // 设置 start 时间为某个已知时间 + executionContext.tmStart.tv_sec = 5; + executionContext.tmStart.tv_nsec = 100000000; // 5.1 seconds + + // 设置一个稍后的 end 时间 + executionContext.tmEnd.tv_sec = 6; + executionContext.tmEnd.tv_nsec = 200000000; // 6.2 seconds + + // 计算时间差 + uint64_t diff = DiffTime(&executionContext.tmStart, &executionContext.tmEnd); + + // 验证时间差为 1.1 秒 (1.1 * 10^9 纳秒) + EXPECT_EQ(diff, 1100000000LL); + } + + // 测试用例 1:验证传入 nullptr 参数时的行为 + TEST_F(AppSpawnHookExecuteTest, InvalidArguments) + { + // 测试 content 和 client 为 nullptr 的情况 + int ret = AppSpawnHookExecute(STAGE_PARENT_PRE_FORK, 0, nullptr, nullptr); + EXPECT_EQ(ret, -1); // 应返回 -1,表示参数无效 + + // 测试 stage 无效时的情况 + ret = AppSpawnHookExecute((AppSpawnHookStage)999, 0, &content, &client); + EXPECT_EQ(ret, -1); // 应返回 -1,表示 stage 无效 + } + + // 测试用例 2:验证日志输出和正常执行 + TEST_F(AppSpawnHookExecuteTest, ValidExecution) + { + // 测试正常的执行路径 + int ret = AppSpawnHookExecute(STAGE_PARENT_PRE_FORK, 0, &content, &client); + + EXPECT_EQ(ret, 0); // 应返回 0,表示执行成功 + + // 检查日志是否包含预期的内容 + std::string logOutput = logStream.str(); + EXPECT_NE(logOutput.find("Execute hook [0] for app: TestApp"), std::string::npos); // stage 和 app name + EXPECT_EQ(logOutput.find("Invalid arg"), std::string::npos); // 无错误日志 + } + + // 测试用例 3:验证 HookMgrExecute 调用 + TEST_F(AppSpawnHookExecuteTest, HookMgrExecuteCalled) + { + // 测试正常的钩子执行 + int ret = AppSpawnHookExecute(STAGE_CHILD_PRE_RUN, 0, &content, &client); + + EXPECT_EQ(ret, 0); // 确保返回值为0,表示执行成功 + + // 检查日志输出 + std::string logOutput = logStream.str(); + EXPECT_NE(logOutput.find("Execute hook [1] result 0"), std::string::npos); // 检查执行成功的日志 + } + + // 测试用例 4:验证无效 stage 时的行为 + TEST_F(AppSpawnHookExecuteTest, InvalidStage) + { + int ret = AppSpawnHookExecute((AppSpawnHookStage)999, 0, &content, &client); + EXPECT_EQ(ret, -1); // 应返回 -1,表示 stage 无效 + + // 检查是否有相应的错误日志 + std::string logOutput = logStream.str(); + EXPECT_NE(logOutput.find("Invalid stage"), std::string::npos); + } +} // namespace OHOS diff --git a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_notify_test.cpp b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_notify_test.cpp new file mode 100644 index 00000000..a4037423 --- /dev/null +++ b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_notify_test.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2024-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 "appspawn.h" +#include "appspawn_hook.h" +#include "appspawn_manager.h" +#include "appspawn_modulemgr.h" +#include "appspawn_permission.h" +#include "appspawn_sandbox.h" +#include "appspawn_utils.h" +#include "appspawn_server.h" +#include "securec.h" + +#include "app_spawn_stub.h" +#include "app_spawn_test_helper.h" + +// 全局变量用于验证回调函数是否被调用 +bool g_callCalled = false; +int g_result = -1; +AppSpawnContent *CALL_CONTENT = nullptr; +AppSpawnClient *CALL_CLIENT = nullptr; + +// 测试用的回调函数 +void TestCallback(AppSpawnContent *content, AppSpawnClient *client, int result) +{ + g_callCalled = true; // 设置标志 + g_result = result; // 保存结果 + CALL_CONTENT = content; // 保存内容 + CALL_CLIENT = client; // 保存客户端 +} +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + class NotifyResToParentTest : public testing::Test { + protected: + void SetUp() override + { + // 在每个测试前初始化 + content = new AppSpawnContent(); + client = new AppSpawnClient(); + g_callCalled = false; // 每个测试开始时重置标志 + content->notifyResToParent = nullptr; // 默认没有回调 + } + + void TearDown() override + { + // 清理资源 + delete content; + content = nullptr; + delete client; + client = nullptr; + } + + AppSpawnContent *content; + AppSpawnClient *client; + }; + + // 测试:notifyResToParent非空时,函数被正确调用 + HWTEST_F(NotifyResToParentTest, TestNotifyResToParent_001, TestSize.Level0) + { + content->notifyResToParent = TestCallback; // 设置自定义回调 + + // 调用NotifyResToParent + NotifyResToParent(content, client, 42); + + // 验证回调是否被调用,并且结果是否正确 + EXPECT_TRUE(g_callCalled); + EXPECT_EQ(g_result, 42); + EXPECT_EQ(CALL_CONTENT, content); + EXPECT_EQ(CALL_CLIENT, client); + } + + // 测试:notifyResToParent为空时,函数不被调用 + HWTEST_F(NotifyResToParentTest, TestNotifyResToParent_002, TestSize.Level0) + { + content->notifyResToParent = nullptr; // 设置回调为NULL + + // 调用NotifyResToParent + NotifyResToParent(content, client, 42); + + // 验证回调没有被调用 + EXPECT_FALSE(g_callCalled); + } + + // 测试:传递不同的result值,回调函数被正确调用 + HWTEST_F(NotifyResToParentTest, TestNotifyResToParent_003, TestSize.Level0) + { + content->notifyResToParent = TestCallback; // 设置自定义回调 + + // 测试不同的result值 + NotifyResToParent(content, client, -1); + EXPECT_TRUE(g_callCalled); + EXPECT_EQ(g_result, -1); + + // 重置回调标志 + g_callCalled = false; + + NotifyResToParent(content, client, 0); + EXPECT_TRUE(g_callCalled); + EXPECT_EQ(g_result, 0); + + // 重置回调标志 + g_callCalled = false; + + NotifyResToParent(content, client, 100); + EXPECT_TRUE(g_callCalled); + EXPECT_EQ(g_result, 100); + } +} // namespace OHOS diff --git a/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_close_test.cpp b/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_close_test.cpp new file mode 100644 index 00000000..00fe1625 --- /dev/null +++ b/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_close_test.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2024-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 "appspawn.h" +#include "appspawn_hook.h" +#include "appspawn_manager.h" +#include "appspawn_modulemgr.h" +#include "appspawn_permission.h" +#include "appspawn_sandbox.h" +#include "appspawn_utils.h" +#include "appspawn_server.h" +#include "securec.h" + +#include "app_spawn_stub.h" +#include "app_spawn_test_helper.h" +#define SOCKET_PORT 8080 +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + class CloseClientSocketTest : public ::testing::Test { + protected: + int socketId; + + void SetUp() override + { + // 创建一个实际的 TCP socket + socketId = socket(AF_INET, SOCK_STREAM, 0); + ASSERT_GE(socketId, 0) << "Failed to create socket"; // 确保 socket 创建成功 + + // 设置一个连接目标 (假设使用本地地址) + struct sockaddr_in addr; + addr.sin_family = AF_INET; + addr.sin_port = htons(SOCKET_PORT); + addr.sin_addr.s_addr = INADDR_LOOPBACK; + + int result = connect(socketId, (struct sockaddr *)&addr, sizeof(addr)); + ASSERT_EQ(result, 0) << "Failed to connect socket"; + } + + void TearDown() override + { + if (socketId >= 0) { + close(socketId); + socketId = -1; + } + } + }; + + // 测试正常关闭的情况 + TEST_F(CloseClientSocketTest, TestCloseValidSocket) + { + int socketIdValid = socketId; // 使用有效的 socketId + EXPECT_NO_THROW(CloseClientSocket(socketIdValid)); // 调用 CloseClientSocket,应该正常关闭 + + // 检查 socket 是否已经关闭 + char buffer[10]; + int result = recv(socketIdValid, buffer, sizeof(buffer), MSG_DONTWAIT); + + EXPECT_EQ(result, -1); // 如果套接字关闭,应该返回 -1,表示连接被重置或关闭 + EXPECT_EQ(errno, EBADF); // 文件描述符无效,errno 应为 EBADF + } + + // 测试无效 socketId + TEST_F(CloseClientSocketTest, TestCloseInvalidSocket) + { + int socketIdInvalid = -1; // 无效的 socketId + EXPECT_NO_THROW(CloseClientSocket(socketIdInvalid)); // 对无效 socketId 调用不应该抛出异常 + } + + // 测试关闭已关闭的套接字 + TEST_F(CloseClientSocketTest, TestCloseAlreadyClosedSocket) + { + int socketIdValid = socketId; // 使用有效的 socketId + CloseClientSocket(socketIdValid); // 首先关闭它 + + EXPECT_NO_THROW(CloseClientSocket(socketIdValid)); // 再次调用不应该出错 + } + + // 测试关闭负值 socketId + TEST_F(CloseClientSocketTest, TestCloseNegativeSocket) + { + int socketIdNegative = -1; // 使用负值 socketId + EXPECT_NO_THROW(CloseClientSocket(socketIdNegative)); // 不会发生错误 + } +} \ No newline at end of file diff --git a/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_connect_test.cpp b/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_connect_test.cpp new file mode 100644 index 00000000..5062084b --- /dev/null +++ b/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_connect_test.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2024-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 "appspawn.h" +#include "appspawn_hook.h" +#include "appspawn_manager.h" +#include "appspawn_modulemgr.h" +#include "appspawn_permission.h" +#include "appspawn_sandbox.h" +#include "appspawn_utils.h" +#include "appspawn_server.h" +#include "securec.h" + +#include "app_spawn_stub.h" +#include "app_spawn_test_helper.h" + +#define SOCKET_NAME "loopserver" + +// 假设 CreateClientSocket 函数已经定义 +namespace OHOS { + class CreateClientSocketTest : public ::testing::Test { + protected: + const char *socketName = SOCKET_NAME; + const char *socketPath; + int serverFd = -1; + int clientFd = -1; + + void SetUp() override + { + // 准备 Unix 域套接字文件路径 + socketPath = std::string(_SOCKET_DIR) + socketName; + + // 创建并启动一个模拟的服务器套接字 + serverFd = socket(AF_UNIX, SOCK_STREAM, 0); + ASSERT_GE(serverFd, 0) << "Failed to create server socket"; + + struct sockaddr_un serverAddr; + serverAddr.sun_family = AF_UNIX; + + // 删除旧的套接字文件 + unlink(socketPath); + + int ret = bind(serverFd, (struct sockaddr *)&serverAddr, sizeof(serverAddr)); + ASSERT_EQ(ret, 0) << "Failed to bind server socket"; + + ret = listen(serverFd, 1); + ASSERT_EQ(ret, 0) << "Failed to listen on server socket"; + + // 创建客户端套接字 + clientFd = socket(AF_UNIX, SOCK_STREAM, 0); + ASSERT_GE(clientFd, 0) << "Failed to create client socket"; + } + + void TearDown() override + { + // 清理资源 + if (clientFd >= 0) { + close(clientFd); + clientFd = -1; + } + + if (serverFd >= 0) { + close(serverFd); + serverFd = -1; + } + + unlink(socketPath); // 删除 Unix 域套接字文件 + socketPath = nullptr; + } + }; + + // 测试套接字成功创建 + TEST_F(CreateClientSocketTest, TestCreateSocketSuccess) + { + uint32_t timeout = 1; // 设置一个合理的超时值 + int socketFd = CreateClientSocket(timeout); + + // 验证是否创建成功 + ASSERT_GE(socketFd, 0) << "Failed to create client socket"; + + // 连接到服务器 + struct sockaddr_un clientAddr; + clientAddr.sun_family = AF_UNIX; + + int ret = connect(socketFd, (struct sockaddr *)&clientAddr, sizeof(clientAddr)); + ASSERT_EQ(ret, 0) << "Failed to connect to server"; + + // 关闭套接字 + CloseClientSocket(socketFd); + } + + // 测试套接字创建失败 + TEST_F(CreateClientSocketTest, TestCreateSocketFailure) + { + uint32_t timeout = 1; + + // 模拟套接字创建失败 + // 比如,通过删除目录,来模拟无法创建套接字 + unlink(socketPath); // 删除存在的套接字文件 + int socketFd = CreateClientSocket(timeout); + + // 验证套接字创建失败,返回 -1 + ASSERT_EQ(socketFd, -1) << "Socket creation should have failed"; + + // 确保错误信息打印(可以通过检查日志输出) + } + + // 测试套接字连接失败 + TEST_F(CreateClientSocketTest, TestConnectSocketFailure) + { + uint32_t timeout = 1; + + // 在未启动服务器的情况下,尝试连接 + unlink(socketPath); // 确保没有现有的套接字文件 + int socketFd = CreateClientSocket(timeout); + + // 验证套接字创建成功,但连接失败 + ASSERT_GE(socketFd, 0) << "Socket creation should have succeeded"; + + // 在没有服务器的情况下,连接应该失败 + struct sockaddr_un clientAddr; + clientAddr.sun_family = AF_UNIX; + + int ret = connect(socketFd, (struct sockaddr *)&clientAddr, sizeof(clientAddr)); + ASSERT_EQ(ret, -1) << "Expected connection failure"; + ASSERT_EQ(errno, ECONNREFUSED) << "Expected ECONNREFUSED error"; + + // 关闭套接字 + CloseClientSocket(socketFd); + } + + // 测试超时设置 + TEST_F(CreateClientSocketTest, TestSetSocketTimeouts) + { + uint32_t timeout = 1; // 设置超时时间 + int socketFd = CreateClientSocket(timeout); + ASSERT_GE(socketFd, 0) << "Failed to create socket"; + + // 通过查看设置的超时来验证是否生效 + struct timeval recvTimeout; + socklen_t optlen = sizeof(recvTimeout); + + int ret = getsockopt(socketFd, SOL_SOCKET, SO_RCVTIMEO, &recvTimeout, &optlen); + ASSERT_EQ(ret, 0) << "Failed to get SO_RCVTIMEO"; + ASSERT_EQ(recvTimeout.tv_sec, 1) << "Expected receive timeout to be 1 second"; + + struct timeval sendTimeout; + ret = getsockopt(socketFd, SOL_SOCKET, SO_SNDTIMEO, &sendTimeout, &optlen); + + ASSERT_EQ(ret, 0) << "Failed to get SO_SNDTIMEO"; + ASSERT_EQ(sendTimeout.tv_sec, 1) << "Expected send timeout to be 1 second"; + + // 关闭套接字 + CloseClientSocket(socketFd); + } +} \ No newline at end of file diff --git a/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_test.cpp b/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_test.cpp new file mode 100644 index 00000000..06cfca4b --- /dev/null +++ b/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_test.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2024-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 "appspawn.h" +#include "appspawn_hook.h" +#include "appspawn_manager.h" +#include "appspawn_modulemgr.h" +#include "appspawn_permission.h" +#include "appspawn_sandbox.h" +#include "appspawn_utils.h" +#include "appspawn_server.h" +#include "securec.h" + +#include "app_spawn_stub.h" +#include "app_spawn_test_helper.h" + +// 假设的全局配置 +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + class GetDefaultTimeoutTest : public testing::Test { + protected: + void SetUp() override + { + // 每个测试前初始化 + global_value = nullptr; // 确保全局值清空 + } + + void TearDown() override + { + // 每个测试后进行清理 + global_value = nullptr; // 清理全局设置 + } + }; + + // 测试默认值 + TEST_F(GetDefaultTimeoutTest, TestDefaultValue) + { + uint32_t def = 60; + uint32_t timeout = GetDefaultTimeout(def); + EXPECT_EQ(timeout, def); // 应该返回默认值 60 + } + + // 测试 SetParameter 设置的有效超时值 + TEST_F(GetDefaultTimeoutTest, TestValidTimeout) + { + SetParameter("persist.appspawn.reqMgr.timeout", "30"); // 设置超时时间为 30 + + uint32_t def = 60; + uint32_t timeout = GetDefaultTimeout(def); + EXPECT_EQ(timeout, 30); // 应该返回 30 + } + + // 测试 SetParameter 设置的无效超时值(非数字) + TEST_F(GetDefaultTimeoutTest, TestInvalidTimeout) + { + SetParameter("persist.appspawn.reqMgr.timeout", "invalid"); // 设置超时时间为无效值 + + uint32_t def = 60; + uint32_t timeout = GetDefaultTimeout(def); + EXPECT_EQ(timeout, def); // 应该返回默认值 60 + } + + // 测试 SetParameter 设置 "0" 时的行为 + TEST_F(GetDefaultTimeoutTest, TestZeroTimeout) + { + SetParameter("persist.appspawn.reqMgr.timeout", "0"); // 设置超时时间为 "0" + + uint32_t def = 60; + uint32_t timeout = GetDefaultTimeout(def); + EXPECT_EQ(timeout, def); // 应该返回默认值 60 + } + + // 测试返回空字符串的情况 + TEST_F(GetDefaultTimeoutTest, TestEmptyTimeout) + { + SetParameter("persist.appspawn.reqMgr.timeout", ""); // 设置超时时间为空 + + uint32_t def = 60; + uint32_t timeout = GetDefaultTimeout(def); + EXPECT_EQ(timeout, def); // 应该返回默认值 60 + } + + // 测试默认行为,没有调用 SetParameter 时 + TEST_F(GetDefaultTimeoutTest, TestNoTimeoutSet) + { + uint32_t def = 60; + uint32_t timeout = GetDefaultTimeout(def); + EXPECT_EQ(timeout, def); // 应该返回默认值 60,因为没有设置超时 + } + +} \ No newline at end of file diff --git a/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_tryconnect_test.cpp b/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_tryconnect_test.cpp new file mode 100644 index 00000000..b6731ddd --- /dev/null +++ b/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_tryconnect_test.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2024-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 "appspawn.h" +#include "appspawn_hook.h" +#include "appspawn_manager.h" +#include "appspawn_modulemgr.h" +#include "appspawn_permission.h" +#include "appspawn_sandbox.h" +#include "appspawn_utils.h" +#include "appspawn_server.h" +#include "securec.h" + +#include "app_spawn_stub.h" +#include "app_spawn_test_helper.h" + +#define RETRY_TIME 100000 // 100ms for testing +#define RETRY_COUNT 2 +#define MAX_RETRY_COUNT 3 + +// 测试用例类 +namespace OHOS { + + class TryCreateSocketTest : public ::testing::Test { + protected: + ReqMsgMgr reqMgr; + + void SetUp() override + { + reqMgr.socketId = -1; // 初始时设置套接字ID为无效 + reqMgr.maxRetryCount = MAX_RETRY_COUNT; // 最大重试次数 + reqMgr.timeout = RETRY_TIME; // 超时设置 + } + }; + + // 模拟 CreateClientSocket 的成功和失败 + int CreateClientSocket(uint32_t timeout) + { + static int attempt = 0; + if (attempt < RETRY_COUNT) { + attempt++; + return -1; // 模拟失败 + } + return 1; // 模拟成功 + } + + // 测试成功创建套接字 + TEST_F(TryCreateSocketTest, TestCreateSocketSuccess) + { + reqMgr.socketId = -1; // 确保初始状态是无效套接字 + reqMgr.maxRetryCount = 3; + + // 调用 TryCreateSocket + TryCreateSocket(&reqMgr); + + // 验证是否成功创建套接字 + ASSERT_GE(reqMgr.socketId, 0) << "Socket creation should succeed after retries"; + } + + // 测试套接字创建失败并重试 + TEST_F(TryCreateSocketTest, TestCreateSocketRetry) + { + reqMgr.socketId = -1; + reqMgr.maxRetryCount = 3; + + // 调用 TryCreateSocket + TryCreateSocket(&reqMgr); + + // 验证是否成功创建套接字 + ASSERT_GE(reqMgr.socketId, 0) << "Socket creation should succeed after retries"; + } + + // 测试最大重试次数后仍然无法创建套接字 + TEST_F(TryCreateSocketTest, TestMaxRetryFailure) + { + reqMgr.socketId = -1; + reqMgr.maxRetryCount = 2; // 设置最大重试次数为2 + + // 调用 TryCreateSocket + TryCreateSocket(&reqMgr); + + // 验证套接字创建失败 + ASSERT_EQ(reqMgr.socketId, -1) << "Socket creation should fail after max retries"; + } + + // 测试超时参数是否影响重试 + TEST_F(TryCreateSocketTest, TestSocketTimeout) + { + reqMgr.socketId = -1; + reqMgr.maxRetryCount = 1; + reqMgr.timeout = 2000; // 设置较长的超时 + + // 调用 TryCreateSocket + TryCreateSocket(&reqMgr); + + // 验证套接字创建是否成功 + ASSERT_GE(reqMgr.socketId, 0) << "Socket creation should succeed after one retry"; + } +} \ No newline at end of file -- Gitee From c007c2f1394810f487f66d42265317f1035ff552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Fri, 29 Nov 2024 10:37:37 +0800 Subject: [PATCH 062/148] =?UTF-8?q?appspawn=E8=A7=A3=E8=80=A6code=5Fsignat?= =?UTF-8?q?ure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- appspawn.gni | 1 + bundle.json | 3 ++- service/hnp/BUILD.gn | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/appspawn.gni b/appspawn.gni index ae2da360..480156ee 100644 --- a/appspawn.gni +++ b/appspawn.gni @@ -33,6 +33,7 @@ declare_args() { appspawn_mount_tmpshm = false appspawn_seccomp_privilege = false appspawn_support_prefork = true + appspawn_support_code_signature = true } if (!defined(global_parts_info) || diff --git a/bundle.json b/bundle.json index bf616295..b91fbdf1 100644 --- a/bundle.json +++ b/bundle.json @@ -25,7 +25,8 @@ "appspawn_use_encaps", "appspawn_mount_tmpshm", "appspawn_seccomp_privilege", - "appspawn_support_prefork" + "appspawn_support_prefork", + "appspawn_support_code_signature" ], "rom": "296KB", "ram": "13125KB", diff --git a/service/hnp/BUILD.gn b/service/hnp/BUILD.gn index ff0d57b0..89e48e85 100644 --- a/service/hnp/BUILD.gn +++ b/service/hnp/BUILD.gn @@ -33,11 +33,15 @@ if (!defined(ohos_lite)) { external_deps = [ "bounds_checking_function:libsec_shared", "cJSON:cjson", - "code_signature:libcode_sign_utils", "hilog:libhilog", "selinux_adapter:librestorecon", "zlib:shared_libz", ] + + if (appspawn_support_code_signature) { + external_deps += [ "code_signature:libcode_sign_utils" ] + } + defines = [] if (defined(global_parts_info) && defined(global_parts_info.security_code_signature)) { -- Gitee From a87c0cdc1de0d6bb316f5b3079634fc04509b135 Mon Sep 17 00:00:00 2001 From: yh Date: Fri, 29 Nov 2024 15:07:03 +0800 Subject: [PATCH 063/148] modify gwp Signed-off-by: yh Change-Id: I2659f493604dcf5930fd7a6fbeba5643fea7abba --- modules/asan/asan_detector.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/asan/asan_detector.c b/modules/asan/asan_detector.c index 81e4e64d..901bc27a 100644 --- a/modules/asan/asan_detector.c +++ b/modules/asan/asan_detector.c @@ -87,9 +87,6 @@ static int SetAsanEnabledEnv(const AppSpawnMgr *content, const AppSpawningCtx *p static void SetGwpAsanEnabled(const AppSpawnMgr *content, const AppSpawningCtx *property) { int enforce = CheckAppMsgFlagsSet(property, APP_FLAGS_GWP_ENABLED_FORCE); - if (!enforce && !CheckAppMsgFlagsSet(property, APP_FLAGS_GWP_ENABLED_NORMAL)) { - return; - } APPSPAWN_LOGV("SetGwpAsanEnabled with flags: %{public}d", enforce); may_init_gwp_asan(enforce); } -- Gitee From dbbd760b4034b1a19b1b8b6b84f490293febce30 Mon Sep 17 00:00:00 2001 From: LXinJie Date: Sat, 30 Nov 2024 17:11:38 +0800 Subject: [PATCH 064/148] liuxinjie6@huawei.com Signed-off-by: LXinJie --- bundle.json | 3 ++- common/appspawn_server.c | 2 ++ standard/BUILD.gn | 4 ++++ test/unittest/app_spawn_client_test/BUILD.gn | 1 + test/unittest/app_spawn_standard_test/BUILD.gn | 1 + 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index bf616295..1a23b850 100644 --- a/bundle.json +++ b/bundle.json @@ -69,7 +69,8 @@ "cJSON", "json", "faultloggerd", - "dlp_permission_service" + "dlp_permission_service", + "ffrt" ], "third_party": [ "bounds_checking_function", diff --git a/common/appspawn_server.c b/common/appspawn_server.c index 93655591..7996148e 100644 --- a/common/appspawn_server.c +++ b/common/appspawn_server.c @@ -26,6 +26,7 @@ #include "appspawn_utils.h" #ifndef OHOS_LITE #include "appspawn_manager.h" +#include "ffrt_inner.h" #endif #define MAX_FORK_TIME (30 * 1000) // 30ms @@ -120,6 +121,7 @@ int AppSpawnChild(AppSpawnContent *content, AppSpawnClient *client) static int CloneAppSpawn(void *arg) { APPSPAWN_CHECK(arg != NULL, return -1, "Invalid content for appspawn"); + ffrt_child_init(); AppSpawnForkArg *forkArg = (AppSpawnForkArg *)arg; ProcessExit(AppSpawnChild(forkArg->content, forkArg->client)); return 0; diff --git a/standard/BUILD.gn b/standard/BUILD.gn index 3dadbe6b..44263767 100644 --- a/standard/BUILD.gn +++ b/standard/BUILD.gn @@ -75,6 +75,7 @@ ohos_executable("appspawn") { "cJSON:cjson", "c_utils:utils", "config_policy:configpolicy_util", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbegetutil", @@ -131,6 +132,7 @@ ohos_shared_library("appspawn_helper") { "-fstack-protector-all", ] external_deps = [ + "ffrt:libffrt", "hilog:libhilog", "init:libbegetutil", ] @@ -185,6 +187,7 @@ ohos_executable("cjappspawn") { "cJSON:cjson", "c_utils:utils", "config_policy:configpolicy_util", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbegetutil", @@ -256,6 +259,7 @@ ohos_executable("nativespawn") { "cJSON:cjson", "c_utils:utils", "config_policy:configpolicy_util", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbegetutil", diff --git a/test/unittest/app_spawn_client_test/BUILD.gn b/test/unittest/app_spawn_client_test/BUILD.gn index 1a027dfa..7f2beb0c 100644 --- a/test/unittest/app_spawn_client_test/BUILD.gn +++ b/test/unittest/app_spawn_client_test/BUILD.gn @@ -87,6 +87,7 @@ ohos_unittest("AppSpawn_client_ut") { "cJSON:cjson", "c_utils:utils", "config_policy:configpolicy_util", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbegetutil", diff --git a/test/unittest/app_spawn_standard_test/BUILD.gn b/test/unittest/app_spawn_standard_test/BUILD.gn index f997543f..ae2b9d8e 100644 --- a/test/unittest/app_spawn_standard_test/BUILD.gn +++ b/test/unittest/app_spawn_standard_test/BUILD.gn @@ -171,6 +171,7 @@ ohos_unittest("AppSpawn_ut") { "c_utils:utils", "config_policy:configpolicy_util", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbegetutil", -- Gitee From 742791ba7ab4cd7dbd58d2e190848b75a726b0d1 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Sun, 1 Dec 2024 01:33:44 +0800 Subject: [PATCH 065/148] fix umount bug Signed-off-by: nianyuu --- modules/module_engine/include/appspawn_hook.h | 1 + modules/modulemgr/appspawn_modulemgr.c | 4 +- modules/sandbox/sandbox_utils.cpp | 51 +++++++++++++++++++ standard/appspawn_service.c | 1 + 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/modules/module_engine/include/appspawn_hook.h b/modules/module_engine/include/appspawn_hook.h index 856f5e80..be9eff8b 100644 --- a/modules/module_engine/include/appspawn_hook.h +++ b/modules/module_engine/include/appspawn_hook.h @@ -60,6 +60,7 @@ typedef enum TagAppSpawnHookStage { // 应用状态处理 STAGE_SERVER_APP_ADD, STAGE_SERVER_APP_DIED, + STAGE_SERVER_APP_UMOUNT, // run before fork STAGE_PARENT_PRE_FORK = 20, STAGE_PARENT_POST_FORK = 21, diff --git a/modules/modulemgr/appspawn_modulemgr.c b/modules/modulemgr/appspawn_modulemgr.c index e3dd3d7e..c29076de 100644 --- a/modules/modulemgr/appspawn_modulemgr.c +++ b/modules/modulemgr/appspawn_modulemgr.c @@ -259,7 +259,7 @@ int ProcessMgrHookExecute(AppSpawnHookStage stage, const AppSpawnContent *conten { APPSPAWN_CHECK(content != NULL && appInfo != NULL, return APPSPAWN_ARG_INVALID, "Invalid hook"); - APPSPAWN_CHECK((stage >= STAGE_SERVER_APP_ADD) && (stage <= STAGE_SERVER_APP_DIED), + APPSPAWN_CHECK((stage >= STAGE_SERVER_APP_ADD) && (stage <= STAGE_SERVER_APP_UMOUNT), return APPSPAWN_ARG_INVALID, "Invalid stage %{public}d", (int)stage); AppSpawnAppArg arg; @@ -279,7 +279,7 @@ static int ProcessMgrHookRun(const HOOK_INFO *hookInfo, void *executionContext) int AddProcessMgrHook(AppSpawnHookStage stage, int prio, ProcessChangeHook hook) { APPSPAWN_CHECK(hook != NULL, return APPSPAWN_ARG_INVALID, "Invalid hook"); - APPSPAWN_CHECK((stage >= STAGE_SERVER_APP_ADD) && (stage <= STAGE_SERVER_APP_DIED), + APPSPAWN_CHECK((stage >= STAGE_SERVER_APP_ADD) && (stage <= STAGE_SERVER_APP_UMOUNT), return APPSPAWN_ARG_INVALID, "Invalid stage %{public}d", (int)stage); HOOK_INFO info; info.stage = stage; diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index e0789664..f2d755a7 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -57,6 +57,8 @@ using namespace std; using namespace OHOS; +static map g_mountInfo; + namespace OHOS { namespace AppSpawn { namespace { @@ -1821,6 +1823,8 @@ int32_t SetAppSandboxProperty(AppSpawnMgr *content, AppSpawningCtx *property) { APPSPAWN_CHECK(property != nullptr, return -1, "Invalid appspwn client"); APPSPAWN_CHECK(content != nullptr, return -1, "Invalid appspwn content"); + // clear g_mountInfo in the child process + g_mountInfo.clear(); int ret = 0; // no sandbox if (CheckAppMsgFlagsSet(property, APP_FLAGS_NO_SANDBOX)) { @@ -1899,6 +1903,9 @@ static void MountDir(const AppSpawningCtx *property, const char *rootPath, const int len = sprintf_s(path, allPathSize, "%s%u/%s%s", rootPath, info->uid / userIdBase, bundleName, targetPath); APPSPAWN_CHECK(len > 0 && ((size_t)len < allPathSize), free(path); return, "Failed to get sandbox path"); + if (srcPath != nullptr) { + g_mountInfo[string(bundleName)]++; + } if (access(path, F_OK) == 0 && srcPath == nullptr) { free(path); @@ -2120,6 +2127,49 @@ static int SpawnMountDirToShared(AppSpawnMgr *content, AppSpawningCtx *property) return 0; } +static void UmountDir(const char *rootPath, const char *targetPath, const AppSpawnedProcessInfo *appInfo) +{ + size_t allPathSize = strlen(rootPath) + USER_ID_SIZE + strlen(appInfo->name) + strlen(targetPath) + 2; + char *path = reinterpret_cast(malloc(sizeof(char) * (allPathSize))); + APPSPAWN_CHECK(path != NULL, return, "Failed to malloc path"); + + int ret = sprintf_s(path, allPathSize, "%s%u/%s%s", rootPath, appInfo->uid / UID_BASE, + appInfo->name, targetPath); + APPSPAWN_CHECK(ret > 0 && ((size_t)ret < allPathSize), free(path); + return, "Failed to get sandbox path errno %{public}d", errno); + + ret = umount2(path, MNT_DETACH); + if (ret == 0) { + APPSPAWN_LOGV("Umount2 sandbox path %{public}s success", path); + } else { + APPSPAWN_LOGW("Failed to umount2 sandbox path %{public}s errno %{public}d", path, errno); + } + free(path); +} + +static int UmountSandboxPath(const AppSpawnMgr *content, const AppSpawnedProcessInfo *appInfo) +{ + APPSPAWN_CHECK(content != NULL && appInfo != NULL && appInfo->name != NULL, + return -1, "Invalid content or appInfo"); + APPSPAWN_LOGV("UmountSandboxPath name %{public}s pid %{public}d", appInfo->name, appInfo->pid); + const char rootPath[] = "/mnt/sandbox/"; + const char el1Path[] = "/data/storage/el1/bundle"; + + if (g_mountInfo.find(string(appInfo->name)) == g_mountInfo.end()) { + return 0; + } + g_mountInfo[string(appInfo->name)]--; + if (g_mountInfo[string(appInfo->name)] == 0) { + APPSPAWN_LOGV("no app %{public}s use it, need umount", appInfo->name); + g_mountInfo.erase(string(appInfo->name)); + UmountDir(rootPath, el1Path, appInfo); + } else { + APPSPAWN_LOGV("app %{public}s use it mount times %{public}d, not need umount", + appInfo->name, g_mountInfo[string(appInfo->name)]); + } + return 0; +} + #ifndef APPSPAWN_SANDBOX_NEW MODULE_CONSTRUCTOR(void) { @@ -2127,5 +2177,6 @@ MODULE_CONSTRUCTOR(void) (void)AddServerStageHook(STAGE_SERVER_PRELOAD, HOOK_PRIO_SANDBOX, LoadAppSandboxConfig); (void)AddAppSpawnHook(STAGE_PARENT_PRE_FORK, HOOK_PRIO_COMMON, SpawnMountDirToShared); (void)AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_SANDBOX, SetAppSandboxProperty); + (void)AddProcessMgrHook(STAGE_SERVER_APP_UMOUNT, HOOK_PRIO_SANDBOX, UmountSandboxPath); } #endif diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index d39ac7fb..30f6512e 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -155,6 +155,7 @@ static void HandleDiedPid(pid_t pid, uid_t uid, int status) APPSPAWN_CHECK_ONLY_LOG(appInfo->uid == uid, "Invalid uid %{public}u %{public}u", appInfo->uid, uid); DumpStatus(appInfo->name, pid, status); ProcessMgrHookExecute(STAGE_SERVER_APP_DIED, GetAppSpawnContent(), appInfo); + ProcessMgrHookExecute(STAGE_SERVER_APP_UMOUNT, GetAppSpawnContent(), appInfo); // if current process of death is nwebspawn, restart appspawn if (strcmp(appInfo->name, NWEBSPAWN_SERVER_NAME) == 0) { -- Gitee From d69176cb209c4f1e336b774313206b675eab17c1 Mon Sep 17 00:00:00 2001 From: zerodragon <644396695@qq.com> Date: Wed, 4 Dec 2024 10:28:14 +0800 Subject: [PATCH 066/148] =?UTF-8?q?=E7=BB=99=20hap=20=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20MCS=20=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zerodragon <644396695@qq.com> --- modules/common/appspawn_adapter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/common/appspawn_adapter.cpp b/modules/common/appspawn_adapter.cpp index 74ea6d78..70ef6d10 100644 --- a/modules/common/appspawn_adapter.cpp +++ b/modules/common/appspawn_adapter.cpp @@ -106,11 +106,13 @@ int SetSelinuxCon(const AppSpawnMgr *content, const AppSpawningCtx *property) reinterpret_cast(GetAppProperty(property, TLV_DOMAIN_INFO)); APPSPAWN_CHECK(msgDomainInfo != NULL, return APPSPAWN_TLV_NONE, "No domain info in req form %{public}s", GetProcessName(property)); + AppDacInfo *appInfo = reinterpret_cast(GetAppProperty(property, TLV_DAC_INFO)); HapContext hapContext; HapDomainInfo hapDomainInfo; hapDomainInfo.apl = msgDomainInfo->apl; hapDomainInfo.packageName = GetBundleName(property); hapDomainInfo.hapFlags = msgDomainInfo->hapFlags; + hapDomainInfo.uid = appInfo == NULL ? 0 : appInfo->uid; if (CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE)) { hapDomainInfo.hapFlags |= SELINUX_HAP_DEBUGGABLE; } -- Gitee From 33c09ed4a60c75b100c3a9f340063a046523fd6b Mon Sep 17 00:00:00 2001 From: nianyuu Date: Wed, 4 Dec 2024 17:25:34 +0800 Subject: [PATCH 067/148] modify sandbox json Signed-off-by: nianyuu --- appdata-sandbox-isolated.json | 45 ------------- appdata-sandbox.json | 120 ---------------------------------- appdata-sandbox64.json | 117 ++------------------------------- 3 files changed, 6 insertions(+), 276 deletions(-) diff --git a/appdata-sandbox-isolated.json b/appdata-sandbox-isolated.json index 19a8b963..bd9aa04b 100644 --- a/appdata-sandbox-isolated.json +++ b/appdata-sandbox-isolated.json @@ -49,51 +49,6 @@ "sandbox-path" : "/system/lib64", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" - }, { - "src-path" : "/system/lib/platformsdk", - "sandbox-path" : "/system/lib/platformsdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/ndk", - "sandbox-path" : "/system/lib/ndk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/module", - "sandbox-path" : "/system/lib/module", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/chipset-pub-sdk", - "sandbox-path" : "/system/lib/chipset-pub-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/chipset-sdk", - "sandbox-path" : "/system/lib/chipset-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/seccomp", - "sandbox-path" : "/system/lib/seccomp", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/extensionability", - "sandbox-path" : "/system/lib/extensionability", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/media", - "sandbox-path" : "/system/lib/media", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/ld-musl-arm.so.1", - "sandbox-path" : "/system/lib/ld-musl-arm.so.1", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" }, { "src-path" : "/data/app/el1/bundle/public/", "sandbox-path" : "/data/storage/el1/bundle", diff --git a/appdata-sandbox.json b/appdata-sandbox.json index f428321e..cf8355c6 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -48,46 +48,6 @@ "sandbox-path" : "/system/lib", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" - }, { - "src-path" : "/system/lib/platformsdk", - "sandbox-path" : "/system/lib/platformsdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/ndk", - "sandbox-path" : "/system/lib/ndk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/module", - "sandbox-path" : "/system/lib/module", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/chipset-pub-sdk", - "sandbox-path" : "/system/lib/chipset-pub-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/chipset-sdk", - "sandbox-path" : "/system/lib/chipset-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/seccomp", - "sandbox-path" : "/system/lib/seccomp", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/extensionability", - "sandbox-path" : "/system/lib/extensionability", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/media", - "sandbox-path" : "/system/lib/media", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" }, { "src-path" : "/system/data", "sandbox-path" : "/system/data", @@ -538,46 +498,6 @@ "sandbox-path" : "/system/lib", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" - }, { - "src-path" : "/system/lib/platformsdk", - "sandbox-path" : "/system/lib/platformsdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/ndk", - "sandbox-path" : "/system/lib/ndk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/module", - "sandbox-path" : "/system/lib/module", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/chipset-pub-sdk", - "sandbox-path" : "/system/lib/chipset-pub-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/chipset-sdk", - "sandbox-path" : "/system/lib/chipset-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/seccomp", - "sandbox-path" : "/system/lib/seccomp", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/extensionability", - "sandbox-path" : "/system/lib/extensionability", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/media", - "sandbox-path" : "/system/lib/media", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" }, { "src-path" : "/system/app/", "sandbox-path" : "/system/app/", @@ -668,46 +588,6 @@ "sandbox-path" : "/system/lib", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" - }, { - "src-path" : "/system/lib/platformsdk", - "sandbox-path" : "/system/lib/platformsdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/ndk", - "sandbox-path" : "/system/lib/ndk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/module", - "sandbox-path" : "/system/lib/module", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/chipset-pub-sdk", - "sandbox-path" : "/system/lib/chipset-pub-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/chipset-sdk", - "sandbox-path" : "/system/lib/chipset-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/seccomp", - "sandbox-path" : "/system/lib/seccomp", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/extensionability", - "sandbox-path" : "/system/lib/extensionability", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib/media", - "sandbox-path" : "/system/lib/media", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" }, { "src-path" : "/system/app/", "sandbox-path" : "/system/app/", diff --git a/appdata-sandbox64.json b/appdata-sandbox64.json index bc54ec69..1167b464 100644 --- a/appdata-sandbox64.json +++ b/appdata-sandbox64.json @@ -5,43 +5,8 @@ "sandbox-root" : "/mnt/sandbox/", "sandbox-ns-flags" : [ "net" ], "mount-paths" : [{ - "src-path" : "/system/lib64/platformsdk", - "sandbox-path" : "/system/lib64/platformsdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/ndk", - "sandbox-path" : "/system/lib64/ndk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/module", - "sandbox-path" : "/system/lib64/module", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/chipset-pub-sdk", - "sandbox-path" : "/system/lib64/chipset-pub-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/chipset-sdk", - "sandbox-path" : "/system/lib64/chipset-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/seccomp", - "sandbox-path" : "/system/lib64/seccomp", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/extensionability", - "sandbox-path" : "/system/lib64/extensionability", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/media", - "sandbox-path" : "/system/lib64/media", + "src-path" : "/system/lib64", + "sandbox-path" : "/system/lib64", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { @@ -85,43 +50,8 @@ "sandbox-root" : "/mnt/sandbox/com.ohos.render/", "sandbox-ns-flags" : [ "pid", "net" ], "mount-paths" : [{ - "src-path" : "/system/lib64/platformsdk", - "sandbox-path" : "/system/lib64/platformsdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/ndk", - "sandbox-path" : "/system/lib64/ndk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/module", - "sandbox-path" : "/system/lib64/module", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/chipset-pub-sdk", - "sandbox-path" : "/system/lib64/chipset-pub-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/chipset-sdk", - "sandbox-path" : "/system/lib64/chipset-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/seccomp", - "sandbox-path" : "/system/lib64/seccomp", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/extensionability", - "sandbox-path" : "/system/lib64/extensionability", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/media", - "sandbox-path" : "/system/lib64/media", + "src-path" : "/system/lib64", + "sandbox-path" : "/system/lib64", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { @@ -142,43 +72,8 @@ "sandbox-root" : "/mnt/sandbox/com.ohos.render/", "sandbox-ns-flags" : [ "pid", "net" ], "mount-paths" : [{ - "src-path" : "/system/lib64/platformsdk", - "sandbox-path" : "/system/lib64/platformsdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/ndk", - "sandbox-path" : "/system/lib64/ndk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/module", - "sandbox-path" : "/system/lib64/module", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/chipset-pub-sdk", - "sandbox-path" : "/system/lib64/chipset-pub-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/chipset-sdk", - "sandbox-path" : "/system/lib64/chipset-sdk", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/seccomp", - "sandbox-path" : "/system/lib64/seccomp", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/extensionability", - "sandbox-path" : "/system/lib64/extensionability", - "sandbox-flags" : [ "bind", "rec" ], - "check-action-status": "false" - }, { - "src-path" : "/system/lib64/media", - "sandbox-path" : "/system/lib64/media", + "src-path" : "/system/lib64", + "sandbox-path" : "/system/lib64", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { -- Gitee From f48c02e644c937d78e85c81860455f922a13316d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=85=B6=E6=96=87?= Date: Wed, 4 Dec 2024 17:53:26 +0800 Subject: [PATCH 068/148] =?UTF-8?q?hnp=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?Hnp=5FInstall=5F007=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈其文 --- test/unittest/hnp_test/hnp_installer_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/hnp_test/hnp_installer_test.cpp b/test/unittest/hnp_test/hnp_installer_test.cpp index 9b288509..d5c2a311 100644 --- a/test/unittest/hnp_test/hnp_installer_test.cpp +++ b/test/unittest/hnp_test/hnp_installer_test.cpp @@ -631,7 +631,7 @@ HWTEST_F(HnpInstallerTest, Hnp_Install_007, TestSize.Level0) char* argv[] = {arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12}; int argc = sizeof(argv) / sizeof(argv[0]); - EXPECT_EQ(HnpCmdInstall(argc, argv), HNP_ERRNO_BASE_DIR_OPEN_FAILED); + EXPECT_EQ(HnpCmdInstall(argc, argv), HNP_ERRNO_BASE_PARAMS_INVALID); } { // dst dir path is invalid char arg3[] = "-u"; -- Gitee From 808ee231dcace85755afa28775740b0a4d0b1a82 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Tue, 3 Dec 2024 22:43:08 +0800 Subject: [PATCH 069/148] fix ut Signed-off-by: nianyuu --- .../app_spawn_module_interface_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp index eed9eac9..90d8dce4 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp @@ -190,14 +190,14 @@ HWTEST_F(AppSpawnModuleInterfaceTest, App_Spawn_Process_Hook_001, TestSize.Level for (int i = 0; i < STAGE_MAX; i++) { for (int k = 0; k <= HOOK_PRIO_LOWEST + 1000; k += 1000) { // 1000 ret = AddProcessMgrHook(static_cast(i), k, ReportProcessExitInfo); - EXPECT_EQ(ret == 0, (i == STAGE_SERVER_APP_ADD || i == STAGE_SERVER_APP_DIED)); + EXPECT_EQ(ret == 0, (i >= STAGE_SERVER_APP_ADD && i <= STAGE_SERVER_APP_UMOUNT)); } ret = AddProcessMgrHook(static_cast(i), 0, nullptr); EXPECT_EQ(ret == 0, 0); ret = ProcessMgrHookExecute(static_cast(i), reinterpret_cast(mgr), app); - EXPECT_EQ(ret == 0, (i == STAGE_SERVER_APP_ADD || i == STAGE_SERVER_APP_DIED)); + EXPECT_EQ(ret == 0, (i >= STAGE_SERVER_APP_ADD && i <= STAGE_SERVER_APP_UMOUNT)); ret = ProcessMgrHookExecute(static_cast(i), nullptr, app); EXPECT_NE(ret, 0); -- Gitee From c79b9d69997b8e18410c28d8bd5af4c40acc2b56 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Thu, 5 Dec 2024 09:41:26 +0800 Subject: [PATCH 070/148] Adjust the mounting timing of the storage/Users directory Signed-off-by: wangfeng --- appdata-sandbox-app.json | 22 ++++++++++++++++---- appdata-sandbox.json | 33 +++++++++++++++++++++++++++++- modules/sandbox/appspawn_sandbox.c | 10 +++++++-- modules/sandbox/sandbox_utils.cpp | 14 ++++++++++--- 4 files changed, 69 insertions(+), 10 deletions(-) diff --git a/appdata-sandbox-app.json b/appdata-sandbox-app.json index b75c1579..a41ba2a4 100755 --- a/appdata-sandbox-app.json +++ b/appdata-sandbox-app.json @@ -178,7 +178,10 @@ "name": "ohos.permission.FILE_ACCESS_MANAGER", "sandbox-switch": "ON", "gids": ["file_manager", "user_data_rw"], - "mount-paths": [], + "mount-paths": [{ + "src-path": "/mnt/user//nosharefs/docs", + "sandbox-path": "/storage/Users" + }], "mount-groups": [ "user-public", "file_manager_recent" ] }, { "name": "ohos.permission.READ_IMAGEVIDEO", @@ -192,11 +195,11 @@ "name": "ohos.permission.FILE_CROSS_APP", "gids": ["file_manager"], "mount-paths": [], - "mount-groups": [ "user-public" ] + "mount-groups": [ "user-public", "storage_users" ] }, { "name": "ohos.permission.FILE_ACCESS_COMMON_DIR", "mount-paths": [], - "mount-groups": [ "user-public" ] + "mount-groups": [ "user-public", "storage_users" ] }, { "name": "ohos.permission.ACTIVATE_THEME_PACKAGE", "gids": ["wallpaper"], @@ -451,13 +454,24 @@ "src-path": "/storage/media//local/files/Docs", "sandbox-path": "/currentUser" }] - }, { + }, { "name": "file_manager_recent", "type": "app-variable", "mount-paths": [{ "src-path": "/storage/media//local/files/.Recent", "sandbox-path": "/storage/Users//.Recent" }] + }, { + "name": "storage_users", + "type": "app-variable", + "mount-paths": [{ + "src-path": "/mnt/user//sharefs/docs", + "sandbox-path": "/mnt/storage/Users" + }, { + "src-path": "/mnt/sandbox//app-root/mnt/storage/Users", + "sandbox-path": "/storage/Users", + "category": "dac_override_delete" + }] }, { "name": "el2", "type": "app-variable", diff --git a/appdata-sandbox.json b/appdata-sandbox.json index f428321e..5b809e76 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -790,6 +790,11 @@ "sandbox-path": "/storage/Users//.Recent", "sandbox-flags": [ "bind", "rec" ] }, + { + "src-path": "/mnt/user//nosharefs/docs", + "sandbox-path": "/storage/Users", + "sandbox-flags": [ "bind", "rec" ] + }, { "src-path": "/mnt/data//hmdfs", "sandbox-path": "/storage/hmdfs", @@ -813,12 +818,38 @@ "src-path": "/mnt/data/external", "sandbox-path": "/storage/External", "sandbox-flags": [ "bind", "rec" ] + }, + { + "src-path": "/mnt/user//sharefs/docs", + "sandbox-path": "/mnt/storage/Users", + "sandbox-flags": [ "bind", "rec" ] + }, + { + "src-path": "/mnt/sandbox///mnt/storage/Users", + "sandbox-path": "/storage/Users", + "sandbox-flags-customized": [ "MS_NODEV"], + "dac-override-sensitive": "true", + "fs-type": "sharefs", + "options": "override" } ] }], "ohos.permission.FILE_ACCESS_COMMON_DIR":[{ "sandbox-switch": "ON", - "mount-paths": [] + "mount-paths": [{ + "src-path": "/mnt/user//sharefs/docs", + "sandbox-path": "/mnt/storage/Users", + "sandbox-flags": [ "bind", "rec" ] + }, + { + "src-path": "/mnt/sandbox///mnt/storage/Users", + "sandbox-path": "/storage/Users", + "sandbox-flags-customized": [ "MS_NODEV"], + "dac-override-sensitive": "true", + "fs-type": "sharefs", + "options": "override" + } + ] }], "ohos.permission.ACTIVATE_THEME_PACKAGE":[{ "sandbox-switch": "ON", diff --git a/modules/sandbox/appspawn_sandbox.c b/modules/sandbox/appspawn_sandbox.c index ea236388..b9c960e9 100644 --- a/modules/sandbox/appspawn_sandbox.c +++ b/modules/sandbox/appspawn_sandbox.c @@ -659,6 +659,7 @@ static int SharedMountInSharefs(const AppSpawnMsgDacInfo *info, const char *root char currentUserPath[MAX_SANDBOX_BUFFER] = {0}; int ret = snprintf_s(currentUserPath, MAX_SANDBOX_BUFFER, MAX_SANDBOX_BUFFER - 1, "%s/currentUser", target); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s currentUserPath failed, errno %{public}d", errno); return APPSPAWN_ERROR_UTILS_MEM_FAIL; } @@ -675,6 +676,7 @@ static int SharedMountInSharefs(const AppSpawnMsgDacInfo *info, const char *root ret = snprintf_s(options, OPTIONS_MAX_LEN, OPTIONS_MAX_LEN - 1, "override_support_delete,user_id=%d", info->uid / UID_BASE); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s options failed, errno %{public}d", errno); return APPSPAWN_ERROR_UTILS_MEM_FAIL; } @@ -704,6 +706,7 @@ static void UpdateStorageDir(const SandboxContext *context, AppSpawnSandboxCfg * int ret = snprintf_s(nosharefsDocsDir, MAX_SANDBOX_BUFFER, MAX_SANDBOX_BUFFER - 1, "%s/%d/%s", mntUser, info->uid / UID_BASE, nosharefsDocs); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s nosharefsDocsDir failed, errno %{public}d", errno); return; } @@ -712,6 +715,7 @@ static void UpdateStorageDir(const SandboxContext *context, AppSpawnSandboxCfg * ret = snprintf_s(sharefsDocsDir, MAX_SANDBOX_BUFFER, MAX_SANDBOX_BUFFER - 1, "%s/%d/%s", mntUser, info->uid / UID_BASE, sharefsDocs); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s sharefsDocsDir failed, errno %{public}d", errno); return; } @@ -722,6 +726,7 @@ static void UpdateStorageDir(const SandboxContext *context, AppSpawnSandboxCfg * ret = snprintf_s(storageUserPath, MAX_SANDBOX_BUFFER, MAX_SANDBOX_BUFFER - 1, "%s/%d/app-root/%s", rootPath, info->uid / UID_BASE, userPath); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s storageUserPath failed, errno %{public}d", errno); return; } /* mount /mnt/user//sharefs/docs to /mnt/sandbox//app-root/storage/Users */ @@ -733,6 +738,7 @@ static void UpdateStorageDir(const SandboxContext *context, AppSpawnSandboxCfg * if (ret != 0) { APPSPAWN_LOGE("Update storage dir, ret %{public}d", ret); } + APPSPAWN_LOGI("Update %{public}s storage dir success", res == 0 ? "sharefs dir" : "no sharefs dir"); } static void MountDirToShared(const SandboxContext *context, AppSpawnSandboxCfg *sandbox) @@ -746,8 +752,6 @@ static void MountDirToShared(const SandboxContext *context, AppSpawnSandboxCfg * return; } - UpdateStorageDir(context, sandbox, info); - MountDir(info, appRootName, rootPath, nwebPath); MountDir(info, appRootName, rootPath, nwebTmpPath); @@ -755,6 +759,8 @@ static void MountDirToShared(const SandboxContext *context, AppSpawnSandboxCfg * return; } + UpdateStorageDir(context, sandbox, info); + int length = sizeof(MOUNT_SHARED_MAP) / sizeof(MOUNT_SHARED_MAP[0]); for (int i = 0; i < length; i++) { if (MOUNT_SHARED_MAP[i].permission == NULL) { diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index f2d755a7..3adb954f 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -274,7 +274,7 @@ int32_t SandboxUtils::DoAppSandboxMountOnce(const char *originPath, const char * struct timespec mountStart = {0}; clock_gettime(CLOCK_MONOTONIC_COARSE, &mountStart); APPSPAWN_LOGV("Bind mount %{public}s to %{public}s '%{public}s' '%{public}lu' '%{public}s' '%{public}u'", - originPath, destinationPath, fsType, mountFlags, options, mountSharedFlag); + originPath, destinationPath, fsType, mountFlags, options, mountSharedFlag); ret = mount(originPath, destinationPath, fsType, mountFlags, options); struct timespec mountEnd = {0}; clock_gettime(CLOCK_MONOTONIC_COARSE, &mountEnd); @@ -1954,12 +1954,14 @@ static int MountInShared(const AppSpawningCtx *property, const char *rootPath, c int ret = snprintf_s(path, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%u/%s/%s", rootPath, info->uid / UID_BASE, bundleName, target); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s path failed, errno %{public}d", errno); return APPSPAWN_ERROR_UTILS_MEM_FAIL; } char currentUserPath[PATH_MAX_LEN] = {0}; ret = snprintf_s(currentUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/currentUser", path); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s currentUserPath failed, errno %{public}d", errno); return APPSPAWN_ERROR_UTILS_MEM_FAIL; } @@ -1995,6 +1997,7 @@ static int SharedMountInSharefs(const AppSpawningCtx *property, const char *root char currentUserPath[PATH_MAX_LEN] = {0}; int ret = snprintf_s(currentUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/currentUser", target); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s currentUserPath failed, errno %{public}d", errno); return APPSPAWN_ERROR_UTILS_MEM_FAIL; } @@ -2011,6 +2014,7 @@ static int SharedMountInSharefs(const AppSpawningCtx *property, const char *root ret = snprintf_s(options, PATH_MAX_LEN, PATH_MAX_LEN - 1, "override_support_delete,user_id=%u", info->uid / UID_BASE); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s options failed, errno %{public}d", errno); return APPSPAWN_ERROR_UTILS_MEM_FAIL; } @@ -2045,6 +2049,7 @@ static void UpdateStorageDir(const AppSpawningCtx *property) int ret = snprintf_s(nosharefsDocsDir, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%u/%s", mntUser, info->uid / UID_BASE, nosharefsDocs); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s nosharefsDocsDir failed, errno %{public}d", errno); return; } @@ -2053,6 +2058,7 @@ static void UpdateStorageDir(const AppSpawningCtx *property) ret = snprintf_s(sharefsDocsDir, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%u/%s", mntUser, info->uid / UID_BASE, sharefsDocs); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s sharefsDocsDir failed, errno %{public}d", errno); return; } @@ -2064,6 +2070,7 @@ static void UpdateStorageDir(const AppSpawningCtx *property) ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%u/%s/%s", rootPath, info->uid / UID_BASE, bundleName, userPath); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s storageUserPath failed, errno %{public}d", errno); return; } /* mount /mnt/user//sharefs/docs to /mnt/sandbox///storage/Users */ @@ -2075,6 +2082,7 @@ static void UpdateStorageDir(const AppSpawningCtx *property) if (ret != 0) { APPSPAWN_LOGE("Update storage dir, ret %{public}d", ret); } + APPSPAWN_LOGI("Update %{public}s storage dir success", res == 0 ? "sharefs dir" : "no sharefs dir"); } static void MountDirToShared(const AppSpawningCtx *property) @@ -2088,8 +2096,6 @@ static void MountDirToShared(const AppSpawningCtx *property) return; } - UpdateStorageDir(property); - string sourcePath = "/data/app/el1/bundle/public/" + string(bundleName); MountDir(property, rootPath, sourcePath.c_str(), el1Path); size_t bundleNameLen = strlen(bundleName); @@ -2097,6 +2103,8 @@ static void MountDirToShared(const AppSpawningCtx *property) return; } + UpdateStorageDir(property); + int length = sizeof(MOUNT_SHARED_MAP) / sizeof(MOUNT_SHARED_MAP[0]); for (int i = 0; i < length; i++) { if (MOUNT_SHARED_MAP[i].permission == nullptr) { -- Gitee From 12a46df0625a019895e4f049df92a833e0b64f6e Mon Sep 17 00:00:00 2001 From: mengguo Date: Thu, 5 Dec 2024 19:58:15 +0800 Subject: [PATCH 071/148] fix comment Signed-off-by: mengguo Change-Id: Ib0e3332fef612d9d6e2394938b0a1c600c7c91c9 --- modules/common/appspawn_adapter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/common/appspawn_adapter.cpp b/modules/common/appspawn_adapter.cpp index 70ef6d10..5a5d2652 100644 --- a/modules/common/appspawn_adapter.cpp +++ b/modules/common/appspawn_adapter.cpp @@ -112,6 +112,7 @@ int SetSelinuxCon(const AppSpawnMgr *content, const AppSpawningCtx *property) hapDomainInfo.apl = msgDomainInfo->apl; hapDomainInfo.packageName = GetBundleName(property); hapDomainInfo.hapFlags = msgDomainInfo->hapFlags; + // This default value 0 is invalid. Its purpose is simply to initialize the hapDomainInfo.uid. hapDomainInfo.uid = appInfo == NULL ? 0 : appInfo->uid; if (CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE)) { hapDomainInfo.hapFlags |= SELINUX_HAP_DEBUGGABLE; -- Gitee From d2dfbc708e642fa27d2628922a316977634ccde1 Mon Sep 17 00:00:00 2001 From: mengguo Date: Fri, 6 Dec 2024 09:24:40 +0800 Subject: [PATCH 072/148] fix build error Signed-off-by: mengguo Change-Id: If1eed3dda9234f74b3e49613820705ebbf3f3a88 --- modules/common/appspawn_adapter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/common/appspawn_adapter.cpp b/modules/common/appspawn_adapter.cpp index 5a5d2652..2a4b6aa5 100644 --- a/modules/common/appspawn_adapter.cpp +++ b/modules/common/appspawn_adapter.cpp @@ -112,8 +112,7 @@ int SetSelinuxCon(const AppSpawnMgr *content, const AppSpawningCtx *property) hapDomainInfo.apl = msgDomainInfo->apl; hapDomainInfo.packageName = GetBundleName(property); hapDomainInfo.hapFlags = msgDomainInfo->hapFlags; - // This default value 0 is invalid. Its purpose is simply to initialize the hapDomainInfo.uid. - hapDomainInfo.uid = appInfo == NULL ? 0 : appInfo->uid; + hapDomainInfo.uid = appInfo == NULL ? 0 : appInfo->uid; //The value of 0 is invalid. Its purpose is to initialize. if (CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE)) { hapDomainInfo.hapFlags |= SELINUX_HAP_DEBUGGABLE; } -- Gitee From 8dc60cef721fc4db36fadacc149a0c917956ecdf Mon Sep 17 00:00:00 2001 From: z00500798 Date: Mon, 2 Dec 2024 16:47:45 +0800 Subject: [PATCH 073/148] Description:erofs mount Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: zl_zl --- interfaces/innerkits/client/appspawn_client.c | 35 ++++++++++++++++ .../client/libappspawn_client.versionscript | 1 + interfaces/innerkits/include/appspawn.h | 11 +++++ modules/sandbox/appspawn_sandbox.c | 28 ++++++------- modules/sandbox/sandbox_utils.cpp | 32 ++++++--------- standard/appspawn_service.c | 40 ++++++++++++++++++- 6 files changed, 110 insertions(+), 37 deletions(-) diff --git a/interfaces/innerkits/client/appspawn_client.c b/interfaces/innerkits/client/appspawn_client.c index 0d2c30b1..8875b4e3 100644 --- a/interfaces/innerkits/client/appspawn_client.c +++ b/interfaces/innerkits/client/appspawn_client.c @@ -35,6 +35,7 @@ #include "parameter.h" #include "securec.h" +#define USER_LOCK_STATUS_SIZE 8 static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; static AppSpawnReqMsgMgr *g_clientInstance[CLIENT_MAX] = {NULL}; @@ -370,3 +371,37 @@ int AppSpawnClientSendMsg(AppSpawnClientHandle handle, AppSpawnReqMsgHandle reqH AppSpawnReqMsgFree(reqHandle); return ret; } + +int AppSpawnClientSendUserLockStatus(uint32_t userId, bool isLocked) +{ + AppSpawnReqMsgHandle reqHandle; + int ret = AppSpawnReqMsgCreate(MSG_LOCK_STATUS, "storage_manager", &reqHandle); + APPSPAWN_CHECK(ret == 0, return ret, "Failed to create appspawn req msg, ret = %{public}d", ret); + + char lockstatus[USER_LOCK_STATUS_SIZE] = {0}; + ret = snprintf_s(lockstatus, USER_LOCK_STATUS_SIZE, USER_LOCK_STATUS_SIZE - 1, "%u:%d", userId, isLocked); + APPSPAWN_CHECK(ret > 0, return ret, "Failed to build lockstatus req msg, ret = %{public}d", ret); + APPSPAWN_LOGI("Send lockstatus msg to appspawn %{public}s", lockstatus); + + ret = AppSpawnReqMsgAddStringInfo(reqHandle, "lockstatus", lockstatus); + APPSPAWN_CHECK(ret == 0, AppSpawnReqMsgFree(reqHandle); + return ret, "Failed to add lockstatus message, ret=%{public}d", ret); + + AppSpawnClientHandle clientHandle; + ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle); + APPSPAWN_CHECK(ret == 0, AppSpawnReqMsgFree(reqHandle); + return ret, "Appspawn client failed to init, ret=%{public}d", ret); + + AppSpawnResult result = {0}; + ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); + AppSpawnClientDestroy(clientHandle); + APPSPAWN_CHECK(ret == 0, AppSpawnReqMsgFree(reqHandle); + return ret, "Send msg to appspawn failed, ret=%{public}d", ret); + + if (result.result != 0) { + APPSPAWN_LOGE("Appspawn failed to handle message, result=%{public}d", result.result); + return result.result; + } + APPSPAWN_LOGI("Send lockstatus msg to appspawn success"); + return 0; +} \ No newline at end of file diff --git a/interfaces/innerkits/client/libappspawn_client.versionscript b/interfaces/innerkits/client/libappspawn_client.versionscript index 0863f541..03ebc5b4 100644 --- a/interfaces/innerkits/client/libappspawn_client.versionscript +++ b/interfaces/innerkits/client/libappspawn_client.versionscript @@ -33,6 +33,7 @@ AppSpawnReqMsgAddStringInfo; AppSpawnTerminateMsgCreate; AppSpawnClientAddPermission; + AppSpawnClientSendUserLockStatus; GetPermissionIndex; GetMaxPermissionIndex; GetPermissionByIndex; diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index de0382fc..1a3157d1 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #ifdef __cplusplus @@ -97,6 +98,15 @@ int AppSpawnClientDestroy(AppSpawnClientHandle handle); */ int AppSpawnClientSendMsg(AppSpawnClientHandle handle, AppSpawnReqMsgHandle reqHandle, AppSpawnResult *result); +/** + * @brief send client user lock status request + * + * @param userId user id + * @param isLocked lock status + * @return if succeed return 0,else return other value + */ +int AppSpawnClientSendUserLockStatus(uint32_t userId, bool isLocked); + typedef enum { MSG_APP_SPAWN = 0, MSG_GET_RENDER_TERMINATION_STATUS, @@ -108,6 +118,7 @@ typedef enum { MSG_RESTART_SPAWNER, MSG_DEVICE_DEBUG, MSG_UNINSTALL_DEBUG_HAP, + MSG_LOCK_STATUS, MAX_TYPE_INVALID } AppSpawnMsgType; diff --git a/modules/sandbox/appspawn_sandbox.c b/modules/sandbox/appspawn_sandbox.c index ea236388..462a6607 100644 --- a/modules/sandbox/appspawn_sandbox.c +++ b/modules/sandbox/appspawn_sandbox.c @@ -47,6 +47,8 @@ #define USER_ID_SIZE 16 #define DIR_MODE 0711 +#define LOCK_STATUS_PARAM_SIZE 64 +#define LOCK_STATUS_SIZE 16 #define DEV_SHM_DIR "/dev/shm/" static inline void SetMountPathOperation(uint32_t *operation, uint32_t index) @@ -543,7 +545,7 @@ static int DoSandboxNodeMount(const SandboxContext *context, const SandboxSectio return 0; } -static bool IsUnlockStatus(uint32_t uid, const char *bundleName, size_t bundleNameLen) +static bool IsUnlockStatus(uint32_t uid) { const int userIdBase = UID_BASE; uid = uid / userIdBase; @@ -551,22 +553,16 @@ static bool IsUnlockStatus(uint32_t uid, const char *bundleName, size_t bundleNa return true; } - const char rootPath[] = "/data/app/el2/"; - const char basePath[] = "/base/"; - size_t allPathSize = strlen(rootPath) + strlen(basePath) + 1 + USER_ID_SIZE + bundleNameLen; - char *path = (char *)malloc(sizeof(char) * allPathSize); - (void)memset_s(path, allPathSize, 0, allPathSize); - APPSPAWN_CHECK(path != NULL, return true, "Failed to malloc path"); - int len = sprintf_s(path, allPathSize, "%s%u%s%s", rootPath, uid, basePath, bundleName); - APPSPAWN_CHECK(len > 0 && ((size_t)len < allPathSize), free(path); return true, "Failed to get base path"); - - if (access(path, F_OK) == 0) { - APPSPAWN_LOGI("this is unlock status"); - free(path); + char lockStatusParam[LOCK_STATUS_PARAM_SIZE] = {0}; + char userLockStatus[LOCK_STATUS_SIZE] = {0}; + int ret = snprintf_s(lockStatusParam, sizeof(lockStatusParam), sizeof(lockStatusParam) - 1, + "startup.appspawn.lockstatus_%u", uid); + APPSPAWN_CHECK(ret > 0, return false, "get lock status param failed, errno %{public}d", errno); + ret = GetParameter(lockStatusParam, "1", userLockStatus, sizeof(userLockStatus)); + APPSPAWN_LOGI("get param %{public}s %{public}s", lockStatusParam, userLockStatus); + if (ret > 0 && (strcmp(userLockStatus, "0") == 0)) { // 0:解密状态 1:加密状态 return true; } - free(path); - APPSPAWN_LOGI("this is lock status"); return false; } @@ -751,7 +747,7 @@ static void MountDirToShared(const SandboxContext *context, AppSpawnSandboxCfg * MountDir(info, appRootName, rootPath, nwebPath); MountDir(info, appRootName, rootPath, nwebTmpPath); - if (IsUnlockStatus(info->uid, context->bundleName, strlen(context->bundleName))) { + if (IsUnlockStatus(info->uid)) { return; } diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index e0789664..8e6e1642 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -52,6 +52,7 @@ #endif // WITH_SELINUX #define MAX_MOUNT_TIME 500 // 500us +#define LOCK_STATUS_SIZE 16 #define DEV_SHM_DIR "/dev/shm/" using namespace std; @@ -1856,30 +1857,20 @@ int32_t SetAppSandboxProperty(AppSpawnMgr *content, AppSpawningCtx *property) #define DIR_MODE 0711 #ifndef APPSPAWN_SANDBOX_NEW -static bool IsUnlockStatus(uint32_t uid, const char *bundleName, size_t bundleNameLen) +static bool IsUnlockStatus(uint32_t uid) { const int userIdBase = 200000; uid = uid / userIdBase; if (uid == 0) { return true; } - - const char rootPath[] = "/data/app/el2/"; - const char basePath[] = "/base/"; - size_t allPathSize = strlen(rootPath) + strlen(basePath) + 1 + USER_ID_SIZE + bundleNameLen; - char *path = reinterpret_cast(malloc(sizeof(char) * allPathSize)); - APPSPAWN_CHECK(path != NULL, return true, "Failed to malloc path"); - int len = sprintf_s(path, allPathSize, "%s%u%s%s", rootPath, uid, basePath, bundleName); - APPSPAWN_CHECK(len > 0 && ((size_t)len < allPathSize), free(path); - return true, "Failed to get base path"); - - if (access(path, F_OK) == 0) { - APPSPAWN_LOGI("this is unlock status"); - free(path); + string lockStatusParam = "startup.appspawn.lockstatus_" + to_string(uid); + char userLockStatus[LOCK_STATUS_SIZE] = {0}; + int ret = GetParameter(lockStatusParam.c_str(), "1", userLockStatus, sizeof(userLockStatus)); + APPSPAWN_LOGI("get param %{public}s %{public}s", lockStatusParam.c_str(), userLockStatus); + if (ret > 0 && (strcmp(userLockStatus, "0") == 0)) { // 0:解密状态 1:加密状态 return true; } - free(path); - APPSPAWN_LOGI("this is lock status"); return false; } @@ -2085,8 +2076,7 @@ static void MountDirToShared(const AppSpawningCtx *property) string sourcePath = "/data/app/el1/bundle/public/" + string(bundleName); MountDir(property, rootPath, sourcePath.c_str(), el1Path); - size_t bundleNameLen = strlen(bundleName); - if (IsUnlockStatus(info->uid, bundleName, bundleNameLen)) { + if (IsUnlockStatus(info->uid)) { return; } @@ -2114,8 +2104,10 @@ static void MountDirToShared(const AppSpawningCtx *property) static int SpawnMountDirToShared(AppSpawnMgr *content, AppSpawningCtx *property) { #ifndef APPSPAWN_SANDBOX_NEW - // mount dynamic directory - MountDirToShared(property); + if (!IsNWebSpawnMode(content)) { + // mount dynamic directory + MountDirToShared(property); + } #endif return 0; } diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index d39ac7fb..78629127 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -50,8 +50,11 @@ #define PATH_SIZE 256 #define FD_PATH_SIZE 128 #define MAX_MEM_SIZE (4 * 1024) -#define APPSPAWN_MSG_USER_CHECK_COUNT 3 +#define APPSPAWN_MSG_USER_CHECK_COUNT 4 #define PREFORK_PROCESS "apppool" +#define USER_ID_MIN_VALUE 100 +#define USER_ID_MAX_VALUE 10736 +#define LOCK_STATUS_PARAM_SIZE 64 #ifndef PIDFD_NONBLOCK #define PIDFD_NONBLOCK O_NONBLOCK #endif @@ -336,6 +339,7 @@ APPSPAWN_STATIC bool OnConnectionUserCheck(uid_t uid) 0, // root 0 3350, // app_fwk_update 3350 5523, // foundation 5523 + 1090, //storage_manager 1090 }; for (int i = 0; i < APPSPAWN_MSG_USER_CHECK_COUNT; i++) { @@ -1620,6 +1624,35 @@ APPSPAWN_STATIC int ProcessAppSpawnDeviceDebugMsg(AppSpawnMsgNode *message) return result; } +static void ProcessAppSpawnLockStatusMsg(AppSpawnMsgNode *message) +{ + APPSPAWN_CHECK_ONLY_EXPER(message != NULL, return); + uint32_t len = 0; + char *lockstatus = (char *)GetAppSpawnMsgExtInfo(message, "lockstatus", &len); + APPSPAWN_CHECK(lockstatus != NULL, return, "failed to get lockstatus"); + APPSPAWN_LOGI("appspawn get lockstatus %{public}s from storage_manager", lockstatus); + char *userLockStatus = NULL; + // userLockStatus format example: 100:0 100代表userid,0代表data分区加解密状态(0:解密状态 1:加密状态) + char *userIdStr = strtok_r(lockstatus, ":", &userLockStatus); + APPSPAWN_CHECK(userIdStr != NULL && userLockStatus != NULL, return, + "lockstatus not satisfied format, failed to get userLockStatus"); + int userId = atoi(userIdStr); + if (userId < USER_ID_MIN_VALUE || userId > USER_ID_MAX_VALUE) { + APPSPAWN_LOGE("userId err %{public}s", userIdStr); + return; + } + if (strcmp(userLockStatus, "0") != 0 && strcmp(userLockStatus, "1") != 0) { + APPSPAWN_LOGE("userLockStatus err %{public}s", userLockStatus); + return; + } + char lockStatusParam[LOCK_STATUS_PARAM_SIZE] = {0}; + int ret = snprintf_s(lockStatusParam, sizeof(lockStatusParam), sizeof(lockStatusParam) - 1, + "startup.appspawn.lockstatus_%d", userId); + APPSPAWN_CHECK(ret > 0, return, "get lock status param failed, errno %{public}d", errno); + ret = SetParameter(lockStatusParam, userLockStatus); + APPSPAWN_CHECK(ret == 0, return, "failed to set lockstatus param value ret %{public}d", ret); +} + static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) { AppSpawnMsg *msg = &message->msgHeader; @@ -1672,6 +1705,11 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess case MSG_UNINSTALL_DEBUG_HAP: ProcessUninstallDebugHap(connection, message); break; + case MSG_LOCK_STATUS: + ProcessAppSpawnLockStatusMsg(message); + SendResponse(connection, msg, 0, 0); + DeleteAppSpawnMsg(message); + break; default: SendResponse(connection, msg, APPSPAWN_MSG_INVALID, 0); DeleteAppSpawnMsg(message); -- Gitee From dc09a9ba1d2030ebb9693918e335214f74faa8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Mon, 9 Dec 2024 15:35:06 +0800 Subject: [PATCH 074/148] =?UTF-8?q?appspawn=E8=A7=A3=E8=80=A6=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=A0=81=E5=85=BC=E5=AE=B9=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- service/hnp/BUILD.gn | 3 ++- test/unittest/hnp_test/BUILD.gn | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/service/hnp/BUILD.gn b/service/hnp/BUILD.gn index 89e48e85..d2f675ea 100644 --- a/service/hnp/BUILD.gn +++ b/service/hnp/BUILD.gn @@ -44,7 +44,8 @@ if (!defined(ohos_lite)) { defines = [] if (defined(global_parts_info) && - defined(global_parts_info.security_code_signature)) { + defined(global_parts_info.security_code_signature) && + appspawn_support_code_signature) { defines += [ "CODE_SIGNATURE_ENABLE" ] } install_enable = true diff --git a/test/unittest/hnp_test/BUILD.gn b/test/unittest/hnp_test/BUILD.gn index af235c35..7855c298 100644 --- a/test/unittest/hnp_test/BUILD.gn +++ b/test/unittest/hnp_test/BUILD.gn @@ -56,11 +56,14 @@ if (!defined(ohos_lite)) { external_deps = [ "bounds_checking_function:libsec_shared", "cJSON:cjson", - "code_signature:libcode_sign_utils", "hilog:libhilog", "init:libbegetutil", "selinux_adapter:librestorecon", "zlib:shared_libz", ] + + if (appspawn_support_code_signature) { + external_deps += [ "code_signature:libcode_sign_utils" ] + } } } -- Gitee From 09968922660ccab0b4e2dcf58b6e84d54a6ed6d5 Mon Sep 17 00:00:00 2001 From: whoselittlelion Date: Mon, 9 Dec 2024 20:39:49 +0800 Subject: [PATCH 075/148] add hisysevent Signed-off-by: whoselittlelion --- bundle.json | 1 + hisysevent.yaml | 27 +++ modules/sandbox/BUILD.gn | 6 + modules/sandbox/sandbox_utils.cpp | 3 + modules/sysevent/hisysevent_adapter.cpp | 156 ++++++++++++++++++ modules/sysevent/hisysevent_adapter.h | 102 ++++++++++++ standard/BUILD.gn | 15 +- standard/appspawn_appmgr.c | 6 + standard/appspawn_manager.h | 6 + standard/appspawn_service.c | 32 +++- .../unittest/app_spawn_standard_test/BUILD.gn | 1 + 11 files changed, 350 insertions(+), 5 deletions(-) create mode 100644 hisysevent.yaml create mode 100644 modules/sysevent/hisysevent_adapter.cpp create mode 100644 modules/sysevent/hisysevent_adapter.h diff --git a/bundle.json b/bundle.json index a0608e6a..878786fa 100644 --- a/bundle.json +++ b/bundle.json @@ -31,6 +31,7 @@ "rom": "296KB", "ram": "13125KB", "hisysevent_config": [ + "//base/startup/appspawn/hisysevent.yaml", "//base/startup/appspawn/startup_events.yaml" ], "deps": { diff --git a/hisysevent.yaml b/hisysevent.yaml new file mode 100644 index 00000000..38bcc464 --- /dev/null +++ b/hisysevent.yaml @@ -0,0 +1,27 @@ +# 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. + +domain: APPSPAWN + +SPAWN_CHILD_PROCESS_FAIL: + __BASE: {type: FAULT, level: CRITICAL, desc: Spawn Child Process Fail} + PROCESS_NAME: {type: STRING, desc: Process Name} + ERROR_CODE: {type: INT32, desc: Error Code} + +SPAWN_PROCESS_DURATION: + __BASE: {type: STATISTIC, level: CRITICAL, desc: Boot Process Duration} + MAXDURATION: {type: INT64, desc: Max Spawn Process Duration} + MINDURATION: {type: INT64, desc: Min Spawn Process Duration} + TOTALDURATION: {type: INT64, desc: Total Spawn Process Duration} + EVENTCOUNT: {type: INT64, desc: Total Spawn Process Count} + STAGE: {type: STRING, desc: Boot Stage Or BootFinished Stage} \ No newline at end of file diff --git a/modules/sandbox/BUILD.gn b/modules/sandbox/BUILD.gn index ad320a82..279ffdb0 100644 --- a/modules/sandbox/BUILD.gn +++ b/modules/sandbox/BUILD.gn @@ -114,6 +114,12 @@ if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) { external_deps += [ "selinux_adapter:librestorecon" ] } } + if (appspawn_report_event) { + defines += [ "APPSPAWN_HISYSEVENT" ] + external_deps += [ "hisysevent:libhisysevent" ] + include_dirs += [ "${appspawn_path}/modules/sysevent" ] + sources += [ "${appspawn_path}/modules/sysevent/hisysevent_adapter.cpp" ] + } subsystem_name = "${subsystem_name}" part_name = "${part_name}" diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 3adb954f..e7d1a35a 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -43,6 +43,9 @@ #include "parameter.h" #include "parameters.h" #include "securec.h" +#ifdef APPSPAWN_HISYSEVENT +#include "hisysevent_adapter.h" +#endif #ifdef WITH_SELINUX #include "hap_restorecon.h" diff --git a/modules/sysevent/hisysevent_adapter.cpp b/modules/sysevent/hisysevent_adapter.cpp new file mode 100644 index 00000000..323ec1ae --- /dev/null +++ b/modules/sysevent/hisysevent_adapter.cpp @@ -0,0 +1,156 @@ +/* + * 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 "hisysevent_adapter.h" +#include "securec.h" +#include "hisysevent.h" +#include "appspawn_utils.h" + +using namespace OHOS::HiviewDFX; +namespace { +// event +constexpr const char* SPAWN_PROCESS_DURATION = "SPAWN_PROCESS_DURATION"; +constexpr const char* SPAWN_CHILD_PROCESS_FAIL = "SPAWN_CHILD_PROCESS_FAIL"; + +// param +constexpr const char* PROCESS_NAME = "PROCESS_NAME"; +constexpr const char* ERROR_CODE = "ERROR_CODE"; +constexpr const char* MAXDURATION = "MAXDURATION"; +constexpr const char* MINDURATION = "MINDURATION"; +constexpr const char* TOTALDURATION = "TOTALDURATION"; +constexpr const char* EVENTCOUNT = "EVENTCOUNT"; +constexpr const char* STAGE = "STAGE"; +constexpr const char* BOOTSTAGE = "BOOTSTAGE"; +constexpr const char* BOOTFINISHEDSTAGE = "BOOTFINISHEDSTAGE"; +} + +static void AddStatisticEvent(AppSpawnHisysevent *event, uint32_t duration) +{ + event->eventCount++; + event->totalDuration += duration; + if (duration > event->maxDuration) { + event->maxDuration = duration; + } + if (duration < event->minDuration) { + event->minDuration = duration; + } + APPSPAWN_LOGV("event->maxDuration is: %{public}d, event->minDuration is: %{public}d", + event->maxDuration, event->minDuration); +} + +void AddStatisticEventInfo(AppSpawnHisyseventInfo *hisyseventInfo, uint32_t duration, bool stage) +{ + APPSPAWN_CHECK(hisyseventInfo != NULL, return, "fail to get AppSpawnHisyseventInfo"); + if (stage) { + AddStatisticEvent(&hisyseventInfo->bootEvent, duration); + } else { + AddStatisticEvent(&hisyseventInfo->manualEvent, duration); + } +} + +static void InitStatisticEvent(AppSpawnHisysevent *event) +{ + event->eventCount = 0; + event->maxDuration = 0; + event->minDuration = UINT32_MAX; + event->totalDuration = 0; +} + +static void InitStatisticEventInfo(AppSpawnHisyseventInfo *appSpawnHisysInfo) +{ + InitStatisticEvent(&appSpawnHisysInfo->bootEvent); + InitStatisticEvent(&appSpawnHisysInfo->manualEvent); +} + +static int CreateHisysTimerLoop(AppSpawnHisyseventInfo *hisyseventInfo) +{ + LoopHandle loop = LE_GetDefaultLoop(); + TimerHandle timer = NULL; + int ret = LE_CreateTimer(loop, &timer, ReportSpawnStatisticDuration, (void *)hisyseventInfo); + APPSPAWN_CHECK(ret == 0, return -1, "fail to create HisysTimer, ret is: %{public}d", ret); + // start a timer to report event every 24h + ret = LE_StartTimer(loop, timer, APPSPAWN_HISYSEVENT_REPORT_TIME, INT64_MAX); + APPSPAWN_CHECK(ret == 0, return -1, "fail to start HisysTimer, ret is: %{public}d", ret); + return ret; +} + +AppSpawnHisyseventInfo *GetAppSpawnHisyseventInfo() +{ + AppSpawnHisyseventInfo *hisyseventInfo = + static_cast(malloc(sizeof(AppSpawnHisyseventInfo))); + APPSPAWN_CHECK(hisyseventInfo != NULL, return NULL, "fail to alloc memory for hisyseventInfo"); + int ret = memset_s(hisyseventInfo, sizeof(AppSpawnHisyseventInfo), 0, sizeof(AppSpawnHisyseventInfo)); + if (ret != 0) { + free(hisyseventInfo); + hisyseventInfo = NULL; + APPSPAWN_LOGE("Failed to memset hisyseventInfo"); + return NULL; + } + InitStatisticEventInfo(hisyseventInfo); + return hisyseventInfo; +} + +void DeleteHisyseventInfo(AppSpawnHisyseventInfo *hisyseventInfo) +{ + APPSPAWN_CHECK_ONLY_EXPER(hisyseventInfo != NULL, return); + free(hisyseventInfo); + hisyseventInfo = NULL; +} + +AppSpawnHisyseventInfo *InitHisyseventTimer() +{ + AppSpawnHisyseventInfo *hisyseventInfo = GetAppSpawnHisyseventInfo(); + APPSPAWN_CHECK(hisyseventInfo != NULL, return NULL, "fail to init hisyseventInfo"); + int ret = CreateHisysTimerLoop(hisyseventInfo); + if (ret != 0) { + DeleteHisyseventInfo(hisyseventInfo); + hisyseventInfo = NULL; + APPSPAWN_LOGE("fail to create hisys timer loop, ret: %{public}d", ret); + } + return hisyseventInfo; +} + +void ReportSpawnChildProcessFail(const char* processName, int32_t errorCode) +{ + int ret = HiSysEventWrite(HiSysEvent::Domain::APPSPAWN, SPAWN_CHILD_PROCESS_FAIL, + HiSysEvent::EventType::FAULT, + PROCESS_NAME, processName, + ERROR_CODE, errorCode); + if (ret != 0) { + APPSPAWN_LOGE("HiSysEventWrite error, ret: %{public}d", ret); + } +} + +void ReportSpawnProcessDuration(AppSpawnHisysevent *hisysevent, const char* stage) +{ + int ret = HiSysEventWrite(HiSysEvent::Domain::APPSPAWN, SPAWN_PROCESS_DURATION, + HiSysEvent::EventType::STATISTIC, + MAXDURATION, hisysevent->maxDuration, + MINDURATION, hisysevent->minDuration, + TOTALDURATION, hisysevent->totalDuration, + EVENTCOUNT, hisysevent->eventCount, + STAGE, stage); + if (ret != 0) { + APPSPAWN_LOGE("HiSysEventWrite error, ret: %{public}d", ret); + } +} + +void ReportSpawnStatisticDuration(const TimerHandle taskHandle, void *content) +{ + AppSpawnHisyseventInfo *hisyseventInfo = static_cast(content); + ReportSpawnProcessDuration(&hisyseventInfo->bootEvent, BOOTSTAGE); + ReportSpawnProcessDuration(&hisyseventInfo->manualEvent, BOOTFINISHEDSTAGE); + + InitStatisticEventInfo(hisyseventInfo); +} \ No newline at end of file diff --git a/modules/sysevent/hisysevent_adapter.h b/modules/sysevent/hisysevent_adapter.h new file mode 100644 index 00000000..649842a3 --- /dev/null +++ b/modules/sysevent/hisysevent_adapter.h @@ -0,0 +1,102 @@ +/* + * 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. + */ + +#ifndef APPSPAWN_HISYSEVENT_ADAPTER_H +#define APPSPAWN_HISYSEVENT_ADAPTER_H + +#include "appspawn_utils.h" +#include "loop_event.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +// 错误码定义规范:子系统ID(28-21位)| 模块ID(20-16位)| 具体错误ID(15-0位) +#define APPSPAWN_HISYSEVENT_REPORT_TIME (24 * 60 * 60 * 1000) // 24h +#define SUBSYS_STARTUP_ID 39 +#define SUBSYSTEM_BIT_NUM 21 +#define MODULE_BIT_NUM 16 +#define ERR_MODULE_APPSPAWN 0x00 +#define ERR_MODULE_INIT 0x10 +#define ERR_APPSPAWN_BASE ((SUBSYS_STARTUP_ID << SUBSYSTEM_BIT_NUM) | (ERR_MODULE_APPSPAWN << MODULE_BIT_NUM)) +#define ERR_INIT_BASE ((SUBSYS_STARTUP_ID << SUBSYSTEM_BIT_NUM) | (ERR_MODULE_INIT << MODULE_BIT_NUM)) + +typedef enum { + // errcode for handle msg, reserved 128, 0x0001-0x0080 + ERR_APPSPAWN_MSG_TOO_LONG = ERR_APPSPAWN_BASE + 0x0001, // 81788929 + ERR_APPSPAWN_MSG_INVALID_HANDLE, + ERR_APPSPAWN_MSG_CREATE_MSG_FAILED, + ERR_APPSPAWN_COPY_MSG_FAILED, + ERR_APPSPAWN_ALLOC_MEMORY_FAILED, + ERR_APPSPAWN_MSG_DECODE_MSG_FAILED, + + // errcode for hnp, reserved 128, 0x0081 - 0x0100 + ERR_APPSPAWN_HNP = ERR_APPSPAWN_BASE + 0x0081, + + // errcode for device_dug, reserved 128, 0x0101 - 0x0180 + ERR_APPSPAWN_DEVICE_DUG = ERR_APPSPAWN_BASE + 0x0101, + + // errcode for process_exit, reserved 128, 0x0181 - 0x0200 + ERR_APPSPAWN_PROCESS_EXIT = ERR_APPSPAWN_BASE + 0x0181, + + // errcode for prefork, reserved 128, 0x0201 - 0x0280 + ERR_APPSPAWN_PREFORK = ERR_APPSPAWN_BASE + 0x0201, + + // errcode for sandbox, reserved 128, 0x0281 - 0x0300 + ERR_APPSPAWN_SANDBOX = ERR_APPSPAWN_BASE + 0x0281, + + // errcode for set permission, reserved 128, 0x0301 - 0x0380 + ERR_APPSPAWN_SET_PERMISSION = ERR_APPSPAWN_BASE + 0x0301, + ERR_APPSPAWN_SET_INTE_PERMISSION_FAIL, + ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_KEEP_CAP_FAIL, + ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_XPM_FAIL, + ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_PROCESSNAME_FAIL, + ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_UIDGID_FAIL, + ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_FD_FAIL, + ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_CAP_FAIL, + ERR_APPSPAWN_SET_PROPERTIES_FAIL_SET_SELINUXCON_FAIL, + + // errorcode for spawn child process fail, reserved 128, 0x0381 - 0x0400 + ERR_APPSPAWN_SPAWN_FAIL = ERR_APPSPAWN_BASE + 0x0381, + ERR_APPSPAWN_SPAWN_TIMEOUT, + ERR_APPSPAWN_CHILD_CRASH, + ERR_APPSPAWN_MAX_FAILURES_EXCEEDED, +} AppSpawnHisysErrorCode; + +typedef struct { + uint32_t eventCount; + uint32_t maxDuration; + uint32_t minDuration; + uint32_t totalDuration; +} AppSpawnHisysevent; + +typedef struct { + AppSpawnHisysevent bootEvent; // bootStage + AppSpawnHisysevent manualEvent; // bootFinished +} AppSpawnHisyseventInfo; + +AppSpawnHisyseventInfo *InitHisyseventTimer(); +AppSpawnHisyseventInfo *GetAppSpawnHisyseventInfo(); +void AddStatisticEventInfo(AppSpawnHisyseventInfo *hisyseventInfo, uint32_t duration, bool stage); +void DeleteHisyseventInfo(AppSpawnHisyseventInfo *hisyseventInfo); + +void ReportSpawnChildProcessFail(const char* processName, int32_t errorCode); +void ReportSpawnStatisticDuration(const TimerHandle taskHandle, void* content); + +#ifdef __cplusplus +} +#endif +#endif // APPSPAWN_HISYSEVENT_ADAPTER_H \ No newline at end of file diff --git a/standard/BUILD.gn b/standard/BUILD.gn index 44263767..06e35539 100644 --- a/standard/BUILD.gn +++ b/standard/BUILD.gn @@ -87,7 +87,10 @@ ohos_executable("appspawn") { if (appspawn_report_event) { defines += [ "APPSPAWN_HISYSEVENT" ] external_deps += [ "hisysevent:libhisysevent" ] - sources += [ "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp" ] + sources += [ + "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp", + "${appspawn_path}/modules/sysevent/hisysevent_adapter.cpp", + ] } if (build_selinux) { defines += [ "WITH_SELINUX" ] @@ -195,7 +198,10 @@ ohos_executable("cjappspawn") { if (appspawn_report_event) { defines += [ "APPSPAWN_HISYSEVENT" ] external_deps += [ "hisysevent:libhisysevent" ] - sources += [ "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp" ] + sources += [ + "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp", + "${appspawn_path}/modules/sysevent/hisysevent_adapter.cpp", + ] } if (build_selinux) { defines += [ "WITH_SELINUX" ] @@ -267,7 +273,10 @@ ohos_executable("nativespawn") { if (appspawn_report_event) { defines += [ "APPSPAWN_HISYSEVENT" ] external_deps += [ "hisysevent:libhisysevent" ] - sources += [ "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp" ] + sources += [ + "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp", + "${appspawn_path}/modules/sysevent/hisysevent_adapter.cpp", + ] } if (build_selinux) { defines += [ "WITH_SELINUX" ] diff --git a/standard/appspawn_appmgr.c b/standard/appspawn_appmgr.c index 248d5df7..d538192c 100644 --- a/standard/appspawn_appmgr.c +++ b/standard/appspawn_appmgr.c @@ -55,6 +55,9 @@ AppSpawnMgr *CreateAppSpawnMgr(int mode) appMgr->servicePid = getpid(); appMgr->server = NULL; appMgr->sigHandler = NULL; +#ifdef APPSPAWN_HISYSEVENT + appMgr->hisyseventInfo = NULL; +#endif OH_ListInit(&appMgr->appQueue); OH_ListInit(&appMgr->diedQueue); OH_ListInit(&appMgr->appSpawnQueue); @@ -98,6 +101,9 @@ void DeleteAppSpawnMgr(AppSpawnMgr *mgr) OH_ListRemoveAll(&mgr->diedQueue, NULL); OH_ListRemoveAll(&mgr->appSpawnQueue, SpawningQueueDestroy); OH_ListRemoveAll(&mgr->extData, ExtDataDestroy); +#ifdef APPSPAWN_HISYSEVENT + DeleteHisyseventInfo(mgr->hisyseventInfo); +#endif APPSPAWN_LOGV("DeleteAppSpawnMgr %{public}d %{public}d", mgr->servicePid, getpid()); free(mgr); diff --git a/standard/appspawn_manager.h b/standard/appspawn_manager.h index 9c78948c..5c5280ac 100644 --- a/standard/appspawn_manager.h +++ b/standard/appspawn_manager.h @@ -27,6 +27,9 @@ #include "appspawn_utils.h" #include "list.h" #include "loop_event.h" +#ifdef APPSPAWN_HISYSEVENT +#include "hisysevent_adapter.h" +#endif #ifdef __cplusplus extern "C" { @@ -120,6 +123,9 @@ typedef struct TagAppSpawnMgr { struct timespec perLoadEnd; struct ListNode extData; struct SpawnTime spawnTime; +#ifdef APPSPAWN_HISYSEVENT + AppSpawnHisyseventInfo *hisyseventInfo; +#endif } AppSpawnMgr; /** diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 30f6512e..d5cd01c0 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -45,6 +45,7 @@ #include "cJSON.h" #ifdef APPSPAWN_HISYSEVENT #include "appspawn_hisysevent.h" +#include "hisysevent_adapter.h" #endif #define PARAM_BUFFER_SIZE 10 #define PATH_SIZE 256 @@ -929,9 +930,13 @@ static uint32_t g_crashTimes = 0; static void WaitChildDied(pid_t pid) { AppSpawningCtx *property = GetAppSpawningCtxByPid(pid); - if (property != NULL && property->state == APP_STATE_SPAWNING) { + if (property != NULL && property->message != NULL && property->state == APP_STATE_SPAWNING) { + const char *processName = GetProcessName(property); APPSPAWN_LOGI("Child process %{public}s fail \'child crash \'pid %{public}d appId: %{public}d", - GetProcessName(property), property->pid, property->client.id); + processName, property->pid, property->client.id); +#ifdef APPSPAWN_HISYSEVENT + ReportSpawnChildProcessFail(processName, ERR_APPSPAWN_CHILD_CRASH); +#endif if (property->client.id == g_lastDiedAppId + 1) { g_crashTimes++; } else { @@ -944,6 +949,9 @@ static void WaitChildDied(pid_t pid) if (g_crashTimes >= MAX_CRASH_TIME) { APPSPAWN_LOGW("Continuous failures in spawning the app, restart appspawn"); +#ifdef APPSPAWN_HISYSEVENT + ReportSpawnChildProcessFail(processName, ERR_APPSPAWN_MAX_FAILURES_EXCEEDED); +#endif StopAppSpawn(); } } @@ -960,6 +968,9 @@ static void WaitChildTimeout(const TimerHandle taskHandle, void *context) #endif kill(property->pid, SIGKILL); } +#ifdef APPSPAWN_HISYSEVENT + ReportSpawnChildProcessFail(GetProcessName(property), ERR_APPSPAWN_SPAWN_TIMEOUT); +#endif SendResponse(property->message->connection, &property->message->msgHeader, APPSPAWN_SPAWN_TIMEOUT, 0); DeleteAppSpawningCtx(property); } @@ -973,6 +984,9 @@ static int ProcessChildFdCheck(int fd, AppSpawningCtx *property) APPSPAWN_CHECK(property->message != NULL, return -1, "Invalid message in ctx %{public}d", property->client.id); if (result != 0) { +#ifdef APPSPAWN_HISYSEVENT + ReportSpawnChildProcessFail(GetProcessName(property), ERR_APPSPAWN_SPAWN_FAIL); +#endif SendResponse(property->message->connection, &property->message->msgHeader, result, property->pid); DeleteAppSpawningCtx(property); return -1; @@ -1007,6 +1021,17 @@ static void ProcessChildResponse(const WatcherHandle taskHandle, int fd, uint32_ clock_gettime(CLOCK_MONOTONIC, &appInfo->spawnEnd); // add max info } + +#ifdef APPSPAWN_HISYSEVENT + //add process spawn duration into hisysevent,(ms) + uint32_t spawnProcessDuration = (appInfo->spawnEnd.tv_sec - appInfo->spawnStart.tv_sec) * (APPSPAWN_USEC_TO_NSEC) + + (uint32_t)((appInfo->spawnEnd.tv_nsec - appInfo->spawnStart.tv_nsec)/(APPSPAWN_MSEC_TO_NSEC)); + AppSpawnMgr *appspawnMgr = GetAppSpawnMgr(); + if (appspawnMgr != NULL) { + AddStatisticEventInfo(appspawnMgr->hisyseventInfo, spawnProcessDuration, IsBootFinished()); + } +#endif + WatchChildProcessFd(property); ProcessMgrHookExecute(STAGE_SERVER_APP_ADD, GetAppSpawnContent(), appInfo); // response @@ -1254,6 +1279,9 @@ AppSpawnContent *AppSpawnCreateContent(const char *socketName, char *longProcNam AppSpawnMgr *appSpawnContent = CreateAppSpawnMgr(mode); APPSPAWN_CHECK(appSpawnContent != NULL, return NULL, "Failed to alloc memory for appspawn"); +#ifdef APPSPAWN_HISYSEVENT + appSpawnContent->hisyseventInfo = InitHisyseventTimer(); +#endif appSpawnContent->content.longProcName = longProcName; appSpawnContent->content.longProcNameLen = nameLen; appSpawnContent->content.notifyResToParent = NotifyResToParent; diff --git a/test/unittest/app_spawn_standard_test/BUILD.gn b/test/unittest/app_spawn_standard_test/BUILD.gn index ae2b9d8e..e12873c2 100644 --- a/test/unittest/app_spawn_standard_test/BUILD.gn +++ b/test/unittest/app_spawn_standard_test/BUILD.gn @@ -203,6 +203,7 @@ ohos_unittest("AppSpawn_ut") { sources += [ "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp", "${appspawn_path}/modules/sysevent/event_reporter.cpp", + "${appspawn_path}/modules/sysevent/hisysevent_adapter.cpp", ] } -- Gitee From 3c723740dd459a87e55dbf679f86e9f7dcd600c2 Mon Sep 17 00:00:00 2001 From: yuchen Date: Tue, 10 Dec 2024 14:53:06 +0800 Subject: [PATCH 076/148] add gpu vulkan Signed-off-by: yuchen --- appdata-sandbox.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appdata-sandbox.json b/appdata-sandbox.json index e32af653..b7a2fda7 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -615,7 +615,7 @@ "check-action-status": "false" }, { "src-path" : "/vendor/etc/vulkan/icd.d", - "sandbox-path" : "/vendor/etc/vulkan/icd.d", + "sandbox-path" : "/system/etc/vulkan/icd.d", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { -- Gitee From 6c47947dbf6442d07eb806ec495de5a16aae2f98 Mon Sep 17 00:00:00 2001 From: mengguo Date: Tue, 10 Dec 2024 15:59:28 +0800 Subject: [PATCH 077/148] =?UTF-8?q?Revert=20"!1757=20=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E8=AE=BE=E7=BD=AEMCS=E6=A0=87=E7=AD=BE"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit ae79473850456bd513cdbfe6802b0d551ddb6c70, reversing changes made to 69df0929bebcf49e2e6362a82bd91740dc7d5528. Signed-off-by: mengguo --- modules/common/appspawn_adapter.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/common/appspawn_adapter.cpp b/modules/common/appspawn_adapter.cpp index 2a4b6aa5..74ea6d78 100644 --- a/modules/common/appspawn_adapter.cpp +++ b/modules/common/appspawn_adapter.cpp @@ -106,13 +106,11 @@ int SetSelinuxCon(const AppSpawnMgr *content, const AppSpawningCtx *property) reinterpret_cast(GetAppProperty(property, TLV_DOMAIN_INFO)); APPSPAWN_CHECK(msgDomainInfo != NULL, return APPSPAWN_TLV_NONE, "No domain info in req form %{public}s", GetProcessName(property)); - AppDacInfo *appInfo = reinterpret_cast(GetAppProperty(property, TLV_DAC_INFO)); HapContext hapContext; HapDomainInfo hapDomainInfo; hapDomainInfo.apl = msgDomainInfo->apl; hapDomainInfo.packageName = GetBundleName(property); hapDomainInfo.hapFlags = msgDomainInfo->hapFlags; - hapDomainInfo.uid = appInfo == NULL ? 0 : appInfo->uid; //The value of 0 is invalid. Its purpose is to initialize. if (CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE)) { hapDomainInfo.hapFlags |= SELINUX_HAP_DEBUGGABLE; } -- Gitee From 0afaaba1dbe286607352162a38194d5f4b2e292f Mon Sep 17 00:00:00 2001 From: lwx1281857 Date: Tue, 10 Dec 2024 20:41:21 +0800 Subject: [PATCH 078/148] Description: Code optimization Feature or Bugfix: Bugfix Binary Source:No Signed-off-by: lwx1281857 --- standard/appspawn_kickdog.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/standard/appspawn_kickdog.c b/standard/appspawn_kickdog.c index 00da55ac..7223bab4 100644 --- a/standard/appspawn_kickdog.c +++ b/standard/appspawn_kickdog.c @@ -66,8 +66,6 @@ static const char *GetProcContent(bool isLinux, bool isOpen, int mode) static void DealSpawnWatchdog(AppSpawnContent *content, bool isOpen) { - APPSPAWN_LOGI("%{public}s %{public}s watchdog begin", - (content->mode == MODE_FOR_NWEB_SPAWN) ? "Nwebspawn" : "Appspawn", isOpen ? "enable" : "kick"); int result = 0; const char *procFile = GetProcFile(content->isLinux); const char *procContent = GetProcContent(content->isLinux, isOpen, content->mode); -- Gitee From a9a31c079b013f0ed8468e209fd6f7405f72f689 Mon Sep 17 00:00:00 2001 From: yh Date: Wed, 11 Dec 2024 16:59:10 +0800 Subject: [PATCH 079/148] add log Signed-off-by: yh Change-Id: Icba1036a94429c3783440b22104d0a4a3999c5fe --- standard/appspawn_appmgr.c | 1 + standard/appspawn_service.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/standard/appspawn_appmgr.c b/standard/appspawn_appmgr.c index d538192c..e0615cc1 100644 --- a/standard/appspawn_appmgr.c +++ b/standard/appspawn_appmgr.c @@ -323,6 +323,7 @@ void DeleteAppSpawningCtx(AppSpawningCtx *property) property->forkCtx.timer = NULL; } if (property->forkCtx.watcherHandle) { + APPSPAWN_LOGI("start clear watcher handle"); LE_RemoveWatcher(LE_GetDefaultLoop(), property->forkCtx.watcherHandle); property->forkCtx.watcherHandle = NULL; } diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index d5cd01c0..0dd61266 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -620,13 +620,13 @@ static int AddChildWatcher(AppSpawningCtx *property) { uint32_t defTimeout = IsChildColdRun(property) ? COLD_CHILD_RESPONSE_TIMEOUT : WAIT_CHILD_RESPONSE_TIMEOUT; uint32_t timeout = GetSpawnTimeout(defTimeout); - APPSPAWN_LOGI("Get Spawn timeout %{public}u", timeout); LE_WatchInfo watchInfo = {}; watchInfo.fd = property->forkCtx.fd[0]; watchInfo.flags = WATCHER_ONCE; watchInfo.events = EVENT_READ; watchInfo.processEvent = ProcessChildResponse; LE_STATUS status = LE_StartWatcher(LE_GetDefaultLoop(), &property->forkCtx.watcherHandle, &watchInfo, property); + APPSPAWN_LOGI("AddChildWatcher with timeout %{public}u fd %{public}d", timeout, watchInfo.fd); APPSPAWN_CHECK(status == LE_SUCCESS, return APPSPAWN_SYSTEM_ERROR, "Failed to watch child %{public}d", property->pid); status = LE_CreateTimer(LE_GetDefaultLoop(), &property->forkCtx.timer, WaitChildTimeout, property); -- Gitee From 54788d1a89f912d891d4022c5a24899651b612fa Mon Sep 17 00:00:00 2001 From: yh Date: Thu, 12 Dec 2024 10:56:46 +0800 Subject: [PATCH 080/148] fix ut Signed-off-by: yh Change-Id: I48a5b8dd30b5586064c531aaa6689e205a744363 --- test/BUILD.gn | 2 + .../unittest/app_spawn_standard_test/BUILD.gn | 374 +++++++++++++++++- 2 files changed, 374 insertions(+), 2 deletions(-) diff --git a/test/BUILD.gn b/test/BUILD.gn index 25fcacb6..faf729d9 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -27,6 +27,8 @@ group("unittest") { deps = [ "unittest/app_spawn_client_test:AppSpawn_client_ut" ] if (!use_libfuzzer) { 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/hnp_test:HnpTest" ] deps += [ "unittest/devicedebug_test:DevicedebugTest" ] diff --git a/test/unittest/app_spawn_standard_test/BUILD.gn b/test/unittest/app_spawn_standard_test/BUILD.gn index e12873c2..da7ccf3a 100644 --- a/test/unittest/app_spawn_standard_test/BUILD.gn +++ b/test/unittest/app_spawn_standard_test/BUILD.gn @@ -132,9 +132,7 @@ ohos_unittest("AppSpawn_ut") { "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_beget_test.cpp", "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_cgroup_test.cpp", "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_child_test.cpp", - "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_cold_run_test.cpp", "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_command_lexer_test.cpp", - "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp", "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_kickdog_test.cpp", "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp", "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandboxmgr_test.cpp", @@ -217,3 +215,375 @@ ohos_unittest("AppSpawn_ut") { external_deps += [ "dlp_permission_service:libdlp_fuse" ] } } + +ohos_unittest("AppSpawn_coldrun_ut") { + module_out_path = "${module_output_path}" + 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_DEBUG", + "DEBUG_BEGETCTL_BOOT", + "USER_TIMER_TO_CHECK", + "OHOS_DEBUG", + "GRAPHIC_PERMISSION_CHECK", + "capset=CapsetStub", + "unshare=UnshareStub", + "mount=MountStub", + "symlink=SymlinkStub", + "chdir=ChdirStub", + "chroot=ChrootStub", + "syscall=SyscallStub", + "umount2=Umount2Stub", + "access=AccessStub", + "dlopen=DlopenStub", + "dlsym=DlsymStub", + "dlclose=DlcloseStub", + "execv=ExecvStub", + "getprocpid=GetprocpidStub", + "setgroups=SetgroupsStub", + "setresgid=SetresgidStub", + "setresuid=SetresuidStub", + "setuid=SetuidStub", + "setgid=SetgidStub", + "execvp=ExecvpStub", + "ioctl=IoctlStub", + "execve=ExecveStub", + "setcon=SetconStub", + ] + + include_dirs = [ + "${appspawn_path}", + "${appspawn_path}/common", + "${appspawn_path}/standard", + "${appspawn_path}/modules/modulemgr", + "${appspawn_path}/modules/ace_adapter", + "${appspawn_path}/modules/common", + "${appspawn_path}/modules/sandbox", + "${appspawn_path}/modules/sysevent", + "${appspawn_innerkits_path}/client", + "${appspawn_innerkits_path}/include", + "${appspawn_innerkits_path}/permission", + "${appspawn_path}/modules/module_engine/include", + "${appspawn_path}/test/mock", + "${appspawn_path}/test/unittest", + "${appspawn_path}/util/include", + ] + sources = [ + "${appspawn_path}/common/appspawn_server.c", + "${appspawn_path}/common/appspawn_trace.cpp", + "${appspawn_path}/modules/modulemgr/appspawn_modulemgr.c", + "${appspawn_path}/standard/appspawn_appmgr.c", + "${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", + ] + + # client + sources += [ + "${appspawn_innerkits_path}/client/appspawn_client.c", + "${appspawn_innerkits_path}/client/appspawn_msg.c", + "${appspawn_innerkits_path}/permission/appspawn_mount_permission.c", + ] + + # modules sources + sources += [ + "${appspawn_path}/modules/ace_adapter/ace_adapter.cpp", + "${appspawn_path}/modules/ace_adapter/command_lexer.cpp", + "${appspawn_path}/modules/common/appspawn_adapter.cpp", + "${appspawn_path}/modules/common/appspawn_begetctl.c", + "${appspawn_path}/modules/common/appspawn_cgroup.c", + "${appspawn_path}/modules/common/appspawn_common.c", + "${appspawn_path}/modules/common/appspawn_dfx_dump.cpp", + "${appspawn_path}/modules/common/appspawn_namespace.c", + "${appspawn_path}/modules/common/appspawn_silk.c", + "${appspawn_path}/modules/nweb_adapter/nwebspawn_adapter.cpp", + "${appspawn_path}/modules/sandbox/appspawn_mount_template.c", + "${appspawn_path}/modules/sandbox/appspawn_permission.c", + "${appspawn_path}/modules/sandbox/appspawn_sandbox.c", + "${appspawn_path}/modules/sandbox/sandbox_adapter.cpp", + "${appspawn_path}/modules/sandbox/sandbox_cfgvar.c", + "${appspawn_path}/modules/sandbox/sandbox_expand.c", + "${appspawn_path}/modules/sandbox/sandbox_load.c", + "${appspawn_path}/modules/sandbox/sandbox_manager.c", + ] + + if (appspawn_use_encaps == true) { + sources += [ "${appspawn_path}/modules/common/appspawn_encaps.c" ] + } + + # add stub + include_dirs += [ "${appspawn_path}/test/mock" ] + sources += [ + "${appspawn_path}/test/mock/app_spawn_stub.cpp", + "${appspawn_path}/test/mock/app_system_stub.c", + ] + + # add test + include_dirs += [ "${appspawn_path}/test/unittest" ] + sources += [ + "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_cold_run_test.cpp", + "${appspawn_path}/test/unittest/app_spawn_test_helper.cpp", + ] + + if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) { + defines += [ "APPSPAWN_SANDBOX_NEW" ] + } else { + sources += [ "${appspawn_path}/modules/sandbox/sandbox_utils.cpp" ] + } + + configs = [ "${appspawn_path}:appspawn_config" ] + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "ability_runtime:appkit_native", + "ability_runtime:runtime", + "access_token:libtokenid_sdk", + "access_token:libtokensetproc_shared", + "ace_engine:ace_forward_compatibility", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "cJSON:cjson", + "c_utils:utils", + "config_policy:configpolicy_util", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "init:seccomp", + "ipc:ipc_core", + "napi:ace_napi", + "os_account:os_account_innerkits", + "resource_management:global_resmgr", + ] + if (enable_appspawn_dump_catcher) { + external_deps += [ "faultloggerd:libdfx_dumpcatcher" ] + } + if (asan_detector || is_asan) { + defines += [ "ASAN_DETECTOR" ] + sources += [ "${appspawn_path}/modules/asan/asan_detector.c" ] + } + + 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 (target_cpu == "arm64" || target_cpu == "x86_64" || + target_cpu == "riscv64") { + defines += [ "APPSPAWN_64" ] + } + + if (dlp_permission_enable) { + cflags_cc = [ "-DWITH_DLP" ] + external_deps += [ "dlp_permission_service:libdlp_fuse" ] + } +} + +ohos_unittest("AppSpawn_common_ut") { + module_out_path = "${module_output_path}" + 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_DEBUG", + "DEBUG_BEGETCTL_BOOT", + "USER_TIMER_TO_CHECK", + "OHOS_DEBUG", + "GRAPHIC_PERMISSION_CHECK", + "capset=CapsetStub", + "unshare=UnshareStub", + "mount=MountStub", + "symlink=SymlinkStub", + "chdir=ChdirStub", + "chroot=ChrootStub", + "syscall=SyscallStub", + "umount2=Umount2Stub", + "access=AccessStub", + "dlopen=DlopenStub", + "dlsym=DlsymStub", + "dlclose=DlcloseStub", + "execv=ExecvStub", + "getprocpid=GetprocpidStub", + "setgroups=SetgroupsStub", + "setresgid=SetresgidStub", + "setresuid=SetresuidStub", + "setuid=SetuidStub", + "setgid=SetgidStub", + "execvp=ExecvpStub", + "ioctl=IoctlStub", + "execve=ExecveStub", + "setcon=SetconStub", + ] + + include_dirs = [ + "${appspawn_path}", + "${appspawn_path}/common", + "${appspawn_path}/standard", + "${appspawn_path}/modules/modulemgr", + "${appspawn_path}/modules/ace_adapter", + "${appspawn_path}/modules/common", + "${appspawn_path}/modules/sandbox", + "${appspawn_path}/modules/sysevent", + "${appspawn_innerkits_path}/client", + "${appspawn_innerkits_path}/include", + "${appspawn_innerkits_path}/permission", + "${appspawn_path}/modules/module_engine/include", + "${appspawn_path}/test/mock", + "${appspawn_path}/test/unittest", + "${appspawn_path}/util/include", + ] + sources = [ + "${appspawn_path}/common/appspawn_server.c", + "${appspawn_path}/common/appspawn_trace.cpp", + "${appspawn_path}/modules/modulemgr/appspawn_modulemgr.c", + "${appspawn_path}/standard/appspawn_appmgr.c", + "${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", + ] + + # client + sources += [ + "${appspawn_innerkits_path}/client/appspawn_client.c", + "${appspawn_innerkits_path}/client/appspawn_msg.c", + "${appspawn_innerkits_path}/permission/appspawn_mount_permission.c", + ] + + # modules sources + sources += [ + "${appspawn_path}/modules/ace_adapter/ace_adapter.cpp", + "${appspawn_path}/modules/ace_adapter/command_lexer.cpp", + "${appspawn_path}/modules/common/appspawn_adapter.cpp", + "${appspawn_path}/modules/common/appspawn_begetctl.c", + "${appspawn_path}/modules/common/appspawn_cgroup.c", + "${appspawn_path}/modules/common/appspawn_common.c", + "${appspawn_path}/modules/common/appspawn_dfx_dump.cpp", + "${appspawn_path}/modules/common/appspawn_namespace.c", + "${appspawn_path}/modules/common/appspawn_silk.c", + "${appspawn_path}/modules/nweb_adapter/nwebspawn_adapter.cpp", + "${appspawn_path}/modules/sandbox/appspawn_mount_template.c", + "${appspawn_path}/modules/sandbox/appspawn_permission.c", + "${appspawn_path}/modules/sandbox/appspawn_sandbox.c", + "${appspawn_path}/modules/sandbox/sandbox_adapter.cpp", + "${appspawn_path}/modules/sandbox/sandbox_cfgvar.c", + "${appspawn_path}/modules/sandbox/sandbox_expand.c", + "${appspawn_path}/modules/sandbox/sandbox_load.c", + "${appspawn_path}/modules/sandbox/sandbox_manager.c", + ] + + if (appspawn_use_encaps == true) { + sources += [ "${appspawn_path}/modules/common/appspawn_encaps.c" ] + } + + # add stub + include_dirs += [ "${appspawn_path}/test/mock" ] + sources += [ + "${appspawn_path}/test/mock/app_spawn_stub.cpp", + "${appspawn_path}/test/mock/app_system_stub.c", + ] + + # add test + include_dirs += [ "${appspawn_path}/test/unittest" ] + sources += [ + "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp", + "${appspawn_path}/test/unittest/app_spawn_test_helper.cpp", + ] + + if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) { + defines += [ "APPSPAWN_SANDBOX_NEW" ] + } else { + sources += [ "${appspawn_path}/modules/sandbox/sandbox_utils.cpp" ] + } + + configs = [ "${appspawn_path}:appspawn_config" ] + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "ability_runtime:appkit_native", + "ability_runtime:runtime", + "access_token:libtokenid_sdk", + "access_token:libtokensetproc_shared", + "ace_engine:ace_forward_compatibility", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "cJSON:cjson", + "c_utils:utils", + "config_policy:configpolicy_util", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "init:seccomp", + "ipc:ipc_core", + "napi:ace_napi", + "os_account:os_account_innerkits", + "resource_management:global_resmgr", + ] + if (enable_appspawn_dump_catcher) { + external_deps += [ "faultloggerd:libdfx_dumpcatcher" ] + } + if (asan_detector || is_asan) { + defines += [ "ASAN_DETECTOR" ] + sources += [ "${appspawn_path}/modules/asan/asan_detector.c" ] + } + + 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 (target_cpu == "arm64" || target_cpu == "x86_64" || + target_cpu == "riscv64") { + defines += [ "APPSPAWN_64" ] + } + + if (dlp_permission_enable) { + cflags_cc = [ "-DWITH_DLP" ] + external_deps += [ "dlp_permission_service:libdlp_fuse" ] + } +} -- Gitee From 7361607812e08ee18bf8f9daca9825d24d6fe256 Mon Sep 17 00:00:00 2001 From: yh Date: Thu, 12 Dec 2024 16:25:26 +0800 Subject: [PATCH 081/148] change delte Signed-off-by: yh Change-Id: I543958a3585d2ba9d49d9ee5465e0f182eb5a61c --- standard/appspawn_service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index d5cd01c0..3a65336d 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -1102,9 +1102,9 @@ void AppSpawnDestroyContent(AppSpawnContent *content) LE_CloseStreamTask(LE_GetDefaultLoop(), appSpawnContent->server); appSpawnContent->server = NULL; } + DeleteAppSpawnMgr(appSpawnContent); LE_StopLoop(LE_GetDefaultLoop()); LE_CloseLoop(LE_GetDefaultLoop()); - DeleteAppSpawnMgr(appSpawnContent); } APPSPAWN_STATIC int AppSpawnColdStartApp(struct AppSpawnContent *content, AppSpawnClient *client) -- Gitee From 472a58c5fddd0ace8e7d919db62de8e88728ab37 Mon Sep 17 00:00:00 2001 From: zerodragon <644396695@qq.com> Date: Wed, 4 Dec 2024 10:28:14 +0800 Subject: [PATCH 082/148] =?UTF-8?q?=E7=BB=99=20hap=20=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20MCS=20=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mengguo Change-Id: Ifff9ffecdcb70f9a3d08407bb3389551c92d043b --- modules/common/appspawn_adapter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/common/appspawn_adapter.cpp b/modules/common/appspawn_adapter.cpp index 74ea6d78..2a4b6aa5 100644 --- a/modules/common/appspawn_adapter.cpp +++ b/modules/common/appspawn_adapter.cpp @@ -106,11 +106,13 @@ int SetSelinuxCon(const AppSpawnMgr *content, const AppSpawningCtx *property) reinterpret_cast(GetAppProperty(property, TLV_DOMAIN_INFO)); APPSPAWN_CHECK(msgDomainInfo != NULL, return APPSPAWN_TLV_NONE, "No domain info in req form %{public}s", GetProcessName(property)); + AppDacInfo *appInfo = reinterpret_cast(GetAppProperty(property, TLV_DAC_INFO)); HapContext hapContext; HapDomainInfo hapDomainInfo; hapDomainInfo.apl = msgDomainInfo->apl; hapDomainInfo.packageName = GetBundleName(property); hapDomainInfo.hapFlags = msgDomainInfo->hapFlags; + hapDomainInfo.uid = appInfo == NULL ? 0 : appInfo->uid; //The value of 0 is invalid. Its purpose is to initialize. if (CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE)) { hapDomainInfo.hapFlags |= SELINUX_HAP_DEBUGGABLE; } -- Gitee From e417c380bb0a2e4f31df5233d4d16c464aff7356 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Fri, 13 Dec 2024 17:04:09 +0800 Subject: [PATCH 083/148] modify JIT permission param Signed-off-by: wangfeng --- modules/common/appspawn_encaps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/common/appspawn_encaps.c b/modules/common/appspawn_encaps.c index 9bf3d456..6821c664 100644 --- a/modules/common/appspawn_encaps.c +++ b/modules/common/appspawn_encaps.c @@ -155,10 +155,10 @@ static int AddJITPermissionToEncaps(cJSON *extInfoJson, cJSON *encaps, uint32_t return APPSPAWN_ARG_INVALID; } - // If permissionName is obtained, it needs to be written in the format of ["permissionName: "true""] in the encaps + // If permissionName is obtained, it needs to be written in the format of ["permissionName: 1"] in the encaps for (int i = 0; i < count; i++) { char *permissionName = cJSON_GetStringValue(cJSON_GetArrayItem(permissions, i)); - if (cJSON_AddStringToObject(encaps, permissionName, "true") == NULL) { + if (cJSON_AddNumberToObject(encaps, permissionName, 1) == NULL) { APPSPAWN_LOGV("Add permission to object failed.(ignore)"); return APPSPAWN_ERROR_UTILS_ADD_JSON_FAIL; } -- Gitee From 1591a5f230c9918e7acc9a7a3b04614a02449c39 Mon Sep 17 00:00:00 2001 From: LXinJie Date: Sat, 14 Dec 2024 17:28:33 +0800 Subject: [PATCH 084/148] liuxinjie6@huawei.com Signed-off-by: LXinJie --- common/appspawn_server.c | 1 + 1 file changed, 1 insertion(+) diff --git a/common/appspawn_server.c b/common/appspawn_server.c index 7996148e..c59f93fa 100644 --- a/common/appspawn_server.c +++ b/common/appspawn_server.c @@ -121,6 +121,7 @@ int AppSpawnChild(AppSpawnContent *content, AppSpawnClient *client) static int CloneAppSpawn(void *arg) { APPSPAWN_CHECK(arg != NULL, return -1, "Invalid content for appspawn"); + APPSPAWN_LOGI("CloneNwebSpawn done."); ffrt_child_init(); AppSpawnForkArg *forkArg = (AppSpawnForkArg *)arg; ProcessExit(AppSpawnChild(forkArg->content, forkArg->client)); -- Gitee From 286dbc1865dce6dc40e380f7afb8245a3530f24d Mon Sep 17 00:00:00 2001 From: chennuo Date: Wed, 18 Dec 2024 16:26:03 +0800 Subject: [PATCH 085/148] fix bugs Signed-off-by: chennuo --- standard/appspawn_service.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 3e80eaa5..b851a31c 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -1024,17 +1024,18 @@ static void ProcessChildResponse(const WatcherHandle taskHandle, int fd, uint32_ #endif clock_gettime(CLOCK_MONOTONIC, &appInfo->spawnEnd); // add max info - } #ifdef APPSPAWN_HISYSEVENT - //add process spawn duration into hisysevent,(ms) - uint32_t spawnProcessDuration = (appInfo->spawnEnd.tv_sec - appInfo->spawnStart.tv_sec) * (APPSPAWN_USEC_TO_NSEC) + - (uint32_t)((appInfo->spawnEnd.tv_nsec - appInfo->spawnStart.tv_nsec)/(APPSPAWN_MSEC_TO_NSEC)); - AppSpawnMgr *appspawnMgr = GetAppSpawnMgr(); - if (appspawnMgr != NULL) { - AddStatisticEventInfo(appspawnMgr->hisyseventInfo, spawnProcessDuration, IsBootFinished()); - } + //add process spawn duration into hisysevent,(ms) + uint32_t spawnProcessDuration = (uint32_t)((appInfo->spawnEnd.tv_sec - appInfo->spawnStart.tv_sec) * + (APPSPAWN_USEC_TO_NSEC)) +(uint32_t)((appInfo->spawnEnd.tv_nsec - appInfo->spawnStart.tv_nsec) / + (APPSPAWN_MSEC_TO_NSEC)); + AppSpawnMgr *appspawnMgr = GetAppSpawnMgr(); + if (appspawnMgr != NULL) { + AddStatisticEventInfo(appspawnMgr->hisyseventInfo, spawnProcessDuration, IsBootFinished()); + } #endif + } WatchChildProcessFd(property); ProcessMgrHookExecute(STAGE_SERVER_APP_ADD, GetAppSpawnContent(), appInfo); -- Gitee From ddf5654cb3cc1e586b8ed16b4774289fbd66d109 Mon Sep 17 00:00:00 2001 From: yuchen Date: Thu, 19 Dec 2024 19:43:57 +0800 Subject: [PATCH 086/148] revert Signed-off-by: yuchen --- appdata-sandbox.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appdata-sandbox.json b/appdata-sandbox.json index b7a2fda7..e32af653 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -615,7 +615,7 @@ "check-action-status": "false" }, { "src-path" : "/vendor/etc/vulkan/icd.d", - "sandbox-path" : "/system/etc/vulkan/icd.d", + "sandbox-path" : "/vendor/etc/vulkan/icd.d", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { -- Gitee From f4e7fc3982b5728749160c702e9f8589645ad3ae Mon Sep 17 00:00:00 2001 From: nianyuu Date: Tue, 17 Dec 2024 20:16:51 +0800 Subject: [PATCH 087/148] check mount status when errno22 Signed-off-by: nianyuu --- modules/sandbox/sandbox_utils.cpp | 33 +++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 58cf9da3..69dea79b 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -263,10 +263,33 @@ static void CheckAndCreatFile(const char *file) return; } +static void CheckMountStatus(const std::string &path) +{ + std::ifstream file("/proc/self/mountinfo"); + if (!file.is_open()) { + APPSPAWN_LOGE("Failed to open /proc/self/mountinfo errno %{public}d", errno); + return; + } + + bool flag = false; + std::string line; + while (std::getline(file, line)) { + if (line.find(path) != std::string::npos) { + flag = true; + APPSPAWN_LOGI("Current mountinfo %{public}s", line.c_str()); + } + } + file.close(); + APPSPAWN_CHECK_ONLY_LOG(flag, "Mountinfo not contains %{public}s", path.c_str()); +} + int32_t SandboxUtils::DoAppSandboxMountOnce(const char *originPath, const char *destinationPath, const char *fsType, unsigned long mountFlags, const char *options, mode_t mountSharedFlag) { + if (originPath == nullptr || destinationPath == nullptr || originPath[0] == '\0' || destinationPath[0] == '\0') { + return 0; + } if (originPath != nullptr && strstr(originPath, "system/etc/hosts") != nullptr) { CheckAndCreatFile(destinationPath); } else { @@ -295,8 +318,14 @@ int32_t SandboxUtils::DoAppSandboxMountOnce(const char *originPath, const char * } ret = mount(nullptr, destinationPath, nullptr, mountSharedFlag, nullptr); - APPSPAWN_CHECK(ret == 0, return ret, "errno is: %{public}d, private mount to %{public}s '%{public}u' failed", - errno, destinationPath, mountSharedFlag); + if (ret != 0) { + APPSPAWN_LOGI("errno is: %{public}d, private mount to %{public}s '%{public}u' failed", + errno, destinationPath, mountSharedFlag); + if (errno == EINVAL) { + CheckMountStatus(destinationPath); + } + return ret; + } return 0; } -- Gitee From 144fb737f6effc4503d47503eb8d3d710f3768d0 Mon Sep 17 00:00:00 2001 From: renzehua Date: Sat, 21 Dec 2024 13:27:28 +0800 Subject: [PATCH 088/148] native process bypass setting fork limit Signed-off-by: renzehua --- modules/common/appspawn_encaps.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/common/appspawn_encaps.c b/modules/common/appspawn_encaps.c index 6821c664..d048b869 100644 --- a/modules/common/appspawn_encaps.c +++ b/modules/common/appspawn_encaps.c @@ -111,7 +111,10 @@ static uint32_t SpawnGetMaxPids(AppSpawnMgr *content, AppSpawningCtx *property) /* set ohos.encaps.fork.count to encaps */ static int SpawnSetMaxPids(AppSpawnMgr *content, AppSpawningCtx *property, cJSON *encaps) { - uint32_t maxPidCount = SpawnGetMaxPids(content, property); + uint32_t maxPidCount = 0; + if (GetAppSpawnMsgType(property) != MSG_SPAWN_NATIVE_PROCESS) { + maxPidCount = SpawnGetMaxPids(content, property); + } if (maxPidCount == 0 || maxPidCount > OH_APP_MAX_PIDS_NUM) { APPSPAWN_LOGV("Don't need to set pid max count. Use default pid max"); return APPSPAWN_PIDMGR_DEFAULT_PID_MAX; -- Gitee From 96f981432ddce931786d0a694552b7fff8f1a01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Tue, 24 Dec 2024 10:31:20 +0800 Subject: [PATCH 089/148] =?UTF-8?q?Extension=20api=E5=BC=BA=E7=AE=A1?= =?UTF-8?q?=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- interfaces/innerkits/include/appspawn.h | 1 + modules/common/appspawn_adapter.cpp | 41 +++++++++++++++++-------- modules/sandbox/appspawn_sandbox.c | 4 +-- modules/sandbox/sandbox_utils.cpp | 4 +-- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index 1a3157d1..7dc86862 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -292,6 +292,7 @@ int AppSpawnClientAddPermission(AppSpawnClientHandle handle, AppSpawnReqMsgHandl #define MSG_EXT_NAME_APP_FD "AppFd" #define MSG_EXT_NAME_JIT_PERMISSIONS "JITPermissions" #define MSG_EXT_NAME_USERID "uid" +#define MSG_EXT_NAME_EXTENSION_TYPE "ExtensionType" int AppSpawnReqMsgAddExtInfo(AppSpawnReqMsgHandle reqHandle, const char *name, const uint8_t *value, uint32_t valueLen); diff --git a/modules/common/appspawn_adapter.cpp b/modules/common/appspawn_adapter.cpp index 2a4b6aa5..f01fd8fe 100644 --- a/modules/common/appspawn_adapter.cpp +++ b/modules/common/appspawn_adapter.cpp @@ -82,6 +82,33 @@ int SetSelinuxConNweb(const AppSpawnMgr *content, const AppSpawningCtx *property return 0; } +#ifdef WITH_SELINUX +void SetHapDomainInfo(HapDomainInfo *hapDomainInfo, const AppSpawningCtx *property, + AppSpawnMsgDomainInfo *msgDomainInfo, AppDacInfo *appInfo) +{ + hapDomainInfo->apl = msgDomainInfo->apl; + hapDomainInfo->packageName = GetBundleName(property); + hapDomainInfo->hapFlags = msgDomainInfo->hapFlags; + //The value of 0 is invalid. Its purpose is to initialize. + hapDomainInfo->uid = appInfo == nullptr ? 0 : appInfo->uid; + if (CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE)) { + hapDomainInfo->hapFlags |= SELINUX_HAP_DEBUGGABLE; + } + if (CheckAppMsgFlagsSet(property, APP_FLAGS_DLP_MANAGER)) { + hapDomainInfo->hapFlags |= SELINUX_HAP_DLP; + } + if (CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX)) { + hapDomainInfo->hapFlags |= SELINUX_HAP_INPUT_ISOLATE; + } + if (CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SELINUX_LABEL)) { + uint32_t len = 0; + std::string extensionType = + reinterpret_cast(GetAppPropertyExt(property, MSG_EXT_NAME_EXTENSION_TYPE, &len)); + hapDomainInfo->extensionType = extensionType; + } +} +#endif + int SetSelinuxCon(const AppSpawnMgr *content, const AppSpawningCtx *property) { #ifdef WITH_SELINUX @@ -109,19 +136,7 @@ int SetSelinuxCon(const AppSpawnMgr *content, const AppSpawningCtx *property) AppDacInfo *appInfo = reinterpret_cast(GetAppProperty(property, TLV_DAC_INFO)); HapContext hapContext; HapDomainInfo hapDomainInfo; - hapDomainInfo.apl = msgDomainInfo->apl; - hapDomainInfo.packageName = GetBundleName(property); - hapDomainInfo.hapFlags = msgDomainInfo->hapFlags; - hapDomainInfo.uid = appInfo == NULL ? 0 : appInfo->uid; //The value of 0 is invalid. Its purpose is to initialize. - if (CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE)) { - hapDomainInfo.hapFlags |= SELINUX_HAP_DEBUGGABLE; - } - if (CheckAppMsgFlagsSet(property, APP_FLAGS_DLP_MANAGER)) { - hapDomainInfo.hapFlags |= SELINUX_HAP_DLP; - } - if (CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX)) { - hapDomainInfo.hapFlags |= SELINUX_HAP_INPUT_ISOLATE; - } + SetHapDomainInfo(&hapDomainInfo, property, msgDomainInfo, appInfo); int32_t ret = hapContext.HapDomainSetcontext(hapDomainInfo); if (CheckAppMsgFlagsSet(property, APP_FLAGS_ASANENABLED)) { ret = 0; diff --git a/modules/sandbox/appspawn_sandbox.c b/modules/sandbox/appspawn_sandbox.c index 7f1fc090..a36c9f4a 100644 --- a/modules/sandbox/appspawn_sandbox.c +++ b/modules/sandbox/appspawn_sandbox.c @@ -210,8 +210,8 @@ static int InitSandboxContext(SandboxContext *context, context->message = property->message; context->sandboxNsFlags = CLONE_NEWNS; - if ((CheckSpawningMsgFlagSet(context, APP_FLAGS_ISOLATED_SANDBOX) && !IsDeveloperModeOpen()) || - CheckSpawningMsgFlagSet(context, APP_FLAGS_ISOLATED_NETWORK)) { + if (!IsDeveloperModeOpen() && (CheckSpawningMsgFlagSet(context, APP_FLAGS_ISOLATED_SANDBOX) || + CheckSpawningMsgFlagSet(context, APP_FLAGS_ISOLATED_NETWORK))) { context->sandboxNsFlags |= sandbox->sandboxNsFlags & CLONE_NEWNET ? CLONE_NEWNET : 0; } diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 69dea79b..f3f952e8 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -1870,8 +1870,8 @@ int32_t SetAppSandboxProperty(AppSpawnMgr *content, AppSpawningCtx *property) } } uint32_t sandboxNsFlags = CLONE_NEWNS; - if ((CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX) && !IsDeveloperModeOpen()) || - CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_NETWORK)) { + if (!IsDeveloperModeOpen() && (CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX) || + CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_NETWORK))) { sandboxNsFlags |= content->content.sandboxNsFlags & CLONE_NEWNET ? CLONE_NEWNET : 0; } APPSPAWN_LOGV("SetAppSandboxProperty sandboxNsFlags 0x%{public}x", sandboxNsFlags); -- Gitee From ffb50d849621dcd687a263c40b3d083b76440812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Tue, 24 Dec 2024 11:14:23 +0800 Subject: [PATCH 090/148] =?UTF-8?q?fix:=20=E9=85=8D=E7=BD=AE=E9=A1=B9?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20create-sandbox-path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- modules/sandbox/sandbox_utils.cpp | 18 ++++- .../app_spawn_sandbox_test.cpp | 78 +++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 69dea79b..983fca83 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -132,6 +132,7 @@ namespace { const char *g_sandBoxNsFlags = "sandbox-ns-flags"; const char* g_fileSeparator = "/"; const char* g_overlayDecollator = "|"; + const char *CREATE_SANDBOX_PATH = "create-sandbox-path"; const std::string g_sandBoxRootDir = "/mnt/sandbox/"; const std::string g_ohosGpu = "__internal__.com.ohos.gpu"; const std::string g_ohosRender = "__internal__.com.ohos.render"; @@ -826,6 +827,19 @@ static bool CheckMountFlag(const AppSpawningCtx *appProperty, const std::string return false; } +static bool GetCreateSandboxPath(nlohmann::json &json) +{ + std::string value = g_statusCheck; + APPSPAWN_CHECK(json != nullptr && json.is_object(), return true, "json is not object."); + bool isRet = json.find(CREATE_SANDBOX_PATH) != json.end() && json.at(CREATE_SANDBOX_PATH).is_string(); + if (isRet) { + value = json.at(CREATE_SANDBOX_PATH).get(); + APPSPAWN_LOGV("Find create-sandbox-path: %{public}s successful.", value.c_str()); + return g_statusCheck == value; + } + return true; +} + int SandboxUtils::DoAllMntPointsMount(const AppSpawningCtx *appProperty, nlohmann::json &appConfig, const char *typeName, const std::string §ion) { @@ -856,7 +870,9 @@ int SandboxUtils::DoAllMntPointsMount(const AppSpawningCtx *appProperty, /* if app mount failed for special strategy, we need deal with common mount config */ int ret = HandleSpecialAppMount(appProperty, srcPath, sandboxPath, mountConfig.fsType, mountFlags); - if (ret < 0) { + bool createSandboxPath = true; + createSandboxPath = GetCreateSandboxPath(mntPoint); + if (ret < 0 && (createSandboxPath || access(srcPath.c_str(), F_OK) == 0)) { ret = DoAppSandboxMountOnce(srcPath.c_str(), sandboxPath.c_str(), mountConfig.fsType.c_str(), mountFlags, mountConfig.optionsPoint.c_str(), mountSharedFlag); } diff --git a/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp index 58a5be7b..6d2d24e9 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp @@ -1348,6 +1348,84 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_45, TestSize.Level0) EXPECT_EQ(ret, 0); GTEST_LOG_(INFO) << "App_Spawn_Sandbox_45 end"; } + +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_46, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_46 start"; + g_testHelper.SetTestUid(1000); // 1000 test + g_testHelper.SetTestGid(1000); // 1000 test + g_testHelper.SetProcessName("com.example.myapplication"); + g_testHelper.SetTestApl("apl123"); + g_testHelper.SetTestMsgFlags(4); // 4 is test parameter + AppSpawningCtx *appProperty = GetTestAppProperty(); + + std::string mJsconfig1 = "{ \ + \"sandbox-root\" : \"/mnt/sandbox//\", \ + \"mount-paths\" : [{ \ + \"src-path\" : \"/data/service/el1/public/themes//a/app/\", \ + \"sandbox-path\" : \"/data/themes/a/app\", \ + \"sandbox-flags\" : [ \"bind\", \"rec\" ], \ + \"check-action-status\": \"false\" \ + }] \ + }"; + nlohmann::json j_config1 = nlohmann::json::parse(mJsconfig1.c_str()); + int ret = OHOS::AppSpawn::SandboxUtils::DoAllMntPointsMount(appProperty, j_config1, nullptr); + EXPECT_EQ(ret, 0); + + std::string mJsconfig2 = "{ \ + \"sandbox-root\" : \"/mnt/sandbox//\", \ + \"mount-paths\" : [{ \ + \"src-path\" : \"/data/service/el1/public/themes//a/app/createSandboxPath01\", \ + \"sandbox-path\" : \"/data/themes/a/app/createSandboxPath01\", \ + \"sandbox-flags\" : [ \"bind\", \"rec\" ], \ + \"check-action-status\": \"false\", \ + \"create-sandbox-path\": \"true\" \ + }] \ + }"; + nlohmann::json j_config2 = nlohmann::json::parse(mJsconfig2.c_str()); + ret = OHOS::AppSpawn::SandboxUtils::DoAllMntPointsMount(appProperty, j_config2, nullptr); + DeleteAppSpawningCtx(appProperty); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_47, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_47 start"; + g_testHelper.SetTestUid(1000); // 1000 test + g_testHelper.SetTestGid(1000); // 1000 test + g_testHelper.SetProcessName("com.example.myapplication"); + g_testHelper.SetTestApl("apl123"); + g_testHelper.SetTestMsgFlags(4); // 4 is test parameter + AppSpawningCtx *appProperty = GetTestAppProperty(); + + std::string mJsconfig1 = "{ \ + \"sandbox-root\" : \"/mnt/sandbox//\", \ + \"mount-paths\" : [{ \ + \"src-path\" : \"/data/service/el1/public/themes//a/app/\", \ + \"sandbox-path\" : \"/data/themes/a/app\", \ + \"sandbox-flags\" : [ \"bind\", \"rec\" ], \ + \"check-action-status\": \"false\" \ + }] \ + }"; + nlohmann::json j_config1 = nlohmann::json::parse(mJsconfig1.c_str()); + int ret = OHOS::AppSpawn::SandboxUtils::DoAllMntPointsMount(appProperty, j_config1, nullptr); + EXPECT_EQ(ret, 0); + + std::string mJsconfig2 = "{ \ + \"sandbox-root\" : \"/mnt/sandbox//\", \ + \"mount-paths\" : [{ \ + \"src-path\" : \"/data/service/el1/public/themes//a/app/createSandboxPath01\", \ + \"sandbox-path\" : \"/data/themes/a/app/createSandboxPath01\", \ + \"sandbox-flags\" : [ \"bind\", \"rec\" ], \ + \"check-action-status\": \"false\", \ + \"create-sandbox-path\": \"false\" \ + }] \ + }"; + nlohmann::json j_config2 = nlohmann::json::parse(mJsconfig2.c_str()); + ret = OHOS::AppSpawn::SandboxUtils::DoAllMntPointsMount(appProperty, j_config2, nullptr); + DeleteAppSpawningCtx(appProperty); + EXPECT_EQ(ret, 0); +} /** * @brief 测试app extension * -- Gitee From f532367669a2d4498385486749640a688700b82b Mon Sep 17 00:00:00 2001 From: wangshengwen Date: Thu, 26 Dec 2024 11:33:05 +0800 Subject: [PATCH 091/148] =?UTF-8?q?=E5=AE=89=E8=A3=85=E5=AD=97=E4=BD=93?= =?UTF-8?q?=E7=9A=84=E6=B2=99=E7=AE=B1=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangshengwen --- appdata-sandbox.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/appdata-sandbox.json b/appdata-sandbox.json index e32af653..2f5ea439 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -498,6 +498,11 @@ "sandbox-path" : "/system/lib", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" + }, { + "src-path" : "/data/service/el1/public/for-all-app", + "sandbox-path" : "/data/service/el1/public/for-all-app", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" }, { "src-path" : "/system/app/", "sandbox-path" : "/system/app/", -- Gitee From 17711e66c9174d496d096f9bce3e2c72d43e8b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Sat, 28 Dec 2024 11:17:27 +0800 Subject: [PATCH 092/148] add autotest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- .../sub_startup_appspawn_cgroup_0100.json | 14 ++++ .../sub_startup_appspawn_cgroup_0100.py | 74 +++++++++++++++++++ .../sub_startup_appspawn_cgroup_0200.json | 14 ++++ .../sub_startup_appspawn_cgroup_0200.py | 73 ++++++++++++++++++ .../sub_startup_appspawn_cgroup_0300.json | 14 ++++ .../sub_startup_appspawn_cgroup_0300.py | 73 ++++++++++++++++++ .../sub_startup_appspawn_coldstart_0100.json | 14 ++++ .../sub_startup_appspawn_coldstart_0100.py | 52 +++++++++++++ ...tartup_appspawn_coldstart_ablity_0100.json | 14 ++++ ..._startup_appspawn_coldstart_ablity_0100.py | 59 +++++++++++++++ ...tartup_appspawn_coldstart_ablity_0200.json | 14 ++++ ..._startup_appspawn_coldstart_ablity_0200.py | 58 +++++++++++++++ 12 files changed, 473 insertions(+) create mode 100644 test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.json create mode 100644 test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.py create mode 100644 test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.json create mode 100644 test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.py create mode 100644 test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.json create mode 100644 test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.py create mode 100644 test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.json create mode 100644 test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.py create mode 100644 test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.json create mode 100644 test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.py create mode 100644 test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.json create mode 100644 test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.py diff --git a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.json b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.json new file mode 100644 index 00000000..b408aca0 --- /dev/null +++ b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "test/autotest/SUB_STARTUP_APPSPAWN_CGROUPS/SubStartupAppspawnCgroup0100.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.py b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.py new file mode 100644 index 00000000..0b69b20d --- /dev/null +++ b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.py @@ -0,0 +1,74 @@ +# 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. + +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver + +from aw import Common + + +class SubStartupAppspawnCgroup0100(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.shell("power-shell setmdoe 602") + + def process(self): + hap_path = Common.sourcepath('ForkTest1.hap', "SUB_STARTUP_APPSPAWN_CGROUPS") + bundle_name = "com.example.exe_sys_cmd" + 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(bundle_name) + else: + self.driver.AppManager.install_app(bundle_name) + self.driver.AppManager.start_app(bundle_name) + pid = self.driver.System.get_pid(bundle_name) + result1 = self.driver.shell("ps -ef |grep %s" % bundle_name) + cgroup1 = self.driver.shell("cat /dev/pids/100/%s/app_%d/cgroup.procs" % (bundle_name, pid)).split() + count = 0 + for i in cgroup1: + self.driver.Assert.contains(result1.split(), i) + if result1.count(i) == 2: + count += 1 + self.driver.Assert.equal(count, 1) + result2 = self.driver.shell("kill -9 %d" % pid) + self.driver.Assert.equal(result2, '') + result3 = self.driver.shell("ps -ef |grep %s|grep -v grep " % bundle_name) + self.driver.Assert.equal(result3, '') + + def teardown(self): + Step("收尾工作...") + self.driver.AppManager.clear_app_data(bundle_name) + self.driver.AppManager.uninstall_app(bundle_name) \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.json b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.json new file mode 100644 index 00000000..9c955111 --- /dev/null +++ b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "test/autotest/SUB_STARTUP_APPSPAWN_CGROUPS/SubStartupAppspawnCgroup0200.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.py b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.py new file mode 100644 index 00000000..2e1efc10 --- /dev/null +++ b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.py @@ -0,0 +1,73 @@ +# 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. + +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver + +from aw import Common + + +class SubStartupAppspawnCgroup0200(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.shell("power-shell timeout -o 86400000") + + def process(self): + hap_path = Common.sourcepath('ForkTest2.hap', "SUB_STARTUP_APPSPAWN_CGROUPS") + bundle_name = "com.example.exe_sys_cmd" + 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(bundle_name) + else: + self.driver.AppManager.install_app(bundle_name) + self.driver.AppManager.start_app(bundle_name) + pid = self.driver.System.get_pid(bundle_name) + result1 = self.driver.shell("ps -ef |grep %s" % bundle_name) + cgroup1 = self.driver.shell("cat /dev/pids/100/%s/app_%d/cgroup.procs" % (bundle_name, pid)).split() + count = 0 + for i in cgroup1: + self.driver.Assert.contains(result1.split(), i) + if result1.count(i) == 3: + count += 1 + self.driver.Assert.equal(count, 1) + result2 = self.driver.shell("kill -9 %d" % pid) + self.driver.Assert.equal(result2, '') + result3 = self.driver.shell("ps -ef |grep %s|grep -v grep " % bundle_name) + self.driver.Assert.equal(result3, '') + + def teardown(self): + Step("收尾工作...") + self.driver.AppManager.clear_app_data("com.example.exe_sys_cmd") diff --git a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.json b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.json new file mode 100644 index 00000000..9f598ad9 --- /dev/null +++ b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "test/autotest/SUB_STARTUP_APPSPAWN_CGROUPS/SubStartupAppspawnCgroup0300.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.py b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.py new file mode 100644 index 00000000..21b0e960 --- /dev/null +++ b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.py @@ -0,0 +1,73 @@ +# 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. + +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver + +from aw import Common + + +class SubStartupAppspawnCgroup0300(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.shell("power-shell timeout -o 86400000") + + def process(self): + hap_path = Common.sourcepath('ForkTest3.hap', "SUB_STARTUP_APPSPAWN_CGROUPS") + bundle_name = "com.example.exe_sys_cmd" + 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(bundle_name) + else: + self.driver.AppManager.install_app(bundle_name) + self.driver.AppManager.start_app(bundle_name) + pid = self.driver.System.get_pid(bundle_name) + result1 = self.driver.shell("ps -ef |grep %s" % bundle_name) + cgroup1 = self.driver.shell("cat /dev/pids/100/%s/app_%d/cgroup.procs" % (bundle_name, pid)).split() + count = 0 + for i in cgroup1: + self.driver.Assert.contains(result1.split(), i) + if result1.count(i) == 2: + count += 1 + self.driver.Assert.equal(count, 2) + result2 = self.driver.shell("kill -9 %d" % pid) + self.driver.Assert.equal(result2, '') + result3 = self.driver.shell("ps -ef |grep %s|grep -v grep " % bundle_name) + self.driver.Assert.equal(result3, '') + + def teardown(self): + Step("收尾工作...") + self.driver.AppManager.clear_app_data("com.example.exe_sys_cmd") diff --git a/test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.json b/test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.json new file mode 100644 index 00000000..cc1ab049 --- /dev/null +++ b/test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "test/autotest/SUB_STARTUP_APPSPAWN_CGROUPS/SubStartupAppspawnColdstart0100.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.py b/test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.py new file mode 100644 index 00000000..b20c065b --- /dev/null +++ b/test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.py @@ -0,0 +1,52 @@ +# 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. + +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver + +from aw import Common + + +class SubStartupAppspawnColdstart0100(TestCase): + + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def test_step1(self): + Step("设置冷启动全局参...............") + result = self.driver.shell('param set startup.appspawn.cold.boot 1') + sleep(3) + if "Set paramter startup.appspawn.cold.boot 1 success" in result: + pass + else: + raise ValueError('设置冷启动全局参数失败') + Step("通过命令启动日历...........") + result = self.driver.shell('aa start -C -d 123456 -a MainAbility -b com.example.calendar') + sleep(3) + self.driver.Assert.contains(result, "start ability successfully", "通过命令启动日历失败") + Step("检查日历冷启动进程............") + result_ps = self.driver.shell("ps -ef|grep com.example.calendar") + result_ps = result_ps.split('\n')[0] + Step("日历进程信息如下:" + str(result_ps)) + + def teardown(self): + Step("收尾工作...") + pid = self.driver.System.get_pid('com.example.calendar') + self.driver.shell('kill -9 %d' % pid) \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.json b/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.json new file mode 100644 index 00000000..6d9e9634 --- /dev/null +++ b/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "test/autotest/SUB_STARTUP_APPSPAWN_CGROUPS/SubStartupAppspawnColdstartAblity0100.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.py b/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.py new file mode 100644 index 00000000..b1763276 --- /dev/null +++ b/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.py @@ -0,0 +1,59 @@ +# 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. + +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver + +from aw import Common + + +class SubStartupAppspawnColdstartAblity0100(TestCase): + + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作开始") + Step(self.devices[0].device_id) + Step("安装测试hap") + sourcepath = Common.sourcepath("asan-enable.hap", "SUB_STARTUP_APPSPAWN_COLDSTARTABLITY") + Step(sourcepath) + self.driver.AppManager.install_app(sourcepath) + Step("预置工作:检查屏幕") + self.driver.Screen.wake_up() + self.driver.ScreenLock.unlock() + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("打开测试hap...............") + result = self.driver.startup_app("com.example.myapplication", "EntryAbility") + sleep(3) + pid = self.driver.System.get_pid('com.example.myapplication') + Step(pid) + Step("校验") + result = self.driver.shell('cat /proc/self/maps|grep libclang_rt.asan.so') + Step(result) + self.driver.Assert.contains(result, '/system/lib64/libclang_rt.asan.so') + self.driver.Assert.contains(result, 'anon:libclang_rt.asan.so.bss') + + def teardown(self): + Step("收尾工作...") + self.driver.AppManager.clear_app_data('com.example.myapplication') + self.driver.AppManager.uninstall_app('com.example.myapplication') \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.json b/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.json new file mode 100644 index 00000000..99782006 --- /dev/null +++ b/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "test/autotest/SUB_STARTUP_APPSPAWN_CGROUPS/SubStartupAppspawnColdstartAblity0200.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.py b/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.py new file mode 100644 index 00000000..eea78653 --- /dev/null +++ b/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.py @@ -0,0 +1,58 @@ +# 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. + +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver + +from aw import Common + + +class SubStartupAppspawnColdstartAblity0200(TestCase): + + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作开始") + Step(self.devices[0].device_id) + Step("安装测试hap") + sourcepath = Common.sourcepath("asan-enable.hap", "SUB_STARTUP_APPSPAWN_COLDSTARTABLITY") + Step(sourcepath) + self.driver.AppManager.install_app(sourcepath) + Step("预置工作:检查屏幕") + self.driver.Screen.wake_up() + self.driver.ScreenLock.unlock() + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("打开测试hap...............") + result = self.driver.startup_app("com.example.myapplication", "EntryAbility") + sleep(3) + pid = self.driver.System.get_pid('com.example.myapplication') + Step(pid) + Step("校验") + result = self.driver.shell('cat /proc/self/maps|grep libclang_rt.asan.so') + Step(result) + self.driver.Assert.contains(result, '') + + def teardown(self): + Step("收尾工作...") + self.driver.AppManager.clear_app_data('com.example.myapplication') + self.driver.AppManager.uninstall_app('com.example.myapplication') -- Gitee From a40e35c107f4cb01427c472de29f7921dc2f49b5 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Fri, 27 Dec 2024 16:07:52 +0800 Subject: [PATCH 093/148] add autotest testcase Signed-off-by: nianyuu --- .../sub_startup_appspawn_appclone_0100.json | 13 ++ .../sub_startup_appspawn_appclone_0100.py | 76 +++++++++ .../sub_startup_appspawn_appclone_0200.json | 13 ++ .../sub_startup_appspawn_appclone_0200.py | 76 +++++++++ .../sub_startup_appspawn_appclone_0300.json | 15 ++ .../sub_startup_appspawn_appclone_0300.py | 100 ++++++++++++ .../sub_startup_appspawn_appclone_0400.json | 15 ++ .../sub_startup_appspawn_appclone_0400.py | 85 ++++++++++ .../sub_startup_appspawn_appclone_0600.json | 15 ++ .../sub_startup_appspawn_appclone_0600.py | 80 ++++++++++ .../sub_startup_appspawn_appclone_0700.json | 15 ++ .../sub_startup_appspawn_appclone_0700.py | 99 ++++++++++++ .../sub_startup_appspawn_appclone_0900.json | 15 ++ .../sub_startup_appspawn_appclone_0900.py | 87 ++++++++++ ...sub_startup_appspawn_atomservice_0100.json | 14 ++ .../sub_startup_appspawn_atomservice_0100.py | 102 ++++++++++++ ...sub_startup_appspawn_atomservice_0200.json | 15 ++ .../sub_startup_appspawn_atomservice_0200.py | 149 ++++++++++++++++++ ...sub_startup_appspawn_atomservice_0300.json | 14 ++ .../sub_startup_appspawn_atomservice_0300.py | 64 ++++++++ ...sub_startup_appspawn_atomservice_0400.json | 15 ++ .../sub_startup_appspawn_atomservice_0400.py | 112 +++++++++++++ .../sub_startup_appspawn_base_0100.json | 14 ++ .../sub_startup_appspawn_base_0100.py | 48 ++++++ .../sub_startup_appspawn_base_0200.json | 14 ++ .../sub_startup_appspawn_base_0200.py | 60 +++++++ .../sub_startup_appspawn_base_0300.json | 14 ++ .../sub_startup_appspawn_base_0300.py | 60 +++++++ .../sub_startup_appspawn_base_0400.json | 14 ++ .../sub_startup_appspawn_base_0400.py | 63 ++++++++ .../sub_startup_appspawn_base_0500.json | 14 ++ .../sub_startup_appspawn_base_0500.py | 56 +++++++ .../sub_startup_appspawn_base_0600.json | 14 ++ .../sub_startup_appspawn_base_0600.py | 84 ++++++++++ 34 files changed, 1644 insertions(+) create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.json create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.py create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.json create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.json create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.py create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.json create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.json create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.json create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.json create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.json create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.json create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.json create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.json new file mode 100644 index 00000000..5e005475 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.json @@ -0,0 +1,13 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py"] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py new file mode 100644 index 00000000..123b491a --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py @@ -0,0 +1,76 @@ +# 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. + +import os +import time +from devicetest.core.test_case import TestCase, Step, CheckPoint +from hypium import UiDriver +from hypium.action.os_hypium.device_logger import DeviceLogger +from hypium.model import UiParam, WindowFilter + + +class SubStartupAppspawnAppclone0100(TestCase): + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:唤醒屏幕.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("步骤1:安装测试hap包") + ishap = self.driver.has_app("com.ohos.mytest") + if(ishap): + self.driver.uninstall_app("com.ohos.mytest") + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + hap = os.path.abspath( + os.path.join(os.path.join(path, "testFile"), + 'sub_startup_appspawn_appclone/entry-signed-release.hap')) + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.ohos.mytest", "EntryAbility") + time.sleep(2) + self.driver.check_window_exist(WindowFilter().bundle_name("com.ohos.mytest")) + Step("步骤3:点击安装克隆应用") + self.driver.touch(BY.text("安装克隆应用")) + self.driver.touch(BY.text("startAbilityByAppIndex")) + Step("步骤4:分身应用的源目录新建123.txt") + self.driver.shell("touch /data/app/el2/100/database/+clone-1+com.ohos.mytest/123.txt") + Step("步骤5:分身应用沙盒路径是否存在123.txt") + cpid = self.driver.System.get_pid("com.ohos.mytest1") + result1 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % cpid) + Step("步骤6:预期结果校验") + self.driver.Assert.contains(result1, "123.txt") + Step("步骤7:主应用沙盒路径是否存在123.txt") + pid = self.driver.System.get_pid("com.ohos.mytest") + result2 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % pid) + Step("步骤6:预期结果校验") + if ("123.txt" in result2): + raise AssertionError() + else: + pass + + def teardown(self): + Step("收尾工作:删除hap") + self.driver.uninstall_app("com.ohos.mytest") diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.json new file mode 100644 index 00000000..bb2984a9 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.json @@ -0,0 +1,13 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py"] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py new file mode 100644 index 00000000..1ef2cf9d --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py @@ -0,0 +1,76 @@ +# 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. + +import os +import time +from devicetest.core.test_case import TestCase, Step, CheckPoint +from hypium import UiDriver +from hypium.action.os_hypium.device_logger import DeviceLogger +from hypium.model import UiParam, WindowFilter + + +class SubStartupAppspawnAppclone0200(TestCase): + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:唤醒屏幕.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("步骤1:安装测试hap包") + ishap = self.driver.has_app("com.ohos.mytest") + if(ishap): + self.driver.uninstall_app("com.ohos.mytest") + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + hap = os.path.abspath( + os.path.join(os.path.join(path, "testFile"), + 'sub_startup_appspawn_appclone/entry-signed-release.hap')) + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.ohos.mytest", "EntryAbility") + time.sleep(2) + self.driver.check_window_exist(WindowFilter().bundle_name("com.ohos.mytest")) + Step("步骤3:点击安装克隆应用") + self.driver.touch(BY.text("安装克隆应用")) + self.driver.touch(BY.text("startAbilityByAppIndex")) + Step("步骤4:分身应用的源目录新建123.txt") + self.driver.shell("touch /data/app/el2/100/database/com.ohos.mytest/abc.txt") + Step("步骤5:主应用沙盒路径是否存在abc.txt") + cpid = self.driver.System.get_pid("com.ohos.mytest") + result1 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % cpid) + Step("步骤6:预期结果校验") + self.driver.Assert.contains(result1, "abc.txt") + Step("步骤7:分身应用沙盒路径是否存在abc.txt") + pid = self.driver.System.get_pid("com.ohos.mytest1") + result2 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % pid) + Step("步骤6:预期结果校验") + if ("abc.txt" in result2): + raise AssertionError() + else: + pass + + def teardown(self): + Step("收尾工作:删除hap") + self.driver.uninstall_app("com.ohos.mytest") diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.json new file mode 100644 index 00000000..f24d94ed --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py new file mode 100644 index 00000000..19c8ae59 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py @@ -0,0 +1,100 @@ +# 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. + +import os +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from hypium.action.os_hypium.device_logger import DeviceLogger +from aw import Common + + +class SubStartupAppspawnAppclone0300(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 build_shell_command(i, path, bundle_name, j): + if bundle_name == "com.example.intaketest": + result01 = self.driver.shell("ls /data/app/el%d/100/%s/%s" % (i, path, bundle_name)) + elif bundle_name == "com.example.intaketest%d" % j: + result01 = self.driver.shell("ls /data/app/el%d/100/%s/+clone-%d+com.example.intaketest" + % (i, path, j)) + return None + + def process(self): + Step("安装测试hap并打开") + pid_bundlename_dict = {} + bundle_name = "com.example.intaketest" + hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") + 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) + pid = self.driver.System.get_pid(bundle_name) + pid_bundlename_dict.update({bundle_name: pid}) + + self.driver.AppManager.stop_app("com.example.settings") + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身", "IntakeTest"]: + self.driver.touch(BY.text(text)) + for i in range(5): + self.driver.touch(BY.text("创建分身")) + time.sleep(1) + self.driver.AppManager.stop_app("com.example.settings") + + for i in range(1, 7): + self.driver.AppManager.start_app(bundle_name) + if i == 1: + self.driver.touch(BY.text("IntakeTest")) + pid = self.driver.System.get_pid(bundle_name) + pid_bundlename_dict.update({bundle_name: pid}) + else: + self.driver.touch(BY.text("更多打开方式")) + self.driver.touch(BY.text("IntakeTest%d" % (i - 1))) + pid = self.driver.System.get_pid("%s%d" % (bundle_name, i - 1)) + pid_bundlename_dict.update({"%s%d" % (bundle_name, i - 1) : pid}) + self.driver.go_home() + + for i in range(1, 5): + for j in range(1, 6): + for bundle_name, pid in pid_bundlename_dict.items(): + result01 = build_shell_command(i, "base", bundle_name, j) + result02 = self.driver.shell("ls /proc/%d/root/data/storage/el%d/%s" % (pid, i, "base")) + self.driver.Assert.equal(result01, result02) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.uninstall_app("com.example.intaketest") diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.json new file mode 100644 index 00000000..8b42c680 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py new file mode 100644 index 00000000..0fac2642 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py @@ -0,0 +1,85 @@ +# 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. + +import os +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from hypium.action.os_hypium.device_logger import DeviceLogger +from aw import Common + + +class SubStartupAppspawnAppclone0400(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): + Step("安装测试hap并打开") + bundle_name = "com.example.intaketest" + hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") + 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.AppManager.stop_app("com.example.settings") + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身", "IntakeTest"]: + self.driver.touch(BY.text(text)) + for i in range(5): + self.driver.touch(BY.text("创建分身")) + time.sleep(1) + self.driver.AppManager.stop_app("com.example.settings") + + for i in range(1, 7): + self.driver.AppManager.start_app(bundle_name) + if i == 1: + self.driver.touch(BY.text("IntakeTest")) + else: + self.driver.touch(BY.text("更多打开方式")) + self.driver.touch(BY.text("IntakeTest%d" % (i - 1))) + self.driver.go_home() + + self.driver.shell("touch /data/app/el2/100/base/%s/test.txt" % bundle_name) + has_file01 = self.driver.Storage.has_file("/data/app/el2/100/base/%s/test.txt" % bundle_name) + self.driver.Assert.equal(has_file01, True) + for i in range(1, 6): + has_file02 = self.driver.Storage.has_file("/data/app/el2/100/base/+clone-%d+%s/test.txt" % (i, bundle_name)) + self.driver.Assert.equal(has_file02, False) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.json new file mode 100644 index 00000000..6d4df89f --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py new file mode 100644 index 00000000..d97cb69a --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py @@ -0,0 +1,80 @@ +# 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. + +import os +import random +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from hypium.action.os_hypium.device_logger import DeviceLogger +from aw import Common + + +class SubStartupAppspawnAppclone0600(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): + Step("安装测试hap并打开") + bundle_name = "com.example.intaketest" + hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") + 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.AppManager.stop_app("com.example.settings") + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身", "IntakeTest"]: + self.driver.touch(BY.text(text)) + for i in range(5): + self.driver.touch(BY.text("创建分身")) + time.sleep(1) + + self.driver.check_component_exist(BY.text("最多可以创建 5 个分身"), expect_exist=True) + + comps01 = self.driver.find_all_components(BY.type("Button")) + self.driver.touch(comps01[random.randint(0, len(comps01) - 1)]) + comps02 = self.driver.find_all_components(BY.type("Button")) + self.driver.touch(comps02[-1]) + self.driver.check_component_exist(BY.text("最多可以创建 5 个分身"), expect_exist=False) + self.driver.touch(BY.text("创建分身")) + self.driver.check_component_exist(BY.text("最多可以创建 5 个分身"), expect_exist=True) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.stop_app("com.example.settings") + self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.json new file mode 100644 index 00000000..1cbfb97e --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py new file mode 100644 index 00000000..d48b79c8 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py @@ -0,0 +1,99 @@ +# 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. + +import os +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from hypium.action.os_hypium.device_logger import DeviceLogger +from aw import Common + + +class SubStartupAppspawnAppclone0700(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): + Step("安装测试hap并打开") + bundle_name = "com.example.intaketest" + hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") + 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.AppManager.stop_app("com.example.settings") + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身", "IntakeTest"]: + self.driver.touch(BY.text(text)) + for i in range(5): + self.driver.touch(BY.text("创建分身")) + time.sleep(1) + self.driver.AppManager.stop_app("com.example.settings") + + for i in range(1, 7): + self.driver.AppManager.start_app(bundle_name) + if i == 1: + self.driver.touch(BY.text("IntakeTest")) + else: + self.driver.touch(BY.text("更多打开方式")) + self.driver.touch(BY.text("IntakeTest%d" % (i - 1))) + + for i in range(1, 5): + for j in range(1, 6): + for path in ["base", "database"]: + has_dir = self.driver.Storage.has_dir("/data/app/el%d/100/%s/+clone-%d+%s" + % (i, path, j, bundle_name)) + self.driver.Assert.equal(has_dir, True) + + self.driver.AppManager.stop_app("com.example.settings") + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身", "IntakeTest"]: + self.driver.touch(BY.text(text)) + comps01 = self.driver.find_all_components(BY.type("Button")) + self.driver.touch(comps01[0]) + comps02 = self.driver.find_all_components(BY.type("Button")) + self.driver.touch(comps02[-1]) + for i in range(1, 5): + for path in ["base", "database"]: + has_dir = self.driver.Storage.has_dir("/data/app/el%d/100/%s/+clone-1+%s" % (i, path, bundle_name)) + self.driver.Assert.equal(has_dir, False) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.stop_app("com.example.settings") + self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.json new file mode 100644 index 00000000..0ffa0631 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py new file mode 100644 index 00000000..4e9a09f7 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py @@ -0,0 +1,87 @@ +# 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. + +import os +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from hypium.action.os_hypium.device_logger import DeviceLogger +from aw import Common + + +class SubStartupAppspawnAppclone0900(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): + Step("安装测试hap并打开") + bundle_name = "com.example.intaketest" + hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") + 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.AppManager.stop_app("com.example.settings") + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身", "IntakeTest"]: + self.driver.touch(BY.text(text)) + for i in range(5): + self.driver.touch(BY.text("创建分身")) + time.sleep(1) + self.driver.AppManager.stop_app("com.example.settings") + + for i in range(1, 7): + self.driver.AppManager.start_app(bundle_name) + if i == 1: + self.driver.touch(BY.text("IntakeTest")) + pid = self.driver.System.get_pid(bundle_name) + else: + self.driver.touch(BY.text("更多打开方式")) + self.driver.touch(BY.text("IntakeTest%d" % (i - 1))) + pid = self.driver.System.get_pid("%s%d" % (bundle_name, i - 1)) + self.driver.Assert.equal(type(pid), int) + + self.driver.AppManager.uninstall_app(bundle_name) + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身"]: + self.driver.touch(BY.text(text)) + self.driver.check_component_exist(BY.text("IntakeTest"), expect_exist=False) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.stop_app("com.example.settings") 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 new file mode 100644 index 00000000..2ab0439d --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.json @@ -0,0 +1,14 @@ +{ + "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 new file mode 100644 index 00000000..d54d8df9 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.py @@ -0,0 +1,102 @@ +# 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. + +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_0200.json b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.json new file mode 100644 index 00000000..10589557 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py new file mode 100644 index 00000000..5e2386b5 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py @@ -0,0 +1,149 @@ +# 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. + +import json +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from aw import Common + + +class SubStartupAppspawnAtomservice0200(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) + + Step("解锁屏幕") + 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 login_account(self): + Step("登录帐号") + setting_name = "com.example.settings" + with open(r"config/userLogin.json", 'r', encoding='UTF-8') as f: + account = json.load(f) + self.driver.AppManager.stop_app(setting_name) + self.driver.AppManager.start_app(setting_name) + self.driver.touch(BY.key("entry_image_account")) + comps1 = self.driver.find_component(BY.key("inp_hwid_login_account_name_before")) + if comps1: + self.driver.input_text(comps1, account["userName"]) + self.driver.close_soft_keyboard() + self.driver.touch(BY.key("button_text")) + comps2 = self.driver.find_component(BY.key("inp_hwid_login_password")) + self.driver.input_text(comps2, account["passWord"]) + else: + comps3 = self.driver.find_component(BY.key("inp_hwid_login_account_name")) + self.driver.clear_text(comps3) + self.driver.input_text(comps3, account["userName"]) + comps4 = self.driver.find_component(BY.key("inp_hwid_login_password")) + self.driver.input_text(comps4, account["passWord"]) + self.driver.touch(BY.key("button_text")) + self.driver.wait_for_component(BY.text("继续"), timeout=15) + self.driver.touch(BY.text("继续")) + + def exit_account(self): + Step("退出帐号") + setting_name = "com.example.settings" + self.driver.AppManager.stop_app(setting_name) + self.driver.AppManager.start_app(setting_name) + self.driver.touch(BY.key("entry_image_account")) + self.driver.swipe(UiParam.UP) + comp = self.driver.find_component(BY.key("hwid_account_center_logout_text"), scroll_target=BY.type("Scroll")) + self.driver.touch(comp) + self.driver.touch(BY.key("button_text")) + comps5 = self.driver.find_component(BY.key("advanced_dialog_button_1")) + if comps5: + self.driver.touch(comps5) + time.sleep(5) + else: + pass + + def process(self): + self.login_account() + hap_info01, hap_info02 = [], [] + bundle_name = "com.atomicservice.5765880207854649689" + bundle_name_start = "+auid-9E1E70ABFF4AAFE1E18AF18E0F75703713D" + "8678F9F9AB06C3B64C1CB1080615A+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) + self.driver.Assert.equal(log_has_dir, True) + + 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) + + Step("校验UGO、所有者、所属组、selinux标签一致") + 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 + #校验用户字符串长度为64 + self.driver.Assert.equal(len(hap_info02.split()[-1].split("-")[1].split("+")[0]), 64) + 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 + self.driver.Assert.equal(len(hap_info02.split()[-1].split("-")[1].split("+")[0]), 64) + for index in range(2, 5): + self.driver.Assert.equal(hap_info01.split()[index], hap_info02.split()[index]) + self.exit_account() + + + 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 new file mode 100644 index 00000000..c79b6b6b --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.json @@ -0,0 +1,14 @@ +{ + "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 new file mode 100644 index 00000000..fa27bdb0 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.py @@ -0,0 +1,64 @@ +# 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. + +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/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.json b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.json new file mode 100644 index 00000000..e7033ac7 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py new file mode 100644 index 00000000..118779eb --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py @@ -0,0 +1,112 @@ +# 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. + +import json +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from aw import Common + + +class SubStartupAppspawnAtomservice0400(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 login_account(self): + Step("登录帐号") + setting_name = "com.example.settings" + with open(r"config/userLogin.json", 'r', encoding='UTF-8') as f: + account = json.load(f) + self.driver.AppManager.stop_app(setting_name) + self.driver.AppManager.start_app(setting_name) + self.driver.touch(BY.key("entry_image_account")) + + def exit_account(self): + Step("退出帐号") + setting_name = "com.example.settings" + self.driver.AppManager.stop_app(setting_name) + self.driver.AppManager.start_app(setting_name) + self.driver.touch(BY.key("entry_image_account")) + self.driver.swipe(UiParam.UP) + comp = self.driver.find_component(BY.key("hwid_account_center_logout_text"), scroll_target=BY.type("Scroll")) + self.driver.touch(comp) + self.driver.touch(BY.key("button_text")) + comps5 = self.driver.find_component(BY.key("advanced_dialog_button_1")) + if comps5: + self.driver.touch(comps5) + time.sleep(5) + else: + pass + + def process(self): + self.login_account() + comps1 = self.driver.find_component(BY.key("inp_hwid_login_account_name_before")) + if comps1: + self.driver.input_text(comps1, account["userName"]) + self.driver.close_soft_keyboard() + self.driver.touch(BY.text("下一步")) + comps2 = self.driver.find_component(BY.key("inp_hwid_login_password")) + self.driver.input_text(comps2, account["passWord"]) + else: + comps3 = self.driver.find_component(BY.key("inp_hwid_login_account_name")) + self.driver.clear_text(comps3) + self.driver.input_text(comps3, account["userName"]) + comps4 = self.driver.find_component(BY.key("inp_hwid_login_password")) + self.driver.input_text(comps4, account["passWord"]) + self.driver.touch(BY.key("button_text")) + self.driver.wait_for_component(BY.text("继续"), timeout=10) + self.driver.touch(BY.text("继续")) + + Step("启动元服务应用,检查目标路径是否存在") + bundle_name = "com.atomicservice.5765880207854649689" + bundle_name_start = "+auid-9E1E70ABFF4AAFE1E18AF18E0F75703713D" + "8678F9F9AB06C3B64C1CB1080615A+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) + self.exit_account() + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.json new file mode 100644 index 00000000..396df2fc --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py new file mode 100644 index 00000000..b505603a --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py @@ -0,0 +1,48 @@ +# 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. + +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver + + +class SubStartupAppspawnBase0100(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.shell("power-shell timeout -o 86400000") + + def process(self): + process_list = ["appspawn", "nwebspawn"] + for process in process_list: + pid = self.driver.System.get_pid(process) + self.driver.Assert.equal(type(pid), int) + + def teardown(self): + Step("收尾工作.................") diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.json new file mode 100644 index 00000000..2b2eb8e9 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py new file mode 100644 index 00000000..a09744d1 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py @@ -0,0 +1,60 @@ +# 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. + +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from aw import Common + + +class SubStartupAppspawnBase0200(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.shell("power-shell timeout -o 86400000") + + def process(self): + Step("安装测试hap并打开") + bundle_name = "com.example.myapplication" + hap_path = Common.sourcepath('test.hap', "sub_startup_appspawn_base") + hap = self.driver.AppManager.has_app(bundle_name) + if hap: + self.driver.AppManager.uninstall_app(bundle_name) + self.driver.AppManager.install_app(hap_path) + else: + self.driver.AppManager.install_app(hap_path) + self.driver.AppManager.start_app(bundle_name) + + result = self.driver.shell("ps -efZ|grep %s|grep -v grep" % bundle_name).split() + for i in ["u:r:debug_hap:s0", bundle_name]: + self.driver.Assert.contains(result, i) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.json new file mode 100644 index 00000000..d5b68022 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py new file mode 100644 index 00000000..8c55be33 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py @@ -0,0 +1,60 @@ +# 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. + +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from aw import Common + + +class SubStartupAppspawnBase0300(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.shell("power-shell timeout -o 86400000") + + def process(self): + Step("安装测试hap并打开") + bundle_name = "com.example.myapplication" + hap_path = Common.sourcepath('asan.hap', "sub_startup_appspawn_base") + hap = self.driver.AppManager.has_app(bundle_name) + if hap: + self.driver.AppManager.uninstall_app(bundle_name) + self.driver.AppManager.install_app(hap_path) + else: + self.driver.AppManager.install_app(hap_path) + self.driver.AppManager.start_app(bundle_name) + + result = self.driver.shell("ps -efZ|grep %s|grep -v grep" % bundle_name).split() + for i in ["u:r:debug_hap:s0", bundle_name]: + self.driver.Assert.contains(result, i) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.json new file mode 100644 index 00000000..3bb7f96a --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py new file mode 100644 index 00000000..0de12df7 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py @@ -0,0 +1,63 @@ +# 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. + +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from aw import Common + + +class SubStartupAppspawnBase0400(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.shell("power-shell timeout -o 86400000") + + def process(self): + Step("安装测试hap并打开") + bundle_name = "com.example.myapplication" + for hap in ['nweb.hap', 'nweb_asan.hap']: + hap_path = Common.sourcepath(hap, "sub_startup_appspawn_base") + hap = self.driver.AppManager.has_app(bundle_name) + if hap: + self.driver.AppManager.uninstall_app(bundle_name) + self.driver.AppManager.install_app(hap_path) + else: + self.driver.AppManager.install_app(hap_path) + self.driver.AppManager.start_app(bundle_name) + + result_dict = self.driver.shell("ps -efZ|grep %s|grep -v grep" % bundle_name).split("\n") + for result in result_dict: + if result.endswith("%s:render" % bundle_name): + result_render = result + self.driver.Assert.contains(result_render.split(), "u:r:isolated_render:s0") + self.driver.AppManager.uninstall_app(bundle_name) + + def teardown(self): + Step("收尾工作.................") diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.json new file mode 100644 index 00000000..10ed408a --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py new file mode 100644 index 00000000..16894eec --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py @@ -0,0 +1,56 @@ +# 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. + +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from aw import Common + + +class SubStartupAppspawnBase0500(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.shell("power-shell timeout -o 86400000") + + def process(self): + Step("安装测试hap并打开") + bundle_name = "com.example.inputmethod" + self.driver.AppManager.start_app(bundle_name) + pid = self.driver.System.get_pid(bundle_name) + for path in ["base", "database"]: + for i in range(1, 5): + result01 = self.driver.Storage.has_dir("/proc/%d/root/data/storage/el%d/%s" % (pid, i, path)) + result02 = self.driver.Storage.has_dir("/data/app/el%d/100/%s" % (i, path)) + self.driver.Assert.equal(result01, True) + self.driver.Assert.equal(result02, True) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.stop_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.json new file mode 100644 index 00000000..c18b00e6 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py new file mode 100644 index 00000000..27d7a797 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py @@ -0,0 +1,84 @@ +# 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. + +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from aw import Common + + +class SubStartupAppspawnBase0600(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.shell("power-shell timeout -o 86400000") + + def process(self): + Step("安装测试hap并打开") + bundle_name = "com.ohos.mytest" + clone_bundle_name = "com.ohos.mytest1" + hap_path = Common.sourcepath("mytest.hap", "sub_startup_appspawn_base") + hap = self.driver.AppManager.has_app(bundle_name) + if hap: + self.driver.AppManager.uninstall_app(bundle_name) + self.driver.AppManager.install_app(hap_path) + else: + self.driver.AppManager.install_app(hap_path) + self.driver.AppManager.start_app(bundle_name) + + for text in ["安装克隆应用", "startAbilityByAppIndex"]: + self.driver.touch(BY.text(text)) + + dict01 = { + bundle_name: "master.txt", + clone_bundle_name: "slave.txt" + } + + dict02 = { + bundle_name: "slave.txt", + clone_bundle_name: "master.txt" + } + + for i, txt in dict01.items(): + pid = self.driver.System.get_pid(i) + if i == clone_bundle_name: + self.driver.shell("touch /data/app/el2/100/base/+clone-1+%s/%s" % (bundle_name, txt)) + else: + self.driver.shell("touch /data/app/el2/100/base/%s/%s" % (i, txt)) + result = self.driver.Storage.has_file("/proc/%d/root/data/storage/el2/base/%s" % (pid, txt)) + self.driver.Assert.equal(result, True) + + for i, txt in dict02.items(): + pid = self.driver.System.get_pid(i) + result = self.driver.Storage.has_file("/proc/%d/root/data/storage/el2/base/%s" % (pid, txt)) + self.driver.Assert.equal(result, False) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.uninstall_app(bundle_name) -- Gitee From 986884e92da07cf30b7da2d02bc862c4583be20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Sat, 28 Dec 2024 14:32:05 +0800 Subject: [PATCH 094/148] add nativespawn autotest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- ...sub_startup_appspawn_nativespawn_0100.json | 12 +++ .../sub_startup_appspawn_nativespawn_0100.py | 83 ++++++++++++++ ...sub_startup_appspawn_nativespawn_0200.json | 12 +++ .../sub_startup_appspawn_nativespawn_0200.py | 82 ++++++++++++++ ...sub_startup_appspawn_nativespawn_0300.json | 12 +++ .../sub_startup_appspawn_nativespawn_0300.py | 82 ++++++++++++++ ...sub_startup_appspawn_nativespawn_0400.json | 12 +++ .../sub_startup_appspawn_nativespawn_0400.py | 82 ++++++++++++++ ...sub_startup_appspawn_nativespawn_0500.json | 12 +++ .../sub_startup_appspawn_nativespawn_0500.py | 82 ++++++++++++++ ...sub_startup_appspawn_nativespawn_0600.json | 12 +++ .../sub_startup_appspawn_nativespawn_0600.py | 83 ++++++++++++++ ...sub_startup_appspawn_nativespawn_0700.json | 12 +++ .../sub_startup_appspawn_nativespawn_0700.py | 82 ++++++++++++++ ...sub_startup_appspawn_nativespawn_0800.json | 12 +++ .../sub_startup_appspawn_nativespawn_0800.py | 83 ++++++++++++++ ...sub_startup_appspawn_nativespawn_0900.json | 12 +++ .../sub_startup_appspawn_nativespawn_0900.py | 84 +++++++++++++++ ...sub_startup_appspawn_nativespawn_1000.json | 12 +++ .../sub_startup_appspawn_nativespawn_1000.py | 91 ++++++++++++++++ ...sub_startup_appspawn_nativespawn_1100.json | 12 +++ .../sub_startup_appspawn_nativespawn_1100.py | 91 ++++++++++++++++ ...sub_startup_appspawn_nativespawn_1200.json | 12 +++ .../sub_startup_appspawn_nativespawn_1200.py | 91 ++++++++++++++++ ...sub_startup_appspawn_nativespawn_1300.json | 12 +++ .../sub_startup_appspawn_nativespawn_1300.py | 91 ++++++++++++++++ ...sub_startup_appspawn_nativespawn_1400.json | 12 +++ .../sub_startup_appspawn_nativespawn_1400.py | 90 ++++++++++++++++ ...sub_startup_appspawn_nativespawn_1500.json | 12 +++ .../sub_startup_appspawn_nativespawn_1500.py | 85 +++++++++++++++ ...sub_startup_appspawn_nativespawn_1600.json | 12 +++ .../sub_startup_appspawn_nativespawn_1600.py | 78 ++++++++++++++ ...sub_startup_appspawn_nativespawn_1700.json | 12 +++ .../sub_startup_appspawn_nativespawn_1700.py | 83 ++++++++++++++ ...sub_startup_appspawn_nativespawn_1800.json | 12 +++ .../sub_startup_appspawn_nativespawn_1800.py | 93 ++++++++++++++++ ...sub_startup_appspawn_nativespawn_1900.json | 12 +++ .../sub_startup_appspawn_nativespawn_1900.py | 102 ++++++++++++++++++ 38 files changed, 1866 insertions(+) create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.py create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.json create mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.py diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.json new file mode 100644 index 00000000..680ba7fe --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.py new file mode 100644 index 00000000..e9ebe366 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.py @@ -0,0 +1,83 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn0100(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:首次获取nativesapwn进程号") + pid1 = self.driver.System.get_pid("nativespawn") + Step("步骤5:点击start Native Process Isolated按钮") + self.driver.touch(BY.text("start Native Process Isolated")) + Step("步骤6:第二次获取nativesapwn进程号") + pid2 = self.driver.System.get_pid("nativespawn") + Step("步骤7:关闭测试应用") + self.driver.stop_app("com.acts.childprocessmanager") + Step("步骤8:第三次获取nativesapwn进程号") + pid3 = self.driver.System.get_pid("nativespawn") + Step("步骤9:预期结果校验") + self.driver.Assert.equal(pid1, None) + self.driver.Assert.not_equal(pid2, None) + self.driver.Assert.equal(pid3, None) + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.json new file mode 100644 index 00000000..35f2dbc3 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.py new file mode 100644 index 00000000..64f2ba3c --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.py @@ -0,0 +1,82 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn0200(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process按钮") + self.driver.touch(BY.text("Start Ark Process")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:获取测试应用appspawn孵化子进程pid") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:ArkProcess0") + Step("步骤7:查看数据") + res = self.driver.shell("ls -l /proc/%d/ns/net" % pid) + childres = self.driver.shell("ls -l /proc/%d/ns/net" % child_pid) + Step("步骤7:预期结果检验") + arr = res.split("-> ")[1] + childarr = childres.split("-> ")[1] + self.driver.Assert.equal(arr, childarr) + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.json new file mode 100644 index 00000000..52c04399 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.py new file mode 100644 index 00000000..32195b39 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.py @@ -0,0 +1,82 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn0300(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process按钮") + self.driver.touch(BY.text("Start Ark Process Isolated")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:获取测试应用appspawn孵化子进程pid") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:ArkProcess0") + Step("步骤7:查看数据") + res = self.driver.shell("ls -l /proc/%d/ns/net" % pid) + childres = self.driver.shell("ls -l /proc/%d/ns/net" % child_pid) + Step("步骤7:预期结果检验") + arr = res.split("-> ")[1] + childarr = childres.split("-> ")[1] + self.driver.Assert.not_equal(arr, childarr) + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.json new file mode 100644 index 00000000..53ec308d --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.py new file mode 100644 index 00000000..5f0c5173 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.py @@ -0,0 +1,82 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn0400(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process按钮") + self.driver.touch(BY.text("start Native Process")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:获取测试应用nativespawn孵化子进程pid") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") + Step("步骤7:查看数据") + res = self.driver.shell("ls -l /proc/%d/ns/net" % pid) + childres = self.driver.shell("ls -l /proc/%d/ns/net" % child_pid) + Step("步骤7:预期结果检验") + arr = res.split("-> ")[1] + childarr = childres.split("-> ")[1] + self.driver.Assert.equal(arr, childarr) + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.json new file mode 100644 index 00000000..8ac0c9f0 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.py new file mode 100644 index 00000000..3f9a7bfc --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.py @@ -0,0 +1,82 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn0500(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process按钮") + self.driver.touch(BY.text("start Native Process Isolated")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:获取测试应用nativespawn孵化子进程pid") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") + Step("步骤7:查看数据") + res = self.driver.shell("ls -l /proc/%d/ns/net" % pid) + childres = self.driver.shell("ls -l /proc/%d/ns/net" % child_pid) + Step("步骤7:预期结果检验") + arr = res.split("-> ")[1] + childarr = childres.split("-> ")[1] + self.driver.Assert.not_equal(arr, childarr) + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.json new file mode 100644 index 00000000..0cc837b1 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.py new file mode 100644 index 00000000..cfd6f864 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.py @@ -0,0 +1,83 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn0600(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process按钮") + self.driver.touch(BY.text("Start Ark Process")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:获取孵化app子进程pid") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:ArkProcess0") + Step("步骤7:测试应用沙箱路径data/storage/el1生成一个123.txt") + self.driver.shell("echo 123456789 > /proc/%d/root/data/storage/el1/123.txt" % pid) + Step("步骤8:孵化app子进程查看沙箱路径data/storage/el1") + childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/123.txt" % child_pid) + Step("步骤8:预期结果检验") + self.driver.Assert.equal(int(childres), 123456789) + self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/123.txt" % pid) + + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.json new file mode 100644 index 00000000..e524f783 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.py new file mode 100644 index 00000000..5486dd66 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.py @@ -0,0 +1,82 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn0700(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process按钮") + self.driver.touch(BY.text("Start Ark Process Isolated")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:获取测试应用appspawn孵化子进程pid") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:ArkProcess0") + Step("步骤7:测试应用沙箱路径data/storage/el1生成一个123.txt") + self.driver.shell("echo 123456789 > /proc/%d/root/data/storage/el1/123.txt" % pid) + Step("步骤8:测试应用appspawn孵化子进程查看沙箱路径data/storage/el1") + childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/123.txt" % child_pid) + Step("步骤8:预期结果检验") + self.driver.Assert.contains(childres, "root/data/storage/el1/123.txt: No such file or directory") + self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/123.txt" % pid) + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.json new file mode 100644 index 00000000..bc651422 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.py new file mode 100644 index 00000000..1a38bb0b --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.py @@ -0,0 +1,83 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn0800(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process按钮") + self.driver.touch(BY.text("start Native Process")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:孵化native子进程pid") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") + Step("步骤7:测试应用沙箱路径data/storage/el1生成一个123.txt") + self.driver.shell("echo 123456789 > /proc/%d/root/data/storage/el1/123.txt" % pid) + Step("步骤8:孵化native子进程查看沙箱路径data/storage/el1") + childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/123.txt" % child_pid) + Step("步骤8:预期结果检验") + self.driver.Assert.equal(int(childres), 123456789) + self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/123.txt" % pid) + + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.json new file mode 100644 index 00000000..4dadc000 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.py new file mode 100644 index 00000000..af214e54 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.py @@ -0,0 +1,84 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn0900(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process Isolated按钮") + self.driver.touch(BY.text("start Native Process Isolated")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:获取测试应用孵化native进程pid") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") + Step("步骤7:测试应用沙箱路径data/storage/el1生成一个123.txt") + self.driver.shell("echo 0123456789 > /proc/%d/root/data/storage/el1/123.txt" % pid) + Step("步骤8:测试应用孵化native进程查看沙箱路径data/storage/el1") + childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/123.txt" % child_pid) + Step("步骤8:预期结果检验") + self.driver.Assert.contains(childres, "root/data/storage/el1/123.txt: No such file or directory") + self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/123.txt" % pid) + + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") + diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.json new file mode 100644 index 00000000..65eb9d6c --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.py new file mode 100644 index 00000000..93161e24 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.py @@ -0,0 +1,91 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn1000(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process按钮") + self.driver.touch(BY.text("Start Ark Process")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:获取测试应用appspawn孵化子进程pid") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:ArkProcess0") + Step("步骤7:测试应用沙箱路径data/storage/el1/bundle目录下,创建2个文件夹") + self.driver.shell("mkdir /proc/%d/root/data/storage/el1/bundle/test1 /proc/%d/root/data/storage/el1/bundle/test2" % (pid, pid)) + Step("步骤8:测试应用沙箱路径data/storage/el1/bundle/tets1,创建1个test.txt文件") + self.driver.shell("echo this is test1 > /proc/%d/root/data/storage/el1/bundle/test1/test.txt" % pid) + Step("步骤9:test1挂载test2") + self.driver.shell("mount /proc/%d/root/data/storage/el1/bundle/test1 /proc/%d/root/data/storage/el1/bundle/test2" % (pid, pid)) + Step("步骤10:查看test2目录下的文件是否和test1内容一致") + res = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/test2/test.txt" % pid) + Step("步骤11:测试应用appspawn孵化子进程查看沙箱路径data/storage/el1/bundle/test2/test.txt") + childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/test2/test.txt" % child_pid) + Step("步骤12:预期结果检验") + self.driver.Assert.contains(res, "this is test1") + self.driver.Assert.contains(childres, "root/data/storage/el1/bundle/test2/test.txt: No such file or directory") + self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/bundle/test1 /proc/%d/root/data/storage/el1/bundle/test2" % (pid, pid)) + + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") + diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.json new file mode 100644 index 00000000..52e18e1c --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.py new file mode 100644 index 00000000..e31c6663 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.py @@ -0,0 +1,91 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn1100(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process Isolated按钮") + self.driver.touch(BY.text("Start Ark Process Isolated")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:获取测试应用appspawn孵化子进程pid") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:ArkProcess0") + Step("步骤7:测试应用沙箱路径data/storage/el1/bundle目录下,创建2个文件夹") + self.driver.shell("mkdir /proc/%d/root/data/storage/el1/bundle/test1 /proc/%d/root/data/storage/el1/bundle/test2" % (pid, pid)) + Step("步骤8:测试应用沙箱路径data/storage/el1/bundle/tets1,创建1个test.txt文件") + self.driver.shell("echo this is test1 > /proc/%d/root/data/storage/el1/bundle/test1/test.txt" % pid) + Step("步骤9:test1挂载test2") + self.driver.shell("mount /proc/%d/root/data/storage/el1/bundle/test1 /proc/%d/root/data/storage/el1/bundle/test2" % (pid, pid)) + Step("步骤10:查看test2目录下的文件是否和test1内容一致") + res = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/test2/test.txt" % pid) + Step("步骤11:测试应用appspawn孵化子进程查看沙箱路径data/storage/el1/bundle/test2/test.txt") + childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/test2/test.txt" % child_pid) + Step("步骤12:预期结果检验") + self.driver.Assert.contains(res, "this is test1") + self.driver.Assert.contains(childres, "root/data/storage/el1/bundle/test2/test.txt: No such file or directory") + self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/bundle/test1 /proc/%d/root/data/storage/el1/bundle/test2" % (pid, pid)) + + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") + diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.json new file mode 100644 index 00000000..ff9fc37a --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.py new file mode 100644 index 00000000..53100365 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.py @@ -0,0 +1,91 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn1200(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Native Process按钮") + self.driver.touch(BY.text("start Native Process")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:孵化native子进程pid") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") + Step("步骤7:测试应用沙箱路径data/storage/el1/bundle目录下,创建2个文件夹") + self.driver.shell("mkdir /proc/%d/root/data/storage/el1/bundle/zsj1 /proc/%d/root/data/storage/el1/bundle/zsj2" % (pid, pid)) + Step("步骤8:测试应用沙箱路径data/storage/el1/bundle/tets1,创建1个zsj.txt文件") + self.driver.shell("echo this is zsj1 > /proc/%d/root/data/storage/el1/bundle/zsj1/zsj.txt" % pid) + Step("步骤9:test1挂载test2") + self.driver.shell("mount /proc/%d/root/data/storage/el1/bundle/zsj1 /proc/%d/root/data/storage/el1/bundle/zsj2" % (pid, pid)) + Step("步骤10:查看test2目录下的文件是否和test1内容一致") + res = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/zsj2/zsj.txt" % pid) + Step("步骤11:孵化native子进程查看沙箱路径data/storage/el1/bundle/zsj2/zsj.txt") + childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/zsj2/zsj.txt" % child_pid) + Step("步骤12:预期结果检验") + self.driver.Assert.contains(res, "this is zsj1") + self.driver.Assert.contains(childres, "root/data/storage/el1/bundle/zsj2/zsj.txt: No such file or directory") + self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/bundle/zsj1 /proc/%d/root/data/storage/el1/bundle/zsj2" % (pid, pid)) + + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") + diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.json new file mode 100644 index 00000000..060f2347 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.py new file mode 100644 index 00000000..ffb58b3e --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.py @@ -0,0 +1,91 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn1300(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Native Process Isolated按钮") + self.driver.touch(BY.text("start Native Process Isolated")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:获取孵化native子进程pid") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") + Step("步骤7:测试应用沙箱路径data/storage/el1/bundle目录下,创建2个文件夹") + self.driver.shell("mkdir /proc/%d/root/data/storage/el1/bundle/zsj1 /proc/%d/root/data/storage/el1/bundle/zsj2" % (pid, pid)) + Step("步骤8:测试应用沙箱路径data/storage/el1/bundle/tets1,创建1个zsj.txt文件") + self.driver.shell("echo this is zsj1 > /proc/%d/root/data/storage/el1/bundle/zsj1/zsj.txt" % pid) + Step("步骤9:test1挂载test2") + self.driver.shell("mount /proc/%d/root/data/storage/el1/bundle/zsj1 /proc/%d/root/data/storage/el1/bundle/zsj2" % (pid, pid)) + Step("步骤10:查看test2目录下的文件是否和test1内容一致") + res = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/zsj2/zsj.txt" % pid) + Step("步骤11:孵化native子进程查看沙箱路径data/storage/el1/bundle/zsj2/zsj.txt") + childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/zsj2/zsj.txt" % child_pid) + Step("步骤12:预期结果检验") + self.driver.Assert.contains(res, "this is zsj1") + self.driver.Assert.contains(childres, "root/data/storage/el1/bundle/zsj2/zsj.txt: No such file or directory") + self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/bundle/zsj1 /proc/%d/root/data/storage/el1/bundle/zsj2" % (pid, pid)) + + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") + diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.json new file mode 100644 index 00000000..6b1aade8 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.py new file mode 100644 index 00000000..5d72bc5b --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.py @@ -0,0 +1,90 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn1400(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process Isolated按钮") + self.driver.touch(BY.text("start Native Process Isolated")) + Step("步骤5:获取测试应用pid") + self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:获取测试应用孵化native进程pid") + child_pid 1 = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") + Step("步骤7:测试应用沙箱路径data/storage/el1生成一个native.txt") + self.driver.shell("echo this is native1 > /proc/%d/root/data/storage/el1/native.txt" % child_pid 1) + childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/native.txt" % child_pid 1) + Step("步骤8:杀死孵化native进程") + self.driver.shell("kill -9 %d" % child_pid 1) + Step("步骤9:再次点击start Ark Process Isolated按钮") + self.driver.touch(BY.text("start Native Process Isolated")) + Step("步骤10:测试应用孵化native进程查看沙箱路径data/storage/el1") + child_pid 2 = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry1") + childres2 = self.driver.shell("cat /proc/%d/root/data/storage/el1/native.txt" % child_pid 2) + Step("步骤11:预期结果检验") + self.driver.Assert.contains(childres, "this is native1") + self.driver.Assert.contains(childres2, "this is native1") + self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/native.txt" % child_pid 2) + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") + diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.json new file mode 100644 index 00000000..851b5122 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.py new file mode 100644 index 00000000..63c6344d --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.py @@ -0,0 +1,85 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn1500(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process Isolated按钮") + self.driver.touch(BY.text("start Native Process Isolated")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:获取测试应用孵化native进程pid") + child_pid 1 = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") + Step("步骤7:杀死nativespawn进程") + self.driver.shell("kill -9 `pidof nativespawn`") + Step("步骤8:查询测试应用") + result = self.driver.shell("ps -ef | grep com.acts.childprocessmanager") + Step("步骤9:查询nativespawn进程号") + nativepid = self.driver.System.get_pid("nativespawn") + self.driver.Assert.contains(result, str(child_pid 1)) + self.driver.Assert.contains(result, str(pid)) + self.driver.Assert.equal(nativepid, None) + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") + diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.json new file mode 100644 index 00000000..749e6f99 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.py new file mode 100644 index 00000000..4c20f740 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.py @@ -0,0 +1,78 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn1600(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process按钮") + self.driver.touch(BY.text("start Native Process Isolated")) + Step("步骤5:获取测试应用nativespawn孵化子进程pid") + time.sleep(1) + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") + Step("步骤6:孵化的native子进程(Isolated=true)selinux标签类型") + childres = self.driver.shell("ps -efZ | grep %d | grep -v grep" % child_pid) + Step("步骤9: 预期结果校验") + self.driver.Assert.contains(childres, "u:r:isolated_render:s0") + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.json new file mode 100644 index 00000000..949a2197 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.py new file mode 100644 index 00000000..474485a7 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.py @@ -0,0 +1,83 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn1700(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:点击start Ark Process按钮") + self.driver.touch(BY.text("start Native Process")) + Step("步骤5:获取测试应用pid") + pid = self.driver.System.get_pid("com.acts.childprocessmanager") + Step("步骤6:获取测试应用nativespawn孵化子进程pid") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") + Step("步骤7:测试应用selinux标签类型") + res = self.driver.shell("ps -efZ | grep %d | grep -v grep" % pid) + Step("步骤8:孵化的native子进程(Isolated=false)selinux标签类型") + childres = self.driver.shell("ps -efZ | grep %d | grep -v grep" % child_pid) + string = res.split(" ")[0] + child_string = childres.split(" ")[0] + Step("步骤9: 预期结果校验") + self.driver.Assert.equal(string, child_string) + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.json new file mode 100644 index 00000000..b5bedb14 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.py new file mode 100644 index 00000000..a99c2ab6 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.py @@ -0,0 +1,93 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn1800(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:首次获取nativesapwn进程号") + pid1 = self.driver.System.get_pid("nativespawn") + Step("步骤5:点击start Native Process Isolated按钮") + self.driver.touch(BY.text("start Native Process Isolated")) + time.sleep(1) + Step("步骤6:再次点击start Native Process Isolated按钮") + self.driver.touch(BY.text("start Native Process Isolated")) + Step("步骤7:第二次获取nativesapwn进程号") + pid2 = self.driver.System.get_pid("nativespawn") + Step("步骤8:杀掉孵化的一个nativ进程") + child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") + self.driver.shell("kill -9 %d" % child_pid) + Step("步骤9:第三次获取nativesapwn进程号") + pid3 = self.driver.System.get_pid("nativespawn") + Step("步骤10:杀掉孵化的最后一个native子进程") + child_pid 1 = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry1") + self.driver.shell("kill -9 %d" % child_pid 1) + Step("步骤11:第四次获取nativesapwn进程号") + pid4 = self.driver.System.get_pid("nativespawn") + Step("步骤12:预期结果校验") + self.driver.Assert.equal(pid1, None) + self.driver.Assert.not_equal(pid2, None) + self.driver.Assert.not_equal(pid3, None) + self.driver.Assert.equal(pid4, None) + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.json new file mode 100644 index 00000000..77347638 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.py new file mode 100644 index 00000000..3ea853e4 --- /dev/null +++ b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.py @@ -0,0 +1,102 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiParam +from hypium.model import UiParam +from aw import Common +import time + + +class SubStartupAppspawnNativespawn1900(TestCase): + + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + Step('获取权限状态') + is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") + if ("true" in is_status): + pass + else: + Step('设置权限为true') + self.driver.shell("param set persist.sys.abilityms.multi_process_model true") + Step('重启生效') + self.driver.shell("reboot") + self.driver.System.wait_for_boot_complete() + self.driver.ScreenLock.unlock() + + def test_step1(self): + Step("步骤1:安装测试应用") + hap1 = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + hap2 = Common.sourcepath('entry-default-nativespawn1.hap', "SUB_STARTUP_STABILITY_APPSPAWN") + is_hap = self.driver.has_app("com.acts.childprocessmanager") + if(is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager") + else: + pass + is_hap = self.driver.has_app("com.acts.childprocessmanager1") + if (is_hap): + self.driver.uninstall_app("com.acts.childprocessmanager1") + else: + pass + self.driver.install_app(hap1) + self.driver.install_app(hap2) + Step("步骤2:打开测试应用1") + self.driver.start_app("com.acts.childprocessmanager") + Step("步骤3:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤4:首次获取nativesapwn进程号") + pid1 = self.driver.System.get_pid("nativespawn") + Step("步骤5:点击start Native Process Isolated按钮") + self.driver.touch(BY.text("start Native Process Isolated")) + Step("步骤6:第二次获取nativesapwn进程号") + pid2 = self.driver.System.get_pid("nativespawn") + Step("步骤7:打开测试应用2") + self.driver.start_app("com.acts.childprocessmanager1") + Step("步骤8:点击StartArk用例按钮") + self.driver.touch(BY.text("StartArk用例")) + Step("步骤9:点击start Native Process Isolated按钮") + self.driver.touch(BY.text("start Native Process Isolated")) + Step("步骤10:关闭测试应用1") + self.driver.stop_app("com.acts.childprocessmanager") + Step("步骤11:第三次获取nativesapwn进程号") + pid3 = self.driver.System.get_pid("nativespawn") + Step("步骤12:关闭测试应用1") + self.driver.stop_app("com.acts.childprocessmanager1") + Step("步骤13:第四次获取nativesapwn进程号") + pid4 = self.driver.System.get_pid("nativespawn") + Step("步骤12:预期结果校验") + self.driver.Assert.equal(pid1, None) + self.driver.Assert.not_equal(pid2, None) + self.driver.Assert.not_equal(pid3, None) + self.driver.Assert.equal(pid4, None) + + def teardown(self): + Step("收尾工作:卸载测试应用") + self.driver.uninstall_app("com.acts.childprocessmanager") + self.driver.uninstall_app("com.acts.childprocessmanager1") \ No newline at end of file -- Gitee From ac4653945a6a18bea16d1a9bf47ae56a768185ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Sat, 28 Dec 2024 15:18:24 +0800 Subject: [PATCH 095/148] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- ...sub_startup_appspawn_nativespawn_0600.json | 12 --- .../sub_startup_appspawn_nativespawn_0600.py | 83 ------------------- ...sub_startup_appspawn_nativespawn_0800.json | 12 --- .../sub_startup_appspawn_nativespawn_0800.py | 83 ------------------- 4 files changed, 190 deletions(-) delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.py diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.json deleted file mode 100644 index 0cc837b1..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.py deleted file mode 100644 index cfd6f864..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0600.py +++ /dev/null @@ -1,83 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn0600(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process按钮") - self.driver.touch(BY.text("Start Ark Process")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:获取孵化app子进程pid") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:ArkProcess0") - Step("步骤7:测试应用沙箱路径data/storage/el1生成一个123.txt") - self.driver.shell("echo 123456789 > /proc/%d/root/data/storage/el1/123.txt" % pid) - Step("步骤8:孵化app子进程查看沙箱路径data/storage/el1") - childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/123.txt" % child_pid) - Step("步骤8:预期结果检验") - self.driver.Assert.equal(int(childres), 123456789) - self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/123.txt" % pid) - - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.json deleted file mode 100644 index bc651422..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.py deleted file mode 100644 index 1a38bb0b..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0800.py +++ /dev/null @@ -1,83 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn0800(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process按钮") - self.driver.touch(BY.text("start Native Process")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:孵化native子进程pid") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") - Step("步骤7:测试应用沙箱路径data/storage/el1生成一个123.txt") - self.driver.shell("echo 123456789 > /proc/%d/root/data/storage/el1/123.txt" % pid) - Step("步骤8:孵化native子进程查看沙箱路径data/storage/el1") - childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/123.txt" % child_pid) - Step("步骤8:预期结果检验") - self.driver.Assert.equal(int(childres), 123456789) - self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/123.txt" % pid) - - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") \ No newline at end of file -- Gitee From c3053efb31a160c0d1f935a26d419a4804aef9ac Mon Sep 17 00:00:00 2001 From: handyohos Date: Mon, 30 Dec 2024 15:06:50 +0800 Subject: [PATCH 096/148] Feat: add hnp and nativespawn autotest Signed-off-by: handyohos Change-Id: Ic1f9890f7cf642589309e904f3c942397fa74d8c #IBE8GZ --- ...b_startup_appspawn_nativeinstall_0200.json | 14 ++ ...sub_startup_appspawn_nativeinstall_0200.py | 130 ++++++++++++ ...b_startup_appspawn_nativeinstall_0300.json | 14 ++ ...sub_startup_appspawn_nativeinstall_0300.py | 122 +++++++++++ ...b_startup_appspawn_nativeinstall_0400.json | 14 ++ ...sub_startup_appspawn_nativeinstall_0400.py | 86 ++++++++ ...b_startup_appspawn_nativeinstall_0500.json | 14 ++ ...sub_startup_appspawn_nativeinstall_0500.py | 88 ++++++++ ...b_startup_appspawn_nativeinstall_0600.json | 14 ++ ...sub_startup_appspawn_nativeinstall_0600.py | 113 ++++++++++ ...b_startup_appspawn_nativeinstall_0700.json | 14 ++ ...sub_startup_appspawn_nativeinstall_0700.py | 95 +++++++++ ...b_startup_appspawn_nativeinstall_0800.json | 14 ++ ...sub_startup_appspawn_nativeinstall_0800.py | 108 ++++++++++ ...b_startup_appspawn_nativeinstall_0900.json | 14 ++ ...sub_startup_appspawn_nativeinstall_0900.py | 105 +++++++++ ...b_startup_appspawn_nativeinstall_1000.json | 14 ++ ...sub_startup_appspawn_nativeinstall_1000.py | 95 +++++++++ ...b_startup_appspawn_nativeinstall_1100.json | 14 ++ ...sub_startup_appspawn_nativeinstall_1100.py | 100 +++++++++ ...b_startup_appspawn_nativeinstall_1200.json | 14 ++ ...sub_startup_appspawn_nativeinstall_1200.py | 105 +++++++++ ...b_startup_appspawn_nativeinstall_1300.json | 14 ++ ...sub_startup_appspawn_nativeinstall_1300.py | 106 ++++++++++ ...b_startup_appspawn_nativeinstall_1400.json | 14 ++ ...sub_startup_appspawn_nativeinstall_1400.py | 110 ++++++++++ ...b_startup_appspawn_nativeinstall_1500.json | 14 ++ ...sub_startup_appspawn_nativeinstall_1500.py | 112 ++++++++++ ...b_startup_appspawn_nativeinstall_1600.json | 14 ++ ...sub_startup_appspawn_nativeinstall_1600.py | 150 +++++++++++++ ...b_startup_appspawn_nativeinstall_1700.json | 14 ++ ...sub_startup_appspawn_nativeinstall_1700.py | 126 +++++++++++ ...b_startup_appspawn_nativeinstall_1800.json | 14 ++ ...sub_startup_appspawn_nativeinstall_1800.py | 86 ++++++++ ...b_startup_appspawn_nativeinstall_1900.json | 14 ++ ...sub_startup_appspawn_nativeinstall_1900.py | 122 +++++++++++ ...b_startup_appspawn_nativeinstall_2000.json | 14 ++ ...sub_startup_appspawn_nativeinstall_2000.py | 136 ++++++++++++ ...b_startup_appspawn_nativeinstall_2100.json | 14 ++ ...sub_startup_appspawn_nativeinstall_2100.py | 157 ++++++++++++++ ...b_startup_appspawn_nativeinstall_2200.json | 14 ++ ...sub_startup_appspawn_nativeinstall_2200.py | 105 +++++++++ ...b_startup_appspawn_nativeinstall_2300.json | 14 ++ ...sub_startup_appspawn_nativeinstall_2300.py | 114 ++++++++++ ...b_startup_appspawn_nativeinstall_2400.json | 14 ++ ...sub_startup_appspawn_nativeinstall_2400.py | 124 +++++++++++ ...b_startup_appspawn_nativeinstall_2500.json | 14 ++ ...sub_startup_appspawn_nativeinstall_2500.py | 136 ++++++++++++ ...b_startup_appspawn_nativeinstall_2600.json | 14 ++ ...sub_startup_appspawn_nativeinstall_2600.py | 138 ++++++++++++ ...b_startup_appspawn_nativeinstall_2700.json | 14 ++ ...sub_startup_appspawn_nativeinstall_2700.py | 152 +++++++++++++ ...b_startup_appspawn_nativeinstall_2800.json | 14 ++ ...sub_startup_appspawn_nativeinstall_2800.py | 200 ++++++++++++++++++ ...b_startup_appspawn_nativeinstall_2900.json | 14 ++ ...sub_startup_appspawn_nativeinstall_2900.py | 145 +++++++++++++ .../sub_startup_appspawn_nativepack_1000.json | 14 ++ .../sub_startup_appspawn_nativepack_1000.py | 101 +++++++++ .../sub_startup_appspawn_nativepack_1100.json | 14 ++ .../sub_startup_appspawn_nativepack_1100.py | 68 ++++++ .../sub_startup_appspawn_nativepack_1200.json | 14 ++ .../sub_startup_appspawn_nativepack_1200.py | 87 ++++++++ .../sub_startup_appspawn_nativepack_1300.json | 14 ++ .../sub_startup_appspawn_nativepack_1300.py | 76 +++++++ .../sub_startup_appspawn_nativepack_1400.json | 14 ++ .../sub_startup_appspawn_nativepack_1400.py | 122 +++++++++++ .../sub_startup_appspawn_nativepack_1500.json | 14 ++ .../sub_startup_appspawn_nativepack_1500.py | 73 +++++++ .../sub_startup_appspawn_nativepack_1600.json | 14 ++ .../sub_startup_appspawn_nativepack_1600.py | 111 ++++++++++ .../sub_startup_appspawn_nativepack_1700.json | 14 ++ .../sub_startup_appspawn_nativepack_1700.py | 122 +++++++++++ .../sub_startup_appspawn_nativepack_1800.json | 14 ++ .../sub_startup_appspawn_nativepack_1800.py | 129 +++++++++++ .../sub_startup_appspawn_nativepack_1900.json | 14 ++ .../sub_startup_appspawn_nativepack_1900.py | 121 +++++++++++ .../sub_startup_appspawn_nativepack_2000.json | 14 ++ .../sub_startup_appspawn_nativepack_2000.py | 79 +++++++ .../sub_startup_appspawn_nativepack_2100.json | 14 ++ .../sub_startup_appspawn_nativepack_2100.py | 99 +++++++++ ...startup_appspawn_nativeuninstall_0300.json | 14 ++ ...b_startup_appspawn_nativeuninstall_0300.py | 108 ++++++++++ ...startup_appspawn_nativeuninstall_0400.json | 14 ++ ...b_startup_appspawn_nativeuninstall_0400.py | 123 +++++++++++ ...startup_appspawn_nativeuninstall_0500.json | 14 ++ ...b_startup_appspawn_nativeuninstall_0500.py | 129 +++++++++++ ...startup_appspawn_nativeuninstall_0600.json | 14 ++ ...b_startup_appspawn_nativeuninstall_0600.py | 147 +++++++++++++ ...startup_appspawn_nativeuninstall_0700.json | 14 ++ ...b_startup_appspawn_nativeuninstall_0700.py | 143 +++++++++++++ .../sub_startup_appspawn_hnpinstall_0100.json | 12 ++ .../sub_startup_appspawn_hnpinstall_0100.py | 74 +++++++ .../sub_startup_appspawn_hnpinstall_0200.json | 12 ++ .../sub_startup_appspawn_hnpinstall_0200.py | 68 ++++++ .../sub_startup_appspawn_hnpinstall_0300.json | 12 ++ .../sub_startup_appspawn_hnpinstall_0300.py | 77 +++++++ .../sub_startup_appspawn_hnpinstall_0400.json | 12 ++ .../sub_startup_appspawn_hnpinstall_0400.py | 72 +++++++ .../sub_startup_appspawn_hnpinstall_0500.json | 12 ++ .../sub_startup_appspawn_hnpinstall_0500.py | 74 +++++++ .../sub_startup_appspawn_hnpinstall_0600.json | 12 ++ .../sub_startup_appspawn_hnpinstall_0600.py | 74 +++++++ .../sub_startup_appspawn_hnpinstall_0700.json | 12 ++ .../sub_startup_appspawn_hnpinstall_0700.py | 75 +++++++ .../sub_startup_appspawn_hnpinstall_0800.json | 12 ++ .../sub_startup_appspawn_hnpinstall_0800.py | 78 +++++++ .../sub_startup_appspawn_hnpinstall_0900.json | 12 ++ .../sub_startup_appspawn_hnpinstall_0900.py | 71 +++++++ 108 files changed, 6605 insertions(+) create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.py create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.json create mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.py create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.json create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.py create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.json create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.py create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.json create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.py create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.json create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.py create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.json create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.py create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.json create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.py create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.json create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.py create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.json create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.py create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.json create mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.py diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.json new file mode 100644 index 00000000..5eb12fdc --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0200.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.py new file mode 100644 index 00000000..772960de --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.py @@ -0,0 +1,130 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0200(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1" + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # hnp进程安装传参校验 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("执行./hnp install") + result = self.driver.shell( + f"{self.hnp_commamd} install") + self.driver.Assert.contains(result, "native manager process exit. ret=8392706") + self.driver.Assert.contains(result, "[ERROR][HNP]hnp install params invalid,uid[(null)],hnp src path[(null)], package name[(null)]") + + Step("执行./hnp install -u 300, 只传userId") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392706 ") + + Step("执行./hnp install -p baidu, 只传应用软件名") + result = self.driver.shell( + f"{self.hnp_commamd} install -p baidu") + self.driver.Assert.contains(result, + "[ERROR][HNP]hnp install params invalid,uid[(null)]," + "hnp src path[(null)], package name[baidu]") + + Step("执行./hnp install -i hnppath, 只传安装路径") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public/ -n hnp_test1 -v 1.3") + self.driver.Assert.contains(result, "linkNum=0, ret=0") + result = self.driver.shell(f"find {self.pack_out_path}/public/ -name hnp_test1.hnp") + self.driver.Assert.contains(result, f"{self.pack_out_path}/public/hnp_test1.hnp") + + result = self.driver.shell( + f"{self.hnp_commamd} install -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[ERROR][HNP]hnp install params invalid," + "uid[(null)],hnp src path[/data/hnp_test/pack_output], " + "package name[(null)]") + + Step("执行./hnp install -f, 只传-f") + result = self.driver.shell( + f"{self.hnp_commamd} install -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392706") + + Step("执行./hnp uninstall") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall") + self.driver.Assert.contains(result, + "[ERROR][HNP]hnp uninstall params invalid uid[(null)], package name[(null)]") + + Step("执行./hnp pack") + result = self.driver.shell( + f"{self.hnp_commamd} pack") + self.driver.Assert.contains(result, "[ERROR][HNP]invalid cmd!. cmd:pack") + + Step("执行./hnp help") + result = self.driver.shell( + f"{self.hnp_commamd} help") + self.driver.Assert.contains(result, "install: install one hap package") + self.driver.Assert.contains(result, "uninstall: uninstall one hap package") + + Step("执行./hnp -h") + result = self.driver.shell( + f"{self.hnp_commamd} -h") + self.driver.Assert.contains(result, "install: install one hap package") + self.driver.Assert.contains(result, "uninstall: uninstall one hap package") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.json new file mode 100644 index 00000000..1e65f616 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0300.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.py new file mode 100644 index 00000000..36d335ec --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.py @@ -0,0 +1,122 @@ +# 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. + +import os +from aw import Common +from hypium import * +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0300(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" + self.hnp_public_dir = "hnppublic/bin" + self.hnp_private_dir = "hnp/baidu/bin" + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # hnp进程安装,hnp包路径异常场景 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("安装软件包时,hnp包路径不存在") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i /data/empty_path/ -f") + self.driver.Assert.contains(result, "[ERROR][HNP]hnp install opendir:/data/empty_path/ unsuccess, errno=2") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392968") + + Step("安装软件包时,hnp包路径长度等于4096") + dir_temp = "/data/" + Common.randomGenerateStingByLen(4090) + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {dir_temp} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392968") + + Step("安装软件包时,hnp包路径长度大于4096") + dir_temp = "/data/" + Common.randomGenerateStingByLen(4096) + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {dir_temp} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392968") + + Step("安装软件包时,hnp包路径中存在非法字符") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i /data/empty**#…………_path/ -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392968") + + Step("安装软件包时,安装路径为空文件夹") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + + Step("安装软件包时没有公有或者私有数据文件夹") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path} -n compute -v 1.3") + self.driver.Assert.contains(result, "linkNum=0, ret=0") + result = self.driver.shell(f"find {self.pack_out_path} -name compute.hnp") + self.driver.Assert.contains(result, f"{self.pack_out_path}/compute.hnp") + + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + + Step("验证软链接是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add 2") + self.driver.Assert.contains(result, "add: inaccessible or not found") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_private_dir}/add 2") + self.driver.Assert.contains(result, "add: inaccessible or not found") + + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.json new file mode 100644 index 00000000..a6ab7e34 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0400.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.py new file mode 100644 index 00000000..b3b6ad8c --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.py @@ -0,0 +1,86 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0400(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # hnp进程安装,保存路径异常场景 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("将compute工具进行打包") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public -n compute -v 1.0") + self.driver.Assert.contains(result, "linkNum=0, ret=0") + + Step("保存路径不存在") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 301 -i {self.pack_out_path} -p baidu -f") + self.driver.Assert.contains(result, "hnp install uid path[/data/app/el1/bundle/301] is not exist") + + Step("usrId为字符串") + result = self.driver.shell( + f"{self.hnp_commamd} install -u string -i {self.pack_out_path} -p baidu -f") + self.driver.Assert.contains(result, "[ERROR][HNP]hnp install arg uid[string] invalid") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.json new file mode 100644 index 00000000..e133c374 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0500.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.py new file mode 100644 index 00000000..f920ee93 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.py @@ -0,0 +1,88 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0500(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output/" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + # 安装用户usrId = 0的场景 & 安装工具为1个的场景 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("将compute工具进行打包") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public -n compute -v 1.0") + self.driver.Assert.contains(result, "linkNum=0, ret=0") + + Step("安装软件时usrId为0") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 0 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + + Step("校验安装工具生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/0/{self.hnp_public_dir}/add") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + else: + pass + + Step("卸载安装的工具") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 0 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.json new file mode 100644 index 00000000..eee9bb51 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0600.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.py new file mode 100644 index 00000000..86ce6f4e --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.py @@ -0,0 +1,113 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0600(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello"] + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 安装目录下存在多个hnp包测试 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("打包两个工具 compute & printfHello") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public -n compute -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path}/public -n printfHello -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("批量安装compute、printfHello工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + + Step("验证软链接是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") + self.driver.Assert.contains(result, "End: 1 - 1 = 0") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/multiplication") + self.driver.Assert.contains(result, "End: 1 * 1 = 1") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello 2") + self.driver.Assert.contains(result, "****************hello**************") + + Step("卸载安装的工具") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "hnp uninstall end! ret=0") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello 2") + self.driver.Assert.contains(result, "printfHello: inaccessible or not found") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.json new file mode 100644 index 00000000..c8024766 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0700.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.py new file mode 100644 index 00000000..703e7c98 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.py @@ -0,0 +1,95 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0700(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello" + self.hnp_public_dir = "hnppublic/bin" + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 打包文件未设置软链接路径,安装hnp包时可执行文件在非bin目录下场景 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建一个空目录temp_dir,该目录下存在一个二进制文件printfHello") + self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/") + self.driver.shell(f"cp {self.native_path}/bin/* {self.work_space_path}/temp_dir/") + + Step("打包temp_dir为test.hnp包") + result = self.driver.shell(f"{self.hnpcli_commamd} pack -i {self.work_space_path}/temp_dir/ " + f"-o {self.pack_out_path}/public -n test -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("安装test.hnp") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}/ -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + + Step("验证软链接是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello 2") + self.driver.Assert.contains(result, "printfHello: inaccessible or not found") + + Step("验证是否存在test.org") + result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic -name test.org") + self.driver.Assert.contains(result, "test.org") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.json new file mode 100644 index 00000000..2c273d11 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0800.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.py new file mode 100644 index 00000000..7168e5e8 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.py @@ -0,0 +1,108 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0800(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello"] + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 打包文件未设置软链接路径,安装hnp包时可执行文件在bin目录,且bin目录下同时存在一个bin目录,第二个bin目录下存在二进制的测试场景 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建一个temp_dir目录,创建bin/bin目录,bin目录下分别存在一个二进制") + self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/") + self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/bin/") + self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/bin/bin/") + self.driver.shell(f"cp {self.native_path[1]}/bin/printfHello {self.work_space_path}/temp_dir/bin") + self.driver.shell(f"cp {self.native_path[0]}/bin/add {self.work_space_path}/temp_dir/bin/bin") + + Step("打包该native文件为test.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.work_space_path}/temp_dir/ -o " + f"{self.pack_out_path}/public -n test -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("强制安装test.hnp") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + + Step("校验bin/printfHello工具生效,bin/bin/add未生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello 2") + self.driver.Assert.contains(result, "****************hello**************") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") + self.driver.Assert.contains(result, "add: inaccessible or not found") + + Step("卸载安装的工具") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("清除安装内容") + self.driver.shell(f"rm -rf {self.work_space_path}/temp_dir/") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.json new file mode 100644 index 00000000..dea6af44 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0900.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.py new file mode 100644 index 00000000..e2406b4f --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.py @@ -0,0 +1,105 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0900(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 打包文件未设置软链接路径,安装hnp包时可执行文件在bin目录,且bin目录下仅存在一个文件夹 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建一个temp_dir目录,创建bin/test目录") + self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/") + self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/bin/") + self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/bin/test/") + + Step("打包该native文件为test.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.work_space_path}/temp_dir/ " + f"-o {self.pack_out_path}/public -n test -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("强制安装test.hnp") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + + Step("验证是否存在test.org") + result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic -name test.org") + self.driver.Assert.contains(result, "test.org") + + result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic -name bin") + self.driver.Assert.contains(result, "bin") + + Step("验证bin目录下是否存在test文件夹") + result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic/bin -name test") + assert ("test" not in result) == True + + Step("清除安装内容") + self.driver.shell(f"rm -rf {self.work_space_path}/temp_dir/") + + Step("卸载安装的工具") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.json new file mode 100644 index 00000000..7cdabaeb --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1000.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.py new file mode 100644 index 00000000..2fa19067 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.py @@ -0,0 +1,95 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1000(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/private') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 需要安装的hnp为空文件 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建一个空文件夹empty_dir") + self.driver.shell(f"mkdir {self.work_space_path}/empty_dir/") + + Step("打包该native文件为test.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.work_space_path}/empty_dir/ " + f"-o {self.pack_out_path}/private -n empty -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("强制安装test.hnp") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + + Step("验证是否存在test.org") + result = self.driver.shell(f"find {self.default_install_root_path}/300/hnp/baidu -name empty.org") + self.driver.Assert.contains(result, "empty.org") + + Step("卸载安装的工具") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + + self.driver.shell(f"rm -rf {self.work_space_path}/empty_dir/") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.json new file mode 100644 index 00000000..16b1c327 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1100.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.py new file mode 100644 index 00000000..21493dd6 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.py @@ -0,0 +1,100 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1100(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1" + self.hnp_public_dir = "hnppublic/bin" + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/private') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 安装单个hnp中存在0软链接 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("打包的sample1包为sample1.hnp,该native包中bin文件下为非可执行文件") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/private -n sample1 -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("强制安装sample1.hnp") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("验证是否存在sample1.org") + result = self.driver.shell(f"find {self.default_install_root_path}/300/hnp/baidu -name sample1.org") + self.driver.Assert.contains(result, "sample1.org") + + Step("验证hnp/baidu/bin目录下是否存在sample.txt") + result = self.driver.shell( + f"find {self.default_install_root_path}/300/hnp/baidu/bin -name sample.txt") + self.driver.Assert.contains(result, "sample.txt") + + Step("卸载安装的工具") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + + result = self.driver.shell( + f"find {self.default_install_root_path}/300/hnp/baidu/bin -name sample.txt") + self.driver.Assert.contains(result, "No such file or directory") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.json new file mode 100644 index 00000000..e7c27227 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1200.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.py new file mode 100644 index 00000000..82ada481 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.py @@ -0,0 +1,105 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1200(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 安装单个hnp中存在1个软链接,软链接文件非可执行文件 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建配置文件,存在一个软链接,软链接类型.txt文件") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/sample.txt" + hnp_cfg_data['install']['links'][0]["target"] = "sample" + hnp_cfg_data['name'] = "sample" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) + + Step("打包sample1.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("强制安装sample1.hnp") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("验证hnp/hnppublic/bin目录下是否存在sample") + result = self.driver.shell(f"find {self.default_install_root_path}/300/{self.hnp_public_dir} -name sample") + self.driver.Assert.contains(result, f"sample") + + Step("卸载安装的工具") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.json new file mode 100644 index 00000000..323bacee --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1300.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.py new file mode 100644 index 00000000..cd4f1bcc --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.py @@ -0,0 +1,106 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1300(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 安装单个hnp中存在1个软链接,软链接文件为文件夹 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建配置文件,存在一个软链接,软链接为文件夹") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin" + hnp_cfg_data['install']['links'][0]["target"] = "printfSymbol_bin" + hnp_cfg_data['name'] = "printfSymbol_bin" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) + + Step("打包printfSymbol_bin.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("强制安装printfSymbol_bin.hnp") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("校验安装printfSymbol_bin.hnp是否成功,是否存在printfSymbol_bin软链") + result = self.driver.shell(f"find {self.default_install_root_path}/300/{self.hnp_public_dir} " + f"-name printfSymbol_bin") + self.driver.Assert.contains(result, "printfSymbol_bin") + + Step("卸载安装的工具") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.json new file mode 100644 index 00000000..64d18a9f --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1400.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.py new file mode 100644 index 00000000..7402fad8 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.py @@ -0,0 +1,110 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1400(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 安装单个hnp中存在1个软链接,软链接文件为一个bin文件 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建配置文件,存在一个软链接,软链接路径指向其中一个bin文件") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/add" + hnp_cfg_data['install']['links'][0]["target"] = "add" + hnp_cfg_data['name'] = "add" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) + + Step("打包add.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("强制安装add.hnp") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("验证软链接是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") + self.driver.Assert.contains(result, "del: inaccessible or not found") + + Step("卸载安装的工具") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.json new file mode 100644 index 00000000..b7cbc767 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1500.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.py new file mode 100644 index 00000000..a0cbdd74 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.py @@ -0,0 +1,112 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1500(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 安装单个hnp中存在2软链接,全部指向存在文件 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建配置文件,hnp中存在3个bin文件,2个软链接,软链接路径分别指向其中bin文件") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/add" + hnp_cfg_data['install']['links'][0]["target"] = "add" + hnp_cfg_data['install']['links'].append({"source": "bin/del", "target": "del"}) + hnp_cfg_data['name'] = "compute" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) + + Step("打包compute.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public " + f"-cfg {self.work_space_path}/compute.json") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("强制安装compute.hnp") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("验证安装compute.hnp是否成功,软链接是否可执行") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") + self.driver.Assert.contains(result, "End: 1 - 1 = 0") + + Step("卸载安装的工具") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.json new file mode 100644 index 00000000..9975cf61 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1600.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.py new file mode 100644 index 00000000..f2447b6c --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.py @@ -0,0 +1,150 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1600(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/readCfgFile", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol"] + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 执行安装包下存在3个hnp包,全部包含软链接 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建compute工具配置文件,存在3个bin文件,3个软链接,软链接路径分别指向其中bin文件") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/add" + hnp_cfg_data['install']['links'][0]["target"] = "add" + hnp_cfg_data['install']['links'].append({"source": "bin/del", "target": "del"}) + hnp_cfg_data['install']['links'].append({"source": "bin/multiplication", "target": "multiplication"}) + hnp_cfg_data['name'] = "compute" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + + Step("创建readCfgFile工具配置文件,存在1个bin文件,1个软链接,软链接路径指向bin文件") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/readCfgFile" + hnp_cfg_data['install']['links'][0]["target"] = "readCfgFile" + hnp_cfg_data['name'] = "readCfgFile" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[1]) + + Step("创建printfSymbol工具配置文件,存在1个bin文件,1个软链接,软链接路径指向bin文件") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/printfSymbol" + hnp_cfg_data['install']['links'][0]["target"] = "printfSymbol" + hnp_cfg_data['name'] = "printfSymbol" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[2]) + + Step("打包compute.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包readCfgFile.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包printfSymbol.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[2]} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("批量安装compute & printfHello & printfSymbol工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("校验设置软链接是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") + self.driver.Assert.contains(result, "End: 1 - 1 = 0") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/multiplication") + self.driver.Assert.contains(result, "End: 1 * 1 = 1") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfSymbol") + self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/readCfgFile") + self.driver.Assert.contains(result, "cfg file test test test") + + Step("卸载安装好的native软件包") + self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.json new file mode 100644 index 00000000..7ec4c65e --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1700.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.py new file mode 100644 index 00000000..b7ebcc24 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.py @@ -0,0 +1,126 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1700(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/readCfgFile", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol"] + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 执行安装包下存在3个hnp包,全部不包含软连接配置 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("打包compute.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public -n compute -v 1.2") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包readCfgFile.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[1]} " + f"-o {self.pack_out_path}/public -n readCfgFile -v 1.2") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包printfSymbol.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[2]} " + f"-o {self.pack_out_path}/public -n printfSymbol -v 1.2") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("批量安装compute & printfHello & printfSymbol工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("校验设置软链接是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") + self.driver.Assert.contains(result, "End: 1 - 1 = 0") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/multiplication") + self.driver.Assert.contains(result, "End: 1 * 1 = 1") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfSymbol") + self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/readCfgFile") + self.driver.Assert.contains(result, "cfg file test test test") + + Step("卸载安装好的native软件包") + self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.json new file mode 100644 index 00000000..5090497d --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1800.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.py new file mode 100644 index 00000000..5a2f84b9 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.py @@ -0,0 +1,86 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common +import shutil + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1800(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 安装的native包非hnpcli工具压缩文件 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建一个临时native包") + os.makedirs(f"{self.current_path}/test/") + os.makedirs(f"{self.current_path}/test/bin") + Common.writeDateToFile(f"{self.current_path}/test/bin/test.txt", "testtesttesttest") + + Step("使用zip工具压缩native包,名称为test.hnp") + Common.zip_folder("test", f"{self.current_path}/test.hnp") + self.driver.push_file(f"{self.current_path}\\test.hnp", f"{self.pack_out_path}/public") + Common.deleteFile(f"{self.current_path}\\test.hnp") + shutil.rmtree(f"{self.current_path}/test/") + + Step("安装test.hnp包") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[ERROR][HNP]hnp cfg file not found.") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.json new file mode 100644 index 00000000..bf4d7ffb --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1900.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.py new file mode 100644 index 00000000..377a5b22 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.py @@ -0,0 +1,122 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1900(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol"] + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 安装的native包对应的软链接名称相同 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建printfHello工具配置文件,软连接名称为printfHello") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/printfHello" + hnp_cfg_data['install']['links'][0]["target"] = "printfHello" + hnp_cfg_data['name'] = "printfHello" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + + Step("创建printfSymbol工具配置文件,软连接名称为printfHello") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/printfSymbol" + hnp_cfg_data['install']['links'][0]["target"] = "printfHello" + hnp_cfg_data['name'] = "printfSymbol" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[1]) + + Step("打包printfHello工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包printfSymbol工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("安装软链接同名工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("验证软连接是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello") + self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") + + Step("卸载安装好的native软件包") + self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello") + self.driver.Assert.contains(result, "printfHello: inaccessible or not found") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.json new file mode 100644 index 00000000..f693122b --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2000.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.py new file mode 100644 index 00000000..31a0acfb --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.py @@ -0,0 +1,136 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2000(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/readCfgFile"] + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/private') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 重复安装名称相同,版本相同的工具 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建compute工具配置文件,软连接名称为add") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/add" + hnp_cfg_data['install']['links'][0]["target"] = "add" + hnp_cfg_data['name'] = "compute" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + + Step("创建readCfgFile工具配置文件,软连接名称为readCfgFile") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/readCfgFile" + hnp_cfg_data['install']['links'][0]["target"] = "readCfgFile" + hnp_cfg_data['name'] = "readCfgFile" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[1]) + + Step("打包printfHello工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/private") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包printfSymbol工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path}/private") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("安装compute & readCfgFile工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("验证工具是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/baidu/bin/readCfgFile") + self.driver.Assert.contains(result, "cfg file test test test") + + Step("重复安装compute & readCfgFile工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393476 ") + + Step("重复强安装compute & readCfgFile工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/baidu/bin/readCfgFile") + self.driver.Assert.contains(result, "cfg file test test test") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/baidu/bin/add") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + Step("卸载安装好的native软件包") + self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.json new file mode 100644 index 00000000..e57ad7f4 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2100.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.py new file mode 100644 index 00000000..f60162a9 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.py @@ -0,0 +1,157 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2100(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/readCfgFile", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello"] + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 重复安装相同名称,版本不同的安装工具 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建compute工具配置文件,软连接名称为add") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/add" + hnp_cfg_data['install']['links'][0]["target"] = "add" + hnp_cfg_data['name'] = "compute" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + + Step("创建readCfgFile工具配置文件,软连接名称为readCfgFile") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/readCfgFile" + hnp_cfg_data['install']['links'][0]["target"] = "readCfgFile" + hnp_cfg_data['name'] = "readCfgFile" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[1]) + + Step("打包printfHello工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包printfSymbol工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("安装compute & readCfgFile工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("安装的新的native.hnp") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/printfHello" + hnp_cfg_data['install']['links'][0]["target"] = "printfHello" + hnp_cfg_data['name'] = "readCfgFile" + hnp_cfg_data['version'] = "2.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[2]) + + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[2]} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("重复非强制安装readCfgFile 2.0版本工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393476 ") + + Step("重复强制安装readCfgFile 2.0版本工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("验证工具是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello 2") + self.driver.Assert.contains(result, "****************hello**************") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/readCfgFile") + self.driver.Assert.contains(result, "readCfgFile: inaccessible or not found") + + result = self.driver.shell( + f"find {self.default_install_root_path}/300/hnppublic/readCfgFile.org/ -name readCfgFile_1.0") + assert ("multiplication" not in result) == True + + result = self.driver.shell( + f"find {self.default_install_root_path}/300/hnppublic/readCfgFile.org/ -name readCfgFile_2.0") + self.driver.Assert.contains(result, "readCfgFile_2.0") + + Step("卸载安装好的native软件包") + self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.json new file mode 100644 index 00000000..d5183678 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2200.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.py new file mode 100644 index 00000000..3dcc13ae --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.py @@ -0,0 +1,105 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2200(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 安装hnp存在两个软链接,不同的软链接路径,相同的配置名称 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建compute工具配置文件,工具add的软连接名称为compute,工具del的软连接名称为compute") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/add" + hnp_cfg_data['install']['links'][0]["target"] = "compute" + hnp_cfg_data['install']['links'].append({"source": "bin/del", "target": "compute"}) + hnp_cfg_data['name'] = "compute" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) + + Step("打包compute工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("安装compute工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("验证工具是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/compute") + self.driver.Assert.contains(result, "End: 1 - 1 = 0") + + Step("卸载安装好的native软件包") + self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.json new file mode 100644 index 00000000..690e61cc --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2300.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.py new file mode 100644 index 00000000..d9129f4a --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.py @@ -0,0 +1,114 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2300(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 重复安装hnp中的软链接无target name + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建compute工具配置文件,工具del的软连接名称为del_temp,工具add、multiplication无软链接name") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/del" + hnp_cfg_data['install']['links'][0]["target"] = "del_temp" + hnp_cfg_data['install']['links'].append({"source": "bin/add"}) + hnp_cfg_data['install']['links'].append({"source": "bin/multiplication"}) + hnp_cfg_data['name'] = "compute_no_target" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) + + Step("打包compute_no_target.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("安装compute_no_target工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("验证工具是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del_temp") + self.driver.Assert.contains(result, "End: 1 - 1 = 0") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/multiplication") + self.driver.Assert.contains(result, "End: 1 * 1 = 1") + + Step("卸载安装好的native软件包") + self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.json new file mode 100644 index 00000000..62eab870 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2400.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.py new file mode 100644 index 00000000..7d518c3c --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.py @@ -0,0 +1,124 @@ +# 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. + +from devicetest.core.test_case import Step, TestCase +from hypium import * +import os +import time +import threading +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2400(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + def worker(self): + Step("执行安装后的软件") + self.driver.shell(f"chmod +x /data/service/hnp/compute.org/compute_1.0/bin/add") + result = self.driver.shell( + f"./data/service/hnp/compute.org/compute_1.0/bin/add 4") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + # 重复安装hnp包时,工具正在使用 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建compute工具配置文件,工具add的软连接名称为compute,工具add的软连接名称为compute") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/add" + hnp_cfg_data['install']['links'][0]["target"] = "compute" + hnp_cfg_data['version'] = "1.0" + hnp_cfg_data['name'] = "compute" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) + + Step("打包compute工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + self.driver.shell(f'mkdir -p /data/service/hnp/compute.org/compute_1.0/') + self.driver.shell(f'cp -r {self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute/ ' + f'/data/service/hnp/compute.org/compute_1.0/') + + Step("安装compute工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("运行安装工具中的compute程序") + t1 = threading.Thread(target=self.worker) + t1.start() + time.sleep(1) + + Step("重复强制安装相同版本的hnp包") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + t1.join() + + Step("待程序运行结束后卸载安装好的native软件包") + self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.shell(f'rm -rf /data/service/hnp') + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.json new file mode 100644 index 00000000..414358a2 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2500.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.py new file mode 100644 index 00000000..f4b2e5b5 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.py @@ -0,0 +1,136 @@ +# 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. + +import os +import time +import threading +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2500(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def worker(self): + Step("执行安装后的软件") + self.driver.shell(f"chmod +x /data/service/hnp/compute.org/compute_1.0/bin/add") + result = self.driver.shell( + f"./data/service/hnp/compute.org/compute_1.0/bin/add 10") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 重复安装升级版本的hnp包时,工具正在使用 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ALN" in device): + Step("创建compute工具配置文件,工具add的软连接名称为compute") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/add" + hnp_cfg_data['install']['links'][0]["target"] = "compute" + hnp_cfg_data['version'] = "1.0" + hnp_cfg_data['name'] = "compute" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) + + Step("打包compute工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + self.driver.shell(f'mkdir -p /data/service/hnp/compute.org/compute_1.0/') + self.driver.shell(f'cp -r {self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute/bin ' + f'/data/service/hnp/compute.org/compute_1.0/') + + Step("安装compute工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + t1 = threading.Thread(target=self.worker) + t1.start() + time.sleep(1) + Step("创建compute工具配置文件,工具del的软连接名称为compute,版本为2.0") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/del" + hnp_cfg_data['install']['links'][0]["target"] = "del" + hnp_cfg_data['version'] = "2.0" + hnp_cfg_data['name'] = "compute" + self.driver.shell(f"rm {self.native_path}/hnp.json") + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) + + Step("打包升级后的compute.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("重复强制安装不同版本的hnp包") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[ERROR][HNP]hnp install path is running now,") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392978") + t1.join() + + Step("卸载安装好的native软件包") + self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.json new file mode 100644 index 00000000..e0193c70 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2600.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.py new file mode 100644 index 00000000..96d84f6d --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.py @@ -0,0 +1,138 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2600(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + self.driver.shell(f'mkdir {self.pack_out_path}/private') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 私有路径与公有路径下安装相同工具 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("打包compute.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public -n compute -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/private -n compute -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("美团用户安装compute工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p meituan -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("验证meituan下是否存在compute.org") + result = self.driver.shell(f"find {self.default_install_root_path}/300/hnp/meituan -name compute.org") + self.driver.Assert.contains(result, "compute.org") + + result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic -name compute.org") + self.driver.Assert.contains(result, "compute.org") + + Step("验证私有路径软链接是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/meituan/bin/del") + self.driver.Assert.contains(result, "End: 1 - 1 = 0") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/meituan/bin/add") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/meituan/bin/multiplication") + self.driver.Assert.contains(result, "End: 1 * 1 = 1") + + Step("验证公有路径软链接是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") + self.driver.Assert.contains(result, "End: 1 - 1 = 0") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/multiplication") + self.driver.Assert.contains(result, "End: 1 * 1 = 1") + + Step("卸载美团应用安装软件") + result = self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p meituan") + print("卸载", result) + + Step("验证meituan下是否存在compute.org") + result = self.driver.shell(f"find {self.default_install_root_path}/300/hnp/meituan -name compute.org") + assert ("compute.org" not in result) == True + + Step("验证公有路径下是否存在compute.org") + result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic -name compute.org") + assert ("compute.org" not in result) == True + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.json new file mode 100644 index 00000000..033da834 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2700.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.py new file mode 100644 index 00000000..35042cc3 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.py @@ -0,0 +1,152 @@ +# 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. + +import os +import time +from hypium import * +import threading +from aw import Common +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2700(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/readCfgFile", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def worker(self): + Step("执行安装后的软件") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add 4") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + self.driver.shell(f'mkdir {self.pack_out_path}/private') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 应用程序安装不同的软件(公有 + 私有) + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("打包compute工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public -n compute -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("百度安装compute工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包printfHello工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[3]} " + f"-o {self.pack_out_path}/private -n printfHello -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包printfSymbol工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[2]} " + f"-o {self.pack_out_path}/public -n printfSymbol -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("非强制增量安装软件") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + + Step("非强制重复安装软件") + self.driver.shell(f'rm {self.pack_out_path}/public/compute.hnp') + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393476 ") + + Step("验证软链接是否生效") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/baidu/bin/printfHello 2") + self.driver.Assert.contains(result, "****************hello**************") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") + self.driver.Assert.contains(result, "End: 1 - 1 = 0") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/multiplication") + self.driver.Assert.contains(result, "End: 1 * 1 = 1") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfSymbol") + self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") + + Step("卸载百度应用软件") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + self.driver.shell(f'rm /data/service/el1/startup/hnp_info.json') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.json new file mode 100644 index 00000000..78f5e5ea --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2800.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.py new file mode 100644 index 00000000..48ef5f91 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.py @@ -0,0 +1,200 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2800(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def worker(self): + Step("执行安装后的软件") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add 4") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + self.driver.shell(f'mkdir {self.pack_out_path}/private') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 不同应用程序安装不同的软件 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("打包compute工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public -n compute -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包printfHello工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[1]} " + f"-o {self.pack_out_path}/private -n printfHello -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("baidu应用软件安装程序") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("meituan应用软件安装程序") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p meituan -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("校验安装工具可用") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/baidu/bin/printfHello 2") + self.driver.Assert.contains(result, "") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/meituan/bin/printfHello 2") + self.driver.Assert.contains(result, "") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") + self.driver.Assert.contains(result, "End: 1 - 1 = 0") + + Step("打包printfSymbol工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[2]} " + f"-o {self.pack_out_path}/private -n printfSymbol -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("强制安装elema应用软件安装程序") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p elema -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("校验安装工具可用") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/baidu/bin/printfHello 2") + self.driver.Assert.contains(result, "****************hello**************") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/elema/bin/printfHello 2") + self.driver.Assert.contains(result, "****************hello**************") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/meituan/bin/printfHello 2") + self.driver.Assert.contains(result, "****************hello**************") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/elema/bin/printfSymbol") + self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") + self.driver.Assert.contains(result, "End: 1 - 1 = 0") + + Step("卸载美团与百度安装的软件") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p meituan") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/baidu/bin/printfHello 2") + self.driver.Assert.contains(result, "printfHello: inaccessible or not found") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/meituan/bin/printfHello 2") + self.driver.Assert.contains(result, "printfHello: inaccessible or not found") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/elema/bin/printfHello 2") + self.driver.Assert.contains(result, "****************hello**************") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/elema/bin/printfSymbol") + self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") + self.driver.Assert.contains(result, "End: 1 - 1 = 0") + + Step("卸载饿了吗软件") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p elema") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/elema/bin/printfHello 2") + self.driver.Assert.contains(result, "printfHello: inaccessible or not found") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/elema/bin/printfSymbol") + self.driver.Assert.contains(result, "printfSymbol: inaccessible or not found") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") + self.driver.Assert.contains(result, "del: inaccessible or not found") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.json new file mode 100644 index 00000000..20715222 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2900.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.py new file mode 100644 index 00000000..0a2770d6 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.py @@ -0,0 +1,145 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2900(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def worker(self): + Step("执行安装后的软件") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add 4") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + self.driver.shell(f'mkdir {self.pack_out_path}/private') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 多个应用程序安装不同版本的工具 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("打包compute工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public -n compute -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包printfHello工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[1]} " + f"-o {self.pack_out_path}/private -n printfHello -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("baidu应用软件安装程序") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包compute 2.0工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[2]} -o {self.pack_out_path}/public -n compute -v 2.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("非强制安装meituan应用软件安装程序") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p meituan -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393476") + + Step("强制安装meituan应用软件安装程序") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p meituan -i {self.pack_out_path} -f") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/meituan/bin/printfHello 1") + self.driver.Assert.contains(result, "****************hello**************") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfSymbol") + self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") + self.driver.Assert.contains(result, "del: inaccessible or not found") + + Step("卸载美团与百度安装的软件") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p meituan") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfSymbol") + self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") + + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.json new file mode 100644 index 00000000..dbdb311a --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1000.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.py new file mode 100644 index 00000000..a21b173a --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.py @@ -0,0 +1,101 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEPACK_1000(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + + TestCase.__init__(self, self.TAG, controllers) + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + # hnpcli bin文件调用参数测试 + def test_step1(self): + Step("执行./hnpcli不传任何参数") + result = self.driver.shell(f"{self.hnpcli_commamd}") + + self.driver.Assert.contains(result, + "-i : [required] input path of software package dir") + self.driver.Assert.contains(result, + "-o : [optional] output path of hnp file. " + "if not set then ouput to current directory") + self.driver.Assert.contains(result, + "-n : [optional] software name. if not hnp.json in input dir then must set") + self.driver.Assert.contains(result, + "-v : [optional] software version. " + "if not hnp.json in input dir then must set") + + Step("执行./hnpcli help") + result = self.driver.shell(f"{self.hnpcli_commamd} help") + self.driver.Assert.contains(result, + "usage:hnpcli [-i ]" + "[-o ][-n ][-v ]") + self.driver.Assert.contains(result, + "-i : [required] input path of software package dir") + self.driver.Assert.contains(result, + "-o : [optional] output path of hnp file. " + "if not set then ouput to current directory") + self.driver.Assert.contains(result, + "-n : [optional] software name. if not hnp.json in input dir then must set") + self.driver.Assert.contains(result, + "-v : [optional] software version. " + "if not hnp.json in input dir then must set") + + Step("执行./hnpcli -h") + result = self.driver.shell(f"{self.hnpcli_commamd} help") + self.driver.Assert.contains(result, + "-i : [required] input path of software package dir") + self.driver.Assert.contains(result, + "-o : [optional] output path of hnp file. " + "if not set then ouput to current directory") + self.driver.Assert.contains(result, + "-n : [optional] software name. if not hnp.json in input dir then must set") + self.driver.Assert.contains(result, + "-v : [optional] software version. " + "if not hnp.json in input dir then must set") + + Step("执行./hnpcli pack") + result = self.driver.shell(f"{self.hnpcli_commamd} pack") + self.driver.Assert.contains(result, "[ERROR][HNP]source dir is null.") + + Step("执行./hnpcli pack2") + result = self.driver.shell(f"{self.hnpcli_commamd} pack2") + self.driver.Assert.contains(result, "[ERROR][HNP]invalid cmd!. cmd:pack2") + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.json new file mode 100644 index 00000000..b8ea89e1 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1100.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.py new file mode 100644 index 00000000..1b2818c4 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.py @@ -0,0 +1,68 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEPACK_1100(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + + TestCase.__init__(self, self.TAG, controllers) + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + # hnpcli 打包native包传参个数异常场景 + def test_step1(self): + Step("执行./hnpcli pack -i native包路径") + result = self.driver.shell(f"{self.hnpcli_commamd} pack -i {self.native_path[0]}") + self.driver.Assert.contains(result, "[ERROR][HNP]name or version argv is miss.") + + Step("执行./hnpcli pack -o 存储包目标路径") + result = self.driver.shell(f"{self.hnpcli_commamd} pack -o {self.pack_out_path[0]}") + self.driver.Assert.contains(result, "[ERROR][HNP]source dir is null.") + + Step("执行./hnpcli 传参等于四个参数,./hnpcli pack -i native包路径 -o 存储包目标路径,native包中无cfg配置文件") + result = self.driver.shell(f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[ERROR][HNP]name or version argv is miss.") + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.json new file mode 100644 index 00000000..89be5024 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1200.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.py new file mode 100644 index 00000000..533020e4 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.py @@ -0,0 +1,87 @@ +# 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. + +import os +from hypium import * +from aw import Common +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEPACK_1200(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + + TestCase.__init__(self, self.TAG, controllers) + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + # hnp程序打包native包,native包路径相关测试场景 + def test_step1(self): + Step("native包路径不存在") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.work_space_path}/empty_dir -o {self.pack_out_path} " + f"-n test -v 1.1") + self.driver.Assert.contains(result, "") + Step("native包路径下的文件夹为空") + self.driver.shell(f'mkdir {self.work_space_path}/empty_dir') + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.work_space_path}/empty_dir -o {self.pack_out_path} " + f"-n test -v 1.1") + self.driver.Assert.contains(result, + "[INFO][HNP]PackHnp end. srcPath=/data/hnp_test/empty_dir, " + "hnpName=test, hnpVer=1.1, hnpDstPath=/data/hnp_test/pack_output, linkNum=0, ret=0") + result = self.driver.shell(f"find {self.pack_out_path} -name test.hnp") + self.driver.Assert.contains(result, f"{self.pack_out_path}/test.hnp") + self.driver.shell(f'rm {self.pack_out_path}/test.hnp') + self.driver.shell(f'rm -rf {self.work_space_path}/empty_dir') + Step("native包路径长度等于max_path") + path_temp = Common.randomGenerateStingByLen(4096) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {path_temp} -o {self.pack_out_path} -n test -v 1.1") + self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess.") + Step("native包路径长度超过max_path") + path_temp = Common.randomGenerateStingByLen(4097) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {path_temp} -o {self.pack_out_path} -n test -v 1.1") + self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess.") + Step("native包路径存在非法字符") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i /data/$^*》《%test/ -o {self.pack_out_path} -n test -v 1.1") + self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess.") + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.json new file mode 100644 index 00000000..09e2c62d --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1300.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.py new file mode 100644 index 00000000..fcdef9d0 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.py @@ -0,0 +1,76 @@ +# 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. + +import os +from hypium import * +from aw import Common +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEPACK_1300(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + + TestCase.__init__(self, self.TAG, controllers) + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + # hnp程序打包native包,存储包目标路径相关测试场景 + def test_step1(self): + Step("存储包目标路径不存在") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/empty_dir -n test -v 1.1") + self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess. path=/data/hnp_test/pack_output/empty_dir") + Step("存储包目标路径长度等于max_path") + path_temp = Common.randomGenerateStingByLen(4088) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {path_temp} -n test -v 1.1") + self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess.") + Step("存储包目标路径长度大于max_path") + path_temp = Common.randomGenerateStingByLen(4097) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {path_temp} -n test -v 1.1") + self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess.") + Step("/hnpcli pack native包路径 存储包目标路径 -cfg 配置路径,native包路径存在非法字符") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o /data/$^*%test/ -n test -v 1.1") + self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess. path=/data/$^*%test/") + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.json new file mode 100644 index 00000000..247b7832 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1400.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.py new file mode 100644 index 00000000..b3264369 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.py @@ -0,0 +1,122 @@ +# 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. + +import os +import shutil +from hypium import * +from aw import Common +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEPACK_1400(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + + TestCase.__init__(self, self.TAG, controllers) + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_cfg_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp.json" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + def check_pack_is_correct(self, hnp_name, native_name, cfg_file, del_hnp): + # 校验是否生成了对应的.hnp文件 + result = self.driver.shell(f"find {self.pack_out_path} -name {hnp_name}") + self.driver.Assert.contains(result, f"{self.pack_out_path}/{hnp_name}") + + # 将生成的.hnp文件推到本地 + self.driver.pull_file(self.pack_out_path, self.hnp_test_file_path) + + # 是否删除生成的.hnp文件 + if del_hnp: + self.driver.shell(f'rm {self.pack_out_path}/{hnp_name}') + + # 将hnp.json文件拷贝到native路径下,为文件比较做好准备工作 + shutil.copy2(cfg_file, f"{self.hnp_test_file_path}\\native\\{native_name}") + Common.unzip_hnp(f"{self.hnp_test_file_path}/pack_output/{hnp_name}", + f"{self.hnp_test_file_path}/pack_output/") + + # 比较打包前后两个文件是否一致 + result = Common.compare_folder(f"{self.hnp_test_file_path}\\native\\{native_name}", + f"{self.hnp_test_file_path}/pack_output/{native_name}") + assert result == True + + # 删除测试PC中的残留文件 + Common.deleteFile(f"{self.hnp_test_file_path}\\native\\{native_name}\\hnp.json") + shutil.rmtree(f"{self.hnp_test_file_path}/pack_output/") + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + # hnp程序打包native包,cfg相关测试场景 + def test_step1(self): + Step("native包中无cfg配置文件,不传name与version") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[ERROR][HNP]name or version argv is miss.") + Step("native包中无cfg配置文件,传name与version") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n test -v 1.1") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + result = self.driver.shell(f"find {self.pack_out_path} -name test.hnp") + self.driver.Assert.contains(result, f"{self.pack_out_path}/test.hnp") + self.driver.shell(f'rm {self.pack_out_path}/test.hnp') + Step("native包中存在cfg配置文件,不传name与version") + self.driver.shell(f'cp -i {self.hnp_cfg_path} {self.native_path[0]}') + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.hnp_test_file_path}\\hnp.json", True) + self.driver.shell(f'rm {self.native_path[0]}/hnp.json') + Step("native包中存在cfg配置文件,传name与version") + self.driver.shell(f'cp -i {self.hnp_cfg_path} {self.native_path[0]}') + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n test -v 1.1") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.hnp_test_file_path}\\hnp.json", True) + self.driver.shell(f'rm {self.native_path[0]}/hnp.json') + Step( + "调用./hnpcli pack -i native包路径 -o 存储包目标路径 -name test -v test, version为字符串,非常规version表述") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n test -v test") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + self.driver.Assert.contains(result, "hnpName=test, hnpVer=test") + result = self.driver.shell(f"find {self.pack_out_path} -name test.hnp") + self.driver.Assert.contains(result, f"{self.pack_out_path}/test.hnp") + self.driver.shell(f'rm {self.pack_out_path}/test.hnp') + self.driver.shell(f'rm {self.native_path[0]}/hnp.json') + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.json new file mode 100644 index 00000000..e80d07eb --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1500.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.py new file mode 100644 index 00000000..0ccbf046 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.py @@ -0,0 +1,73 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEPACK_1500(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + + TestCase.__init__(self, self.TAG, controllers) + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + # 打包native包时,传参异常 + def test_step1(self): + Step("调用./hnpcli 待打包native软件路径 打包后文件存放路径 -n test") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n test") + self.driver.Assert.contains(result, "[ERROR][HNP]name or version argv is miss.") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392706") + Step("调用./hnpcli 待打包native软件路径 打包后文件存放路径 -v 1.1") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -v 1.1") + self.driver.Assert.contains(result, "[ERROR][HNP]name or version argv is miss.") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392706") + Step("调用./hnpcli pack native包路径 存储包目标路径 -n "" -v """) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -name "" -v """) + self.driver.Assert.contains(result, "[ERROR][HNP]name or version argv is miss.") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392706") + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.json new file mode 100644 index 00000000..b7a07117 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1600.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.py new file mode 100644 index 00000000..75949550 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.py @@ -0,0 +1,111 @@ +# 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. + +import os +import shutil +from hypium import * +from aw import Common +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEPACK_1600(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + + TestCase.__init__(self, self.TAG, controllers) + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_cfg_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp.json" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + def check_pack_is_correct(self, hnp_name, native_name, cfg_file, del_hnp): + # 校验是否生成了对应的.hnp文件 + result = self.driver.shell(f"find {self.pack_out_path} -name {hnp_name}") + self.driver.Assert.contains(result, f"{self.pack_out_path}/{hnp_name}") + + # 将生成的.hnp文件推到本地 + self.driver.pull_file(self.pack_out_path, self.hnp_test_file_path) + + # 是否删除生成的.hnp文件 + if del_hnp: + self.driver.shell(f'rm {self.pack_out_path}/{hnp_name}') + + # 将hnp.json文件拷贝到native路径下,为文件比较做好准备工作 + shutil.copy2(cfg_file, f"{self.hnp_test_file_path}\\native\\{native_name}") + Common.unzip_hnp(f"{self.hnp_test_file_path}/pack_output/{hnp_name}", + f"{self.hnp_test_file_path}/pack_output/") + + # 比较打包前后两个文件是否一致 + result = Common.compare_folder(f"{self.hnp_test_file_path}\\native\\{native_name}", + f"{self.hnp_test_file_path}/pack_output/{native_name}") + assert result == True + + # 删除测试PC中的残留文件 + Common.deleteFile(f"{self.hnp_test_file_path}\\native\\{native_name}\\hnp.json") + shutil.rmtree(f"{self.hnp_test_file_path}/pack_output/") + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + # 根据配置打包不同数量的native包 + def test_step1(self): + Step("打包文件存在cfg文件") + self.driver.shell(f'cp -i {self.hnp_cfg_path} {self.native_path[0]}') + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.hnp_test_file_path}\\hnp.json", False) + self.driver.shell(f'rm {self.native_path[0]}/hnp.json') + Step("打包文件不存在cfg文件,传入name与version") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n test -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + result = self.driver.shell(f"find {self.pack_out_path} -name test.hnp") + self.driver.Assert.contains(result, f"{self.pack_out_path}/test.hnp") + Step("打包文件不存在cfg文件,传入name与version,其中name与第一次传入不同") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n test2 -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + result = self.driver.shell(f"find {self.pack_out_path} -name test2.hnp") + self.driver.Assert.contains(result, f"{self.pack_out_path}/test2.hnp") + Step("调用./hnpcli 待打包native软件路径(与上不同)打包后文件存放路径(与上相同)-n test -v 1.0") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path} -n test -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + result = self.driver.shell(f"find {self.pack_out_path} -name test.hnp") + self.driver.Assert.contains(result, f"{self.pack_out_path}/test.hnp") + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.json new file mode 100644 index 00000000..23d86b05 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1700.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.py new file mode 100644 index 00000000..145b7f7d --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.py @@ -0,0 +1,122 @@ +# 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. + +import os +from hypium import * +from aw import Common +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEPACK_1700(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + + TestCase.__init__(self, self.TAG, controllers) + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + def test_step1(self): + Step("对应的配置文件非json文件") + hnp_cfg_data = """{ + "type": "hnp-config", + "name": "python", + "version": "2.7", + "install": { + "links": [ + { + "source": "bin/python2.7", + "target": "python" + } + ] + }""" + Common.writeDateToFile("hnp.json", hnp_cfg_data) + self.driver.push_file(f"{self.current_path}\\hnp.json", self.native_path[0]) + Common.deleteFile(f"{self.current_path}\\hnp.json") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392986") + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + Step("配置文件无type字段") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + del hnp_cfg_data['type'] + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[ERROR][HNP]get type info in cfg unsuccess.") + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + Step("配置文件无name字段") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + del hnp_cfg_data['name'] + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[ERROR][HNP]get name info in cfg unsuccess.") + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + Step("配置文件无version字段") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + del hnp_cfg_data['version'] + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[ERROR][HNP]get version info in cfg unsuccess.") + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + Step("配置文件无install字段") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + del hnp_cfg_data['install'] + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[ERROR][HNP]get install info in cfg unsuccess.") + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + Step("配置文件非hnp类型") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data["type"] = "test" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[ERROR][HNP]type info not match.type=test") + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.json new file mode 100644 index 00000000..cb97293b --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1800.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.py new file mode 100644 index 00000000..ba5b130b --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.py @@ -0,0 +1,129 @@ +# 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. + +import os +import shutil +from hypium import * +from aw import Common +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEPACK_1800(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + + TestCase.__init__(self, self.TAG, controllers) + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path, delete_file): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + if delete_file: + assert Common.deleteFile(json_file_name) == 0 + + def check_pack_is_correct(self, hnp_name, native_name, cfg_file, del_hnp): + # 校验是否生成了对应的.hnp文件 + result = self.driver.shell(f"find {self.pack_out_path} -name {hnp_name}") + self.driver.Assert.contains(result, f"{self.pack_out_path}/{hnp_name}") + + # 将生成的.hnp文件推到本地 + self.driver.pull_file(self.pack_out_path, self.hnp_test_file_path) + + # 是否删除生成的.hnp文件 + if del_hnp: + self.driver.shell(f'rm {self.pack_out_path}/{hnp_name}') + + # 将hnp.json文件拷贝到native路径下,为文件比较做好准备工作 + shutil.copy2(cfg_file, f"{self.hnp_test_file_path}\\native\\{native_name}") + Common.unzip_hnp(f"{self.hnp_test_file_path}/pack_output/{hnp_name}", + f"{self.hnp_test_file_path}/pack_output/") + + # 比较打包前后两个文件是否一致 + result = Common.compare_folder(f"{self.hnp_test_file_path}\\native\\{native_name}", + f"{self.hnp_test_file_path}/pack_output/{native_name}") + assert result == True + + # 删除测试PC中的残留文件 + Common.deleteFile(f"{self.hnp_test_file_path}\\native\\{native_name}\\hnp.json") + shutil.rmtree(f"{self.hnp_test_file_path}/pack_output/") + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + # 软连接路径与配置名称内容测试 + def test_step1(self): + Step("配置软连接路径正确,但是未配置目标名称") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + del hnp_cfg_data['install']['links'][0]["target"] + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], False) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.current_path}/hnp.json", True) + assert Common.deleteFile(f"{self.current_path}/hnp.json") == 0 + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + Step("未配置软连接路径,配置了目标名称") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + del hnp_cfg_data['install']['links'][0]["source"] + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], True) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[ERROR][HNP]get source info in cfg unsuccess.") + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + Step("配置软连接路径,配置目标名称为空") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["target"] = None + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], False) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.current_path}/hnp.json", True) + assert Common.deleteFile(f"{self.current_path}/hnp.json") == 0 + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + Step("配置软连接路径,配置了目标名称长度为0") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["target"] = "" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], False) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.current_path}/hnp.json", True) + assert Common.deleteFile(f"{self.current_path}/hnp.json") == 0 + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.json new file mode 100644 index 00000000..86f7400c --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1900.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.py new file mode 100644 index 00000000..1f0752aa --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.py @@ -0,0 +1,121 @@ +# 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. + +import os +import shutil +from hypium import * +from aw import Common +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEPACK_1900(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + + TestCase.__init__(self, self.TAG, controllers) + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path, delete_file): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + if delete_file: + assert Common.deleteFile(json_file_name) == 0 + + def check_pack_is_correct(self, hnp_name, native_name, cfg_file, del_hnp): + # 校验是否生成了对应的.hnp文件 + result = self.driver.shell(f"find {self.pack_out_path} -name {hnp_name}") + self.driver.Assert.contains(result, f"{self.pack_out_path}/{hnp_name}") + + # 将生成的.hnp文件推到本地 + self.driver.pull_file(self.pack_out_path, self.hnp_test_file_path) + + # 是否删除生成的.hnp文件 + if del_hnp: + self.driver.shell(f'rm {self.pack_out_path}/{hnp_name}') + + # 将hnp.json文件拷贝到native路径下,为文件比较做好准备工作 + shutil.copy2(cfg_file, f"{self.hnp_test_file_path}\\native\\{native_name}") + Common.unzip_hnp(f"{self.hnp_test_file_path}/pack_output/{hnp_name}", + f"{self.hnp_test_file_path}/pack_output/") + + # 比较打包前后两个文件是否一致 + result = Common.compare_folder(f"{self.hnp_test_file_path}\\native\\{native_name}", + f"{self.hnp_test_file_path}/pack_output/{native_name}") + assert result == True + + # 删除测试PC中的残留文件 + Common.deleteFile(f"{self.hnp_test_file_path}\\native\\{native_name}\\hnp.json") + shutil.rmtree(f"{self.hnp_test_file_path}/pack_output/") + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + # 软连接路径与配置不同关系的测试 + def test_step1(self): + Step("配置文件字段正确,存在两个软连接,不同的软连接路径,相同的配置名称") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'].append({"source": "bin/sample.txt", "target": "hnp_test"}) + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], False) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "linkNum=2, ret=0") + self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.current_path}/hnp.json", False) + Common.deleteFile(f"{self.current_path}/hnp.json") + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + Step("配置文件字段正确,存在两个软连接,相同的软连接路径,不同的配置名称") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'].append({"source": "bin/sample.txt", "target": "hnp_test2"}) + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], False) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "linkNum=2, ret=0") + self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.current_path}/hnp.json", False) + Common.deleteFile(f"{self.current_path}/hnp.json") + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + Step("配置文件字段正确,存在多个软连接,相同的软连接路径,相同的配置名称") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + for i in range(5): + hnp_cfg_data['install']['links'].append({"source": "bin/sample.txt", "target": "hnp_test"}) + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], False) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "linkNum=6, ret=0") + self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.current_path}/hnp.json", False) + Common.deleteFile(f"{self.current_path}/hnp.json") + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.json new file mode 100644 index 00000000..c20074b5 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_2000.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.py new file mode 100644 index 00000000..8c6813d5 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.py @@ -0,0 +1,79 @@ +# 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. + +import os +from hypium import * +from aw import Common +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEPACK_2000(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + + TestCase.__init__(self, self.TAG, controllers) + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + # 软连接路径不存在测试场景 + def test_step1(self): + Step("存在一个软连接,软连接路径不存在") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/testsample.txt" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393217") + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + Step("存在两个软连接,其中一个软连接路径不存在") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'].append({"source": "bin/test_sample.txt", "target": "hnp_test2"}) + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393217") + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.json new file mode 100644 index 00000000..cb06b7ca --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_2100.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.py new file mode 100644 index 00000000..c11f45bd --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.py @@ -0,0 +1,99 @@ +# 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. + +import os +from hypium import * +from aw import Common +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEPACK_2100(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + + TestCase.__init__(self, self.TAG, controllers) + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" # 测试设备工作路径 + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + # 升级打包同名native包 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("配置文件字段正确,存在两个软连接,不同的软连接路径,相同的配置名称") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") + self.driver.Assert.contains(result, "linkNum=1, ret=0") + self.driver.shell(f"rm {self.native_path[0]}/hnp.json") + + Step("根据name + version打包与配置文件的同名hnp包") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n hnp_test -v 1.0") + self.driver.Assert.contains(result, "linkNum=0, ret=0") + result = self.driver.shell(f"find {self.pack_out_path} -name hnp_test.hnp") + self.driver.Assert.contains(result, f"{self.pack_out_path}/hnp_test.hnp") + + Step("根据name + version打包与配置文件的同名hnp包,版本号不同") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n hnp_test -v 1.2") + self.driver.Assert.contains(result, "linkNum=0, ret=0") + result = self.driver.shell(f"find {self.pack_out_path} -name hnp_test.hnp") + self.driver.Assert.contains(result, f"{self.pack_out_path}/hnp_test.hnp") + + Step("根据name + version打包与配置文件的同名hnp包,打包的native包与原有不同,版本号不同") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path} -n hnp_test1 -v 1.3") + self.driver.Assert.contains(result, "linkNum=0, ret=0") + result = self.driver.shell(f"find {self.pack_out_path} -name hnp_test1.hnp") + self.driver.Assert.contains(result, f"{self.pack_out_path}/hnp_test1.hnp") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.json new file mode 100644 index 00000000..1f075588 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0300.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.py new file mode 100644 index 00000000..d4c5bfaf --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.py @@ -0,0 +1,108 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0300(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 卸载路径不存在测试场景 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("打包compute.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public -n compute -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("安装compute工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("卸载软件usrId不存在") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 301 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393477 ") + + Step("卸载的应用不存在") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p meituan") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + + Step("正常卸载") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("重复卸载") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.json new file mode 100644 index 00000000..f0cc152b --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0400.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.py new file mode 100644 index 00000000..1725e37a --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.py @@ -0,0 +1,123 @@ +# 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. + +import os +import time +from hypium import * +import threading +from aw import Common +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0400(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def worker(self): + Step("执行安装后的软件") + self.driver.shell(f"chmod +x /data/service/hnp/compute.org/compute_1.0/bin/add") + result = self.driver.shell( + f"./data/service/hnp/compute.org/compute_1.0/bin/add 4") + + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 卸载的软件正在运行的软件(未配置软连接) + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("打包compute.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public -n compute -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("安装compute工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + self.driver.shell(f'mkdir -p /data/service/hnp/compute.org/compute_1.0/') + self.driver.shell(f'cp -r {self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute/bin ' + f'/data/service/hnp/compute.org/compute_1.0/') + + Step("执行安装的工具") + t1 = threading.Thread(target=self.worker) + t1.start() + time.sleep(1) + Step("卸载百度应用安装工具") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + + self.driver.Assert.contains(result, "[ERROR][HNP]hnp install path is running now,") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392978") + t1.join() + + Step("待工具运行结束,卸载安装的compute工具") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic -name compute.org") + assert ("compute.org" not in result) == True + self.driver.shell(f'rm -rf /data/service/hnp') + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.json new file mode 100644 index 00000000..908275cb --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0500.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.py new file mode 100644 index 00000000..f93a74c5 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.py @@ -0,0 +1,129 @@ +# 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. + +import os +import time +from hypium import * +import threading +from aw import Common +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0500(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def worker(self): + Step("执行安装后的软件") + self.driver.shell(f"chmod +x /data/service/hnp/compute.org/compute_1.0/bin/add") + result = self.driver.shell( + f"./data/service/hnp/compute.org/compute_1.0/bin/add 4") + self.driver.Assert.contains(result, "End: 1 + 1 = 2") + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 卸载的软件正在运行的软件(配置软连接) + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建compute工具配置文件,工具add的软连接名称为compute,工具add的软连接名称为compute") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/add" + hnp_cfg_data['install']['links'][0]["target"] = "add" + hnp_cfg_data['install']['links'].append({"source": "bin/del", "target": "compute"}) + hnp_cfg_data['install']['links'].append({"source": "bin/multiplication", "target": "mul"}) + hnp_cfg_data['name'] = "compute" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) + + Step("打包compute.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public -n compute -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("安装compute工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + self.driver.shell(f'mkdir -p /data/service/hnp/compute.org/compute_1.0/') + self.driver.shell(f'cp -r {self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute/bin ' + f'/data/service/hnp/compute.org/compute_1.0/') + + Step("卸载百度应用安装工具") + t1 = threading.Thread(target=self.worker) + t1.start() + time.sleep(1) + Step("正常卸载") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[ERROR][HNP]hnp install path is running now,") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392978") + t1.join() + + Step("待工具运行结束,卸载安装的compute工具") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + self.driver.shell(f'rm -rf /data/service/hnp') + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.json new file mode 100644 index 00000000..482dce88 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0600.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.py new file mode 100644 index 00000000..12371721 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.py @@ -0,0 +1,147 @@ +# 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. + +import os +from hypium import * +from devicetest.core.test_case import Step, TestCase +from aw import Common + + +class SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0600(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/readCfgFile"] + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + self.driver.shell(f'mkdir {self.pack_out_path}/private') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 卸载的多个软件 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建compute工具配置文件") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/add" + hnp_cfg_data['install']['links'][0]["target"] = "add" + hnp_cfg_data['install']['links'].append({"source": "bin/del", "target": "del"}) + hnp_cfg_data['install']['links'].append({"source": "bin/multiplication", "target": "multiplication"}) + hnp_cfg_data['name'] = "compute" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + + Step("创建readCfgFile工具配置文件") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/readCfgFile" + hnp_cfg_data['install']['links'][0]["target"] = "readCfgFile" + hnp_cfg_data['name'] = "readCfgFile" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[2]) + + Step("打包readCfgFile.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[2]} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包compute.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包printfHello.hnp") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[1]} " + f"-o {self.pack_out_path}/private -n printfHello -v 1.0") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("批量安装readCfgFile、compute、printfHello、printfHello工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("卸载百度程序对应的软件") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("验证compute工具卸载成功") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") + self.driver.Assert.contains(result, "del: inaccessible or not found") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") + self.driver.Assert.contains(result, "add: inaccessible or not found") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/hnp/baidu/bin/multiplication") + self.driver.Assert.contains(result, "multiplication: inaccessible or not found") + + Step("验证printfHello工具卸载成功") + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello") + self.driver.Assert.contains(result, "printfHello: inaccessible or not found") + + result = self.driver.shell( + f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/readCfgFile") + self.driver.Assert.contains(result, "readCfgFile: inaccessible or not found") + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.json new file mode 100644 index 00000000..ba1cdb56 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_HNP/SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0700.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.py new file mode 100644 index 00000000..94852098 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.py @@ -0,0 +1,143 @@ +# 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. + +import os +import time +from hypium import * +import threading +from aw import Common +from devicetest.core.test_case import Step, TestCase + + +class SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0700(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + + self.default_install_root_path = "/data/app/el1/bundle" + self.current_path = os.getcwd() + self.driver = UiDriver(self.device1) + self.work_space_path = "/data/hnp_test" + self.pack_out_path = f"{self.work_space_path}/pack_output" + self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" + self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" + self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" + self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" + self.hnp_public_dir = "hnppublic/bin" + self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol", + f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello"] + + def creat_json_and_push_remote(self, json_file_name, json_data, target_path): + Common.writeJsonDateToFile(json_file_name, json_data) + self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) + assert Common.deleteFile(json_file_name) == 0 + + def worker(self): + Step("执行安装后的软件") + self.driver.shell(f"chmod +x /data/service/hnp/printfSymbol.org/printfSymbol_1.0/bin/printfSymbol") + result = self.driver.shell( + f"./data/service/hnp/printfSymbol.org/printfSymbol_1.0/bin/printfSymbol 4") + self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") + + def setup(self): + Step("预置工作:初始化PC开始") + Step(self.devices[0].device_id) + + Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") + self.driver.shell(f'mkdir {self.work_space_path}') + + Step("预置工作:创建打包保存文件,为native打包后的保存路径") + self.driver.shell(f'mkdir {self.pack_out_path}') + self.driver.shell(f'mkdir {self.pack_out_path}/public') + + self.driver.push_file(self.hnp_test_file_path, self.work_space_path) + + Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") + self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") + + Step("创建一个userId为300的路径,为后续测试使用目录") + self.driver.shell(f"mkdir {self.default_install_root_path}/300") + + # 不同hnp软件包配置的软连接路径不同,target名称相同测试,同名进程运行过程中卸载工具 + def test_step1(self): + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): + Step("创建printfSymbol工具配置文件") + hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") + hnp_cfg_data['install']['links'][0]["source"] = "bin/printfSymbol" + hnp_cfg_data['install']['links'][0]["target"] = "print" + hnp_cfg_data['name'] = "printfSymbol" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) + + Step("创建printfHello工具配置文件") + hnp_cfg_data['install']['links'][0]["source"] = "bin/printfHello" + hnp_cfg_data['install']['links'][0]["target"] = "print" + hnp_cfg_data['name'] = "printfHello" + hnp_cfg_data['version'] = "1.0" + self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[1]) + + Step("打包printfSymbol工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("打包printfHello工具") + result = self.driver.shell( + f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path}/public") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + Step("安装printfSymbol、printfHello工具") + result = self.driver.shell( + f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + + self.driver.shell(f'mkdir -p /data/service/hnp/printfSymbol.org/printfSymbol_1.0/') + self.driver.shell(f'mkdir -p /data/service/hnp/printfHello.org/printfHello_1.0/') + self.driver.shell(f'cp -r {self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello/bin ' + f'/data/service/hnp/printfHello.org/printfHello_1.0/') + self.driver.shell(f'cp -r {self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol/bin ' + f'/data/service/hnp/printfSymbol.org/printfSymbol_1.0/') + + Step("运行print进程") + t1 = threading.Thread(target=self.worker) + t1.start() + time.sleep(1) + + Step("卸载baidu应用安装的软件") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[ERROR][HNP]hnp install path is running now,") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392978") + t1.join() + + Step("待程序运行结束后,卸载baidu应用安装的软件") + result = self.driver.shell( + f"{self.hnp_commamd} uninstall -u 300 -p baidu") + self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") + self.driver.shell(f'rm -rf /data/service/hnp') + else: + pass + + def teardown(self): + self.driver.shell(f'rm -rf {self.work_space_path}') + self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') + Step("收尾工作") + diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.json new file mode 100644 index 00000000..af09a5d3 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0100.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.py new file mode 100644 index 00000000..e84fab6f --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.py @@ -0,0 +1,74 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import * +from hypium.model import UiParam, WindowFilter +import os +from aw import Common + +class SUB_STARTUP_APPSPAWN_HNPINSTALL_0100(TestCase): + + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("步骤1:安装测试应用") + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + hnp = os.path.abspath(os.path.join( + os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) + isHap = self.driver.has_app("com.example.hnp_test") + if(isHap): + self.driver.uninstall_app("com.example.hnp_test") + else: + pass + self.driver.install_app(hnp) + Step("是否刷root包") + isroot = self.driver.shell("ls") + Step("步骤2:展示公有目录列表") + result1 = self.driver.shell("ls /data/app/el1/bundle/100/hnppublic") + self.driver.Assert.contains(result1, "hnpsample.org") + if ("Permission denied" in isroot): + Step("步骤4:执行公有目录软链二进制") + th = Common.hnpexecute_async(self.driver, "/data/app/el1/bundle/100/hnppublic/bin/hnpsample 5") + th.start() + result3 = self.driver.shell("ps -ef | grep hnpsample | grep -v grep") + self.driver.Assert.contains(result3, "hnpsample") + else: + Step("步骤3:展示私有目录列表") + result2 = self.driver.shell("ls /data/app/el1/bundle/100/hnp/com.example.hnp_test") + self.driver.Assert.contains(result2, "node.org") + Step("步骤4:执行公有目录软链二进制") + result3 = self.driver.hdc("hdc shell /data/app/el1/bundle/100/hnppublic/bin/hnpsample") + self.driver.Assert.contains(result3, "start hnp sample") + self.driver.Assert.contains(result3, "hnp sample end") + + def teardown(self): + Step("收尾工作:卸载hap") + self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.json new file mode 100644 index 00000000..df3e9b72 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0200.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.py new file mode 100644 index 00000000..a99ae3a5 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.py @@ -0,0 +1,68 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import * +from hypium.model import UiParam, WindowFilter +import os + +class SUB_STARTUP_APPSPAWN_HNPINSTALL_0200(TestCase): + + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("步骤1:安装测试应用") + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + hnp = os.path.abspath(os.path.join( + os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) + isHap = self.driver.has_app("com.example.hnp_test") + if(isHap): + self.driver.uninstall_app("com.example.hnp_test") + else: + pass + self.driver.install_app(hnp) + Step("步骤2:读取公有目录列表") + result1 = self.driver.shell("cat /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") + self.driver.Assert.contains(result1, "hnpsample") + Step("是否刷root包") + isroot = self.driver.shell("ls") + if("Permission denied" in isroot): + Step("步骤3:读取私有目录列表") + result2 = self.driver.shell( + "cat /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") + self.driver.Assert.contains(result2, "Permission denied") + else: + Step("步骤3:读取私有目录列表") + result2 = self.driver.shell("cat /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") + self.driver.Assert.contains(result2, "node") + + def teardown(self): + Step("收尾工作:卸载hap") + self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.json new file mode 100644 index 00000000..a15ed738 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0300.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.py new file mode 100644 index 00000000..5fe4b6e4 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.py @@ -0,0 +1,77 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import * +from hypium.model import UiParam, WindowFilter +import os + +class SUB_STARTUP_APPSPAWN_HNPINSTALL_0300(TestCase): + + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("步骤1:安装测试应用") + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + hnp = os.path.abspath(os.path.join( + os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) + isHap = self.driver.has_app("com.example.hnp_test") + if (isHap): + self.driver.uninstall_app("com.example.hnp_test") + else: + pass + self.driver.install_app(hnp) + isroot = self.driver.shell("ls") + if ("Permission denied" in isroot): + Step("步骤2:修改公有目录文件内容") + data = {"name": "zsj", "sex": "girl", "age": 31}; + result1 = self.driver.shell(f"echo {data} > /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") + self.driver.Assert.contains(result1, "Permission denied") + Step("步骤3:修改私有目录文件内容") + data = {"name": "private", "sex": "girl", "age": 31}; + result2 = self.driver.shell(f"echo {data} > /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") + self.driver.Assert.contains(result2, "Permission denied") + else: + Step("步骤2:修改公有目录文件内容") + data = {"name": "zsj", "sex": "girl", "age": 31}; + self.driver.shell(f"echo {data} > /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") + result1 = self.driver.shell("cat /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") + self.driver.Assert.contains(result1, "zsj") + Step("步骤3:修改私有目录文件内容") + data = {"name": "private", "sex": "girl", "age": 31}; + self.driver.shell( + f"echo {data} > /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") + result2 = self.driver.shell( + "cat /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") + self.driver.Assert.contains(result2, "private") + + def teardown(self): + Step("收尾工作:卸载hap") + self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.json new file mode 100644 index 00000000..bfb061dc --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0400.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.py new file mode 100644 index 00000000..5465632d --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.py @@ -0,0 +1,72 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import * +from hypium.model import UiParam, WindowFilter +import os + +class SUB_STARTUP_APPSPAWN_HNPINSTALL_0400(TestCase): + + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("步骤1:安装测试应用") + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + hnp = os.path.abspath(os.path.join( + os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) + isHap = self.driver.has_app("com.example.hnp_test") + if (isHap): + self.driver.uninstall_app("com.example.hnp_test") + else: + pass + self.driver.install_app(hnp) + isroot = self.driver.shell("ls") + if ("Permission denied" in isroot): + Step("步骤2:修改公有目录文件内容") + result1 = self.driver.shell(f"touch /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/123.txt") + self.driver.Assert.contains(result1, "Permission denied") + Step("步骤3:修改私有目录文件内容") + result2 = self.driver.shell(f"touch /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/abc.txt") + self.driver.Assert.contains(result2, "Permission denied") + else: + Step("步骤2:修改公有目录文件内容") + self.driver.shell(f"touch /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/123.txt") + result1 = self.driver.shell("ls /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/") + self.driver.Assert.contains(result1, "123.txt") + Step("步骤3:修改私有目录文件内容") + self.driver.shell(f"touch /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/abc.txt") + result2 = self.driver.shell( + "ls /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/") + self.driver.Assert.contains(result2, "abc.txt") + + def teardown(self): + Step("收尾工作:卸载hap") + self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.json new file mode 100644 index 00000000..e63f23a5 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0500.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.py new file mode 100644 index 00000000..2b214341 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.py @@ -0,0 +1,74 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import * +from hypium.model import UiParam, WindowFilter +import os + +class SUB_STARTUP_APPSPAWN_HNPINSTALL_0500(TestCase): + + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("步骤1:安装测试应用") + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + hnp = os.path.abspath(os.path.join( + os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) + isHap = self.driver.has_app("com.example.hnp_test") + if (isHap): + self.driver.uninstall_app("com.example.hnp_test") + else: + pass + self.driver.install_app(hnp) + isroot = self.driver.shell("ls") + if ("Permission denied" in isroot): + Step("步骤2:修改公有目录文件内容") + result1 = self.driver.shell( + f"rm -rf /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") + self.driver.Assert.contains(result1, "Permission denied") + Step("步骤3:修改私有目录文件内容") + result2 = self.driver.shell( + f"rm -rf /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") + self.driver.Assert.contains(result2, "Permission denied") + else: + Step("步骤2:修改公有目录文件内容") + self.driver.shell(f"rm -rf /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") + result1 = self.driver.shell("ls /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/") + self.driver.Assert.is_true("hnp.json" not in result1) + Step("步骤3:修改私有目录文件内容") + self.driver.shell(f"rm -rf /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") + result2 = self.driver.shell( + "ls /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/") + self.driver.Assert.is_true("hnp.json" not in result2) + + def teardown(self): + Step("收尾工作:卸载hap") + self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.json new file mode 100644 index 00000000..ca88d6b4 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0600.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.py new file mode 100644 index 00000000..3b9c4030 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.py @@ -0,0 +1,74 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import * +from hypium.model import UiParam, WindowFilter +import os + +class SUB_STARTUP_APPSPAWN_HNPINSTALL_0600(TestCase): + + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("步骤1:安装测试应用") + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + hnp = os.path.abspath(os.path.join( + os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) + isHap = self.driver.has_app("com.example.hnp_test") + if (isHap): + self.driver.uninstall_app("com.example.hnp_test") + else: + pass + self.driver.install_app(hnp) + isroot = self.driver.shell("ls") + if ("Permission denied" in isroot): + Step("步骤2:修改公有目录文件内容") + result1 = self.driver.shell( + f"chmod 777 /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") + self.driver.Assert.contains(result1, "Operation not permitted") + Step("步骤3:修改私有目录文件内容") + result2 = self.driver.shell( + f"chmod 777 /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") + self.driver.Assert.contains(result2, "Permission denied") + else: + Step("步骤2:修改公有目录文件内容") + self.driver.shell(f"chmod 777 /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") + result1 = self.driver.shell("ls -l /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") + self.driver.Assert.contains(result1, "rwxrwxrwx") + Step("步骤3:修改私有目录文件内容") + self.driver.shell(f"chmod 777 /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") + result2 = self.driver.shell( + "ls -l /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") + self.driver.Assert.contains(result2, "rwxrwxrwx") + + def teardown(self): + Step("收尾工作:卸载hap") + self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.json new file mode 100644 index 00000000..aad70f10 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0700.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.py new file mode 100644 index 00000000..3e2fd84c --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.py @@ -0,0 +1,75 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import * +from hypium.model import UiParam, WindowFilter +import os + +class SUB_STARTUP_APPSPAWN_HNPINSTALL_0700(TestCase): + + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("步骤1:安装测试应用") + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + hnp = os.path.abspath(os.path.join( + os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) + isHap = self.driver.has_app("com.example.hnp_test") + if (isHap): + self.driver.uninstall_app("com.example.hnp_test") + else: + pass + self.driver.install_app(hnp) + isroot = self.driver.shell("ls") + if ("Permission denied" in isroot): + Step("步骤2:修改公有目录文件内容") + result1 = self.driver.shell( + f"mv /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/zsj.json") + self.driver.Assert.contains(result1, "Permission denied") + Step("步骤3:修改私有目录文件内容") + result2 = self.driver.shell( + f"mv /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/zsj.json") + self.driver.Assert.contains(result2, "Permission denied") + else: + Step("步骤2:修改公有目录文件内容") + self.driver.shell(f"mv /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/zsj.json") + result1 = self.driver.shell("ls /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/") + self.driver.Assert.contains(result1, "zsj.json") + Step("步骤3:修改私有目录文件内容") + self.driver.shell(f"mv /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/zsj.json") + result2 = self.driver.shell( + "ls /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/") + self.driver.Assert.contains(result2, "zsj.json") + + +def teardown(self): + Step("收尾工作:卸载hap") + self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.json new file mode 100644 index 00000000..b4675353 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0800.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.py new file mode 100644 index 00000000..84edd35c --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.py @@ -0,0 +1,78 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import * +from hypium.model import UiParam, WindowFilter +import os + +class SUB_STARTUP_APPSPAWN_HNPINSTALL_0800(TestCase): + + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("步骤1:安装测试应用") + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + hnp = os.path.abspath(os.path.join( + os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) + isHap = self.driver.has_app("com.example.hnp_test") + if (isHap): + self.driver.uninstall_app("com.example.hnp_test") + else: + pass + self.driver.install_app(hnp) + isroot = self.driver.shell("ls") + if ("Permission denied" in isroot): + Step("步骤2:修改公有目录文件内容") + result1 = self.driver.shell( + f"cp /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/zsj.json") + self.driver.Assert.contains(result1, "Permission denied") + Step("步骤3:修改私有目录文件内容") + result2 = self.driver.shell( + f"cp /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/zsj.json") + self.driver.Assert.contains(result2, "Permission denied") + else: + Step("步骤2:修改公有目录文件内容") + self.driver.shell( + f"cp /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/zsj.json") + result1 = self.driver.shell("ls /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/") + self.driver.Assert.contains(result1, "zsj.json") + self.driver.Assert.contains(result1, "hnp.json") + Step("步骤3:修改私有目录文件内容") + self.driver.shell( + f"cp /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/zsj.json") + result2 = self.driver.shell( + "ls /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/") + self.driver.Assert.contains(result2, "zsj.json") + self.driver.Assert.contains(result2, "hnp.json") + + def teardown(self): + Step("收尾工作:卸载hap") + self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.json new file mode 100644 index 00000000..ecc92a85 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0900.py"] + } +} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.py new file mode 100644 index 00000000..c46afb68 --- /dev/null +++ b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.py @@ -0,0 +1,71 @@ +# 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. + +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import * +from hypium.model import UiParam, WindowFilter +import os +from aw import Common + +class SUB_STARTUP_APPSPAWN_HNPINSTALL_0900(TestCase): + + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:检测屏幕是否亮.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("步骤1:安装测试应用") + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + hnp = os.path.abspath(os.path.join( + os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) + isHap = self.driver.has_app("com.example.hnp_test") + if (isHap): + self.driver.uninstall_app("com.example.hnp_test") + else: + pass + self.driver.install_app(hnp) + Step("是否刷root包") + isroot = self.driver.shell("ls") + if ("Permission denied" in isroot): + Step("步骤2:执行公有目录二进制文件") + th = Common.hnpexecute_async(self.driver, "/data/app/el1/bundle/100/hnppublic/bin/hnpsample 5") + th.start() + result3 = self.driver.shell("ps -ef | grep hnpsample | grep -v grep") + self.driver.Assert.contains(result3, "hnpsample") + Step("步骤3:读取私有目录列表") + result2 = self.driver.shell("./data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/bin/node") + self.driver.Assert.contains(result2, "inaccessible or not found") + else: + Step("步骤2:执行公有目录二进制文件") + result1 = self.driver.shell("./data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/bin/hnpsample") + self.driver.Assert.contains(result1, "start hnp sample") + self.driver.Assert.contains(result1, "hnp sample end") + + def teardown(self): + Step("收尾工作:卸载hap") + self.driver.uninstall_app("com.example.hnp_test") -- Gitee From be43738a3d905734ffec62446eb052911ab58213 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Mon, 30 Dec 2024 15:42:00 +0800 Subject: [PATCH 097/148] fix umount bug in different userId Signed-off-by: nianyuu --- modules/sandbox/sandbox_utils.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index d88358a8..856017a6 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -1926,6 +1926,11 @@ static bool IsUnlockStatus(uint32_t uid) return false; } +static string GetMountInfoKey(uint32_t userId, const char *bundleName) +{ + return std::to_string(userId) + "-" + std::string(bundleName); +} + static void MountDir(const AppSpawningCtx *property, const char *rootPath, const char *srcPath, const char *targetPath) { const int userIdBase = 200000; @@ -1943,7 +1948,8 @@ static void MountDir(const AppSpawningCtx *property, const char *rootPath, const APPSPAWN_CHECK(len > 0 && ((size_t)len < allPathSize), free(path); return, "Failed to get sandbox path"); if (srcPath != nullptr) { - g_mountInfo[string(bundleName)]++; + string key = GetMountInfoKey(info->uid / userIdBase, bundleName); + g_mountInfo[key]++; } if (access(path, F_OK) == 0 && srcPath == nullptr) { @@ -2188,7 +2194,7 @@ static void UmountDir(const char *rootPath, const char *targetPath, const AppSpa ret = umount2(path, MNT_DETACH); if (ret == 0) { - APPSPAWN_LOGV("Umount2 sandbox path %{public}s success", path); + APPSPAWN_LOGI("Umount2 sandbox path %{public}s success", path); } else { APPSPAWN_LOGW("Failed to umount2 sandbox path %{public}s errno %{public}d", path, errno); } @@ -2199,21 +2205,26 @@ static int UmountSandboxPath(const AppSpawnMgr *content, const AppSpawnedProcess { APPSPAWN_CHECK(content != NULL && appInfo != NULL && appInfo->name != NULL, return -1, "Invalid content or appInfo"); + if (IsNWebSpawnMode(content)) { + return 0; + } APPSPAWN_LOGV("UmountSandboxPath name %{public}s pid %{public}d", appInfo->name, appInfo->pid); const char rootPath[] = "/mnt/sandbox/"; const char el1Path[] = "/data/storage/el1/bundle"; - if (g_mountInfo.find(string(appInfo->name)) == g_mountInfo.end()) { + uint32_t userId = appInfo->uid / UID_BASE; + string key = GetMountInfoKey(userId, appInfo->name); + if (g_mountInfo.find(key) == g_mountInfo.end()) { return 0; } - g_mountInfo[string(appInfo->name)]--; - if (g_mountInfo[string(appInfo->name)] == 0) { - APPSPAWN_LOGV("no app %{public}s use it, need umount", appInfo->name); - g_mountInfo.erase(string(appInfo->name)); + g_mountInfo[key]--; + if (g_mountInfo[key] == 0) { + APPSPAWN_LOGV("no app %{public}s use it in userId %{public}u, need umount", appInfo->name, userId); UmountDir(rootPath, el1Path, appInfo); + g_mountInfo.erase(key); } else { - APPSPAWN_LOGV("app %{public}s use it mount times %{public}d, not need umount", - appInfo->name, g_mountInfo[string(appInfo->name)]); + APPSPAWN_LOGV("app %{public}s use it mount times %{public}d in userId %{public}u, not need umount", + appInfo->name, g_mountInfo[key], userId); } return 0; } -- Gitee From 245181d86eb607b8cfa4b37361b34ff40356dfb2 Mon Sep 17 00:00:00 2001 From: h00788559 Date: Thu, 2 Jan 2025 15:47:42 +0800 Subject: [PATCH 098/148] =?UTF-8?q?=E8=87=AA=E6=B8=B2=E6=9F=93APP=E6=94=AF?= =?UTF-8?q?=E6=8C=81shader=E9=A2=84=E7=BD=AE=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: h00788559 --- appdata-sandbox-app.json | 3 +++ appdata-sandbox.json | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/appdata-sandbox-app.json b/appdata-sandbox-app.json index a41ba2a4..5916a3f0 100755 --- a/appdata-sandbox-app.json +++ b/appdata-sandbox-app.json @@ -95,6 +95,9 @@ }, { "src-path" : "/data/service/el1/public/cert_manager_service/certificates/user_open", "sandbox-path" : "/data/certificates/user_cacerts" + },{ + "sandbox-path" : "/chip_prod/etc/passthrough", + "src-path" : "/chip_prod/etc/passthrough" }], "mount-files": [{ "src-path" : "/system/etc/hosts", diff --git a/appdata-sandbox.json b/appdata-sandbox.json index 2f5ea439..62f07d3f 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -243,6 +243,11 @@ "sandbox-path" : "/data/storage/el2/media", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" + }, { + "src-path" : "/chip_prod/etc/passthrough", + "sandbox-path" : "/chip_prod/etc/passthrough", + "sandbox-flags" : [ "bind", "rec" ], + "check-action-status": "false" } ], "symbol-links" : [{ -- Gitee From 849cddf3d769aadc8f72e22cc7f0fe17715fa3e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Tue, 31 Dec 2024 11:01:55 +0800 Subject: [PATCH 099/148] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E8=93=9D?= =?UTF-8?q?=E9=BB=84=E4=B8=8D=E4=B8=80=E8=87=B4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- modules/common/appspawn_adapter.cpp | 2 +- modules/sandbox/appspawn_sandbox.c | 22 ++++++++++++++-- modules/sandbox/sandbox_utils.cpp | 39 ++++++++++++++++++++++------- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/modules/common/appspawn_adapter.cpp b/modules/common/appspawn_adapter.cpp index f01fd8fe..37856a33 100644 --- a/modules/common/appspawn_adapter.cpp +++ b/modules/common/appspawn_adapter.cpp @@ -89,7 +89,7 @@ void SetHapDomainInfo(HapDomainInfo *hapDomainInfo, const AppSpawningCtx *proper hapDomainInfo->apl = msgDomainInfo->apl; hapDomainInfo->packageName = GetBundleName(property); hapDomainInfo->hapFlags = msgDomainInfo->hapFlags; - //The value of 0 is invalid. Its purpose is to initialize. + // The value of 0 is invalid. Its purpose is to initialize. hapDomainInfo->uid = appInfo == nullptr ? 0 : appInfo->uid; if (CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE)) { hapDomainInfo->hapFlags |= SELINUX_HAP_DEBUGGABLE; diff --git a/modules/sandbox/appspawn_sandbox.c b/modules/sandbox/appspawn_sandbox.c index a36c9f4a..beb7edc5 100644 --- a/modules/sandbox/appspawn_sandbox.c +++ b/modules/sandbox/appspawn_sandbox.c @@ -188,6 +188,24 @@ void DeleteSandboxContext(SandboxContext *context) free(context); } +static bool NeedNetworkIsolated(SandboxContext *context, const AppSpawningCtx *property) +{ + int developerMode = IsDeveloperModeOpen(); + if (CheckSpawningMsgFlagSet(context, APP_FLAGS_ISOLATED_SANDBOX) && !developerMode) { + return true; + } + + if (CheckSpawningMsgFlagSet(context, APP_FLAGS_ISOLATED_NETWORK)) { + uint32_t len = 0; + char *extensionType = GetAppPropertyExt(property, MSG_EXT_NAME_EXTENSION_TYPE, &len); + if (extensionType == NULL || extensionType[0] == '\0' || !developerMode) { + return true; + } + } + + return false; +} + static int InitSandboxContext(SandboxContext *context, const AppSpawnSandboxCfg *sandbox, const AppSpawningCtx *property, int nwebspawn) { @@ -210,8 +228,8 @@ static int InitSandboxContext(SandboxContext *context, context->message = property->message; context->sandboxNsFlags = CLONE_NEWNS; - if (!IsDeveloperModeOpen() && (CheckSpawningMsgFlagSet(context, APP_FLAGS_ISOLATED_SANDBOX) || - CheckSpawningMsgFlagSet(context, APP_FLAGS_ISOLATED_NETWORK))) { + + if (NeedNetworkIsolated(context, property)) { context->sandboxNsFlags |= sandbox->sandboxNsFlags & CLONE_NEWNET ? CLONE_NEWNET : 0; } diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index d88358a8..c9cae4fd 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -827,15 +827,16 @@ static bool CheckMountFlag(const AppSpawningCtx *appProperty, const std::string return false; } -static bool GetCreateSandboxPath(nlohmann::json &json) +static bool GetCreateSandboxPath(nlohmann::json &json, std::string srcPath) { - std::string value = g_statusCheck; APPSPAWN_CHECK(json != nullptr && json.is_object(), return true, "json is not object."); bool isRet = json.find(CREATE_SANDBOX_PATH) != json.end() && json.at(CREATE_SANDBOX_PATH).is_string(); if (isRet) { - value = json.at(CREATE_SANDBOX_PATH).get(); + std::string value = json.at(CREATE_SANDBOX_PATH).get(); APPSPAWN_LOGV("Find create-sandbox-path: %{public}s successful.", value.c_str()); - return g_statusCheck == value; + if (value == "false" && access(srcPath.c_str(), F_OK) != 0) { + return false; + } } return true; } @@ -862,6 +863,9 @@ int SandboxUtils::DoAllMntPointsMount(const AppSpawningCtx *appProperty, } std::string srcPath = ConvertToRealPath(appProperty, mntPoint[g_srcPath].get()); + if (!GetCreateSandboxPath(mntPoint, srcPath)) { + continue; + } std::string sandboxPath = GetSandboxPath(appProperty, mntPoint, section, sandboxRoot); SandboxMountConfig mountConfig = {0}; GetSandboxMountConfig(appProperty, section, mntPoint, mountConfig); @@ -870,9 +874,7 @@ int SandboxUtils::DoAllMntPointsMount(const AppSpawningCtx *appProperty, /* if app mount failed for special strategy, we need deal with common mount config */ int ret = HandleSpecialAppMount(appProperty, srcPath, sandboxPath, mountConfig.fsType, mountFlags); - bool createSandboxPath = true; - createSandboxPath = GetCreateSandboxPath(mntPoint); - if (ret < 0 && (createSandboxPath || access(srcPath.c_str(), F_OK) == 0)) { + if (ret < 0) { ret = DoAppSandboxMountOnce(srcPath.c_str(), sandboxPath.c_str(), mountConfig.fsType.c_str(), mountFlags, mountConfig.optionsPoint.c_str(), mountSharedFlag); } @@ -1868,6 +1870,24 @@ int LoadAppSandboxConfig(AppSpawnMgr *content) return 0; } +static bool NeedNetworkIsolated(AppSpawningCtx *property) +{ + int developerMode = IsDeveloperModeOpen(); + if (CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX) && !developerMode) { + return true; + } + + if (CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_NETWORK)) { + std::string extensionType = + OHOS::AppSpawn::SandboxUtils::GetExtraInfoByType(property, MSG_EXT_NAME_EXTENSION_TYPE); + if (extensionType.length() == 0 || !developerMode) { + return true; + } + } + + return false; +} + int32_t SetAppSandboxProperty(AppSpawnMgr *content, AppSpawningCtx *property) { APPSPAWN_CHECK(property != nullptr, return -1, "Invalid appspwn client"); @@ -1886,10 +1906,11 @@ int32_t SetAppSandboxProperty(AppSpawnMgr *content, AppSpawningCtx *property) } } uint32_t sandboxNsFlags = CLONE_NEWNS; - if (!IsDeveloperModeOpen() && (CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX) || - CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_NETWORK))) { + + if (NeedNetworkIsolated(property)) { sandboxNsFlags |= content->content.sandboxNsFlags & CLONE_NEWNET ? CLONE_NEWNET : 0; } + APPSPAWN_LOGV("SetAppSandboxProperty sandboxNsFlags 0x%{public}x", sandboxNsFlags); if (IsNWebSpawnMode(content)) { -- Gitee From 5d91ae99cdfe981da0b7ea12436339d868383626 Mon Sep 17 00:00:00 2001 From: z00500798 Date: Thu, 2 Jan 2025 18:52:18 +0800 Subject: [PATCH 100/148] Description:erofs mount Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: zl_zl --- interfaces/innerkits/client/appspawn_client.c | 10 +++++----- modules/sandbox/sandbox_utils.cpp | 4 ++-- standard/appspawn_service.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/interfaces/innerkits/client/appspawn_client.c b/interfaces/innerkits/client/appspawn_client.c index 8875b4e3..be63b799 100644 --- a/interfaces/innerkits/client/appspawn_client.c +++ b/interfaces/innerkits/client/appspawn_client.c @@ -374,15 +374,15 @@ int AppSpawnClientSendMsg(AppSpawnClientHandle handle, AppSpawnReqMsgHandle reqH int AppSpawnClientSendUserLockStatus(uint32_t userId, bool isLocked) { - AppSpawnReqMsgHandle reqHandle; - int ret = AppSpawnReqMsgCreate(MSG_LOCK_STATUS, "storage_manager", &reqHandle); - APPSPAWN_CHECK(ret == 0, return ret, "Failed to create appspawn req msg, ret = %{public}d", ret); - char lockstatus[USER_LOCK_STATUS_SIZE] = {0}; - ret = snprintf_s(lockstatus, USER_LOCK_STATUS_SIZE, USER_LOCK_STATUS_SIZE - 1, "%u:%d", userId, isLocked); + int ret = snprintf_s(lockstatus, USER_LOCK_STATUS_SIZE, USER_LOCK_STATUS_SIZE - 1, "%u:%d", userId, isLocked); APPSPAWN_CHECK(ret > 0, return ret, "Failed to build lockstatus req msg, ret = %{public}d", ret); APPSPAWN_LOGI("Send lockstatus msg to appspawn %{public}s", lockstatus); + AppSpawnReqMsgHandle reqHandle; + ret = AppSpawnReqMsgCreate(MSG_LOCK_STATUS, "storage_manager", &reqHandle); + APPSPAWN_CHECK(ret == 0, return ret, "Failed to create appspawn req msg, ret = %{public}d", ret); + ret = AppSpawnReqMsgAddStringInfo(reqHandle, "lockstatus", lockstatus); APPSPAWN_CHECK(ret == 0, AppSpawnReqMsgFree(reqHandle); return ret, "Failed to add lockstatus message, ret=%{public}d", ret); diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 856017a6..4c90e8ac 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -1919,8 +1919,8 @@ static bool IsUnlockStatus(uint32_t uid) string lockStatusParam = "startup.appspawn.lockstatus_" + to_string(uid); char userLockStatus[LOCK_STATUS_SIZE] = {0}; int ret = GetParameter(lockStatusParam.c_str(), "1", userLockStatus, sizeof(userLockStatus)); - APPSPAWN_LOGI("get param %{public}s %{public}s", lockStatusParam.c_str(), userLockStatus); - if (ret > 0 && (strcmp(userLockStatus, "0") == 0)) { // 0:解密状态 1:加密状态 + APPSPAWN_LOGI("get param %{public}s %{public}s %{public}d", lockStatusParam.c_str(), userLockStatus, ret); + if (ret > 0 && (strcmp(userLockStatus, "0") == 0)) { // 0:unlock 1:lock return true; } return false; diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index b851a31c..efdb8d4d 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -1662,7 +1662,7 @@ static void ProcessAppSpawnLockStatusMsg(AppSpawnMsgNode *message) APPSPAWN_CHECK(lockstatus != NULL, return, "failed to get lockstatus"); APPSPAWN_LOGI("appspawn get lockstatus %{public}s from storage_manager", lockstatus); char *userLockStatus = NULL; - // userLockStatus format example: 100:0 100代表userid,0代表data分区加解密状态(0:解密状态 1:加密状态) + // userLockStatus format example: 100:0 100 for userid 0:unlock 1:lock char *userIdStr = strtok_r(lockstatus, ":", &userLockStatus); APPSPAWN_CHECK(userIdStr != NULL && userLockStatus != NULL, return, "lockstatus not satisfied format, failed to get userLockStatus"); -- Gitee From 89376f5247e0ff3430196d928f728776a6ddd43b Mon Sep 17 00:00:00 2001 From: nianyuu Date: Fri, 3 Jan 2025 15:11:49 +0800 Subject: [PATCH 101/148] revert autotest and sync code to master Signed-off-by: nianyuu --- appdata-sandbox-app.json | 12 +- bundle.json | 4 +- modules/common/appspawn_namespace.c | 2 +- modules/nweb_adapter/nwebspawn_adapter.cpp | 6 +- modules/sandbox/sandbox_expand.c | 2 +- modules/sysevent/hisysevent_adapter.cpp | 4 +- modules/sysevent/hisysevent_adapter.h | 4 +- standard/appspawn_appmgr.c | 1 - standard/appspawn_service.c | 4 + ...b_startup_appspawn_nativeinstall_0200.json | 14 -- ...sub_startup_appspawn_nativeinstall_0200.py | 130 ------------ ...b_startup_appspawn_nativeinstall_0300.json | 14 -- ...sub_startup_appspawn_nativeinstall_0300.py | 122 ----------- ...b_startup_appspawn_nativeinstall_0400.json | 14 -- ...sub_startup_appspawn_nativeinstall_0400.py | 86 -------- ...b_startup_appspawn_nativeinstall_0500.json | 14 -- ...sub_startup_appspawn_nativeinstall_0500.py | 88 -------- ...b_startup_appspawn_nativeinstall_0600.json | 14 -- ...sub_startup_appspawn_nativeinstall_0600.py | 113 ---------- ...b_startup_appspawn_nativeinstall_0700.json | 14 -- ...sub_startup_appspawn_nativeinstall_0700.py | 95 --------- ...b_startup_appspawn_nativeinstall_0800.json | 14 -- ...sub_startup_appspawn_nativeinstall_0800.py | 108 ---------- ...b_startup_appspawn_nativeinstall_0900.json | 14 -- ...sub_startup_appspawn_nativeinstall_0900.py | 105 --------- ...b_startup_appspawn_nativeinstall_1000.json | 14 -- ...sub_startup_appspawn_nativeinstall_1000.py | 95 --------- ...b_startup_appspawn_nativeinstall_1100.json | 14 -- ...sub_startup_appspawn_nativeinstall_1100.py | 100 --------- ...b_startup_appspawn_nativeinstall_1200.json | 14 -- ...sub_startup_appspawn_nativeinstall_1200.py | 105 --------- ...b_startup_appspawn_nativeinstall_1300.json | 14 -- ...sub_startup_appspawn_nativeinstall_1300.py | 106 ---------- ...b_startup_appspawn_nativeinstall_1400.json | 14 -- ...sub_startup_appspawn_nativeinstall_1400.py | 110 ---------- ...b_startup_appspawn_nativeinstall_1500.json | 14 -- ...sub_startup_appspawn_nativeinstall_1500.py | 112 ---------- ...b_startup_appspawn_nativeinstall_1600.json | 14 -- ...sub_startup_appspawn_nativeinstall_1600.py | 150 ------------- ...b_startup_appspawn_nativeinstall_1700.json | 14 -- ...sub_startup_appspawn_nativeinstall_1700.py | 126 ----------- ...b_startup_appspawn_nativeinstall_1800.json | 14 -- ...sub_startup_appspawn_nativeinstall_1800.py | 86 -------- ...b_startup_appspawn_nativeinstall_1900.json | 14 -- ...sub_startup_appspawn_nativeinstall_1900.py | 122 ----------- ...b_startup_appspawn_nativeinstall_2000.json | 14 -- ...sub_startup_appspawn_nativeinstall_2000.py | 136 ------------ ...b_startup_appspawn_nativeinstall_2100.json | 14 -- ...sub_startup_appspawn_nativeinstall_2100.py | 157 -------------- ...b_startup_appspawn_nativeinstall_2200.json | 14 -- ...sub_startup_appspawn_nativeinstall_2200.py | 105 --------- ...b_startup_appspawn_nativeinstall_2300.json | 14 -- ...sub_startup_appspawn_nativeinstall_2300.py | 114 ---------- ...b_startup_appspawn_nativeinstall_2400.json | 14 -- ...sub_startup_appspawn_nativeinstall_2400.py | 124 ----------- ...b_startup_appspawn_nativeinstall_2500.json | 14 -- ...sub_startup_appspawn_nativeinstall_2500.py | 136 ------------ ...b_startup_appspawn_nativeinstall_2600.json | 14 -- ...sub_startup_appspawn_nativeinstall_2600.py | 138 ------------ ...b_startup_appspawn_nativeinstall_2700.json | 14 -- ...sub_startup_appspawn_nativeinstall_2700.py | 152 ------------- ...b_startup_appspawn_nativeinstall_2800.json | 14 -- ...sub_startup_appspawn_nativeinstall_2800.py | 200 ------------------ ...b_startup_appspawn_nativeinstall_2900.json | 14 -- ...sub_startup_appspawn_nativeinstall_2900.py | 145 ------------- .../sub_startup_appspawn_nativepack_1000.json | 14 -- .../sub_startup_appspawn_nativepack_1000.py | 101 --------- .../sub_startup_appspawn_nativepack_1100.json | 14 -- .../sub_startup_appspawn_nativepack_1100.py | 68 ------ .../sub_startup_appspawn_nativepack_1200.json | 14 -- .../sub_startup_appspawn_nativepack_1200.py | 87 -------- .../sub_startup_appspawn_nativepack_1300.json | 14 -- .../sub_startup_appspawn_nativepack_1300.py | 76 ------- .../sub_startup_appspawn_nativepack_1400.json | 14 -- .../sub_startup_appspawn_nativepack_1400.py | 122 ----------- .../sub_startup_appspawn_nativepack_1500.json | 14 -- .../sub_startup_appspawn_nativepack_1500.py | 73 ------- .../sub_startup_appspawn_nativepack_1600.json | 14 -- .../sub_startup_appspawn_nativepack_1600.py | 111 ---------- .../sub_startup_appspawn_nativepack_1700.json | 14 -- .../sub_startup_appspawn_nativepack_1700.py | 122 ----------- .../sub_startup_appspawn_nativepack_1800.json | 14 -- .../sub_startup_appspawn_nativepack_1800.py | 129 ----------- .../sub_startup_appspawn_nativepack_1900.json | 14 -- .../sub_startup_appspawn_nativepack_1900.py | 121 ----------- .../sub_startup_appspawn_nativepack_2000.json | 14 -- .../sub_startup_appspawn_nativepack_2000.py | 79 ------- .../sub_startup_appspawn_nativepack_2100.json | 14 -- .../sub_startup_appspawn_nativepack_2100.py | 99 --------- ...startup_appspawn_nativeuninstall_0300.json | 14 -- ...b_startup_appspawn_nativeuninstall_0300.py | 108 ---------- ...startup_appspawn_nativeuninstall_0400.json | 14 -- ...b_startup_appspawn_nativeuninstall_0400.py | 123 ----------- ...startup_appspawn_nativeuninstall_0500.json | 14 -- ...b_startup_appspawn_nativeuninstall_0500.py | 129 ----------- ...startup_appspawn_nativeuninstall_0600.json | 14 -- ...b_startup_appspawn_nativeuninstall_0600.py | 147 ------------- ...startup_appspawn_nativeuninstall_0700.json | 14 -- ...b_startup_appspawn_nativeuninstall_0700.py | 143 ------------- .../sub_startup_appspawn_hnpinstall_0100.json | 12 -- .../sub_startup_appspawn_hnpinstall_0100.py | 74 ------- .../sub_startup_appspawn_hnpinstall_0200.json | 12 -- .../sub_startup_appspawn_hnpinstall_0200.py | 68 ------ .../sub_startup_appspawn_hnpinstall_0300.json | 12 -- .../sub_startup_appspawn_hnpinstall_0300.py | 77 ------- .../sub_startup_appspawn_hnpinstall_0400.json | 12 -- .../sub_startup_appspawn_hnpinstall_0400.py | 72 ------- .../sub_startup_appspawn_hnpinstall_0500.json | 12 -- .../sub_startup_appspawn_hnpinstall_0500.py | 74 ------- .../sub_startup_appspawn_hnpinstall_0600.json | 12 -- .../sub_startup_appspawn_hnpinstall_0600.py | 74 ------- .../sub_startup_appspawn_hnpinstall_0700.json | 12 -- .../sub_startup_appspawn_hnpinstall_0700.py | 75 ------- .../sub_startup_appspawn_hnpinstall_0800.json | 12 -- .../sub_startup_appspawn_hnpinstall_0800.py | 78 ------- .../sub_startup_appspawn_hnpinstall_0900.json | 12 -- .../sub_startup_appspawn_hnpinstall_0900.py | 71 ------- ...sub_startup_appspawn_nativespawn_0100.json | 12 -- .../sub_startup_appspawn_nativespawn_0100.py | 83 -------- ...sub_startup_appspawn_nativespawn_0200.json | 12 -- .../sub_startup_appspawn_nativespawn_0200.py | 82 ------- ...sub_startup_appspawn_nativespawn_0300.json | 12 -- .../sub_startup_appspawn_nativespawn_0300.py | 82 ------- ...sub_startup_appspawn_nativespawn_0400.json | 12 -- .../sub_startup_appspawn_nativespawn_0400.py | 82 ------- ...sub_startup_appspawn_nativespawn_0500.json | 12 -- .../sub_startup_appspawn_nativespawn_0500.py | 82 ------- ...sub_startup_appspawn_nativespawn_0700.json | 12 -- .../sub_startup_appspawn_nativespawn_0700.py | 82 ------- ...sub_startup_appspawn_nativespawn_0900.json | 12 -- .../sub_startup_appspawn_nativespawn_0900.py | 84 -------- ...sub_startup_appspawn_nativespawn_1000.json | 12 -- .../sub_startup_appspawn_nativespawn_1000.py | 91 -------- ...sub_startup_appspawn_nativespawn_1100.json | 12 -- .../sub_startup_appspawn_nativespawn_1100.py | 91 -------- ...sub_startup_appspawn_nativespawn_1200.json | 12 -- .../sub_startup_appspawn_nativespawn_1200.py | 91 -------- ...sub_startup_appspawn_nativespawn_1300.json | 12 -- .../sub_startup_appspawn_nativespawn_1300.py | 91 -------- ...sub_startup_appspawn_nativespawn_1400.json | 12 -- .../sub_startup_appspawn_nativespawn_1400.py | 90 -------- ...sub_startup_appspawn_nativespawn_1500.json | 12 -- .../sub_startup_appspawn_nativespawn_1500.py | 85 -------- ...sub_startup_appspawn_nativespawn_1600.json | 12 -- .../sub_startup_appspawn_nativespawn_1600.py | 78 ------- ...sub_startup_appspawn_nativespawn_1700.json | 12 -- .../sub_startup_appspawn_nativespawn_1700.py | 83 -------- ...sub_startup_appspawn_nativespawn_1800.json | 12 -- .../sub_startup_appspawn_nativespawn_1800.py | 93 -------- ...sub_startup_appspawn_nativespawn_1900.json | 12 -- .../sub_startup_appspawn_nativespawn_1900.py | 102 --------- .../sub_startup_appspawn_cgroup_0100.json | 14 -- .../sub_startup_appspawn_cgroup_0100.py | 74 ------- .../sub_startup_appspawn_cgroup_0200.json | 14 -- .../sub_startup_appspawn_cgroup_0200.py | 73 ------- .../sub_startup_appspawn_cgroup_0300.json | 14 -- .../sub_startup_appspawn_cgroup_0300.py | 73 ------- .../sub_startup_appspawn_coldstart_0100.json | 14 -- .../sub_startup_appspawn_coldstart_0100.py | 52 ----- ...tartup_appspawn_coldstart_ablity_0100.json | 14 -- ..._startup_appspawn_coldstart_ablity_0100.py | 59 ------ ...tartup_appspawn_coldstart_ablity_0200.json | 14 -- ..._startup_appspawn_coldstart_ablity_0200.py | 58 ----- .../sub_startup_appspawn_appclone_0100.json | 13 -- .../sub_startup_appspawn_appclone_0100.py | 76 ------- .../sub_startup_appspawn_appclone_0200.json | 13 -- .../sub_startup_appspawn_appclone_0200.py | 76 ------- .../sub_startup_appspawn_appclone_0300.json | 15 -- .../sub_startup_appspawn_appclone_0300.py | 100 --------- .../sub_startup_appspawn_appclone_0400.json | 15 -- .../sub_startup_appspawn_appclone_0400.py | 85 -------- .../sub_startup_appspawn_appclone_0600.json | 15 -- .../sub_startup_appspawn_appclone_0600.py | 80 ------- .../sub_startup_appspawn_appclone_0700.json | 15 -- .../sub_startup_appspawn_appclone_0700.py | 99 --------- .../sub_startup_appspawn_appclone_0900.json | 15 -- .../sub_startup_appspawn_appclone_0900.py | 87 -------- ...sub_startup_appspawn_atomservice_0100.json | 14 -- .../sub_startup_appspawn_atomservice_0100.py | 102 --------- ...sub_startup_appspawn_atomservice_0200.json | 15 -- .../sub_startup_appspawn_atomservice_0200.py | 149 ------------- ...sub_startup_appspawn_atomservice_0300.json | 14 -- .../sub_startup_appspawn_atomservice_0300.py | 64 ------ ...sub_startup_appspawn_atomservice_0400.json | 15 -- .../sub_startup_appspawn_atomservice_0400.py | 112 ---------- .../sub_startup_appspawn_base_0100.json | 14 -- .../sub_startup_appspawn_base_0100.py | 48 ----- .../sub_startup_appspawn_base_0200.json | 14 -- .../sub_startup_appspawn_base_0200.py | 60 ------ .../sub_startup_appspawn_base_0300.json | 14 -- .../sub_startup_appspawn_base_0300.py | 60 ------ .../sub_startup_appspawn_base_0400.json | 14 -- .../sub_startup_appspawn_base_0400.py | 63 ------ .../sub_startup_appspawn_base_0500.json | 14 -- .../sub_startup_appspawn_base_0500.py | 56 ----- .../sub_startup_appspawn_base_0600.json | 14 -- .../sub_startup_appspawn_base_0600.py | 84 -------- 197 files changed, 20 insertions(+), 10417 deletions(-) delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.py delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.json delete mode 100644 test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.py delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.json delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.py delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.json delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.py delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.json delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.py delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.json delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.py delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.json delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.py delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.json delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.py delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.json delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.py delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.json delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.py delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.json delete mode 100644 test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.py delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.json delete mode 100644 test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.py delete mode 100644 test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.json delete mode 100644 test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.py delete mode 100644 test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.json delete mode 100644 test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.py delete mode 100644 test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.json delete mode 100644 test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.py delete mode 100644 test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.json delete mode 100644 test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.py delete mode 100644 test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.json delete mode 100644 test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.py delete mode 100644 test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.json delete mode 100644 test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.py delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.json delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.json delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.json delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.json delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.json delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.json delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.json delete mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py 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_0200.json delete mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.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 delete mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.json delete mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py delete mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.json delete mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py delete mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.json delete mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py delete mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.json delete mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py delete mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.json delete mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py delete mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.json delete mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py delete mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.json delete mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py diff --git a/appdata-sandbox-app.json b/appdata-sandbox-app.json index 5916a3f0..a91144e1 100755 --- a/appdata-sandbox-app.json +++ b/appdata-sandbox-app.json @@ -13,7 +13,7 @@ "sandbox-path" : "/dev" }, { "src-path" : "/proc", - "sandbox-path" : "/proc" + "sandbox-path" : "/proc" }, { "src-path" : "/sys", "sandbox-path" : "/sys" @@ -61,7 +61,7 @@ "sandbox-path" : "/vendor/" }, { "src-path" : "/vendor/etc/vulkan", - "sandbox-path" : "/vendor/etc/vulkan" + "sandbox-path" : "/vendor/etc/vulkan" }, { "src-path" : "/vendor/etc/silk", "sandbox-path" : "/vendor/etc/silk" @@ -96,8 +96,8 @@ "src-path" : "/data/service/el1/public/cert_manager_service/certificates/user_open", "sandbox-path" : "/data/certificates/user_cacerts" },{ - "sandbox-path" : "/chip_prod/etc/passthrough", - "src-path" : "/chip_prod/etc/passthrough" + "src-path" : "/chip_prod/etc/passthrough", + "sandbox-path" : "/chip_prod/etc/passthrough" }], "mount-files": [{ "src-path" : "/system/etc/hosts", @@ -338,7 +338,7 @@ }] }, { "name": "ohos.permission.RECEIVE_UPDATE_MESSAGE", - "mount-paths": [{ + "mount-paths": [{ "src-path": "/data/service/el1/public/update/param_service/install/system/etc/", "sandbox-path": "/data/service/el1/public/update/param_service/install/system/etc/" }] @@ -574,4 +574,4 @@ "category": "shared" }] }] -} \ No newline at end of file +} diff --git a/bundle.json b/bundle.json index 878786fa..100c49a8 100644 --- a/bundle.json +++ b/bundle.json @@ -74,12 +74,12 @@ "dlp_permission_service", "ffrt" ], - "third_party": [ + "third_party": [ "bounds_checking_function", "zlib", "selinux", "cJSON" - ] + ] }, "build": { "sub_component": [ diff --git a/modules/common/appspawn_namespace.c b/modules/common/appspawn_namespace.c index 8122410f..5f087023 100644 --- a/modules/common/appspawn_namespace.c +++ b/modules/common/appspawn_namespace.c @@ -32,7 +32,7 @@ #define PID_NS_INIT_UID 100000 // reserved for pid_ns_init process, avoid app, render proc, etc. #define PID_NS_INIT_GID 100000 -typedef struct TagAppSpawnNamespace { +typedef struct { AppSpawnExtData extData; int nsSelfPidFd; // ns pid fd of appspawn int nsInitPidFd; // ns pid fd of pid_ns_init diff --git a/modules/nweb_adapter/nwebspawn_adapter.cpp b/modules/nweb_adapter/nwebspawn_adapter.cpp index f07dd124..f3af3945 100644 --- a/modules/nweb_adapter/nwebspawn_adapter.cpp +++ b/modules/nweb_adapter/nwebspawn_adapter.cpp @@ -109,17 +109,15 @@ APPSPAWN_STATIC int RunChildProcessor(AppSpawnContent *content, AppSpawnClient * const std::string renderLibName = GetArkWebRenderLibName(); #ifdef __MUSL__ - Dl_namespace dlns; + Dl_namespace dlns, ndkns; dlns_init(&dlns, "nweb_ns"); dlns_create(&dlns, libPath.c_str()); - Dl_namespace ndkns; dlns_get("ndk", &ndkns); dlns_inherit(&dlns, &ndkns, "allow_all_shared_libs"); // preload libweb_engine webEngineHandle = dlopen_ns(&dlns, engineLibName.c_str(), RTLD_NOW | RTLD_GLOBAL); // load libnweb_render - nwebRenderHandle = - dlopen_ns(&dlns, renderLibName.c_str(), RTLD_NOW | RTLD_GLOBAL); + nwebRenderHandle = dlopen_ns(&dlns, renderLibName.c_str(), RTLD_NOW | RTLD_GLOBAL); #else // preload libweb_engine const std::string engineLibPath = libPath + "/" + engineLibName; diff --git a/modules/sandbox/sandbox_expand.c b/modules/sandbox/sandbox_expand.c index dfc4091b..7c53fcb8 100644 --- a/modules/sandbox/sandbox_expand.c +++ b/modules/sandbox/sandbox_expand.c @@ -167,7 +167,7 @@ static int SetOverlayAppPath(const char *hapPath, void *context) sandboxContext->buffer[0].buffer, sandboxContext->buffer[1].buffer); ret = MakeDirRec(sandboxContext->buffer[1].buffer, FILE_MODE, 1); - APPSPAWN_CHECK(ret == 0, return ret, "Fail to mkdir dir %{public}s, ret :%{public}d", + APPSPAWN_CHECK(ret == 0, return ret, "Fail to mkdir dir %{public}s, ret: %{public}d", sandboxContext->buffer[1].buffer, ret); MountArg mountArg = { sandboxContext->buffer[0].buffer, sandboxContext->buffer[1].buffer, NULL, MS_REC | MS_BIND, NULL, MS_SHARED diff --git a/modules/sysevent/hisysevent_adapter.cpp b/modules/sysevent/hisysevent_adapter.cpp index 323ec1ae..8e1dbad1 100644 --- a/modules/sysevent/hisysevent_adapter.cpp +++ b/modules/sysevent/hisysevent_adapter.cpp @@ -85,7 +85,7 @@ static int CreateHisysTimerLoop(AppSpawnHisyseventInfo *hisyseventInfo) return ret; } -AppSpawnHisyseventInfo *GetAppSpawnHisyseventInfo() +AppSpawnHisyseventInfo *GetAppSpawnHisyseventInfo(void) { AppSpawnHisyseventInfo *hisyseventInfo = static_cast(malloc(sizeof(AppSpawnHisyseventInfo))); @@ -108,7 +108,7 @@ void DeleteHisyseventInfo(AppSpawnHisyseventInfo *hisyseventInfo) hisyseventInfo = NULL; } -AppSpawnHisyseventInfo *InitHisyseventTimer() +AppSpawnHisyseventInfo *InitHisyseventTimer(void) { AppSpawnHisyseventInfo *hisyseventInfo = GetAppSpawnHisyseventInfo(); APPSPAWN_CHECK(hisyseventInfo != NULL, return NULL, "fail to init hisyseventInfo"); diff --git a/modules/sysevent/hisysevent_adapter.h b/modules/sysevent/hisysevent_adapter.h index 649842a3..89f3fbac 100644 --- a/modules/sysevent/hisysevent_adapter.h +++ b/modules/sysevent/hisysevent_adapter.h @@ -88,8 +88,8 @@ typedef struct { AppSpawnHisysevent manualEvent; // bootFinished } AppSpawnHisyseventInfo; -AppSpawnHisyseventInfo *InitHisyseventTimer(); -AppSpawnHisyseventInfo *GetAppSpawnHisyseventInfo(); +AppSpawnHisyseventInfo *InitHisyseventTimer(void); +AppSpawnHisyseventInfo *GetAppSpawnHisyseventInfo(void); void AddStatisticEventInfo(AppSpawnHisyseventInfo *hisyseventInfo, uint32_t duration, bool stage); void DeleteHisyseventInfo(AppSpawnHisyseventInfo *hisyseventInfo); diff --git a/standard/appspawn_appmgr.c b/standard/appspawn_appmgr.c index e0615cc1..f8703828 100644 --- a/standard/appspawn_appmgr.c +++ b/standard/appspawn_appmgr.c @@ -235,7 +235,6 @@ int KillAndWaitStatus(pid_t pid, int sig, int *exitStatus) int retry = 0; pid_t exitPid = 0; - while (retry * SLEEP_DURATION < EXIT_APP_TIMEOUT) { exitPid = waitpid(pid, exitStatus, WNOHANG); if (exitPid == pid) { diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index efdb8d4d..a900df5c 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -36,6 +36,7 @@ #include "appspawn_manager.h" #include "appspawn_msg.h" #include "appspawn_server.h" +#include "appspawn_trace.h" #include "appspawn_utils.h" #include "init_socket.h" #include "init_utils.h" @@ -457,7 +458,9 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer, // decode msg ret = DecodeAppSpawnMsg(message); APPSPAWN_CHECK_ONLY_EXPER(ret == 0, break); + StartAppspawnTrace("ProcessRecvMsg"); (void)ProcessRecvMsg(connection, message); + FinishAppspawnTrace(); message = NULL; currLen += buffLen - reminder; } while (reminder > 0); @@ -624,6 +627,7 @@ static int AddChildWatcher(AppSpawningCtx *property) { uint32_t defTimeout = IsChildColdRun(property) ? COLD_CHILD_RESPONSE_TIMEOUT : WAIT_CHILD_RESPONSE_TIMEOUT; uint32_t timeout = GetSpawnTimeout(defTimeout); + LE_WatchInfo watchInfo = {}; watchInfo.fd = property->forkCtx.fd[0]; watchInfo.flags = WATCHER_ONCE; diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.json deleted file mode 100644 index 5eb12fdc..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0200.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.py deleted file mode 100644 index 772960de..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0200.py +++ /dev/null @@ -1,130 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0200(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1" - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # hnp进程安装传参校验 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("执行./hnp install") - result = self.driver.shell( - f"{self.hnp_commamd} install") - self.driver.Assert.contains(result, "native manager process exit. ret=8392706") - self.driver.Assert.contains(result, "[ERROR][HNP]hnp install params invalid,uid[(null)],hnp src path[(null)], package name[(null)]") - - Step("执行./hnp install -u 300, 只传userId") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392706 ") - - Step("执行./hnp install -p baidu, 只传应用软件名") - result = self.driver.shell( - f"{self.hnp_commamd} install -p baidu") - self.driver.Assert.contains(result, - "[ERROR][HNP]hnp install params invalid,uid[(null)]," - "hnp src path[(null)], package name[baidu]") - - Step("执行./hnp install -i hnppath, 只传安装路径") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public/ -n hnp_test1 -v 1.3") - self.driver.Assert.contains(result, "linkNum=0, ret=0") - result = self.driver.shell(f"find {self.pack_out_path}/public/ -name hnp_test1.hnp") - self.driver.Assert.contains(result, f"{self.pack_out_path}/public/hnp_test1.hnp") - - result = self.driver.shell( - f"{self.hnp_commamd} install -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[ERROR][HNP]hnp install params invalid," - "uid[(null)],hnp src path[/data/hnp_test/pack_output], " - "package name[(null)]") - - Step("执行./hnp install -f, 只传-f") - result = self.driver.shell( - f"{self.hnp_commamd} install -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392706") - - Step("执行./hnp uninstall") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall") - self.driver.Assert.contains(result, - "[ERROR][HNP]hnp uninstall params invalid uid[(null)], package name[(null)]") - - Step("执行./hnp pack") - result = self.driver.shell( - f"{self.hnp_commamd} pack") - self.driver.Assert.contains(result, "[ERROR][HNP]invalid cmd!. cmd:pack") - - Step("执行./hnp help") - result = self.driver.shell( - f"{self.hnp_commamd} help") - self.driver.Assert.contains(result, "install: install one hap package") - self.driver.Assert.contains(result, "uninstall: uninstall one hap package") - - Step("执行./hnp -h") - result = self.driver.shell( - f"{self.hnp_commamd} -h") - self.driver.Assert.contains(result, "install: install one hap package") - self.driver.Assert.contains(result, "uninstall: uninstall one hap package") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.json deleted file mode 100644 index 1e65f616..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0300.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.py deleted file mode 100644 index 36d335ec..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0300.py +++ /dev/null @@ -1,122 +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. - -import os -from aw import Common -from hypium import * -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0300(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" - self.hnp_public_dir = "hnppublic/bin" - self.hnp_private_dir = "hnp/baidu/bin" - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # hnp进程安装,hnp包路径异常场景 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("安装软件包时,hnp包路径不存在") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i /data/empty_path/ -f") - self.driver.Assert.contains(result, "[ERROR][HNP]hnp install opendir:/data/empty_path/ unsuccess, errno=2") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392968") - - Step("安装软件包时,hnp包路径长度等于4096") - dir_temp = "/data/" + Common.randomGenerateStingByLen(4090) - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {dir_temp} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392968") - - Step("安装软件包时,hnp包路径长度大于4096") - dir_temp = "/data/" + Common.randomGenerateStingByLen(4096) - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {dir_temp} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392968") - - Step("安装软件包时,hnp包路径中存在非法字符") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i /data/empty**#…………_path/ -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392968") - - Step("安装软件包时,安装路径为空文件夹") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - - Step("安装软件包时没有公有或者私有数据文件夹") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path} -n compute -v 1.3") - self.driver.Assert.contains(result, "linkNum=0, ret=0") - result = self.driver.shell(f"find {self.pack_out_path} -name compute.hnp") - self.driver.Assert.contains(result, f"{self.pack_out_path}/compute.hnp") - - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - - Step("验证软链接是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add 2") - self.driver.Assert.contains(result, "add: inaccessible or not found") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_private_dir}/add 2") - self.driver.Assert.contains(result, "add: inaccessible or not found") - - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.json deleted file mode 100644 index a6ab7e34..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0400.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.py deleted file mode 100644 index b3b6ad8c..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0400.py +++ /dev/null @@ -1,86 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0400(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # hnp进程安装,保存路径异常场景 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("将compute工具进行打包") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public -n compute -v 1.0") - self.driver.Assert.contains(result, "linkNum=0, ret=0") - - Step("保存路径不存在") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 301 -i {self.pack_out_path} -p baidu -f") - self.driver.Assert.contains(result, "hnp install uid path[/data/app/el1/bundle/301] is not exist") - - Step("usrId为字符串") - result = self.driver.shell( - f"{self.hnp_commamd} install -u string -i {self.pack_out_path} -p baidu -f") - self.driver.Assert.contains(result, "[ERROR][HNP]hnp install arg uid[string] invalid") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.json deleted file mode 100644 index e133c374..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0500.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.py deleted file mode 100644 index f920ee93..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0500.py +++ /dev/null @@ -1,88 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0500(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output/" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - # 安装用户usrId = 0的场景 & 安装工具为1个的场景 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("将compute工具进行打包") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public -n compute -v 1.0") - self.driver.Assert.contains(result, "linkNum=0, ret=0") - - Step("安装软件时usrId为0") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 0 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - - Step("校验安装工具生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/0/{self.hnp_public_dir}/add") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - else: - pass - - Step("卸载安装的工具") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 0 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.json deleted file mode 100644 index eee9bb51..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0600.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.py deleted file mode 100644 index 86ce6f4e..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0600.py +++ /dev/null @@ -1,113 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0600(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello"] - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 安装目录下存在多个hnp包测试 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("打包两个工具 compute & printfHello") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public -n compute -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path}/public -n printfHello -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("批量安装compute、printfHello工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - - Step("验证软链接是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") - self.driver.Assert.contains(result, "End: 1 - 1 = 0") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/multiplication") - self.driver.Assert.contains(result, "End: 1 * 1 = 1") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello 2") - self.driver.Assert.contains(result, "****************hello**************") - - Step("卸载安装的工具") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "hnp uninstall end! ret=0") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello 2") - self.driver.Assert.contains(result, "printfHello: inaccessible or not found") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.json deleted file mode 100644 index c8024766..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0700.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.py deleted file mode 100644 index 703e7c98..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0700.py +++ /dev/null @@ -1,95 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0700(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello" - self.hnp_public_dir = "hnppublic/bin" - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 打包文件未设置软链接路径,安装hnp包时可执行文件在非bin目录下场景 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建一个空目录temp_dir,该目录下存在一个二进制文件printfHello") - self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/") - self.driver.shell(f"cp {self.native_path}/bin/* {self.work_space_path}/temp_dir/") - - Step("打包temp_dir为test.hnp包") - result = self.driver.shell(f"{self.hnpcli_commamd} pack -i {self.work_space_path}/temp_dir/ " - f"-o {self.pack_out_path}/public -n test -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("安装test.hnp") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}/ -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - - Step("验证软链接是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello 2") - self.driver.Assert.contains(result, "printfHello: inaccessible or not found") - - Step("验证是否存在test.org") - result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic -name test.org") - self.driver.Assert.contains(result, "test.org") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.json deleted file mode 100644 index 2c273d11..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0800.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.py deleted file mode 100644 index 7168e5e8..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0800.py +++ /dev/null @@ -1,108 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0800(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello"] - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 打包文件未设置软链接路径,安装hnp包时可执行文件在bin目录,且bin目录下同时存在一个bin目录,第二个bin目录下存在二进制的测试场景 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建一个temp_dir目录,创建bin/bin目录,bin目录下分别存在一个二进制") - self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/") - self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/bin/") - self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/bin/bin/") - self.driver.shell(f"cp {self.native_path[1]}/bin/printfHello {self.work_space_path}/temp_dir/bin") - self.driver.shell(f"cp {self.native_path[0]}/bin/add {self.work_space_path}/temp_dir/bin/bin") - - Step("打包该native文件为test.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.work_space_path}/temp_dir/ -o " - f"{self.pack_out_path}/public -n test -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("强制安装test.hnp") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - - Step("校验bin/printfHello工具生效,bin/bin/add未生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello 2") - self.driver.Assert.contains(result, "****************hello**************") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") - self.driver.Assert.contains(result, "add: inaccessible or not found") - - Step("卸载安装的工具") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("清除安装内容") - self.driver.shell(f"rm -rf {self.work_space_path}/temp_dir/") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.json deleted file mode 100644 index dea6af44..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0900.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.py deleted file mode 100644 index e2406b4f..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_0900.py +++ /dev/null @@ -1,105 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_0900(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 打包文件未设置软链接路径,安装hnp包时可执行文件在bin目录,且bin目录下仅存在一个文件夹 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建一个temp_dir目录,创建bin/test目录") - self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/") - self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/bin/") - self.driver.shell(f"mkdir {self.work_space_path}/temp_dir/bin/test/") - - Step("打包该native文件为test.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.work_space_path}/temp_dir/ " - f"-o {self.pack_out_path}/public -n test -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("强制安装test.hnp") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - - Step("验证是否存在test.org") - result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic -name test.org") - self.driver.Assert.contains(result, "test.org") - - result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic -name bin") - self.driver.Assert.contains(result, "bin") - - Step("验证bin目录下是否存在test文件夹") - result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic/bin -name test") - assert ("test" not in result) == True - - Step("清除安装内容") - self.driver.shell(f"rm -rf {self.work_space_path}/temp_dir/") - - Step("卸载安装的工具") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.json deleted file mode 100644 index 7cdabaeb..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1000.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.py deleted file mode 100644 index 2fa19067..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1000.py +++ /dev/null @@ -1,95 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1000(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/private') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 需要安装的hnp为空文件 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建一个空文件夹empty_dir") - self.driver.shell(f"mkdir {self.work_space_path}/empty_dir/") - - Step("打包该native文件为test.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.work_space_path}/empty_dir/ " - f"-o {self.pack_out_path}/private -n empty -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("强制安装test.hnp") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - - Step("验证是否存在test.org") - result = self.driver.shell(f"find {self.default_install_root_path}/300/hnp/baidu -name empty.org") - self.driver.Assert.contains(result, "empty.org") - - Step("卸载安装的工具") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - - self.driver.shell(f"rm -rf {self.work_space_path}/empty_dir/") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.json deleted file mode 100644 index 16b1c327..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1100.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.py deleted file mode 100644 index 21493dd6..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1100.py +++ /dev/null @@ -1,100 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1100(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1" - self.hnp_public_dir = "hnppublic/bin" - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/private') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 安装单个hnp中存在0软链接 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("打包的sample1包为sample1.hnp,该native包中bin文件下为非可执行文件") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/private -n sample1 -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("强制安装sample1.hnp") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("验证是否存在sample1.org") - result = self.driver.shell(f"find {self.default_install_root_path}/300/hnp/baidu -name sample1.org") - self.driver.Assert.contains(result, "sample1.org") - - Step("验证hnp/baidu/bin目录下是否存在sample.txt") - result = self.driver.shell( - f"find {self.default_install_root_path}/300/hnp/baidu/bin -name sample.txt") - self.driver.Assert.contains(result, "sample.txt") - - Step("卸载安装的工具") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - - result = self.driver.shell( - f"find {self.default_install_root_path}/300/hnp/baidu/bin -name sample.txt") - self.driver.Assert.contains(result, "No such file or directory") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.json deleted file mode 100644 index e7c27227..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1200.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.py deleted file mode 100644 index 82ada481..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1200.py +++ /dev/null @@ -1,105 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1200(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 安装单个hnp中存在1个软链接,软链接文件非可执行文件 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建配置文件,存在一个软链接,软链接类型.txt文件") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/sample.txt" - hnp_cfg_data['install']['links'][0]["target"] = "sample" - hnp_cfg_data['name'] = "sample" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) - - Step("打包sample1.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("强制安装sample1.hnp") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("验证hnp/hnppublic/bin目录下是否存在sample") - result = self.driver.shell(f"find {self.default_install_root_path}/300/{self.hnp_public_dir} -name sample") - self.driver.Assert.contains(result, f"sample") - - Step("卸载安装的工具") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.json deleted file mode 100644 index 323bacee..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1300.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.py deleted file mode 100644 index cd4f1bcc..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1300.py +++ /dev/null @@ -1,106 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1300(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 安装单个hnp中存在1个软链接,软链接文件为文件夹 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建配置文件,存在一个软链接,软链接为文件夹") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin" - hnp_cfg_data['install']['links'][0]["target"] = "printfSymbol_bin" - hnp_cfg_data['name'] = "printfSymbol_bin" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) - - Step("打包printfSymbol_bin.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("强制安装printfSymbol_bin.hnp") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("校验安装printfSymbol_bin.hnp是否成功,是否存在printfSymbol_bin软链") - result = self.driver.shell(f"find {self.default_install_root_path}/300/{self.hnp_public_dir} " - f"-name printfSymbol_bin") - self.driver.Assert.contains(result, "printfSymbol_bin") - - Step("卸载安装的工具") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.json deleted file mode 100644 index 64d18a9f..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1400.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.py deleted file mode 100644 index 7402fad8..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1400.py +++ /dev/null @@ -1,110 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1400(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 安装单个hnp中存在1个软链接,软链接文件为一个bin文件 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建配置文件,存在一个软链接,软链接路径指向其中一个bin文件") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/add" - hnp_cfg_data['install']['links'][0]["target"] = "add" - hnp_cfg_data['name'] = "add" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) - - Step("打包add.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("强制安装add.hnp") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("验证软链接是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") - self.driver.Assert.contains(result, "del: inaccessible or not found") - - Step("卸载安装的工具") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.json deleted file mode 100644 index b7cbc767..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1500.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.py deleted file mode 100644 index a0cbdd74..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1500.py +++ /dev/null @@ -1,112 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1500(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 安装单个hnp中存在2软链接,全部指向存在文件 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建配置文件,hnp中存在3个bin文件,2个软链接,软链接路径分别指向其中bin文件") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/add" - hnp_cfg_data['install']['links'][0]["target"] = "add" - hnp_cfg_data['install']['links'].append({"source": "bin/del", "target": "del"}) - hnp_cfg_data['name'] = "compute" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) - - Step("打包compute.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public " - f"-cfg {self.work_space_path}/compute.json") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("强制安装compute.hnp") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("验证安装compute.hnp是否成功,软链接是否可执行") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") - self.driver.Assert.contains(result, "End: 1 - 1 = 0") - - Step("卸载安装的工具") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.json deleted file mode 100644 index 9975cf61..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1600.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.py deleted file mode 100644 index f2447b6c..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1600.py +++ /dev/null @@ -1,150 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1600(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/readCfgFile", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol"] - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 执行安装包下存在3个hnp包,全部包含软链接 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建compute工具配置文件,存在3个bin文件,3个软链接,软链接路径分别指向其中bin文件") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/add" - hnp_cfg_data['install']['links'][0]["target"] = "add" - hnp_cfg_data['install']['links'].append({"source": "bin/del", "target": "del"}) - hnp_cfg_data['install']['links'].append({"source": "bin/multiplication", "target": "multiplication"}) - hnp_cfg_data['name'] = "compute" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - - Step("创建readCfgFile工具配置文件,存在1个bin文件,1个软链接,软链接路径指向bin文件") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/readCfgFile" - hnp_cfg_data['install']['links'][0]["target"] = "readCfgFile" - hnp_cfg_data['name'] = "readCfgFile" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[1]) - - Step("创建printfSymbol工具配置文件,存在1个bin文件,1个软链接,软链接路径指向bin文件") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/printfSymbol" - hnp_cfg_data['install']['links'][0]["target"] = "printfSymbol" - hnp_cfg_data['name'] = "printfSymbol" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[2]) - - Step("打包compute.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包readCfgFile.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包printfSymbol.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[2]} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("批量安装compute & printfHello & printfSymbol工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("校验设置软链接是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") - self.driver.Assert.contains(result, "End: 1 - 1 = 0") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/multiplication") - self.driver.Assert.contains(result, "End: 1 * 1 = 1") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfSymbol") - self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/readCfgFile") - self.driver.Assert.contains(result, "cfg file test test test") - - Step("卸载安装好的native软件包") - self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.json deleted file mode 100644 index 7ec4c65e..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1700.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.py deleted file mode 100644 index b7ebcc24..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1700.py +++ /dev/null @@ -1,126 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1700(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/readCfgFile", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol"] - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 执行安装包下存在3个hnp包,全部不包含软连接配置 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("打包compute.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public -n compute -v 1.2") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包readCfgFile.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[1]} " - f"-o {self.pack_out_path}/public -n readCfgFile -v 1.2") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包printfSymbol.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[2]} " - f"-o {self.pack_out_path}/public -n printfSymbol -v 1.2") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("批量安装compute & printfHello & printfSymbol工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("校验设置软链接是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") - self.driver.Assert.contains(result, "End: 1 - 1 = 0") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/multiplication") - self.driver.Assert.contains(result, "End: 1 * 1 = 1") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfSymbol") - self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/readCfgFile") - self.driver.Assert.contains(result, "cfg file test test test") - - Step("卸载安装好的native软件包") - self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.json deleted file mode 100644 index 5090497d..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1800.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.py deleted file mode 100644 index 5a2f84b9..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1800.py +++ /dev/null @@ -1,86 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common -import shutil - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1800(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 安装的native包非hnpcli工具压缩文件 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建一个临时native包") - os.makedirs(f"{self.current_path}/test/") - os.makedirs(f"{self.current_path}/test/bin") - Common.writeDateToFile(f"{self.current_path}/test/bin/test.txt", "testtesttesttest") - - Step("使用zip工具压缩native包,名称为test.hnp") - Common.zip_folder("test", f"{self.current_path}/test.hnp") - self.driver.push_file(f"{self.current_path}\\test.hnp", f"{self.pack_out_path}/public") - Common.deleteFile(f"{self.current_path}\\test.hnp") - shutil.rmtree(f"{self.current_path}/test/") - - Step("安装test.hnp包") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[ERROR][HNP]hnp cfg file not found.") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.json deleted file mode 100644 index bf4d7ffb..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1900.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.py deleted file mode 100644 index 377a5b22..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_1900.py +++ /dev/null @@ -1,122 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_1900(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol"] - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 安装的native包对应的软链接名称相同 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建printfHello工具配置文件,软连接名称为printfHello") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/printfHello" - hnp_cfg_data['install']['links'][0]["target"] = "printfHello" - hnp_cfg_data['name'] = "printfHello" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - - Step("创建printfSymbol工具配置文件,软连接名称为printfHello") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/printfSymbol" - hnp_cfg_data['install']['links'][0]["target"] = "printfHello" - hnp_cfg_data['name'] = "printfSymbol" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[1]) - - Step("打包printfHello工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包printfSymbol工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("安装软链接同名工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("验证软连接是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello") - self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") - - Step("卸载安装好的native软件包") - self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello") - self.driver.Assert.contains(result, "printfHello: inaccessible or not found") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.json deleted file mode 100644 index f693122b..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2000.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.py deleted file mode 100644 index 31a0acfb..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2000.py +++ /dev/null @@ -1,136 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2000(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/readCfgFile"] - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/private') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 重复安装名称相同,版本相同的工具 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建compute工具配置文件,软连接名称为add") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/add" - hnp_cfg_data['install']['links'][0]["target"] = "add" - hnp_cfg_data['name'] = "compute" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - - Step("创建readCfgFile工具配置文件,软连接名称为readCfgFile") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/readCfgFile" - hnp_cfg_data['install']['links'][0]["target"] = "readCfgFile" - hnp_cfg_data['name'] = "readCfgFile" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[1]) - - Step("打包printfHello工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/private") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包printfSymbol工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path}/private") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("安装compute & readCfgFile工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("验证工具是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/baidu/bin/readCfgFile") - self.driver.Assert.contains(result, "cfg file test test test") - - Step("重复安装compute & readCfgFile工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393476 ") - - Step("重复强安装compute & readCfgFile工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/baidu/bin/readCfgFile") - self.driver.Assert.contains(result, "cfg file test test test") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/baidu/bin/add") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - Step("卸载安装好的native软件包") - self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.json deleted file mode 100644 index e57ad7f4..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2100.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.py deleted file mode 100644 index f60162a9..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2100.py +++ /dev/null @@ -1,157 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2100(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/readCfgFile", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello"] - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 重复安装相同名称,版本不同的安装工具 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建compute工具配置文件,软连接名称为add") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/add" - hnp_cfg_data['install']['links'][0]["target"] = "add" - hnp_cfg_data['name'] = "compute" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - - Step("创建readCfgFile工具配置文件,软连接名称为readCfgFile") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/readCfgFile" - hnp_cfg_data['install']['links'][0]["target"] = "readCfgFile" - hnp_cfg_data['name'] = "readCfgFile" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[1]) - - Step("打包printfHello工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包printfSymbol工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("安装compute & readCfgFile工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("安装的新的native.hnp") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/printfHello" - hnp_cfg_data['install']['links'][0]["target"] = "printfHello" - hnp_cfg_data['name'] = "readCfgFile" - hnp_cfg_data['version'] = "2.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[2]) - - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[2]} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("重复非强制安装readCfgFile 2.0版本工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393476 ") - - Step("重复强制安装readCfgFile 2.0版本工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("验证工具是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello 2") - self.driver.Assert.contains(result, "****************hello**************") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/readCfgFile") - self.driver.Assert.contains(result, "readCfgFile: inaccessible or not found") - - result = self.driver.shell( - f"find {self.default_install_root_path}/300/hnppublic/readCfgFile.org/ -name readCfgFile_1.0") - assert ("multiplication" not in result) == True - - result = self.driver.shell( - f"find {self.default_install_root_path}/300/hnppublic/readCfgFile.org/ -name readCfgFile_2.0") - self.driver.Assert.contains(result, "readCfgFile_2.0") - - Step("卸载安装好的native软件包") - self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.json deleted file mode 100644 index d5183678..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2200.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.py deleted file mode 100644 index 3dcc13ae..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2200.py +++ /dev/null @@ -1,105 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2200(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 安装hnp存在两个软链接,不同的软链接路径,相同的配置名称 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建compute工具配置文件,工具add的软连接名称为compute,工具del的软连接名称为compute") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/add" - hnp_cfg_data['install']['links'][0]["target"] = "compute" - hnp_cfg_data['install']['links'].append({"source": "bin/del", "target": "compute"}) - hnp_cfg_data['name'] = "compute" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) - - Step("打包compute工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("安装compute工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("验证工具是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/compute") - self.driver.Assert.contains(result, "End: 1 - 1 = 0") - - Step("卸载安装好的native软件包") - self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.json deleted file mode 100644 index 690e61cc..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2300.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.py deleted file mode 100644 index d9129f4a..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2300.py +++ /dev/null @@ -1,114 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2300(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 重复安装hnp中的软链接无target name - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建compute工具配置文件,工具del的软连接名称为del_temp,工具add、multiplication无软链接name") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/del" - hnp_cfg_data['install']['links'][0]["target"] = "del_temp" - hnp_cfg_data['install']['links'].append({"source": "bin/add"}) - hnp_cfg_data['install']['links'].append({"source": "bin/multiplication"}) - hnp_cfg_data['name'] = "compute_no_target" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) - - Step("打包compute_no_target.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("安装compute_no_target工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("验证工具是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del_temp") - self.driver.Assert.contains(result, "End: 1 - 1 = 0") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/multiplication") - self.driver.Assert.contains(result, "End: 1 * 1 = 1") - - Step("卸载安装好的native软件包") - self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.json deleted file mode 100644 index 62eab870..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2400.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.py deleted file mode 100644 index 7d518c3c..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2400.py +++ /dev/null @@ -1,124 +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. - -from devicetest.core.test_case import Step, TestCase -from hypium import * -import os -import time -import threading -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2400(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - def worker(self): - Step("执行安装后的软件") - self.driver.shell(f"chmod +x /data/service/hnp/compute.org/compute_1.0/bin/add") - result = self.driver.shell( - f"./data/service/hnp/compute.org/compute_1.0/bin/add 4") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - # 重复安装hnp包时,工具正在使用 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建compute工具配置文件,工具add的软连接名称为compute,工具add的软连接名称为compute") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/add" - hnp_cfg_data['install']['links'][0]["target"] = "compute" - hnp_cfg_data['version'] = "1.0" - hnp_cfg_data['name'] = "compute" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) - - Step("打包compute工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - self.driver.shell(f'mkdir -p /data/service/hnp/compute.org/compute_1.0/') - self.driver.shell(f'cp -r {self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute/ ' - f'/data/service/hnp/compute.org/compute_1.0/') - - Step("安装compute工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("运行安装工具中的compute程序") - t1 = threading.Thread(target=self.worker) - t1.start() - time.sleep(1) - - Step("重复强制安装相同版本的hnp包") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - t1.join() - - Step("待程序运行结束后卸载安装好的native软件包") - self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.shell(f'rm -rf /data/service/hnp') - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.json deleted file mode 100644 index 414358a2..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2500.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.py deleted file mode 100644 index f4b2e5b5..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2500.py +++ /dev/null @@ -1,136 +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. - -import os -import time -import threading -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2500(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def worker(self): - Step("执行安装后的软件") - self.driver.shell(f"chmod +x /data/service/hnp/compute.org/compute_1.0/bin/add") - result = self.driver.shell( - f"./data/service/hnp/compute.org/compute_1.0/bin/add 10") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 重复安装升级版本的hnp包时,工具正在使用 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ALN" in device): - Step("创建compute工具配置文件,工具add的软连接名称为compute") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/add" - hnp_cfg_data['install']['links'][0]["target"] = "compute" - hnp_cfg_data['version'] = "1.0" - hnp_cfg_data['name'] = "compute" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) - - Step("打包compute工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - self.driver.shell(f'mkdir -p /data/service/hnp/compute.org/compute_1.0/') - self.driver.shell(f'cp -r {self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute/bin ' - f'/data/service/hnp/compute.org/compute_1.0/') - - Step("安装compute工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - t1 = threading.Thread(target=self.worker) - t1.start() - time.sleep(1) - Step("创建compute工具配置文件,工具del的软连接名称为compute,版本为2.0") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/del" - hnp_cfg_data['install']['links'][0]["target"] = "del" - hnp_cfg_data['version'] = "2.0" - hnp_cfg_data['name'] = "compute" - self.driver.shell(f"rm {self.native_path}/hnp.json") - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) - - Step("打包升级后的compute.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("重复强制安装不同版本的hnp包") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[ERROR][HNP]hnp install path is running now,") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392978") - t1.join() - - Step("卸载安装好的native软件包") - self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p baidu") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.json deleted file mode 100644 index e0193c70..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2600.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.py deleted file mode 100644 index 96d84f6d..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2600.py +++ /dev/null @@ -1,138 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2600(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - self.driver.shell(f'mkdir {self.pack_out_path}/private') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 私有路径与公有路径下安装相同工具 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("打包compute.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public -n compute -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/private -n compute -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("美团用户安装compute工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p meituan -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("验证meituan下是否存在compute.org") - result = self.driver.shell(f"find {self.default_install_root_path}/300/hnp/meituan -name compute.org") - self.driver.Assert.contains(result, "compute.org") - - result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic -name compute.org") - self.driver.Assert.contains(result, "compute.org") - - Step("验证私有路径软链接是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/meituan/bin/del") - self.driver.Assert.contains(result, "End: 1 - 1 = 0") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/meituan/bin/add") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/meituan/bin/multiplication") - self.driver.Assert.contains(result, "End: 1 * 1 = 1") - - Step("验证公有路径软链接是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") - self.driver.Assert.contains(result, "End: 1 - 1 = 0") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/multiplication") - self.driver.Assert.contains(result, "End: 1 * 1 = 1") - - Step("卸载美团应用安装软件") - result = self.driver.shell(f"{self.hnp_commamd} uninstall -u 300 -p meituan") - print("卸载", result) - - Step("验证meituan下是否存在compute.org") - result = self.driver.shell(f"find {self.default_install_root_path}/300/hnp/meituan -name compute.org") - assert ("compute.org" not in result) == True - - Step("验证公有路径下是否存在compute.org") - result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic -name compute.org") - assert ("compute.org" not in result) == True - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.json deleted file mode 100644 index 033da834..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2700.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.py deleted file mode 100644 index 35042cc3..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2700.py +++ /dev/null @@ -1,152 +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. - -import os -import time -from hypium import * -import threading -from aw import Common -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2700(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/readCfgFile", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def worker(self): - Step("执行安装后的软件") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add 4") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - self.driver.shell(f'mkdir {self.pack_out_path}/private') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 应用程序安装不同的软件(公有 + 私有) - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("打包compute工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public -n compute -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("百度安装compute工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包printfHello工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[3]} " - f"-o {self.pack_out_path}/private -n printfHello -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包printfSymbol工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[2]} " - f"-o {self.pack_out_path}/public -n printfSymbol -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("非强制增量安装软件") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - - Step("非强制重复安装软件") - self.driver.shell(f'rm {self.pack_out_path}/public/compute.hnp') - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393476 ") - - Step("验证软链接是否生效") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/baidu/bin/printfHello 2") - self.driver.Assert.contains(result, "****************hello**************") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") - self.driver.Assert.contains(result, "End: 1 - 1 = 0") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/multiplication") - self.driver.Assert.contains(result, "End: 1 * 1 = 1") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfSymbol") - self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") - - Step("卸载百度应用软件") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - self.driver.shell(f'rm /data/service/el1/startup/hnp_info.json') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.json deleted file mode 100644 index 78f5e5ea..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2800.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.py deleted file mode 100644 index 48ef5f91..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2800.py +++ /dev/null @@ -1,200 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2800(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def worker(self): - Step("执行安装后的软件") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add 4") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - self.driver.shell(f'mkdir {self.pack_out_path}/private') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 不同应用程序安装不同的软件 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("打包compute工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public -n compute -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包printfHello工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[1]} " - f"-o {self.pack_out_path}/private -n printfHello -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("baidu应用软件安装程序") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("meituan应用软件安装程序") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p meituan -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("校验安装工具可用") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/baidu/bin/printfHello 2") - self.driver.Assert.contains(result, "") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/meituan/bin/printfHello 2") - self.driver.Assert.contains(result, "") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") - self.driver.Assert.contains(result, "End: 1 - 1 = 0") - - Step("打包printfSymbol工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[2]} " - f"-o {self.pack_out_path}/private -n printfSymbol -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("强制安装elema应用软件安装程序") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p elema -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("校验安装工具可用") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/baidu/bin/printfHello 2") - self.driver.Assert.contains(result, "****************hello**************") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/elema/bin/printfHello 2") - self.driver.Assert.contains(result, "****************hello**************") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/meituan/bin/printfHello 2") - self.driver.Assert.contains(result, "****************hello**************") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/elema/bin/printfSymbol") - self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") - self.driver.Assert.contains(result, "End: 1 - 1 = 0") - - Step("卸载美团与百度安装的软件") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p meituan") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/baidu/bin/printfHello 2") - self.driver.Assert.contains(result, "printfHello: inaccessible or not found") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/meituan/bin/printfHello 2") - self.driver.Assert.contains(result, "printfHello: inaccessible or not found") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/elema/bin/printfHello 2") - self.driver.Assert.contains(result, "****************hello**************") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/elema/bin/printfSymbol") - self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") - self.driver.Assert.contains(result, "End: 1 - 1 = 0") - - Step("卸载饿了吗软件") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p elema") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/elema/bin/printfHello 2") - self.driver.Assert.contains(result, "printfHello: inaccessible or not found") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/elema/bin/printfSymbol") - self.driver.Assert.contains(result, "printfSymbol: inaccessible or not found") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") - self.driver.Assert.contains(result, "del: inaccessible or not found") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.json deleted file mode 100644 index 20715222..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2900.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.py deleted file mode 100644 index 0a2770d6..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeinstall_2900.py +++ /dev/null @@ -1,145 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEINSTALL_2900(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def worker(self): - Step("执行安装后的软件") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add 4") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - self.driver.shell(f'mkdir {self.pack_out_path}/private') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 多个应用程序安装不同版本的工具 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("打包compute工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public -n compute -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包printfHello工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[1]} " - f"-o {self.pack_out_path}/private -n printfHello -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("baidu应用软件安装程序") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包compute 2.0工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[2]} -o {self.pack_out_path}/public -n compute -v 2.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("非强制安装meituan应用软件安装程序") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p meituan -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393476") - - Step("强制安装meituan应用软件安装程序") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p meituan -i {self.pack_out_path} -f") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/meituan/bin/printfHello 1") - self.driver.Assert.contains(result, "****************hello**************") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfSymbol") - self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") - self.driver.Assert.contains(result, "del: inaccessible or not found") - - Step("卸载美团与百度安装的软件") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p meituan") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfSymbol") - self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") - - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.json deleted file mode 100644 index dbdb311a..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1000.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.py deleted file mode 100644 index a21b173a..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1000.py +++ /dev/null @@ -1,101 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEPACK_1000(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - - TestCase.__init__(self, self.TAG, controllers) - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - # hnpcli bin文件调用参数测试 - def test_step1(self): - Step("执行./hnpcli不传任何参数") - result = self.driver.shell(f"{self.hnpcli_commamd}") - - self.driver.Assert.contains(result, - "-i : [required] input path of software package dir") - self.driver.Assert.contains(result, - "-o : [optional] output path of hnp file. " - "if not set then ouput to current directory") - self.driver.Assert.contains(result, - "-n : [optional] software name. if not hnp.json in input dir then must set") - self.driver.Assert.contains(result, - "-v : [optional] software version. " - "if not hnp.json in input dir then must set") - - Step("执行./hnpcli help") - result = self.driver.shell(f"{self.hnpcli_commamd} help") - self.driver.Assert.contains(result, - "usage:hnpcli [-i ]" - "[-o ][-n ][-v ]") - self.driver.Assert.contains(result, - "-i : [required] input path of software package dir") - self.driver.Assert.contains(result, - "-o : [optional] output path of hnp file. " - "if not set then ouput to current directory") - self.driver.Assert.contains(result, - "-n : [optional] software name. if not hnp.json in input dir then must set") - self.driver.Assert.contains(result, - "-v : [optional] software version. " - "if not hnp.json in input dir then must set") - - Step("执行./hnpcli -h") - result = self.driver.shell(f"{self.hnpcli_commamd} help") - self.driver.Assert.contains(result, - "-i : [required] input path of software package dir") - self.driver.Assert.contains(result, - "-o : [optional] output path of hnp file. " - "if not set then ouput to current directory") - self.driver.Assert.contains(result, - "-n : [optional] software name. if not hnp.json in input dir then must set") - self.driver.Assert.contains(result, - "-v : [optional] software version. " - "if not hnp.json in input dir then must set") - - Step("执行./hnpcli pack") - result = self.driver.shell(f"{self.hnpcli_commamd} pack") - self.driver.Assert.contains(result, "[ERROR][HNP]source dir is null.") - - Step("执行./hnpcli pack2") - result = self.driver.shell(f"{self.hnpcli_commamd} pack2") - self.driver.Assert.contains(result, "[ERROR][HNP]invalid cmd!. cmd:pack2") - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.json deleted file mode 100644 index b8ea89e1..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1100.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.py deleted file mode 100644 index 1b2818c4..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1100.py +++ /dev/null @@ -1,68 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEPACK_1100(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - - TestCase.__init__(self, self.TAG, controllers) - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - # hnpcli 打包native包传参个数异常场景 - def test_step1(self): - Step("执行./hnpcli pack -i native包路径") - result = self.driver.shell(f"{self.hnpcli_commamd} pack -i {self.native_path[0]}") - self.driver.Assert.contains(result, "[ERROR][HNP]name or version argv is miss.") - - Step("执行./hnpcli pack -o 存储包目标路径") - result = self.driver.shell(f"{self.hnpcli_commamd} pack -o {self.pack_out_path[0]}") - self.driver.Assert.contains(result, "[ERROR][HNP]source dir is null.") - - Step("执行./hnpcli 传参等于四个参数,./hnpcli pack -i native包路径 -o 存储包目标路径,native包中无cfg配置文件") - result = self.driver.shell(f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[ERROR][HNP]name or version argv is miss.") - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.json deleted file mode 100644 index 89be5024..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1200.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.py deleted file mode 100644 index 533020e4..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1200.py +++ /dev/null @@ -1,87 +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. - -import os -from hypium import * -from aw import Common -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEPACK_1200(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - - TestCase.__init__(self, self.TAG, controllers) - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - # hnp程序打包native包,native包路径相关测试场景 - def test_step1(self): - Step("native包路径不存在") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.work_space_path}/empty_dir -o {self.pack_out_path} " - f"-n test -v 1.1") - self.driver.Assert.contains(result, "") - Step("native包路径下的文件夹为空") - self.driver.shell(f'mkdir {self.work_space_path}/empty_dir') - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.work_space_path}/empty_dir -o {self.pack_out_path} " - f"-n test -v 1.1") - self.driver.Assert.contains(result, - "[INFO][HNP]PackHnp end. srcPath=/data/hnp_test/empty_dir, " - "hnpName=test, hnpVer=1.1, hnpDstPath=/data/hnp_test/pack_output, linkNum=0, ret=0") - result = self.driver.shell(f"find {self.pack_out_path} -name test.hnp") - self.driver.Assert.contains(result, f"{self.pack_out_path}/test.hnp") - self.driver.shell(f'rm {self.pack_out_path}/test.hnp') - self.driver.shell(f'rm -rf {self.work_space_path}/empty_dir') - Step("native包路径长度等于max_path") - path_temp = Common.randomGenerateStingByLen(4096) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {path_temp} -o {self.pack_out_path} -n test -v 1.1") - self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess.") - Step("native包路径长度超过max_path") - path_temp = Common.randomGenerateStingByLen(4097) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {path_temp} -o {self.pack_out_path} -n test -v 1.1") - self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess.") - Step("native包路径存在非法字符") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i /data/$^*》《%test/ -o {self.pack_out_path} -n test -v 1.1") - self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess.") - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.json deleted file mode 100644 index 09e2c62d..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1300.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.py deleted file mode 100644 index fcdef9d0..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1300.py +++ /dev/null @@ -1,76 +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. - -import os -from hypium import * -from aw import Common -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEPACK_1300(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - - TestCase.__init__(self, self.TAG, controllers) - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - # hnp程序打包native包,存储包目标路径相关测试场景 - def test_step1(self): - Step("存储包目标路径不存在") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/empty_dir -n test -v 1.1") - self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess. path=/data/hnp_test/pack_output/empty_dir") - Step("存储包目标路径长度等于max_path") - path_temp = Common.randomGenerateStingByLen(4088) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {path_temp} -n test -v 1.1") - self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess.") - Step("存储包目标路径长度大于max_path") - path_temp = Common.randomGenerateStingByLen(4097) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {path_temp} -n test -v 1.1") - self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess.") - Step("/hnpcli pack native包路径 存储包目标路径 -cfg 配置路径,native包路径存在非法字符") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o /data/$^*%test/ -n test -v 1.1") - self.driver.Assert.contains(result, "[ERROR][HNP]realpath unsuccess. path=/data/$^*%test/") - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.json deleted file mode 100644 index 247b7832..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1400.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.py deleted file mode 100644 index b3264369..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1400.py +++ /dev/null @@ -1,122 +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. - -import os -import shutil -from hypium import * -from aw import Common -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEPACK_1400(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - - TestCase.__init__(self, self.TAG, controllers) - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_cfg_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp.json" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - def check_pack_is_correct(self, hnp_name, native_name, cfg_file, del_hnp): - # 校验是否生成了对应的.hnp文件 - result = self.driver.shell(f"find {self.pack_out_path} -name {hnp_name}") - self.driver.Assert.contains(result, f"{self.pack_out_path}/{hnp_name}") - - # 将生成的.hnp文件推到本地 - self.driver.pull_file(self.pack_out_path, self.hnp_test_file_path) - - # 是否删除生成的.hnp文件 - if del_hnp: - self.driver.shell(f'rm {self.pack_out_path}/{hnp_name}') - - # 将hnp.json文件拷贝到native路径下,为文件比较做好准备工作 - shutil.copy2(cfg_file, f"{self.hnp_test_file_path}\\native\\{native_name}") - Common.unzip_hnp(f"{self.hnp_test_file_path}/pack_output/{hnp_name}", - f"{self.hnp_test_file_path}/pack_output/") - - # 比较打包前后两个文件是否一致 - result = Common.compare_folder(f"{self.hnp_test_file_path}\\native\\{native_name}", - f"{self.hnp_test_file_path}/pack_output/{native_name}") - assert result == True - - # 删除测试PC中的残留文件 - Common.deleteFile(f"{self.hnp_test_file_path}\\native\\{native_name}\\hnp.json") - shutil.rmtree(f"{self.hnp_test_file_path}/pack_output/") - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - # hnp程序打包native包,cfg相关测试场景 - def test_step1(self): - Step("native包中无cfg配置文件,不传name与version") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[ERROR][HNP]name or version argv is miss.") - Step("native包中无cfg配置文件,传name与version") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n test -v 1.1") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - result = self.driver.shell(f"find {self.pack_out_path} -name test.hnp") - self.driver.Assert.contains(result, f"{self.pack_out_path}/test.hnp") - self.driver.shell(f'rm {self.pack_out_path}/test.hnp') - Step("native包中存在cfg配置文件,不传name与version") - self.driver.shell(f'cp -i {self.hnp_cfg_path} {self.native_path[0]}') - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.hnp_test_file_path}\\hnp.json", True) - self.driver.shell(f'rm {self.native_path[0]}/hnp.json') - Step("native包中存在cfg配置文件,传name与version") - self.driver.shell(f'cp -i {self.hnp_cfg_path} {self.native_path[0]}') - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n test -v 1.1") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.hnp_test_file_path}\\hnp.json", True) - self.driver.shell(f'rm {self.native_path[0]}/hnp.json') - Step( - "调用./hnpcli pack -i native包路径 -o 存储包目标路径 -name test -v test, version为字符串,非常规version表述") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n test -v test") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - self.driver.Assert.contains(result, "hnpName=test, hnpVer=test") - result = self.driver.shell(f"find {self.pack_out_path} -name test.hnp") - self.driver.Assert.contains(result, f"{self.pack_out_path}/test.hnp") - self.driver.shell(f'rm {self.pack_out_path}/test.hnp') - self.driver.shell(f'rm {self.native_path[0]}/hnp.json') - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.json deleted file mode 100644 index e80d07eb..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1500.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.py deleted file mode 100644 index 0ccbf046..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1500.py +++ /dev/null @@ -1,73 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEPACK_1500(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - - TestCase.__init__(self, self.TAG, controllers) - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - # 打包native包时,传参异常 - def test_step1(self): - Step("调用./hnpcli 待打包native软件路径 打包后文件存放路径 -n test") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n test") - self.driver.Assert.contains(result, "[ERROR][HNP]name or version argv is miss.") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392706") - Step("调用./hnpcli 待打包native软件路径 打包后文件存放路径 -v 1.1") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -v 1.1") - self.driver.Assert.contains(result, "[ERROR][HNP]name or version argv is miss.") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392706") - Step("调用./hnpcli pack native包路径 存储包目标路径 -n "" -v """) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -name "" -v """) - self.driver.Assert.contains(result, "[ERROR][HNP]name or version argv is miss.") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392706") - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.json deleted file mode 100644 index b7a07117..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1600.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.py deleted file mode 100644 index 75949550..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1600.py +++ /dev/null @@ -1,111 +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. - -import os -import shutil -from hypium import * -from aw import Common -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEPACK_1600(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - - TestCase.__init__(self, self.TAG, controllers) - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_cfg_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp.json" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - def check_pack_is_correct(self, hnp_name, native_name, cfg_file, del_hnp): - # 校验是否生成了对应的.hnp文件 - result = self.driver.shell(f"find {self.pack_out_path} -name {hnp_name}") - self.driver.Assert.contains(result, f"{self.pack_out_path}/{hnp_name}") - - # 将生成的.hnp文件推到本地 - self.driver.pull_file(self.pack_out_path, self.hnp_test_file_path) - - # 是否删除生成的.hnp文件 - if del_hnp: - self.driver.shell(f'rm {self.pack_out_path}/{hnp_name}') - - # 将hnp.json文件拷贝到native路径下,为文件比较做好准备工作 - shutil.copy2(cfg_file, f"{self.hnp_test_file_path}\\native\\{native_name}") - Common.unzip_hnp(f"{self.hnp_test_file_path}/pack_output/{hnp_name}", - f"{self.hnp_test_file_path}/pack_output/") - - # 比较打包前后两个文件是否一致 - result = Common.compare_folder(f"{self.hnp_test_file_path}\\native\\{native_name}", - f"{self.hnp_test_file_path}/pack_output/{native_name}") - assert result == True - - # 删除测试PC中的残留文件 - Common.deleteFile(f"{self.hnp_test_file_path}\\native\\{native_name}\\hnp.json") - shutil.rmtree(f"{self.hnp_test_file_path}/pack_output/") - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - # 根据配置打包不同数量的native包 - def test_step1(self): - Step("打包文件存在cfg文件") - self.driver.shell(f'cp -i {self.hnp_cfg_path} {self.native_path[0]}') - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.hnp_test_file_path}\\hnp.json", False) - self.driver.shell(f'rm {self.native_path[0]}/hnp.json') - Step("打包文件不存在cfg文件,传入name与version") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n test -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - result = self.driver.shell(f"find {self.pack_out_path} -name test.hnp") - self.driver.Assert.contains(result, f"{self.pack_out_path}/test.hnp") - Step("打包文件不存在cfg文件,传入name与version,其中name与第一次传入不同") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n test2 -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - result = self.driver.shell(f"find {self.pack_out_path} -name test2.hnp") - self.driver.Assert.contains(result, f"{self.pack_out_path}/test2.hnp") - Step("调用./hnpcli 待打包native软件路径(与上不同)打包后文件存放路径(与上相同)-n test -v 1.0") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path} -n test -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - result = self.driver.shell(f"find {self.pack_out_path} -name test.hnp") - self.driver.Assert.contains(result, f"{self.pack_out_path}/test.hnp") - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.json deleted file mode 100644 index 23d86b05..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1700.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.py deleted file mode 100644 index 145b7f7d..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1700.py +++ /dev/null @@ -1,122 +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. - -import os -from hypium import * -from aw import Common -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEPACK_1700(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - - TestCase.__init__(self, self.TAG, controllers) - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - def test_step1(self): - Step("对应的配置文件非json文件") - hnp_cfg_data = """{ - "type": "hnp-config", - "name": "python", - "version": "2.7", - "install": { - "links": [ - { - "source": "bin/python2.7", - "target": "python" - } - ] - }""" - Common.writeDateToFile("hnp.json", hnp_cfg_data) - self.driver.push_file(f"{self.current_path}\\hnp.json", self.native_path[0]) - Common.deleteFile(f"{self.current_path}\\hnp.json") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392986") - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - Step("配置文件无type字段") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - del hnp_cfg_data['type'] - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[ERROR][HNP]get type info in cfg unsuccess.") - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - Step("配置文件无name字段") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - del hnp_cfg_data['name'] - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[ERROR][HNP]get name info in cfg unsuccess.") - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - Step("配置文件无version字段") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - del hnp_cfg_data['version'] - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[ERROR][HNP]get version info in cfg unsuccess.") - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - Step("配置文件无install字段") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - del hnp_cfg_data['install'] - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[ERROR][HNP]get install info in cfg unsuccess.") - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - Step("配置文件非hnp类型") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data["type"] = "test" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[ERROR][HNP]type info not match.type=test") - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.json deleted file mode 100644 index cb97293b..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1800.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.py deleted file mode 100644 index ba5b130b..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1800.py +++ /dev/null @@ -1,129 +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. - -import os -import shutil -from hypium import * -from aw import Common -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEPACK_1800(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - - TestCase.__init__(self, self.TAG, controllers) - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path, delete_file): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - if delete_file: - assert Common.deleteFile(json_file_name) == 0 - - def check_pack_is_correct(self, hnp_name, native_name, cfg_file, del_hnp): - # 校验是否生成了对应的.hnp文件 - result = self.driver.shell(f"find {self.pack_out_path} -name {hnp_name}") - self.driver.Assert.contains(result, f"{self.pack_out_path}/{hnp_name}") - - # 将生成的.hnp文件推到本地 - self.driver.pull_file(self.pack_out_path, self.hnp_test_file_path) - - # 是否删除生成的.hnp文件 - if del_hnp: - self.driver.shell(f'rm {self.pack_out_path}/{hnp_name}') - - # 将hnp.json文件拷贝到native路径下,为文件比较做好准备工作 - shutil.copy2(cfg_file, f"{self.hnp_test_file_path}\\native\\{native_name}") - Common.unzip_hnp(f"{self.hnp_test_file_path}/pack_output/{hnp_name}", - f"{self.hnp_test_file_path}/pack_output/") - - # 比较打包前后两个文件是否一致 - result = Common.compare_folder(f"{self.hnp_test_file_path}\\native\\{native_name}", - f"{self.hnp_test_file_path}/pack_output/{native_name}") - assert result == True - - # 删除测试PC中的残留文件 - Common.deleteFile(f"{self.hnp_test_file_path}\\native\\{native_name}\\hnp.json") - shutil.rmtree(f"{self.hnp_test_file_path}/pack_output/") - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - # 软连接路径与配置名称内容测试 - def test_step1(self): - Step("配置软连接路径正确,但是未配置目标名称") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - del hnp_cfg_data['install']['links'][0]["target"] - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], False) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.current_path}/hnp.json", True) - assert Common.deleteFile(f"{self.current_path}/hnp.json") == 0 - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - Step("未配置软连接路径,配置了目标名称") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - del hnp_cfg_data['install']['links'][0]["source"] - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], True) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[ERROR][HNP]get source info in cfg unsuccess.") - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - Step("配置软连接路径,配置目标名称为空") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["target"] = None - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], False) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.current_path}/hnp.json", True) - assert Common.deleteFile(f"{self.current_path}/hnp.json") == 0 - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - Step("配置软连接路径,配置了目标名称长度为0") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["target"] = "" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], False) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.current_path}/hnp.json", True) - assert Common.deleteFile(f"{self.current_path}/hnp.json") == 0 - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.json deleted file mode 100644 index 86f7400c..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_1900.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.py deleted file mode 100644 index 1f0752aa..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_1900.py +++ /dev/null @@ -1,121 +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. - -import os -import shutil -from hypium import * -from aw import Common -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEPACK_1900(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - - TestCase.__init__(self, self.TAG, controllers) - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path, delete_file): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - if delete_file: - assert Common.deleteFile(json_file_name) == 0 - - def check_pack_is_correct(self, hnp_name, native_name, cfg_file, del_hnp): - # 校验是否生成了对应的.hnp文件 - result = self.driver.shell(f"find {self.pack_out_path} -name {hnp_name}") - self.driver.Assert.contains(result, f"{self.pack_out_path}/{hnp_name}") - - # 将生成的.hnp文件推到本地 - self.driver.pull_file(self.pack_out_path, self.hnp_test_file_path) - - # 是否删除生成的.hnp文件 - if del_hnp: - self.driver.shell(f'rm {self.pack_out_path}/{hnp_name}') - - # 将hnp.json文件拷贝到native路径下,为文件比较做好准备工作 - shutil.copy2(cfg_file, f"{self.hnp_test_file_path}\\native\\{native_name}") - Common.unzip_hnp(f"{self.hnp_test_file_path}/pack_output/{hnp_name}", - f"{self.hnp_test_file_path}/pack_output/") - - # 比较打包前后两个文件是否一致 - result = Common.compare_folder(f"{self.hnp_test_file_path}\\native\\{native_name}", - f"{self.hnp_test_file_path}/pack_output/{native_name}") - assert result == True - - # 删除测试PC中的残留文件 - Common.deleteFile(f"{self.hnp_test_file_path}\\native\\{native_name}\\hnp.json") - shutil.rmtree(f"{self.hnp_test_file_path}/pack_output/") - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - # 软连接路径与配置不同关系的测试 - def test_step1(self): - Step("配置文件字段正确,存在两个软连接,不同的软连接路径,相同的配置名称") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'].append({"source": "bin/sample.txt", "target": "hnp_test"}) - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], False) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "linkNum=2, ret=0") - self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.current_path}/hnp.json", False) - Common.deleteFile(f"{self.current_path}/hnp.json") - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - Step("配置文件字段正确,存在两个软连接,相同的软连接路径,不同的配置名称") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'].append({"source": "bin/sample.txt", "target": "hnp_test2"}) - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], False) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "linkNum=2, ret=0") - self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.current_path}/hnp.json", False) - Common.deleteFile(f"{self.current_path}/hnp.json") - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - Step("配置文件字段正确,存在多个软连接,相同的软连接路径,相同的配置名称") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - for i in range(5): - hnp_cfg_data['install']['links'].append({"source": "bin/sample.txt", "target": "hnp_test"}) - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0], False) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "linkNum=6, ret=0") - self.check_pack_is_correct("hnp_test.hnp", "sample1", f"{self.current_path}/hnp.json", False) - Common.deleteFile(f"{self.current_path}/hnp.json") - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.json deleted file mode 100644 index c20074b5..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_2000.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.py deleted file mode 100644 index 8c6813d5..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2000.py +++ /dev/null @@ -1,79 +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. - -import os -from hypium import * -from aw import Common -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEPACK_2000(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - - TestCase.__init__(self, self.TAG, controllers) - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - # 软连接路径不存在测试场景 - def test_step1(self): - Step("存在一个软连接,软连接路径不存在") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/testsample.txt" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393217") - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - Step("存在两个软连接,其中一个软连接路径不存在") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'].append({"source": "bin/test_sample.txt", "target": "hnp_test2"}) - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393217") - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.json deleted file mode 100644 index cb06b7ca..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEPACK_2100.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.py deleted file mode 100644 index c11f45bd..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativepack_2100.py +++ /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. - -import os -from hypium import * -from aw import Common -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEPACK_2100(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - - TestCase.__init__(self, self.TAG, controllers) - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" # 测试设备工作路径 - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample1", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/sample2"] - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - # 升级打包同名native包 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("配置文件字段正确,存在两个软连接,不同的软连接路径,相同的配置名称") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}") - self.driver.Assert.contains(result, "linkNum=1, ret=0") - self.driver.shell(f"rm {self.native_path[0]}/hnp.json") - - Step("根据name + version打包与配置文件的同名hnp包") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n hnp_test -v 1.0") - self.driver.Assert.contains(result, "linkNum=0, ret=0") - result = self.driver.shell(f"find {self.pack_out_path} -name hnp_test.hnp") - self.driver.Assert.contains(result, f"{self.pack_out_path}/hnp_test.hnp") - - Step("根据name + version打包与配置文件的同名hnp包,版本号不同") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path} -n hnp_test -v 1.2") - self.driver.Assert.contains(result, "linkNum=0, ret=0") - result = self.driver.shell(f"find {self.pack_out_path} -name hnp_test.hnp") - self.driver.Assert.contains(result, f"{self.pack_out_path}/hnp_test.hnp") - - Step("根据name + version打包与配置文件的同名hnp包,打包的native包与原有不同,版本号不同") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path} -n hnp_test1 -v 1.3") - self.driver.Assert.contains(result, "linkNum=0, ret=0") - result = self.driver.shell(f"find {self.pack_out_path} -name hnp_test1.hnp") - self.driver.Assert.contains(result, f"{self.pack_out_path}/hnp_test1.hnp") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.json deleted file mode 100644 index 1f075588..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_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_HNP/SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0300.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.py deleted file mode 100644 index d4c5bfaf..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0300.py +++ /dev/null @@ -1,108 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0300(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 卸载路径不存在测试场景 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("打包compute.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public -n compute -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("安装compute工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("卸载软件usrId不存在") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 301 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8393477 ") - - Step("卸载的应用不存在") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p meituan") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - - Step("正常卸载") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("重复卸载") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0 ") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.json deleted file mode 100644 index f0cc152b..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0400.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.py deleted file mode 100644 index 1725e37a..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0400.py +++ /dev/null @@ -1,123 +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. - -import os -import time -from hypium import * -import threading -from aw import Common -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0400(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def worker(self): - Step("执行安装后的软件") - self.driver.shell(f"chmod +x /data/service/hnp/compute.org/compute_1.0/bin/add") - result = self.driver.shell( - f"./data/service/hnp/compute.org/compute_1.0/bin/add 4") - - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 卸载的软件正在运行的软件(未配置软连接) - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("打包compute.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public -n compute -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("安装compute工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - self.driver.shell(f'mkdir -p /data/service/hnp/compute.org/compute_1.0/') - self.driver.shell(f'cp -r {self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute/bin ' - f'/data/service/hnp/compute.org/compute_1.0/') - - Step("执行安装的工具") - t1 = threading.Thread(target=self.worker) - t1.start() - time.sleep(1) - Step("卸载百度应用安装工具") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - - self.driver.Assert.contains(result, "[ERROR][HNP]hnp install path is running now,") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392978") - t1.join() - - Step("待工具运行结束,卸载安装的compute工具") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - result = self.driver.shell(f"find {self.default_install_root_path}/300/hnppublic -name compute.org") - assert ("compute.org" not in result) == True - self.driver.shell(f'rm -rf /data/service/hnp') - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.json deleted file mode 100644 index 908275cb..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0500.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.py deleted file mode 100644 index f93a74c5..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0500.py +++ /dev/null @@ -1,129 +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. - -import os -import time -from hypium import * -import threading -from aw import Common -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0500(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute" - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def worker(self): - Step("执行安装后的软件") - self.driver.shell(f"chmod +x /data/service/hnp/compute.org/compute_1.0/bin/add") - result = self.driver.shell( - f"./data/service/hnp/compute.org/compute_1.0/bin/add 4") - self.driver.Assert.contains(result, "End: 1 + 1 = 2") - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 卸载的软件正在运行的软件(配置软连接) - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建compute工具配置文件,工具add的软连接名称为compute,工具add的软连接名称为compute") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/add" - hnp_cfg_data['install']['links'][0]["target"] = "add" - hnp_cfg_data['install']['links'].append({"source": "bin/del", "target": "compute"}) - hnp_cfg_data['install']['links'].append({"source": "bin/multiplication", "target": "mul"}) - hnp_cfg_data['name'] = "compute" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path) - - Step("打包compute.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path} -o {self.pack_out_path}/public -n compute -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("安装compute工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - self.driver.shell(f'mkdir -p /data/service/hnp/compute.org/compute_1.0/') - self.driver.shell(f'cp -r {self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute/bin ' - f'/data/service/hnp/compute.org/compute_1.0/') - - Step("卸载百度应用安装工具") - t1 = threading.Thread(target=self.worker) - t1.start() - time.sleep(1) - Step("正常卸载") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[ERROR][HNP]hnp install path is running now,") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392978") - t1.join() - - Step("待工具运行结束,卸载安装的compute工具") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - self.driver.shell(f'rm -rf /data/service/hnp') - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.json deleted file mode 100644 index 482dce88..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0600.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.py deleted file mode 100644 index 12371721..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0600.py +++ /dev/null @@ -1,147 +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. - -import os -from hypium import * -from devicetest.core.test_case import Step, TestCase -from aw import Common - - -class SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0600(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/compute", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/readCfgFile"] - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - self.driver.shell(f'mkdir {self.pack_out_path}/private') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 卸载的多个软件 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建compute工具配置文件") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/add" - hnp_cfg_data['install']['links'][0]["target"] = "add" - hnp_cfg_data['install']['links'].append({"source": "bin/del", "target": "del"}) - hnp_cfg_data['install']['links'].append({"source": "bin/multiplication", "target": "multiplication"}) - hnp_cfg_data['name'] = "compute" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - - Step("创建readCfgFile工具配置文件") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/readCfgFile" - hnp_cfg_data['install']['links'][0]["target"] = "readCfgFile" - hnp_cfg_data['name'] = "readCfgFile" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[2]) - - Step("打包readCfgFile.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[2]} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包compute.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包printfHello.hnp") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[1]} " - f"-o {self.pack_out_path}/private -n printfHello -v 1.0") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("批量安装readCfgFile、compute、printfHello、printfHello工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("卸载百度程序对应的软件") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("验证compute工具卸载成功") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/del") - self.driver.Assert.contains(result, "del: inaccessible or not found") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/add") - self.driver.Assert.contains(result, "add: inaccessible or not found") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/hnp/baidu/bin/multiplication") - self.driver.Assert.contains(result, "multiplication: inaccessible or not found") - - Step("验证printfHello工具卸载成功") - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/printfHello") - self.driver.Assert.contains(result, "printfHello: inaccessible or not found") - - result = self.driver.shell( - f"./{self.default_install_root_path}/300/{self.hnp_public_dir}/readCfgFile") - self.driver.Assert.contains(result, "readCfgFile: inaccessible or not found") - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.json b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.json deleted file mode 100644 index ba1cdb56..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.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_HNP/SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0700.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.py b/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.py deleted file mode 100644 index 94852098..00000000 --- a/test/autotest/SubStartAppspawnHnp/sub_startup_appspawn_nativeuninstall_0700.py +++ /dev/null @@ -1,143 +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. - -import os -import time -from hypium import * -import threading -from aw import Common -from devicetest.core.test_case import Step, TestCase - - -class SUB_STARTUP_APPSPAWN_NATIVEUNINSTALL_0700(TestCase): - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - - self.default_install_root_path = "/data/app/el1/bundle" - self.current_path = os.getcwd() - self.driver = UiDriver(self.device1) - self.work_space_path = "/data/hnp_test" - self.pack_out_path = f"{self.work_space_path}/pack_output" - self.hnp_tools_path = f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/hnp" - self.hnp_test_file_path = f"{self.current_path}\\testFile\SUB_STARTUP_APPSPAWN_HNP" - self.hnp_commamd = f"./{self.hnp_tools_path}/hnp" - self.hnpcli_commamd = f"./{self.hnp_tools_path}/hnpcli" - self.hnp_public_dir = "hnppublic/bin" - self.native_path = [f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol", - f"{self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello"] - - def creat_json_and_push_remote(self, json_file_name, json_data, target_path): - Common.writeJsonDateToFile(json_file_name, json_data) - self.driver.push_file(f"{self.current_path}\\{json_file_name}", target_path) - assert Common.deleteFile(json_file_name) == 0 - - def worker(self): - Step("执行安装后的软件") - self.driver.shell(f"chmod +x /data/service/hnp/printfSymbol.org/printfSymbol_1.0/bin/printfSymbol") - result = self.driver.shell( - f"./data/service/hnp/printfSymbol.org/printfSymbol_1.0/bin/printfSymbol 4") - self.driver.Assert.contains(result, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") - - def setup(self): - Step("预置工作:初始化PC开始") - Step(self.devices[0].device_id) - - Step("预置工作:创建测试目录,将测试文件拷贝到测试PC") - self.driver.shell(f'mkdir {self.work_space_path}') - - Step("预置工作:创建打包保存文件,为native打包后的保存路径") - self.driver.shell(f'mkdir {self.pack_out_path}') - self.driver.shell(f'mkdir {self.pack_out_path}/public') - - self.driver.push_file(self.hnp_test_file_path, self.work_space_path) - - Step("预置工作:进入到bin文件目录,bin文件增加可执行权限") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnp") - self.driver.shell(f"chmod +x {self.hnp_tools_path}/hnpcli") - - Step("创建一个userId为300的路径,为后续测试使用目录") - self.driver.shell(f"mkdir {self.default_install_root_path}/300") - - # 不同hnp软件包配置的软连接路径不同,target名称相同测试,同名进程运行过程中卸载工具 - def test_step1(self): - Step("识别设备型号...............................") - device = self.driver.shell("param get const.product.model") - device = device.replace("\n", "").replace(" ", "") - device = str(device) - if ("HYM" in device or "HAD" in device or "ohos" in device or "ALN" in device): - Step("创建printfSymbol工具配置文件") - hnp_cfg_data = Common.readJsonFile("testFile\SUB_STARTUP_APPSPAWN_HNP\hnp.json") - hnp_cfg_data['install']['links'][0]["source"] = "bin/printfSymbol" - hnp_cfg_data['install']['links'][0]["target"] = "print" - hnp_cfg_data['name'] = "printfSymbol" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[0]) - - Step("创建printfHello工具配置文件") - hnp_cfg_data['install']['links'][0]["source"] = "bin/printfHello" - hnp_cfg_data['install']['links'][0]["target"] = "print" - hnp_cfg_data['name'] = "printfHello" - hnp_cfg_data['version'] = "1.0" - self.creat_json_and_push_remote("hnp.json", hnp_cfg_data, self.native_path[1]) - - Step("打包printfSymbol工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[0]} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("打包printfHello工具") - result = self.driver.shell( - f"{self.hnpcli_commamd} pack -i {self.native_path[1]} -o {self.pack_out_path}/public") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - Step("安装printfSymbol、printfHello工具") - result = self.driver.shell( - f"{self.hnp_commamd} install -u 300 -p baidu -i {self.pack_out_path}") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - - self.driver.shell(f'mkdir -p /data/service/hnp/printfSymbol.org/printfSymbol_1.0/') - self.driver.shell(f'mkdir -p /data/service/hnp/printfHello.org/printfHello_1.0/') - self.driver.shell(f'cp -r {self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfHello/bin ' - f'/data/service/hnp/printfHello.org/printfHello_1.0/') - self.driver.shell(f'cp -r {self.work_space_path}/SUB_STARTUP_APPSPAWN_HNP/native/printfSymbol/bin ' - f'/data/service/hnp/printfSymbol.org/printfSymbol_1.0/') - - Step("运行print进程") - t1 = threading.Thread(target=self.worker) - t1.start() - time.sleep(1) - - Step("卸载baidu应用安装的软件") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[ERROR][HNP]hnp install path is running now,") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=8392978") - t1.join() - - Step("待程序运行结束后,卸载baidu应用安装的软件") - result = self.driver.shell( - f"{self.hnp_commamd} uninstall -u 300 -p baidu") - self.driver.Assert.contains(result, "[INFO][HNP]native manager process exit. ret=0") - self.driver.shell(f'rm -rf /data/service/hnp') - else: - pass - - def teardown(self): - self.driver.shell(f'rm -rf {self.work_space_path}') - self.driver.shell(f'rm -rf {self.default_install_root_path}/300/') - Step("收尾工作") - diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.json deleted file mode 100644 index af09a5d3..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0100.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.py deleted file mode 100644 index e84fab6f..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0100.py +++ /dev/null @@ -1,74 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import * -from hypium.model import UiParam, WindowFilter -import os -from aw import Common - -class SUB_STARTUP_APPSPAWN_HNPINSTALL_0100(TestCase): - - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - - def test_step1(self): - Step("步骤1:安装测试应用") - path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) - hnp = os.path.abspath(os.path.join( - os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) - isHap = self.driver.has_app("com.example.hnp_test") - if(isHap): - self.driver.uninstall_app("com.example.hnp_test") - else: - pass - self.driver.install_app(hnp) - Step("是否刷root包") - isroot = self.driver.shell("ls") - Step("步骤2:展示公有目录列表") - result1 = self.driver.shell("ls /data/app/el1/bundle/100/hnppublic") - self.driver.Assert.contains(result1, "hnpsample.org") - if ("Permission denied" in isroot): - Step("步骤4:执行公有目录软链二进制") - th = Common.hnpexecute_async(self.driver, "/data/app/el1/bundle/100/hnppublic/bin/hnpsample 5") - th.start() - result3 = self.driver.shell("ps -ef | grep hnpsample | grep -v grep") - self.driver.Assert.contains(result3, "hnpsample") - else: - Step("步骤3:展示私有目录列表") - result2 = self.driver.shell("ls /data/app/el1/bundle/100/hnp/com.example.hnp_test") - self.driver.Assert.contains(result2, "node.org") - Step("步骤4:执行公有目录软链二进制") - result3 = self.driver.hdc("hdc shell /data/app/el1/bundle/100/hnppublic/bin/hnpsample") - self.driver.Assert.contains(result3, "start hnp sample") - self.driver.Assert.contains(result3, "hnp sample end") - - def teardown(self): - Step("收尾工作:卸载hap") - self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.json deleted file mode 100644 index df3e9b72..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0200.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.py deleted file mode 100644 index a99ae3a5..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0200.py +++ /dev/null @@ -1,68 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import * -from hypium.model import UiParam, WindowFilter -import os - -class SUB_STARTUP_APPSPAWN_HNPINSTALL_0200(TestCase): - - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - - def test_step1(self): - Step("步骤1:安装测试应用") - path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) - hnp = os.path.abspath(os.path.join( - os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) - isHap = self.driver.has_app("com.example.hnp_test") - if(isHap): - self.driver.uninstall_app("com.example.hnp_test") - else: - pass - self.driver.install_app(hnp) - Step("步骤2:读取公有目录列表") - result1 = self.driver.shell("cat /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") - self.driver.Assert.contains(result1, "hnpsample") - Step("是否刷root包") - isroot = self.driver.shell("ls") - if("Permission denied" in isroot): - Step("步骤3:读取私有目录列表") - result2 = self.driver.shell( - "cat /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") - self.driver.Assert.contains(result2, "Permission denied") - else: - Step("步骤3:读取私有目录列表") - result2 = self.driver.shell("cat /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") - self.driver.Assert.contains(result2, "node") - - def teardown(self): - Step("收尾工作:卸载hap") - self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.json deleted file mode 100644 index a15ed738..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0300.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.py deleted file mode 100644 index 5fe4b6e4..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0300.py +++ /dev/null @@ -1,77 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import * -from hypium.model import UiParam, WindowFilter -import os - -class SUB_STARTUP_APPSPAWN_HNPINSTALL_0300(TestCase): - - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - - def test_step1(self): - Step("步骤1:安装测试应用") - path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) - hnp = os.path.abspath(os.path.join( - os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) - isHap = self.driver.has_app("com.example.hnp_test") - if (isHap): - self.driver.uninstall_app("com.example.hnp_test") - else: - pass - self.driver.install_app(hnp) - isroot = self.driver.shell("ls") - if ("Permission denied" in isroot): - Step("步骤2:修改公有目录文件内容") - data = {"name": "zsj", "sex": "girl", "age": 31}; - result1 = self.driver.shell(f"echo {data} > /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") - self.driver.Assert.contains(result1, "Permission denied") - Step("步骤3:修改私有目录文件内容") - data = {"name": "private", "sex": "girl", "age": 31}; - result2 = self.driver.shell(f"echo {data} > /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") - self.driver.Assert.contains(result2, "Permission denied") - else: - Step("步骤2:修改公有目录文件内容") - data = {"name": "zsj", "sex": "girl", "age": 31}; - self.driver.shell(f"echo {data} > /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") - result1 = self.driver.shell("cat /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") - self.driver.Assert.contains(result1, "zsj") - Step("步骤3:修改私有目录文件内容") - data = {"name": "private", "sex": "girl", "age": 31}; - self.driver.shell( - f"echo {data} > /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") - result2 = self.driver.shell( - "cat /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") - self.driver.Assert.contains(result2, "private") - - def teardown(self): - Step("收尾工作:卸载hap") - self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.json deleted file mode 100644 index bfb061dc..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0400.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.py deleted file mode 100644 index 5465632d..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0400.py +++ /dev/null @@ -1,72 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import * -from hypium.model import UiParam, WindowFilter -import os - -class SUB_STARTUP_APPSPAWN_HNPINSTALL_0400(TestCase): - - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - - def test_step1(self): - Step("步骤1:安装测试应用") - path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) - hnp = os.path.abspath(os.path.join( - os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) - isHap = self.driver.has_app("com.example.hnp_test") - if (isHap): - self.driver.uninstall_app("com.example.hnp_test") - else: - pass - self.driver.install_app(hnp) - isroot = self.driver.shell("ls") - if ("Permission denied" in isroot): - Step("步骤2:修改公有目录文件内容") - result1 = self.driver.shell(f"touch /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/123.txt") - self.driver.Assert.contains(result1, "Permission denied") - Step("步骤3:修改私有目录文件内容") - result2 = self.driver.shell(f"touch /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/abc.txt") - self.driver.Assert.contains(result2, "Permission denied") - else: - Step("步骤2:修改公有目录文件内容") - self.driver.shell(f"touch /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/123.txt") - result1 = self.driver.shell("ls /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/") - self.driver.Assert.contains(result1, "123.txt") - Step("步骤3:修改私有目录文件内容") - self.driver.shell(f"touch /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/abc.txt") - result2 = self.driver.shell( - "ls /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/") - self.driver.Assert.contains(result2, "abc.txt") - - def teardown(self): - Step("收尾工作:卸载hap") - self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.json deleted file mode 100644 index e63f23a5..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0500.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.py deleted file mode 100644 index 2b214341..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0500.py +++ /dev/null @@ -1,74 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import * -from hypium.model import UiParam, WindowFilter -import os - -class SUB_STARTUP_APPSPAWN_HNPINSTALL_0500(TestCase): - - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - - def test_step1(self): - Step("步骤1:安装测试应用") - path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) - hnp = os.path.abspath(os.path.join( - os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) - isHap = self.driver.has_app("com.example.hnp_test") - if (isHap): - self.driver.uninstall_app("com.example.hnp_test") - else: - pass - self.driver.install_app(hnp) - isroot = self.driver.shell("ls") - if ("Permission denied" in isroot): - Step("步骤2:修改公有目录文件内容") - result1 = self.driver.shell( - f"rm -rf /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") - self.driver.Assert.contains(result1, "Permission denied") - Step("步骤3:修改私有目录文件内容") - result2 = self.driver.shell( - f"rm -rf /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") - self.driver.Assert.contains(result2, "Permission denied") - else: - Step("步骤2:修改公有目录文件内容") - self.driver.shell(f"rm -rf /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") - result1 = self.driver.shell("ls /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/") - self.driver.Assert.is_true("hnp.json" not in result1) - Step("步骤3:修改私有目录文件内容") - self.driver.shell(f"rm -rf /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") - result2 = self.driver.shell( - "ls /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/") - self.driver.Assert.is_true("hnp.json" not in result2) - - def teardown(self): - Step("收尾工作:卸载hap") - self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.json deleted file mode 100644 index ca88d6b4..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0600.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.py deleted file mode 100644 index 3b9c4030..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0600.py +++ /dev/null @@ -1,74 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import * -from hypium.model import UiParam, WindowFilter -import os - -class SUB_STARTUP_APPSPAWN_HNPINSTALL_0600(TestCase): - - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - - def test_step1(self): - Step("步骤1:安装测试应用") - path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) - hnp = os.path.abspath(os.path.join( - os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) - isHap = self.driver.has_app("com.example.hnp_test") - if (isHap): - self.driver.uninstall_app("com.example.hnp_test") - else: - pass - self.driver.install_app(hnp) - isroot = self.driver.shell("ls") - if ("Permission denied" in isroot): - Step("步骤2:修改公有目录文件内容") - result1 = self.driver.shell( - f"chmod 777 /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") - self.driver.Assert.contains(result1, "Operation not permitted") - Step("步骤3:修改私有目录文件内容") - result2 = self.driver.shell( - f"chmod 777 /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") - self.driver.Assert.contains(result2, "Permission denied") - else: - Step("步骤2:修改公有目录文件内容") - self.driver.shell(f"chmod 777 /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") - result1 = self.driver.shell("ls -l /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json") - self.driver.Assert.contains(result1, "rwxrwxrwx") - Step("步骤3:修改私有目录文件内容") - self.driver.shell(f"chmod 777 /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") - result2 = self.driver.shell( - "ls -l /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json") - self.driver.Assert.contains(result2, "rwxrwxrwx") - - def teardown(self): - Step("收尾工作:卸载hap") - self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.json deleted file mode 100644 index aad70f10..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0700.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.py deleted file mode 100644 index 3e2fd84c..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0700.py +++ /dev/null @@ -1,75 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import * -from hypium.model import UiParam, WindowFilter -import os - -class SUB_STARTUP_APPSPAWN_HNPINSTALL_0700(TestCase): - - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - - def test_step1(self): - Step("步骤1:安装测试应用") - path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) - hnp = os.path.abspath(os.path.join( - os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) - isHap = self.driver.has_app("com.example.hnp_test") - if (isHap): - self.driver.uninstall_app("com.example.hnp_test") - else: - pass - self.driver.install_app(hnp) - isroot = self.driver.shell("ls") - if ("Permission denied" in isroot): - Step("步骤2:修改公有目录文件内容") - result1 = self.driver.shell( - f"mv /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/zsj.json") - self.driver.Assert.contains(result1, "Permission denied") - Step("步骤3:修改私有目录文件内容") - result2 = self.driver.shell( - f"mv /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/zsj.json") - self.driver.Assert.contains(result2, "Permission denied") - else: - Step("步骤2:修改公有目录文件内容") - self.driver.shell(f"mv /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/zsj.json") - result1 = self.driver.shell("ls /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/") - self.driver.Assert.contains(result1, "zsj.json") - Step("步骤3:修改私有目录文件内容") - self.driver.shell(f"mv /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/zsj.json") - result2 = self.driver.shell( - "ls /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/") - self.driver.Assert.contains(result2, "zsj.json") - - -def teardown(self): - Step("收尾工作:卸载hap") - self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.json deleted file mode 100644 index b4675353..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0800.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.py deleted file mode 100644 index 84edd35c..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0800.py +++ /dev/null @@ -1,78 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import * -from hypium.model import UiParam, WindowFilter -import os - -class SUB_STARTUP_APPSPAWN_HNPINSTALL_0800(TestCase): - - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - - def test_step1(self): - Step("步骤1:安装测试应用") - path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) - hnp = os.path.abspath(os.path.join( - os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) - isHap = self.driver.has_app("com.example.hnp_test") - if (isHap): - self.driver.uninstall_app("com.example.hnp_test") - else: - pass - self.driver.install_app(hnp) - isroot = self.driver.shell("ls") - if ("Permission denied" in isroot): - Step("步骤2:修改公有目录文件内容") - result1 = self.driver.shell( - f"cp /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/zsj.json") - self.driver.Assert.contains(result1, "Permission denied") - Step("步骤3:修改私有目录文件内容") - result2 = self.driver.shell( - f"cp /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/zsj.json") - self.driver.Assert.contains(result2, "Permission denied") - else: - Step("步骤2:修改公有目录文件内容") - self.driver.shell( - f"cp /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/hnp.json /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/zsj.json") - result1 = self.driver.shell("ls /data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/") - self.driver.Assert.contains(result1, "zsj.json") - self.driver.Assert.contains(result1, "hnp.json") - Step("步骤3:修改私有目录文件内容") - self.driver.shell( - f"cp /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/hnp.json /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/zsj.json") - result2 = self.driver.shell( - "ls /data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/") - self.driver.Assert.contains(result2, "zsj.json") - self.driver.Assert.contains(result2, "hnp.json") - - def teardown(self): - Step("收尾工作:卸载hap") - self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.json b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.json deleted file mode 100644 index ecc92a85..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SUB_STARTUP_APPSPAWN_HNPINSTALL/SUB_STARTUP_APPSPAWN_HNPINSTALL_0900.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.py b/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.py deleted file mode 100644 index c46afb68..00000000 --- a/test/autotest/SubStartAppspawnHnpinstall/sub_startup_appspawn_hnpinstall_0900.py +++ /dev/null @@ -1,71 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import * -from hypium.model import UiParam, WindowFilter -import os -from aw import Common - -class SUB_STARTUP_APPSPAWN_HNPINSTALL_0900(TestCase): - - def __init__(self, controllers): - self.TAG = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.TAG, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - - def test_step1(self): - Step("步骤1:安装测试应用") - path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) - hnp = os.path.abspath(os.path.join( - os.path.join(path, "testFile"), 'SUB_STARTUP_APPSPAWN_NATIVE/entry-default-hnpinsall.hap')) - isHap = self.driver.has_app("com.example.hnp_test") - if (isHap): - self.driver.uninstall_app("com.example.hnp_test") - else: - pass - self.driver.install_app(hnp) - Step("是否刷root包") - isroot = self.driver.shell("ls") - if ("Permission denied" in isroot): - Step("步骤2:执行公有目录二进制文件") - th = Common.hnpexecute_async(self.driver, "/data/app/el1/bundle/100/hnppublic/bin/hnpsample 5") - th.start() - result3 = self.driver.shell("ps -ef | grep hnpsample | grep -v grep") - self.driver.Assert.contains(result3, "hnpsample") - Step("步骤3:读取私有目录列表") - result2 = self.driver.shell("./data/app/el1/bundle/100/hnp/com.example.hnp_test/node.org/node_1.0/bin/node") - self.driver.Assert.contains(result2, "inaccessible or not found") - else: - Step("步骤2:执行公有目录二进制文件") - result1 = self.driver.shell("./data/app/el1/bundle/100/hnppublic/hnpsample.org/hnpsample_1.1/bin/hnpsample") - self.driver.Assert.contains(result1, "start hnp sample") - self.driver.Assert.contains(result1, "hnp sample end") - - def teardown(self): - Step("收尾工作:卸载hap") - self.driver.uninstall_app("com.example.hnp_test") diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.json deleted file mode 100644 index 680ba7fe..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.py deleted file mode 100644 index e9ebe366..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0100.py +++ /dev/null @@ -1,83 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn0100(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:首次获取nativesapwn进程号") - pid1 = self.driver.System.get_pid("nativespawn") - Step("步骤5:点击start Native Process Isolated按钮") - self.driver.touch(BY.text("start Native Process Isolated")) - Step("步骤6:第二次获取nativesapwn进程号") - pid2 = self.driver.System.get_pid("nativespawn") - Step("步骤7:关闭测试应用") - self.driver.stop_app("com.acts.childprocessmanager") - Step("步骤8:第三次获取nativesapwn进程号") - pid3 = self.driver.System.get_pid("nativespawn") - Step("步骤9:预期结果校验") - self.driver.Assert.equal(pid1, None) - self.driver.Assert.not_equal(pid2, None) - self.driver.Assert.equal(pid3, None) - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.json deleted file mode 100644 index 35f2dbc3..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.py deleted file mode 100644 index 64f2ba3c..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0200.py +++ /dev/null @@ -1,82 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn0200(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process按钮") - self.driver.touch(BY.text("Start Ark Process")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:获取测试应用appspawn孵化子进程pid") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:ArkProcess0") - Step("步骤7:查看数据") - res = self.driver.shell("ls -l /proc/%d/ns/net" % pid) - childres = self.driver.shell("ls -l /proc/%d/ns/net" % child_pid) - Step("步骤7:预期结果检验") - arr = res.split("-> ")[1] - childarr = childres.split("-> ")[1] - self.driver.Assert.equal(arr, childarr) - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.json deleted file mode 100644 index 52c04399..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.py deleted file mode 100644 index 32195b39..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0300.py +++ /dev/null @@ -1,82 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn0300(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process按钮") - self.driver.touch(BY.text("Start Ark Process Isolated")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:获取测试应用appspawn孵化子进程pid") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:ArkProcess0") - Step("步骤7:查看数据") - res = self.driver.shell("ls -l /proc/%d/ns/net" % pid) - childres = self.driver.shell("ls -l /proc/%d/ns/net" % child_pid) - Step("步骤7:预期结果检验") - arr = res.split("-> ")[1] - childarr = childres.split("-> ")[1] - self.driver.Assert.not_equal(arr, childarr) - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.json deleted file mode 100644 index 53ec308d..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.py deleted file mode 100644 index 5f0c5173..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0400.py +++ /dev/null @@ -1,82 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn0400(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process按钮") - self.driver.touch(BY.text("start Native Process")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:获取测试应用nativespawn孵化子进程pid") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") - Step("步骤7:查看数据") - res = self.driver.shell("ls -l /proc/%d/ns/net" % pid) - childres = self.driver.shell("ls -l /proc/%d/ns/net" % child_pid) - Step("步骤7:预期结果检验") - arr = res.split("-> ")[1] - childarr = childres.split("-> ")[1] - self.driver.Assert.equal(arr, childarr) - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.json deleted file mode 100644 index 8ac0c9f0..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.py deleted file mode 100644 index 3f9a7bfc..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0500.py +++ /dev/null @@ -1,82 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn0500(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process按钮") - self.driver.touch(BY.text("start Native Process Isolated")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:获取测试应用nativespawn孵化子进程pid") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") - Step("步骤7:查看数据") - res = self.driver.shell("ls -l /proc/%d/ns/net" % pid) - childres = self.driver.shell("ls -l /proc/%d/ns/net" % child_pid) - Step("步骤7:预期结果检验") - arr = res.split("-> ")[1] - childarr = childres.split("-> ")[1] - self.driver.Assert.not_equal(arr, childarr) - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.json deleted file mode 100644 index e524f783..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.py deleted file mode 100644 index 5486dd66..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0700.py +++ /dev/null @@ -1,82 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn0700(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process按钮") - self.driver.touch(BY.text("Start Ark Process Isolated")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:获取测试应用appspawn孵化子进程pid") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:ArkProcess0") - Step("步骤7:测试应用沙箱路径data/storage/el1生成一个123.txt") - self.driver.shell("echo 123456789 > /proc/%d/root/data/storage/el1/123.txt" % pid) - Step("步骤8:测试应用appspawn孵化子进程查看沙箱路径data/storage/el1") - childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/123.txt" % child_pid) - Step("步骤8:预期结果检验") - self.driver.Assert.contains(childres, "root/data/storage/el1/123.txt: No such file or directory") - self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/123.txt" % pid) - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.json deleted file mode 100644 index 4dadc000..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.py deleted file mode 100644 index af214e54..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_0900.py +++ /dev/null @@ -1,84 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn0900(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process Isolated按钮") - self.driver.touch(BY.text("start Native Process Isolated")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:获取测试应用孵化native进程pid") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") - Step("步骤7:测试应用沙箱路径data/storage/el1生成一个123.txt") - self.driver.shell("echo 0123456789 > /proc/%d/root/data/storage/el1/123.txt" % pid) - Step("步骤8:测试应用孵化native进程查看沙箱路径data/storage/el1") - childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/123.txt" % child_pid) - Step("步骤8:预期结果检验") - self.driver.Assert.contains(childres, "root/data/storage/el1/123.txt: No such file or directory") - self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/123.txt" % pid) - - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") - diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.json deleted file mode 100644 index 65eb9d6c..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.py deleted file mode 100644 index 93161e24..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1000.py +++ /dev/null @@ -1,91 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn1000(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process按钮") - self.driver.touch(BY.text("Start Ark Process")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:获取测试应用appspawn孵化子进程pid") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:ArkProcess0") - Step("步骤7:测试应用沙箱路径data/storage/el1/bundle目录下,创建2个文件夹") - self.driver.shell("mkdir /proc/%d/root/data/storage/el1/bundle/test1 /proc/%d/root/data/storage/el1/bundle/test2" % (pid, pid)) - Step("步骤8:测试应用沙箱路径data/storage/el1/bundle/tets1,创建1个test.txt文件") - self.driver.shell("echo this is test1 > /proc/%d/root/data/storage/el1/bundle/test1/test.txt" % pid) - Step("步骤9:test1挂载test2") - self.driver.shell("mount /proc/%d/root/data/storage/el1/bundle/test1 /proc/%d/root/data/storage/el1/bundle/test2" % (pid, pid)) - Step("步骤10:查看test2目录下的文件是否和test1内容一致") - res = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/test2/test.txt" % pid) - Step("步骤11:测试应用appspawn孵化子进程查看沙箱路径data/storage/el1/bundle/test2/test.txt") - childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/test2/test.txt" % child_pid) - Step("步骤12:预期结果检验") - self.driver.Assert.contains(res, "this is test1") - self.driver.Assert.contains(childres, "root/data/storage/el1/bundle/test2/test.txt: No such file or directory") - self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/bundle/test1 /proc/%d/root/data/storage/el1/bundle/test2" % (pid, pid)) - - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") - diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.json deleted file mode 100644 index 52e18e1c..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.py deleted file mode 100644 index e31c6663..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1100.py +++ /dev/null @@ -1,91 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn1100(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process Isolated按钮") - self.driver.touch(BY.text("Start Ark Process Isolated")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:获取测试应用appspawn孵化子进程pid") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:ArkProcess0") - Step("步骤7:测试应用沙箱路径data/storage/el1/bundle目录下,创建2个文件夹") - self.driver.shell("mkdir /proc/%d/root/data/storage/el1/bundle/test1 /proc/%d/root/data/storage/el1/bundle/test2" % (pid, pid)) - Step("步骤8:测试应用沙箱路径data/storage/el1/bundle/tets1,创建1个test.txt文件") - self.driver.shell("echo this is test1 > /proc/%d/root/data/storage/el1/bundle/test1/test.txt" % pid) - Step("步骤9:test1挂载test2") - self.driver.shell("mount /proc/%d/root/data/storage/el1/bundle/test1 /proc/%d/root/data/storage/el1/bundle/test2" % (pid, pid)) - Step("步骤10:查看test2目录下的文件是否和test1内容一致") - res = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/test2/test.txt" % pid) - Step("步骤11:测试应用appspawn孵化子进程查看沙箱路径data/storage/el1/bundle/test2/test.txt") - childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/test2/test.txt" % child_pid) - Step("步骤12:预期结果检验") - self.driver.Assert.contains(res, "this is test1") - self.driver.Assert.contains(childres, "root/data/storage/el1/bundle/test2/test.txt: No such file or directory") - self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/bundle/test1 /proc/%d/root/data/storage/el1/bundle/test2" % (pid, pid)) - - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") - diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.json deleted file mode 100644 index ff9fc37a..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.py deleted file mode 100644 index 53100365..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1200.py +++ /dev/null @@ -1,91 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn1200(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Native Process按钮") - self.driver.touch(BY.text("start Native Process")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:孵化native子进程pid") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") - Step("步骤7:测试应用沙箱路径data/storage/el1/bundle目录下,创建2个文件夹") - self.driver.shell("mkdir /proc/%d/root/data/storage/el1/bundle/zsj1 /proc/%d/root/data/storage/el1/bundle/zsj2" % (pid, pid)) - Step("步骤8:测试应用沙箱路径data/storage/el1/bundle/tets1,创建1个zsj.txt文件") - self.driver.shell("echo this is zsj1 > /proc/%d/root/data/storage/el1/bundle/zsj1/zsj.txt" % pid) - Step("步骤9:test1挂载test2") - self.driver.shell("mount /proc/%d/root/data/storage/el1/bundle/zsj1 /proc/%d/root/data/storage/el1/bundle/zsj2" % (pid, pid)) - Step("步骤10:查看test2目录下的文件是否和test1内容一致") - res = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/zsj2/zsj.txt" % pid) - Step("步骤11:孵化native子进程查看沙箱路径data/storage/el1/bundle/zsj2/zsj.txt") - childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/zsj2/zsj.txt" % child_pid) - Step("步骤12:预期结果检验") - self.driver.Assert.contains(res, "this is zsj1") - self.driver.Assert.contains(childres, "root/data/storage/el1/bundle/zsj2/zsj.txt: No such file or directory") - self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/bundle/zsj1 /proc/%d/root/data/storage/el1/bundle/zsj2" % (pid, pid)) - - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") - diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.json deleted file mode 100644 index 060f2347..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.py deleted file mode 100644 index ffb58b3e..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1300.py +++ /dev/null @@ -1,91 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn1300(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Native Process Isolated按钮") - self.driver.touch(BY.text("start Native Process Isolated")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:获取孵化native子进程pid") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") - Step("步骤7:测试应用沙箱路径data/storage/el1/bundle目录下,创建2个文件夹") - self.driver.shell("mkdir /proc/%d/root/data/storage/el1/bundle/zsj1 /proc/%d/root/data/storage/el1/bundle/zsj2" % (pid, pid)) - Step("步骤8:测试应用沙箱路径data/storage/el1/bundle/tets1,创建1个zsj.txt文件") - self.driver.shell("echo this is zsj1 > /proc/%d/root/data/storage/el1/bundle/zsj1/zsj.txt" % pid) - Step("步骤9:test1挂载test2") - self.driver.shell("mount /proc/%d/root/data/storage/el1/bundle/zsj1 /proc/%d/root/data/storage/el1/bundle/zsj2" % (pid, pid)) - Step("步骤10:查看test2目录下的文件是否和test1内容一致") - res = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/zsj2/zsj.txt" % pid) - Step("步骤11:孵化native子进程查看沙箱路径data/storage/el1/bundle/zsj2/zsj.txt") - childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/bundle/zsj2/zsj.txt" % child_pid) - Step("步骤12:预期结果检验") - self.driver.Assert.contains(res, "this is zsj1") - self.driver.Assert.contains(childres, "root/data/storage/el1/bundle/zsj2/zsj.txt: No such file or directory") - self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/bundle/zsj1 /proc/%d/root/data/storage/el1/bundle/zsj2" % (pid, pid)) - - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") - diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.json deleted file mode 100644 index 6b1aade8..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.py deleted file mode 100644 index 5d72bc5b..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1400.py +++ /dev/null @@ -1,90 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn1400(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process Isolated按钮") - self.driver.touch(BY.text("start Native Process Isolated")) - Step("步骤5:获取测试应用pid") - self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:获取测试应用孵化native进程pid") - child_pid 1 = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") - Step("步骤7:测试应用沙箱路径data/storage/el1生成一个native.txt") - self.driver.shell("echo this is native1 > /proc/%d/root/data/storage/el1/native.txt" % child_pid 1) - childres = self.driver.shell("cat /proc/%d/root/data/storage/el1/native.txt" % child_pid 1) - Step("步骤8:杀死孵化native进程") - self.driver.shell("kill -9 %d" % child_pid 1) - Step("步骤9:再次点击start Ark Process Isolated按钮") - self.driver.touch(BY.text("start Native Process Isolated")) - Step("步骤10:测试应用孵化native进程查看沙箱路径data/storage/el1") - child_pid 2 = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry1") - childres2 = self.driver.shell("cat /proc/%d/root/data/storage/el1/native.txt" % child_pid 2) - Step("步骤11:预期结果检验") - self.driver.Assert.contains(childres, "this is native1") - self.driver.Assert.contains(childres2, "this is native1") - self.driver.shell("rm -rf /proc/%d/root/data/storage/el1/native.txt" % child_pid 2) - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") - diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.json deleted file mode 100644 index 851b5122..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.py deleted file mode 100644 index 63c6344d..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1500.py +++ /dev/null @@ -1,85 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn1500(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process Isolated按钮") - self.driver.touch(BY.text("start Native Process Isolated")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:获取测试应用孵化native进程pid") - child_pid 1 = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") - Step("步骤7:杀死nativespawn进程") - self.driver.shell("kill -9 `pidof nativespawn`") - Step("步骤8:查询测试应用") - result = self.driver.shell("ps -ef | grep com.acts.childprocessmanager") - Step("步骤9:查询nativespawn进程号") - nativepid = self.driver.System.get_pid("nativespawn") - self.driver.Assert.contains(result, str(child_pid 1)) - self.driver.Assert.contains(result, str(pid)) - self.driver.Assert.equal(nativepid, None) - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") - diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.json deleted file mode 100644 index 749e6f99..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.py deleted file mode 100644 index 4c20f740..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1600.py +++ /dev/null @@ -1,78 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn1600(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process按钮") - self.driver.touch(BY.text("start Native Process Isolated")) - Step("步骤5:获取测试应用nativespawn孵化子进程pid") - time.sleep(1) - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") - Step("步骤6:孵化的native子进程(Isolated=true)selinux标签类型") - childres = self.driver.shell("ps -efZ | grep %d | grep -v grep" % child_pid) - Step("步骤9: 预期结果校验") - self.driver.Assert.contains(childres, "u:r:isolated_render:s0") - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.json deleted file mode 100644 index 949a2197..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.py deleted file mode 100644 index 474485a7..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1700.py +++ /dev/null @@ -1,83 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn1700(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:点击start Ark Process按钮") - self.driver.touch(BY.text("start Native Process")) - Step("步骤5:获取测试应用pid") - pid = self.driver.System.get_pid("com.acts.childprocessmanager") - Step("步骤6:获取测试应用nativespawn孵化子进程pid") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") - Step("步骤7:测试应用selinux标签类型") - res = self.driver.shell("ps -efZ | grep %d | grep -v grep" % pid) - Step("步骤8:孵化的native子进程(Isolated=false)selinux标签类型") - childres = self.driver.shell("ps -efZ | grep %d | grep -v grep" % child_pid) - string = res.split(" ")[0] - child_string = childres.split(" ")[0] - Step("步骤9: 预期结果校验") - self.driver.Assert.equal(string, child_string) - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.json deleted file mode 100644 index b5bedb14..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.py deleted file mode 100644 index a99c2ab6..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1800.py +++ /dev/null @@ -1,93 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn1800(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:首次获取nativesapwn进程号") - pid1 = self.driver.System.get_pid("nativespawn") - Step("步骤5:点击start Native Process Isolated按钮") - self.driver.touch(BY.text("start Native Process Isolated")) - time.sleep(1) - Step("步骤6:再次点击start Native Process Isolated按钮") - self.driver.touch(BY.text("start Native Process Isolated")) - Step("步骤7:第二次获取nativesapwn进程号") - pid2 = self.driver.System.get_pid("nativespawn") - Step("步骤8:杀掉孵化的一个nativ进程") - child_pid = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry0") - self.driver.shell("kill -9 %d" % child_pid) - Step("步骤9:第三次获取nativesapwn进程号") - pid3 = self.driver.System.get_pid("nativespawn") - Step("步骤10:杀掉孵化的最后一个native子进程") - child_pid 1 = self.driver.System.get_pid("com.acts.childprocessmanager:Native_libentry1") - self.driver.shell("kill -9 %d" % child_pid 1) - Step("步骤11:第四次获取nativesapwn进程号") - pid4 = self.driver.System.get_pid("nativespawn") - Step("步骤12:预期结果校验") - self.driver.Assert.equal(pid1, None) - self.driver.Assert.not_equal(pid2, None) - self.driver.Assert.not_equal(pid3, None) - self.driver.Assert.equal(pid4, None) - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.json b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.json deleted file mode 100644 index 77347638..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.py"] - } -} \ No newline at end of file diff --git a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.py b/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.py deleted file mode 100644 index 3ea853e4..00000000 --- a/test/autotest/SubStartupAppspawnNativespawn/sub_startup_appspawn_nativespawn_1900.py +++ /dev/null @@ -1,102 +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. - -from devicetest.core.test_case import TestCase, Step, CheckPoint -from devicetest.core.test_case import Step, TestCase -from hypium import UiParam -from hypium.model import UiParam -from aw import Common -import time - - -class SubStartupAppspawnNativespawn1900(TestCase): - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:检测屏幕是否亮.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - Step('获取权限状态') - is_status = self.driver.shell("param get persist.sys.abilityms.multi_process_model") - if ("true" in is_status): - pass - else: - Step('设置权限为true') - self.driver.shell("param set persist.sys.abilityms.multi_process_model true") - Step('重启生效') - self.driver.shell("reboot") - self.driver.System.wait_for_boot_complete() - self.driver.ScreenLock.unlock() - - def test_step1(self): - Step("步骤1:安装测试应用") - hap1 = Common.sourcepath('entry-default-nativespawn.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - hap2 = Common.sourcepath('entry-default-nativespawn1.hap', "SUB_STARTUP_STABILITY_APPSPAWN") - is_hap = self.driver.has_app("com.acts.childprocessmanager") - if(is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager") - else: - pass - is_hap = self.driver.has_app("com.acts.childprocessmanager1") - if (is_hap): - self.driver.uninstall_app("com.acts.childprocessmanager1") - else: - pass - self.driver.install_app(hap1) - self.driver.install_app(hap2) - Step("步骤2:打开测试应用1") - self.driver.start_app("com.acts.childprocessmanager") - Step("步骤3:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤4:首次获取nativesapwn进程号") - pid1 = self.driver.System.get_pid("nativespawn") - Step("步骤5:点击start Native Process Isolated按钮") - self.driver.touch(BY.text("start Native Process Isolated")) - Step("步骤6:第二次获取nativesapwn进程号") - pid2 = self.driver.System.get_pid("nativespawn") - Step("步骤7:打开测试应用2") - self.driver.start_app("com.acts.childprocessmanager1") - Step("步骤8:点击StartArk用例按钮") - self.driver.touch(BY.text("StartArk用例")) - Step("步骤9:点击start Native Process Isolated按钮") - self.driver.touch(BY.text("start Native Process Isolated")) - Step("步骤10:关闭测试应用1") - self.driver.stop_app("com.acts.childprocessmanager") - Step("步骤11:第三次获取nativesapwn进程号") - pid3 = self.driver.System.get_pid("nativespawn") - Step("步骤12:关闭测试应用1") - self.driver.stop_app("com.acts.childprocessmanager1") - Step("步骤13:第四次获取nativesapwn进程号") - pid4 = self.driver.System.get_pid("nativespawn") - Step("步骤12:预期结果校验") - self.driver.Assert.equal(pid1, None) - self.driver.Assert.not_equal(pid2, None) - self.driver.Assert.not_equal(pid3, None) - self.driver.Assert.equal(pid4, None) - - def teardown(self): - Step("收尾工作:卸载测试应用") - self.driver.uninstall_app("com.acts.childprocessmanager") - self.driver.uninstall_app("com.acts.childprocessmanager1") \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.json b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.json deleted file mode 100644 index b408aca0..00000000 --- a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "test/autotest/SUB_STARTUP_APPSPAWN_CGROUPS/SubStartupAppspawnCgroup0100.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.py b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.py deleted file mode 100644 index 0b69b20d..00000000 --- a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0100.py +++ /dev/null @@ -1,74 +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. - -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver - -from aw import Common - - -class SubStartupAppspawnCgroup0100(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.shell("power-shell setmdoe 602") - - def process(self): - hap_path = Common.sourcepath('ForkTest1.hap', "SUB_STARTUP_APPSPAWN_CGROUPS") - bundle_name = "com.example.exe_sys_cmd" - 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(bundle_name) - else: - self.driver.AppManager.install_app(bundle_name) - self.driver.AppManager.start_app(bundle_name) - pid = self.driver.System.get_pid(bundle_name) - result1 = self.driver.shell("ps -ef |grep %s" % bundle_name) - cgroup1 = self.driver.shell("cat /dev/pids/100/%s/app_%d/cgroup.procs" % (bundle_name, pid)).split() - count = 0 - for i in cgroup1: - self.driver.Assert.contains(result1.split(), i) - if result1.count(i) == 2: - count += 1 - self.driver.Assert.equal(count, 1) - result2 = self.driver.shell("kill -9 %d" % pid) - self.driver.Assert.equal(result2, '') - result3 = self.driver.shell("ps -ef |grep %s|grep -v grep " % bundle_name) - self.driver.Assert.equal(result3, '') - - def teardown(self): - Step("收尾工作...") - self.driver.AppManager.clear_app_data(bundle_name) - self.driver.AppManager.uninstall_app(bundle_name) \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.json b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.json deleted file mode 100644 index 9c955111..00000000 --- a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "test/autotest/SUB_STARTUP_APPSPAWN_CGROUPS/SubStartupAppspawnCgroup0200.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.py b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.py deleted file mode 100644 index 2e1efc10..00000000 --- a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0200.py +++ /dev/null @@ -1,73 +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. - -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver - -from aw import Common - - -class SubStartupAppspawnCgroup0200(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.shell("power-shell timeout -o 86400000") - - def process(self): - hap_path = Common.sourcepath('ForkTest2.hap', "SUB_STARTUP_APPSPAWN_CGROUPS") - bundle_name = "com.example.exe_sys_cmd" - 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(bundle_name) - else: - self.driver.AppManager.install_app(bundle_name) - self.driver.AppManager.start_app(bundle_name) - pid = self.driver.System.get_pid(bundle_name) - result1 = self.driver.shell("ps -ef |grep %s" % bundle_name) - cgroup1 = self.driver.shell("cat /dev/pids/100/%s/app_%d/cgroup.procs" % (bundle_name, pid)).split() - count = 0 - for i in cgroup1: - self.driver.Assert.contains(result1.split(), i) - if result1.count(i) == 3: - count += 1 - self.driver.Assert.equal(count, 1) - result2 = self.driver.shell("kill -9 %d" % pid) - self.driver.Assert.equal(result2, '') - result3 = self.driver.shell("ps -ef |grep %s|grep -v grep " % bundle_name) - self.driver.Assert.equal(result3, '') - - def teardown(self): - Step("收尾工作...") - self.driver.AppManager.clear_app_data("com.example.exe_sys_cmd") diff --git a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.json b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.json deleted file mode 100644 index 9f598ad9..00000000 --- a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "test/autotest/SUB_STARTUP_APPSPAWN_CGROUPS/SubStartupAppspawnCgroup0300.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.py b/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.py deleted file mode 100644 index 21b0e960..00000000 --- a/test/autotest/subStartupAppspawnCgroup/sub_startup_appspawn_cgroup_0300.py +++ /dev/null @@ -1,73 +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. - -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver - -from aw import Common - - -class SubStartupAppspawnCgroup0300(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.shell("power-shell timeout -o 86400000") - - def process(self): - hap_path = Common.sourcepath('ForkTest3.hap', "SUB_STARTUP_APPSPAWN_CGROUPS") - bundle_name = "com.example.exe_sys_cmd" - 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(bundle_name) - else: - self.driver.AppManager.install_app(bundle_name) - self.driver.AppManager.start_app(bundle_name) - pid = self.driver.System.get_pid(bundle_name) - result1 = self.driver.shell("ps -ef |grep %s" % bundle_name) - cgroup1 = self.driver.shell("cat /dev/pids/100/%s/app_%d/cgroup.procs" % (bundle_name, pid)).split() - count = 0 - for i in cgroup1: - self.driver.Assert.contains(result1.split(), i) - if result1.count(i) == 2: - count += 1 - self.driver.Assert.equal(count, 2) - result2 = self.driver.shell("kill -9 %d" % pid) - self.driver.Assert.equal(result2, '') - result3 = self.driver.shell("ps -ef |grep %s|grep -v grep " % bundle_name) - self.driver.Assert.equal(result3, '') - - def teardown(self): - Step("收尾工作...") - self.driver.AppManager.clear_app_data("com.example.exe_sys_cmd") diff --git a/test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.json b/test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.json deleted file mode 100644 index cc1ab049..00000000 --- a/test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "test/autotest/SUB_STARTUP_APPSPAWN_CGROUPS/SubStartupAppspawnColdstart0100.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.py b/test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.py deleted file mode 100644 index b20c065b..00000000 --- a/test/autotest/subStartupAppspawnColdstart/sub_startup_appspawn_coldstart_0100.py +++ /dev/null @@ -1,52 +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. - -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver - -from aw import Common - - -class SubStartupAppspawnColdstart0100(TestCase): - - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def test_step1(self): - Step("设置冷启动全局参...............") - result = self.driver.shell('param set startup.appspawn.cold.boot 1') - sleep(3) - if "Set paramter startup.appspawn.cold.boot 1 success" in result: - pass - else: - raise ValueError('设置冷启动全局参数失败') - Step("通过命令启动日历...........") - result = self.driver.shell('aa start -C -d 123456 -a MainAbility -b com.example.calendar') - sleep(3) - self.driver.Assert.contains(result, "start ability successfully", "通过命令启动日历失败") - Step("检查日历冷启动进程............") - result_ps = self.driver.shell("ps -ef|grep com.example.calendar") - result_ps = result_ps.split('\n')[0] - Step("日历进程信息如下:" + str(result_ps)) - - def teardown(self): - Step("收尾工作...") - pid = self.driver.System.get_pid('com.example.calendar') - self.driver.shell('kill -9 %d' % pid) \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.json b/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.json deleted file mode 100644 index 6d9e9634..00000000 --- a/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "test/autotest/SUB_STARTUP_APPSPAWN_CGROUPS/SubStartupAppspawnColdstartAblity0100.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.py b/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.py deleted file mode 100644 index b1763276..00000000 --- a/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0100.py +++ /dev/null @@ -1,59 +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. - -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver - -from aw import Common - - -class SubStartupAppspawnColdstartAblity0100(TestCase): - - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作开始") - Step(self.devices[0].device_id) - Step("安装测试hap") - sourcepath = Common.sourcepath("asan-enable.hap", "SUB_STARTUP_APPSPAWN_COLDSTARTABLITY") - Step(sourcepath) - self.driver.AppManager.install_app(sourcepath) - Step("预置工作:检查屏幕") - self.driver.Screen.wake_up() - self.driver.ScreenLock.unlock() - self.driver.Screen.enable_stay_awake() - - def test_step1(self): - Step("打开测试hap...............") - result = self.driver.startup_app("com.example.myapplication", "EntryAbility") - sleep(3) - pid = self.driver.System.get_pid('com.example.myapplication') - Step(pid) - Step("校验") - result = self.driver.shell('cat /proc/self/maps|grep libclang_rt.asan.so') - Step(result) - self.driver.Assert.contains(result, '/system/lib64/libclang_rt.asan.so') - self.driver.Assert.contains(result, 'anon:libclang_rt.asan.so.bss') - - def teardown(self): - Step("收尾工作...") - self.driver.AppManager.clear_app_data('com.example.myapplication') - self.driver.AppManager.uninstall_app('com.example.myapplication') \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.json b/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.json deleted file mode 100644 index 99782006..00000000 --- a/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "test/autotest/SUB_STARTUP_APPSPAWN_CGROUPS/SubStartupAppspawnColdstartAblity0200.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.py b/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.py deleted file mode 100644 index eea78653..00000000 --- a/test/autotest/subStartupAppspawnColdstartAblity/sub_startup_appspawn_coldstart_ablity_0200.py +++ /dev/null @@ -1,58 +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. - -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver - -from aw import Common - - -class SubStartupAppspawnColdstartAblity0200(TestCase): - - - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作开始") - Step(self.devices[0].device_id) - Step("安装测试hap") - sourcepath = Common.sourcepath("asan-enable.hap", "SUB_STARTUP_APPSPAWN_COLDSTARTABLITY") - Step(sourcepath) - self.driver.AppManager.install_app(sourcepath) - Step("预置工作:检查屏幕") - self.driver.Screen.wake_up() - self.driver.ScreenLock.unlock() - self.driver.Screen.enable_stay_awake() - - def test_step1(self): - Step("打开测试hap...............") - result = self.driver.startup_app("com.example.myapplication", "EntryAbility") - sleep(3) - pid = self.driver.System.get_pid('com.example.myapplication') - Step(pid) - Step("校验") - result = self.driver.shell('cat /proc/self/maps|grep libclang_rt.asan.so') - Step(result) - self.driver.Assert.contains(result, '') - - def teardown(self): - Step("收尾工作...") - self.driver.AppManager.clear_app_data('com.example.myapplication') - self.driver.AppManager.uninstall_app('com.example.myapplication') diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.json deleted file mode 100644 index 5e005475..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py"] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py deleted file mode 100644 index 123b491a..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py +++ /dev/null @@ -1,76 +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. - -import os -import time -from devicetest.core.test_case import TestCase, Step, CheckPoint -from hypium import UiDriver -from hypium.action.os_hypium.device_logger import DeviceLogger -from hypium.model import UiParam, WindowFilter - - -class SubStartupAppspawnAppclone0100(TestCase): - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:唤醒屏幕.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - - def test_step1(self): - Step("步骤1:安装测试hap包") - ishap = self.driver.has_app("com.ohos.mytest") - if(ishap): - self.driver.uninstall_app("com.ohos.mytest") - path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) - hap = os.path.abspath( - os.path.join(os.path.join(path, "testFile"), - 'sub_startup_appspawn_appclone/entry-signed-release.hap')) - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.ohos.mytest", "EntryAbility") - time.sleep(2) - self.driver.check_window_exist(WindowFilter().bundle_name("com.ohos.mytest")) - Step("步骤3:点击安装克隆应用") - self.driver.touch(BY.text("安装克隆应用")) - self.driver.touch(BY.text("startAbilityByAppIndex")) - Step("步骤4:分身应用的源目录新建123.txt") - self.driver.shell("touch /data/app/el2/100/database/+clone-1+com.ohos.mytest/123.txt") - Step("步骤5:分身应用沙盒路径是否存在123.txt") - cpid = self.driver.System.get_pid("com.ohos.mytest1") - result1 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % cpid) - Step("步骤6:预期结果校验") - self.driver.Assert.contains(result1, "123.txt") - Step("步骤7:主应用沙盒路径是否存在123.txt") - pid = self.driver.System.get_pid("com.ohos.mytest") - result2 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % pid) - Step("步骤6:预期结果校验") - if ("123.txt" in result2): - raise AssertionError() - else: - pass - - def teardown(self): - Step("收尾工作:删除hap") - self.driver.uninstall_app("com.ohos.mytest") diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.json deleted file mode 100644 index bb2984a9..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": ["sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py"] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py deleted file mode 100644 index 1ef2cf9d..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py +++ /dev/null @@ -1,76 +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. - -import os -import time -from devicetest.core.test_case import TestCase, Step, CheckPoint -from hypium import UiDriver -from hypium.action.os_hypium.device_logger import DeviceLogger -from hypium.model import UiParam, WindowFilter - - -class SubStartupAppspawnAppclone0200(TestCase): - def __init__(self, controllers): - self.tag = self.__class__.__name__ - self.tests = [ - "test_step1" - ] - TestCase.__init__(self, self.tag, controllers) - self.driver = UiDriver(self.device1) - - def setup(self): - Step("预置工作:初始化手机开始.................") - self.driver = UiDriver(self.device1) - Step("预置工作:唤醒屏幕.................") - self.driver.enable_auto_wakeup(self.device1) - Step("预置工作:滑动解锁.................") - self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) - Step('设置屏幕常亮') - self.driver.Screen.enable_stay_awake() - - def test_step1(self): - Step("步骤1:安装测试hap包") - ishap = self.driver.has_app("com.ohos.mytest") - if(ishap): - self.driver.uninstall_app("com.ohos.mytest") - path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) - hap = os.path.abspath( - os.path.join(os.path.join(path, "testFile"), - 'sub_startup_appspawn_appclone/entry-signed-release.hap')) - self.driver.install_app(hap) - Step("步骤2:打开测试应用") - self.driver.start_app("com.ohos.mytest", "EntryAbility") - time.sleep(2) - self.driver.check_window_exist(WindowFilter().bundle_name("com.ohos.mytest")) - Step("步骤3:点击安装克隆应用") - self.driver.touch(BY.text("安装克隆应用")) - self.driver.touch(BY.text("startAbilityByAppIndex")) - Step("步骤4:分身应用的源目录新建123.txt") - self.driver.shell("touch /data/app/el2/100/database/com.ohos.mytest/abc.txt") - Step("步骤5:主应用沙盒路径是否存在abc.txt") - cpid = self.driver.System.get_pid("com.ohos.mytest") - result1 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % cpid) - Step("步骤6:预期结果校验") - self.driver.Assert.contains(result1, "abc.txt") - Step("步骤7:分身应用沙盒路径是否存在abc.txt") - pid = self.driver.System.get_pid("com.ohos.mytest1") - result2 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % pid) - Step("步骤6:预期结果校验") - if ("abc.txt" in result2): - raise AssertionError() - else: - pass - - def teardown(self): - Step("收尾工作:删除hap") - self.driver.uninstall_app("com.ohos.mytest") diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.json deleted file mode 100644 index f24d94ed..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py deleted file mode 100644 index 19c8ae59..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py +++ /dev/null @@ -1,100 +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. - -import os -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from hypium.model import UiParam -from hypium.action.os_hypium.device_logger import DeviceLogger -from aw import Common - - -class SubStartupAppspawnAppclone0300(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 build_shell_command(i, path, bundle_name, j): - if bundle_name == "com.example.intaketest": - result01 = self.driver.shell("ls /data/app/el%d/100/%s/%s" % (i, path, bundle_name)) - elif bundle_name == "com.example.intaketest%d" % j: - result01 = self.driver.shell("ls /data/app/el%d/100/%s/+clone-%d+com.example.intaketest" - % (i, path, j)) - return None - - def process(self): - Step("安装测试hap并打开") - pid_bundlename_dict = {} - bundle_name = "com.example.intaketest" - hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") - 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) - pid = self.driver.System.get_pid(bundle_name) - pid_bundlename_dict.update({bundle_name: pid}) - - self.driver.AppManager.stop_app("com.example.settings") - self.driver.AppManager.start_app("com.example.settings") - self.driver.swipe(UiParam.UP) - for text in ["系统", "应用分身", "IntakeTest"]: - self.driver.touch(BY.text(text)) - for i in range(5): - self.driver.touch(BY.text("创建分身")) - time.sleep(1) - self.driver.AppManager.stop_app("com.example.settings") - - for i in range(1, 7): - self.driver.AppManager.start_app(bundle_name) - if i == 1: - self.driver.touch(BY.text("IntakeTest")) - pid = self.driver.System.get_pid(bundle_name) - pid_bundlename_dict.update({bundle_name: pid}) - else: - self.driver.touch(BY.text("更多打开方式")) - self.driver.touch(BY.text("IntakeTest%d" % (i - 1))) - pid = self.driver.System.get_pid("%s%d" % (bundle_name, i - 1)) - pid_bundlename_dict.update({"%s%d" % (bundle_name, i - 1) : pid}) - self.driver.go_home() - - for i in range(1, 5): - for j in range(1, 6): - for bundle_name, pid in pid_bundlename_dict.items(): - result01 = build_shell_command(i, "base", bundle_name, j) - result02 = self.driver.shell("ls /proc/%d/root/data/storage/el%d/%s" % (pid, i, "base")) - self.driver.Assert.equal(result01, result02) - - def teardown(self): - Step("收尾工作.................") - self.driver.AppManager.uninstall_app("com.example.intaketest") diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.json deleted file mode 100644 index 8b42c680..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py deleted file mode 100644 index 0fac2642..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py +++ /dev/null @@ -1,85 +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. - -import os -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from hypium.model import UiParam -from hypium.action.os_hypium.device_logger import DeviceLogger -from aw import Common - - -class SubStartupAppspawnAppclone0400(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): - Step("安装测试hap并打开") - bundle_name = "com.example.intaketest" - hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") - 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.AppManager.stop_app("com.example.settings") - self.driver.AppManager.start_app("com.example.settings") - self.driver.swipe(UiParam.UP) - for text in ["系统", "应用分身", "IntakeTest"]: - self.driver.touch(BY.text(text)) - for i in range(5): - self.driver.touch(BY.text("创建分身")) - time.sleep(1) - self.driver.AppManager.stop_app("com.example.settings") - - for i in range(1, 7): - self.driver.AppManager.start_app(bundle_name) - if i == 1: - self.driver.touch(BY.text("IntakeTest")) - else: - self.driver.touch(BY.text("更多打开方式")) - self.driver.touch(BY.text("IntakeTest%d" % (i - 1))) - self.driver.go_home() - - self.driver.shell("touch /data/app/el2/100/base/%s/test.txt" % bundle_name) - has_file01 = self.driver.Storage.has_file("/data/app/el2/100/base/%s/test.txt" % bundle_name) - self.driver.Assert.equal(has_file01, True) - for i in range(1, 6): - has_file02 = self.driver.Storage.has_file("/data/app/el2/100/base/+clone-%d+%s/test.txt" % (i, bundle_name)) - self.driver.Assert.equal(has_file02, False) - - def teardown(self): - Step("收尾工作.................") - self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.json deleted file mode 100644 index 6d4df89f..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py deleted file mode 100644 index d97cb69a..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py +++ /dev/null @@ -1,80 +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. - -import os -import random -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from hypium.model import UiParam -from hypium.action.os_hypium.device_logger import DeviceLogger -from aw import Common - - -class SubStartupAppspawnAppclone0600(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): - Step("安装测试hap并打开") - bundle_name = "com.example.intaketest" - hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") - 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.AppManager.stop_app("com.example.settings") - self.driver.AppManager.start_app("com.example.settings") - self.driver.swipe(UiParam.UP) - for text in ["系统", "应用分身", "IntakeTest"]: - self.driver.touch(BY.text(text)) - for i in range(5): - self.driver.touch(BY.text("创建分身")) - time.sleep(1) - - self.driver.check_component_exist(BY.text("最多可以创建 5 个分身"), expect_exist=True) - - comps01 = self.driver.find_all_components(BY.type("Button")) - self.driver.touch(comps01[random.randint(0, len(comps01) - 1)]) - comps02 = self.driver.find_all_components(BY.type("Button")) - self.driver.touch(comps02[-1]) - self.driver.check_component_exist(BY.text("最多可以创建 5 个分身"), expect_exist=False) - self.driver.touch(BY.text("创建分身")) - self.driver.check_component_exist(BY.text("最多可以创建 5 个分身"), expect_exist=True) - - def teardown(self): - Step("收尾工作.................") - self.driver.AppManager.stop_app("com.example.settings") - self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.json deleted file mode 100644 index 1cbfb97e..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py deleted file mode 100644 index d48b79c8..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py +++ /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. - -import os -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from hypium.model import UiParam -from hypium.action.os_hypium.device_logger import DeviceLogger -from aw import Common - - -class SubStartupAppspawnAppclone0700(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): - Step("安装测试hap并打开") - bundle_name = "com.example.intaketest" - hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") - 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.AppManager.stop_app("com.example.settings") - self.driver.AppManager.start_app("com.example.settings") - self.driver.swipe(UiParam.UP) - for text in ["系统", "应用分身", "IntakeTest"]: - self.driver.touch(BY.text(text)) - for i in range(5): - self.driver.touch(BY.text("创建分身")) - time.sleep(1) - self.driver.AppManager.stop_app("com.example.settings") - - for i in range(1, 7): - self.driver.AppManager.start_app(bundle_name) - if i == 1: - self.driver.touch(BY.text("IntakeTest")) - else: - self.driver.touch(BY.text("更多打开方式")) - self.driver.touch(BY.text("IntakeTest%d" % (i - 1))) - - for i in range(1, 5): - for j in range(1, 6): - for path in ["base", "database"]: - has_dir = self.driver.Storage.has_dir("/data/app/el%d/100/%s/+clone-%d+%s" - % (i, path, j, bundle_name)) - self.driver.Assert.equal(has_dir, True) - - self.driver.AppManager.stop_app("com.example.settings") - self.driver.AppManager.start_app("com.example.settings") - self.driver.swipe(UiParam.UP) - for text in ["系统", "应用分身", "IntakeTest"]: - self.driver.touch(BY.text(text)) - comps01 = self.driver.find_all_components(BY.type("Button")) - self.driver.touch(comps01[0]) - comps02 = self.driver.find_all_components(BY.type("Button")) - self.driver.touch(comps02[-1]) - for i in range(1, 5): - for path in ["base", "database"]: - has_dir = self.driver.Storage.has_dir("/data/app/el%d/100/%s/+clone-1+%s" % (i, path, bundle_name)) - self.driver.Assert.equal(has_dir, False) - - def teardown(self): - Step("收尾工作.................") - self.driver.AppManager.stop_app("com.example.settings") - self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.json deleted file mode 100644 index 0ffa0631..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py deleted file mode 100644 index 4e9a09f7..00000000 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py +++ /dev/null @@ -1,87 +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. - -import os -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from hypium.model import UiParam -from hypium.action.os_hypium.device_logger import DeviceLogger -from aw import Common - - -class SubStartupAppspawnAppclone0900(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): - Step("安装测试hap并打开") - bundle_name = "com.example.intaketest" - hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") - 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.AppManager.stop_app("com.example.settings") - self.driver.AppManager.start_app("com.example.settings") - self.driver.swipe(UiParam.UP) - for text in ["系统", "应用分身", "IntakeTest"]: - self.driver.touch(BY.text(text)) - for i in range(5): - self.driver.touch(BY.text("创建分身")) - time.sleep(1) - self.driver.AppManager.stop_app("com.example.settings") - - for i in range(1, 7): - self.driver.AppManager.start_app(bundle_name) - if i == 1: - self.driver.touch(BY.text("IntakeTest")) - pid = self.driver.System.get_pid(bundle_name) - else: - self.driver.touch(BY.text("更多打开方式")) - self.driver.touch(BY.text("IntakeTest%d" % (i - 1))) - pid = self.driver.System.get_pid("%s%d" % (bundle_name, i - 1)) - self.driver.Assert.equal(type(pid), int) - - self.driver.AppManager.uninstall_app(bundle_name) - self.driver.AppManager.start_app("com.example.settings") - self.driver.swipe(UiParam.UP) - for text in ["系统", "应用分身"]: - self.driver.touch(BY.text(text)) - self.driver.check_component_exist(BY.text("IntakeTest"), expect_exist=False) - - def teardown(self): - Step("收尾工作.................") - self.driver.AppManager.stop_app("com.example.settings") 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 2ab0439d..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 d54d8df9..00000000 --- a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.py +++ /dev/null @@ -1,102 +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. - -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_0200.json b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.json deleted file mode 100644 index 10589557..00000000 --- a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py deleted file mode 100644 index 5e2386b5..00000000 --- a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py +++ /dev/null @@ -1,149 +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. - -import json -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from hypium.model import UiParam -from aw import Common - - -class SubStartupAppspawnAtomservice0200(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) - - Step("解锁屏幕") - 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 login_account(self): - Step("登录帐号") - setting_name = "com.example.settings" - with open(r"config/userLogin.json", 'r', encoding='UTF-8') as f: - account = json.load(f) - self.driver.AppManager.stop_app(setting_name) - self.driver.AppManager.start_app(setting_name) - self.driver.touch(BY.key("entry_image_account")) - comps1 = self.driver.find_component(BY.key("inp_hwid_login_account_name_before")) - if comps1: - self.driver.input_text(comps1, account["userName"]) - self.driver.close_soft_keyboard() - self.driver.touch(BY.key("button_text")) - comps2 = self.driver.find_component(BY.key("inp_hwid_login_password")) - self.driver.input_text(comps2, account["passWord"]) - else: - comps3 = self.driver.find_component(BY.key("inp_hwid_login_account_name")) - self.driver.clear_text(comps3) - self.driver.input_text(comps3, account["userName"]) - comps4 = self.driver.find_component(BY.key("inp_hwid_login_password")) - self.driver.input_text(comps4, account["passWord"]) - self.driver.touch(BY.key("button_text")) - self.driver.wait_for_component(BY.text("继续"), timeout=15) - self.driver.touch(BY.text("继续")) - - def exit_account(self): - Step("退出帐号") - setting_name = "com.example.settings" - self.driver.AppManager.stop_app(setting_name) - self.driver.AppManager.start_app(setting_name) - self.driver.touch(BY.key("entry_image_account")) - self.driver.swipe(UiParam.UP) - comp = self.driver.find_component(BY.key("hwid_account_center_logout_text"), scroll_target=BY.type("Scroll")) - self.driver.touch(comp) - self.driver.touch(BY.key("button_text")) - comps5 = self.driver.find_component(BY.key("advanced_dialog_button_1")) - if comps5: - self.driver.touch(comps5) - time.sleep(5) - else: - pass - - def process(self): - self.login_account() - hap_info01, hap_info02 = [], [] - bundle_name = "com.atomicservice.5765880207854649689" - bundle_name_start = "+auid-9E1E70ABFF4AAFE1E18AF18E0F75703713D" + "8678F9F9AB06C3B64C1CB1080615A+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) - self.driver.Assert.equal(log_has_dir, True) - - 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) - - Step("校验UGO、所有者、所属组、selinux标签一致") - 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 - #校验用户字符串长度为64 - self.driver.Assert.equal(len(hap_info02.split()[-1].split("-")[1].split("+")[0]), 64) - 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 - self.driver.Assert.equal(len(hap_info02.split()[-1].split("-")[1].split("+")[0]), 64) - for index in range(2, 5): - self.driver.Assert.equal(hap_info01.split()[index], hap_info02.split()[index]) - self.exit_account() - - - 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 c79b6b6b..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 fa27bdb0..00000000 --- a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.py +++ /dev/null @@ -1,64 +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. - -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/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.json b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.json deleted file mode 100644 index e7033ac7..00000000 --- a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "description": "Config for OpenHarmony devicetest test cases", - "environment": [ - { - "type": "device", - "label": "phone" - } - ], - "driver": { - "type": "DeviceTest", - "py_file": [ - "sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py deleted file mode 100644 index 118779eb..00000000 --- a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py +++ /dev/null @@ -1,112 +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. - -import json -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from hypium.model import UiParam -from aw import Common - - -class SubStartupAppspawnAtomservice0400(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 login_account(self): - Step("登录帐号") - setting_name = "com.example.settings" - with open(r"config/userLogin.json", 'r', encoding='UTF-8') as f: - account = json.load(f) - self.driver.AppManager.stop_app(setting_name) - self.driver.AppManager.start_app(setting_name) - self.driver.touch(BY.key("entry_image_account")) - - def exit_account(self): - Step("退出帐号") - setting_name = "com.example.settings" - self.driver.AppManager.stop_app(setting_name) - self.driver.AppManager.start_app(setting_name) - self.driver.touch(BY.key("entry_image_account")) - self.driver.swipe(UiParam.UP) - comp = self.driver.find_component(BY.key("hwid_account_center_logout_text"), scroll_target=BY.type("Scroll")) - self.driver.touch(comp) - self.driver.touch(BY.key("button_text")) - comps5 = self.driver.find_component(BY.key("advanced_dialog_button_1")) - if comps5: - self.driver.touch(comps5) - time.sleep(5) - else: - pass - - def process(self): - self.login_account() - comps1 = self.driver.find_component(BY.key("inp_hwid_login_account_name_before")) - if comps1: - self.driver.input_text(comps1, account["userName"]) - self.driver.close_soft_keyboard() - self.driver.touch(BY.text("下一步")) - comps2 = self.driver.find_component(BY.key("inp_hwid_login_password")) - self.driver.input_text(comps2, account["passWord"]) - else: - comps3 = self.driver.find_component(BY.key("inp_hwid_login_account_name")) - self.driver.clear_text(comps3) - self.driver.input_text(comps3, account["userName"]) - comps4 = self.driver.find_component(BY.key("inp_hwid_login_password")) - self.driver.input_text(comps4, account["passWord"]) - self.driver.touch(BY.key("button_text")) - self.driver.wait_for_component(BY.text("继续"), timeout=10) - self.driver.touch(BY.text("继续")) - - Step("启动元服务应用,检查目标路径是否存在") - bundle_name = "com.atomicservice.5765880207854649689" - bundle_name_start = "+auid-9E1E70ABFF4AAFE1E18AF18E0F75703713D" + "8678F9F9AB06C3B64C1CB1080615A+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) - self.exit_account() - - def teardown(self): - Step("收尾工作.................") - self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.json deleted file mode 100644 index 396df2fc..00000000 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_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_base/sub_startup_appspawn_base_0100.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py deleted file mode 100644 index b505603a..00000000 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py +++ /dev/null @@ -1,48 +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. - -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver - - -class SubStartupAppspawnBase0100(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.shell("power-shell timeout -o 86400000") - - def process(self): - process_list = ["appspawn", "nwebspawn"] - for process in process_list: - pid = self.driver.System.get_pid(process) - self.driver.Assert.equal(type(pid), int) - - def teardown(self): - Step("收尾工作.................") diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.json deleted file mode 100644 index 2b2eb8e9..00000000 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.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_base/sub_startup_appspawn_base_0200.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py deleted file mode 100644 index a09744d1..00000000 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py +++ /dev/null @@ -1,60 +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. - -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from aw import Common - - -class SubStartupAppspawnBase0200(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.shell("power-shell timeout -o 86400000") - - def process(self): - Step("安装测试hap并打开") - bundle_name = "com.example.myapplication" - hap_path = Common.sourcepath('test.hap', "sub_startup_appspawn_base") - hap = self.driver.AppManager.has_app(bundle_name) - if hap: - self.driver.AppManager.uninstall_app(bundle_name) - self.driver.AppManager.install_app(hap_path) - else: - self.driver.AppManager.install_app(hap_path) - self.driver.AppManager.start_app(bundle_name) - - result = self.driver.shell("ps -efZ|grep %s|grep -v grep" % bundle_name).split() - for i in ["u:r:debug_hap:s0", bundle_name]: - self.driver.Assert.contains(result, i) - - def teardown(self): - Step("收尾工作.................") - self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.json deleted file mode 100644 index d5b68022..00000000 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_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_base/sub_startup_appspawn_base_0300.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py deleted file mode 100644 index 8c55be33..00000000 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py +++ /dev/null @@ -1,60 +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. - -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from aw import Common - - -class SubStartupAppspawnBase0300(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.shell("power-shell timeout -o 86400000") - - def process(self): - Step("安装测试hap并打开") - bundle_name = "com.example.myapplication" - hap_path = Common.sourcepath('asan.hap', "sub_startup_appspawn_base") - hap = self.driver.AppManager.has_app(bundle_name) - if hap: - self.driver.AppManager.uninstall_app(bundle_name) - self.driver.AppManager.install_app(hap_path) - else: - self.driver.AppManager.install_app(hap_path) - self.driver.AppManager.start_app(bundle_name) - - result = self.driver.shell("ps -efZ|grep %s|grep -v grep" % bundle_name).split() - for i in ["u:r:debug_hap:s0", bundle_name]: - self.driver.Assert.contains(result, i) - - def teardown(self): - Step("收尾工作.................") - self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.json deleted file mode 100644 index 3bb7f96a..00000000 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.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_base/sub_startup_appspawn_base_0400.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py deleted file mode 100644 index 0de12df7..00000000 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py +++ /dev/null @@ -1,63 +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. - -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from aw import Common - - -class SubStartupAppspawnBase0400(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.shell("power-shell timeout -o 86400000") - - def process(self): - Step("安装测试hap并打开") - bundle_name = "com.example.myapplication" - for hap in ['nweb.hap', 'nweb_asan.hap']: - hap_path = Common.sourcepath(hap, "sub_startup_appspawn_base") - hap = self.driver.AppManager.has_app(bundle_name) - if hap: - self.driver.AppManager.uninstall_app(bundle_name) - self.driver.AppManager.install_app(hap_path) - else: - self.driver.AppManager.install_app(hap_path) - self.driver.AppManager.start_app(bundle_name) - - result_dict = self.driver.shell("ps -efZ|grep %s|grep -v grep" % bundle_name).split("\n") - for result in result_dict: - if result.endswith("%s:render" % bundle_name): - result_render = result - self.driver.Assert.contains(result_render.split(), "u:r:isolated_render:s0") - self.driver.AppManager.uninstall_app(bundle_name) - - def teardown(self): - Step("收尾工作.................") diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.json deleted file mode 100644 index 10ed408a..00000000 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.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_base/sub_startup_appspawn_base_0500.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py deleted file mode 100644 index 16894eec..00000000 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py +++ /dev/null @@ -1,56 +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. - -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from aw import Common - - -class SubStartupAppspawnBase0500(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.shell("power-shell timeout -o 86400000") - - def process(self): - Step("安装测试hap并打开") - bundle_name = "com.example.inputmethod" - self.driver.AppManager.start_app(bundle_name) - pid = self.driver.System.get_pid(bundle_name) - for path in ["base", "database"]: - for i in range(1, 5): - result01 = self.driver.Storage.has_dir("/proc/%d/root/data/storage/el%d/%s" % (pid, i, path)) - result02 = self.driver.Storage.has_dir("/data/app/el%d/100/%s" % (i, path)) - self.driver.Assert.equal(result01, True) - self.driver.Assert.equal(result02, True) - - def teardown(self): - Step("收尾工作.................") - self.driver.AppManager.stop_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.json deleted file mode 100644 index c18b00e6..00000000 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.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_base/sub_startup_appspawn_base_0600.py" - ] - } -} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py deleted file mode 100644 index 27d7a797..00000000 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py +++ /dev/null @@ -1,84 +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. - -import time -from devicetest.core.test_case import TestCase, Step -from hypium import UiDriver -from aw import Common - - -class SubStartupAppspawnBase0600(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.shell("power-shell timeout -o 86400000") - - def process(self): - Step("安装测试hap并打开") - bundle_name = "com.ohos.mytest" - clone_bundle_name = "com.ohos.mytest1" - hap_path = Common.sourcepath("mytest.hap", "sub_startup_appspawn_base") - hap = self.driver.AppManager.has_app(bundle_name) - if hap: - self.driver.AppManager.uninstall_app(bundle_name) - self.driver.AppManager.install_app(hap_path) - else: - self.driver.AppManager.install_app(hap_path) - self.driver.AppManager.start_app(bundle_name) - - for text in ["安装克隆应用", "startAbilityByAppIndex"]: - self.driver.touch(BY.text(text)) - - dict01 = { - bundle_name: "master.txt", - clone_bundle_name: "slave.txt" - } - - dict02 = { - bundle_name: "slave.txt", - clone_bundle_name: "master.txt" - } - - for i, txt in dict01.items(): - pid = self.driver.System.get_pid(i) - if i == clone_bundle_name: - self.driver.shell("touch /data/app/el2/100/base/+clone-1+%s/%s" % (bundle_name, txt)) - else: - self.driver.shell("touch /data/app/el2/100/base/%s/%s" % (i, txt)) - result = self.driver.Storage.has_file("/proc/%d/root/data/storage/el2/base/%s" % (pid, txt)) - self.driver.Assert.equal(result, True) - - for i, txt in dict02.items(): - pid = self.driver.System.get_pid(i) - result = self.driver.Storage.has_file("/proc/%d/root/data/storage/el2/base/%s" % (pid, txt)) - self.driver.Assert.equal(result, False) - - def teardown(self): - Step("收尾工作.................") - self.driver.AppManager.uninstall_app(bundle_name) -- Gitee From f1f093673acac64e292a4f20f88b4ee034cd7a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=98=8E?= Date: Fri, 3 Jan 2025 16:52:54 +0800 Subject: [PATCH 102/148] =?UTF-8?q?=E9=80=82=E9=85=8D=E4=BB=93=E9=A2=89ext?= =?UTF-8?q?ensionAbility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 罗明 --- modules/ace_adapter/ace_adapter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/ace_adapter/ace_adapter.cpp b/modules/ace_adapter/ace_adapter.cpp index c8ff872d..4f2dc804 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -138,6 +138,8 @@ APPSPAWN_STATIC void LoadExtendCJLib(void) void *aceAbilityLib = dlopen(acelibdir, RTLD_NOW | RTLD_LOCAL); APPSPAWN_CHECK(aceAbilityLib != nullptr, return, "Fail to dlopen %{public}s, [%{public}s]", acelibdir, dlerror()); APPSPAWN_LOGI("LoadExtendLib: Success to dlopen %{public}s", acelibdir); + + OHOS::AppExecFwk::MainThread::PreloadExtensionPlugin(); } APPSPAWN_STATIC int BuildFdInfoMap(const AppSpawnMsgNode *message, std::map &fdMap, int isColdRun) -- Gitee From 80690b0a3a1636400302527f2bc2cae8b241c898 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Mon, 6 Jan 2025 20:48:07 +0800 Subject: [PATCH 103/148] update mount again Signed-off-by: wangfeng --- modules/sandbox/BUILD.gn | 1 + modules/sandbox/appspawn_mount_template.c | 14 +- modules/sandbox/sandbox_manager.c | 64 +-- modules/sandbox/sandbox_shared_mount.cpp | 463 ++++++++++++++++++ modules/sandbox/sandbox_shared_mount.h | 67 +++ modules/sandbox/sandbox_utils.cpp | 285 +---------- modules/sandbox/sandbox_utils.h | 5 - standard/appspawn_appmgr.c | 26 +- standard/appspawn_manager.h | 20 + standard/appspawn_msgmgr.c | 22 +- .../datagroup/test_app_info.json | 38 ++ .../unittest/app_spawn_standard_test/BUILD.gn | 11 +- util/include/appspawn_utils.h | 2 +- 13 files changed, 677 insertions(+), 341 deletions(-) create mode 100644 modules/sandbox/sandbox_shared_mount.cpp create mode 100644 modules/sandbox/sandbox_shared_mount.h create mode 100644 test/test_app_info/datagroup/test_app_info.json diff --git a/modules/sandbox/BUILD.gn b/modules/sandbox/BUILD.gn index 279ffdb0..5a7d2d2c 100644 --- a/modules/sandbox/BUILD.gn +++ b/modules/sandbox/BUILD.gn @@ -78,6 +78,7 @@ if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) { sources = [ "${appspawn_innerkits_path}/permission/appspawn_mount_permission.c", "appspawn_permission.c", + "sandbox_shared_mount.cpp", "sandbox_utils.cpp", ] diff --git a/modules/sandbox/appspawn_mount_template.c b/modules/sandbox/appspawn_mount_template.c index eb889e5f..49c6f2b9 100644 --- a/modules/sandbox/appspawn_mount_template.c +++ b/modules/sandbox/appspawn_mount_template.c @@ -160,7 +160,7 @@ static void DumpMode(const char *info, mode_t mode) APPSPAWN_CHECK_ONLY_EXPER(info != NULL, return); char buffer[64] = {0}; // 64 to show flags DumpSandboxFlags(buffer, sizeof(buffer), mode, PATH_MODE_MAP, ARRAY_LENGTH(PATH_MODE_MAP)); - APPSPAPWN_DUMP("%{public}s[0x%{public}x] %{public}s", info, (uint32_t)(mode), buffer); + APPSPAWN_DUMP("%{public}s[0x%{public}x] %{public}s", info, (uint32_t)(mode), buffer); } static void DumpMountFlags(const char *info, unsigned long mountFlags) @@ -168,7 +168,7 @@ static void DumpMountFlags(const char *info, unsigned long mountFlags) APPSPAWN_CHECK_ONLY_EXPER(info != NULL, return); char buffer[128] = {0}; // 64 to show flags DumpSandboxFlags(buffer, sizeof(buffer), mountFlags, MOUNT_FLAGS_MAP, ARRAY_LENGTH(MOUNT_FLAGS_MAP)); - APPSPAPWN_DUMP("%{public}s[0x%{public}x] %{public}s", info, (uint32_t)(mountFlags), buffer); + APPSPAWN_DUMP("%{public}s[0x%{public}x] %{public}s", info, (uint32_t)(mountFlags), buffer); } void DumpMountPathMountNode(const PathMountNode *pathNode) @@ -177,13 +177,13 @@ void DumpMountPathMountNode(const PathMountNode *pathNode) if (tmp == NULL) { return; } - APPSPAPWN_DUMP(" sandbox node category: %{public}u(%{public}s)", tmp->category, tmp->name); + APPSPAWN_DUMP(" sandbox node category: %{public}u(%{public}s)", tmp->category, tmp->name); DumpMountFlags(" sandbox node mountFlags: ", tmp->mountFlags); - APPSPAPWN_DUMP(" sandbox node mountSharedFlag: %{public}s", + APPSPAWN_DUMP(" sandbox node mountSharedFlag: %{public}s", tmp->mountSharedFlag == MS_SLAVE ? "MS_SLAVE" : "MS_SHARED"); - APPSPAPWN_DUMP(" sandbox node options: %{public}s", tmp->options ? tmp->options : "null"); - APPSPAPWN_DUMP(" sandbox node fsType: %{public}s", tmp->fsType ? tmp->fsType : "null"); + APPSPAWN_DUMP(" sandbox node options: %{public}s", tmp->options ? tmp->options : "null"); + APPSPAWN_DUMP(" sandbox node fsType: %{public}s", tmp->fsType ? tmp->fsType : "null"); DumpMode(" sandbox node destMode: ", pathNode->destMode); - APPSPAPWN_DUMP(" sandbox node config mountSharedFlag: %{public}s", + APPSPAWN_DUMP(" sandbox node config mountSharedFlag: %{public}s", pathNode->mountSharedFlag ? "MS_SHARED" : "MS_SLAVE"); } \ No newline at end of file diff --git a/modules/sandbox/sandbox_manager.c b/modules/sandbox/sandbox_manager.c index bf2f2970..80e0fd1f 100644 --- a/modules/sandbox/sandbox_manager.c +++ b/modules/sandbox/sandbox_manager.c @@ -165,24 +165,24 @@ void DumpSandboxMountNode(const SandboxMountNode *sandboxNode, uint32_t index) case SANDBOX_TAG_MOUNT_PATH: case SANDBOX_TAG_MOUNT_FILE: { PathMountNode *pathNode = (PathMountNode *)sandboxNode; - APPSPAPWN_DUMP(" ****************************** %{public}u", index); - APPSPAPWN_DUMP(" sandbox node source: %{public}s", pathNode->source ? pathNode->source : "null"); - APPSPAPWN_DUMP(" sandbox node target: %{public}s", pathNode->target ? pathNode->target : "null"); + APPSPAWN_DUMP(" ****************************** %{public}u", index); + APPSPAWN_DUMP(" sandbox node source: %{public}s", pathNode->source ? pathNode->source : "null"); + APPSPAWN_DUMP(" sandbox node target: %{public}s", pathNode->target ? pathNode->target : "null"); DumpMountPathMountNode(pathNode); - APPSPAPWN_DUMP(" sandbox node apl: %{public}s", + APPSPAWN_DUMP(" sandbox node apl: %{public}s", pathNode->appAplName ? pathNode->appAplName : "null"); - APPSPAPWN_DUMP(" sandbox node checkErrorFlag: %{public}s", + APPSPAWN_DUMP(" sandbox node checkErrorFlag: %{public}s", pathNode->checkErrorFlag ? "true" : "false"); break; } case SANDBOX_TAG_SYMLINK: { SymbolLinkNode *linkNode = (SymbolLinkNode *)sandboxNode; - APPSPAPWN_DUMP(" ***********************************"); - APPSPAPWN_DUMP(" sandbox node target: %{public}s", linkNode->target ? linkNode->target : "null"); - APPSPAPWN_DUMP(" sandbox node linkName: %{public}s", + APPSPAWN_DUMP(" ***********************************"); + APPSPAWN_DUMP(" sandbox node target: %{public}s", linkNode->target ? linkNode->target : "null"); + APPSPAWN_DUMP(" sandbox node linkName: %{public}s", linkNode->linkName ? linkNode->linkName : "null"); - APPSPAPWN_DUMP(" sandbox node destMode: %{public}x", linkNode->destMode); - APPSPAPWN_DUMP(" sandbox node checkErrorFlag: %{public}s", + APPSPAWN_DUMP(" sandbox node destMode: %{public}x", linkNode->destMode); + APPSPAWN_DUMP(" sandbox node checkErrorFlag: %{public}s", linkNode->checkErrorFlag ? "true" : "false"); break; } @@ -255,20 +255,20 @@ static void DumpSandboxQueue(const ListNode *front, static void DumpSandboxSection(const SandboxSection *section) { - APPSPAPWN_DUMP(" sandboxSwitch %{public}s", section->sandboxSwitch ? "true" : "false"); - APPSPAPWN_DUMP(" sandboxShared %{public}s", section->sandboxShared ? "true" : "false"); - APPSPAPWN_DUMP(" gidCount: %{public}u", section->gidCount); + APPSPAWN_DUMP(" sandboxSwitch %{public}s", section->sandboxSwitch ? "true" : "false"); + APPSPAWN_DUMP(" sandboxShared %{public}s", section->sandboxShared ? "true" : "false"); + APPSPAWN_DUMP(" gidCount: %{public}u", section->gidCount); for (uint32_t index = 0; index < section->gidCount; index++) { - APPSPAPWN_DUMP(" gidTable[%{public}u]: %{public}u", index, section->gidTable[index]); + APPSPAWN_DUMP(" gidTable[%{public}u]: %{public}u", index, section->gidTable[index]); } - APPSPAPWN_DUMP(" mount group count: %{public}u", section->number); + APPSPAWN_DUMP(" mount group count: %{public}u", section->number); for (uint32_t i = 0; i < section->number; i++) { if (section->nameGroups[i]) { SandboxNameGroupNode *groupNode = (SandboxNameGroupNode *)section->nameGroups[i]; - APPSPAPWN_DUMP(" name[%{public}d] %{public}s", i, groupNode->section.name); + APPSPAWN_DUMP(" name[%{public}d] %{public}s", i, groupNode->section.name); } } - APPSPAPWN_DUMP(" mount-paths: "); + APPSPAWN_DUMP(" mount-paths: "); DumpSandboxQueue(§ion->front, DumpSandboxMountNode); } @@ -385,29 +385,29 @@ void DeleteAppSpawnSandbox(AppSpawnSandboxCfg *sandbox) static void DumpSandboxPermission(const SandboxMountNode *node, uint32_t index) { SandboxPermissionNode *permissionNode = (SandboxPermissionNode *)node; - APPSPAPWN_DUMP(" ========================================= "); - APPSPAPWN_DUMP(" Section %{public}s", permissionNode->section.name); - APPSPAPWN_DUMP(" Section permission index %{public}d", permissionNode->permissionIndex); + APPSPAWN_DUMP(" ========================================= "); + APPSPAWN_DUMP(" Section %{public}s", permissionNode->section.name); + APPSPAWN_DUMP(" Section permission index %{public}d", permissionNode->permissionIndex); DumpSandboxSection(&permissionNode->section); } static void DumpSandboxSectionNode(const SandboxMountNode *node, uint32_t index) { SandboxSection *section = (SandboxSection *)node; - APPSPAPWN_DUMP(" ========================================= "); - APPSPAPWN_DUMP(" Section %{public}s", section->name); + APPSPAWN_DUMP(" ========================================= "); + APPSPAWN_DUMP(" Section %{public}s", section->name); DumpSandboxSection(section); } static void DumpSandboxNameGroupNode(const SandboxMountNode *node, uint32_t index) { SandboxNameGroupNode *nameGroupNode = (SandboxNameGroupNode *)node; - APPSPAPWN_DUMP(" ========================================= "); - APPSPAPWN_DUMP(" Section %{public}s", nameGroupNode->section.name); - APPSPAPWN_DUMP(" Section dep mode %{public}s", + APPSPAWN_DUMP(" ========================================= "); + APPSPAWN_DUMP(" Section %{public}s", nameGroupNode->section.name); + APPSPAWN_DUMP(" Section dep mode %{public}s", nameGroupNode->depMode == MOUNT_MODE_ALWAYS ? "always" : "not-exists"); if (nameGroupNode->depNode != NULL) { - APPSPAPWN_DUMP(" mount-paths-deps: "); + APPSPAWN_DUMP(" mount-paths-deps: "); DumpMountPathMountNode(nameGroupNode->depNode); } DumpSandboxSection(&nameGroupNode->section); @@ -469,12 +469,12 @@ AppSpawnSandboxCfg *CreateAppSpawnSandbox(ExtDataType type) void DumpAppSpawnSandboxCfg(AppSpawnSandboxCfg *sandbox) { APPSPAWN_CHECK_ONLY_EXPER(sandbox != NULL, return); - APPSPAPWN_DUMP("Sandbox root path: %{public}s", sandbox->rootPath); - APPSPAPWN_DUMP("Sandbox sandboxNsFlags: %{public}x ", sandbox->sandboxNsFlags); - APPSPAPWN_DUMP("Sandbox topSandboxSwitch: %{public}s", sandbox->topSandboxSwitch ? "true" : "false"); - APPSPAPWN_DUMP("Sandbox appFullMountEnable: %{public}s", sandbox->appFullMountEnable ? "true" : "false"); - APPSPAPWN_DUMP("Sandbox pidNamespaceSupport: %{public}s", sandbox->pidNamespaceSupport ? "true" : "false"); - APPSPAPWN_DUMP("Sandbox common info: "); + APPSPAWN_DUMP("Sandbox root path: %{public}s", sandbox->rootPath); + APPSPAWN_DUMP("Sandbox sandboxNsFlags: %{public}x ", sandbox->sandboxNsFlags); + APPSPAWN_DUMP("Sandbox topSandboxSwitch: %{public}s", sandbox->topSandboxSwitch ? "true" : "false"); + APPSPAWN_DUMP("Sandbox appFullMountEnable: %{public}s", sandbox->appFullMountEnable ? "true" : "false"); + APPSPAWN_DUMP("Sandbox pidNamespaceSupport: %{public}s", sandbox->pidNamespaceSupport ? "true" : "false"); + APPSPAWN_DUMP("Sandbox common info: "); DumpSandboxQueue(&sandbox->requiredQueue.front, DumpSandboxSectionNode); DumpSandboxQueue(&sandbox->packageNameQueue.front, DumpSandboxSectionNode); DumpSandboxQueue(&sandbox->permissionQueue.front, DumpSandboxPermission); diff --git a/modules/sandbox/sandbox_shared_mount.cpp b/modules/sandbox/sandbox_shared_mount.cpp new file mode 100644 index 00000000..f5e3bd85 --- /dev/null +++ b/modules/sandbox/sandbox_shared_mount.cpp @@ -0,0 +1,463 @@ +/* + * 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 +#include +#include +#include +#include +#include "securec.h" +#include "nlohmann/json.hpp" + +#include "sandbox_shared_mount.h" +#include "appspawn_mount_permission.h" +#include "appspawn_utils.h" +#include "parameter.h" + +#define USER_ID_SIZE 16 +#define DIR_MODE 0711 +#define LOCK_STATUS_SIZE 16 + +#define DATA_GROUP_SOCKET_TYPE "DataGroup" +#define GROUPLIST_KEY_DATAGROUPID "dataGroupId" +#define GROUPLIST_KEY_GID "gid" +#define GROUPLIST_KEY_DIR "dir" +#define GROUPLIST_KEY_UUID "uuid" + +static const MountSharedTemplate MOUNT_SHARED_MAP[] = { + {"/data/storage/el2", nullptr}, + {"/data/storage/el3", nullptr}, + {"/data/storage/el4", nullptr}, + {"/data/storage/el5", "ohos.permission.PROTECT_SCREEN_LOCK_DATA"}, +}; + +static const DataGroupSandboxPathTemplate DATA_GROUP_SANDBOX_PATH_MAP[] = { + {"el2", EL2, "/data/storage/el2/group/", nullptr}, + {"el3", EL3, "/data/storage/el3/group/", nullptr}, + {"el4", EL4, "/data/storage/el4/group/", nullptr}, + {"el5", EL5, "/data/storage/el5/group/", "ohos.permission.PROTECT_SCREEN_LOCK_DATA"}, +}; + +static std::map g_mountInfoMap; + +int GetElxInfoFromDir(const char *path) +{ + int ret = ELX_MAX; + if (path == nullptr) { + return ret; + } + uint32_t count = ARRAY_LENGTH(DATA_GROUP_SANDBOX_PATH_MAP); + for (uint32_t i = 0; i < count; ++i) { + if (strstr(path, DATA_GROUP_SANDBOX_PATH_MAP[i].elxName) != nullptr) { + return DATA_GROUP_SANDBOX_PATH_MAP[i].category; + } + } + if (ret == 0) { + APPSPAWN_LOGE("Get elx info from dir failed, path %{public}s", path); + } + return ret; +} + +const DataGroupSandboxPathTemplate *GetDataGroupArgTemplate(uint32_t category) +{ + uint32_t count = ARRAY_LENGTH(DATA_GROUP_SANDBOX_PATH_MAP); + if (category > count) { + APPSPAWN_LOGE("category %{public}d is out of range", category); + return nullptr; + } + for (uint32_t i = 0; i < count; ++i) { + if (DATA_GROUP_SANDBOX_PATH_MAP[i].category == category) { + return &DATA_GROUP_SANDBOX_PATH_MAP[i]; + } + } + return nullptr; +} + +bool IsValidDataGroupItem(nlohmann::json &item) +{ + // Check if the item contains the specified key and if the value corresponding to the key is a string + if (item.contains(GROUPLIST_KEY_DATAGROUPID) && item[GROUPLIST_KEY_DATAGROUPID].is_string() && + item.contains(GROUPLIST_KEY_GID) && item[GROUPLIST_KEY_GID].is_string() && + item.contains(GROUPLIST_KEY_DIR) && item[GROUPLIST_KEY_DIR].is_string() && + item.contains(GROUPLIST_KEY_UUID) && item[GROUPLIST_KEY_UUID].is_string()) { + return true; + } + return false; +} + +void *GetEl1BundleMountCount(void) +{ + return static_cast(&g_mountInfoMap); +} + +#ifndef APPSPAWN_SANDBOX_NEW +static bool IsUnlockStatus(uint32_t uid) +{ + const int userIdBase = UID_BASE; + uid = uid / userIdBase; + if (uid == 0) { + return true; + } + std::string lockStatusParam = "startup.appspawn.lockstatus_" + std::to_string(uid); + char userLockStatus[LOCK_STATUS_SIZE] = {0}; + int ret = GetParameter(lockStatusParam.c_str(), "1", userLockStatus, sizeof(userLockStatus)); + APPSPAWN_LOGI("get param %{public}s %{public}s", lockStatusParam.c_str(), userLockStatus); + if (ret > 0 && (strcmp(userLockStatus, "0") == 0)) { // 0:unlock status 1:lock status + return true; + } + return false; +} + +static int DoSharedMount(const SharedMountArgs *arg) +{ + if (arg == nullptr || arg->srcPath == nullptr || arg->destPath == nullptr) { + APPSPAWN_LOGE("Invalid arg"); + return APPSPAWN_ARG_INVALID; + } + + APPSPAWN_LOGV("Mount arg: '%{public}s' '%{public}s' %{public}lu '%{public}s' %{public}s => %{public}s", + arg->fsType, arg->mountSharedFlag == MS_SHARED ? "MS_SHARED" : "MS_SLAVE", + arg->mountFlags, arg->options, arg->srcPath, arg->destPath); + + int ret = mount(arg->srcPath, arg->destPath, arg->fsType, arg->mountFlags, arg->options); + if (ret != 0) { + APPSPAWN_LOGE("mount %{public}s to %{public}s failed, errno %{public}d", + arg->srcPath, arg->destPath, errno); + return ret; + } + ret = mount(nullptr, arg->destPath, nullptr, arg->mountSharedFlag, nullptr); + if (ret != 0) { + APPSPAWN_LOGE("mount path %{public}s to shared failed, errno %{public}d", arg->destPath, errno); + return ret; + } + APPSPAWN_LOGI("mount path %{public}s to shared success", arg->destPath); + return 0; +} + +static void GetMountInfo(std::vector &sharedMounts, AppDacInfo *info, const std::string &bundleName) +{ + APPSPAWN_LOGI("Get mountinfo %{public}s start", bundleName.c_str()); + std::ifstream file("/proc/self/mountinfo"); + if (!file.is_open()) { + APPSPAWN_LOGE("Failed to open mountinfo, errno: %{public}d", errno); + return; + } + + std::string line; + while (std::getline(file, line)) { + if ((line.find(info->uid / UID_BASE) != std::string::npos) && (line.find(bundleName) != std::string::npos) && + (line.find("shared:") != std::string::npos)) { + sharedMounts.push_back(line); + } + } + file.close(); + APPSPAWN_LOGW("Get mountinfo %{public}s end", bundleName.c_str()); +} + +static bool IsSandboxPathShared(const std::vector &sharedMounts, const std::string &sandboxPath) +{ + std::regex mountPoint(sandboxPath); + for (const auto &sharedMount : sharedMounts) { + if (std::regex_search(sharedMount, mountPoint)) { + return true; + } + } + return false; +} + +static int MountEl1Bundle(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName) +{ + /* /data/app/el1/bundle/public/ */ + char sourcePath[PATH_MAX_LEN] = {0}; + int ret = snprintf_s(sourcePath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/data/app/el1/bundle/public/%s", bundleName); + if (ret <= 0) { + APPSPAWN_LOGE("snprintf data/app/el1/bundle/public/%{public}s failed, errno %{public}d", bundleName, errno); + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + /* /mnt/sandbox///data/storage/el1/bundle */ + char targetPath[PATH_MAX_LEN] = {0}; + ret = snprintf_s(targetPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%d/%s/data/storage/el1/bundle", + info->uid/ UID_BASE, bundleName); + if (ret <= 0) { + APPSPAWN_LOGE("snprintf el1 bundle sandbox path failed, errno %{public}d", errno); + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + ret = MakeDirRec(targetPath, DIR_MODE, 1); + if (ret != 0) { + APPSPAWN_LOGE("mkdir %{public}s failed, errno %{public}d", targetPath, errno); + return APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL; + } + + ret = umount2(targetPath, MNT_DETACH); + if (ret < 0) { + APPSPAWN_LOGE("umount2 %{public}s failed, errno %{public}d", targetPath, errno); + } + + SharedMountArgs arg = { + .srcPath = sourcePath, + .destPath = targetPath, + .fsType = nullptr, + .mountFlags = MS_BIND | MS_REC, + .options = nullptr, + .mountSharedFlag = MS_SHARED + }; + ret = DoSharedMount(&arg); + if (ret != 0) { + APPSPAWN_LOGE("mount %{public}s shared failed, ret %{public}d", targetPath, ret); + } + std::string key = std::to_string(info->uid / UID_BASE) + "-" + std::string(bundleName); + g_mountInfoMap[key]++; + return ret; +} + +static int MountWithFileMgr(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName, + std::vector &sharedMounts) +{ + /* /mnt/user//nosharefs/docs */ + char nosharefsDocsDir[PATH_MAX_LEN] = {0}; + int ret = snprintf_s(nosharefsDocsDir, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/user/%u/nosharefs/docs", + info->uid / UID_BASE); + if (ret <= 0) { + APPSPAWN_LOGE("snprintf nosharefsDocsDir failed, errno %{public}d", errno); + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + /* /mnt/sandbox//storage/Users */ + char storageUserPath[PATH_MAX_LEN] = {0}; + ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%d/%s/storage/Users", + info->uid / UID_BASE, bundleName); + if (ret <= 0) { + APPSPAWN_LOGE("snprintf nosharefsDocsDir failed, errno %{public}d", errno); + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + // Check whether the directory is a shared mount point + if (IsSandboxPathShared(sharedMounts, storageUserPath)) { + APPSPAWN_LOGI("shared mountpoint is exist"); + return 0; + } + + ret = MakeDirRec(storageUserPath, DIR_MODE, 1); + if (ret != 0) { + APPSPAWN_LOGE("mkdir %{public}s failed, errno %{public}d", storageUserPath, errno); + return APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL; + } + + SharedMountArgs arg = { + .srcPath = nosharefsDocsDir, + .destPath = storageUserPath, + .fsType = nullptr, + .mountFlags = MS_BIND | MS_REC, + .options = nullptr, + .mountSharedFlag = MS_SHARED + }; + ret = DoSharedMount(&arg); + if (ret != 0) { + APPSPAWN_LOGE("mount %{public}s shared failed, ret %{public}d", storageUserPath, ret); + } + return ret; +} + +static int MountWithOther(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName, + std::vector &sharedMounts) +{ + /* /mnt/user//sharefs/docs */ + char sharefsDocsDir[PATH_MAX_LEN] = {0}; + int ret = snprintf_s(sharefsDocsDir, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/user/%u/sharefs/docs", + info->uid / UID_BASE); + if (ret <= 0) { + APPSPAWN_LOGE("snprintf sharefsDocsDir failed, errno %{public}d", errno); + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + /* /mnt/sandbox//storage/Users */ + char storageUserPath[PATH_MAX_LEN] = {0}; + ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%d/%s/storage/Users", + info->uid / UID_BASE, bundleName); + if (ret <= 0) { + APPSPAWN_LOGE("snprintf nosharefsDocsDir failed, errno %{public}d", errno); + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + // Check whether the directory is a shared mount point + if (IsSandboxPathShared(sharedMounts, storageUserPath)) { + APPSPAWN_LOGI("shared mountpoint is exist"); + return 0; + } + + ret = MakeDirRec(storageUserPath, DIR_MODE, 1); + if (ret != 0) { + APPSPAWN_LOGE("mkdir %{public}s failed, errno %{public}d", storageUserPath, errno); + return APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL; + } + + char options[PATH_MAX_LEN] = {0}; + ret = snprintf_s(options, PATH_MAX_LEN, PATH_MAX_LEN - 1, "override_support_delete,user_id=%u", + info->uid / UID_BASE); + if (ret <= 0) { + APPSPAWN_LOGE("snprintf options failed, errno %{public}d", errno); + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + SharedMountArgs arg = { + .srcPath = sharefsDocsDir, + .destPath = storageUserPath, + .fsType = "sharefs", + .mountFlags = MS_NODEV, + .options = options, + .mountSharedFlag = MS_SHARED + }; + ret = DoSharedMount(&arg); + if (ret != 0) { + APPSPAWN_LOGE("mount %{public}s shared failed, ret %{public}d", storageUserPath, ret); + } + return ret; +} + +static void MountStorageUsers(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName, + std::vector &sharedMounts) +{ + int ret = 0; + int index = GetPermissionIndex(nullptr, "ohos.permission.FILE_ACCESS_MANAGER"); + int checkRes = CheckAppPermissionFlagSet(property, static_cast(index)); + if (checkRes == 0) { + /* mount /mnt/user//sharefs/docs to /mnt/sandbox///storage/Users */ + ret = MountWithOther(property, info, bundleName, sharedMounts); + } else { + /* mount /mnt/user//nosharefs/docs to /mnt/sandbox///storage/Users */ + ret = MountWithFileMgr(property, info, bundleName, sharedMounts); + } + if (ret != 0) { + APPSPAWN_LOGE("Update %{public}s storage dir failed, ret %{public}d", + checkRes == 0 ? "sharefs dir" : "no sharefs dir", ret); + } else { + APPSPAWN_LOGI("Update %{public}s storage dir success", checkRes == 0 ? "sharefs dir" : "no sharefs dir"); + } +} + +static int MountSharedMapItem(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName, + const char *sandboxPathItem, std::vector &sharedMounts) +{ + /* /mnt/sandbox///data/storage/el */ + char sandboxPath[PATH_MAX_LEN] = {0}; + int ret = snprintf_s(sandboxPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%d/%s%s", + info->uid / UID_BASE, bundleName, sandboxPathItem); + if (ret <= 0) { + APPSPAWN_LOGE("snprintf sandboxPath failed, errno %{public}d", errno); + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + // Check whether the directory is a shared mount point + if (IsSandboxPathShared(sharedMounts, sandboxPath)) { + APPSPAWN_LOGI("shared mountpoint is exist"); + return 0; + } + + ret = MakeDirRec(sandboxPath, DIR_MODE, 1); + if (ret != 0) { + APPSPAWN_LOGE("mkdir %{public}s failed, errno %{public}d", sandboxPath, errno); + return APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL; + } + + SharedMountArgs arg = { + .srcPath = sandboxPath, + .destPath = sandboxPath, + .fsType = nullptr, + .mountFlags = MS_BIND | MS_REC, + .options = nullptr, + .mountSharedFlag = MS_SHARED + }; + ret = DoSharedMount(&arg); + if (ret != 0) { + APPSPAWN_LOGE("mount %{public}s shared failed, ret %{public}d", sandboxPath, ret); + } + return ret; +} + +static void MountSharedMap(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName, + std::vector &sharedMounts) +{ + int length = sizeof(MOUNT_SHARED_MAP) / sizeof(MOUNT_SHARED_MAP[0]); + for (int i = 0; i < length; i++) { + if (MOUNT_SHARED_MAP[i].permission == nullptr) { + MountSharedMapItem(property, info, bundleName, MOUNT_SHARED_MAP[i].sandboxPath, sharedMounts); + } else { + int index = GetPermissionIndex(nullptr, MOUNT_SHARED_MAP[i].permission); + APPSPAWN_LOGV("mount dir on lock mountPermissionFlags %{public}d", index); + if (CheckAppPermissionFlagSet(property, static_cast(index))) { + MountSharedMapItem(property, info, bundleName, MOUNT_SHARED_MAP[i].sandboxPath, sharedMounts); + } + } + } + APPSPAWN_LOGI("mount shared map success"); +} + +static void MountDirToShared(AppSpawnMgr *content, const AppSpawningCtx *property) +{ + if (property == nullptr) { + return; + } + + AppDacInfo *info = reinterpret_cast(GetAppProperty(property, TLV_DAC_INFO)); + AppSpawnMsgBundleInfo *bundleInfo = + reinterpret_cast(GetAppProperty(property, TLV_BUNDLE_INFO)); + if (info == NULL || bundleInfo == NULL) { + return; + } + + MountEl1Bundle(property, info, bundleInfo->bundleName); + + if (IsUnlockStatus(info->uid)) { + return; + } + + struct timespec checkStart = {0}; + clock_gettime(CLOCK_MONOTONIC, &checkStart); + + std::vector sharedMounts; + GetMountInfo(sharedMounts, info, std::string(bundleInfo->bundleName)); + MountSharedMap(property, info, bundleInfo->bundleName, sharedMounts); + MountStorageUsers(property, info, bundleInfo->bundleName, sharedMounts); + + struct timespec checkEnd = {0}; + clock_gettime(CLOCK_MONOTONIC, &checkEnd); + uint64_t diff = DiffTime(&checkStart, &checkEnd); + APPSPAWN_LOGI("Check %{public}s mount status use time %{public}" PRId64" us", bundleInfo->bundleName, diff); + + std::string lockSbxPathStamp = "/mnt/sandbox/" + std::to_string(info->uid / UID_BASE) + "/"; + lockSbxPathStamp += CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX_TYPE) ? "isolated/" : ""; + lockSbxPathStamp += bundleInfo->bundleName; + lockSbxPathStamp += "_locked"; + int ret = MakeDirRec(lockSbxPathStamp.c_str(), DIR_MODE, 1); + if (ret != 0) { + APPSPAWN_LOGE("mkdir %{public}s failed, errno %{public}d", lockSbxPathStamp.c_str(), errno); + } +} +#endif + +int MountToShared(AppSpawnMgr *content, const AppSpawningCtx *property) +{ +#ifndef APPSPAWN_SANDBOX_NEW + // mount dynamic directory to shared + MountDirToShared(content, property); +#endif + return 0; +} diff --git a/modules/sandbox/sandbox_shared_mount.h b/modules/sandbox/sandbox_shared_mount.h new file mode 100644 index 00000000..7bdd28de --- /dev/null +++ b/modules/sandbox/sandbox_shared_mount.h @@ -0,0 +1,67 @@ +/* + * 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 SANDBOX_SHARED_MOUNT_H +#define SANDBOX_SHARED_MOUNT_H + +#include "appspawn.h" +#include "appspawn_hook.h" +#include "appspawn_manager.h" +#include "appspawn_utils.h" +#include "list.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct MountSharedTemplate { + const char *sandboxPath; + const char *permission; +} MountSharedTemplate; + +enum { + EL2 = 0, + EL3, + EL4, + EL5, + ELX_MAX +}; + +typedef struct DataGroupSandboxPathTemplate { + const char *elxName; + uint32_t category; + const char *sandboxPath;; + const char *permission; +} DataGroupSandboxPathTemplate; + +typedef struct { + const char *srcPath; + const char *destPath; + const char *fsType; + unsigned long mountFlags; + const char *options; + mode_t mountSharedFlag; +} SharedMountArgs; + +bool IsValidDataGroupItem(nlohmann::json &item); +int GetElxInfoFromDir(const char *path); +const DataGroupSandboxPathTemplate *GetDataGroupArgTemplate(uint32_t category); +void *GetEl1BundleMountCount(void); +int MountToShared(AppSpawnMgr *content, const AppSpawningCtx *property); + +#ifdef __cplusplus +} +#endif +#endif // SANDBOX_SHARED_MOUNT_H diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 6d198746..00ecd090 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2024-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 @@ -35,6 +35,7 @@ #include "appspawn_service.h" #include "appspawn_utils.h" #include "config_policy_utils.h" +#include "sandbox_shared_mount.h" #ifdef WITH_DLP #include "dlp_fuse_fd.h" #endif @@ -61,8 +62,6 @@ using namespace std; using namespace OHOS; -static map g_mountInfo; - namespace OHOS { namespace AppSpawn { namespace { @@ -1893,7 +1892,8 @@ int32_t SetAppSandboxProperty(AppSpawnMgr *content, AppSpawningCtx *property) APPSPAWN_CHECK(property != nullptr, return -1, "Invalid appspwn client"); APPSPAWN_CHECK(content != nullptr, return -1, "Invalid appspwn content"); // clear g_mountInfo in the child process - g_mountInfo.clear(); + std::map* mapPtr = static_cast*>(GetEl1BundleMountCount()); + mapPtr->clear(); int ret = 0; // no sandbox if (CheckAppMsgFlagsSet(property, APP_FLAGS_NO_SANDBOX)) { @@ -1929,274 +1929,12 @@ int32_t SetAppSandboxProperty(AppSpawnMgr *content, AppSpawningCtx *property) #define USER_ID_SIZE 16 #define DIR_MODE 0711 -#ifndef APPSPAWN_SANDBOX_NEW -static bool IsUnlockStatus(uint32_t uid) -{ - const int userIdBase = 200000; - uid = uid / userIdBase; - if (uid == 0) { - return true; - } - string lockStatusParam = "startup.appspawn.lockstatus_" + to_string(uid); - char userLockStatus[LOCK_STATUS_SIZE] = {0}; - int ret = GetParameter(lockStatusParam.c_str(), "1", userLockStatus, sizeof(userLockStatus)); - APPSPAWN_LOGI("get param %{public}s %{public}s %{public}d", lockStatusParam.c_str(), userLockStatus, ret); - if (ret > 0 && (strcmp(userLockStatus, "0") == 0)) { // 0:unlock 1:lock - return true; - } - return false; -} - -static string GetMountInfoKey(uint32_t userId, const char *bundleName) -{ - return std::to_string(userId) + "-" + std::string(bundleName); -} - -static void MountDir(const AppSpawningCtx *property, const char *rootPath, const char *srcPath, const char *targetPath) -{ - const int userIdBase = 200000; - AppDacInfo *info = reinterpret_cast(GetAppProperty(property, TLV_DAC_INFO)); - const char *bundleName = GetBundleName(property); - if (info == NULL || bundleName == NULL) { - return; - } - - size_t allPathSize = strlen(rootPath) + strlen(targetPath) + strlen(bundleName) + 2; - allPathSize += USER_ID_SIZE; - char *path = reinterpret_cast(malloc(sizeof(char) * (allPathSize))); - APPSPAWN_CHECK(path != NULL, return, "Failed to malloc path"); - int len = sprintf_s(path, allPathSize, "%s%u/%s%s", rootPath, info->uid / userIdBase, bundleName, targetPath); - APPSPAWN_CHECK(len > 0 && ((size_t)len < allPathSize), free(path); - return, "Failed to get sandbox path"); - if (srcPath != nullptr) { - string key = GetMountInfoKey(info->uid / userIdBase, bundleName); - g_mountInfo[key]++; - } - - if (access(path, F_OK) == 0 && srcPath == nullptr) { - free(path); - return; - } - - MakeDirRec(path, DIR_MODE, 1); - const char *sourcePath = (srcPath == nullptr) ? path : srcPath; - if (srcPath != nullptr) { - int ret = umount2(path, MNT_DETACH); - APPSPAWN_CHECK_ONLY_LOG(ret == 0, "Failed to umount path %{public}s, errno %{public}d", path, errno); - } - - if (mount(sourcePath, path, nullptr, MS_BIND | MS_REC, nullptr) != 0) { - APPSPAWN_LOGI("bind mount %{public}s to %{public}s failed, error %{public}d", sourcePath, path, errno); - free(path); - return; - } - if (mount(nullptr, path, nullptr, MS_SHARED, nullptr) != 0) { - APPSPAWN_LOGI("mount path %{public}s to shared failed, errno %{public}d", path, errno); - free(path); - return; - } - APPSPAWN_LOGI("mount path %{public}s to shared success", path); - free(path); - return; -} - -static const MountSharedTemplate MOUNT_SHARED_MAP[] = { - {"/data/storage/el2", nullptr}, - {"/data/storage/el3", nullptr}, - {"/data/storage/el4", nullptr}, - {"/data/storage/el5", "ohos.permission.PROTECT_SCREEN_LOCK_DATA"}, -}; - -#define PATH_MAX_LEN 256 -static int MountInShared(const AppSpawningCtx *property, const char *rootPath, const char *src, const char *target) -{ - AppDacInfo *info = reinterpret_cast(GetAppProperty(property, TLV_DAC_INFO)); - const char *bundleName = GetBundleName(property); - if (info == NULL || bundleName == NULL) { - return APPSPAWN_ARG_INVALID; - } - - char path[PATH_MAX_LEN] = {0}; - int ret = snprintf_s(path, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%u/%s/%s", rootPath, info->uid / UID_BASE, - bundleName, target); - if (ret <= 0) { - APPSPAWN_LOGE("snprintf_s path failed, errno %{public}d", errno); - return APPSPAWN_ERROR_UTILS_MEM_FAIL; - } - - char currentUserPath[PATH_MAX_LEN] = {0}; - ret = snprintf_s(currentUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/currentUser", path); - if (ret <= 0) { - APPSPAWN_LOGE("snprintf_s currentUserPath failed, errno %{public}d", errno); - return APPSPAWN_ERROR_UTILS_MEM_FAIL; - } - - if (access(currentUserPath, F_OK) == 0) { - return 0; - } - - ret = MakeDirRec(path, DIR_MODE, 1); - if (ret != 0) { - return APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL; - } - - if (mount(src, path, nullptr, MS_BIND | MS_REC, nullptr) != 0) { - APPSPAWN_LOGI("bind mount %{public}s to %{public}s failed, error %{public}d", src, path, errno); - return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; - } - if (mount(nullptr, path, nullptr, MS_SHARED, nullptr) != 0) { - APPSPAWN_LOGI("mount path %{public}s to shared failed, errno %{public}d", path, errno); - return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; - } - - return 0; -} - -static int SharedMountInSharefs(const AppSpawningCtx *property, const char *rootPath, - const char *src, const char *target) -{ - AppDacInfo *info = reinterpret_cast(GetAppProperty(property, TLV_DAC_INFO)); - if (info == NULL) { - return APPSPAWN_ARG_INVALID; - } - - char currentUserPath[PATH_MAX_LEN] = {0}; - int ret = snprintf_s(currentUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/currentUser", target); - if (ret <= 0) { - APPSPAWN_LOGE("snprintf_s currentUserPath failed, errno %{public}d", errno); - return APPSPAWN_ERROR_UTILS_MEM_FAIL; - } - - if (access(currentUserPath, F_OK) == 0) { - return 0; - } - - ret = MakeDirRec(target, DIR_MODE, 1); - if (ret != 0) { - return APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL; - } - - char options[PATH_MAX_LEN] = {0}; - ret = snprintf_s(options, PATH_MAX_LEN, PATH_MAX_LEN - 1, "override_support_delete,user_id=%u", - info->uid / UID_BASE); - if (ret <= 0) { - APPSPAWN_LOGE("snprintf_s options failed, errno %{public}d", errno); - return APPSPAWN_ERROR_UTILS_MEM_FAIL; - } - - if (mount(src, target, "sharefs", MS_NODEV, options) != 0) { - APPSPAWN_LOGE("sharefs mount %{public}s to %{public}s failed, error %{public}d", - src, target, errno); - return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; - } - if (mount(nullptr, target, nullptr, MS_SHARED, nullptr) != 0) { - APPSPAWN_LOGE("mount path %{public}s to shared failed, errno %{public}d", target, errno); - return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; - } - - return 0; -} - -static void UpdateStorageDir(const AppSpawningCtx *property) -{ - const char mntUser[] = "/mnt/user"; - const char nosharefsDocs[] = "nosharefs/docs"; - const char sharefsDocs[] = "sharefs/docs"; - const char rootPath[] = "/mnt/sandbox"; - const char userPath[] = "/storage/Users"; - - AppDacInfo *info = reinterpret_cast(GetAppProperty(property, TLV_DAC_INFO)); - if (info == nullptr) { - return; - } - - /* /mnt/user//nosharefs/Docs */ - char nosharefsDocsDir[PATH_MAX_LEN] = {0}; - int ret = snprintf_s(nosharefsDocsDir, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%u/%s", - mntUser, info->uid / UID_BASE, nosharefsDocs); - if (ret <= 0) { - APPSPAWN_LOGE("snprintf_s nosharefsDocsDir failed, errno %{public}d", errno); - return; - } - - /* /mnt/user//sharefs/Docs */ - char sharefsDocsDir[PATH_MAX_LEN] = {0}; - ret = snprintf_s(sharefsDocsDir, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%u/%s", - mntUser, info->uid / UID_BASE, sharefsDocs); - if (ret <= 0) { - APPSPAWN_LOGE("snprintf_s sharefsDocsDir failed, errno %{public}d", errno); - return; - } - - int index = GetPermissionIndex(nullptr, "ohos.permission.FILE_ACCESS_MANAGER"); - int res = CheckAppPermissionFlagSet(property, static_cast(index)); - if (res == 0) { - char storageUserPath[PATH_MAX_LEN] = {0}; - const char *bundleName = GetBundleName(property); - ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%u/%s/%s", rootPath, info->uid / UID_BASE, - bundleName, userPath); - if (ret <= 0) { - APPSPAWN_LOGE("snprintf_s storageUserPath failed, errno %{public}d", errno); - return; - } - /* mount /mnt/user//sharefs/docs to /mnt/sandbox///storage/Users */ - ret = SharedMountInSharefs(property, rootPath, sharefsDocsDir, storageUserPath); - } else { - /* mount /mnt/user//nosharefs/docs to /mnt/sandbox///storage/Users */ - ret = MountInShared(property, rootPath, nosharefsDocsDir, userPath); - } - if (ret != 0) { - APPSPAWN_LOGE("Update storage dir, ret %{public}d", ret); - } - APPSPAWN_LOGI("Update %{public}s storage dir success", res == 0 ? "sharefs dir" : "no sharefs dir"); -} - -static void MountDirToShared(const AppSpawningCtx *property) -{ - const char rootPath[] = "/mnt/sandbox/"; - const char el1Path[] = "/data/storage/el1/bundle"; - const char lockSuffix[] = "_locked"; - AppDacInfo *info = reinterpret_cast(GetAppProperty(property, TLV_DAC_INFO)); - const char *bundleName = GetBundleName(property); - if (info == NULL || bundleName == NULL) { - return; - } - - string sourcePath = "/data/app/el1/bundle/public/" + string(bundleName); - MountDir(property, rootPath, sourcePath.c_str(), el1Path); - if (IsUnlockStatus(info->uid)) { - return; - } - - UpdateStorageDir(property); - - int length = sizeof(MOUNT_SHARED_MAP) / sizeof(MOUNT_SHARED_MAP[0]); - for (int i = 0; i < length; i++) { - if (MOUNT_SHARED_MAP[i].permission == nullptr) { - MountDir(property, rootPath, nullptr, MOUNT_SHARED_MAP[i].sandboxPath); - } else { - int index = GetPermissionIndex(nullptr, MOUNT_SHARED_MAP[i].permission); - APPSPAWN_LOGV("mount dir on lock mountPermissionFlags %{public}d", index); - if (CheckAppPermissionFlagSet(property, static_cast(index))) { - MountDir(property, rootPath, nullptr, MOUNT_SHARED_MAP[i].sandboxPath); - } - } - } - - std::string lockSbxPathStamp = rootPath + to_string(info->uid / UID_BASE) + "/"; - lockSbxPathStamp += CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX_TYPE) ? "isolated/" : ""; - lockSbxPathStamp += bundleName; - lockSbxPathStamp += lockSuffix; - OHOS::AppSpawn::MakeDirRecursive(lockSbxPathStamp.c_str(), OHOS::AppSpawn::FILE_MODE); -} -#endif - static int SpawnMountDirToShared(AppSpawnMgr *content, AppSpawningCtx *property) { #ifndef APPSPAWN_SANDBOX_NEW if (!IsNWebSpawnMode(content)) { // mount dynamic directory - MountDirToShared(property); + MountToShared(content, property); } #endif return 0; @@ -2234,18 +1972,19 @@ static int UmountSandboxPath(const AppSpawnMgr *content, const AppSpawnedProcess const char el1Path[] = "/data/storage/el1/bundle"; uint32_t userId = appInfo->uid / UID_BASE; - string key = GetMountInfoKey(userId, appInfo->name); - if (g_mountInfo.find(key) == g_mountInfo.end()) { + std::string key = std::to_string(userId) + "-" + std::string(appInfo->name); + map *el1BundleCountMap = static_cast*>(GetEl1BundleMountCount()); + if (el1BundleCountMap->find(key) == el1BundleCountMap->end()) { return 0; } - g_mountInfo[key]--; - if (g_mountInfo[key] == 0) { + (*el1BundleCountMap)[key]--; + if ((*el1BundleCountMap)[key] == 0) { APPSPAWN_LOGV("no app %{public}s use it in userId %{public}u, need umount", appInfo->name, userId); UmountDir(rootPath, el1Path, appInfo); - g_mountInfo.erase(key); + el1BundleCountMap->erase(key); } else { APPSPAWN_LOGV("app %{public}s use it mount times %{public}d in userId %{public}u, not need umount", - appInfo->name, g_mountInfo[key], userId); + appInfo->name, (*el1BundleCountMap)[key], userId); } return 0; } diff --git a/modules/sandbox/sandbox_utils.h b/modules/sandbox/sandbox_utils.h index 442eba7a..1ad93280 100755 --- a/modules/sandbox/sandbox_utils.h +++ b/modules/sandbox/sandbox_utils.h @@ -137,9 +137,4 @@ public: int LoadAppSandboxConfig(AppSpawnMgr *content); -typedef struct { - const char *sandboxPath; - const char *permission; -} MountSharedTemplate; - #endif // SANDBOX_UTILS_H diff --git a/standard/appspawn_appmgr.c b/standard/appspawn_appmgr.c index f8703828..7866bac8 100644 --- a/standard/appspawn_appmgr.c +++ b/standard/appspawn_appmgr.c @@ -61,6 +61,9 @@ AppSpawnMgr *CreateAppSpawnMgr(int mode) OH_ListInit(&appMgr->appQueue); OH_ListInit(&appMgr->diedQueue); OH_ListInit(&appMgr->appSpawnQueue); +#ifndef APPSPAWN_SANDBOX_NEW + OH_ListInit(&appMgr->dataGroupCtxQueue); +#endif appMgr->diedAppCount = 0; OH_ListInit(&appMgr->extData); g_appSpawnMgr = appMgr; @@ -101,6 +104,9 @@ void DeleteAppSpawnMgr(AppSpawnMgr *mgr) OH_ListRemoveAll(&mgr->diedQueue, NULL); OH_ListRemoveAll(&mgr->appSpawnQueue, SpawningQueueDestroy); OH_ListRemoveAll(&mgr->extData, ExtDataDestroy); +#ifndef APPSPAWN_SANDBOX_NEW + OH_ListRemoveAll(&mgr->dataGroupCtxQueue, NULL); +#endif #ifdef APPSPAWN_HISYSEVENT DeleteHisyseventInfo(mgr->hisyseventInfo); #endif @@ -372,9 +378,9 @@ void AppSpawningCtxTraversal(ProcessTraversal traversal, void *data) static int DumpAppSpawnQueue(ListNode *node, void *data) { AppSpawningCtx *property = ListEntry(node, AppSpawningCtx, node); - APPSPAPWN_DUMP("app property id: %{public}u flags: %{public}x", + APPSPAWN_DUMP("app property id: %{public}u flags: %{public}x", property->client.id, property->client.flags); - APPSPAPWN_DUMP("app property state: %{public}d", property->state); + APPSPAWN_DUMP("app property state: %{public}d", property->state); DumpAppSpawnMsg(property->message); return 0; @@ -384,8 +390,8 @@ static int DumpAppQueue(ListNode *node, void *data) { AppSpawnedProcess *appInfo = ListEntry(node, AppSpawnedProcess, node); uint64_t diff = DiffTime(&appInfo->spawnStart, &appInfo->spawnEnd); - APPSPAPWN_DUMP("App info uid: %{public}u pid: %{public}x", appInfo->uid, appInfo->pid); - APPSPAPWN_DUMP("App info name: %{public}s exitStatus: 0x%{public}x spawn time: %{public}" PRIu64 " us ", + APPSPAWN_DUMP("App info uid: %{public}u pid: %{public}x", appInfo->uid, appInfo->pid); + APPSPAWN_DUMP("App info name: %{public}s exitStatus: 0x%{public}x spawn time: %{public}" PRIu64 " us ", appInfo->name, appInfo->exitStatus, diff); return 0; } @@ -417,16 +423,16 @@ void ProcessAppSpawnDumpMsg(const AppSpawnMsgNode *message) } else { SetDumpToStream(stdout); } - APPSPAPWN_DUMP("Dump appspawn info start ... "); - APPSPAPWN_DUMP("APP spawning queue: "); + APPSPAWN_DUMP("Dump appspawn info start ... "); + APPSPAWN_DUMP("APP spawning queue: "); OH_ListTraversal((ListNode *)&g_appSpawnMgr->appSpawnQueue, NULL, DumpAppSpawnQueue, 0); - APPSPAPWN_DUMP("APP queue: "); + APPSPAWN_DUMP("APP queue: "); OH_ListTraversal((ListNode *)&g_appSpawnMgr->appQueue, "App queue", DumpAppQueue, 0); - APPSPAPWN_DUMP("APP died queue: "); + APPSPAWN_DUMP("APP died queue: "); OH_ListTraversal((ListNode *)&g_appSpawnMgr->diedQueue, "App died queue", DumpAppQueue, 0); - APPSPAPWN_DUMP("Ext data: "); + APPSPAWN_DUMP("Ext data: "); OH_ListTraversal((ListNode *)&g_appSpawnMgr->extData, "Ext data", DumpExtData, 0); - APPSPAPWN_DUMP("Dump appspawn info finish "); + APPSPAWN_DUMP("Dump appspawn info finish "); if (stream != NULL) { (void)fflush(stream); fclose(stream); diff --git a/standard/appspawn_manager.h b/standard/appspawn_manager.h index 5c5280ac..2cca34d8 100644 --- a/standard/appspawn_manager.h +++ b/standard/appspawn_manager.h @@ -53,6 +53,8 @@ extern "C" { #define APP_STATE_IDLE 1 #define APP_STATE_SPAWNING 2 #define APPSPAWN_MAX_TIME 3000000 +#define UUID_MAX_LEN 37 +#define PATH_MAX_LEN 256 #define APPSPAWN_INLINE __attribute__((always_inline)) inline @@ -109,6 +111,21 @@ typedef struct SpawnTime { int maxAppspawnTime; } SpawnTime; +#ifndef APPSPAWN_SANDBOX_NEW +typedef struct TagPathBuffer { + uint32_t pathLen; + char path[PATH_MAX_LEN]; +} PathBuffer; + +typedef struct TagDataGroupCtx { + struct ListNode node; + int gid; + char dataGroupUuid[UUID_MAX_LEN]; + PathBuffer srcPath; + PathBuffer destPath; +} DataGroupCtx; +#endif + typedef struct TagAppSpawnMgr { AppSpawnContent content; TaskHandle server; @@ -123,6 +140,9 @@ typedef struct TagAppSpawnMgr { struct timespec perLoadEnd; struct ListNode extData; struct SpawnTime spawnTime; +#ifndef APPSPAWN_SANDBOX_NEW + struct ListNode dataGroupCtxQueue; +#endif #ifdef APPSPAWN_HISYSEVENT AppSpawnHisyseventInfo *hisyseventInfo; #endif diff --git a/standard/appspawn_msgmgr.c b/standard/appspawn_msgmgr.c index 27bc031e..b7b7b903 100644 --- a/standard/appspawn_msgmgr.c +++ b/standard/appspawn_msgmgr.c @@ -348,29 +348,29 @@ int GetAppSpawnMsgFromBuffer(const uint8_t *buffer, uint32_t bufferLen, static inline void DumpMsgFlags(const char *info, const AppSpawnMsgFlags *msgFlags) { for (uint32_t i = 0; i < msgFlags->count; i++) { - APPSPAPWN_DUMP("%{public}s flags: 0x%{public}x", info, msgFlags->flags[i]); + APPSPAWN_DUMP("%{public}s flags: 0x%{public}x", info, msgFlags->flags[i]); } } static inline void DumpMsgExtInfo(const AppSpawnTlv *tlv) { if (tlv->tlvType != TLV_MAX) { - APPSPAPWN_DUMP("App tlv info: [%{public}d %{public}d]", tlv->tlvType, tlv->tlvLen); + APPSPAWN_DUMP("App tlv info: [%{public}d %{public}d]", tlv->tlvType, tlv->tlvLen); return; } AppSpawnTlvExt *tlvExt = (AppSpawnTlvExt *)(tlv); if (tlvExt->dataType == DATA_TYPE_STRING) { - APPSPAPWN_DUMP("App extend info name: %{public}s len: %{public}u value: '%{public}s'", + APPSPAWN_DUMP("App extend info name: %{public}s len: %{public}u value: '%{public}s'", tlvExt->tlvName, tlvExt->dataLen, (char *)(tlvExt + 1)); } else { - APPSPAPWN_DUMP("App extend info name: %{public}s len: %{public}u", tlvExt->tlvName, tlvExt->dataLen); + APPSPAWN_DUMP("App extend info name: %{public}s len: %{public}u", tlvExt->tlvName, tlvExt->dataLen); } } void DumpAppSpawnMsg(const AppSpawnMsgNode *message) { APPSPAWN_CHECK_ONLY_EXPER(message != NULL, return); - APPSPAPWN_DUMP("App spawn msg msgId: %{public}u msgLen: %{public}u tlvCount: %{public}u processName: %{public}s", + APPSPAWN_DUMP("App spawn msg msgId: %{public}u msgLen: %{public}u tlvCount: %{public}u processName: %{public}s", message->msgHeader.msgId, message->msgHeader.msgLen, message->tlvCount, message->msgHeader.processName); AppSpawnMsgFlags *msgFlags = (AppSpawnMsgFlags *)GetAppSpawnMsgInfo(message, TLV_MSG_FLAGS); @@ -380,20 +380,20 @@ void DumpAppSpawnMsg(const AppSpawnMsgNode *message) AppSpawnMsgDacInfo *dacInfo = (AppSpawnMsgDacInfo *)GetAppSpawnMsgInfo(message, TLV_DAC_INFO); if (dacInfo != NULL) { - APPSPAPWN_DUMP("App dac info uid: %{public}d gid: %{public}d count: %{public}d", + APPSPAWN_DUMP("App dac info uid: %{public}d gid: %{public}d count: %{public}d", dacInfo->uid, dacInfo->gid, dacInfo->gidCount); for (uint32_t i = 0; i < dacInfo->gidCount; i++) { - APPSPAPWN_DUMP("gid group[%{public}d]: %{public}d", i, dacInfo->gidTable[i]); + APPSPAWN_DUMP("gid group[%{public}d]: %{public}d", i, dacInfo->gidTable[i]); } } AppSpawnMsgBundleInfo *bundleInfo = (AppSpawnMsgBundleInfo *)GetAppSpawnMsgInfo(message, TLV_BUNDLE_INFO); APPSPAWN_ONLY_EXPER(bundleInfo != NULL, - APPSPAPWN_DUMP("App bundle info name: \"%{public}s\" index: %{public}d", + APPSPAWN_DUMP("App bundle info name: \"%{public}s\" index: %{public}d", bundleInfo->bundleName, bundleInfo->bundleIndex)); AppSpawnMsgDomainInfo *domainInfo = (AppSpawnMsgDomainInfo *)GetAppSpawnMsgInfo(message, TLV_DOMAIN_INFO); APPSPAWN_ONLY_EXPER(domainInfo != NULL, - APPSPAPWN_DUMP("App domain info hap: 0x%{public}x apl: \"%{public}s\"", domainInfo->hapFlags, domainInfo->apl)); + APPSPAWN_DUMP("App domain info hap: 0x%{public}x apl: \"%{public}s\"", domainInfo->hapFlags, domainInfo->apl)); AppSpawnMgr *mgr = GetAppSpawnMgr(); if (mgr == NULL || ((mgr->flags & APP_DEVELOPER_MODE) != APP_DEVELOPER_MODE)) { @@ -401,11 +401,11 @@ void DumpAppSpawnMsg(const AppSpawnMsgNode *message) } AppSpawnMsgOwnerId *owner = (AppSpawnMsgOwnerId *)GetAppSpawnMsgInfo(message, TLV_OWNER_INFO); - APPSPAWN_ONLY_EXPER(owner != NULL, APPSPAPWN_DUMP("App owner info: \"%{public}s\" ", owner->ownerId)); + APPSPAWN_ONLY_EXPER(owner != NULL, APPSPAWN_DUMP("App owner info: \"%{public}s\" ", owner->ownerId)); AppSpawnMsgInternetInfo *info = (AppSpawnMsgInternetInfo *)GetAppSpawnMsgInfo(message, TLV_INTERNET_INFO); APPSPAWN_ONLY_EXPER(info != NULL, - APPSPAPWN_DUMP("App internet permission info [%{public}d %{public}d]", + APPSPAWN_DUMP("App internet permission info [%{public}d %{public}d]", info->setAllowInternet, info->allowInternet)); for (uint32_t i = TLV_MAX; i < TLV_MAX + message->tlvCount; i++) { diff --git a/test/test_app_info/datagroup/test_app_info.json b/test/test_app_info/datagroup/test_app_info.json new file mode 100644 index 00000000..5be72afa --- /dev/null +++ b/test/test_app_info/datagroup/test_app_info.json @@ -0,0 +1,38 @@ +{ + "msg-type": 0, + "msg-flags": [1, 2, 14], + "process-name" : "ohos.samples.etsclock", + "pid": 328018, + "dac-info" : { + "uid" : 20010043, + "gid" : 20010043, + "gid-table" : [20010043], + "user-name" : "" + }, + "access-token": { + "accessTokenIdEx": 537854093 + }, + "permission": [ + "ohos.permission.PROTECT_SCREEN_LOCK_DATA" + ], + "internet-permission": { + "set-allow-internet": 0, + "allow-internet": 0 + }, + "bundle-info": { + "bundle-index": 0, + "bundle-name": "ohos.samples.etsclock" + }, + "owner-id": "", + "render-cmd": "1234567890", + "domain-info": { + "hap-flags": 0, + "apl": "normal" + }, + "ext-info": [ + { + "name": "DataGroup", + "value": "[{\"gid\": \"1002\", \"dir\": \"data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840\", \"dataGroupId\": \"43200\", \"uuid\": \"49c016e6-065a-abd1-5867-b1f91114f840\"}, {\"gid\": \"1002\", \"dir\": \"data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840\", \"dataGroupId\": \"43200\", \"uuid\": \"49c016e6-065a-abd1-5867-b1f91114f840\"}, {\"gid\": \"1002\", \"dir\": \"data/app/el3/100/group/49c016e6-065a-abd1-5867-b1f91114f840\", \"dataGroupId\": \"43200\", \"uuid\": \"49c016e6-065a-abd1-5867-b1f91114f840\"}, {\"gid\": \"1002\", \"dir\": \"data/app/el4/100/group/49c016e6-065a-abd1-5867-b1f91114f840\", \"dataGroupId\": \"43200\", \"uuid\": \"49c016e6-065a-abd1-5867-b1f91114f840\"}, { \"gid\": \"1002\", \"dir\": \"data/app/el5/100/group/49c016e6-065a-abd1-5867-b1f91114f840\", \"dataGroupId\": \"43200\", \"uuid\": \"49c016e6-065a-abd1-5867-b1f91114f840\"}]" + } + ] +} diff --git a/test/unittest/app_spawn_standard_test/BUILD.gn b/test/unittest/app_spawn_standard_test/BUILD.gn index da7ccf3a..7a2e1921 100644 --- a/test/unittest/app_spawn_standard_test/BUILD.gn +++ b/test/unittest/app_spawn_standard_test/BUILD.gn @@ -149,6 +149,7 @@ ohos_unittest("AppSpawn_ut") { defines += [ "APPSPAWN_SANDBOX_NEW" ] } else { sources += [ + "${appspawn_path}/modules/sandbox/sandbox_shared_mount.cpp", "${appspawn_path}/modules/sandbox/sandbox_utils.cpp", "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp", ] @@ -337,7 +338,10 @@ ohos_unittest("AppSpawn_coldrun_ut") { if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) { defines += [ "APPSPAWN_SANDBOX_NEW" ] } else { - sources += [ "${appspawn_path}/modules/sandbox/sandbox_utils.cpp" ] + sources += [ + "${appspawn_path}/modules/sandbox/sandbox_shared_mount.cpp", + "${appspawn_path}/modules/sandbox/sandbox_utils.cpp", + ] } configs = [ "${appspawn_path}:appspawn_config" ] @@ -523,7 +527,10 @@ ohos_unittest("AppSpawn_common_ut") { if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) { defines += [ "APPSPAWN_SANDBOX_NEW" ] } else { - sources += [ "${appspawn_path}/modules/sandbox/sandbox_utils.cpp" ] + sources += [ + "${appspawn_path}/modules/sandbox/sandbox_shared_mount.cpp", + "${appspawn_path}/modules/sandbox/sandbox_utils.cpp", + ] } configs = [ "${appspawn_path}:appspawn_config" ] diff --git a/util/include/appspawn_utils.h b/util/include/appspawn_utils.h index dbf2aedb..ff220c33 100755 --- a/util/include/appspawn_utils.h +++ b/util/include/appspawn_utils.h @@ -176,7 +176,7 @@ int EnableNewNetNamespace(void); #define APPSPAWN_LOGF(fmt, ...) \ HILOG_FATAL(LOG_CORE, "[%{public}s:%{public}d]" fmt, (APP_FILE_NAME), (__LINE__), ##__VA_ARGS__) -#define APPSPAPWN_DUMP(fmt, ...) \ +#define APPSPAWN_DUMP(fmt, ...) \ do { \ HILOG_INFO(LOG_CORE, fmt, ##__VA_ARGS__); \ AppSpawnDump(fmt "\n", ##__VA_ARGS__); \ -- Gitee From c05137afc2876eeaf0f983e880198e06d09eda6c Mon Sep 17 00:00:00 2001 From: harryhrp Date: Tue, 31 Dec 2024 15:15:55 +0800 Subject: [PATCH 104/148] Aot disk file path adjustment Aot disk file path adjustment Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IBEVFO Signed-off-by: harryhrp --- appdata-sandbox-app.json | 4 ++-- appdata-sandbox.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/appdata-sandbox-app.json b/appdata-sandbox-app.json index a41ba2a4..960bb1e4 100755 --- a/appdata-sandbox-app.json +++ b/appdata-sandbox-app.json @@ -133,10 +133,10 @@ "src-path" : "/data/misc", "sandbox-path" : "/data/storage/el1/bundle/misc" }, { - "src-path" : "/data/local/ark-cache/", + "src-path" : "/data/app/el1/public/aot_compiler/ark_cache/", "sandbox-path" : "/data/storage/ark-cache" }, { - "src-path" : "/data/local/ark-profile//", + "src-path" : "/data/app/el1//aot_compiler/ark_profile/", "sandbox-path" : "/data/storage/ark-profile" }, { "src-path" : "/data/local/shader_cache/local/", diff --git a/appdata-sandbox.json b/appdata-sandbox.json index 2f5ea439..65fcc4ec 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -154,12 +154,12 @@ "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/data/local/ark-cache/", + "src-path" : "/data/app/el1/public/aot_compiler/ark_cache/", "sandbox-path" : "/data/storage/ark-cache", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/data/local/ark-profile//", + "src-path" : "/data/app/el1//aot_compiler/ark_profile/", "sandbox-path" : "/data/storage/ark-profile", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" -- Gitee From e8963cc031842548639c26577866c62b3c3bf08d Mon Sep 17 00:00:00 2001 From: wangfeng Date: Wed, 8 Jan 2025 11:00:06 +0800 Subject: [PATCH 105/148] datagroup dir update mount Signed-off-by: wangfeng --- modules/module_engine/include/appspawn_hook.h | 1 + modules/sandbox/sandbox_shared_mount.cpp | 170 +++++++++++++++++- modules/sandbox/sandbox_shared_mount.h | 2 +- modules/sandbox/sandbox_utils.cpp | 41 +++-- standard/appspawn_service.c | 5 + 5 files changed, 205 insertions(+), 14 deletions(-) diff --git a/modules/module_engine/include/appspawn_hook.h b/modules/module_engine/include/appspawn_hook.h index be9eff8b..8b59bc74 100644 --- a/modules/module_engine/include/appspawn_hook.h +++ b/modules/module_engine/include/appspawn_hook.h @@ -56,6 +56,7 @@ typedef struct TagAppSpawnExtData { typedef enum TagAppSpawnHookStage { // 服务状态处理 STAGE_SERVER_PRELOAD = 10, + STAGE_SERVER_LOCK, STAGE_SERVER_EXIT, // 应用状态处理 STAGE_SERVER_APP_ADD, diff --git a/modules/sandbox/sandbox_shared_mount.cpp b/modules/sandbox/sandbox_shared_mount.cpp index f5e3bd85..b69bd734 100644 --- a/modules/sandbox/sandbox_shared_mount.cpp +++ b/modules/sandbox/sandbox_shared_mount.cpp @@ -207,7 +207,7 @@ static int MountEl1Bundle(const AppSpawningCtx *property, const AppDacInfo *info } ret = umount2(targetPath, MNT_DETACH); - if (ret < 0) { + if (ret != 0) { APPSPAWN_LOGE("umount2 %{public}s failed, errno %{public}d", targetPath, errno); } @@ -245,7 +245,7 @@ static int MountWithFileMgr(const AppSpawningCtx *property, const AppDacInfo *in ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%d/%s/storage/Users", info->uid / UID_BASE, bundleName); if (ret <= 0) { - APPSPAWN_LOGE("snprintf nosharefsDocsDir failed, errno %{public}d", errno); + APPSPAWN_LOGE("snprintf storageUserPath failed, errno %{public}d", errno); return APPSPAWN_ERROR_UTILS_MEM_FAIL; } @@ -293,7 +293,7 @@ static int MountWithOther(const AppSpawningCtx *property, const AppDacInfo *info ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%d/%s/storage/Users", info->uid / UID_BASE, bundleName); if (ret <= 0) { - APPSPAWN_LOGE("snprintf nosharefsDocsDir failed, errno %{public}d", errno); + APPSPAWN_LOGE("snprintf storageUserPath failed, errno %{public}d", errno); return APPSPAWN_ERROR_UTILS_MEM_FAIL; } @@ -410,6 +410,161 @@ static void MountSharedMap(const AppSpawningCtx *property, const AppDacInfo *inf APPSPAWN_LOGI("mount shared map success"); } +static inline bool CheckPath(const std::string& name) +{ + return !name.empty() && name != "." && name != ".." && name.find("/") == std::string::npos; +} + +static int AddDataGroupItemToQueue(AppSpawnMgr *content, const std::string &srcPath, const std::string &destPath, + const std::string &dataGroupUuid) +{ + DataGroupCtx *dataGroupNode = (DataGroupCtx *)calloc(1, sizeof(DataGroupCtx)); + APPSPAWN_CHECK(dataGroupNode != nullptr, return APPSPAWN_ERROR_UTILS_MEM_FAIL, "Calloc dataGroupNode failed"); + if (strcpy_s(dataGroupNode->srcPath.path, PATH_MAX_LEN - 1, srcPath.c_str()) != EOK || + strcpy_s(dataGroupNode->destPath.path, PATH_MAX_LEN - 1, destPath.c_str()) != EOK || + strcpy_s(dataGroupNode->dataGroupUuid, UUID_MAX_LEN, dataGroupUuid.c_str()) != EOK) { + APPSPAWN_LOGE("strcpy dataGroupNode->srcPath failed"); + free(dataGroupNode); + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + dataGroupNode->srcPath.pathLen = strlen(dataGroupNode->srcPath.path); + dataGroupNode->destPath.pathLen = strlen(dataGroupNode->destPath.path); + OH_ListInit(&dataGroupNode->node); + OH_ListAddTail(&content->dataGroupCtxQueue, &dataGroupNode->node); + return 0; +} + +static std::string GetExtraInfoByType(const AppSpawningCtx *appPropery, const std::string &type) +{ + uint32_t len = 0; + char *info = reinterpret_cast(GetAppPropertyExt(appPropery, type.c_str(), &len)); + if (info == nullptr) { + return ""; + } + return std::string(info, len); +} + +static void DumpDataGroupCtxQueue(const ListNode *front) +{ + if (front == nullptr) { + return; + } + + uint32_t count = 0; + ListNode *node = front->next; + while (node != front) { + DataGroupCtx *dataGroupNode = (DataGroupCtx *)ListEntry(node, DataGroupCtx, node); + count++; + APPSPAWN_LOGV(" ************************************** %{public}d", count); + APPSPAWN_LOGV(" srcPath: %{public}s", dataGroupNode->srcPath.path); + APPSPAWN_LOGV(" destPath: %{public}s", dataGroupNode->destPath.path); + APPSPAWN_LOGV(" uuid: %{public}s", dataGroupNode->dataGroupUuid); + node = node->next; + } +} + +static int ParseDataGroupList(AppSpawnMgr *content, const AppSpawningCtx *property, AppDacInfo *info, + AppSpawnMsgBundleInfo *bundleInfo) +{ + int ret = 0; + std::string dataGroupList = GetExtraInfoByType(property, DATA_GROUP_SOCKET_TYPE); + if (dataGroupList.length() == 0) { + APPSPAWN_LOGE("dataGroupList is empty"); + return APPSPAWN_ARG_INVALID; + } + + nlohmann::json dataGroupJson = nlohmann::json::parse(dataGroupList.c_str(), nullptr, false); + APPSPAWN_CHECK(!dataGroupJson.is_discarded() && dataGroupJson.contains(GROUPLIST_KEY_DATAGROUPID) && + dataGroupJson.contains(GROUPLIST_KEY_GID) && dataGroupJson.contains(GROUPLIST_KEY_DIR), return -1, + "MountAllGroup: json parse failed"); + + nlohmann::json& dataGroupIds = dataGroupJson[GROUPLIST_KEY_DATAGROUPID]; + nlohmann::json& gids = dataGroupJson[GROUPLIST_KEY_GID]; + nlohmann::json& dirs = dataGroupJson[GROUPLIST_KEY_DIR]; + APPSPAWN_CHECK(dataGroupIds.is_array() && gids.is_array() && dirs.is_array() && dataGroupIds.size() == gids.size() + && dataGroupIds.size() == dirs.size(), return -1, "MountAllGroup: value is not arrary or sizes are not same"); + for (uint32_t i = 0; i < dataGroupIds.size(); i++) { + // elements in json arrary can be different type + APPSPAWN_CHECK(dataGroupIds[i].is_string() && gids[i].is_string() && dirs[i].is_string(), + return -1, "MountAllGroup: element type error"); + + std::string srcPath = dirs[i]; + APPSPAWN_CHECK(!CheckPath(srcPath), return -1, "MountAllGroup: path error"); + + size_t lastPathSplitPos = srcPath.find_last_of("/"); + APPSPAWN_CHECK(lastPathSplitPos != std::string::npos, return -1, "MountAllGroup: path error"); + std::string dataGroupUuid = srcPath.substr(lastPathSplitPos + 1); + + + uint32_t elxValue = GetElxInfoFromDir(srcPath.c_str()); + APPSPAWN_CHECK((elxValue >= EL2 && elxValue < ELX_MAX), return -1, "Get elx value failed"); + + const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(elxValue); + APPSPAWN_CHECK(templateItem != nullptr, return -1, "Get data group arg template failed"); + + // If permission isn't null, need check permission flag + if (templateItem->permission != nullptr) { + int index = GetPermissionIndex(nullptr, templateItem->permission); + APPSPAWN_LOGV("mount dir no lock mount permission flag %{public}d", index); + if (CheckAppPermissionFlagSet(property, static_cast(index)) == 0) { + continue; + } + } + + // sandboxPath: /mnt/sandbox///data/storage/el/group + std::string sandboxPath = "/mnt/sandbox/" + std::to_string(info->uid / UID_BASE) + "/" + bundleInfo->bundleName + + templateItem->sandboxPath; + + ret = AddDataGroupItemToQueue(content, srcPath, sandboxPath, dataGroupUuid); + if (ret != 0) { + APPSPAWN_LOGE("Add datagroup item to dataGroupCtxQueue failed, el%{public}d", elxValue); + OH_ListRemoveAll(&content->dataGroupCtxQueue, nullptr); + return -1; + } + } + + DumpDataGroupCtxQueue(&content->dataGroupCtxQueue); + return ret; +} + +int UpdateDataGroupDirs(AppSpawnMgr *content) +{ + if (content == nullptr) { + return APPSPAWN_ARG_INVALID; + } + + ListNode *node = content->dataGroupCtxQueue.next; + while (node != &content->dataGroupCtxQueue) { + DataGroupCtx *dataGroupNode = (DataGroupCtx *)ListEntry(node, DataGroupCtx, node); + char sandboxPath[PATH_MAX_LEN] = {0}; + int ret = snprintf_s(sandboxPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%s", dataGroupNode->destPath.path, + dataGroupNode->dataGroupUuid); + if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s sandboxPath: %{public}s failed, errno %{public}d", + dataGroupNode->destPath.path, errno); + return APPSPAWN_ERROR_UTILS_MEM_FAIL; + } + + SharedMountArgs args = { + .srcPath = dataGroupNode->srcPath.path, + .destPath = sandboxPath, + .fsType = nullptr, + .mountFlags = MS_BIND | MS_REC, + .options = nullptr, + .mountSharedFlag = MS_SHARED + }; + ret = DoSharedMount(&args); + if (ret != 0) { + APPSPAWN_LOGE("Shared mount %{public}s to %{public}s failed, errno %{public}d", args.srcPath, + sandboxPath, ret); + return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; + } + node = node->next; + } + OH_ListRemoveAll(&content->dataGroupCtxQueue, NULL); + return 0; +} + static void MountDirToShared(AppSpawnMgr *content, const AppSpawningCtx *property) { if (property == nullptr) { @@ -436,6 +591,7 @@ static void MountDirToShared(AppSpawnMgr *content, const AppSpawningCtx *propert GetMountInfo(sharedMounts, info, std::string(bundleInfo->bundleName)); MountSharedMap(property, info, bundleInfo->bundleName, sharedMounts); MountStorageUsers(property, info, bundleInfo->bundleName, sharedMounts); + ParseDataGroupList(content, property, info, bundleInfo); struct timespec checkEnd = {0}; clock_gettime(CLOCK_MONOTONIC, &checkEnd); @@ -461,3 +617,11 @@ int MountToShared(AppSpawnMgr *content, const AppSpawningCtx *property) #endif return 0; } + +MODULE_CONSTRUCTOR(void) +{ +#ifndef APPSPAWN_SANDBOX_NEW + (void)AddServerStageHook(STAGE_SERVER_LOCK, HOOK_PRIO_COMMON, UpdateDataGroupDirs); +#endif +} + diff --git a/modules/sandbox/sandbox_shared_mount.h b/modules/sandbox/sandbox_shared_mount.h index 7bdd28de..ad2e8cd9 100644 --- a/modules/sandbox/sandbox_shared_mount.h +++ b/modules/sandbox/sandbox_shared_mount.h @@ -42,7 +42,7 @@ enum { typedef struct DataGroupSandboxPathTemplate { const char *elxName; uint32_t category; - const char *sandboxPath;; + const char *sandboxPath; const char *permission; } DataGroupSandboxPathTemplate; diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 00ecd090..e06f9c8f 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -98,6 +98,7 @@ namespace { const std::string g_groupList_key_dataGroupId = "dataGroupId"; const std::string g_groupList_key_gid = "gid"; const std::string g_groupList_key_dir = "dir"; + const std::string g_groupList_key_uuid = "uuid"; const std::string HSPLIST_SOCKET_TYPE = "HspList"; const std::string OVERLAY_SOCKET_TYPE = "Overlay"; const std::string DATA_GROUP_SOCKET_TYPE = "DataGroup"; @@ -1380,24 +1381,40 @@ int32_t SandboxUtils::MountAllGroup(const AppSpawningCtx *appProperty, std::stri APPSPAWN_CHECK(dataGroupIds[i].is_string() && gids[i].is_string() && dirs[i].is_string(), return -1, "MountAllGroup: element type error"); - std::string libPhysicalPath = dirs[i]; - APPSPAWN_CHECK(!CheckPath(libPhysicalPath), return -1, "MountAllGroup: path error"); + std::string srcPath = dirs[i]; + APPSPAWN_CHECK(!CheckPath(srcPath), return -1, "MountAllGroup: path error"); - size_t lastPathSplitPos = libPhysicalPath.find_last_of(g_fileSeparator); + size_t lastPathSplitPos = srcPath.find_last_of(g_fileSeparator); APPSPAWN_CHECK(lastPathSplitPos != std::string::npos, return -1, "MountAllGroup: path error"); + std::string dataGroupUuid = srcPath.substr(lastPathSplitPos + 1); + + uint32_t elxValue = GetElxInfoFromDir(srcPath.c_str()); + APPSPAWN_CHECK((elxValue >= EL2 && elxValue < ELX_MAX), return -1, "Get elx value failed"); + + const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(elxValue); + APPSPAWN_CHECK(templateItem != nullptr, return -1, "Get data group arg template failed"); + + // If permission isn't null, need check permission flag + if (templateItem->permission != nullptr) { + int index = GetPermissionIndex(nullptr, templateItem->permission); + APPSPAWN_LOGV("mount dir no lock mount permission flag %{public}d", index); + if (CheckAppPermissionFlagSet(appProperty, static_cast(index)) == 0) { + continue; + } + } - std::string dataGroupUuid = libPhysicalPath.substr(lastPathSplitPos + 1); - std::string mntPath = sandboxPackagePath + g_sandboxGroupPath + dataGroupUuid; + std::string mntPath = sandboxPackagePath + templateItem->sandboxPath + dataGroupUuid; mode_t mountFlags = MS_REC | MS_BIND; mode_t mountSharedFlag = MS_SLAVE; if (CheckAppMsgFlagsSet(appProperty, APP_FLAGS_ISOLATED_SANDBOX)) { mountSharedFlag |= MS_REMOUNT | MS_NODEV | MS_RDONLY | MS_BIND; } - ret = DoAppSandboxMountOnce(libPhysicalPath.c_str(), mntPath.c_str(), "", mountFlags, nullptr, - mountSharedFlag); - APPSPAWN_CHECK(ret == 0, return ret, "mount library failed %{public}d", ret); + ret = DoAppSandboxMountOnce(srcPath.c_str(), mntPath.c_str(), "", mountFlags, nullptr, mountSharedFlag); + if (ret != 0) { + APPSPAWN_LOGE("mount el%{public}d datagroup failed", elxValue); + } } - return ret; + return 0; } int32_t SandboxUtils::DoSandboxRootFolderCreate(const AppSpawningCtx *appProperty, @@ -1893,6 +1910,10 @@ int32_t SetAppSandboxProperty(AppSpawnMgr *content, AppSpawningCtx *property) APPSPAWN_CHECK(content != nullptr, return -1, "Invalid appspwn content"); // clear g_mountInfo in the child process std::map* mapPtr = static_cast*>(GetEl1BundleMountCount()); + if (mapPtr == nullptr) { + APPSPAWN_LOGE("Get el1 bundle mount count failed"); + return APPSPAWN_ARG_INVALID; + } mapPtr->clear(); int ret = 0; // no sandbox @@ -1974,7 +1995,7 @@ static int UmountSandboxPath(const AppSpawnMgr *content, const AppSpawnedProcess uint32_t userId = appInfo->uid / UID_BASE; std::string key = std::to_string(userId) + "-" + std::string(appInfo->name); map *el1BundleCountMap = static_cast*>(GetEl1BundleMountCount()); - if (el1BundleCountMap->find(key) == el1BundleCountMap->end()) { + if (el1BundleCountMap == nullptr || el1BundleCountMap->find(key) == el1BundleCountMap->end()) { return 0; } (*el1BundleCountMap)[key]--; diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index a900df5c..954e9bc7 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -1685,6 +1685,11 @@ static void ProcessAppSpawnLockStatusMsg(AppSpawnMsgNode *message) APPSPAWN_CHECK(ret > 0, return, "get lock status param failed, errno %{public}d", errno); ret = SetParameter(lockStatusParam, userLockStatus); APPSPAWN_CHECK(ret == 0, return, "failed to set lockstatus param value ret %{public}d", ret); +#ifndef APPSPAWN_SANDBOX_NEW + if (strcmp(userLockStatus, "0") == 0) { + ServerStageHookExecute(STAGE_SERVER_LOCK, GetAppSpawnContent()); + } +#endif } static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) -- Gitee From 4d3981724f70f4a247051e49f1e96c1c27fdeee5 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Thu, 9 Jan 2025 10:22:32 +0800 Subject: [PATCH 106/148] support datagroup dir mount again Signed-off-by: wangfeng --- modules/sandbox/sandbox_shared_mount.cpp | 33 +++++++------------ modules/sandbox/sandbox_utils.cpp | 31 ++++++----------- .../app_spawn_sandbox_test.cpp | 20 +++++++---- 3 files changed, 35 insertions(+), 49 deletions(-) diff --git a/modules/sandbox/sandbox_shared_mount.cpp b/modules/sandbox/sandbox_shared_mount.cpp index b69bd734..3d5bd581 100644 --- a/modules/sandbox/sandbox_shared_mount.cpp +++ b/modules/sandbox/sandbox_shared_mount.cpp @@ -474,27 +474,16 @@ static int ParseDataGroupList(AppSpawnMgr *content, const AppSpawningCtx *proper } nlohmann::json dataGroupJson = nlohmann::json::parse(dataGroupList.c_str(), nullptr, false); - APPSPAWN_CHECK(!dataGroupJson.is_discarded() && dataGroupJson.contains(GROUPLIST_KEY_DATAGROUPID) && - dataGroupJson.contains(GROUPLIST_KEY_GID) && dataGroupJson.contains(GROUPLIST_KEY_DIR), return -1, - "MountAllGroup: json parse failed"); - - nlohmann::json& dataGroupIds = dataGroupJson[GROUPLIST_KEY_DATAGROUPID]; - nlohmann::json& gids = dataGroupJson[GROUPLIST_KEY_GID]; - nlohmann::json& dirs = dataGroupJson[GROUPLIST_KEY_DIR]; - APPSPAWN_CHECK(dataGroupIds.is_array() && gids.is_array() && dirs.is_array() && dataGroupIds.size() == gids.size() - && dataGroupIds.size() == dirs.size(), return -1, "MountAllGroup: value is not arrary or sizes are not same"); - for (uint32_t i = 0; i < dataGroupIds.size(); i++) { - // elements in json arrary can be different type - APPSPAWN_CHECK(dataGroupIds[i].is_string() && gids[i].is_string() && dirs[i].is_string(), - return -1, "MountAllGroup: element type error"); - - std::string srcPath = dirs[i]; - APPSPAWN_CHECK(!CheckPath(srcPath), return -1, "MountAllGroup: path error"); - - size_t lastPathSplitPos = srcPath.find_last_of("/"); - APPSPAWN_CHECK(lastPathSplitPos != std::string::npos, return -1, "MountAllGroup: path error"); - std::string dataGroupUuid = srcPath.substr(lastPathSplitPos + 1); - + if (dataGroupJson.is_discarded() && dataGroupJson.contains(GROUPLIST_KEY_DATAGROUPID) && + dataGroupJson.contains(GROUPLIST_KEY_GID) && dataGroupJson.contains(GROUPLIST_KEY_DIR) && + dataGroupJson.contains(GROUPLIST_KEY_UUID)) { + APPSPAWN_LOGE("dataGroupJson is discarded"); + return APPSPAWN_ARG_INVALID; + } + for (auto &item : dataGroupJson) { + APPSPAWN_CHECK(IsValidDataGroupItem(item), return -1, "Element is not a valid data group item"); + std::string srcPath = item[GROUPLIST_KEY_DIR]; + APPSPAWN_CHECK(!CheckPath(srcPath), return -1, "src path %{public}s is invalid", srcPath.c_str()); uint32_t elxValue = GetElxInfoFromDir(srcPath.c_str()); APPSPAWN_CHECK((elxValue >= EL2 && elxValue < ELX_MAX), return -1, "Get elx value failed"); @@ -515,7 +504,7 @@ static int ParseDataGroupList(AppSpawnMgr *content, const AppSpawningCtx *proper std::string sandboxPath = "/mnt/sandbox/" + std::to_string(info->uid / UID_BASE) + "/" + bundleInfo->bundleName + templateItem->sandboxPath; - ret = AddDataGroupItemToQueue(content, srcPath, sandboxPath, dataGroupUuid); + ret = AddDataGroupItemToQueue(content, srcPath, sandboxPath, item[GROUPLIST_KEY_UUID]); if (ret != 0) { APPSPAWN_LOGE("Add datagroup item to dataGroupCtxQueue failed, el%{public}d", elxValue); OH_ListRemoveAll(&content->dataGroupCtxQueue, nullptr); diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index e06f9c8f..1a89e6b0 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -1365,29 +1365,18 @@ int32_t SandboxUtils::MountAllGroup(const AppSpawningCtx *appProperty, std::stri } nlohmann::json groups = nlohmann::json::parse(dataGroupInfo.c_str(), nullptr, false); - APPSPAWN_CHECK(!groups.is_discarded() && groups.contains(g_groupList_key_dataGroupId) - && groups.contains(g_groupList_key_gid) && groups.contains(g_groupList_key_dir), return -1, - "MountAllGroup: json parse failed"); - - nlohmann::json& dataGroupIds = groups[g_groupList_key_dataGroupId]; - nlohmann::json& gids = groups[g_groupList_key_gid]; - nlohmann::json& dirs = groups[g_groupList_key_dir]; - APPSPAWN_CHECK(dataGroupIds.is_array() && gids.is_array() && dirs.is_array() && dataGroupIds.size() == gids.size() - && dataGroupIds.size() == dirs.size(), return -1, "MountAllGroup: value is not arrary or sizes are not same"); - APPSPAWN_LOGI("MountAllGroup: app = %{public}s, cnt = %{public}lu", - GetBundleName(appProperty), static_cast(dataGroupIds.size())); - for (uint32_t i = 0; i < dataGroupIds.size(); i++) { - // elements in json arrary can be different type - APPSPAWN_CHECK(dataGroupIds[i].is_string() && gids[i].is_string() && dirs[i].is_string(), - return -1, "MountAllGroup: element type error"); + if (groups.is_discarded() && groups.contains(g_groupList_key_dataGroupId) && groups.contains(g_groupList_key_dir) && + groups.contains(g_groupList_key_gid) && groups.contains(g_groupList_key_uuid)) { + APPSPAWN_LOGE("dataGroupJson is discarded"); + return APPSPAWN_ARG_INVALID; + } - std::string srcPath = dirs[i]; + for (auto& item : groups) { + // elements in json arrary can be different type + APPSPAWN_CHECK(IsValidDataGroupItem(item), return -1, "MountAllGroup: data group item error"); + std::string srcPath = item[g_groupList_key_dir]; APPSPAWN_CHECK(!CheckPath(srcPath), return -1, "MountAllGroup: path error"); - size_t lastPathSplitPos = srcPath.find_last_of(g_fileSeparator); - APPSPAWN_CHECK(lastPathSplitPos != std::string::npos, return -1, "MountAllGroup: path error"); - std::string dataGroupUuid = srcPath.substr(lastPathSplitPos + 1); - uint32_t elxValue = GetElxInfoFromDir(srcPath.c_str()); APPSPAWN_CHECK((elxValue >= EL2 && elxValue < ELX_MAX), return -1, "Get elx value failed"); @@ -1402,7 +1391,7 @@ int32_t SandboxUtils::MountAllGroup(const AppSpawningCtx *appProperty, std::stri continue; } } - + std::string dataGroupUuid = item[g_groupList_key_uuid]; std::string mntPath = sandboxPackagePath + templateItem->sandboxPath + dataGroupUuid; mode_t mountFlags = MS_REC | MS_BIND; mode_t mountSharedFlag = MS_SLAVE; diff --git a/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp index 6d2d24e9..aa417ed0 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp @@ -1162,12 +1162,20 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_40, TestSize.Level0) g_testHelper.SetTestApl("normal"); g_testHelper.SetTestMsgFlags(0x100); std::string sandboxPrefix = "/mnt/sandbox/100/testBundle"; - char dataGroupInfoListStr[] = "{ \ - \"dataGroupId\":[\"1234abcd5678efgh\", \"abcduiop1234\"], \ - \"dir\":[\"/data/app/el2/100/group/091a68a9-2cc9-4279-8849-28631b598975\", \ - \"/data/app/el2/100/group/ce876162-fe69-45d3-aa8e-411a047af564\"], \ - \"gid\":[\"20100001\", \"20100002\"] \ - }"; + char dataGroupInfoListStr[] = R"([ + { + "gid": "1002", + "dir": "data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840", + "dataGroupId": "43200", + "uuid": "49c016e6-065a-abd1-5867-b1f91114f840" + }, + { + "gid": "1002", + "dir": "data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840", + "dataGroupId": "43200", + "uuid": "49c016e6-065a-abd1-5867-b1f91114f840" + } + ])"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("DataGroup", dataGroupInfoListStr); int ret = OHOS::AppSpawn::SandboxUtils::MountAllGroup(appProperty, sandboxPrefix); DeleteAppSpawningCtx(appProperty); -- Gitee From e06344a1edc8e8c565a068154e7da397f483dbe4 Mon Sep 17 00:00:00 2001 From: z00500798 Date: Thu, 9 Jan 2025 16:31:18 +0800 Subject: [PATCH 107/148] Description:erofs mount Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: zl_zl --- interfaces/innerkits/client/appspawn_client.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/interfaces/innerkits/client/appspawn_client.c b/interfaces/innerkits/client/appspawn_client.c index be63b799..d63a6f77 100644 --- a/interfaces/innerkits/client/appspawn_client.c +++ b/interfaces/innerkits/client/appspawn_client.c @@ -395,8 +395,7 @@ int AppSpawnClientSendUserLockStatus(uint32_t userId, bool isLocked) AppSpawnResult result = {0}; ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); AppSpawnClientDestroy(clientHandle); - APPSPAWN_CHECK(ret == 0, AppSpawnReqMsgFree(reqHandle); - return ret, "Send msg to appspawn failed, ret=%{public}d", ret); + APPSPAWN_CHECK(ret == 0, return ret, "Send msg to appspawn failed, ret=%{public}d", ret); if (result.result != 0) { APPSPAWN_LOGE("Appspawn failed to handle message, result=%{public}d", result.result); -- Gitee From ee6a9c768f568817c6fd8c168cbb3eb1e8d5dde9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Mon, 13 Jan 2025 19:18:06 +0800 Subject: [PATCH 108/148] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9appspawn=20?= =?UTF-8?q?=E7=BC=BA=E5=B0=91=E6=96=AD=E8=A8=80=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- .../app_spawn_client_test/app_spawn_interface_test.cpp | 1 + .../app_spawn_standard_test/app_spawn_common_test.cpp | 6 ++++-- .../app_spawn_module_interface_test.cpp | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) 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 fa1547d1..31b80b7d 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 @@ -584,6 +584,7 @@ HWTEST_F(AppSpawnInterfaceTest, App_Spawn_Interface_ClientSocket_001, TestSize.L socketId = CreateClientSocket(CLIENT_MAX, 2); CloseClientSocket(socketId); CloseClientSocket(-1); + EXPECT_NE(socketId, 0); } HWTEST_F(AppSpawnInterfaceTest, App_Spawn_Interface_GetSpawnTimeout_001, TestSize.Level0) 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 1a529e44..c545f7ab 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 @@ -56,12 +56,14 @@ public: HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_001, TestSize.Level0) { - SetSelinuxConNweb(nullptr, nullptr); + int ret = SetSelinuxConNweb(nullptr, nullptr); + EXPECT_EQ(ret, 0); } HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_002, TestSize.Level0) { - SetAppAccessToken(nullptr, nullptr); + int ret = SetAppAccessToken(nullptr, nullptr); + EXPECT_NE(ret, 0); } HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_003, TestSize.Level0) diff --git a/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp index 90d8dce4..29257231 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp @@ -315,6 +315,7 @@ HWTEST_F(AppSpawnModuleInterfaceTest, App_Spawn_DumpCurrentDir_001, TestSize.Lev DumpCurrentDir(path, 0, APPSPAWN_BASE_DIR "/test_appspawn/"); DumpCurrentDir(nullptr, sizeof(path), APPSPAWN_BASE_DIR "/test_appspawn/"); DumpCurrentDir(nullptr, sizeof(path), nullptr); + EXPECT_NE(path, nullptr); } static int TestParseAppSandboxConfig(const cJSON *root, ParseJsonContext *context) -- Gitee From 3fb2ce58b4bf551d4592b3ef648e9321fc4a5b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Fri, 10 Jan 2025 13:55:49 +0800 Subject: [PATCH 109/148] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E7=8E=87=E8=BF=87=E9=AB=98=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- modules/sandbox/sandbox_utils.cpp | 4 ++-- standard/appspawn_kickdog.c | 7 ++++--- standard/appspawn_msgmgr.c | 16 +++++++++------- standard/appspawn_service.c | 4 ++-- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 1a89e6b0..fccbb286 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -1618,7 +1618,7 @@ int32_t SandboxUtils::SetSandboxProperty(AppSpawningCtx *appProperty, std::strin ret = SetBundleResourceAppSandboxProperty(appProperty, sandboxPackagePath); APPSPAWN_CHECK(ret == 0, return ret, "SetBundleResourceAppSandboxProperty failed, packagename is %{public}s", bundleName.c_str()); - APPSPAWN_LOGI("Set appsandbox property success"); + APPSPAWN_LOGV("Set appsandbox property success"); return ret; } @@ -1757,7 +1757,7 @@ int32_t SandboxUtils::SetAppSandboxProperty(AppSpawningCtx *appProperty, uint32_ #ifndef APPSPAWN_TEST rc = ChangeCurrentDir(sandboxPackagePath, bundleName, sandboxSharedStatus); APPSPAWN_CHECK(rc == 0, return rc, "change current dir failed"); - APPSPAWN_LOGI("Change root dir success"); + APPSPAWN_LOGV("Change root dir success"); #if defined(APPSPAWN_MOUNT_TMPSHM) && defined(WITH_SELINUX) Restorecon(DEV_SHM_DIR); #endif // APPSPAWN_MOUNT_TMPSHM && WITH_SELINUX diff --git a/standard/appspawn_kickdog.c b/standard/appspawn_kickdog.c index 7223bab4..8d270749 100644 --- a/standard/appspawn_kickdog.c +++ b/standard/appspawn_kickdog.c @@ -34,7 +34,7 @@ static int OpenAndWriteToProc(const char *procName, const char *writeStr, size_t if (writeResult != (int)writeLen) { APPSPAWN_LOGE("write %{public}s fail,result:%{public}d", writeStr, writeResult); } else { - APPSPAWN_LOGI("write %{public}s success", writeStr); + APPSPAWN_LOGV("write %{public}s success", writeStr); } close(procFd); @@ -73,8 +73,9 @@ static void DealSpawnWatchdog(AppSpawnContent *content, bool isOpen) if (isOpen) { content->wdgOpened = (result != -1); } - APPSPAWN_LOGI("%{public}s %{public}s watchdog end, result:%{public}d", - (content->mode == MODE_FOR_NWEB_SPAWN) ? "Nwebspawn" : "Appspawn", isOpen ? "enable" : "kick", result); + APPSPAWN_LOGI("procFile: %{public}s procContent: %{public}s %{public}s %{public}s watchdog end, result:%{public}d", + procFile, procContent, (content->mode == MODE_FOR_NWEB_SPAWN) ? + "Nwebspawn" : "Appspawn", isOpen ? "enable" : "kick", result); } static void ProcessTimerHandle(const TimerHandle taskHandle, void *context) diff --git a/standard/appspawn_msgmgr.c b/standard/appspawn_msgmgr.c index b7b7b903..4c45e88b 100644 --- a/standard/appspawn_msgmgr.c +++ b/standard/appspawn_msgmgr.c @@ -345,10 +345,11 @@ int GetAppSpawnMsgFromBuffer(const uint8_t *buffer, uint32_t bufferLen, return 0; } -static inline void DumpMsgFlags(const char *info, const AppSpawnMsgFlags *msgFlags) +static inline void DumpMsgFlags(const char *processName, const char *info, const AppSpawnMsgFlags *msgFlags) { for (uint32_t i = 0; i < msgFlags->count; i++) { - APPSPAWN_DUMP("%{public}s flags: 0x%{public}x", info, msgFlags->flags[i]); + APPSPAWN_DUMP("processName: %{public}s %{public}d %{public}s flags: 0x%{public}x", + processName, i, info, msgFlags->flags[i]); } } @@ -360,7 +361,7 @@ static inline void DumpMsgExtInfo(const AppSpawnTlv *tlv) } AppSpawnTlvExt *tlvExt = (AppSpawnTlvExt *)(tlv); if (tlvExt->dataType == DATA_TYPE_STRING) { - APPSPAWN_DUMP("App extend info name: %{public}s len: %{public}u value: '%{public}s'", + APPSPAWN_LOGV("App extend info name: %{public}s len: %{public}u value: '%{public}s'", tlvExt->tlvName, tlvExt->dataLen, (char *)(tlvExt + 1)); } else { APPSPAWN_DUMP("App extend info name: %{public}s len: %{public}u", tlvExt->tlvName, tlvExt->dataLen); @@ -374,9 +375,10 @@ void DumpAppSpawnMsg(const AppSpawnMsgNode *message) message->msgHeader.msgId, message->msgHeader.msgLen, message->tlvCount, message->msgHeader.processName); AppSpawnMsgFlags *msgFlags = (AppSpawnMsgFlags *)GetAppSpawnMsgInfo(message, TLV_MSG_FLAGS); - APPSPAWN_ONLY_EXPER(msgFlags != NULL, DumpMsgFlags("App flags", msgFlags)); + APPSPAWN_ONLY_EXPER(msgFlags != NULL, DumpMsgFlags(message->msgHeader.processName, "App flags", msgFlags)); msgFlags = (AppSpawnMsgFlags *)GetAppSpawnMsgInfo(message, TLV_PERMISSION); - APPSPAWN_ONLY_EXPER(msgFlags != NULL, DumpMsgFlags("App permission bits", msgFlags)); + APPSPAWN_ONLY_EXPER(msgFlags != NULL, + DumpMsgFlags(message->msgHeader.processName, "App permission bits", msgFlags)); AppSpawnMsgDacInfo *dacInfo = (AppSpawnMsgDacInfo *)GetAppSpawnMsgInfo(message, TLV_DAC_INFO); if (dacInfo != NULL) { @@ -401,11 +403,11 @@ void DumpAppSpawnMsg(const AppSpawnMsgNode *message) } AppSpawnMsgOwnerId *owner = (AppSpawnMsgOwnerId *)GetAppSpawnMsgInfo(message, TLV_OWNER_INFO); - APPSPAWN_ONLY_EXPER(owner != NULL, APPSPAWN_DUMP("App owner info: \"%{public}s\" ", owner->ownerId)); + APPSPAWN_ONLY_EXPER(owner != NULL, APPSPAWN_LOGV("App owner info: \"%{public}s\" ", owner->ownerId)); AppSpawnMsgInternetInfo *info = (AppSpawnMsgInternetInfo *)GetAppSpawnMsgInfo(message, TLV_INTERNET_INFO); APPSPAWN_ONLY_EXPER(info != NULL, - APPSPAWN_DUMP("App internet permission info [%{public}d %{public}d]", + APPSPAWN_LOGV("App internet permission info [%{public}d %{public}d]", info->setAllowInternet, info->allowInternet)); for (uint32_t i = TLV_MAX; i < TLV_MAX + message->tlvCount; i++) { diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 954e9bc7..1764d93c 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -772,7 +772,7 @@ static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property) (void)close(property->forkCtx.fd[0]); (void)close(property->forkCtx.fd[1]); int isRet = SetPreforkProcessName(content); - APPSPAWN_LOGI("prefork process start wait read msg with set processname %{public}d", isRet); + APPSPAWN_LOGV("prefork process start wait read msg with set processname %{public}d", isRet); AppSpawnClient client = {0, 0}; int infoSize = read(content->parentToChildFd[0], &client, sizeof(AppSpawnClient)); if (infoSize != sizeof(AppSpawnClient)) { @@ -897,7 +897,7 @@ static void ProcessSpawnReqMsg(AppSpawnConnection *connection, AppSpawnMsgNode * if (IsSupportRunHnp()) { SetAppSpawnMsgFlag(message, TLV_MSG_FLAGS, APP_FLAGS_DEVELOPER_MODE); } else { - APPSPAWN_LOGI("Not support execute hnp file!"); + APPSPAWN_LOGV("Not support execute hnp file!"); } } -- Gitee From ccd000097e2833bf2861de03502d7ee2fb8c7dd9 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Tue, 14 Jan 2025 15:44:32 +0800 Subject: [PATCH 110/148] Increase the message length of the prefork application process to 64 * 1024 characters Signed-off-by: wangfeng --- standard/appspawn_service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 1764d93c..27bd3e60 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -51,7 +51,7 @@ #define PARAM_BUFFER_SIZE 10 #define PATH_SIZE 256 #define FD_PATH_SIZE 128 -#define MAX_MEM_SIZE (4 * 1024) +#define MAX_MEM_SIZE (64 * 1024) #define APPSPAWN_MSG_USER_CHECK_COUNT 4 #define PREFORK_PROCESS "apppool" #define USER_ID_MIN_VALUE 100 -- Gitee From e2b94ff7fb7824e35e208fbfa5028adf2cf7b770 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Wed, 15 Jan 2025 17:38:12 +0800 Subject: [PATCH 111/148] fix:filemanager no recent dir Signed-off-by: wangfeng --- appdata-sandbox.json | 9 ++++----- standard/appspawn_service.c | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/appdata-sandbox.json b/appdata-sandbox.json index 62f07d3f..463b1ea3 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -666,6 +666,10 @@ "sandbox-switch": "ON", "gids": [1006, 1008], "mount-paths": [{ + "src-path": "/mnt/user//nosharefs/docs", + "sandbox-path": "/storage/Users", + "sandbox-flags": [ "bind", "rec" ] + },{ "src-path": "/data/service/el1/public/storage_daemon/share/public", "sandbox-path": "/storage/Share", "sandbox-flags": [ "bind", "rec" ] @@ -680,11 +684,6 @@ "sandbox-path": "/storage/Users//.Recent", "sandbox-flags": [ "bind", "rec" ] }, - { - "src-path": "/mnt/user//nosharefs/docs", - "sandbox-path": "/storage/Users", - "sandbox-flags": [ "bind", "rec" ] - }, { "src-path": "/mnt/data//hmdfs", "sandbox-path": "/storage/hmdfs", diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 27bd3e60..1764d93c 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -51,7 +51,7 @@ #define PARAM_BUFFER_SIZE 10 #define PATH_SIZE 256 #define FD_PATH_SIZE 128 -#define MAX_MEM_SIZE (64 * 1024) +#define MAX_MEM_SIZE (4 * 1024) #define APPSPAWN_MSG_USER_CHECK_COUNT 4 #define PREFORK_PROCESS "apppool" #define USER_ID_MIN_VALUE 100 -- Gitee From 2ca3f85ba8aac25292b4eb5f925410095b23007c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Thu, 16 Jan 2025 11:03:40 +0800 Subject: [PATCH 112/148] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- modules/ace_adapter/ace_adapter.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/ace_adapter/ace_adapter.cpp b/modules/ace_adapter/ace_adapter.cpp index 4f2dc804..9ff87a79 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -279,11 +279,12 @@ APPSPAWN_STATIC int DoDlopenLibs(const cJSON *root, ParseJsonContext *context) uint32_t libsCount = (uint32_t)cJSON_GetArraySize(systemLibs); for (uint32_t i = 0; i < libsCount; ++i) { const char *libName = cJSON_GetStringValue(cJSON_GetArrayItem(systemLibs, i)); - if (libName == nullptr) { + char reaLibPath[PATH_MAX] = {0}; + if (libName == nullptr || realpath(libName, reaLibPath) == nullptr) { continue; } - APPSPAWN_LOGV("libName %{public}s", libName); - void *lib = dlopen(libName, RTLD_LAZY); + APPSPAWN_LOGV("reaLibPath %{public}s", reaLibPath); + void *lib = dlopen(reaLibPath, RTLD_LAZY); if (lib == nullptr) { APPSPAWN_LOGE("FAILED to dlopen %{public}s %{public}s", libName, dlerror()); } -- Gitee From 9de989fdfe5c3d46561d7ed8d9d7b953b34c7b66 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Thu, 16 Jan 2025 16:52:13 +0800 Subject: [PATCH 113/148] sync test code Signed-off-by: nianyuu --- .../appspawnserver_fuzzer.cpp | 157 ---- .../appspawnserver_fuzzer.h | 19 - .../appspawnserver_fuzzer/corpus/init | 14 - .../appspawnserver_fuzzer/project.xml | 25 - .../clienttest/app_spawn_client_destory.cpp | 142 ---- .../clienttest/app_spawn_client_init.cpp | 117 --- .../clienttest/app_spawn_client_send.cpp | 158 ---- .../clienttest/app_spawn_module_test.cpp | 710 ------------------ .../clienttest/app_spawn_notify_test.cpp | 129 ---- .../clienttest/appspawn_client_close_test.cpp | 105 --- .../appspawn_client_connect_test.cpp | 175 ----- .../clienttest/appspawn_client_test.cpp | 112 --- .../appspawn_client_tryconnect_test.cpp | 118 --- util/src/appspawn_utils.c | 2 +- 14 files changed, 1 insertion(+), 1982 deletions(-) delete mode 100644 test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.cpp delete mode 100644 test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.h delete mode 100644 test/fuzztest/appspawnserver_fuzzer/corpus/init delete mode 100644 test/fuzztest/appspawnserver_fuzzer/project.xml delete mode 100644 test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_destory.cpp delete mode 100644 test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_init.cpp delete mode 100644 test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_send.cpp delete mode 100644 test/unittest/app_spawn_standard_test/clienttest/app_spawn_module_test.cpp delete mode 100644 test/unittest/app_spawn_standard_test/clienttest/app_spawn_notify_test.cpp delete mode 100644 test/unittest/app_spawn_standard_test/clienttest/appspawn_client_close_test.cpp delete mode 100644 test/unittest/app_spawn_standard_test/clienttest/appspawn_client_connect_test.cpp delete mode 100644 test/unittest/app_spawn_standard_test/clienttest/appspawn_client_test.cpp delete mode 100644 test/unittest/app_spawn_standard_test/clienttest/appspawn_client_tryconnect_test.cpp diff --git a/test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.cpp b/test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.cpp deleted file mode 100644 index 2afb1aac..00000000 --- a/test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.cpp +++ /dev/null @@ -1,157 +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 "appspawnserver_fuzzer.h" -#include -#include "appspawn_server.h" - -namespace OHOS { - - // Fuzz测试: AppSpawnExecuteClearEnvHook - int FuzzerAppSpawnExecuteClearEnvHook(const uint8_t *data, size_t size) - { - if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*)) { - return 0; - } - - AppSpawnContent *content = reinterpret_cast(const_cast(data)); - AppSpawnClient *client = reinterpret_cast(const_cast(data + - sizeof(AppSpawnContent*))); - - // 调用待测试函数 - AppSpawnExecuteClearEnvHook(content, client); - return 0; - } - - // Fuzz测试: AppSpawnExecuteSpawningHook - int FuzzerAppSpawnExecuteSpawningHook(const uint8_t *data, size_t size) - { - if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*)) { - return 0; - } - AppSpawnContent *content = reinterpret_cast(const_cast(data)); - AppSpawnClient *client = reinterpret_cast(const_cast(data + - sizeof(AppSpawnContent*))); - - // 调用待测试函数 - AppSpawnExecuteSpawningHook(content, client); - return 0; - } - - // Fuzz测试: AppSpawnExecutePreReplyHook - int FuzzerAppSpawnExecutePreReplyHook(const uint8_t *data, size_t size) - { - if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*)) { - return 0; - } - AppSpawnContent *content = reinterpret_cast(const_cast(data)); - AppSpawnClient *client = reinterpret_cast(const_cast(data + - sizeof(AppSpawnContent*))); - - // 调用待测试函数 - AppSpawnExecutePreReplyHook(content, client); - return 0; - } - - // Fuzz测试: AppSpawnExecutePostReplyHook - int FuzzerAppSpawnExecutePostReplyHook(const uint8_t *data, size_t size) - { - if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*)) { - return 0; - } - AppSpawnContent *content = reinterpret_cast(const_cast(data)); - AppSpawnClient *client = reinterpret_cast(const_cast(data + - sizeof(AppSpawnContent*))); - - // 调用待测试函数 - AppSpawnExecutePostReplyHook(content, client); - return 0; - } - - // Fuzz测试: AppSpawnEnvClear - int FuzzerAppSpawnEnvClear(const uint8_t *data, size_t size) - { - if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*)) { - return 0; - } - AppSpawnContent *content = reinterpret_cast(const_cast(data)); - AppSpawnClient *client = reinterpret_cast(const_cast(data + - sizeof(AppSpawnContent*))); - - // 调用待测试函数 - AppSpawnEnvClear(content, client); - return 0; - } - - // Fuzz测试: AppSpawnProcessMsg - int FuzzerAppSpawnProcessMsg(const uint8_t *data, size_t size) - { - if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*) + sizeof(pid_t)) { - return 0; - } - - AppSpawnContent *content = reinterpret_cast(const_cast(data)); - AppSpawnClient *client = reinterpret_cast(const_cast(data + - sizeof(AppSpawnContent*))); - pid_t *childPid = reinterpret_cast(const_cast(data + - sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*))); - - // 调用待测试函数 - AppSpawnProcessMsg(content, client, childPid); - return 0; - } - - // Fuzz测试: ProcessExit - int FuzzerProcessExit(const uint8_t *data, size_t size) - { - if (size < sizeof(int)) { - return 0; - } - int code = *reinterpret_cast(data); - - // 调用待测试函数 - ProcessExit(code); - return 0; - } - - // Fuzz测试: AppSpawnChild - int FuzzerAppSpawnChild(const uint8_t *data, size_t size) - { - if (size < sizeof(AppSpawnContent*) + sizeof(AppSpawnClient*)) { - return 0; - } - AppSpawnContent *content = reinterpret_cast(const_cast(data)); - AppSpawnClient *client = reinterpret_cast(const_cast(data + - sizeof(AppSpawnContent*))); - - // 调用待测试函数 - AppSpawnChild(content, client); - return 0; - } -} -/* Fuzzer entry point */ -int FuzzerTestOneInput(const uint8_t *data, size_t size) -{ - /* Run your code on data */ - OHOS::FuzzerAppSpawnExecuteClearEnvHook(data, size); - OHOS::FuzzerAppSpawnExecuteSpawningHook(data, size); - OHOS::FuzzerAppSpawnExecutePreReplyHook(data, size); - OHOS::FuzzerAppSpawnExecutePostReplyHook(data, size); - OHOS::FuzzerAppSpawnEnvClear(data, size); - OHOS::FuzzerAppSpawnProcessMsg(data, size); - OHOS::FuzzerProcessExit(data, size); - OHOS::FuzzerAppSpawnChild(data, size); - return 0; -} \ No newline at end of file diff --git a/test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.h b/test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.h deleted file mode 100644 index e5eee134..00000000 --- a/test/fuzztest/appspawnserver_fuzzer/appspawnserver_fuzzer.h +++ /dev/null @@ -1,19 +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. - */ - -#ifndef APPSPAWNSERVER_FUZZER -#define APPSPAWNSERVER_FUZZER -#define FUZZ_PROJECT_NAME "appspawnserver_fuzzer" -#endif // appspawnserver_fuzzer \ No newline at end of file diff --git a/test/fuzztest/appspawnserver_fuzzer/corpus/init b/test/fuzztest/appspawnserver_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd..00000000 --- a/test/fuzztest/appspawnserver_fuzzer/corpus/init +++ /dev/null @@ -1,14 +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. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/appspawnserver_fuzzer/project.xml b/test/fuzztest/appspawnserver_fuzzer/project.xml deleted file mode 100644 index 949d03ef..00000000 --- a/test/fuzztest/appspawnserver_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 100 - - 30 - - 2048 - - diff --git a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_destory.cpp b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_destory.cpp deleted file mode 100644 index b04174f5..00000000 --- a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_destory.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2024-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 "appspawn.h" -#include "appspawn_hook.h" -#include "appspawn_manager.h" -#include "appspawn_modulemgr.h" -#include "appspawn_permission.h" -#include "appspawn_sandbox.h" -#include "appspawn_utils.h" -#include "appspawn_server.h" -#include "securec.h" - -#include "app_spawn_stub.h" -#include "app_spawn_test_helper.h" - -namespace OHOS { - - // 常量定义 - constexpr int APPSPAWN_SYSTEM_ERROR = -1; - constexpr int CLIENT_COUNT = 4; - - // 使用智能指针来管理资源 - using AppSpawnClientHandle = std::unique_ptr; - - struct AppSpawnReqMsgMgr { - ClientType type; - int socketId; - std::mutex mutex; - }; - - class AppSpawnClientDestroyTest : public ::testing::Test { - protected: - void SetUp() override - { - // 初始化客户端实例为空 - for (auto &client : g_clientInstance) { - client.reset(); - } - } - - void TearDown() override - { - // 不需要手动释放资源,unique_ptr 会自动清理 - } - - // 使用 std::array 管理客户端实例 - std::array g_clientInstance{}; - }; - - // 测试:验证无效的 handle 返回错误 - TEST_F(AppSpawnClientDestroyTest, TestNullHandle) - { - int ret = AppSpawnClientDestroy(nullptr); - EXPECT_EQ(ret, APPSPAWN_SYSTEM_ERROR); - } - - // 测试:验证正常销毁流程 - TEST_F(AppSpawnClientDestroyTest, TestValidHandle) - { - // 创建一个有效的 AppSpawnReqMsgMgr 实例 - auto reqMgr = std::make_unique(); - - reqMgr->type = ClientType::AppSpawn; - reqMgr->socketId = 123; // 模拟一个有效的 socketId - - // 将这个实例放入全局实例中 - g_clientInstance[static_cast(ClientType::AppSpawn)] = std::move(reqMgr); - - // 调用销毁函数 - int ret = AppSpawnClientDestroy(g_clientInstance[static_cast(ClientType::AppSpawn)].get()); - EXPECT_EQ(ret, 0); - - // 验证销毁后的实例为空 - EXPECT_EQ(g_clientInstance[static_cast(ClientType::AppSpawn)], nullptr); - } - - // 测试:验证互斥锁是否正常工作 - TEST_F(AppSpawnClientDestroyTest, TestMutexProtection) - { - // 创建一个有效的 AppSpawnReqMsgMgr 实例 - auto reqMgr = std::make_unique(); - - reqMgr->type = ClientType::AppSpawn; - reqMgr->socketId = 123; // 模拟一个有效的 socketId - - // 将这个实例放入全局实例中 - g_clientInstance[static_cast(ClientType::AppSpawn)] = std::move(reqMgr); - - // 在不同线程中测试互斥锁的保护 - std::thread t([&]() - { - int ret = AppSpawnClientDestroy(g_clientInstance[static_cast(ClientType::AppSpawn)].get()); - EXPECT_EQ(ret, 0); }); - - // 等待线程完成 - t.join(); - - // 验证销毁后的实例为空 - EXPECT_EQ(g_clientInstance[static_cast(ClientType::AppSpawn)], nullptr); - } - - // 测试:验证 socketId 小于 0 时不关闭套接字 - TEST_F(AppSpawnClientDestroyTest, TestNoSocketCloseWhenSocketIdNegative) - { - // 创建一个没有有效 socketId 的实例 - auto reqMgr = std::make_unique(); - - reqMgr->type = ClientType::AppSpawn; - reqMgr->socketId = -1; // 模拟无效的 socketId - - // 将这个实例放入全局实例中 - g_clientInstance[static_cast(ClientType::AppSpawn)] = std::move(reqMgr); - - // 调用销毁函数 - int ret = AppSpawnClientDestroy(g_clientInstance[static_cast(ClientType::AppSpawn)].get()); - EXPECT_EQ(ret, 0); - - // 验证销毁后的实例为空 - EXPECT_EQ(g_clientInstance[static_cast(ClientType::AppSpawn)], nullptr); - } - -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_init.cpp b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_init.cpp deleted file mode 100644 index 48f75eb3..00000000 --- a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_init.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2024-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 "appspawn.h" -#include "appspawn_hook.h" -#include "appspawn_manager.h" -#include "appspawn_modulemgr.h" -#include "appspawn_permission.h" -#include "appspawn_sandbox.h" - -#include "appspawn_utils.h" -#include "appspawn_server.h" -#include "securec.h" - -#include "app_spawn_stub.h" -#include "app_spawn_test_helper.h" - -// 常量定义 -namespace OHOS { - const std::string CJAPPSPAWN_SERVICE_NAME = "CJAppSpawn"; - const std::string NWEBSPAWN_SERVICE_NAME = "NWebSpawn"; - const std::string NATIVESPAWN_SERVICE_NAME = "NativeSpawn"; - const std::string NWEBSPAWN_SOCKET_NAME = "SomeNWebSocketName"; -} - -// 测试用例类 -class AppSpawnClientInitTest : public ::testing::Test { -protected: - void SetUp() {} -}; - -// 测试:验证参数校验 -TEST_F(AppSpawnClientInitTest, TestInvalidArguments) -{ - AppSpawnClientHandle handle = nullptr; - - // 测试 serviceName 为 nullptr - int ret = AppSpawnClientInit(nullptr, &handle); - EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); - - // 测试 handle 为 nullptr - ret = AppSpawnClientInit(OHOS::CJAPPSPAWN_SERVICE_NAME.c_str(), nullptr); - EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); -} - -// 测试:验证正确的客户端类型选择 -TEST_F(AppSpawnClientInitTest, TestClientTypeSelection) -{ - AppSpawnClientHandle handle = nullptr; - - // 测试 CJAPPSPAWN_SERVER_NAME - int ret = AppSpawnClientInit(OHOS::CJAPPSPAWN_SERVICE_NAME.c_str(), &handle); - - EXPECT_EQ(ret, 0); - EXPECT_EQ(handle, g_clientInstance[CLIENT_FOR_CJAPPSPAWN]); - - // 测试 NWEBSPAWN_SERVER_NAME - ret = AppSpawnClientInit(OHOS::NWEBSPAWN_SERVICE_NAME.c_str(), &handle); - - EXPECT_EQ(ret, 0); - EXPECT_EQ(handle, g_clientInstance[CLIENT_FOR_NWEBSPAWN]); - - // 测试 NATIVESPAWN_SERVER_NAME - ret = AppSpawnClientInit(OHOS::NATIVESPAWN_SERVICE_NAME.c_str(), &handle); - - EXPECT_EQ(ret, 0); - EXPECT_EQ(handle, g_clientInstance[CLIENT_FOR_NATIVESPAWN]); - - // 测试包含 NWEBSPAWN_SOCKET_NAME 的字符串 - ret = AppSpawnClientInit(OHOS::NWEBSPAWN_SOCKET_NAME.c_str(), &handle); - - EXPECT_EQ(ret, 0); - EXPECT_EQ(handle, g_clientInstance[CLIENT_FOR_NWEBSPAWN]); -} - -// 测试:验证客户端实例初始化成功 -TEST_F(AppSpawnClientInitTest, TestClientInstanceInitSuccess) -{ - AppSpawnClientHandle handle = nullptr; - - // 测试 CJAPPSPAWN_SERVER_NAME - int ret = AppSpawnClientInit(OHOS::CJAPPSPAWN_SERVICE_NAME.c_str(), &handle); - - EXPECT_EQ(ret, 0); - EXPECT_EQ(handle, g_clientInstance[CLIENT_FOR_CJAPPSPAWN]); -} - -// 测试:验证客户端实例初始化失败 -TEST_F(AppSpawnClientInitTest, TestClientInstanceInitFailure) -{ - AppSpawnClientHandle handle = nullptr; - - // 模拟 InitClientInstance 失败 - int ret = AppSpawnClientInit("InvalidService", &handle); - - EXPECT_EQ(ret, APPSPAWN_SYSTEM_ERROR); - EXPECT_EQ(handle, nullptr); // 由于初始化失败,handle 应该为 null -} \ No newline at end of file diff --git a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_send.cpp b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_send.cpp deleted file mode 100644 index dbc615d8..00000000 --- a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_client_send.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2024-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 "appspawn.h" -#include "appspawn_hook.h" -#include "appspawn_manager.h" -#include "appspawn_modulemgr.h" -#include "appspawn_permission.h" -#include "appspawn_sandbox.h" -#include "appspawn_utils.h" -#include "appspawn_server.h" -#include "securec.h" - -#include "app_spawn_stub.h" -#include "app_spawn_test_helper.h" - -#define TEST_PID 1234 - -constexpr unsigned int DEF_REQ_ID = 123; -constexpr unsigned int DEFAULT_MSG_LEN = 10; -constexpr const char *DEFAULT_PROCESS_NAME = "TestProcess"; - -// 错误码 -constexpr int APPSPAWN_ARG_INVALID = -1; - -// 测试用例类 -namespace OHOS { - - typedef void *AppSpawnClientHandle; - typedef void *AppSpawnReqMsgHandle; - - typedef struct { - int result; - int pid; - } AppSpawnResult; - - typedef struct { - unsigned int reqId; - struct { - unsigned int msgLen; - char processName[128]; - } *msg; - } AppSpawnReqMsgNode; - - typedef struct { - pthread_mutex_t mutex; - } AppSpawnReqMsgMgr; - - // 测试用例类 - class AppSpawnClientSendMsgTest : public ::testing::Test { - protected: - void SetUp() override - { - // 初始化 mutex - pthread_mutex_init(&reqMgr.mutex, nullptr); - } - - void TearDown() override - { - pthread_mutex_destroy(&reqMgr.mutex); - } - - AppSpawnReqMsgMgr reqMgr; - }; - - // 工具函数:创建一个测试用的请求节点 - std::unique_ptr CreateTestReqNode(unsigned int reqId = DEF_REQ_ID) - { - auto reqNode = std::make_unique(); - - reqNode->reqId = reqId; - reqNode->msg = std::make_uniquemsg)::element_type>(); - - reqNode->msg->msgLen = kDEFAULT_MSG_LEN; - return reqNode; - } - - // 测试:验证 result 为 nullptr 时返回 APPSPAWN_ARG_INVALID - TEST_F(AppSpawnClientSendMsgTest, TestNullResult) - { - auto reqNode = CreateTestReqNode(); - - int ret = AppSpawnClientSendMsg(&reqMgr, reqNode.get(), nullptr); - EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); - } - - // 测试:验证 reqHandle 为 nullptr 时返回 APPSPAWN_ARG_INVALID - TEST_F(AppSpawnClientSendMsgTest, TestNullReqHandle) - { - AppSpawnResult result; - - int ret = AppSpawnClientSendMsg(&reqMgr, nullptr, &result); - EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); - } - - // 测试:验证 handle 为 nullptr 时返回 APPSPAWN_ARG_INVALID - TEST_F(AppSpawnClientSendMsgTest, TestNullHandle) - { - auto reqNode = CreateTestReqNode(); - - AppSpawnResult result; - int ret = AppSpawnClientSendMsg(nullptr, reqNode.get(), &result); - EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); - } - - // 测试:验证正常的调用流程 - TEST_F(AppSpawnClientSendMsgTest, TestValidCase) - { - auto reqNode = CreateTestReqNode(); - - AppSpawnResult result; - int ret = AppSpawnClientSendMsg(&reqMgr, reqNode.get(), &result); - - // 验证返回值和 result - EXPECT_EQ(ret, 0); - EXPECT_EQ(result.result, 0); - - EXPECT_EQ(result.pid, TEST_PID); // 来自 ClientSendMsg 的模拟返回 - } - - // 测试:验证线程安全 - TEST_F(AppSpawnClientSendMsgTest, TestMutexProtection) - { - auto reqNode = CreateTestReqNode(); - AppSpawnResult result; - - // 在不同线程中调用 - std::thread t([&]() - { - int ret = AppSpawnClientSendMsg(&reqMgr, reqNode.get(), &result); - - EXPECT_EQ(ret, 0); - EXPECT_EQ(result.result, 0); - - EXPECT_EQ(result.pid, TEST_PID); }); - - t.join(); - } -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_module_test.cpp b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_module_test.cpp deleted file mode 100644 index f40fd620..00000000 --- a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_module_test.cpp +++ /dev/null @@ -1,710 +0,0 @@ -/* - * Copyright (c) 2024-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 // For strcmp - -// 假设这些类型和全局变量已定义在目标代码中 -#define MODULE_DEFAULT 0 -#define APPSPAWN_TEST 1 // 让测试用例在测试模式下编译 -#define MODULE_MAX 10 -#define MODULE_DEFAULT 0 -// 模拟的结构和函数定义 -struct ModuleMgr { - const char *moduleName; - // 假设我们有一个模块管理器的接口 - void *moduleMgr; -}; - -ModuleMgr g_moduleMgr[MODULE_MAX]; // 这里只有一个模块 - -int ModuleMgrCreate(const char *name) -{ - // 模拟创建模块管理器 - return 1; // 假设成功创建 -} - -int ModuleMgrInstall(void *mgr, const char *moduleName, int flag, void *data) -{ - // 模拟安装模块 - return 0; // 假设安装成功 -} - -int AppSpawnModuleMgrInstall(const char *moduleName); - -namespace OHOS { - // 测试类 - class AppSpawnModuleMgrInstallTest : public ::testing::Test { - protected: - // 在每个测试之前执行 - void SetUp() override - { - // 这里可以对 `g_moduleMgr` 进行初始化,以确保每个测试环境独立 - g_moduleMgr[MODULE_DEFAULT].moduleMgr = nullptr; // 初始时模块管理器为空 - } - }; - - // 测试用例:传入 nullptr 参数时,函数应该返回 -1 - TEST_F(AppSpawnModuleMgrInstallTest, TestNullModuleName) - { - EXPECT_EQ(AppSpawnModuleMgrInstall(nullptr), -1); - } - - // 测试用例:`g_moduleMgr[type].moduleMgr` 为 nullptr 时,应该调用 `ModuleMgrCreate` 创建模块管理器 - TEST_F(AppSpawnModuleMgrInstallTest, TestCreateModuleMgrWhenNull) - { - // 检查模块管理器是否为空 - EXPECT_EQ(g_moduleMgr[MODULE_DEFAULT].moduleMgr, nullptr); - - // 调用函数 - EXPECT_EQ(AppSpawnModuleMgrInstall("testModule"), 0); - - // 检查模块管理器是否已经创建 - EXPECT_NE(g_moduleMgr[MODULE_DEFAULT].moduleMgr, nullptr); - } - - // 测试用例:`ModuleMgrInstall` 成功时,函数返回 0 - TEST_F(AppSpawnModuleMgrInstallTest, TestModuleInstallSuccess) - { - g_moduleMgr[MODULE_DEFAULT].moduleMgr = reinterpret_cast(1); - - // 传入有效的模块名 - EXPECT_EQ(AppSpawnModuleMgrInstall("testModule"), 0); - } - - // 测试用例:如果 `ModuleMgrCreate` 失败,返回 -1 - TEST_F(AppSpawnModuleMgrInstallTest, TestCreateFail) - { - // 模拟 `ModuleMgrCreate` 失败 - g_moduleMgr[MODULE_DEFAULT].moduleMgr = nullptr; // 模拟创建失败 - - // 传入有效的模块名 - EXPECT_EQ(AppSpawnModuleMgrInstall("testModule"), -1); - } - -#ifdef APPSPAWN_TEST - // 测试用例:如果在测试模式下,函数应该直接返回 0 - TEST_F(AppSpawnModuleMgrInstallTest, TestInTestMode) - { - EXPECT_EQ(AppSpawnModuleMgrInstall("testModule"), 0); - } -#endif - - // 测试用例 1:`type` 超出范围时,应该直接返回,不做任何操作 - TEST_F(AppSpawnModuleMgrUnInstallTest, TestTypeOutOfRange) - { - // `type` 小于 0 - AppSpawnModuleMgrUnInstall(-1); - for (int i = 0; i < MODULE_MAX; ++i) - { - EXPECT_EQ(g_moduleMgr[i].moduleMgr, nullptr); - } - - // `type` 大于等于 MODULE_MAX - AppSpawnModuleMgrUnInstall(MODULE_MAX); - for (int i = 0; i < MODULE_MAX; ++i) - { - EXPECT_EQ(g_moduleMgr[i].moduleMgr, nullptr); - } - } - - // 测试用例 2:`g_moduleMgr[type].moduleMgr` 为 nullptr 时,应该不进行任何操作 - TEST_F(AppSpawnModuleMgrUnInstallTest, TestModuleMgrIsNull) - { - // `g_moduleMgr[MODULE_DEFAULT].moduleMgr` 依然是 nullptr - AppSpawnModuleMgrUnInstall(MODULE_DEFAULT); - EXPECT_EQ(g_moduleMgr[MODULE_DEFAULT].moduleMgr, nullptr); // 确保没有改变 - } - - // 测试用例 3:`g_moduleMgr[type].moduleMgr` 不为 nullptr 时,应该销毁模块并将其设为 nullptr - TEST_F(AppSpawnModuleMgrUnInstallTest, TestUninstallModule) - { - // 设置 `g_moduleMgr[MODULE_DEFAULT].moduleMgr` 为一个非 nullptr 值 - void *mockMgr = reinterpret_cast(1); - g_moduleMgr[MODULE_DEFAULT].moduleMgr = mockMgr; - - // 调用卸载函数 - AppSpawnModuleMgrUnInstall(MODULE_DEFAULT); - - // 检查模块是否已被销毁,并且值是否已设为 nullptr - EXPECT_EQ(g_moduleMgr[MODULE_DEFAULT].moduleMgr, nullptr); - } - - // 测试用例 4:`g_moduleMgr` 的其他位置没有影响 - TEST_F(AppSpawnModuleMgrUnInstallTest, TestOtherModuleUnchanged) - { - // 设置 `g_moduleMgr[1].moduleMgr` 为一个非 nullptr 值 - void *mockMgr = reinterpret_cast(1); - g_moduleMgr[1].moduleMgr = mockMgr; - - // 调用卸载函数,使用不同的 `type` - AppSpawnModuleMgrUnInstall(MODULE_DEFAULT); // 不影响 g_moduleMgr[1] - - // 检查 `g_moduleMgr[1]` 是否仍然有效 - EXPECT_EQ(g_moduleMgr[1].moduleMgr, mockMgr); - } - - // 测试用例 5:`type` 为一个有效值,但模块已经被销毁的情况 - TEST_F(AppSpawnModuleMgrUnInstallTest, TestModuleAlreadyUninstalled) - { - // 初始化一个模块管理器并销毁它 - void *mockMgr = reinterpret_cast(1); - g_moduleMgr[MODULE_DEFAULT].moduleMgr = mockMgr; - - // 手动销毁模块 - ModuleMgrDestroy(mockMgr); - g_moduleMgr[MODULE_DEFAULT].moduleMgr = nullptr; - - // 调用卸载函数 - AppSpawnModuleMgrUnInstall(MODULE_DEFAULT); - - // 检查模块是否仍然为空 - EXPECT_EQ(g_moduleMgr[MODULE_DEFAULT].moduleMgr, nullptr); - } - - // 测试用例 1:`type` 超出范围时,应该返回 -1 - TEST_F(AppSpawnLoadAutoRunModulesTest, TestTypeOutOfRange) - { - EXPECT_EQ(AppSpawnLoadAutoRunModules(-1), -1); // `type` 小于 0 - EXPECT_EQ(AppSpawnLoadAutoRunModules(MODULE_MAX), -1); // `type` 大于等于 MODULE_MAX - } - - // 测试用例 2:模块已加载时,返回 0 - TEST_F(AppSpawnLoadAutoRunModulesTest, TestModuleAlreadyLoaded) - { - // 设置模块已经加载 - g_moduleMgr[MODULE_DEFAULT].moduleMgr = reinterpret_cast(1); // 模拟模块已加载 - - // 调用函数,应该返回 0 - EXPECT_EQ(AppSpawnLoadAutoRunModules(MODULE_DEFAULT), 0); - } - - // 测试用例 3:模块未加载时,调用 `ModuleMgrScan` 加载模块并返回 0 - TEST_F(AppSpawnLoadAutoRunModulesTest, TestModuleNotLoaded) - { - // `g_moduleMgr[MODULE_DEFAULT].moduleMgr` 初始为 nullptr - - // 调用函数,应该返回 0,并加载模块 - EXPECT_EQ(AppSpawnLoadAutoRunModules(MODULE_DEFAULT), 0); - // 检查 `moduleMgr` 是否已被加载 - EXPECT_NE(g_moduleMgr[MODULE_DEFAULT].moduleMgr, nullptr); - } - -// 测试用例 4:`APPSPAWN_TEST` 环境下,应该跳过 `ModuleMgrScan` 的调用并直接返回 0 -#ifdef APPSPAWN_TEST - TEST_F(AppSpawnLoadAutoRunModulesTest, TestInTestEnvironment) - { - // 在 APPSPAWN_TEST 环境下,`ModuleMgrScan` 被跳过,直接返回 0 - EXPECT_EQ(AppSpawnLoadAutoRunModules(MODULE_DEFAULT), 0); - } -#endif - - // 测试用例 5:模块加载失败时,返回 -1 - TEST_F(AppSpawnLoadAutoRunModulesTest, TestModuleLoadFailure) - { - // 修改 ModuleMgrScan 让它返回 NULL,模拟加载失败 - void *(*originalModuleMgrScan)(const char *) = ModuleMgrScan; - ModuleMgrScan = [](const char *moduleName) -> void * - { return nullptr; }; - - // 调用函数,应该返回 -1 - EXPECT_EQ(AppSpawnLoadAutoRunModules(MODULE_DEFAULT), -1); - - // 恢复原始的 ModuleMgrScan 函数 - ModuleMgrScan = originalModuleMgrScan; - } - - // 测试用例 1:g_appspawnHookMgr 已经初始化为非 nullptr - TEST_F(GetAppSpawnHookMgrTest, TestHookMgrAlreadyInitialized) - { - // 先初始化 g_appspawnHookMgr - g_appspawnHookMgr = HookMgrCreate("test"); - - // 调用 GetAppSpawnHookMgr,应该返回已经存在的 g_appspawnHookMgr - HOOK_MGR *hookMgr = GetAppSpawnHookMgr(); - EXPECT_EQ(hookMgr, g_appspawnHookMgr); - EXPECT_STREQ(hookMgr->name, "test"); - } - - // 测试用例 2:g_appspawnHookMgr 为 nullptr 时,调用 HookMgrCreate - TEST_F(GetAppSpawnHookMgrTest, TestHookMgrNotInitialized) - { - // g_appspawnHookMgr 初始为 nullptr - - // 调用 GetAppSpawnHookMgr,应该创建新的 g_appspawnHookMgr - HOOK_MGR *hookMgr = GetAppSpawnHookMgr(); - EXPECT_NE(hookMgr, nullptr); - EXPECT_STREQ(hookMgr->name, "appspawn"); - - // 确认 g_appspawnHookMgr 已被初始化 - EXPECT_EQ(g_appspawnHookMgr, hookMgr); - } - - // 测试用例 3:多次调用 GetAppSpawnHookMgr 返回同一个实例 - TEST_F(GetAppSpawnHookMgrTest, TestMultipleCallsReturnSameInstance) - { - // g_appspawnHookMgr 初始为 nullptr - - // 第一次调用,创建并返回新的实例 - HOOK_MGR *hookMgr1 = GetAppSpawnHookMgr(); - EXPECT_NE(hookMgr1, nullptr); - EXPECT_STREQ(hookMgr1->name, "appspawn"); - - // 第二次调用,返回相同的实例 - HOOK_MGR *hookMgr2 = GetAppSpawnHookMgr(); - EXPECT_EQ(hookMgr1, hookMgr2); - EXPECT_STREQ(hookMgr2->name, "appspawn"); - } - - // 测试用例 4:确保返回的对象的 name 是我们期望的 - TEST_F(GetAppSpawnHookMgrTest, TestCorrectName) - { - // g_appspawnHookMgr 初始为 nullptr - - // 调用 GetAppSpawnHookMgr,应该创建新的 g_appspawnHookMgr - HOOK_MGR *hookMgr = GetAppSpawnHookMgr(); - EXPECT_EQ(hookMgr->name, "appspawn"); - } - - // 测试用例 1:更新最小时间 - TEST_F(UpdateAppSpawnTimeTest, TestUpdateMinTime) - { - // 初始值为 INT_MAX 和 0 - GetAppSpawnMgr()->spawnTime.minAppspawnTime = INT_MAX; - GetAppSpawnMgr()->spawnTime.maxAppspawnTime = 0; - - // 调用 UpdateAppSpawnTime 来更新最小时间 - UpdateAppSpawnTime(100); - - // 验证最小时间已更新 - EXPECT_EQ(GetAppSpawnMgr()->spawnTime.minAppspawnTime, 100); - - // 验证日志输出 - std::string captured = testing::internal::CaptureStdout(); - EXPECT_NE(captured.find("spawn min time: 100"), std::string::npos); - } - - // 测试用例 2:更新最大时间 - TEST_F(UpdateAppSpawnTimeTest, TestUpdateMaxTime) - { - // 初始值为 INT_MAX 和 0 - GetAppSpawnMgr()->spawnTime.minAppspawnTime = INT_MAX; - GetAppSpawnMgr()->spawnTime.maxAppspawnTime = 0; - - // 调用 UpdateAppSpawnTime 来更新最大时间 - UpdateAppSpawnTime(500); - - // 验证最大时间已更新 - EXPECT_EQ(GetAppSpawnMgr()->spawnTime.maxAppspawnTime, 500); - - // 验证日志输出 - std::string captured = testing::internal::CaptureStdout(); - EXPECT_NE(captured.find("spawn max time: 500"), std::string::npos); - } - - // 测试用例 3:不更新最小时间和最大时间 - TEST_F(UpdateAppSpawnTimeTest, TestNoUpdate) - { - // 初始值为 100 和 500 - GetAppSpawnMgr()->spawnTime.minAppspawnTime = 100; - GetAppSpawnMgr()->spawnTime.maxAppspawnTime = 500; - - // 调用 UpdateAppSpawnTime,应该不做更新 - UpdateAppSpawnTime(200); - - // 验证最小时间和最大时间没有变化 - EXPECT_EQ(GetAppSpawnMgr()->spawnTime.minAppspawnTime, 100); - EXPECT_EQ(GetAppSpawnMgr()->spawnTime.maxAppspawnTime, 500); - - // 验证没有日志输出 - std::string captured = testing::internal::CaptureStdout(); - EXPECT_EQ(captured, ""); - } - - // 测试用例 1:验证正常执行和时间差计算 - TEST_F(PostHookExecTest, TestNormalExecution) - { - // 模拟 perLoadEnd 时间,假设它比 perLoadStart 大 1秒 - spawnMgr->perLoadEnd.tv_sec = 1001; - spawnMgr->perLoadEnd.tv_nsec = 500000000; // 1001s 500ms - - HOOK_INFO hookInfo = {1, 10}; // stage 1, prio 10 - int executionRetVal = 0; // 执行结果,假设为0 - - // 捕获输出 - std::string captured = testing::internal::CaptureStdout(); - - // 调用 PostHookExec - PostHookExec(&hookInfo, &hookArg, executionRetVal); - - // 验证 UpdateAppSpawnTime 被调用,检查时间差是否正确计算 - uint64_t expectedDiff = 1000000000; // 1秒 = 1e9 纳秒 - EXPECT_NE(captured.find("Updated AppSpawn Time: " + std::to_string(expectedDiff)), std::string::npos); - - // 验证日志输出内容是否包含预期的 Hook 信息 - EXPECT_NE(captured.find("Hook stage: 1 prio: 10 end time 1000000000 ns result: 0"), std::string::npos); - } - - // 测试用例 2:验证时间差为零时的行为 - TEST_F(PostHookExecTest, TestZeroTimeDifference) - { - // 模拟 perLoadEnd 时间与 perLoadStart 时间相同 - spawnMgr->perLoadEnd.tv_sec = 1000; - spawnMgr->perLoadEnd.tv_nsec = 500000000; // 1000s 500ms - - HOOK_INFO hookInfo = {1, 10}; // stage 1, prio 10 - int executionRetVal = 0; // 执行结果,假设为0 - - // 捕获输出 - std::string captured = testing::internal::CaptureStdout(); - - // 调用 PostHookExec - PostHookExec(&hookInfo, &hookArg, executionRetVal); - - // 验证 UpdateAppSpawnTime 被调用,检查时间差是否为零 - uint64_t expectedDiff = 0; - EXPECT_NE(captured.find("Updated AppSpawn Time: " + std::to_string(expectedDiff)), std::string::npos); - - // 验证日志输出内容是否包含预期的 Hook 信息 - EXPECT_NE(captured.find("Hook stage: 1 prio: 10 end time 0 ns result: 0"), std::string::npos); - } - - // 测试用例 1:验证 content 为 nullptr 时返回 APPSPAWN_ARG_INVALID - TEST_F(ServerStageHookExecuteTest, TestContentNull) - { - AppSpawnContent *nullContent = nullptr; - - int ret = ServerStageHookExecute(STAGE_SERVER_PRELOAD, nullContent); - - EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); - } - - // 测试用例 2:验证无效 stage 返回 APPSPAWN_ARG_INVALID - TEST_F(ServerStageHookExecuteTest, TestInvalidStage) - { - // 假设 STAGE_SERVER_EXIT 之后有个无效的 stage - AppSpawnHookStage invalidStage = static_cast(999); // 无效的阶段 - - int ret = ServerStageHookExecute(invalidStage, content); - - EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); - } - - // 测试用例 3:验证有效的 content 和 stage 执行成功 - TEST_F(ServerStageHookExecuteTest, TestValidExecution) - { - // 使用有效的 stage - AppSpawnHookStage validStage = STAGE_SERVER_PRELOAD; - - // 捕获日志输出 - std::string captured = testing::internal::CaptureStdout(); - - int ret = ServerStageHookExecute(validStage, content); - - // 期望钩子执行成功 - EXPECT_EQ(ret, 0); // 假设钩子返回值为 0 - - // 验证日志是否包含正确的钩子执行信息 - EXPECT_NE(captured.find("Execute hook [0] result 0"), std::string::npos); // STAGE_SERVER_PRELOAD 对应值为 0 - } - - // 测试用例 4:验证无效的钩子执行返回 ERR_NO_HOOK_STAGE - TEST_F(ServerStageHookExecuteTest, TestNoHookStage) - { - // 模拟钩子返回 ERR_NO_HOOK_STAGE - HookMgrExecute = [](void *, AppSpawnHookStage, void *, HOOK_EXEC_OPTIONS *) - { - return ERR_NO_HOOK_STAGE; - }; - - AppSpawnHookStage validStage = STAGE_SERVER_EXIT; - - int ret = ServerStageHookExecute(validStage, content); - - // 期望返回 0 因为 ERR_NO_HOOK_STAGE 被转换为 0 - EXPECT_EQ(ret, 0); - } - - // 测试用例 1:验证 hook 为 nullptr 时返回 APPSPAWN_ARG_INVALID - TEST_F(AddServerStageHookTest, TestHookNull) - { - ServerStageHook nullHook = nullptr; - - int ret = AddServerStageHook(STAGE_SERVER_PRELOAD, 10, nullHook); - - EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); - } - - // 测试用例 2:验证无效的 stage 返回 APPSPAWN_ARG_INVALID - TEST_F(AddServerStageHookTest, TestInvalidStage) - { - // 假设 STAGE_SERVER_EXIT 后有个无效的 stage - AppSpawnHookStage invalidStage = static_cast(999); // 无效的阶段 - - ServerStageHook validHook = ServerStageHookRun; - - int ret = AddServerStageHook(invalidStage, 10, validHook); - - EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); - } - - // 测试用例 3:验证有效的 stage 和 hook 时能够成功添加钩子 - TEST_F(AddServerStageHookTest, TestValidHookAndStage) - { - AppSpawnHookStage validStage = STAGE_SERVER_PRELOAD; - ServerStageHook validHook = ServerStageHookRun; - int prio = 10; - - // 捕获日志输出 - std::string captured = testing::internal::CaptureStdout(); - - int ret = AddServerStageHook(validStage, prio, validHook); - - // 期望返回 0,表示成功 - EXPECT_EQ(ret, 0); - - // 验证日志是否包含正确的钩子添加信息 - EXPECT_NE(captured.find("AddServerStageHook prio: 10"), std::string::npos); - } - - // 测试用例 4:验证无效的钩子(模拟钩子执行错误) - TEST_F(AddServerStageHookTest, TestHookExecutionError) - { - // 假设有一个无效的钩子 - ServerStageHook invalidHook = nullptr; // 无效钩子 - - int ret = AddServerStageHook(STAGE_SERVER_EXIT, 20, invalidHook); - - // 期望返回 APPSPAWN_ARG_INVALID,因为钩子是无效的 - EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); - } - // 测试用例 1:验证有效钩子函数的调用 - TEST_F(AppSpawnHookRunTest, ValidHookExecution) - { - int result = AppSpawnHookRun(&hookInfo, &executionContext); - - // 验证返回值是否符合预期,表示钩子被正确调用 - EXPECT_EQ(result, 42); - } - - // 测试用例 2:验证执行上下文为空的情况 - TEST_F(AppSpawnHookRunTest, NullExecutionContext) - { - int result = AppSpawnHookRun(&hookInfo, nullptr); - - // 验证如果 executionContext 为 NULL,函数应返回 0 或其它合适的错误码 - EXPECT_EQ(result, 0); // 这里假设返回 0 - } - - // 测试用例 3:验证 hookCookie 为 nullptr 时的行为 - TEST_F(AppSpawnHookRunTest, NullHookCookie) - { - hookInfo.hookCookie = nullptr; // 设置钩子为 nullptr - - int result = AppSpawnHookRun(&hookInfo, &executionContext); - - // 验证如果 hookCookie 为 NULL,函数应返回某个错误码或异常 - EXPECT_EQ(result, 0); // 这里假设返回 0 - } - - // 测试用例 4:验证钩子函数为其它实现时的调用 - TEST_F(AppSpawnHookRunTest, CustomHookFunction) - { - // 定义一个新的钩子函数 - auto customHook = [](AppSpawnMgr *mgr, AppSpawningCtx *ctx) -> int - { - return 99; // 自定义钩子返回 99 - }; - - hookInfo.hookCookie = (void *)customHook; // 使用自定义钩子 - - int result = AppSpawnHookRun(&hookInfo, &executionContext); - - // 验证自定义钩子函数被正确调用 - EXPECT_EQ(result, 99); - } - - // 测试用例 1:验证正常的日志输出和时间记录 - TEST_F(PreAppSpawnHookExecTest, NormalExecution) - { - hookInfo.stage = 1; - hookInfo.prio = 5; - - // 执行 PreAppSpawnHookExec - PreAppSpawnHookExec(&hookInfo, &executionContext); - - // 验证日志输出是否符合预期 - EXPECT_NE(logStream.str().find("Hook stage: 1 prio: 5 start"), std::string::npos); - - // 验证时间是否已经被记录(tmStart 的值应大于 0) - EXPECT_GT(executionContext.tmStart.tv_sec, 0); - EXPECT_GE(executionContext.tmStart.tv_nsec, 0); - } - - // 测试用例 2:验证 executionContext 为 nullptr 时的行为 - TEST_F(PreAppSpawnHookExecTest, NullExecutionContext) - { - hookInfo.stage = 1; - hookInfo.prio = 5; - - // 执行时传入 nullptr executionContext - PreAppSpawnHookExec(&hookInfo, nullptr); - - // 验证没有崩溃,且日志正确输出 - EXPECT_NE(logStream.str().find("Hook stage: 1 prio: 5 start"), std::string::npos); - } - - // 测试用例 3:验证 hookInfo 为 nullptr 时的行为 - TEST_F(PreAppSpawnHookExecTest, NullHookInfo) - { - // 执行时传入 nullptr hookInfo - PreAppSpawnHookExec(nullptr, &executionContext); - - // 验证没有崩溃,日志是否正确 - EXPECT_EQ(logStream.str(), ""); // 如果 hookInfo 为空,日志应该没有输出 - } - - // 测试用例 4:验证时间记录 - TEST_F(PreAppSpawnHookExecTest, TimeRecorded) - { - hookInfo.stage = 1; - hookInfo.prio = 5; - - // 执行函数 - PreAppSpawnHookExec(&hookInfo, &executionContext); - - // 验证时间字段是否被正确设置 - EXPECT_GT(executionContext.tmStart.tv_sec, 0); - EXPECT_GE(executionContext.tmStart.tv_nsec, 0); - } - - // 测试用例 1:验证正常的日志输出和时间计算 - TEST_F(PostAppSpawnHookExecTest, NormalExecution) - { - hookInfo.stage = 1; - hookInfo.prio = 5; - - // 假设 tmStart 已经设置 - executionContext.tmStart.tv_sec = 10; - executionContext.tmStart.tv_nsec = 500000000; // 10.5 seconds - - // 执行 PostAppSpawnHookExec - PostAppSpawnHookExec(&hookInfo, &executionContext, 0); - - // 验证日志输出是否符合预期 - EXPECT_NE(logStream.str().find("Hook stage: 1 prio: 5 end time"), std::string::npos); - EXPECT_NE(logStream.str().find("result: 0"), std::string::npos); - - // 验证时间差是否大于 0(假设 tmEnd 被正确设置) - uint64_t diff = DiffTime(&executionContext.tmStart, &executionContext.tmEnd); - EXPECT_GT(diff, 0); - } - - // 测试用例 2:验证 executionContext 为 nullptr 时的行为 - TEST_F(PostAppSpawnHookExecTest, NullExecutionContext) - { - hookInfo.stage = 1; - hookInfo.prio = 5; - - // 执行时传入 nullptr executionContext - PostAppSpawnHookExec(&hookInfo, nullptr, 0); - - // 验证没有崩溃,且日志正确输出(虽然 executionContext 为 NULL,函数仍应正常工作) - EXPECT_NE(logStream.str().find("Hook stage: 1 prio: 5 end time"), std::string::npos); - EXPECT_NE(logStream.str().find("result: 0"), std::string::npos); - } - - // 测试用例 3:验证 hookInfo 为 nullptr 时的行为 - TEST_F(PostAppSpawnHookExecTest, NullHookInfo) - { - // 执行时传入 nullptr hookInfo - PostAppSpawnHookExec(nullptr, &executionContext, 0); - - // 验证没有崩溃,日志应该为空(没有 hookInfo 的情况下,无法输出相关信息) - EXPECT_EQ(logStream.str(), ""); - } - - // 测试用例 4:验证时间差计算 - TEST_F(PostAppSpawnHookExecTest, TimeDiffCalculation) - { - hookInfo.stage = 1; - hookInfo.prio = 5; - - // 设置 start 时间为某个已知时间 - executionContext.tmStart.tv_sec = 5; - executionContext.tmStart.tv_nsec = 100000000; // 5.1 seconds - - // 设置一个稍后的 end 时间 - executionContext.tmEnd.tv_sec = 6; - executionContext.tmEnd.tv_nsec = 200000000; // 6.2 seconds - - // 计算时间差 - uint64_t diff = DiffTime(&executionContext.tmStart, &executionContext.tmEnd); - - // 验证时间差为 1.1 秒 (1.1 * 10^9 纳秒) - EXPECT_EQ(diff, 1100000000LL); - } - - // 测试用例 1:验证传入 nullptr 参数时的行为 - TEST_F(AppSpawnHookExecuteTest, InvalidArguments) - { - // 测试 content 和 client 为 nullptr 的情况 - int ret = AppSpawnHookExecute(STAGE_PARENT_PRE_FORK, 0, nullptr, nullptr); - EXPECT_EQ(ret, -1); // 应返回 -1,表示参数无效 - - // 测试 stage 无效时的情况 - ret = AppSpawnHookExecute((AppSpawnHookStage)999, 0, &content, &client); - EXPECT_EQ(ret, -1); // 应返回 -1,表示 stage 无效 - } - - // 测试用例 2:验证日志输出和正常执行 - TEST_F(AppSpawnHookExecuteTest, ValidExecution) - { - // 测试正常的执行路径 - int ret = AppSpawnHookExecute(STAGE_PARENT_PRE_FORK, 0, &content, &client); - - EXPECT_EQ(ret, 0); // 应返回 0,表示执行成功 - - // 检查日志是否包含预期的内容 - std::string logOutput = logStream.str(); - EXPECT_NE(logOutput.find("Execute hook [0] for app: TestApp"), std::string::npos); // stage 和 app name - EXPECT_EQ(logOutput.find("Invalid arg"), std::string::npos); // 无错误日志 - } - - // 测试用例 3:验证 HookMgrExecute 调用 - TEST_F(AppSpawnHookExecuteTest, HookMgrExecuteCalled) - { - // 测试正常的钩子执行 - int ret = AppSpawnHookExecute(STAGE_CHILD_PRE_RUN, 0, &content, &client); - - EXPECT_EQ(ret, 0); // 确保返回值为0,表示执行成功 - - // 检查日志输出 - std::string logOutput = logStream.str(); - EXPECT_NE(logOutput.find("Execute hook [1] result 0"), std::string::npos); // 检查执行成功的日志 - } - - // 测试用例 4:验证无效 stage 时的行为 - TEST_F(AppSpawnHookExecuteTest, InvalidStage) - { - int ret = AppSpawnHookExecute((AppSpawnHookStage)999, 0, &content, &client); - EXPECT_EQ(ret, -1); // 应返回 -1,表示 stage 无效 - - // 检查是否有相应的错误日志 - std::string logOutput = logStream.str(); - EXPECT_NE(logOutput.find("Invalid stage"), std::string::npos); - } -} // namespace OHOS diff --git a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_notify_test.cpp b/test/unittest/app_spawn_standard_test/clienttest/app_spawn_notify_test.cpp deleted file mode 100644 index a4037423..00000000 --- a/test/unittest/app_spawn_standard_test/clienttest/app_spawn_notify_test.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2024-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 "appspawn.h" -#include "appspawn_hook.h" -#include "appspawn_manager.h" -#include "appspawn_modulemgr.h" -#include "appspawn_permission.h" -#include "appspawn_sandbox.h" -#include "appspawn_utils.h" -#include "appspawn_server.h" -#include "securec.h" - -#include "app_spawn_stub.h" -#include "app_spawn_test_helper.h" - -// 全局变量用于验证回调函数是否被调用 -bool g_callCalled = false; -int g_result = -1; -AppSpawnContent *CALL_CONTENT = nullptr; -AppSpawnClient *CALL_CLIENT = nullptr; - -// 测试用的回调函数 -void TestCallback(AppSpawnContent *content, AppSpawnClient *client, int result) -{ - g_callCalled = true; // 设置标志 - g_result = result; // 保存结果 - CALL_CONTENT = content; // 保存内容 - CALL_CLIENT = client; // 保存客户端 -} -using namespace testing; -using namespace testing::ext; - -namespace OHOS { - class NotifyResToParentTest : public testing::Test { - protected: - void SetUp() override - { - // 在每个测试前初始化 - content = new AppSpawnContent(); - client = new AppSpawnClient(); - g_callCalled = false; // 每个测试开始时重置标志 - content->notifyResToParent = nullptr; // 默认没有回调 - } - - void TearDown() override - { - // 清理资源 - delete content; - content = nullptr; - delete client; - client = nullptr; - } - - AppSpawnContent *content; - AppSpawnClient *client; - }; - - // 测试:notifyResToParent非空时,函数被正确调用 - HWTEST_F(NotifyResToParentTest, TestNotifyResToParent_001, TestSize.Level0) - { - content->notifyResToParent = TestCallback; // 设置自定义回调 - - // 调用NotifyResToParent - NotifyResToParent(content, client, 42); - - // 验证回调是否被调用,并且结果是否正确 - EXPECT_TRUE(g_callCalled); - EXPECT_EQ(g_result, 42); - EXPECT_EQ(CALL_CONTENT, content); - EXPECT_EQ(CALL_CLIENT, client); - } - - // 测试:notifyResToParent为空时,函数不被调用 - HWTEST_F(NotifyResToParentTest, TestNotifyResToParent_002, TestSize.Level0) - { - content->notifyResToParent = nullptr; // 设置回调为NULL - - // 调用NotifyResToParent - NotifyResToParent(content, client, 42); - - // 验证回调没有被调用 - EXPECT_FALSE(g_callCalled); - } - - // 测试:传递不同的result值,回调函数被正确调用 - HWTEST_F(NotifyResToParentTest, TestNotifyResToParent_003, TestSize.Level0) - { - content->notifyResToParent = TestCallback; // 设置自定义回调 - - // 测试不同的result值 - NotifyResToParent(content, client, -1); - EXPECT_TRUE(g_callCalled); - EXPECT_EQ(g_result, -1); - - // 重置回调标志 - g_callCalled = false; - - NotifyResToParent(content, client, 0); - EXPECT_TRUE(g_callCalled); - EXPECT_EQ(g_result, 0); - - // 重置回调标志 - g_callCalled = false; - - NotifyResToParent(content, client, 100); - EXPECT_TRUE(g_callCalled); - EXPECT_EQ(g_result, 100); - } -} // namespace OHOS diff --git a/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_close_test.cpp b/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_close_test.cpp deleted file mode 100644 index 00fe1625..00000000 --- a/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_close_test.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2024-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 "appspawn.h" -#include "appspawn_hook.h" -#include "appspawn_manager.h" -#include "appspawn_modulemgr.h" -#include "appspawn_permission.h" -#include "appspawn_sandbox.h" -#include "appspawn_utils.h" -#include "appspawn_server.h" -#include "securec.h" - -#include "app_spawn_stub.h" -#include "app_spawn_test_helper.h" -#define SOCKET_PORT 8080 -using namespace testing; -using namespace testing::ext; - -namespace OHOS { - class CloseClientSocketTest : public ::testing::Test { - protected: - int socketId; - - void SetUp() override - { - // 创建一个实际的 TCP socket - socketId = socket(AF_INET, SOCK_STREAM, 0); - ASSERT_GE(socketId, 0) << "Failed to create socket"; // 确保 socket 创建成功 - - // 设置一个连接目标 (假设使用本地地址) - struct sockaddr_in addr; - addr.sin_family = AF_INET; - addr.sin_port = htons(SOCKET_PORT); - addr.sin_addr.s_addr = INADDR_LOOPBACK; - - int result = connect(socketId, (struct sockaddr *)&addr, sizeof(addr)); - ASSERT_EQ(result, 0) << "Failed to connect socket"; - } - - void TearDown() override - { - if (socketId >= 0) { - close(socketId); - socketId = -1; - } - } - }; - - // 测试正常关闭的情况 - TEST_F(CloseClientSocketTest, TestCloseValidSocket) - { - int socketIdValid = socketId; // 使用有效的 socketId - EXPECT_NO_THROW(CloseClientSocket(socketIdValid)); // 调用 CloseClientSocket,应该正常关闭 - - // 检查 socket 是否已经关闭 - char buffer[10]; - int result = recv(socketIdValid, buffer, sizeof(buffer), MSG_DONTWAIT); - - EXPECT_EQ(result, -1); // 如果套接字关闭,应该返回 -1,表示连接被重置或关闭 - EXPECT_EQ(errno, EBADF); // 文件描述符无效,errno 应为 EBADF - } - - // 测试无效 socketId - TEST_F(CloseClientSocketTest, TestCloseInvalidSocket) - { - int socketIdInvalid = -1; // 无效的 socketId - EXPECT_NO_THROW(CloseClientSocket(socketIdInvalid)); // 对无效 socketId 调用不应该抛出异常 - } - - // 测试关闭已关闭的套接字 - TEST_F(CloseClientSocketTest, TestCloseAlreadyClosedSocket) - { - int socketIdValid = socketId; // 使用有效的 socketId - CloseClientSocket(socketIdValid); // 首先关闭它 - - EXPECT_NO_THROW(CloseClientSocket(socketIdValid)); // 再次调用不应该出错 - } - - // 测试关闭负值 socketId - TEST_F(CloseClientSocketTest, TestCloseNegativeSocket) - { - int socketIdNegative = -1; // 使用负值 socketId - EXPECT_NO_THROW(CloseClientSocket(socketIdNegative)); // 不会发生错误 - } -} \ No newline at end of file diff --git a/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_connect_test.cpp b/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_connect_test.cpp deleted file mode 100644 index 5062084b..00000000 --- a/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_connect_test.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2024-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 "appspawn.h" -#include "appspawn_hook.h" -#include "appspawn_manager.h" -#include "appspawn_modulemgr.h" -#include "appspawn_permission.h" -#include "appspawn_sandbox.h" -#include "appspawn_utils.h" -#include "appspawn_server.h" -#include "securec.h" - -#include "app_spawn_stub.h" -#include "app_spawn_test_helper.h" - -#define SOCKET_NAME "loopserver" - -// 假设 CreateClientSocket 函数已经定义 -namespace OHOS { - class CreateClientSocketTest : public ::testing::Test { - protected: - const char *socketName = SOCKET_NAME; - const char *socketPath; - int serverFd = -1; - int clientFd = -1; - - void SetUp() override - { - // 准备 Unix 域套接字文件路径 - socketPath = std::string(_SOCKET_DIR) + socketName; - - // 创建并启动一个模拟的服务器套接字 - serverFd = socket(AF_UNIX, SOCK_STREAM, 0); - ASSERT_GE(serverFd, 0) << "Failed to create server socket"; - - struct sockaddr_un serverAddr; - serverAddr.sun_family = AF_UNIX; - - // 删除旧的套接字文件 - unlink(socketPath); - - int ret = bind(serverFd, (struct sockaddr *)&serverAddr, sizeof(serverAddr)); - ASSERT_EQ(ret, 0) << "Failed to bind server socket"; - - ret = listen(serverFd, 1); - ASSERT_EQ(ret, 0) << "Failed to listen on server socket"; - - // 创建客户端套接字 - clientFd = socket(AF_UNIX, SOCK_STREAM, 0); - ASSERT_GE(clientFd, 0) << "Failed to create client socket"; - } - - void TearDown() override - { - // 清理资源 - if (clientFd >= 0) { - close(clientFd); - clientFd = -1; - } - - if (serverFd >= 0) { - close(serverFd); - serverFd = -1; - } - - unlink(socketPath); // 删除 Unix 域套接字文件 - socketPath = nullptr; - } - }; - - // 测试套接字成功创建 - TEST_F(CreateClientSocketTest, TestCreateSocketSuccess) - { - uint32_t timeout = 1; // 设置一个合理的超时值 - int socketFd = CreateClientSocket(timeout); - - // 验证是否创建成功 - ASSERT_GE(socketFd, 0) << "Failed to create client socket"; - - // 连接到服务器 - struct sockaddr_un clientAddr; - clientAddr.sun_family = AF_UNIX; - - int ret = connect(socketFd, (struct sockaddr *)&clientAddr, sizeof(clientAddr)); - ASSERT_EQ(ret, 0) << "Failed to connect to server"; - - // 关闭套接字 - CloseClientSocket(socketFd); - } - - // 测试套接字创建失败 - TEST_F(CreateClientSocketTest, TestCreateSocketFailure) - { - uint32_t timeout = 1; - - // 模拟套接字创建失败 - // 比如,通过删除目录,来模拟无法创建套接字 - unlink(socketPath); // 删除存在的套接字文件 - int socketFd = CreateClientSocket(timeout); - - // 验证套接字创建失败,返回 -1 - ASSERT_EQ(socketFd, -1) << "Socket creation should have failed"; - - // 确保错误信息打印(可以通过检查日志输出) - } - - // 测试套接字连接失败 - TEST_F(CreateClientSocketTest, TestConnectSocketFailure) - { - uint32_t timeout = 1; - - // 在未启动服务器的情况下,尝试连接 - unlink(socketPath); // 确保没有现有的套接字文件 - int socketFd = CreateClientSocket(timeout); - - // 验证套接字创建成功,但连接失败 - ASSERT_GE(socketFd, 0) << "Socket creation should have succeeded"; - - // 在没有服务器的情况下,连接应该失败 - struct sockaddr_un clientAddr; - clientAddr.sun_family = AF_UNIX; - - int ret = connect(socketFd, (struct sockaddr *)&clientAddr, sizeof(clientAddr)); - ASSERT_EQ(ret, -1) << "Expected connection failure"; - ASSERT_EQ(errno, ECONNREFUSED) << "Expected ECONNREFUSED error"; - - // 关闭套接字 - CloseClientSocket(socketFd); - } - - // 测试超时设置 - TEST_F(CreateClientSocketTest, TestSetSocketTimeouts) - { - uint32_t timeout = 1; // 设置超时时间 - int socketFd = CreateClientSocket(timeout); - ASSERT_GE(socketFd, 0) << "Failed to create socket"; - - // 通过查看设置的超时来验证是否生效 - struct timeval recvTimeout; - socklen_t optlen = sizeof(recvTimeout); - - int ret = getsockopt(socketFd, SOL_SOCKET, SO_RCVTIMEO, &recvTimeout, &optlen); - ASSERT_EQ(ret, 0) << "Failed to get SO_RCVTIMEO"; - ASSERT_EQ(recvTimeout.tv_sec, 1) << "Expected receive timeout to be 1 second"; - - struct timeval sendTimeout; - ret = getsockopt(socketFd, SOL_SOCKET, SO_SNDTIMEO, &sendTimeout, &optlen); - - ASSERT_EQ(ret, 0) << "Failed to get SO_SNDTIMEO"; - ASSERT_EQ(sendTimeout.tv_sec, 1) << "Expected send timeout to be 1 second"; - - // 关闭套接字 - CloseClientSocket(socketFd); - } -} \ No newline at end of file diff --git a/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_test.cpp b/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_test.cpp deleted file mode 100644 index 06cfca4b..00000000 --- a/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_test.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2024-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 "appspawn.h" -#include "appspawn_hook.h" -#include "appspawn_manager.h" -#include "appspawn_modulemgr.h" -#include "appspawn_permission.h" -#include "appspawn_sandbox.h" -#include "appspawn_utils.h" -#include "appspawn_server.h" -#include "securec.h" - -#include "app_spawn_stub.h" -#include "app_spawn_test_helper.h" - -// 假设的全局配置 -using namespace testing; -using namespace testing::ext; - -namespace OHOS { - class GetDefaultTimeoutTest : public testing::Test { - protected: - void SetUp() override - { - // 每个测试前初始化 - global_value = nullptr; // 确保全局值清空 - } - - void TearDown() override - { - // 每个测试后进行清理 - global_value = nullptr; // 清理全局设置 - } - }; - - // 测试默认值 - TEST_F(GetDefaultTimeoutTest, TestDefaultValue) - { - uint32_t def = 60; - uint32_t timeout = GetDefaultTimeout(def); - EXPECT_EQ(timeout, def); // 应该返回默认值 60 - } - - // 测试 SetParameter 设置的有效超时值 - TEST_F(GetDefaultTimeoutTest, TestValidTimeout) - { - SetParameter("persist.appspawn.reqMgr.timeout", "30"); // 设置超时时间为 30 - - uint32_t def = 60; - uint32_t timeout = GetDefaultTimeout(def); - EXPECT_EQ(timeout, 30); // 应该返回 30 - } - - // 测试 SetParameter 设置的无效超时值(非数字) - TEST_F(GetDefaultTimeoutTest, TestInvalidTimeout) - { - SetParameter("persist.appspawn.reqMgr.timeout", "invalid"); // 设置超时时间为无效值 - - uint32_t def = 60; - uint32_t timeout = GetDefaultTimeout(def); - EXPECT_EQ(timeout, def); // 应该返回默认值 60 - } - - // 测试 SetParameter 设置 "0" 时的行为 - TEST_F(GetDefaultTimeoutTest, TestZeroTimeout) - { - SetParameter("persist.appspawn.reqMgr.timeout", "0"); // 设置超时时间为 "0" - - uint32_t def = 60; - uint32_t timeout = GetDefaultTimeout(def); - EXPECT_EQ(timeout, def); // 应该返回默认值 60 - } - - // 测试返回空字符串的情况 - TEST_F(GetDefaultTimeoutTest, TestEmptyTimeout) - { - SetParameter("persist.appspawn.reqMgr.timeout", ""); // 设置超时时间为空 - - uint32_t def = 60; - uint32_t timeout = GetDefaultTimeout(def); - EXPECT_EQ(timeout, def); // 应该返回默认值 60 - } - - // 测试默认行为,没有调用 SetParameter 时 - TEST_F(GetDefaultTimeoutTest, TestNoTimeoutSet) - { - uint32_t def = 60; - uint32_t timeout = GetDefaultTimeout(def); - EXPECT_EQ(timeout, def); // 应该返回默认值 60,因为没有设置超时 - } - -} \ No newline at end of file diff --git a/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_tryconnect_test.cpp b/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_tryconnect_test.cpp deleted file mode 100644 index b6731ddd..00000000 --- a/test/unittest/app_spawn_standard_test/clienttest/appspawn_client_tryconnect_test.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2024-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 "appspawn.h" -#include "appspawn_hook.h" -#include "appspawn_manager.h" -#include "appspawn_modulemgr.h" -#include "appspawn_permission.h" -#include "appspawn_sandbox.h" -#include "appspawn_utils.h" -#include "appspawn_server.h" -#include "securec.h" - -#include "app_spawn_stub.h" -#include "app_spawn_test_helper.h" - -#define RETRY_TIME 100000 // 100ms for testing -#define RETRY_COUNT 2 -#define MAX_RETRY_COUNT 3 - -// 测试用例类 -namespace OHOS { - - class TryCreateSocketTest : public ::testing::Test { - protected: - ReqMsgMgr reqMgr; - - void SetUp() override - { - reqMgr.socketId = -1; // 初始时设置套接字ID为无效 - reqMgr.maxRetryCount = MAX_RETRY_COUNT; // 最大重试次数 - reqMgr.timeout = RETRY_TIME; // 超时设置 - } - }; - - // 模拟 CreateClientSocket 的成功和失败 - int CreateClientSocket(uint32_t timeout) - { - static int attempt = 0; - if (attempt < RETRY_COUNT) { - attempt++; - return -1; // 模拟失败 - } - return 1; // 模拟成功 - } - - // 测试成功创建套接字 - TEST_F(TryCreateSocketTest, TestCreateSocketSuccess) - { - reqMgr.socketId = -1; // 确保初始状态是无效套接字 - reqMgr.maxRetryCount = 3; - - // 调用 TryCreateSocket - TryCreateSocket(&reqMgr); - - // 验证是否成功创建套接字 - ASSERT_GE(reqMgr.socketId, 0) << "Socket creation should succeed after retries"; - } - - // 测试套接字创建失败并重试 - TEST_F(TryCreateSocketTest, TestCreateSocketRetry) - { - reqMgr.socketId = -1; - reqMgr.maxRetryCount = 3; - - // 调用 TryCreateSocket - TryCreateSocket(&reqMgr); - - // 验证是否成功创建套接字 - ASSERT_GE(reqMgr.socketId, 0) << "Socket creation should succeed after retries"; - } - - // 测试最大重试次数后仍然无法创建套接字 - TEST_F(TryCreateSocketTest, TestMaxRetryFailure) - { - reqMgr.socketId = -1; - reqMgr.maxRetryCount = 2; // 设置最大重试次数为2 - - // 调用 TryCreateSocket - TryCreateSocket(&reqMgr); - - // 验证套接字创建失败 - ASSERT_EQ(reqMgr.socketId, -1) << "Socket creation should fail after max retries"; - } - - // 测试超时参数是否影响重试 - TEST_F(TryCreateSocketTest, TestSocketTimeout) - { - reqMgr.socketId = -1; - reqMgr.maxRetryCount = 1; - reqMgr.timeout = 2000; // 设置较长的超时 - - // 调用 TryCreateSocket - TryCreateSocket(&reqMgr); - - // 验证套接字创建是否成功 - ASSERT_GE(reqMgr.socketId, 0) << "Socket creation should succeed after one retry"; - } -} \ No newline at end of file diff --git a/util/src/appspawn_utils.c b/util/src/appspawn_utils.c index bdcc1b36..774b11f8 100644 --- a/util/src/appspawn_utils.c +++ b/util/src/appspawn_utils.c @@ -167,7 +167,7 @@ int MakeDirRec(const char *path, mode_t mode, int lastPath) static void TrimTail(char *buffer, uint32_t maxLen) { - uint32_t index = maxLen - 1; + int32_t index = (int32_t)maxLen - 1; while (index > 0) { if (isspace(buffer[index])) { buffer[index] = '\0'; -- Gitee From b005765c9cfc973aea37edf95d27a43759b144fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Thu, 16 Jan 2025 21:17:14 +0800 Subject: [PATCH 114/148] modify msgdir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- appspawn.cfg | 5 ++--- util/include/appspawn_utils.h | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/appspawn.cfg b/appspawn.cfg index 2cd57bb0..a0b61fc7 100644 --- a/appspawn.cfg +++ b/appspawn.cfg @@ -4,9 +4,8 @@ "cmds" : [ "mkdir /mnt/sandbox", "mkdir /mnt/sandbox/com.ohos.render/ 0711 nwebspawn nwebspawn", - "mkdir /mnt/startup", - "mkdir /mnt/startup/appspawn 0700 root root", - "mkdir /mnt/startup/nwebspawn/ 0700 nwebspawn nwebspawn" + "mkdir /data/service/el1/startup/appspawn 0700 root root", + "mkdir /data/service/el1/startup/nwebspawn/ 0700 nwebspawn nwebspawn" ] }, { diff --git a/util/include/appspawn_utils.h b/util/include/appspawn_utils.h index ff220c33..38e96f90 100755 --- a/util/include/appspawn_utils.h +++ b/util/include/appspawn_utils.h @@ -45,10 +45,10 @@ extern "C" { #endif #if defined(__MUSL__) #define APPSPAWN_SOCKET_DIR APPSPAWN_BASE_DIR "/dev/unix/socket/" -#define APPSPAWN_MSG_DIR APPSPAWN_BASE_DIR "/mnt/startup/" +#define APPSPAWN_MSG_DIR APPSPAWN_BASE_DIR "/data/service/el1/startup/" #else #define APPSPAWN_SOCKET_DIR APPSPAWN_BASE_DIR "/dev/socket/" -#define APPSPAWN_MSG_DIR APPSPAWN_BASE_DIR "/mnt/startup/" +#define APPSPAWN_MSG_DIR APPSPAWN_BASE_DIR "/data/service/el1/startup/" #endif #define DEVICE_VIRTUAL_NET_IO_FLAGS "/sys/devices/virtual/net/lo/flags" -- Gitee From 624e8c4daa3cda7129732fca86cf7d00ff6a79c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Thu, 16 Jan 2025 21:22:09 +0800 Subject: [PATCH 115/148] modify memSize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- common/appspawn_server.h | 6 ++ standard/appspawn_service.c | 138 +++++++++++++++++++++--------------- 2 files changed, 86 insertions(+), 58 deletions(-) diff --git a/common/appspawn_server.h b/common/appspawn_server.h index 7ccc93b1..def2c774 100644 --- a/common/appspawn_server.h +++ b/common/appspawn_server.h @@ -56,6 +56,12 @@ typedef struct AppSpawnClient { uint32_t flags; // Save negotiated flags } AppSpawnClient; +typedef struct AppSpawnPreforkMsg { + uint32_t id; + uint32_t flags; // Save negotiated flags + uint32_t msgLen; +} AppSpawnPreforkMsg; + typedef struct AppSpawnContent { char *longProcName; uint32_t longProcNameLen; diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 1764d93c..08be8927 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -51,7 +51,6 @@ #define PARAM_BUFFER_SIZE 10 #define PATH_SIZE 256 #define FD_PATH_SIZE 128 -#define MAX_MEM_SIZE (4 * 1024) #define APPSPAWN_MSG_USER_CHECK_COUNT 4 #define PREFORK_PROCESS "apppool" #define USER_ID_MIN_VALUE 100 @@ -670,7 +669,25 @@ static bool IsSupportRunHnp() return false; } -static int WritePreforkMsg(AppSpawningCtx *property) +static void ClearMMAP(int clientId, uint32_t memSize) +{ + char path[PATH_MAX] = {0}; + int ret = snprintf_s(path, sizeof(path), sizeof(path) - 1, APPSPAWN_MSG_DIR "appspawn/prefork_%d", clientId); + APPSPAWN_LOGV("prefork unlink %{public}s ret :%{public}d", path, ret); + if (ret > 0 && access(path, F_OK) == 0) { + ret = unlink(path); + APPSPAWN_CHECK_ONLY_LOG(ret == 0, "prefork unlink result %{public}d %{public}d", ret, errno); + } + + AppSpawnContent *content = GetAppSpawnContent(); + if (content != NULL && content->propertyBuffer != NULL) { + ret = munmap(content->propertyBuffer, memSize); + APPSPAWN_CHECK_ONLY_LOG(ret == 0, "munmap failed %{public}d", ret); + content->propertyBuffer = NULL; + } +} + +static int WritePreforkMsg(AppSpawningCtx *property, uint32_t memSize) { AppSpawnContent *content = GetAppSpawnContent(); if (content == NULL || content->propertyBuffer == NULL) { @@ -678,22 +695,28 @@ static int WritePreforkMsg(AppSpawningCtx *property) return -1; } - int ret = memcpy_s(content->propertyBuffer, MAX_MEM_SIZE, &property->message->msgHeader, sizeof(AppSpawnMsg)); - APPSPAWN_CHECK(ret == 0, goto fail, "memcpys_s msgHeader failed"); - ret = memcpy_s((char *)content->propertyBuffer + sizeof(AppSpawnMsg), MAX_MEM_SIZE - sizeof(AppSpawnMsg), - property->message->buffer, property->message->msgHeader.msgLen - sizeof(AppSpawnMsg)); - APPSPAWN_CHECK(ret == 0, goto fail, "memcpys_s AppSpawnMsg failed"); - return ret; + int ret = memcpy_s(content->propertyBuffer, memSize, &property->message->msgHeader, sizeof(AppSpawnMsg)); + if (ret != 0) { + APPSPAWN_LOGE("memcpys_s msgHeader failed"); + ClearMMAP(property->client.id, memSize); + return ret; + } -fail: - munmap((char *)content->propertyBuffer, MAX_MEM_SIZE); + ret = memcpy_s((char *)content->propertyBuffer + sizeof(AppSpawnMsg), memSize - sizeof(AppSpawnMsg), + property->message->buffer, property->message->msgHeader.msgLen - sizeof(AppSpawnMsg)); + if (ret != 0) { + APPSPAWN_LOGE("memcpys_s AppSpawnMsg failed"); + ClearMMAP(property->client.id, memSize); + return ret; + } + munmap((char *)content->propertyBuffer, memSize); content->propertyBuffer = NULL; return ret; } -static int GetAppSpawnMsg(AppSpawningCtx *property) +static int GetAppSpawnMsg(AppSpawningCtx *property, uint32_t memSize) { - uint8_t *buffer = (uint8_t *)GetMapMem(property->client.id, "prefork", MAX_MEM_SIZE, true, false); + uint8_t *buffer = (uint8_t *)GetMapMem(property->client.id, "prefork", memSize, true, false); if (buffer == NULL) { APPSPAWN_LOGE("prefork buffer is null can not write propery"); return -1; @@ -701,7 +724,7 @@ static int GetAppSpawnMsg(AppSpawningCtx *property) uint32_t msgRecvLen = 0; uint32_t remainLen = 0; property->forkCtx.childMsg = (char *)buffer; - property->forkCtx.msgSize = MAX_MEM_SIZE; + property->forkCtx.msgSize = memSize; AppSpawnMsgNode *message = NULL; int ret = GetAppSpawnMsgFromBuffer(buffer, ((AppSpawnMsg *)buffer)->msgLen, &message, &msgRecvLen, &remainLen); // release map @@ -714,25 +737,6 @@ static int GetAppSpawnMsg(AppSpawningCtx *property) return -1; } -static void ClearMMAP(int clientId) -{ - char path[PATH_MAX] = {0}; - int ret = snprintf_s(path, sizeof(path), sizeof(path) - 1, APPSPAWN_MSG_DIR "appspawn/prefork_%d", clientId); - APPSPAWN_LOGV("prefork unlink %{public}s ret :%{public}d", path, ret); - if (ret > 0) { - errno = 0; - ret = unlink(path); - APPSPAWN_LOGV("prefork unlink result %{public}d %{public}d", ret, errno); - } - - AppSpawnContent *content = GetAppSpawnContent(); - if (content != NULL && content->propertyBuffer != NULL) { - ret = munmap(content->propertyBuffer, MAX_MEM_SIZE); - APPSPAWN_CHECK_ONLY_LOG(ret == 0, "munmap failed %{public}d", ret); - content->propertyBuffer = NULL; - } -} - static int SetPreforkProcessName(AppSpawnContent *content) { int ret = prctl(PR_SET_NAME, PREFORK_PROCESS); @@ -773,28 +777,30 @@ static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property) (void)close(property->forkCtx.fd[1]); int isRet = SetPreforkProcessName(content); APPSPAWN_LOGV("prefork process start wait read msg with set processname %{public}d", isRet); - AppSpawnClient client = {0, 0}; - int infoSize = read(content->parentToChildFd[0], &client, sizeof(AppSpawnClient)); - if (infoSize != sizeof(AppSpawnClient)) { + AppSpawnPreforkMsg preforkMsg = {0, 0, 0}; + int infoSize = read(content->parentToChildFd[0], &preforkMsg, sizeof(AppSpawnPreforkMsg)); + if (infoSize != sizeof(AppSpawnPreforkMsg) || preforkMsg.msgLen > MAX_MSG_TOTAL_LENGTH || + preforkMsg.msgLen < sizeof(AppSpawnMsg)) { APPSPAWN_LOGE("prefork process read msg failed %{public}d,%{public}d", infoSize, errno); ProcessExit(0); return; } - property->client.id = client.id; - property->client.flags = client.flags; + property->client.id = preforkMsg.id; + property->client.flags = preforkMsg.flags; property->isPrefork = true; property->forkCtx.fd[0] = content->preforkFd[0]; property->forkCtx.fd[1] = content->preforkFd[1]; property->state = APP_STATE_SPAWNING; - if (GetAppSpawnMsg(property) == -1) { + const uint32_t memSize = (preforkMsg.msgLen / MAX_MSG_BLOCK_LEN + 1) * MAX_MSG_BLOCK_LEN; + if (GetAppSpawnMsg(property, memSize) == -1) { APPSPAWN_LOGE("prefork child read GetAppSpawnMsg failed"); - ClearMMAP(property->client.id); + ClearMMAP(property->client.id, memSize); content->notifyResToParent(content, &property->client, APPSPAWN_MSG_INVALID); ProcessExit(0); return; } - ClearMMAP(property->client.id); + ClearMMAP(property->client.id, memSize); // Inherit the error level of the original process (void)fdsan_set_error_level(errorLevel); ProcessExit(AppSpawnChild(content, &property->client)); @@ -803,38 +809,57 @@ static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property) } } +static int NormalSpawnChild(AppSpawnContent *content, AppSpawnClient *client, pid_t *childPid) +{ + APPSPAWN_CHECK(client != NULL, return APPSPAWN_ARG_INVALID, "client is null"); + int ret = InitForkContext((AppSpawningCtx *)client); + APPSPAWN_CHECK(ret == 0, return ret, "init fork context failed"); + return AppSpawnProcessMsg(content, client, childPid); +} + static int AppSpawnProcessMsgForPrefork(AppSpawnContent *content, AppSpawnClient *client, pid_t *childPid) { int ret = 0; AppSpawningCtx *property = (AppSpawningCtx *)client; - if (content->reservedPid <= 0) { - APPSPAWN_CHECK(client != NULL, return ret, "client is null"); - ret = InitForkContext((AppSpawningCtx *)client); - APPSPAWN_CHECK(ret == 0, return ret, "init fork context failed"); - ret = AppSpawnProcessMsg(content, client, childPid); + ret = NormalSpawnChild(content, client, childPid); } else { - APPSPAWN_CHECK_ONLY_EXPER(content->propertyBuffer == NULL, ClearMMAP(client->id)); - content->propertyBuffer = GetMapMem(property->client.id, "prefork", MAX_MEM_SIZE, false, false); - APPSPAWN_CHECK(content->propertyBuffer != NULL, return -1, "GetPreforkMem failed"); - ret = WritePreforkMsg(property); - APPSPAWN_CHECK(ret == 0, return ret, "WritePreforkMsg failed"); - + const uint32_t memSize = (property->message->msgHeader.msgLen / MAX_MSG_BLOCK_LEN + 1) * + MAX_MSG_BLOCK_LEN; + content->propertyBuffer = GetMapMem(property->client.id, "prefork", memSize, false, false); + if (content->propertyBuffer == NULL) { + ClearMMAP(property->client.id, memSize); + return NormalSpawnChild(content, client, childPid); + } + ret = WritePreforkMsg(property, memSize); + if (ret != 0) { + ClearMMAP(property->client.id, memSize); + return NormalSpawnChild(content, client, childPid); + } *childPid = content->reservedPid; property->forkCtx.fd[0] = content->preforkFd[0]; property->forkCtx.fd[1] = content->preforkFd[1]; - int option = fcntl(property->forkCtx.fd[0], F_GETFD); if (option > 0) { ret = fcntl(property->forkCtx.fd[0], F_SETFD, (unsigned int)option | O_NONBLOCK); APPSPAWN_CHECK_ONLY_LOG(ret == 0, "fcntl failed %{public}d,%{public}d", ret, errno); } + AppSpawnPreforkMsg *preforkMsg = (AppSpawnPreforkMsg *)calloc(1, sizeof(AppSpawnPreforkMsg)); + if (preforkMsg == NULL) { + APPSPAWN_LOGE("calloc failed"); + ClearMMAP(property->client.id, memSize); + return NormalSpawnChild(content, client, childPid); + } - ssize_t writesize = write(content->parentToChildFd[1], client, sizeof(AppSpawnClient)) ; - APPSPAWN_CHECK(writesize == sizeof(AppSpawnClient), kill(*childPid, SIGKILL); + preforkMsg->id = client->id; + preforkMsg->flags = client->flags; + preforkMsg->msgLen = property->message->msgHeader.msgLen; + ssize_t writesize = write(content->parentToChildFd[1], preforkMsg, sizeof(AppSpawnPreforkMsg)) ; + APPSPAWN_CHECK(writesize == sizeof(AppSpawnPreforkMsg), kill(*childPid, SIGKILL); *childPid = 0; ret = -1, "write msg to child failed %{public}d", errno); + free(preforkMsg); } ProcessPreFork(content, property); return ret; @@ -876,10 +901,7 @@ static int RunAppSpawnProcessMsg(AppSpawnContent *content, AppSpawnClient *clien if (IsBootFinished() && IsSupportPrefork(content, client)) { ret = AppSpawnProcessMsgForPrefork(content, client, childPid); } else { - APPSPAWN_CHECK(client != NULL, return ret, "client is null"); - ret = InitForkContext((AppSpawningCtx *)client); - APPSPAWN_CHECK(ret == 0, return ret, "init fork context failed"); - ret = AppSpawnProcessMsg(content, client, childPid); + ret = NormalSpawnChild(content, client, childPid); } return ret; } -- Gitee From 98429e89b609a8033b38fd9d1b19a84d9e40d57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Fri, 17 Jan 2025 16:18:19 +0800 Subject: [PATCH 116/148] modify memSize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- standard/appspawn_service.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 08be8927..8ab8a827 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -673,7 +673,7 @@ static void ClearMMAP(int clientId, uint32_t memSize) { char path[PATH_MAX] = {0}; int ret = snprintf_s(path, sizeof(path), sizeof(path) - 1, APPSPAWN_MSG_DIR "appspawn/prefork_%d", clientId); - APPSPAWN_LOGV("prefork unlink %{public}s ret :%{public}d", path, ret); + APPSPAWN_CHECK_ONLY_LOG(ret > 0, "snprintf failed with %{public}d %{public}d", ret, errno); if (ret > 0 && access(path, F_OK) == 0) { ret = unlink(path); APPSPAWN_CHECK_ONLY_LOG(ret == 0, "prefork unlink result %{public}d %{public}d", ret, errno); @@ -682,7 +682,7 @@ static void ClearMMAP(int clientId, uint32_t memSize) AppSpawnContent *content = GetAppSpawnContent(); if (content != NULL && content->propertyBuffer != NULL) { ret = munmap(content->propertyBuffer, memSize); - APPSPAWN_CHECK_ONLY_LOG(ret == 0, "munmap failed %{public}d", ret); + APPSPAWN_CHECK_ONLY_LOG(ret == 0, "munmap failed %{public}d %{public}d", ret, errno); content->propertyBuffer = NULL; } } @@ -709,7 +709,8 @@ static int WritePreforkMsg(AppSpawningCtx *property, uint32_t memSize) ClearMMAP(property->client.id, memSize); return ret; } - munmap((char *)content->propertyBuffer, memSize); + ret = munmap((char *)content->propertyBuffer, memSize); + APPSPAWN_CHECK_ONLY_LOG(ret == 0, "munmap failed %{public}d,%{public}d", ret, errno); content->propertyBuffer = NULL; return ret; } @@ -777,7 +778,7 @@ static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property) (void)close(property->forkCtx.fd[1]); int isRet = SetPreforkProcessName(content); APPSPAWN_LOGV("prefork process start wait read msg with set processname %{public}d", isRet); - AppSpawnPreforkMsg preforkMsg = {0, 0, 0}; + AppSpawnPreforkMsg preforkMsg = {0}; int infoSize = read(content->parentToChildFd[0], &preforkMsg, sizeof(AppSpawnPreforkMsg)); if (infoSize != sizeof(AppSpawnPreforkMsg) || preforkMsg.msgLen > MAX_MSG_TOTAL_LENGTH || preforkMsg.msgLen < sizeof(AppSpawnMsg)) { -- Gitee From 454370aed4308cc91533335cb787f24a1092be21 Mon Sep 17 00:00:00 2001 From: wangmengyao111 Date: Fri, 17 Jan 2025 18:23:45 +0800 Subject: [PATCH 117/148] internet_permission Signed-off-by: wangmengyao111 --- appspawn.gni | 1 + bundle.json | 3 ++- modules/common/BUILD.gn | 4 ++++ modules/common/appspawn_adapter.cpp | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/appspawn.gni b/appspawn.gni index 480156ee..dd383ed4 100644 --- a/appspawn.gni +++ b/appspawn.gni @@ -34,6 +34,7 @@ declare_args() { appspawn_seccomp_privilege = false appspawn_support_prefork = true appspawn_support_code_signature = true + appspawn_allow_internet_permission = false } if (!defined(global_parts_info) || diff --git a/bundle.json b/bundle.json index 100c49a8..2e91919a 100644 --- a/bundle.json +++ b/bundle.json @@ -26,7 +26,8 @@ "appspawn_mount_tmpshm", "appspawn_seccomp_privilege", "appspawn_support_prefork", - "appspawn_support_code_signature" + "appspawn_support_code_signature", + "appspawn_allow_internet_permission" ], "rom": "296KB", "ram": "13125KB", diff --git a/modules/common/BUILD.gn b/modules/common/BUILD.gn index 7e678381..41c028f0 100644 --- a/modules/common/BUILD.gn +++ b/modules/common/BUILD.gn @@ -81,6 +81,10 @@ ohos_shared_library("appspawn_common") { defines += [ "APPSPAWN_SANDBOX_NEW" ] } + if (appspawn_allow_internet_permission) { + defines += [ "APPSPAWN_ALLOW_INTERNET_PERMISSION" ] + } + subsystem_name = "${subsystem_name}" part_name = "${part_name}" install_enable = true diff --git a/modules/common/appspawn_adapter.cpp b/modules/common/appspawn_adapter.cpp index 37856a33..7f4d0395 100644 --- a/modules/common/appspawn_adapter.cpp +++ b/modules/common/appspawn_adapter.cpp @@ -219,7 +219,9 @@ int SetInternetPermission(const AppSpawningCtx *property) "No tlv internet permission info in req form %{public}s", GetProcessName(property)); APPSPAWN_LOGV("Set internet permission %{public}d %{public}d", info->setAllowInternet, info->allowInternet); if (info->setAllowInternet == 1 && info->allowInternet == 0) { +#ifndef APPSPAWN_ALLOW_INTERNET_PERMISSION DisallowInternet(); +#endif } return 0; } -- Gitee From 859d2d8de7b2a8811cf39f932f7819b93c6d5c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Fri, 17 Jan 2025 14:17:36 +0800 Subject: [PATCH 118/148] add autotest for appspawn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- .../sub_startup_appspawn_appclone_0100.json | 13 ++ .../sub_startup_appspawn_appclone_0100.py | 76 +++++++++ .../sub_startup_appspawn_appclone_0200.json | 13 ++ .../sub_startup_appspawn_appclone_0200.py | 76 +++++++++ .../sub_startup_appspawn_appclone_0300.json | 15 ++ .../sub_startup_appspawn_appclone_0300.py | 100 ++++++++++++ .../sub_startup_appspawn_appclone_0400.json | 15 ++ .../sub_startup_appspawn_appclone_0400.py | 85 ++++++++++ .../sub_startup_appspawn_appclone_0600.json | 15 ++ .../sub_startup_appspawn_appclone_0600.py | 80 ++++++++++ .../sub_startup_appspawn_appclone_0700.json | 15 ++ .../sub_startup_appspawn_appclone_0700.py | 99 ++++++++++++ .../sub_startup_appspawn_appclone_0900.json | 15 ++ .../sub_startup_appspawn_appclone_0900.py | 87 ++++++++++ ...sub_startup_appspawn_atomservice_0100.json | 14 ++ .../sub_startup_appspawn_atomservice_0100.py | 102 ++++++++++++ ...sub_startup_appspawn_atomservice_0200.json | 15 ++ .../sub_startup_appspawn_atomservice_0200.py | 149 ++++++++++++++++++ ...sub_startup_appspawn_atomservice_0300.json | 14 ++ .../sub_startup_appspawn_atomservice_0300.py | 64 ++++++++ ...sub_startup_appspawn_atomservice_0400.json | 15 ++ .../sub_startup_appspawn_atomservice_0400.py | 112 +++++++++++++ 22 files changed, 1189 insertions(+) create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.json create mode 100644 test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.json create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.py create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.json create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.json create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.py create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.json create mode 100644 test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.json new file mode 100644 index 00000000..260d6b73 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.json @@ -0,0 +1,13 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py"] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py new file mode 100644 index 00000000..2e6e4a81 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py @@ -0,0 +1,76 @@ +# 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 os +import time +from devicetest.core.test_case import TestCase, Step, CheckPoint +from hypium import UiDriver +from hypium.action.os_hypium.device_logger import DeviceLogger +from hypium.model import UiParam, WindowFilter + + +class SubStartupAppspawnAppclone0100(TestCase): + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:唤醒屏幕.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("步骤1:安装测试hap包") + ishap = self.driver.has_app("com.ohos.mytest") + if(ishap): + self.driver.uninstall_app("com.ohos.mytest") + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + hap = os.path.abspath( + os.path.join(os.path.join(path, "testFile"), + 'sub_startup_appspawn_appclone/entry-signed-release.hap')) + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.ohos.mytest", "EntryAbility") + time.sleep(2) + self.driver.check_window_exist(WindowFilter().bundle_name("com.ohos.mytest")) + Step("步骤3:点击安装克隆应用") + self.driver.touch(BY.text("安装克隆应用")) + self.driver.touch(BY.text("startAbilityByAppIndex")) + Step("步骤4:分身应用的源目录新建123.txt") + self.driver.shell("touch /data/app/el2/100/database/+clone-1+com.ohos.mytest/123.txt") + Step("步骤5:分身应用沙盒路径是否存在123.txt") + cpid = self.driver.System.get_pid("com.ohos.mytest1") + result1 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % cpid) + Step("步骤6:预期结果校验") + self.driver.Assert.contains(result1, "123.txt") + Step("步骤7:主应用沙盒路径是否存在123.txt") + pid = self.driver.System.get_pid("com.ohos.mytest") + result2 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % pid) + Step("步骤6:预期结果校验") + if ("123.txt" in result2): + raise AssertionError() + else: + pass + + def teardown(self): + Step("收尾工作:删除hap") + self.driver.uninstall_app("com.ohos.mytest") diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.json new file mode 100644 index 00000000..91d041bf --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.json @@ -0,0 +1,13 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py"] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py new file mode 100644 index 00000000..196615e9 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py @@ -0,0 +1,76 @@ +# 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 os +import time +from devicetest.core.test_case import TestCase, Step, CheckPoint +from hypium import UiDriver +from hypium.action.os_hypium.device_logger import DeviceLogger +from hypium.model import UiParam, WindowFilter + + +class SubStartupAppspawnAppclone0200(TestCase): + def __init__(self, controllers): + self.tag = self.__class__.__name__ + self.tests = [ + "test_step1" + ] + TestCase.__init__(self, self.tag, controllers) + self.driver = UiDriver(self.device1) + + def setup(self): + Step("预置工作:初始化手机开始.................") + self.driver = UiDriver(self.device1) + Step("预置工作:唤醒屏幕.................") + self.driver.enable_auto_wakeup(self.device1) + Step("预置工作:滑动解锁.................") + self.driver.swipe(UiParam.UP, side=UiParam.BOTTOM) + Step('设置屏幕常亮') + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("步骤1:安装测试hap包") + ishap = self.driver.has_app("com.ohos.mytest") + if(ishap): + self.driver.uninstall_app("com.ohos.mytest") + path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + hap = os.path.abspath( + os.path.join(os.path.join(path, "testFile"), + 'sub_startup_appspawn_appclone/entry-signed-release.hap')) + self.driver.install_app(hap) + Step("步骤2:打开测试应用") + self.driver.start_app("com.ohos.mytest", "EntryAbility") + time.sleep(2) + self.driver.check_window_exist(WindowFilter().bundle_name("com.ohos.mytest")) + Step("步骤3:点击安装克隆应用") + self.driver.touch(BY.text("安装克隆应用")) + self.driver.touch(BY.text("startAbilityByAppIndex")) + Step("步骤4:分身应用的源目录新建123.txt") + self.driver.shell("touch /data/app/el2/100/database/com.ohos.mytest/abc.txt") + Step("步骤5:主应用沙盒路径是否存在abc.txt") + cpid = self.driver.System.get_pid("com.ohos.mytest") + result1 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % cpid) + Step("步骤6:预期结果校验") + self.driver.Assert.contains(result1, "abc.txt") + Step("步骤7:分身应用沙盒路径是否存在abc.txt") + pid = self.driver.System.get_pid("com.ohos.mytest1") + result2 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % pid) + Step("步骤6:预期结果校验") + if ("abc.txt" in result2): + raise AssertionError() + else: + pass + + def teardown(self): + Step("收尾工作:删除hap") + self.driver.uninstall_app("com.ohos.mytest") diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.json new file mode 100644 index 00000000..845ff596 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py new file mode 100644 index 00000000..c4633080 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py @@ -0,0 +1,100 @@ +# 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 os +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from hypium.action.os_hypium.device_logger import DeviceLogger +from aw import Common + + +class SubStartupAppspawnAppclone0300(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 build_shell_command(i, path, bundle_name, j): + if bundle_name == "com.example.intaketest": + result01 = self.driver.shell("ls /data/app/el%d/100/%s/%s" % (i, path, bundle_name)) + elif bundle_name == "com.example.intaketest%d" % j: + result01 = self.driver.shell("ls /data/app/el%d/100/%s/+clone-%d+com.example.intaketest" + % (i, path, j)) + return None + + def process(self): + Step("安装测试hap并打开") + pid_bundlename_dict = {} + bundle_name = "com.example.intaketest" + hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") + 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) + pid = self.driver.System.get_pid(bundle_name) + pid_bundlename_dict.update({bundle_name: pid}) + + self.driver.AppManager.stop_app("com.example.settings") + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身", "IntakeTest"]: + self.driver.touch(BY.text(text)) + for i in range(5): + self.driver.touch(BY.text("创建分身")) + time.sleep(1) + self.driver.AppManager.stop_app("com.example.settings") + + for i in range(1, 7): + self.driver.AppManager.start_app(bundle_name) + if i == 1: + self.driver.touch(BY.text("IntakeTest")) + pid = self.driver.System.get_pid(bundle_name) + pid_bundlename_dict.update({bundle_name: pid}) + else: + self.driver.touch(BY.text("更多打开方式")) + self.driver.touch(BY.text("IntakeTest%d" % (i - 1))) + pid = self.driver.System.get_pid("%s%d" % (bundle_name, i - 1)) + pid_bundlename_dict.update({"%s%d" % (bundle_name, i - 1) : pid}) + self.driver.go_home() + + for i in range(1, 5): + for j in range(1, 6): + for bundle_name, pid in pid_bundlename_dict.items(): + result01 = build_shell_command(i, "base", bundle_name, j) + result02 = self.driver.shell("ls /proc/%d/root/data/storage/el%d/%s" % (pid, i, "base")) + self.driver.Assert.equal(result01, result02) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.uninstall_app("com.example.intaketest") diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.json new file mode 100644 index 00000000..a3e3431a --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py new file mode 100644 index 00000000..faf80d3c --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py @@ -0,0 +1,85 @@ +# 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 os +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from hypium.action.os_hypium.device_logger import DeviceLogger +from aw import Common + + +class SubStartupAppspawnAppclone0400(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): + Step("安装测试hap并打开") + bundle_name = "com.example.intaketest" + hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") + 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.AppManager.stop_app("com.example.settings") + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身", "IntakeTest"]: + self.driver.touch(BY.text(text)) + for i in range(5): + self.driver.touch(BY.text("创建分身")) + time.sleep(1) + self.driver.AppManager.stop_app("com.example.settings") + + for i in range(1, 7): + self.driver.AppManager.start_app(bundle_name) + if i == 1: + self.driver.touch(BY.text("IntakeTest")) + else: + self.driver.touch(BY.text("更多打开方式")) + self.driver.touch(BY.text("IntakeTest%d" % (i - 1))) + self.driver.go_home() + + self.driver.shell("touch /data/app/el2/100/base/%s/test.txt" % bundle_name) + has_file01 = self.driver.Storage.has_file("/data/app/el2/100/base/%s/test.txt" % bundle_name) + self.driver.Assert.equal(has_file01, True) + for i in range(1, 6): + has_file02 = self.driver.Storage.has_file("/data/app/el2/100/base/+clone-%d+%s/test.txt" % (i, bundle_name)) + self.driver.Assert.equal(has_file02, False) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.json new file mode 100644 index 00000000..ce0e0df9 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py new file mode 100644 index 00000000..8c3036be --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py @@ -0,0 +1,80 @@ +# 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 os +import random +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from hypium.action.os_hypium.device_logger import DeviceLogger +from aw import Common + + +class SubStartupAppspawnAppclone0600(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): + Step("安装测试hap并打开") + bundle_name = "com.example.intaketest" + hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") + 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.AppManager.stop_app("com.example.settings") + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身", "IntakeTest"]: + self.driver.touch(BY.text(text)) + for i in range(5): + self.driver.touch(BY.text("创建分身")) + time.sleep(1) + + self.driver.check_component_exist(BY.text("最多可以创建 5 个分身"), expect_exist=True) + + comps01 = self.driver.find_all_components(BY.type("Button")) + self.driver.touch(comps01[random.randint(0, len(comps01) - 1)]) + comps02 = self.driver.find_all_components(BY.type("Button")) + self.driver.touch(comps02[-1]) + self.driver.check_component_exist(BY.text("最多可以创建 5 个分身"), expect_exist=False) + self.driver.touch(BY.text("创建分身")) + self.driver.check_component_exist(BY.text("最多可以创建 5 个分身"), expect_exist=True) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.stop_app("com.example.settings") + self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.json new file mode 100644 index 00000000..a5ad1a2e --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py new file mode 100644 index 00000000..6a1d075f --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py @@ -0,0 +1,99 @@ +# 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 os +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from hypium.action.os_hypium.device_logger import DeviceLogger +from aw import Common + + +class SubStartupAppspawnAppclone0700(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): + Step("安装测试hap并打开") + bundle_name = "com.example.intaketest" + hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") + 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.AppManager.stop_app("com.example.settings") + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身", "IntakeTest"]: + self.driver.touch(BY.text(text)) + for i in range(5): + self.driver.touch(BY.text("创建分身")) + time.sleep(1) + self.driver.AppManager.stop_app("com.example.settings") + + for i in range(1, 7): + self.driver.AppManager.start_app(bundle_name) + if i == 1: + self.driver.touch(BY.text("IntakeTest")) + else: + self.driver.touch(BY.text("更多打开方式")) + self.driver.touch(BY.text("IntakeTest%d" % (i - 1))) + + for i in range(1, 5): + for j in range(1, 6): + for path in ["base", "database"]: + has_dir = self.driver.Storage.has_dir("/data/app/el%d/100/%s/+clone-%d+%s" + % (i, path, j, bundle_name)) + self.driver.Assert.equal(has_dir, True) + + self.driver.AppManager.stop_app("com.example.settings") + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身", "IntakeTest"]: + self.driver.touch(BY.text(text)) + comps01 = self.driver.find_all_components(BY.type("Button")) + self.driver.touch(comps01[0]) + comps02 = self.driver.find_all_components(BY.type("Button")) + self.driver.touch(comps02[-1]) + for i in range(1, 5): + for path in ["base", "database"]: + has_dir = self.driver.Storage.has_dir("/data/app/el%d/100/%s/+clone-1+%s" % (i, path, bundle_name)) + self.driver.Assert.equal(has_dir, False) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.stop_app("com.example.settings") + self.driver.AppManager.uninstall_app(bundle_name) diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.json b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.json new file mode 100644 index 00000000..e029c9d7 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py new file mode 100644 index 00000000..63d87c4c --- /dev/null +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py @@ -0,0 +1,87 @@ +# 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 os +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from hypium.action.os_hypium.device_logger import DeviceLogger +from aw import Common + + +class SubStartupAppspawnAppclone0900(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): + Step("安装测试hap并打开") + bundle_name = "com.example.intaketest" + hap_path = Common.sourcepath('intaketest.hap', "sub_startup_appspawn_appclone") + 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.AppManager.stop_app("com.example.settings") + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身", "IntakeTest"]: + self.driver.touch(BY.text(text)) + for i in range(5): + self.driver.touch(BY.text("创建分身")) + time.sleep(1) + self.driver.AppManager.stop_app("com.example.settings") + + for i in range(1, 7): + self.driver.AppManager.start_app(bundle_name) + if i == 1: + self.driver.touch(BY.text("IntakeTest")) + pid = self.driver.System.get_pid(bundle_name) + else: + self.driver.touch(BY.text("更多打开方式")) + self.driver.touch(BY.text("IntakeTest%d" % (i - 1))) + pid = self.driver.System.get_pid("%s%d" % (bundle_name, i - 1)) + self.driver.Assert.equal(type(pid), int) + + self.driver.AppManager.uninstall_app(bundle_name) + self.driver.AppManager.start_app("com.example.settings") + self.driver.swipe(UiParam.UP) + for text in ["系统", "应用分身"]: + self.driver.touch(BY.text(text)) + self.driver.check_component_exist(BY.text("IntakeTest"), expect_exist=False) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.stop_app("com.example.settings") 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 new file mode 100644 index 00000000..a69713ef --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.json @@ -0,0 +1,14 @@ +{ + "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 new file mode 100644 index 00000000..fa6f0aa7 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0100.py @@ -0,0 +1,102 @@ +# 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_0200.json b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.json new file mode 100644 index 00000000..0e23f909 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py new file mode 100644 index 00000000..5442712b --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py @@ -0,0 +1,149 @@ +# 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 json +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from aw import Common + + +class SubStartupAppspawnAtomservice0200(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) + + Step("解锁屏幕") + 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 login_account(self): + Step("登录帐号") + setting_name = "com.example.settings" + with open(r"config/userLogin.json", 'r', encoding='UTF-8') as f: + account = json.load(f) + self.driver.AppManager.stop_app(setting_name) + self.driver.AppManager.start_app(setting_name) + self.driver.touch(BY.key("entry_image_account")) + comps1 = self.driver.find_component(BY.key("inp_hwid_login_account_name_before")) + if comps1: + self.driver.input_text(comps1, account["userName"]) + self.driver.close_soft_keyboard() + self.driver.touch(BY.key("button_text")) + comps2 = self.driver.find_component(BY.key("inp_hwid_login_password")) + self.driver.input_text(comps2, account["passWord"]) + else: + comps3 = self.driver.find_component(BY.key("inp_hwid_login_account_name")) + self.driver.clear_text(comps3) + self.driver.input_text(comps3, account["userName"]) + comps4 = self.driver.find_component(BY.key("inp_hwid_login_password")) + self.driver.input_text(comps4, account["passWord"]) + self.driver.touch(BY.key("button_text")) + self.driver.wait_for_component(BY.text("继续"), timeout=15) + self.driver.touch(BY.text("继续")) + + def exit_account(self): + Step("退出帐号") + setting_name = "com.example.settings" + self.driver.AppManager.stop_app(setting_name) + self.driver.AppManager.start_app(setting_name) + self.driver.touch(BY.key("entry_image_account")) + self.driver.swipe(UiParam.UP) + comp = self.driver.find_component(BY.key("hwid_account_center_logout_text"), scroll_target=BY.type("Scroll")) + self.driver.touch(comp) + self.driver.touch(BY.key("button_text")) + comps5 = self.driver.find_component(BY.key("advanced_dialog_button_1")) + if comps5: + self.driver.touch(comps5) + time.sleep(5) + else: + pass + + def process(self): + self.login_account() + hap_info01, hap_info02 = [], [] + bundle_name = "com.atomicservice.5765880207854649689" + bundle_name_start = "+auid-9E1E70ABFF4AAFE1E18AF18E0F75703713D" + "8678F9F9AB06C3B64C1CB1080615A+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) + self.driver.Assert.equal(log_has_dir, True) + + 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) + + Step("校验UGO、所有者、所属组、selinux标签一致") + 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 + #校验用户字符串长度为64 + self.driver.Assert.equal(len(hap_info02.split()[-1].split("-")[1].split("+")[0]), 64) + 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 + self.driver.Assert.equal(len(hap_info02.split()[-1].split("-")[1].split("+")[0]), 64) + for index in range(2, 5): + self.driver.Assert.equal(hap_info01.split()[index], hap_info02.split()[index]) + self.exit_account() + + + 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 new file mode 100644 index 00000000..c5a1372f --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.json @@ -0,0 +1,14 @@ +{ + "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 new file mode 100644 index 00000000..aaf35b8d --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0300.py @@ -0,0 +1,64 @@ +# 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/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.json b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.json new file mode 100644 index 00000000..fac1fba7 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py new file mode 100644 index 00000000..d2f3086e --- /dev/null +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py @@ -0,0 +1,112 @@ +# 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 json +import time +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from hypium.model import UiParam +from aw import Common + + +class SubStartupAppspawnAtomservice0400(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 login_account(self): + Step("登录帐号") + setting_name = "com.example.settings" + with open(r"config/userLogin.json", 'r', encoding='UTF-8') as f: + account = json.load(f) + self.driver.AppManager.stop_app(setting_name) + self.driver.AppManager.start_app(setting_name) + self.driver.touch(BY.key("entry_image_account")) + + def exit_account(self): + Step("退出帐号") + setting_name = "com.example.settings" + self.driver.AppManager.stop_app(setting_name) + self.driver.AppManager.start_app(setting_name) + self.driver.touch(BY.key("entry_image_account")) + self.driver.swipe(UiParam.UP) + comp = self.driver.find_component(BY.key("hwid_account_center_logout_text"), scroll_target=BY.type("Scroll")) + self.driver.touch(comp) + self.driver.touch(BY.key("button_text")) + comps5 = self.driver.find_component(BY.key("advanced_dialog_button_1")) + if comps5: + self.driver.touch(comps5) + time.sleep(5) + else: + pass + + def process(self): + self.login_account() + comps1 = self.driver.find_component(BY.key("inp_hwid_login_account_name_before")) + if comps1: + self.driver.input_text(comps1, account["userName"]) + self.driver.close_soft_keyboard() + self.driver.touch(BY.text("下一步")) + comps2 = self.driver.find_component(BY.key("inp_hwid_login_password")) + self.driver.input_text(comps2, account["passWord"]) + else: + comps3 = self.driver.find_component(BY.key("inp_hwid_login_account_name")) + self.driver.clear_text(comps3) + self.driver.input_text(comps3, account["userName"]) + comps4 = self.driver.find_component(BY.key("inp_hwid_login_password")) + self.driver.input_text(comps4, account["passWord"]) + self.driver.touch(BY.key("button_text")) + self.driver.wait_for_component(BY.text("继续"), timeout=10) + self.driver.touch(BY.text("继续")) + + Step("启动元服务应用,检查目标路径是否存在") + bundle_name = "com.atomicservice.5765880207854649689" + bundle_name_start = "+auid-9E1E70ABFF4AAFE1E18AF18E0F75703713D" + "8678F9F9AB06C3B64C1CB1080615A+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) + self.exit_account() + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.uninstall_app(bundle_name) -- Gitee From 0940a441809d1e55b68e70375e5d3dd011875c19 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Sat, 18 Jan 2025 10:43:59 +0800 Subject: [PATCH 119/148] nativespawn support JIT permission Signed-off-by: wangfeng --- modules/common/appspawn_encaps.c | 4 ++-- standard/appspawn_manager.h | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/common/appspawn_encaps.c b/modules/common/appspawn_encaps.c index d048b869..9337ce16 100644 --- a/modules/common/appspawn_encaps.c +++ b/modules/common/appspawn_encaps.c @@ -269,8 +269,8 @@ APPSPAWN_STATIC int SpawnSetEncapsPermissions(AppSpawnMgr *content, AppSpawningC return APPSPAWN_ARG_INVALID; } - // The trustlist is used to control not appspawn - if (!IsAppSpawnMode(content)) { + // The trustlist is used to control not appspawn or nativespawn + if (!(IsAppSpawnMode(content) || IsNativeSpawnMode(content))) { return 0; } diff --git a/standard/appspawn_manager.h b/standard/appspawn_manager.h index 2cca34d8..1cb026ac 100644 --- a/standard/appspawn_manager.h +++ b/standard/appspawn_manager.h @@ -221,6 +221,12 @@ APPSPAWN_INLINE int IsNWebSpawnMode(const AppSpawnMgr *content) (content->content.mode == MODE_FOR_NWEB_SPAWN || content->content.mode == MODE_FOR_NWEB_COLD_RUN); } +APPSPAWN_INLINE int IsNativeSpawnMode(const AppSpawnMgr *content) +{ + return (content != NULL) && + (content->content.mode == MODE_FOR_NATIVE_SPAWN); +} + APPSPAWN_INLINE int IsColdRunMode(const AppSpawnMgr *content) { return (content != NULL) && -- Gitee From c54961ed071175407ff63fb5ebcae45b7f9ab2f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Wed, 22 Jan 2025 14:23:58 +0800 Subject: [PATCH 120/148] =?UTF-8?q?fix:=20appspawn=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=AE=89=E5=85=A8=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- modules/sandbox/sandbox_shared_mount.cpp | 8 ++++---- modules/sandbox/sandbox_utils.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/sandbox/sandbox_shared_mount.cpp b/modules/sandbox/sandbox_shared_mount.cpp index 3d5bd581..da2b651a 100644 --- a/modules/sandbox/sandbox_shared_mount.cpp +++ b/modules/sandbox/sandbox_shared_mount.cpp @@ -242,7 +242,7 @@ static int MountWithFileMgr(const AppSpawningCtx *property, const AppDacInfo *in /* /mnt/sandbox//storage/Users */ char storageUserPath[PATH_MAX_LEN] = {0}; - ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%d/%s/storage/Users", + ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%u/%s/storage/Users", info->uid / UID_BASE, bundleName); if (ret <= 0) { APPSPAWN_LOGE("snprintf storageUserPath failed, errno %{public}d", errno); @@ -290,7 +290,7 @@ static int MountWithOther(const AppSpawningCtx *property, const AppDacInfo *info /* /mnt/sandbox//storage/Users */ char storageUserPath[PATH_MAX_LEN] = {0}; - ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%d/%s/storage/Users", + ret = snprintf_s(storageUserPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%u/%s/storage/Users", info->uid / UID_BASE, bundleName); if (ret <= 0) { APPSPAWN_LOGE("snprintf storageUserPath failed, errno %{public}d", errno); @@ -358,7 +358,7 @@ static int MountSharedMapItem(const AppSpawningCtx *property, const AppDacInfo * { /* /mnt/sandbox///data/storage/el */ char sandboxPath[PATH_MAX_LEN] = {0}; - int ret = snprintf_s(sandboxPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%d/%s%s", + int ret = snprintf_s(sandboxPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%u/%s%s", info->uid / UID_BASE, bundleName, sandboxPathItem); if (ret <= 0) { APPSPAWN_LOGE("snprintf sandboxPath failed, errno %{public}d", errno); @@ -485,7 +485,7 @@ static int ParseDataGroupList(AppSpawnMgr *content, const AppSpawningCtx *proper std::string srcPath = item[GROUPLIST_KEY_DIR]; APPSPAWN_CHECK(!CheckPath(srcPath), return -1, "src path %{public}s is invalid", srcPath.c_str()); - uint32_t elxValue = GetElxInfoFromDir(srcPath.c_str()); + int elxValue = GetElxInfoFromDir(srcPath.c_str()); APPSPAWN_CHECK((elxValue >= EL2 && elxValue < ELX_MAX), return -1, "Get elx value failed"); const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(elxValue); diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index fccbb286..430f3cce 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -1377,7 +1377,7 @@ int32_t SandboxUtils::MountAllGroup(const AppSpawningCtx *appProperty, std::stri std::string srcPath = item[g_groupList_key_dir]; APPSPAWN_CHECK(!CheckPath(srcPath), return -1, "MountAllGroup: path error"); - uint32_t elxValue = GetElxInfoFromDir(srcPath.c_str()); + int elxValue = GetElxInfoFromDir(srcPath.c_str()); APPSPAWN_CHECK((elxValue >= EL2 && elxValue < ELX_MAX), return -1, "Get elx value failed"); const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(elxValue); -- Gitee From c23b0494b6ddcabebbb533ddfa563e43d55eac70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Wed, 22 Jan 2025 11:28:19 +0800 Subject: [PATCH 121/148] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9appspawn?= =?UTF-8?q?=E4=B8=8D=E8=A7=84=E8=8C=83=E6=A0=87=E7=82=B9=E7=AC=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- service/hnp/installer/README_zh.md | 24 ++-- service/hnp/installer/api_hnp.md | 12 +- service/hnp/installer/errorcode-api.md | 20 +-- service/hnp/installer/errorcode-hnp.md | 178 ++++++++++++------------- 4 files changed, 117 insertions(+), 117 deletions(-) diff --git a/service/hnp/installer/README_zh.md b/service/hnp/installer/README_zh.md index 1ba676e8..bbf53414 100644 --- a/service/hnp/installer/README_zh.md +++ b/service/hnp/installer/README_zh.md @@ -6,7 +6,7 @@ ## 接口说明 - 针对安装卸载功能提供了以下API调用接口 + 针对安装卸载功能提供了以下API调用接口。 | 接口名 | 描述 | | :----------------------------------------------------------- | :--------------------------------------- | @@ -20,7 +20,7 @@ Native软件包安装就是将从应用市场下载解压出来的hnp包安装到鸿蒙PC设备上。当前提供接口调用以及hnp命令行两种方式进行安装。 - 1) hnp帮助命令 hnp -h + 1) hnp帮助命令 hnp -h。 ``` usage:hnp [-u ][-p ][-i ][-f][-s ][-a ] @@ -48,7 +48,7 @@ ``` hnp install -u [系统用户ID] -p [hap包名] <-i [hnp安装包所在路径]> <-f> ``` - -u [必选] 用户ID + -u [必选] 用户ID。 -p [必选] 指定hap应用软件名。 @@ -134,14 +134,14 @@ a. 安装时发现已经有同款软件相同版本则跳过安装,返回安装成功。 -b. 非强制安装模式下,安装时发现已经有同款软件不同版本会安装失败. +b. 非强制安装模式下,安装时发现已经有同款软件不同版本会安装失败。 b. 强制安装会将已安装的软件先卸载掉之后再安装当前新的软件。 c. 批量安装应用的hnp软件时如果中间安装出错,则直接退出安装流程返回,之前已安装的软件继续保留。 -3) 接口调用安装 +3) 接口调用安装。 安装接口原型: ``` @@ -166,7 +166,7 @@ c. 批量安装应用的hnp软件时如果中间安装出错,则直接退出 int ret = NativeInstallHnp(100, "./sample.hap", "./baidu_hnp_path", "baidu", 0x1); ... - 执行成功后输出件和上面命令行的一样 + 执行成功后输出件和上面命令行的一样。 ``` **2. Native软件包卸载** @@ -178,9 +178,9 @@ c. 批量安装应用的hnp软件时如果中间安装出错,则直接退出 ``` 该命令根据用户传入的信息对已安装的属于对应hap应用下的所有hnp软件进行卸载。 - -u [必选] 系统用户ID,用于拼接软件的安装路径 + -u [必选] 系统用户ID,用于拼接软件的安装路径。 - -p [必选] 要卸载hnp包所属的hap包名(应用软件名) + -p [必选] 要卸载hnp包所属的hap包名(应用软件名)。 样例: ``` @@ -191,9 +191,9 @@ c. 批量安装应用的hnp软件时如果中间安装出错,则直接退出 执行成功观察点: 观察点1:之前baidu应用安装的时候分别安装了公有和私有的hnpsample软件,所以本次卸载需要观察以下之前安装的软件目录“hnpsample.org”是否已删除。 公有软件: - /data/app/el1/bundle/100/hnppublic/hnpsample.org + /data/app/el1/bundle/100/hnppublic/hnpsample.org。 私有软件: - /data/app/el1/bundle/100/hnp/baidu/hnpsample.org + /data/app/el1/bundle/100/hnp/baidu/hnpsample.org。 观察点2:查看/data/service/el1/startup/hnp_info.json安装管理文件中对应baidu这一hap节点信息是否删除。 ``` @@ -203,7 +203,7 @@ a. 如果公有hnp软件被其它应用所共有,则卸载本应用不会删 b. 公有hnp软件卸载前会判断该软件是否正在运行,如果正在运行则会卸载失败。私有hnp软件因为其所属应用已经卸载,不存在正在使用的情况,因此私有软件不用校验是否正在运行。 -2) 接口调用卸载 +2) 接口调用卸载。 卸载接口原型: ``` @@ -232,5 +232,5 @@ b. 公有hnp软件卸载前会判断该软件是否正在运行,如果正在 native包管理功能运行控制,需要在用户开启“开发者模式”场景下才能使用native包管理的安装卸载软件功能,否则命令会执行失败。在PC设备上打开“开发者模式”的方法如下: ``` - 点击“设置”按钮——》选择“系统和更新”界面——》选择“开发者选项”——》打开“开发者选项” + 点击“设置”按钮——》选择“系统和更新”界面——》选择“开发者选项”——》打开“开发者选项”。 ``` diff --git a/service/hnp/installer/api_hnp.md b/service/hnp/installer/api_hnp.md index 70e31b94..075b2d4c 100644 --- a/service/hnp/installer/api_hnp.md +++ b/service/hnp/installer/api_hnp.md @@ -12,7 +12,7 @@ ### 结构体定义 -NA +NA。 ### 函数 @@ -35,11 +35,11 @@ int NativeInstallHnp(const char *userId, const char *hnpRootPath, const HapInfo 参数: - userId:用户ID; + userId:用户ID。 - hapPath:hap包所在路径。用于签名校验 + hapPath:hap包所在路径。用于签名校验。 - hnpRootPath:hnp安装包存放路径; + hnpRootPath:hnp安装包存放路径。 hapInfo:hap应用软件信息,结构如下。 ``` @@ -65,7 +65,7 @@ int NativeInstallHnp(const char *userId, const char *hnpRootPath, const HapInfo **返回:** -安装成功返回0;失败返回错误码 +安装成功返回0;失败返回错误码。 ### NativeUnInstallHnp @@ -85,4 +85,4 @@ int NativeUnInstallHnp(const char *userId, const char *packageName); **返回:** -卸载成功返回0;失败返回错误码 +卸载成功返回0;失败返回错误码。 diff --git a/service/hnp/installer/errorcode-api.md b/service/hnp/installer/errorcode-api.md index 1c04e37e..da8dd476 100644 --- a/service/hnp/installer/errorcode-api.md +++ b/service/hnp/installer/errorcode-api.md @@ -12,7 +12,7 @@ params is invalid. **错误描述** -参数非法 +参数非法。 **可能原因** @@ -20,7 +20,7 @@ params is invalid. **处理步骤** -检查传入的参数是否正确 +检查传入的参数是否正确。 ## 0x2002 fork子进程失败 @@ -63,7 +63,7 @@ wait pid unsuccess. **错误信息** -native package install/uninstall not in developer mode。 +native package install/uninstall not in developer mode. **错误描述** @@ -71,11 +71,11 @@ native package install/uninstall not in developer mode。 **可能原因** -当前为非开发者模式 +当前为非开发者模式。 **处理步骤** -打开开发者模式进行接口请求 +打开开发者模式进行接口请求。 ## 0x2005 创建管道失败 @@ -85,7 +85,7 @@ pipe fd unsuccess. **错误描述** -创建pipe管道失败 +创建pipe管道失败。 **可能原因** @@ -107,11 +107,11 @@ read stream unsuccess. **可能原因** -系统禁止管道输出 +系统禁止管道输出。 **处理步骤** -查看权限 +查看权限。 ## 0x2007 获取返回码失败 @@ -125,7 +125,7 @@ get return unsuccess. **可能原因** -输出影响 +输出影响。 **处理步骤** @@ -143,7 +143,7 @@ mem move unsuccess. **可能原因** -系统内部原因 +系统内部原因。 **处理步骤** diff --git a/service/hnp/installer/errorcode-hnp.md b/service/hnp/installer/errorcode-hnp.md index e339e9dc..457ec415 100644 --- a/service/hnp/installer/errorcode-hnp.md +++ b/service/hnp/installer/errorcode-hnp.md @@ -22,7 +22,7 @@ **处理步骤** - 检查传入的参数个数是否正确。可通过命令hnpcli help查询正确的参数格式 + 检查传入的参数个数是否正确。可通过命令hnpcli help查询正确的参数格式。 ## 0x801002 缺少必要的操作参数 @@ -40,7 +40,7 @@ **处理步骤** -检查传入的参数是否正确以及完整。可通过命令hnpcli help查询正确的参数格式 +检查传入的参数是否正确以及完整。可通过命令hnpcli help查询正确的参数格式。 ## 0x801101 打开文件失败 @@ -55,7 +55,7 @@ Open file failed. **可能原因** 1. 文件不存在。 -2. 没有权限 +2. 没有权限。 **处理步骤** @@ -75,8 +75,8 @@ Read file content failed. **可能原因** 1. 文件不存在。 -2. 没有权限 -3. 文件读出的内容大小和期望的大小不相等 +2. 没有权限。 +3. 文件读出的内容大小和期望的大小不相等。 **处理步骤** @@ -97,8 +97,8 @@ fseek设置失败。 **可能原因** 1. 文件不存在。 -2. 没有权限 -3. fseek系统报错 +2. 没有权限。 +3. fseek系统报错。 **处理步骤** @@ -119,8 +119,8 @@ ftell设置失败。 **可能原因** 1. 文件不存在。 -2. 没有权限 -3. ftell系统报错 +2. 没有权限。 +3. ftell系统报错。 **处理步骤** @@ -140,7 +140,7 @@ Get real path failed. **可能原因** -路径不存在 +路径不存在。 **处理步骤** @@ -158,7 +158,7 @@ Get file content size is 0. **可能原因** -文件内容为空 +文件内容为空。 **处理步骤** @@ -176,11 +176,11 @@ The len of string exceed limit. **可能原因** -用户传入的字符串超出了限制的大小 +用户传入的字符串超出了限制的大小。 **处理步骤** -根据错误信息检查参数是否存在问题 +根据错误信息检查参数是否存在问题。 ## 0x801108 目录打开失败 @@ -194,13 +194,13 @@ Open Dir failed. **可能原因** -1. 目录不存在 -2. 权限问题 +1. 目录不存在。 +2. 权限问题。 **处理步骤** -1. 检查传入的目录是否存在 -2. 检查目录权限是否本进程能够打开 +1. 检查传入的目录是否存在。 +2. 检查目录权限是否本进程能够打开。 ## 0x801109 sprintf拼接失败 @@ -214,11 +214,11 @@ sprintf拼接失败。 **可能原因** -sprintf接口返回错误 +sprintf接口返回错误。 **处理步骤** -查看sprintf错误码并检查参数是否正确 +查看sprintf错误码并检查参数是否正确。 ## 0x80110a 生成压缩文件失败 @@ -232,11 +232,11 @@ Create new file in zip failed. **可能原因** -压缩软件报错 +压缩软件报错。 **处理步骤** -查看压缩软件报错原因并修复 +查看压缩软件报错原因并修复。 ## 0x80110b 写文件失败 @@ -250,15 +250,15 @@ Write file failed. **可能原因** -1. 文件不存在 -2. 权限问题 -3. 写入的是压缩的内容 +1. 文件不存在。 +2. 权限问题。 +3. 写入的是压缩的内容。 **处理步骤** -1. 检查传入的文件是否存在 -2. 检查文件权限是否本进程能够打开 -3. 使用“wb”打开文件再进行写入 +1. 检查传入的文件是否存在。 +2. 检查文件权限是否本进程能够打开。 +3. 使用“wb”打开文件再进行写入。 ## 0x80110c strcpy拷贝失败 **错误信息** @@ -271,11 +271,11 @@ strcpy拷贝失败。 **可能原因** -strcpy接口返回错误 +strcpy接口返回错误。 **处理步骤** -查看strcpy错误码并检查参数是否正确 +查看strcpy错误码并检查参数是否正确。 ## 0x80110d 获取文件属性失败 @@ -289,15 +289,15 @@ Get file attr failed. **可能原因** -1. 文件不存在 -2. 权限问题 -3. 系统接口报错 +1. 文件不存在。 +2. 权限问题。 +3. 系统接口报错。 **处理步骤** -1. 检查传入的文件是否存在 -2. 检查文件权限是否本进程能够打开 -3. 查看具体的系统报错信息并修改 +1. 检查传入的文件是否存在。 +2. 检查文件权限是否本进程能够打开。 +3. 查看具体的系统报错信息并修改。 ## 0x80110e 解压缩打开文件失败 @@ -312,13 +312,13 @@ Unzip process open file failed. **可能原因** -1. 当前打开的文件不是zip格式的文件 -2. 文件不存在 +1. 当前打开的文件不是zip格式的文件。 +2. 文件不存在。 **处理步骤** -1. 检查文件是否为zip格式的文件 -2. 检查文件是否存在 +1. 检查文件是否为zip格式的文件。 +2. 检查文件是否存在。 ## 0x80110f 解压缩获取文件信息失败 @@ -332,12 +332,12 @@ Unzip process get file info failed. **可能原因** -zip里没有文件内容 +zip里没有文件内容。 **处理步骤** -检查zip压缩文件内是否有文件 +检查zip压缩文件内是否有文件。 ## 0x801110 解压缩读取文件内容失败 @@ -351,14 +351,14 @@ Unzip process read file failed. **可能原因** -1. 文件不存在 -2. zip压缩文件已损坏 +1. 文件不存在。 +2. zip压缩文件已损坏。 **处理步骤** -1. 检查文件是否存在 -2. 使用第三方工具检查zip压缩包是否损坏 +1. 检查文件是否存在。 +2. 使用第三方工具检查zip压缩包是否损坏。 ## 0x801111 生成软链接失败 @@ -371,14 +371,14 @@ Symlink failed. 生成软链接失败。 **可能原因** -1. 软链接源文件路径不存在 -2. 软链接目标文件路径不存在 +1. 软链接源文件路径不存在。 +2. 软链接目标文件路径不存在。 **处理步骤** -1. 检查软链接源文件路径是否存在 -2. 检查软连接目标文件路径是否存在 +1. 检查软链接源文件路径是否存在。 +2. 检查软连接目标文件路径是否存在。 ## 0x801112 进程正在运行 @@ -392,11 +392,11 @@ Uninstall failed because software is running. **可能原因** -卸载的软件正在运行中,不能卸载 +卸载的软件正在运行中,不能卸载。 **处理步骤** -检查期望卸载的软件是否正在运行,如果正在运行,则需停止后才能卸载 +检查期望卸载的软件是否正在运行,如果正在运行,则需停止后才能卸载。 ## 0x801113 入参失败 @@ -410,11 +410,11 @@ Arg check failed. **可能原因** -入参非法 +入参非法。 **处理步骤** -根据报错检查入参是否非法 +根据报错检查入参是否非法。 ## 0x801114 strdup失败 @@ -428,11 +428,11 @@ Strdup操作失败。 **可能原因** -申请内存失败 +申请内存失败。 **处理步骤** -根据报错检查内存是否不足 +根据报错检查内存是否不足。 ## 0x801115 设置权限失败 @@ -446,13 +446,13 @@ Chmod failed. Chmod操作失败。 **可能原因** -1. 权限不足 -2. 参数不正确 +1. 权限不足。 +2. 参数不正确。 **处理步骤** -1. 检查当前进程是否有权限执行chmod操作 -2. 检查chmod参数是否正确 +1. 检查当前进程是否有权限执行chmod操作。 +2. 检查chmod参数是否正确。 ## 0x801116 删除目录失败 @@ -466,11 +466,11 @@ Remove dir failed. **可能原因** -权限不足 +权限不足。 **处理步骤** -检查当前进程是否有权限执行unlink操作 +检查当前进程是否有权限执行unlink操作。 ## 0x801117 对应进程不存在 @@ -488,7 +488,7 @@ Process is not running. **处理步骤** -检查查询的进程是否正在运行 +检查查询的进程是否正在运行。 ## 0x801118 创建路径失败 @@ -507,7 +507,7 @@ mkdir创建目录失败。 **处理步骤** -检查当前进程是否有权限执行mkdir操作 +检查当前进程是否有权限执行mkdir操作。 ## 0x801119 读取配置文件流失败 @@ -525,7 +525,7 @@ Read cfg stream failed. **处理步骤** -检查配置文件是否存在 +检查配置文件是否存在。 ## 0x80111a 解析json信息失败 @@ -543,7 +543,7 @@ Parse json info failed. **处理步骤** -检查文件内容是否是json格式 +检查文件内容是否是json格式。 ## 0x80111b 未找到json项 @@ -562,7 +562,7 @@ Get json item failed. **处理步骤** -检查文件内容是否存在对应的item项 +检查文件内容是否存在对应的item项。 ## 0x80111c 解析json数组失败 @@ -580,7 +580,7 @@ json文件中不存在对应的数据信息。 **处理步骤** -检查json文件内容是否存在对应的数组信息 +检查json文件内容是否存在对应的数组信息。 @@ -603,7 +603,7 @@ The cmd arg num is invalid. **处理步骤** -检查传入的参数个数是否正确。可通过命令hnp help查询正确的参数格式 +检查传入的参数个数是否正确。可通过命令hnp help查询正确的参数格式。 ## 0x801302 组装安装路径失败 @@ -621,7 +621,7 @@ sprintf拼接路径时报错。 **处理步骤** -检查拼接的参数是否超出路径大小上限。根据sprintf报错处理 +检查拼接的参数是否超出路径大小上限。根据sprintf报错处理。 ## 0x801303 获取安装实际路径失败 **错误信息** @@ -634,12 +634,12 @@ Get real path failed. **可能原因** -1. 传入的hnp包所在路径非法 -2. 传入的安装路径非法 +1. 传入的hnp包所在路径非法。 +2. 传入的安装路径非法。 **处理步骤** -检查安装卸载传入的路径是否正确 +检查安装卸载传入的路径是否正确。 ## 0x801304 获取Hnp安装包名称失败 **错误信息** @@ -648,15 +648,15 @@ Get hnp file name failed. **错误描述** -获取不到hnp文件的名字信息 +获取不到hnp文件的名字信息。 **可能原因** -文件名不是.hnp结尾的名字 +文件名不是.hnp结尾的名字。 **处理步骤** -检查目录下是否存在非.hnp后缀名的文件 +检查目录下是否存在非.hnp后缀名的文件。 ## 0x801305 软件已安装 **错误信息** @@ -673,7 +673,7 @@ Software has been installed. **处理步骤** -1. 检查软件是否已被安装 +1. 检查软件是否已被安装。 2. 软件已安装,用户确认后可通过-f选项进行强制安装。 ## 0x801306 卸载命令参数错误 @@ -691,29 +691,29 @@ The cmd arg num is invalid. **处理步骤** -检查传入的参数个数是否正确。可通过命令hnp help查询正确的参数格式 +检查传入的参数个数是否正确。可通过命令hnp help查询正确的参数格式。 ## 0x801307 获取卸载路径失败 **错误信息** -Get uninstall path failed。 +Get uninstall path failed. **错误描述** 获取卸载路径失败。 **可能原因** -1. 传参错误 +1. 传参错误。 2. 要卸载的软件不存在。 **处理步骤** -1. 检查卸载的软件信息是否正确 -2. 检查卸载的软件是否已安装 +1. 检查卸载的软件信息是否正确。 +2. 检查卸载的软件是否已安装。 ## 0x801308 安装命令参数uid错误 **错误信息** -Get user id failed。 +Get user id failed. **错误描述** @@ -721,11 +721,11 @@ Get user id failed。 **可能原因** -用户传入的用户ID非数字 +用户传入的用户ID非数字。 **处理步骤** -检查用户传入的用户ID是否非数字 +检查用户传入的用户ID是否非数字。 ## 0x801309 获取版本目录失败 **错误信息** @@ -738,11 +738,11 @@ Get software version path failed. **可能原因** -软件安装路径下为空,外层安装路径残留 +软件安装路径下为空,外层安装路径残留。 **处理步骤** -检查安装路径是否残留一个空的.org文件夹。是的话需要删除 +检查安装路径是否残留一个空的.org文件夹。是的话需要删除。 ## 0x80130a 安装包个数超过阈值 **错误信息** @@ -751,15 +751,15 @@ Num of hnp file over limit. **错误描述** -安装包的个数超出了限制。阈值为32个 +安装包的个数超出了限制。阈值为32个。 **可能原因** -安装包的个数超出了32个 +安装包的个数超出了32个。 **处理步骤** -检查安装包的个数是否超出了32个。如果超出需要分批次安装 +检查安装包的个数是否超出了32个。如果超出需要分批次安装。 -- Gitee From 08369a3a284592fcbeba27925d6829a485052c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Thu, 23 Jan 2025 10:31:57 +0800 Subject: [PATCH 122/148] Support passing the process exit signal to Ams when the application exits abnormally MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- common/appspawn_server.h | 1 + interfaces/innerkits/client/appspawn_client.c | 61 +++++++++++ .../client/libappspawn_client.versionscript | 2 + interfaces/innerkits/include/appspawn.h | 17 +++ modules/module_engine/include/appspawn_msg.h | 1 + standard/appspawn_service.c | 95 ++++++++++++++++ .../app_spawn_interface_test.cpp | 28 +++++ .../app_spawn_service_test.cpp | 102 ++++++++++++++++++ 8 files changed, 307 insertions(+) diff --git a/common/appspawn_server.h b/common/appspawn_server.h index 7ccc93b1..98a4f96b 100644 --- a/common/appspawn_server.h +++ b/common/appspawn_server.h @@ -64,6 +64,7 @@ typedef struct AppSpawnContent { bool isLinux; int sandboxType; RunMode mode; + int signalFd; #ifndef OHOS_LITE int32_t preforkFd[2]; int32_t parentToChildFd[2]; diff --git a/interfaces/innerkits/client/appspawn_client.c b/interfaces/innerkits/client/appspawn_client.c index d63a6f77..458fb13c 100644 --- a/interfaces/innerkits/client/appspawn_client.c +++ b/interfaces/innerkits/client/appspawn_client.c @@ -38,6 +38,11 @@ #define USER_LOCK_STATUS_SIZE 8 static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; static AppSpawnReqMsgMgr *g_clientInstance[CLIENT_MAX] = {NULL}; +static pthread_mutex_t g_spawnListenMutex = PTHREAD_MUTEX_INITIALIZER; +static int g_spawnListenFd = 0; +static bool g_spawnListenStart = false; + +APPSPAWN_STATIC void SpawnListen(AppSpawnReqMsgMgr *reqMgr, const char *processName); static uint32_t GetDefaultTimeout(uint32_t def) { @@ -294,6 +299,11 @@ static int ClientSendMsg(AppSpawnReqMsgMgr *reqMgr, AppSpawnReqMsgNode *reqNode, if (isColdRun && reqMgr->timeout < ASAN_TIMEOUT) { UpdateSocketTimeout(reqMgr->timeout, reqMgr->socketId); } + if (reqNode->msg->msgType != MSG_OBSERVE_PROCESS_SIGNAL_STATUS) { + pthread_mutex_lock(&g_spawnListenMutex); + SpawnListen(reqMgr, reqNode->msg->processName); + pthread_mutex_unlock(&g_spawnListenMutex); + } return 0; } // retry @@ -307,6 +317,37 @@ static int ClientSendMsg(AppSpawnReqMsgMgr *reqMgr, AppSpawnReqMsgNode *reqNode, return APPSPAWN_TIMEOUT; } +APPSPAWN_STATIC void SpawnListen(AppSpawnReqMsgMgr *reqMgr, const char *processName) +{ + AppSpawnClientType type = reqMgr->type; + if (g_spawnListenFd <= 0 || g_spawnListenStart) { + APPSPAWN_LOGV("Spawn Listen fail,fd:%{public}d,start:%{public}d", g_spawnListenFd, g_spawnListenStart); + return; + } + APPSPAWN_CHECK((type == CLIENT_FOR_APPSPAWN), return, "Invalid type"); + APPSPAWN_CHECK(processName != NULL, return, "Invalid process name"); + + APPSPAWN_LOGI("Spawn Listen start type:%{public}d,fd:%{public}d,start:%{public}d", type, g_spawnListenFd, + g_spawnListenStart); + + AppSpawnReqMsgHandle reqHandle; + int ret = AppSpawnReqMsgCreate(MSG_OBSERVE_PROCESS_SIGNAL_STATUS, processName, &reqHandle); + APPSPAWN_CHECK(ret == 0, return, "Failed to create type:%{public}d req msg, ret = %{public}d", type, ret); + + ret = AppSpawnReqMsgAddFd(reqHandle, SPAWN_LISTEN_FD_NAME, g_spawnListenFd); + APPSPAWN_CHECK(ret == 0, AppSpawnReqMsgFree(reqHandle); + return, "Failed to add info message, ret=%{public}d", ret); + + AppSpawnResult result = {0}; + ret = ClientSendMsg(reqMgr, (AppSpawnReqMsgNode *)reqHandle, &result); + APPSPAWN_CHECK(ret == 0, return, "Send msg to type:%{public}d failed, ret=%{public}d", type, ret); + APPSPAWN_CHECK(result.result == 0, return, "Appspawn failed to handle message, result=%{public}d", result.result); + + g_spawnListenStart = true; + APPSPAWN_LOGI("Spawn Listen client type[%{public}d]] Send fd[%{public}d] success", type, g_spawnListenFd); + return; +} + int AppSpawnClientInit(const char *serviceName, AppSpawnClientHandle *handle) { APPSPAWN_CHECK(serviceName != NULL, return APPSPAWN_ARG_INVALID, "Invalid service name"); @@ -403,4 +444,24 @@ int AppSpawnClientSendUserLockStatus(uint32_t userId, bool isLocked) } APPSPAWN_LOGI("Send lockstatus msg to appspawn success"); return 0; +} + +int SpawnListenFdSet(int fd) +{ + if (fd <= 0) { + APPSPAWN_LOGE("Spawn Listen fd set[%{public}d] failed", fd); + return APPSPAWN_ARG_INVALID; + } + g_spawnListenFd = fd; + APPSPAWN_LOGI("Spawn Listen fd set[%{public}d] success", fd); + return 0; +} + +int SpawnListenCloseSet(void) +{ + pthread_mutex_lock(&g_spawnListenMutex); + g_spawnListenStart = false; + pthread_mutex_unlock(&g_spawnListenMutex); + APPSPAWN_LOGI("Spawn Listen close set success"); + return 0; } \ No newline at end of file diff --git a/interfaces/innerkits/client/libappspawn_client.versionscript b/interfaces/innerkits/client/libappspawn_client.versionscript index 03ebc5b4..dce211fc 100644 --- a/interfaces/innerkits/client/libappspawn_client.versionscript +++ b/interfaces/innerkits/client/libappspawn_client.versionscript @@ -37,6 +37,8 @@ GetPermissionIndex; GetMaxPermissionIndex; GetPermissionByIndex; + SpawnListenFdSet; + SpawnListenCloseSet; local: *; }; diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index 7dc86862..5bf6623e 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -119,6 +119,7 @@ typedef enum { MSG_DEVICE_DEBUG, MSG_UNINSTALL_DEBUG_HAP, MSG_LOCK_STATUS, + MSG_OBSERVE_PROCESS_SIGNAL_STATUS, MAX_TYPE_INVALID } AppSpawnMsgType; @@ -342,6 +343,22 @@ int32_t GetMaxPermissionIndex(AppSpawnClientHandle handle); */ const char *GetPermissionByIndex(AppSpawnClientHandle handle, int32_t index); +/** + * @brief set up a pipe fd to capture the exit reason of a child process + * + * @param fd fd for write signal info + * @return if succeed return 0,else return other value + */ +int SpawnListenFdSet(int fd); + + +/** + * @brief close the listener for child process exit + * + * @return if succeed return 0,else return other value + */ +int SpawnListenCloseSet(void); + #ifdef __cplusplus } #endif diff --git a/modules/module_engine/include/appspawn_msg.h b/modules/module_engine/include/appspawn_msg.h index 3c632529..94f966b9 100644 --- a/modules/module_engine/include/appspawn_msg.h +++ b/modules/module_engine/include/appspawn_msg.h @@ -31,6 +31,7 @@ extern "C" { #define CJAPPSPAWN_SOCKET_NAME "CJAppSpawn" #define KEEPALIVE_NAME "keepalive" #define NATIVESPAWN_SOCKET_NAME "NativeSpawn" +#define SPAWN_LISTEN_FD_NAME "SpawnListenFd" #define APPSPAWN_ALIGN(len) (((len) + 0x03) & (~0x03)) #define APPSPAWN_TLV_NAME_LEN 32 diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 954e9bc7..eb61cd20 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -174,6 +174,40 @@ static void HandleDiedPid(pid_t pid, uid_t uid, int status) TerminateSpawnedProcess(appInfo); } +APPSPAWN_STATIC void WriteSignalInfoToFd(pid_t pid, int status) +{ + AppSpawnContent *content = GetAppSpawnContent(); + APPSPAWN_CHECK(content->signalFd > 0, return, "Invalid signal fd[%{public}d]", content->signalFd); + APPSPAWN_CHECK(pid > 0, return, "Invalid pid[%{public}d]", pid); + + int signal = 0; + if (WIFSIGNALED(status)) { + signal = WTERMSIG(status); + } + if (WIFEXITED(status)) { + signal = WEXITSTATUS(status); + } + + cJSON *root = cJSON_CreateObject(); + if (root == NULL) { + APPSPAWN_LOGE("signal json write create root object unsuccess"); + return; + } + cJSON_AddNumberToObject(root, "pid", pid); + cJSON_AddNumberToObject(root, "signal", signal); + char *jsonString = cJSON_Print(root); + cJSON_Delete(root); + + int ret = write(content->signalFd, jsonString, strlen(jsonString) + 1); + if (ret < 0) { + free(jsonString); + APPSPAWN_LOGE("Spawn Listen failed to write signal info to fd errno %{public}d", errno); + return; + } + APPSPAWN_LOGI("Spawn Listen successfully write signal info[%{public}s] to fd", jsonString); + free(jsonString); +} + APPSPAWN_STATIC void ProcessSignal(const struct signalfd_siginfo *siginfo) { APPSPAWN_LOGI("ProcessSignal signum %{public}d %{public}d", siginfo->ssi_signo, siginfo->ssi_pid); @@ -185,6 +219,7 @@ APPSPAWN_STATIC void ProcessSignal(const struct signalfd_siginfo *siginfo) APPSPAWN_CHECK(WIFSIGNALED(status) || WIFEXITED(status), return, "ProcessSignal with wrong status:%{public}d", status); HandleDiedPid(pid, siginfo->ssi_uid, status); + WriteSignalInfoToFd(pid, status); } #if (defined(CJAPP_SPAWN) || defined(NATIVE_SPAWN)) if (OH_ListGetCnt(&GetAppSpawnMgr()->appQueue) == 0) { @@ -1692,6 +1727,63 @@ static void ProcessAppSpawnLockStatusMsg(AppSpawnMsgNode *message) #endif } +APPSPAWN_STATIC int AppSpawnReqMsgFdGet(AppSpawnConnection *connection, AppSpawnMsgNode *message, + const char *fdName, int *fd) +{ + APPSPAWN_CHECK_ONLY_EXPER(message != NULL && message->buffer != NULL && connection != NULL, return -1); + APPSPAWN_CHECK_ONLY_EXPER(message->tlvOffset != NULL, return -1); + int findFdIndex = 0; + AppSpawnMsgReceiverCtx recvCtx = connection->receiverCtx; + APPSPAWN_CHECK(recvCtx.fds != NULL && recvCtx.fdCount > 0, return 0, + "no need get fd info %{public}d, %{public}d", recvCtx.fds != NULL, recvCtx.fdCount); + + for (uint32_t index = TLV_MAX; index < (TLV_MAX + message->tlvCount); index++) { + if (message->tlvOffset[index] == INVALID_OFFSET) { + return APPSPAWN_SYSTEM_ERROR; + } + uint8_t *data = message->buffer + message->tlvOffset[index]; + if (((AppSpawnTlv *)data)->tlvType != TLV_MAX) { + continue; + } + AppSpawnTlvExt *tlv = (AppSpawnTlvExt *)data; + if (strcmp(tlv->tlvName, MSG_EXT_NAME_APP_FD) != 0) { + continue; + } + APPSPAWN_CHECK(findFdIndex < recvCtx.fdCount && recvCtx.fds[findFdIndex] > 0, return -1, + "check get fd args failed %{public}d, %{public}d, %{public}d", + findFdIndex, recvCtx.fdCount, recvCtx.fds[findFdIndex]); + + if (strcmp((const char *)(data + sizeof(AppSpawnTlvExt)), fdName) == 0 && recvCtx.fds[findFdIndex] > 0) { + *fd = recvCtx.fds[findFdIndex]; + APPSPAWN_LOGI("Spawn Listen fd %{public}s get success %{public}d", fdName, recvCtx.fds[findFdIndex]); + break; + } + findFdIndex++; + if (findFdIndex >= recvCtx.fdCount) { + break; + } + } + return 0; +} + +APPSPAWN_STATIC void ProcessObserveProcessSignalMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) +{ + APPSPAWN_CHECK_ONLY_EXPER(message != NULL, return); + int fd = 0; + int ret = AppSpawnReqMsgFdGet(connection, message, SPAWN_LISTEN_FD_NAME, &fd); + if (fd <= 0 || ret != 0) { + APPSPAWN_LOGE("Spawn Listen appspawn signal fd get unsuccess"); + SendResponse(connection, &message->msgHeader, APPSPAWN_SYSTEM_ERROR, 0); + DeleteAppSpawnMsg(message); + return; + } + + AppSpawnContent *content = GetAppSpawnContent(); + content->signalFd = fd; + SendResponse(connection, &message->msgHeader, 0, 0); + DeleteAppSpawnMsg(message); +} + static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) { AppSpawnMsg *msg = &message->msgHeader; @@ -1749,6 +1841,9 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess SendResponse(connection, msg, 0, 0); DeleteAppSpawnMsg(message); break; + case MSG_OBSERVE_PROCESS_SIGNAL_STATUS: + ProcessObserveProcessSignalMsg(connection, message); + break; default: SendResponse(connection, msg, APPSPAWN_MSG_INVALID, 0); DeleteAppSpawnMsg(message); 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 fa1547d1..c7bb3ce1 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 @@ -608,4 +608,32 @@ HWTEST_F(AppSpawnInterfaceTest, App_Spawn_Interface_NWeb, TestSize.Level0) EXPECT_GE(pid, 0); } +/** + * @brief 测试接口:SpawnListenFdSet + * + */ +HWTEST_F(AppSpawnInterfaceTest, App_SpawnListenFdSet_001, TestSize.Level0) +{ + int ret = SpawnListenFdSet(-1); + EXPECT_EQ(ret, APPSPAWN_ARG_INVALID); + + int pipefd[2]; + EXPECT_EQ(pipe(pipefd), 0); + + ret = SpawnListenFdSet(pipefd[1]); + EXPECT_EQ(ret, 0); + + close(pipefd[0]); + close(pipefd[1]); +} + +/** + * @brief 测试接口:SpawnListenCloseSet + * + */ +HWTEST_F(AppSpawnInterfaceTest, App_SpawnListenCloseSet_001, TestSize.Level0) +{ + int ret = SpawnListenCloseSet(); + EXPECT_EQ(ret, 0); +} } // namespace OHOS diff --git a/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp index ccadb11c..c22f749e 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp @@ -641,6 +641,108 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_010, TestSize.Level0) ASSERT_EQ(result.result, 0); } +HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_011, TestSize.Level0) +{ + int ret = 0; + AppSpawnClientHandle clientHandle = nullptr; + AppSpawnResult result = {}; + do { + int pipefd[2]; // 2 pipe fd + char buffer[1024]; //1024 1k + APPSPAWN_CHECK(pipe(pipefd) == 0, break, "Failed to pipe fd errno:%{public}d", errno); + ret = SpawnListenFdSet(pipefd[0]); + + ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle); + APPSPAWN_CHECK(ret == 0, break, "Failed to create client %{public}s", APPSPAWN_SERVER_NAME); + AppSpawnReqMsgHandle reqHandle = testServer->CreateMsg(clientHandle, MSG_APP_SPAWN, 0); + + AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_DEBUGGABLE); + AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_NATIVEDEBUG); + AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_BUNDLE_RESOURCES); + AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_ACCESS_BUNDLE_DIR); + + ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); + APPSPAWN_CHECK(ret == 0, break, "Failed to send msg %{public}d", ret); + AppSpawnClientDestroy(clientHandle); + sleep(1); // wait child process stand up + + AppSpawnedProcess *app = GetSpawnedProcessByName(testServer->GetDefaultTestAppBundleName()); + ASSERT_NE(app, nullptr); + char commamd[16]; // command len 16 + APPSPAWN_CHECK(sprintf_s(commamd, 16, "kill -9 %d", app->pid) > 0, break, "sprintf command unsuccess"); + system(commamd); + + bool isFind = false; + int count = 0; + while (count < 10) { + if (read(pipefd[1], buffer, sizeof(buffer)) <= 0) { + count++; + continue; + } + if (strstr(buffer, std::to_string(app->pid).c_str()) != NULL) { + isFind = true; + break; + } + count++; + } + close(pipefd[0]); + close(pipefd[1]); + ASSERT_EQ(isFind, false); + SpawnListenCloseSet(); + } while (0); +} + +HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_012, TestSize.Level0) +{ + int ret = 0; + AppSpawnClientHandle clientHandle = nullptr; + AppSpawnResult result = {}; + do { + int pipefd[2]; // 2 pipe fd + char buffer[1024]; //1024 1k + APPSPAWN_CHECK(pipe(pipefd) == 0, break, "Failed to pipe fd errno:%{public}d", errno); + ret = SpawnListenFdSet(pipefd[1]); + + ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle); + APPSPAWN_CHECK(ret == 0, break, "Failed to create client %{public}s", APPSPAWN_SERVER_NAME); + AppSpawnReqMsgHandle reqHandle = testServer->CreateMsg(clientHandle, MSG_APP_SPAWN, 0); + + AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_DEBUGGABLE); + AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_NATIVEDEBUG); + AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_BUNDLE_RESOURCES); + AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_ACCESS_BUNDLE_DIR); + + ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); + APPSPAWN_CHECK(ret == 0, break, "Failed to send msg %{public}d", ret); + AppSpawnClientDestroy(clientHandle); + sleep(1); // wait child process stand up + + AppSpawnedProcess *app = GetSpawnedProcessByName(testServer->GetDefaultTestAppBundleName()); + ASSERT_NE(app, nullptr); + char commamd[16]; // command len 16 + APPSPAWN_CHECK(sprintf_s(commamd, 16, "kill -9 %d", app->pid) > 0, break, "sprintf command unsuccess"); + system(commamd); + + bool isFind = false; + int count = 0; + while (count < 10) { + if (read(pipefd[0], buffer, sizeof(buffer)) <= 0) { + count++; + continue; + } + if (strstr(buffer, std::to_string(app->pid).c_str()) != NULL) { + isFind = true; + break; + } + count++; + } + close(pipefd[0]); + close(pipefd[1]); + ASSERT_EQ(isFind, false); + SpawnListenCloseSet(); + } while (0); +} + /** * @brief 必须最后一个,kill nwebspawn,appspawn的线程结束 * -- Gitee From def84a79b89abc21e5991c95f160e3c3846dc0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Thu, 23 Jan 2025 10:04:41 +0800 Subject: [PATCH 123/148] hisysevent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- hisysevent.yaml | 14 ++++- modules/common/BUILD.gn | 6 ++ modules/sandbox/sandbox_utils.cpp | 56 +++++++++++++++++-- modules/sysevent/hisysevent_adapter.cpp | 73 +++++++++++++++++++++++-- modules/sysevent/hisysevent_adapter.h | 14 ++++- standard/appspawn_service.c | 16 ++++-- 6 files changed, 162 insertions(+), 17 deletions(-) diff --git a/hisysevent.yaml b/hisysevent.yaml index 38bcc464..10df09ac 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -17,6 +17,13 @@ SPAWN_CHILD_PROCESS_FAIL: __BASE: {type: FAULT, level: CRITICAL, desc: Spawn Child Process Fail} PROCESS_NAME: {type: STRING, desc: Process Name} ERROR_CODE: {type: INT32, desc: Error Code} + SRC_PATH : {type: STRING, desc: Source Path For Mount Failed} + TARGET_PATH: {type: STRING, desc: Target Path For Mount Failed} + SPAWN_RESULT : {type: INT32, desc: Process Spawn Result} + +SPAWN_KEY_EVENT: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: Spawn Key Event Finish} + EVENT_NAME: {type: STRING, desc: Event Name} SPAWN_PROCESS_DURATION: __BASE: {type: STATISTIC, level: CRITICAL, desc: Boot Process Duration} @@ -24,4 +31,9 @@ SPAWN_PROCESS_DURATION: MINDURATION: {type: INT64, desc: Min Spawn Process Duration} TOTALDURATION: {type: INT64, desc: Total Spawn Process Duration} EVENTCOUNT: {type: INT64, desc: Total Spawn Process Count} - STAGE: {type: STRING, desc: Boot Stage Or BootFinished Stage} \ No newline at end of file + STAGE: {type: STRING, desc: Boot Stage Or BootFinished Stage} + +SPAWN_ABNORMAL_DURATION: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: Scene Duration} + SCENE_NAME: {type: STRING, desc: Scene Name} + DURATION: {type: INT64, desc: Scene Duration} \ No newline at end of file diff --git a/modules/common/BUILD.gn b/modules/common/BUILD.gn index 41c028f0..a8441284 100644 --- a/modules/common/BUILD.gn +++ b/modules/common/BUILD.gn @@ -84,6 +84,12 @@ ohos_shared_library("appspawn_common") { if (appspawn_allow_internet_permission) { defines += [ "APPSPAWN_ALLOW_INTERNET_PERMISSION" ] } + if (appspawn_report_event) { + defines += [ "APPSPAWN_HISYSEVENT" ] + external_deps += [ "hisysevent:libhisysevent" ] + include_dirs += [ "${appspawn_path}/modules/sysevent" ] + sources += [ "${appspawn_path}/modules/sysevent/hisysevent_adapter.cpp" ] + } subsystem_name = "${subsystem_name}" part_name = "${part_name}" diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index fccbb286..d24934a2 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -225,6 +225,37 @@ static void MakeDirRecursive(const std::string &path, mode_t mode) } while (index < size); } +static void MakeDirRecursiveWithClock(const std::string &path, mode_t mode) +{ + size_t size = path.size(); + if (size == 0) { + return; + } +#ifdef APPSPAWN_HISYSEVENT + struct timespec startClock = {0}; + clock_gettime(CLOCK_MONOTONIC, &startClock); +#endif + size_t index = 0; + do { + size_t pathIndex = path.find_first_of('/', index); + index = pathIndex == std::string::npos ? size : pathIndex + 1; + std::string dir = path.substr(0, index); +#ifndef APPSPAWN_TEST + APPSPAWN_CHECK(!(access(dir.c_str(), F_OK) < 0 && mkdir(dir.c_str(), mode) < 0), + return, "errno is %{public}d, mkdir %{public}s failed", errno, dir.c_str()); +#endif + } while (index < size); + +#ifdef APPSPAWN_HISYSEVENT + struct timespec endClock = {0}; + clock_gettime(CLOCK_MONOTONIC, &endClock); + uint64_t diff = DiffTime(&startClock, &endClock); + + APPSPAWN_CHECK_ONLY_EXPER(diff < FUNC_REPORT_DURATION, + ReportAbnormalDuration("MakeDirRecursive", diff)); +#endif +} + static bool CheckDirRecursive(const std::string &path) { size_t size = path.size(); @@ -308,6 +339,9 @@ int32_t SandboxUtils::DoAppSandboxMountOnce(const char *originPath, const char * clock_gettime(CLOCK_MONOTONIC_COARSE, &mountEnd); uint64_t diff = DiffTime(&mountStart, &mountEnd); APPSPAWN_CHECK_ONLY_LOG(diff < MAX_MOUNT_TIME, "mount %{public}s time %{public}" PRId64 " us", originPath, diff); +#ifdef APPSPAWN_HISYSEVENT + APPSPAWN_CHECK_ONLY_EXPER(diff < FUNC_REPORT_DURATION, ReportAbnormalDuration("MOUNT", diff)); +#endif if (ret != 0) { APPSPAWN_LOGI("errno is: %{public}d, bind mount %{public}s to %{public}s", errno, originPath, destinationPath); std::string originPathStr = originPath == nullptr ? "" : originPath; @@ -884,6 +918,10 @@ int SandboxUtils::DoAllMntPointsMount(const AppSpawningCtx *appProperty, if (actionStatus == g_statusCheck) { APPSPAWN_LOGE("DoAppSandboxMountOnce section %{public}s failed, %{public}s", section.c_str(), sandboxPath.c_str()); +#ifdef APPSPAWN_HISYSEVENT + ReportMountFail(bundleName.c_str(), srcPath.c_str(), sandboxPath.c_str(), errno); + ret = APPSPAWN_SANDBOX_MOUNT_FAIL; +#endif return ret; } } @@ -1646,9 +1684,19 @@ int32_t SandboxUtils::ChangeCurrentDir(std::string &sandboxPackagePath, const st return ret; } -static inline int EnableSandboxNamespace(AppSpawningCtx *appProperty, uint32_t sandboxNsFlags) +static int EnableSandboxNamespace(AppSpawningCtx *appProperty, uint32_t sandboxNsFlags) { +#ifdef APPSPAWN_HISYSEVENT + struct timespec startClock = {0}; + clock_gettime(CLOCK_MONOTONIC, &startClock); +#endif int rc = unshare(sandboxNsFlags); +#ifdef APPSPAWN_HISYSEVENT + struct timespec endClock = {0}; + clock_gettime(CLOCK_MONOTONIC, &endClock); + uint64_t diff = DiffTime(&startClock, &endClock); + APPSPAWN_CHECK_ONLY_EXPER(diff < FUNC_REPORT_DURATION, ReportAbnormalDuration("unshare", diff)); +#endif APPSPAWN_CHECK(rc == 0, return rc, "unshare failed, packagename is %{public}s", GetBundleName(appProperty)); if ((sandboxNsFlags & CLONE_NEWNET) == CLONE_NEWNET) { @@ -1727,18 +1775,16 @@ int32_t SandboxUtils::SetAppSandboxProperty(AppSpawningCtx *appProperty, uint32_ ACCESS_DLP_FILE_MODE.c_str()))) != 0); sandboxPackagePath += CheckAppMsgFlagsSet(appProperty, APP_FLAGS_ISOLATED_SANDBOX_TYPE) ? "isolated/" : ""; sandboxPackagePath += bundleName; - MakeDirRecursive(sandboxPackagePath.c_str(), FILE_MODE); + MakeDirRecursiveWithClock(sandboxPackagePath.c_str(), FILE_MODE); // add pid to a new mnt namespace int rc = EnableSandboxNamespace(appProperty, sandboxNsFlags); APPSPAWN_CHECK(rc == 0, return rc, "unshare failed, packagename is %{public}s", bundleName.c_str()); - if (UpdatePermissionFlags(appProperty) != 0) { APPSPAWN_LOGW("Set app permission flag fail."); return -1; } UpdateMsgFlagsWithPermission(appProperty); - // check app sandbox switch if ((CheckTotalSandboxSwitchStatus(appProperty) == false) || (CheckAppSandboxSwitchStatus(appProperty) == false)) { @@ -1775,7 +1821,7 @@ int32_t SandboxUtils::SetAppSandboxPropertyNweb(AppSpawningCtx *appProperty, uin const std::string bundleName = GetBundleName(appProperty); bool sandboxSharedStatus = GetSandboxPrivateSharedStatus(bundleName, appProperty); sandboxPackagePath += bundleName; - MakeDirRecursive(sandboxPackagePath.c_str(), FILE_MODE); + MakeDirRecursiveWithClock(sandboxPackagePath.c_str(), FILE_MODE); // add pid to a new mnt namespace int rc = EnableSandboxNamespace(appProperty, sandboxNsFlags); diff --git a/modules/sysevent/hisysevent_adapter.cpp b/modules/sysevent/hisysevent_adapter.cpp index 8e1dbad1..78711cf7 100644 --- a/modules/sysevent/hisysevent_adapter.cpp +++ b/modules/sysevent/hisysevent_adapter.cpp @@ -19,13 +19,28 @@ using namespace OHOS::HiviewDFX; namespace { -// event -constexpr const char* SPAWN_PROCESS_DURATION = "SPAWN_PROCESS_DURATION"; +// fail event constexpr const char* SPAWN_CHILD_PROCESS_FAIL = "SPAWN_CHILD_PROCESS_FAIL"; +// behavior event +constexpr const char* SPAWN_KEY_EVENT = "SPAWN_KEY_EVENT"; +constexpr const char* SPAWN_ABNORMAL_DURATION = "SPAWN_ABNORMAL_DURATION"; + +// statistic event +constexpr const char* SPAWN_PROCESS_DURATION = "SPAWN_PROCESS_DURATION"; + // param constexpr const char* PROCESS_NAME = "PROCESS_NAME"; constexpr const char* ERROR_CODE = "ERROR_CODE"; +constexpr const char* SPAWN_RESULT = "SPAWN_RESULT"; +constexpr const char* SRC_PATH = "SRC_PATH"; +constexpr const char* TARGET_PATH = "TARGET_PATH"; + +constexpr const char* EVENT_NAME = "EVENT_NAME"; + +constexpr const char* SCENE_NAME = "SCENE_NAME"; +constexpr const char* DURATION = "DURATION"; + constexpr const char* MAXDURATION = "MAXDURATION"; constexpr const char* MINDURATION = "MINDURATION"; constexpr const char* TOTALDURATION = "TOTALDURATION"; @@ -121,14 +136,60 @@ AppSpawnHisyseventInfo *InitHisyseventTimer(void) return hisyseventInfo; } -void ReportSpawnChildProcessFail(const char* processName, int32_t errorCode) +void ReportSpawnChildProcessFail(const char* processName, int32_t errorCode, int32_t spawnResult) { + if (spawnResult == APPSPAWN_SANDBOX_MOUNT_FAIL) { + return; + } int ret = HiSysEventWrite(HiSysEvent::Domain::APPSPAWN, SPAWN_CHILD_PROCESS_FAIL, HiSysEvent::EventType::FAULT, PROCESS_NAME, processName, - ERROR_CODE, errorCode); + ERROR_CODE, errorCode, + SPAWN_RESULT, spawnResult); + if (ret != 0) { + APPSPAWN_LOGE("ReportSpawnChildProcessFail error, ret: %{public}d", ret); + } +} + +void ReportMountFail(const char* bundleName, const char* srcPath, const char* targetPath, + int32_t spawnResult) +{ + if (srcPath == nullptr || (strstr(srcPath, "data/app/el1/") == nullptr && + strstr(srcPath, "data/app/el2/") == nullptr)) { + return; + } + int ret = HiSysEventWrite(HiSysEvent::Domain::APPSPAWN, SPAWN_CHILD_PROCESS_FAIL, + HiSysEvent::EventType::FAULT, + PROCESS_NAME, bundleName, + ERROR_CODE, ERR_APPSPAWN_CHILD_MOUNT_FAILED, + SRC_PATH, srcPath, + TARGET_PATH, targetPath, + SPAWN_RESULT, spawnResult); + if (ret != 0) { + APPSPAWN_LOGE("ReportMountFail error, ret: %{public}d", ret); + } +} + +void ReportKeyEvent(const char *eventName) +{ + int ret = HiSysEventWrite(HiSysEvent::Domain::APPSPAWN, SPAWN_KEY_EVENT, + HiSysEvent::EventType::BEHAVIOR, + EVENT_NAME, eventName); + if (ret != 0) { + APPSPAWN_LOGE("ReportKeyEvent error, ret: %{public}d", ret); + } +} + +void ReportAbnormalDuration(const char* scene, uint64_t duration) +{ + APPSPAWN_LOGI("ReportAbnormalDuration %{public}d with %{public}s %{public}" PRId64 " us", + getpid(), scene, duration); + int ret = HiSysEventWrite(HiSysEvent::Domain::APPSPAWN, SPAWN_ABNORMAL_DURATION, + HiSysEvent::EventType::BEHAVIOR, + SCENE_NAME, scene, + DURATION, duration); if (ret != 0) { - APPSPAWN_LOGE("HiSysEventWrite error, ret: %{public}d", ret); + APPSPAWN_LOGE("ReportAbnormalDuration error, ret: %{public}d", ret); } } @@ -142,7 +203,7 @@ void ReportSpawnProcessDuration(AppSpawnHisysevent *hisysevent, const char* stag EVENTCOUNT, hisysevent->eventCount, STAGE, stage); if (ret != 0) { - APPSPAWN_LOGE("HiSysEventWrite error, ret: %{public}d", ret); + APPSPAWN_LOGE("ReportSpawnProcessDuration error, ret: %{public}d", ret); } } diff --git a/modules/sysevent/hisysevent_adapter.h b/modules/sysevent/hisysevent_adapter.h index 89f3fbac..1e9fb62e 100644 --- a/modules/sysevent/hisysevent_adapter.h +++ b/modules/sysevent/hisysevent_adapter.h @@ -73,6 +73,7 @@ typedef enum { ERR_APPSPAWN_SPAWN_FAIL = ERR_APPSPAWN_BASE + 0x0381, ERR_APPSPAWN_SPAWN_TIMEOUT, ERR_APPSPAWN_CHILD_CRASH, + ERR_APPSPAWN_CHILD_MOUNT_FAILED, ERR_APPSPAWN_MAX_FAILURES_EXCEEDED, } AppSpawnHisysErrorCode; @@ -88,12 +89,23 @@ typedef struct { AppSpawnHisysevent manualEvent; // bootFinished } AppSpawnHisyseventInfo; +#define FUNC_REPORT_DURATION (20 * 1000) +#define SPAWN_DURATION (120 * 1000) +#define SPAWN_COLDRUN_DURATION (5 * 1000 * 1000) + +#define UNLOCK_SUCCESS "UNLOCK_SUCCESS" +#define LOCK_SUCCESS "LOCK_SUCCESS" +#define APPSPAWN_MAX_FAILURES_EXCEEDED "APPSPAWN_MAX_FAILURES_EXCEEDED" AppSpawnHisyseventInfo *InitHisyseventTimer(void); AppSpawnHisyseventInfo *GetAppSpawnHisyseventInfo(void); void AddStatisticEventInfo(AppSpawnHisyseventInfo *hisyseventInfo, uint32_t duration, bool stage); void DeleteHisyseventInfo(AppSpawnHisyseventInfo *hisyseventInfo); -void ReportSpawnChildProcessFail(const char* processName, int32_t errorCode); +void ReportSpawnChildProcessFail(const char* processName, int32_t errorCode, int32_t spawnResult); +void ReportMountFail(const char* bundleName, const char* srcPath, const char* targetPath, + int32_t spawnResult); +void ReportKeyEvent(const char *eventName); +void ReportAbnormalDuration(const char* funcName, uint64_t duration); void ReportSpawnStatisticDuration(const TimerHandle taskHandle, void* content); #ifdef __cplusplus diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 1764d93c..6ed135e6 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -943,7 +943,7 @@ static void WaitChildDied(pid_t pid) APPSPAWN_LOGI("Child process %{public}s fail \'child crash \'pid %{public}d appId: %{public}d", processName, property->pid, property->client.id); #ifdef APPSPAWN_HISYSEVENT - ReportSpawnChildProcessFail(processName, ERR_APPSPAWN_CHILD_CRASH); + ReportSpawnChildProcessFail(processName, ERR_APPSPAWN_CHILD_CRASH, APPSPAWN_CHILD_CRASH); #endif if (property->client.id == g_lastDiedAppId + 1) { g_crashTimes++; @@ -958,7 +958,7 @@ static void WaitChildDied(pid_t pid) if (g_crashTimes >= MAX_CRASH_TIME) { APPSPAWN_LOGW("Continuous failures in spawning the app, restart appspawn"); #ifdef APPSPAWN_HISYSEVENT - ReportSpawnChildProcessFail(processName, ERR_APPSPAWN_MAX_FAILURES_EXCEEDED); + ReportKeyEvent(APPSPAWN_MAX_FAILURES_EXCEEDED); #endif StopAppSpawn(); } @@ -977,7 +977,7 @@ static void WaitChildTimeout(const TimerHandle taskHandle, void *context) kill(property->pid, SIGKILL); } #ifdef APPSPAWN_HISYSEVENT - ReportSpawnChildProcessFail(GetProcessName(property), ERR_APPSPAWN_SPAWN_TIMEOUT); + ReportSpawnChildProcessFail(GetProcessName(property), ERR_APPSPAWN_SPAWN_TIMEOUT, APPSPAWN_SPAWN_TIMEOUT); #endif SendResponse(property->message->connection, &property->message->msgHeader, APPSPAWN_SPAWN_TIMEOUT, 0); DeleteAppSpawningCtx(property); @@ -993,7 +993,7 @@ static int ProcessChildFdCheck(int fd, AppSpawningCtx *property) if (result != 0) { #ifdef APPSPAWN_HISYSEVENT - ReportSpawnChildProcessFail(GetProcessName(property), ERR_APPSPAWN_SPAWN_FAIL); + ReportSpawnChildProcessFail(GetProcessName(property), ERR_APPSPAWN_SPAWN_FAIL, result); #endif SendResponse(property->message->connection, &property->message->msgHeader, result, property->pid); DeleteAppSpawningCtx(property); @@ -1038,6 +1038,11 @@ static void ProcessChildResponse(const WatcherHandle taskHandle, int fd, uint32_ if (appspawnMgr != NULL) { AddStatisticEventInfo(appspawnMgr->hisyseventInfo, spawnProcessDuration, IsBootFinished()); } +#ifndef ASAN_DETECTOR + uint64_t diff = DiffTime(&appInfo->spawnStart, &appInfo->spawnEnd); + APPSPAWN_CHECK_ONLY_EXPER(diff < (IsChildColdRun(property) ? SPAWN_COLDRUN_DURATION : SPAWN_DURATION), + ReportAbnormalDuration("SPAWNCHILD", diff)); +#endif #endif } @@ -1685,6 +1690,9 @@ static void ProcessAppSpawnLockStatusMsg(AppSpawnMsgNode *message) APPSPAWN_CHECK(ret > 0, return, "get lock status param failed, errno %{public}d", errno); ret = SetParameter(lockStatusParam, userLockStatus); APPSPAWN_CHECK(ret == 0, return, "failed to set lockstatus param value ret %{public}d", ret); +#ifdef APPSPAWN_HISYSEVENT + ReportKeyEvent(strcmp(userLockStatus, "0") == 0 ? UNLOCK_SUCCESS : LOCK_SUCCESS); +#endif #ifndef APPSPAWN_SANDBOX_NEW if (strcmp(userLockStatus, "0") == 0) { ServerStageHookExecute(STAGE_SERVER_LOCK, GetAppSpawnContent()); -- Gitee From c1f65e39018ca3e1f4f8cfb86b04c4458fe9da41 Mon Sep 17 00:00:00 2001 From: liujiaxing19 Date: Thu, 23 Jan 2025 18:11:56 +0800 Subject: [PATCH 124/148] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=86=E8=BA=AB?= =?UTF-8?q?=E5=92=8C=E5=85=83=E6=9C=8D=E5=8A=A1=E6=95=85=E9=9A=9C=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E9=9A=94=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liujiaxing19 Change-Id: I712d85f4f34edb834ad4d9dfb21aec265be72823 --- appdata-sandbox-app.json | 2 +- appdata-sandbox.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appdata-sandbox-app.json b/appdata-sandbox-app.json index a91144e1..88e351c2 100755 --- a/appdata-sandbox-app.json +++ b/appdata-sandbox-app.json @@ -491,7 +491,7 @@ "src-path": "/data/app/el2//database/", "sandbox-path": "/database" }, { - "src-path": "/data/app/el2//log/", + "src-path": "/data/app/el2//log/", "sandbox-path": "/log" }, { "src-path": "/mnt/hmdfs//non_account/merge_view/data", diff --git a/appdata-sandbox.json b/appdata-sandbox.json index 463b1ea3..36c5bb06 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -119,7 +119,7 @@ "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/data/app/el2//log/", + "src-path" : "/data/app/el2//log/", "sandbox-path" : "/data/storage/el2/log", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" -- Gitee From 8c2df0e353fd1684dc3c2fc0881bf8278823515f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Thu, 23 Jan 2025 18:55:04 +0800 Subject: [PATCH 125/148] fix bug for fd close MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- standard/appspawn_service.c | 1 + 1 file changed, 1 insertion(+) diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index eb61cd20..74a8425c 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -1780,6 +1780,7 @@ APPSPAWN_STATIC void ProcessObserveProcessSignalMsg(AppSpawnConnection *connecti AppSpawnContent *content = GetAppSpawnContent(); content->signalFd = fd; + connection->receiverCtx.fdCount = 0; SendResponse(connection, &message->msgHeader, 0, 0); DeleteAppSpawnMsg(message); } -- Gitee From ec79997746fecdd0db6c13312c86cc5d2a882d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Thu, 23 Jan 2025 19:01:58 +0800 Subject: [PATCH 126/148] change send fd time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- interfaces/innerkits/client/appspawn_client.c | 10 +++++----- .../app_spawn_standard_test/app_spawn_service_test.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/interfaces/innerkits/client/appspawn_client.c b/interfaces/innerkits/client/appspawn_client.c index 458fb13c..44876165 100644 --- a/interfaces/innerkits/client/appspawn_client.c +++ b/interfaces/innerkits/client/appspawn_client.c @@ -284,6 +284,11 @@ static int ClientSendMsg(AppSpawnReqMsgMgr *reqMgr, AppSpawnReqMsgNode *reqNode, continue; } } + if (reqNode->msg->msgType != MSG_OBSERVE_PROCESS_SIGNAL_STATUS) { + pthread_mutex_lock(&g_spawnListenMutex); + SpawnListen(reqMgr, reqNode->msg->processName); + pthread_mutex_unlock(&g_spawnListenMutex); + } if (isColdRun && reqMgr->timeout < ASAN_TIMEOUT) { UpdateSocketTimeout(ASAN_TIMEOUT, reqMgr->socketId); } @@ -299,11 +304,6 @@ static int ClientSendMsg(AppSpawnReqMsgMgr *reqMgr, AppSpawnReqMsgNode *reqNode, if (isColdRun && reqMgr->timeout < ASAN_TIMEOUT) { UpdateSocketTimeout(reqMgr->timeout, reqMgr->socketId); } - if (reqNode->msg->msgType != MSG_OBSERVE_PROCESS_SIGNAL_STATUS) { - pthread_mutex_lock(&g_spawnListenMutex); - SpawnListen(reqMgr, reqNode->msg->processName); - pthread_mutex_unlock(&g_spawnListenMutex); - } return 0; } // retry diff --git a/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp index c22f749e..18b4a860 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp @@ -738,7 +738,7 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_012, TestSize.Level0) } close(pipefd[0]); close(pipefd[1]); - ASSERT_EQ(isFind, false); + ASSERT_EQ(isFind, true); SpawnListenCloseSet(); } while (0); } -- Gitee From f853d947482d3132c5c4620db872c01880deea2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Fri, 24 Jan 2025 17:51:29 +0800 Subject: [PATCH 127/148] add uid to fd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- interfaces/innerkits/client/appspawn_client.c | 3 +- standard/appspawn_service.c | 77 +++++++++---------- 2 files changed, 38 insertions(+), 42 deletions(-) diff --git a/interfaces/innerkits/client/appspawn_client.c b/interfaces/innerkits/client/appspawn_client.c index 44876165..42b4df0c 100644 --- a/interfaces/innerkits/client/appspawn_client.c +++ b/interfaces/innerkits/client/appspawn_client.c @@ -344,8 +344,7 @@ APPSPAWN_STATIC void SpawnListen(AppSpawnReqMsgMgr *reqMgr, const char *processN APPSPAWN_CHECK(result.result == 0, return, "Appspawn failed to handle message, result=%{public}d", result.result); g_spawnListenStart = true; - APPSPAWN_LOGI("Spawn Listen client type[%{public}d]] Send fd[%{public}d] success", type, g_spawnListenFd); - return; + APPSPAWN_LOGI("Spawn Listen client type[%{public}d] Send fd[%{public}d] success", type, g_spawnListenFd); } int AppSpawnClientInit(const char *serviceName, AppSpawnClientHandle *handle) diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 74a8425c..23839a98 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -130,16 +130,46 @@ static void StopAppSpawn(void) LE_StopLoop(LE_GetDefaultLoop()); } -static inline void DumpStatus(const char *appName, pid_t pid, int status) +static inline void DumpStatus(const char *appName, pid_t pid, int status, int *signal) { if (WIFSIGNALED(status)) { - APPSPAWN_LOGW("%{public}s with pid %{public}d exit with signal:%{public}d", appName, pid, WTERMSIG(status)); + *signal = WTERMSIG(status); + APPSPAWN_LOGW("%{public}s with pid %{public}d exit with signal:%{public}d", appName, pid, *signal); } if (WIFEXITED(status)) { - APPSPAWN_LOGW("%{public}s with pid %{public}d exit with code:%{public}d", appName, pid, WEXITSTATUS(status)); + *signal = WEXITSTATUS(status); + APPSPAWN_LOGW("%{public}s with pid %{public}d exit with code:%{public}d", appName, pid, *signal); } } +APPSPAWN_STATIC void WriteSignalInfoToFd(pid_t pid, uid_t uid, int signal) +{ + AppSpawnContent *content = GetAppSpawnContent(); + APPSPAWN_CHECK(content->signalFd > 0, return, "Invalid signal fd[%{public}d]", content->signalFd); + APPSPAWN_CHECK(pid > 0, return, "Invalid pid[%{public}d]", pid); + APPSPAWN_CHECK(uid > 0, return, "Invalid uid[%{public}d]", uid); + + cJSON *root = cJSON_CreateObject(); + if (root == NULL) { + APPSPAWN_LOGE("signal json write create root object unsuccess"); + return; + } + cJSON_AddNumberToObject(root, "pid", pid); + cJSON_AddNumberToObject(root, "uid", uid); + cJSON_AddNumberToObject(root, "signal", signal); + char *jsonString = cJSON_Print(root); + cJSON_Delete(root); + + int ret = write(content->signalFd, jsonString, strlen(jsonString) + 1); + if (ret < 0) { + free(jsonString); + APPSPAWN_LOGE("Spawn Listen failed to write signal info to fd errno %{public}d", errno); + return; + } + APPSPAWN_LOGI("Spawn Listen successfully write signal info[%{public}s] to fd", jsonString); + free(jsonString); +} + static void HandleDiedPid(pid_t pid, uid_t uid, int status) { AppSpawnContent *content = GetAppSpawnContent(); @@ -149,16 +179,18 @@ static void HandleDiedPid(pid_t pid, uid_t uid, int status) APPSPAWN_LOGW("HandleDiedPid with reservedPid %{public}d", pid); content->reservedPid = 0; } + int signal = 0; AppSpawnedProcess *appInfo = GetSpawnedProcess(pid); if (appInfo == NULL) { // If an exception occurs during app spawning, kill pid, return failed WaitChildDied(pid); - DumpStatus("unknown", pid, status); + DumpStatus("unknown", pid, status, &signal); return; } appInfo->exitStatus = status; APPSPAWN_CHECK_ONLY_LOG(appInfo->uid == uid, "Invalid uid %{public}u %{public}u", appInfo->uid, uid); - DumpStatus(appInfo->name, pid, status); + DumpStatus(appInfo->name, pid, status, &signal); + WriteSignalInfoToFd(pid, appInfo->uid, signal); ProcessMgrHookExecute(STAGE_SERVER_APP_DIED, GetAppSpawnContent(), appInfo); ProcessMgrHookExecute(STAGE_SERVER_APP_UMOUNT, GetAppSpawnContent(), appInfo); @@ -174,40 +206,6 @@ static void HandleDiedPid(pid_t pid, uid_t uid, int status) TerminateSpawnedProcess(appInfo); } -APPSPAWN_STATIC void WriteSignalInfoToFd(pid_t pid, int status) -{ - AppSpawnContent *content = GetAppSpawnContent(); - APPSPAWN_CHECK(content->signalFd > 0, return, "Invalid signal fd[%{public}d]", content->signalFd); - APPSPAWN_CHECK(pid > 0, return, "Invalid pid[%{public}d]", pid); - - int signal = 0; - if (WIFSIGNALED(status)) { - signal = WTERMSIG(status); - } - if (WIFEXITED(status)) { - signal = WEXITSTATUS(status); - } - - cJSON *root = cJSON_CreateObject(); - if (root == NULL) { - APPSPAWN_LOGE("signal json write create root object unsuccess"); - return; - } - cJSON_AddNumberToObject(root, "pid", pid); - cJSON_AddNumberToObject(root, "signal", signal); - char *jsonString = cJSON_Print(root); - cJSON_Delete(root); - - int ret = write(content->signalFd, jsonString, strlen(jsonString) + 1); - if (ret < 0) { - free(jsonString); - APPSPAWN_LOGE("Spawn Listen failed to write signal info to fd errno %{public}d", errno); - return; - } - APPSPAWN_LOGI("Spawn Listen successfully write signal info[%{public}s] to fd", jsonString); - free(jsonString); -} - APPSPAWN_STATIC void ProcessSignal(const struct signalfd_siginfo *siginfo) { APPSPAWN_LOGI("ProcessSignal signum %{public}d %{public}d", siginfo->ssi_signo, siginfo->ssi_pid); @@ -219,7 +217,6 @@ APPSPAWN_STATIC void ProcessSignal(const struct signalfd_siginfo *siginfo) APPSPAWN_CHECK(WIFSIGNALED(status) || WIFEXITED(status), return, "ProcessSignal with wrong status:%{public}d", status); HandleDiedPid(pid, siginfo->ssi_uid, status); - WriteSignalInfoToFd(pid, status); } #if (defined(CJAPP_SPAWN) || defined(NATIVE_SPAWN)) if (OH_ListGetCnt(&GetAppSpawnMgr()->appQueue) == 0) { -- Gitee From 08145b7abb043b182f288a613f4db0e278cc4642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Fri, 24 Jan 2025 20:32:48 +0800 Subject: [PATCH 128/148] delete log and space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- interfaces/innerkits/client/appspawn_client.c | 3 +-- interfaces/innerkits/include/appspawn.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/interfaces/innerkits/client/appspawn_client.c b/interfaces/innerkits/client/appspawn_client.c index 42b4df0c..563b0569 100644 --- a/interfaces/innerkits/client/appspawn_client.c +++ b/interfaces/innerkits/client/appspawn_client.c @@ -327,8 +327,7 @@ APPSPAWN_STATIC void SpawnListen(AppSpawnReqMsgMgr *reqMgr, const char *processN APPSPAWN_CHECK((type == CLIENT_FOR_APPSPAWN), return, "Invalid type"); APPSPAWN_CHECK(processName != NULL, return, "Invalid process name"); - APPSPAWN_LOGI("Spawn Listen start type:%{public}d,fd:%{public}d,start:%{public}d", type, g_spawnListenFd, - g_spawnListenStart); + APPSPAWN_LOGI("Spawn Listen start type:%{public}d,fd:%{public}d", type, g_spawnListenFd); AppSpawnReqMsgHandle reqHandle; int ret = AppSpawnReqMsgCreate(MSG_OBSERVE_PROCESS_SIGNAL_STATUS, processName, &reqHandle); diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index 5bf6623e..1abb96d7 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -351,7 +351,6 @@ const char *GetPermissionByIndex(AppSpawnClientHandle handle, int32_t index); */ int SpawnListenFdSet(int fd); - /** * @brief close the listener for child process exit * -- Gitee From d8d0de5470ea6ce45c45e899239829ff263df338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Sun, 26 Jan 2025 09:32:44 +0800 Subject: [PATCH 129/148] =?UTF-8?q?=E6=96=B0=E5=A2=9EbundleName=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- standard/appspawn_service.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 23839a98..5350c3e0 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -142,21 +142,23 @@ static inline void DumpStatus(const char *appName, pid_t pid, int status, int *s } } -APPSPAWN_STATIC void WriteSignalInfoToFd(pid_t pid, uid_t uid, int signal) +APPSPAWN_STATIC void WriteSignalInfoToFd(AppSpawnedProcess *appInfo, int signal) { AppSpawnContent *content = GetAppSpawnContent(); APPSPAWN_CHECK(content->signalFd > 0, return, "Invalid signal fd[%{public}d]", content->signalFd); - APPSPAWN_CHECK(pid > 0, return, "Invalid pid[%{public}d]", pid); - APPSPAWN_CHECK(uid > 0, return, "Invalid uid[%{public}d]", uid); + APPSPAWN_CHECK(appInfo->pid > 0, return, "Invalid pid[%{public}d]", appInfo->pid); + APPSPAWN_CHECK(appInfo->uid > 0, return, "Invalid uid[%{public}d]", appInfo->uid); + APPSPAWN_CHECK(appInfo->name != NULL, return, "Invalid name[%{public}s]", appInfo->name); cJSON *root = cJSON_CreateObject(); if (root == NULL) { APPSPAWN_LOGE("signal json write create root object unsuccess"); return; } - cJSON_AddNumberToObject(root, "pid", pid); - cJSON_AddNumberToObject(root, "uid", uid); + cJSON_AddNumberToObject(root, "pid", appInfo->pid); + cJSON_AddNumberToObject(root, "uid", appInfo->uid); cJSON_AddNumberToObject(root, "signal", signal); + cJSON_AddStringToObject(root, "bundleName", appInfo->name); char *jsonString = cJSON_Print(root); cJSON_Delete(root); @@ -190,7 +192,7 @@ static void HandleDiedPid(pid_t pid, uid_t uid, int status) appInfo->exitStatus = status; APPSPAWN_CHECK_ONLY_LOG(appInfo->uid == uid, "Invalid uid %{public}u %{public}u", appInfo->uid, uid); DumpStatus(appInfo->name, pid, status, &signal); - WriteSignalInfoToFd(pid, appInfo->uid, signal); + WriteSignalInfoToFd(appInfo, signal); ProcessMgrHookExecute(STAGE_SERVER_APP_DIED, GetAppSpawnContent(), appInfo); ProcessMgrHookExecute(STAGE_SERVER_APP_UMOUNT, GetAppSpawnContent(), appInfo); -- Gitee From 241b9e4a44a31545b87890e70bc1e4dbf77270f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Sun, 26 Jan 2025 15:16:12 +0800 Subject: [PATCH 130/148] fix content is null MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- standard/appspawn_service.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index c552b201..5fb55e3c 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -141,13 +141,12 @@ static inline void DumpStatus(const char *appName, pid_t pid, int status, int *s } } -APPSPAWN_STATIC void WriteSignalInfoToFd(AppSpawnedProcess *appInfo, int signal) +APPSPAWN_STATIC void WriteSignalInfoToFd(AppSpawnedProcess *appInfo, AppSpawnContent *content, int signal) { - AppSpawnContent *content = GetAppSpawnContent(); APPSPAWN_CHECK(content->signalFd > 0, return, "Invalid signal fd[%{public}d]", content->signalFd); APPSPAWN_CHECK(appInfo->pid > 0, return, "Invalid pid[%{public}d]", appInfo->pid); APPSPAWN_CHECK(appInfo->uid > 0, return, "Invalid uid[%{public}d]", appInfo->uid); - APPSPAWN_CHECK(appInfo->name != NULL, return, "Invalid name[%{public}s]", appInfo->name); + APPSPAWN_CHECK(appInfo->name != NULL, return, "Invalid name"); cJSON *root = cJSON_CreateObject(); if (root == NULL) { @@ -191,7 +190,7 @@ static void HandleDiedPid(pid_t pid, uid_t uid, int status) appInfo->exitStatus = status; APPSPAWN_CHECK_ONLY_LOG(appInfo->uid == uid, "Invalid uid %{public}u %{public}u", appInfo->uid, uid); DumpStatus(appInfo->name, pid, status, &signal); - WriteSignalInfoToFd(appInfo, signal); + WriteSignalInfoToFd(appInfo, content, signal); ProcessMgrHookExecute(STAGE_SERVER_APP_DIED, GetAppSpawnContent(), appInfo); ProcessMgrHookExecute(STAGE_SERVER_APP_UMOUNT, GetAppSpawnContent(), appInfo); @@ -1809,6 +1808,7 @@ APPSPAWN_STATIC void ProcessObserveProcessSignalMsg(AppSpawnConnection *connecti } AppSpawnContent *content = GetAppSpawnContent(); + APPSPAWN_CHECK(content != NULL, return, "Spawn Listen appspawn content is null"); content->signalFd = fd; connection->receiverCtx.fdCount = 0; SendResponse(connection, &message->msgHeader, 0, 0); -- Gitee From a54fb0875510eb3c1e97a568d6bcb40edd5c0851 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Sun, 26 Jan 2025 16:58:34 +0800 Subject: [PATCH 131/148] Add the logic of datagroup deduplication Signed-off-by: wangfeng --- modules/sandbox/sandbox_shared_mount.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/sandbox/sandbox_shared_mount.cpp b/modules/sandbox/sandbox_shared_mount.cpp index da2b651a..dd30935a 100644 --- a/modules/sandbox/sandbox_shared_mount.cpp +++ b/modules/sandbox/sandbox_shared_mount.cpp @@ -415,6 +415,22 @@ static inline bool CheckPath(const std::string& name) return !name.empty() && name != "." && name != ".." && name.find("/") == std::string::npos; } +static int DataGroupCtxNodeCompare(ListNode *node, void *data) +{ + DataGroupCtx *existingNode = (DataGroupCtx *)ListEntry(node, DataGroupCtx, node); + DataGroupCtx *newNode = (DataGroupCtx *)data; + if (existingNode == nullptr || newNode == nullptr) { + APPSPAWN_LOGE("Invalid param"); + return APPSPAWN_ARG_INVALID; + } + + // compare src path and sandbox path + bool isSrcPathEqual = (strcmp(existingNode->srcPath.path, newNode->srcPath.path) == 0); + bool isDestPathEqual = (strcmp(existingNode->destPath.path, newNode->destPath.path) == 0); + + return (isSrcPathEqual && isDestPathEqual) ? 0 : 1; +} + static int AddDataGroupItemToQueue(AppSpawnMgr *content, const std::string &srcPath, const std::string &destPath, const std::string &dataGroupUuid) { @@ -429,6 +445,11 @@ static int AddDataGroupItemToQueue(AppSpawnMgr *content, const std::string &srcP } dataGroupNode->srcPath.pathLen = strlen(dataGroupNode->srcPath.path); dataGroupNode->destPath.pathLen = strlen(dataGroupNode->destPath.path); + ListNode *node = OH_ListFind(&content->dataGroupCtxQueue, (void*)dataGroupNode, DataGroupCtxNodeCompare); + if (node != nullptr) { + APPSPAWN_LOGI("DataGroupCtxNode %{public}s is exist", dataGroupNode->srcPath.path); + return 0; + } OH_ListInit(&dataGroupNode->node); OH_ListAddTail(&content->dataGroupCtxQueue, &dataGroupNode->node); return 0; -- Gitee From d55d1511d9b68846bf881c3945dfb81dc8a7013c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Wed, 5 Feb 2025 10:54:53 +0800 Subject: [PATCH 132/148] fix path traversal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- service/hnp/base/hnp_zip.c | 4 ++-- service/hnp/installer/src/hnp_installer.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/service/hnp/base/hnp_zip.c b/service/hnp/base/hnp_zip.c index ad7a5762..f9877d77 100644 --- a/service/hnp/base/hnp_zip.c +++ b/service/hnp/base/hnp_zip.c @@ -445,8 +445,8 @@ int HnpUnZip(const char *inputFile, const char *outputDir, const char *hnpSignKe unzClose(zipFile); return HNP_ERRNO_BASE_UNZIP_GET_INFO_FAILED; } - if (strstr(fileName, "../")) { - HNP_LOGE("unzip filename[%{public}s],does not allow the use of ../", fileName); + if (strstr(fileName, "..")) { + HNP_LOGE("unzip filename[%{public}s],does not allow the use of ..", fileName); unzClose(zipFile); return HNP_ERRNO_BASE_UNZIP_GET_INFO_FAILED; } diff --git a/service/hnp/installer/src/hnp_installer.c b/service/hnp/installer/src/hnp_installer.c index fb671f25..c8bee464 100644 --- a/service/hnp/installer/src/hnp_installer.c +++ b/service/hnp/installer/src/hnp_installer.c @@ -63,8 +63,8 @@ static int HnpGenerateSoftLinkAllByJson(const char *installPath, const char *dst } for (unsigned int i = 0; i < hnpCfg->linkNum; i++) { - if (strstr(currentLink->source, "../") || strstr(currentLink->target, "../")) { - HNP_LOGE("hnp json link source[%{public}s],target[%{public}s],does not allow the use of ../", + if (strstr(currentLink->source, "..") || strstr(currentLink->target, "..")) { + HNP_LOGE("hnp json link source[%{public}s],target[%{public}s],does not allow the use of ..", currentLink->source, currentLink->target); return HNP_ERRNO_INSTALLER_GET_HNP_PATH_FAILED; } @@ -375,8 +375,8 @@ static int HnpInstallPathGet(HnpCfgInfo *hnpCfgInfo, HnpInstallInfo *hnpInfo) HNP_LOGE("hnp install sprintf install path unsuccess."); return HNP_ERRNO_BASE_SPRINTF_FAILED; } - if (strstr(hnpInfo->hnpVersionPath, "../")) { - HNP_LOGE("hnp version path[%{public}s], does not allow the use of ../", hnpInfo->hnpVersionPath); + if (strstr(hnpInfo->hnpVersionPath, "..")) { + HNP_LOGE("hnp version path[%{public}s], does not allow the use of ..", hnpInfo->hnpVersionPath); return HNP_ERRNO_INSTALLER_GET_HNP_PATH_FAILED; } -- Gitee From f80f7de8eb7d24d391562a6ed626fe9ab70ef9cb Mon Sep 17 00:00:00 2001 From: liuyics15 <1179805842@qq.com> Date: Thu, 6 Feb 2025 11:00:55 +0800 Subject: [PATCH 133/148] appspawn preload cj libraries Signed-off-by: liuyics15 <1179805842@qq.com> --- modules/ace_adapter/ace_adapter.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/ace_adapter/ace_adapter.cpp b/modules/ace_adapter/ace_adapter.cpp index 9ff87a79..d22fcfd3 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -131,6 +131,18 @@ static void LoadExtendLib(void) APPSPAWN_LOGI("LoadExtendLib: End preload JS VM"); } +APPSPAWN_STATIC void PreloadCJLibs(void) +{ + const char* cjEnvLibName = "libcj_environment.z.so"; + const char* cjEnvInitName = "OHOS_InitSpawnEnv"; + void* cjEnvLib = dlopen(cjEnvLibName, RTLD_NOW | RTLD_LOCAL); + APPSPAWN_CHECK(cjEnvLib != nullptr, return, "Failed to dlopen %{public}s, [%{public}s]", cjEnvLibName, dlerror()); + auto symbol = dlsym(cjEnvLib, cjEnvInitName); + APPSPAWN_CHECK(symbol != nullptr, return, "Failed to dlsym %{public}s, [%{public}s]", cjEnvInitName, dlerror()); + auto initSpawnEnv = reinterpret_cast(symbol); + initSpawnEnv(); +} + APPSPAWN_STATIC void LoadExtendCJLib(void) { const char *acelibdir = OHOS::Ace::AceForwardCompatibility::GetAceLibName(); @@ -140,6 +152,8 @@ APPSPAWN_STATIC void LoadExtendCJLib(void) APPSPAWN_LOGI("LoadExtendLib: Success to dlopen %{public}s", acelibdir); OHOS::AppExecFwk::MainThread::PreloadExtensionPlugin(); + + PreloadCJLibs(); } APPSPAWN_STATIC int BuildFdInfoMap(const AppSpawnMsgNode *message, std::map &fdMap, int isColdRun) -- Gitee From 55c2ddb34c461fe19812add6dcb4fe3dbaeb488c Mon Sep 17 00:00:00 2001 From: YinZong Date: Thu, 6 Feb 2025 07:10:18 +0000 Subject: [PATCH 134/148] update modules/common/appspawn_adapter.cpp. Signed-off-by: YinZong --- modules/common/appspawn_adapter.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/common/appspawn_adapter.cpp b/modules/common/appspawn_adapter.cpp index 7f4d0395..65c81b25 100644 --- a/modules/common/appspawn_adapter.cpp +++ b/modules/common/appspawn_adapter.cpp @@ -202,6 +202,10 @@ int SetSeccompFilter(const AppSpawnMgr *content, const AppSpawningCtx *property) appName = IMF_EXTENTOIN_NAME; } + if (CheckAppMsgFlagsSet(property, APP_FLAGS_ATOMIC_SERVICE) != 0) { + appName = APP_ATOMIC; + } + if (!SetSeccompPolicyWithName(type, appName)) { APPSPAWN_LOGE("Failed to set %{public}s seccomp filter and exit %{public}d", appName, errno); return -EINVAL; -- Gitee From 688572944d7dbc8e30097be913a93ab4b17421d7 Mon Sep 17 00:00:00 2001 From: liuyics15 <1179805842@qq.com> Date: Fri, 7 Feb 2025 16:45:37 +0800 Subject: [PATCH 135/148] appspawn preload cj libraries fix exp case Signed-off-by: liuyics15 <1179805842@qq.com> --- modules/ace_adapter/ace_adapter.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/ace_adapter/ace_adapter.cpp b/modules/ace_adapter/ace_adapter.cpp index d22fcfd3..37da3a22 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -138,7 +138,11 @@ APPSPAWN_STATIC void PreloadCJLibs(void) void* cjEnvLib = dlopen(cjEnvLibName, RTLD_NOW | RTLD_LOCAL); APPSPAWN_CHECK(cjEnvLib != nullptr, return, "Failed to dlopen %{public}s, [%{public}s]", cjEnvLibName, dlerror()); auto symbol = dlsym(cjEnvLib, cjEnvInitName); - APPSPAWN_CHECK(symbol != nullptr, return, "Failed to dlsym %{public}s, [%{public}s]", cjEnvInitName, dlerror()); + if (!symbol) { + dlclose(cjEnvLib); + APPSPAWN_LOGE("Failed to dlsym %{public}s, [%{public}s]", cjEnvInitName, dlerror()); + return; + } auto initSpawnEnv = reinterpret_cast(symbol); initSpawnEnv(); } -- Gitee From 37ad746fbbdee2c1f00cd5d40308a7b4673e4909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Mon, 10 Feb 2025 20:26:44 +0800 Subject: [PATCH 136/148] markdown format fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- service/hnp/pack/README_zh.md | 2 +- service/hnp/pack/errorcode-hnpcli.md | 88 ++++++++++++++-------------- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/service/hnp/pack/README_zh.md b/service/hnp/pack/README_zh.md index ed029fbe..6ebd0f8b 100644 --- a/service/hnp/pack/README_zh.md +++ b/service/hnp/pack/README_zh.md @@ -125,5 +125,5 @@ Native包管理功能模块提供了对Native软件的打包、安装、卸载 ``` 1. 对hnpsample软件进行打包,由于hnpsample目录下存在hnp.json文件,不需要指定软件名和版本号。因此命令如下: hnpcli pack -i ./hnpsample -o ./out - 2. 命令返回成功,则在out目录下生成hnpsample.hnp文件 + 2. 命令返回成功,则在out目录下生成hnpsample.hnp文件。 ``` diff --git a/service/hnp/pack/errorcode-hnpcli.md b/service/hnp/pack/errorcode-hnpcli.md index 04014098..a569eb72 100644 --- a/service/hnp/pack/errorcode-hnpcli.md +++ b/service/hnp/pack/errorcode-hnpcli.md @@ -22,7 +22,7 @@ The cmd operate type is invalid. **处理步骤** -检查传入的参数个数是否正确。可通过命令hnpcli help查询正确的参数格式 +检查传入的参数个数是否正确。可通过命令hnpcli help查询正确的参数格式。 ## 0x801002 缺少必要的操作参数 @@ -56,7 +56,7 @@ Open file failed. **可能原因** 1. 文件不存在。 -2. 没有权限 +2. 没有权限。 **处理步骤** @@ -76,8 +76,8 @@ Read file content failed. **可能原因** 1. 文件不存在。 -2. 没有权限 -3. 文件读出的内容大小和期望的大小不相等 +2. 没有权限。 +3. 文件读出的内容大小和期望的大小不相等。 **处理步骤** @@ -98,8 +98,8 @@ fseek设置失败。 **可能原因** 1. 文件不存在。 -2. 没有权限 -3. fseek系统报错 +2. 没有权限。 +3. fseek系统报错。 **处理步骤** @@ -120,8 +120,8 @@ ftell设置失败。 **可能原因** 1. 文件不存在。 -2. 没有权限 -3. ftell系统报错 +2. 没有权限。 +3. ftell系统报错。 **处理步骤** @@ -141,7 +141,7 @@ Get real path failed. **可能原因** -路径不存在 +路径不存在。 **处理步骤** @@ -159,7 +159,7 @@ Get file content size is 0. **可能原因** -文件内容为空 +文件内容为空。 **处理步骤** @@ -177,11 +177,11 @@ The len of string exceed limit. **可能原因** -用户传入的字符串超出了限制的大小 +用户传入的字符串超出了限制的大小。 **处理步骤** -根据错误信息检查参数是否存在问题 +根据错误信息检查参数是否存在问题。 ## 0x801108 目录打开失败 @@ -195,13 +195,13 @@ Open Dir failed. **可能原因** -1. 目录不存在 -2. 权限问题 +1. 目录不存在。 +2. 权限问题。 **处理步骤** -1. 检查传入的目录是否存在 -2. 检查目录权限是否本进程能够打开 +1. 检查传入的目录是否存在。 +2. 检查目录权限是否本进程能够打开。 ## 0x801109 sprintf拼接失败 @@ -215,11 +215,11 @@ sprintf拼接失败。 **可能原因** -sprintf接口返回错误 +sprintf接口返回错误。 **处理步骤** -查看sprintf错误码并检查参数是否正确 +查看sprintf错误码并检查参数是否正确。 ## 0x80110a 生成压缩文件失败 @@ -233,11 +233,11 @@ Create new file in zip failed. **可能原因** -压缩软件报错 +压缩软件报错。 **处理步骤** -查看压缩软件报错原因并修复 +查看压缩软件报错原因并修复。 ## 0x80110b 写文件失败 @@ -251,15 +251,15 @@ Write file failed. **可能原因** -1. 文件不存在 -2. 权限问题 -3. 写入的是压缩的内容 +1. 文件不存在。 +2. 权限问题。 +3. 写入的是压缩的内容。 **处理步骤** -1. 检查传入的文件是否存在 -2. 检查文件权限是否本进程能够打开 -3. 使用“wb”打开文件再进行写入 +1. 检查传入的文件是否存在。 +2. 检查文件权限是否本进程能够打开。 +3. 使用“wb”打开文件再进行写入。 ## 0x80110c strcpy拷贝失败 **错误信息** @@ -272,11 +272,11 @@ strcpy拷贝失败。 **可能原因** -strcpy接口返回错误 +strcpy接口返回错误。 **处理步骤** -查看strcpy错误码并检查参数是否正确 +查看strcpy错误码并检查参数是否正确。 ## 0x80110d 获取文件属性失败 @@ -290,15 +290,15 @@ Get file attr failed. **可能原因** -1. 文件不存在 -2. 权限问题 -3. 系统接口报错 +1. 文件不存在。 +2. 权限问题。 +3. 系统接口报错。 **处理步骤** -1. 检查传入的文件是否存在 -2. 检查文件权限是否本进程能够打开 -3. 查看具体的系统报错信息并修改 +1. 检查传入的文件是否存在。 +2. 检查文件权限是否本进程能够打开。 +3. 查看具体的系统报错信息并修改。 @@ -318,7 +318,7 @@ Read cfg stream failed. **处理步骤** -检查配置文件是否存在 +检查配置文件是否存在。 ## 0x80111a 解析json信息失败 @@ -336,7 +336,7 @@ Parse json info failed. **处理步骤** -检查文件内容是否是json格式 +检查文件内容是否是json格式。 ## 0x80111b 未找到json项 @@ -355,7 +355,7 @@ Get json item failed. **处理步骤** -检查文件内容是否存在对应的item项 +检查文件内容是否存在对应的item项。 ## 0x80111c 解析json数组失败 @@ -373,7 +373,7 @@ json文件中不存在对应的数据信息。 **处理步骤** -检查json文件内容是否存在对应的数组信息 +检查json文件内容是否存在对应的数组信息。 # pack打包模块错误码 @@ -393,7 +393,7 @@ Get real path failed. **处理步骤** -检查传入的打包目录路径、输出路径以及配置项文件路径是否存在 +检查传入的打包目录路径、输出路径以及配置项文件路径是否存在。 ## 0x801202 组装输出文件路径失败 **错误信息** @@ -406,7 +406,7 @@ Get output file path failed。 **可能原因** -sprintf拼接文件名失败 +sprintf拼接文件名失败。 **处理步骤** @@ -423,13 +423,13 @@ Compress dir failed。 **可能原因** -1. 权限问题导致无法访问原目录或者输出目录 -2. 压缩软件报错 +1. 权限问题导致无法访问原目录或者输出目录。 +2. 压缩软件报错。 **处理步骤** -1. 查看原目录和输出目录的访问权限,确定本进程是否可以访问 -2. 查看对应的压缩软件错误信息进行定位 +1. 查看原目录和输出目录的访问权限,确定本进程是否可以访问。 +2. 查看对应的压缩软件错误信息进行定位。 -- Gitee From 514ad2bc50c199f78e26125dc4a7d7636405af40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Tue, 11 Feb 2025 15:30:31 +0800 Subject: [PATCH 137/148] Punctuation Marks Fix for Markdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- service/hnp/pack/errorcode-hnpcli.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/hnp/pack/errorcode-hnpcli.md b/service/hnp/pack/errorcode-hnpcli.md index a569eb72..41e54d13 100644 --- a/service/hnp/pack/errorcode-hnpcli.md +++ b/service/hnp/pack/errorcode-hnpcli.md @@ -41,7 +41,7 @@ The cmd operate required arg is miss. **处理步骤** -检查传入的参数是否正确以及完整。可通过命令hnpcli help查询正确的参数格式 +检查传入的参数是否正确以及完整。可通过命令hnpcli help查询正确的参数格式。 ## 0x801101 打开文件失败 -- Gitee From 2ff9d2ce0b4c4471a391d31b751360d2556662af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Mon, 10 Feb 2025 20:55:16 +0800 Subject: [PATCH 138/148] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9appspawn=20Del?= =?UTF-8?q?eteAppSpawnMsg=20=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- standard/appspawn_appmgr.c | 2 +- standard/appspawn_manager.h | 2 +- standard/appspawn_msgmgr.c | 27 ++++++------ standard/appspawn_service.c | 44 +++++++++---------- .../app_spawn_appmgr_test.cpp | 42 ++++++++++++------ test/unittest/app_spawn_test_helper.cpp | 6 +-- 6 files changed, 70 insertions(+), 53 deletions(-) diff --git a/standard/appspawn_appmgr.c b/standard/appspawn_appmgr.c index 7866bac8..18740ea9 100644 --- a/standard/appspawn_appmgr.c +++ b/standard/appspawn_appmgr.c @@ -320,7 +320,7 @@ void DeleteAppSpawningCtx(AppSpawningCtx *property) APPSPAWN_CHECK_ONLY_EXPER(property != NULL, return); APPSPAWN_LOGV("DeleteAppSpawningCtx"); - DeleteAppSpawnMsg(property->message); + DeleteAppSpawnMsg(&property->message); OH_ListRemove(&property->node); if (property->forkCtx.timer) { diff --git a/standard/appspawn_manager.h b/standard/appspawn_manager.h index 1cb026ac..3c16cb2f 100644 --- a/standard/appspawn_manager.h +++ b/standard/appspawn_manager.h @@ -187,7 +187,7 @@ void ProcessAppSpawnDumpMsg(const AppSpawnMsgNode *message); int ProcessTerminationStatusMsg(const AppSpawnMsgNode *message, AppSpawnResult *result); AppSpawnMsgNode *CreateAppSpawnMsg(void); -void DeleteAppSpawnMsg(AppSpawnMsgNode *msgNode); +void DeleteAppSpawnMsg(AppSpawnMsgNode **msgNode); int CheckAppSpawnMsg(const AppSpawnMsgNode *message); int DecodeAppSpawnMsg(AppSpawnMsgNode *message); int GetAppSpawnMsgFromBuffer(const uint8_t *buffer, uint32_t bufferLen, diff --git a/standard/appspawn_msgmgr.c b/standard/appspawn_msgmgr.c index 4c45e88b..588693b7 100644 --- a/standard/appspawn_msgmgr.c +++ b/standard/appspawn_msgmgr.c @@ -100,20 +100,21 @@ AppSpawnMsgNode *CreateAppSpawnMsg(void) return message; } -void DeleteAppSpawnMsg(AppSpawnMsgNode *msgNode) +void DeleteAppSpawnMsg(AppSpawnMsgNode **msgNode) { - if (msgNode == NULL) { + if (msgNode == NULL || *msgNode == NULL) { return; } - if (msgNode->buffer) { - free(msgNode->buffer); - msgNode->buffer = NULL; + if ((*msgNode)->buffer) { + free((*msgNode)->buffer); + (*msgNode)->buffer = NULL; } - if (msgNode->tlvOffset) { - free(msgNode->tlvOffset); - msgNode->tlvOffset = NULL; + if ((*msgNode)->tlvOffset) { + free((*msgNode)->tlvOffset); + (*msgNode)->tlvOffset = NULL; } - free(msgNode); + free(*msgNode); + *msgNode = NULL; } static inline int CheckRecvMsg(const AppSpawnMsg *msg) @@ -157,19 +158,19 @@ AppSpawnMsgNode *RebuildAppSpawnMsgNode(AppSpawnMsgNode *message, AppSpawnedProc AppSpawnMsgNode *node = CreateAppSpawnMsg(); APPSPAWN_CHECK(node != NULL, return NULL, "Failed to create AppSpawnMsgNode"); int ret = memcpy_s(&node->msgHeader, sizeof(AppSpawnMsg), &message->msgHeader, sizeof(AppSpawnMsg)); - APPSPAWN_CHECK(ret == 0, DeleteAppSpawnMsg(node); return NULL, "Failed to memcpy_s node->msgHeader"); + APPSPAWN_CHECK(ret == 0, DeleteAppSpawnMsg(&node); return NULL, "Failed to memcpy_s node->msgHeader"); bufferLen = message->msgHeader.msgLen + appInfo->message->msgHeader.msgLen - sizeof(AppSpawnMsg); node->msgHeader.msgLen = bufferLen; node->msgHeader.msgType = MSG_SPAWN_NATIVE_PROCESS; node->msgHeader.tlvCount += message->msgHeader.tlvCount; ret = AppSpawnMsgRebuild(node, &node->msgHeader); - APPSPAWN_CHECK(ret == 0, DeleteAppSpawnMsg(node); return NULL, "Failed to alloc memory for recv message"); + APPSPAWN_CHECK(ret == 0, DeleteAppSpawnMsg(&node); return NULL, "Failed to alloc memory for recv message"); uint32_t appInfoBufLen = appInfo->message->msgHeader.msgLen - sizeof(AppSpawnMsg); uint32_t msgBufLen = message->msgHeader.msgLen - sizeof(AppSpawnMsg); ret = memcpy_s(node->buffer, bufferLen, appInfo->message->buffer, appInfoBufLen); - APPSPAWN_CHECK(ret == 0, DeleteAppSpawnMsg(node); return NULL, "Failed to memcpy_s appInfo buffer"); + APPSPAWN_CHECK(ret == 0, DeleteAppSpawnMsg(&node); return NULL, "Failed to memcpy_s appInfo buffer"); ret = memcpy_s(node->buffer + appInfoBufLen, bufferLen - appInfoBufLen, message->buffer, msgBufLen); - APPSPAWN_CHECK(ret == 0, DeleteAppSpawnMsg(node); return NULL, "Failed to memcpy_s message->buffer"); + APPSPAWN_CHECK(ret == 0, DeleteAppSpawnMsg(&node); return NULL, "Failed to memcpy_s message->buffer"); return node; #endif return NULL; diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 5fb55e3c..8ca1bb10 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -260,7 +260,7 @@ static void OnClose(const TaskHandle taskHandle) } APPSPAWN_LOGI("OnClose connectionId: %{public}u socket %{public}d", connection->connectionId, LE_GetSocketFd(taskHandle)); - DeleteAppSpawnMsg(connection->receiverCtx.incompleteMsg); + DeleteAppSpawnMsg(&connection->receiverCtx.incompleteMsg); connection->receiverCtx.incompleteMsg = NULL; // connect close, to close spawning app AppSpawningCtxTraversal(AppSpawningCtxOnClose, connection); @@ -314,7 +314,7 @@ static void WaitMsgCompleteTimeOut(const TimerHandle taskHandle, void *context) { AppSpawnConnection *connection = (AppSpawnConnection *)context; APPSPAWN_LOGE("Long time no msg complete so close connectionId: %{public}u", connection->connectionId); - DeleteAppSpawnMsg(connection->receiverCtx.incompleteMsg); + DeleteAppSpawnMsg(&connection->receiverCtx.incompleteMsg); connection->receiverCtx.incompleteMsg = NULL; LE_CloseStreamTask(LE_GetDefaultLoop(), connection->stream); } @@ -498,7 +498,7 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer, } while (reminder > 0); if (message) { - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); } if (ret != 0) { LE_CloseTask(LE_GetDefaultLoop(), taskHandle); @@ -945,7 +945,7 @@ static void ProcessSpawnReqMsg(AppSpawnConnection *connection, AppSpawnMsgNode * int ret = CheckAppSpawnMsg(message); if (ret != 0) { SendResponse(connection, &message->msgHeader, ret, 0); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); return; } @@ -960,7 +960,7 @@ static void ProcessSpawnReqMsg(AppSpawnConnection *connection, AppSpawnMsgNode * AppSpawningCtx *property = CreateAppSpawningCtx(); if (property == NULL) { SendResponse(connection, &message->msgHeader, APPSPAWN_SYSTEM_ERROR, 0); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); return; } @@ -1260,7 +1260,7 @@ static AppSpawningCtx *GetAppSpawningCtxFromArg(AppSpawnMgr *content, int argc, return property; } NotifyResToParent(&content->content, &property->client, APPSPAWN_MSG_INVALID); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); DeleteAppSpawningCtx(property); return NULL; } @@ -1432,7 +1432,7 @@ static AppSpawnMsgNode *ProcessSpawnBegetctlMsg(AppSpawnConnection *connection, APPSPAWN_CHECK(msgNode != NULL, return NULL, "Failed to rebuild app message node"); int ret = DecodeAppSpawnMsg(msgNode); if (ret != 0) { - DeleteAppSpawnMsg(msgNode); + DeleteAppSpawnMsg(&msgNode); return NULL; } return msgNode; @@ -1443,18 +1443,18 @@ static void ProcessBegetCmdMsg(AppSpawnConnection *connection, AppSpawnMsgNode * AppSpawnMsg *msg = &message->msgHeader; if (!IsDeveloperModeOpen()) { SendResponse(connection, msg, APPSPAWN_DEBUG_MODE_NOT_SUPPORT, 0); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); return; } AppSpawnMsgNode *msgNode = ProcessSpawnBegetctlMsg(connection, message); if (msgNode == NULL) { SendResponse(connection, msg, APPSPAWN_DEBUG_MODE_NOT_SUPPORT, 0); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); return; } ProcessSpawnReqMsg(connection, msgNode); - DeleteAppSpawnMsg(message); - DeleteAppSpawnMsg(msgNode); + DeleteAppSpawnMsg(&message); + DeleteAppSpawnMsg(&msgNode); } static int GetArkWebInstallPath(const char *key, char *value) @@ -1587,14 +1587,14 @@ static void ProcessSpawnRestartMsg(AppSpawnConnection *connection, AppSpawnMsgNo AppSpawnContent *content = GetAppSpawnContent(); if (!IsNWebSpawnMode((AppSpawnMgr *)content)) { SendResponse(connection, &message->msgHeader, APPSPAWN_MSG_INVALID, 0); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); APPSPAWN_LOGE("Restart msg only support nwebspawn"); return; } TraversalSpawnedProcess(AppQueueDestroyProc, NULL); SendResponse(connection, &message->msgHeader, 0, 0); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); (void) ServerStageHookExecute(STAGE_SERVER_EXIT, content); errno = 0; @@ -1624,7 +1624,7 @@ APPSPAWN_STATIC void ProcessUninstallDebugHap(AppSpawnConnection *connection, Ap AppSpawningCtx *property = CreateAppSpawningCtx(); if (property == NULL) { SendResponse(connection, &message->msgHeader, APPSPAWN_SYSTEM_ERROR, 0); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); return; } @@ -1803,7 +1803,7 @@ APPSPAWN_STATIC void ProcessObserveProcessSignalMsg(AppSpawnConnection *connecti if (fd <= 0 || ret != 0) { APPSPAWN_LOGE("Spawn Listen appspawn signal fd get unsuccess"); SendResponse(connection, &message->msgHeader, APPSPAWN_SYSTEM_ERROR, 0); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); return; } @@ -1812,7 +1812,7 @@ APPSPAWN_STATIC void ProcessObserveProcessSignalMsg(AppSpawnConnection *connecti content->signalFd = fd; connection->receiverCtx.fdCount = 0; SendResponse(connection, &message->msgHeader, 0, 0); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); } static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) @@ -1830,7 +1830,7 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess AppSpawnResult result = {0}; ret = ProcessTerminationStatusMsg(message, &result); SendResponse(connection, msg, ret == 0 ? result.result : ret, result.pid); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); break; } case MSG_SPAWN_NATIVE_PROCESS: // spawn msg @@ -1841,7 +1841,7 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess case MSG_DUMP: ProcessAppSpawnDumpMsg(message); SendResponse(connection, msg, 0, 0); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); break; case MSG_BEGET_CMD: { ProcessBegetCmdMsg(connection, message); @@ -1850,7 +1850,7 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess case MSG_BEGET_SPAWNTIME: SendResponse(connection, msg, GetAppSpawnMgr()->spawnTime.minAppspawnTime, GetAppSpawnMgr()->spawnTime.maxAppspawnTime); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); break; case MSG_UPDATE_MOUNT_POINTS: ret = ProcessSpawnRemountMsg(connection, message); @@ -1862,7 +1862,7 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess case MSG_DEVICE_DEBUG: ret = ProcessAppSpawnDeviceDebugMsg(message); SendResponse(connection, msg, ret, 0); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); break; case MSG_UNINSTALL_DEBUG_HAP: ProcessUninstallDebugHap(connection, message); @@ -1870,14 +1870,14 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess case MSG_LOCK_STATUS: ProcessAppSpawnLockStatusMsg(message); SendResponse(connection, msg, 0, 0); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); break; case MSG_OBSERVE_PROCESS_SIGNAL_STATUS: ProcessObserveProcessSignalMsg(connection, message); break; default: SendResponse(connection, msg, APPSPAWN_MSG_INVALID, 0); - DeleteAppSpawnMsg(message); + DeleteAppSpawnMsg(&message); break; } } 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 64787af2..f6012a28 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 @@ -307,7 +307,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_001, TestSize.Level0) EXPECT_NE(0, ret); // check fail // delete - DeleteAppSpawnMsg(msgNode); + DeleteAppSpawnMsg(&msgNode); DeleteAppSpawnMsg(nullptr); // get from buffer @@ -327,7 +327,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_001, TestSize.Level0) ret = GetAppSpawnMsgFromBuffer(inputBuffer[i], buffer.size(), &outMsg, inputMsgLen[j], inputReminder[k]); EXPECT_EQ(ret == 0, result[i * inputCount * inputCount + j * inputCount + k]); // check fail - DeleteAppSpawnMsg(outMsg); + DeleteAppSpawnMsg(&outMsg); } } } @@ -394,7 +394,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_002, TestSize.Level0) EXPECT_EQ(msgLen, msgRecvLen); EXPECT_EQ(memcmp(buffer.data() + sizeof(AppSpawnMsg), outMsg->buffer, msgLen - sizeof(AppSpawnMsg)), 0); EXPECT_EQ(sizeof(AppSpawnMsg), reminder); - DeleteAppSpawnMsg(outMsg); + DeleteAppSpawnMsg(&outMsg); } HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_003, TestSize.Level0) @@ -423,7 +423,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_003, TestSize.Level0) EXPECT_EQ(0, ret); ret = CheckAppSpawnMsg(outMsg); EXPECT_EQ(0, ret); - DeleteAppSpawnMsg(outMsg); + DeleteAppSpawnMsg(&outMsg); } HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_004, TestSize.Level0) @@ -449,7 +449,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_004, TestSize.Level0) EXPECT_EQ(0, ret); ret = CheckAppSpawnMsg(outMsg); EXPECT_NE(0, ret); - DeleteAppSpawnMsg(outMsg); + DeleteAppSpawnMsg(&outMsg); } static int AddRenderTerminationTlv(uint8_t *buffer, uint32_t bufferLen, uint32_t &realLen, uint32_t &tlvCount) @@ -514,7 +514,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_005, TestSize.Level0) ret = ProcessTerminationStatusMsg(nullptr, nullptr); EXPECT_NE(0, ret); - DeleteAppSpawnMsg(outMsg); + DeleteAppSpawnMsg(&outMsg); DeleteAppSpawnMgr(mgr); } @@ -550,7 +550,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_006, TestSize.Level0) ret = ProcessTerminationStatusMsg(outMsg, &result); EXPECT_EQ(0, ret); - DeleteAppSpawnMsg(outMsg); + DeleteAppSpawnMsg(&outMsg); DeleteAppSpawnMgr(mgr); } @@ -582,7 +582,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_007, TestSize.Level0) ret = ProcessTerminationStatusMsg(outMsg, &result); EXPECT_EQ(0, ret); - DeleteAppSpawnMsg(outMsg); + DeleteAppSpawnMsg(&outMsg); DeleteAppSpawnMgr(mgr); } @@ -615,10 +615,26 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_008, TestSize.Level0) outMsg->tlvOffset = nullptr; ProcessAppSpawnDumpMsg(outMsg); - DeleteAppSpawnMsg(outMsg); + DeleteAppSpawnMsg(&outMsg); DeleteAppSpawnMgr(mgr); } +HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsgNode_009, TestSize.Level0) +{ + AppSpawnMsgNode *msgNode = CreateAppSpawnMsg(); + msgNode->buffer = static_cast(malloc(255));; + msgNode->tlvOffset = static_cast(malloc(128)); + EXPECT_EQ(msgNode != nullptr, 1); + DeleteAppSpawnMsg(&msgNode); + EXPECT_EQ(msgNode, NULL); + DeleteAppSpawnMsg(&msgNode); + EXPECT_EQ(msgNode, NULL); + msgNode = CreateAppSpawnMsg(); + EXPECT_NE(msgNode, NULL); + DeleteAppSpawnMsg(&msgNode); + EXPECT_EQ(msgNode, NULL); + DeleteAppSpawnMsg(nullptr); +} /** * @brief 消息内容操作接口 * @@ -658,7 +674,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsg_001, TestSize.Level0) void *info = GetAppSpawnMsgInfo(nullptr, i); EXPECT_EQ(info == nullptr, 1); } - DeleteAppSpawnMsg(outMsg); + DeleteAppSpawnMsg(&outMsg); DeleteAppSpawnMgr(mgr); } @@ -725,7 +741,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsg_002, TestSize.Level0) void *info = GetAppSpawnMsgExtInfo(nullptr, inputName[i], &len); EXPECT_EQ(info == nullptr, 1); } - DeleteAppSpawnMsg(outMsg); + DeleteAppSpawnMsg(&outMsg); DeleteAppSpawnMgr(mgr); } @@ -780,7 +796,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsg_003, TestSize.Level0) EXPECT_EQ(0, ret); } } - DeleteAppSpawnMsg(outMsg); + DeleteAppSpawnMsg(&outMsg); DeleteAppSpawnMgr(mgr); } @@ -810,7 +826,7 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawnMsg_004, TestSize.Level0) // dump msg DumpAppSpawnMsg(outMsg); DumpAppSpawnMsg(nullptr); - DeleteAppSpawnMsg(outMsg); + DeleteAppSpawnMsg(&outMsg); DeleteAppSpawnMgr(mgr); } diff --git a/test/unittest/app_spawn_test_helper.cpp b/test/unittest/app_spawn_test_helper.cpp index 4751384f..49802175 100644 --- a/test/unittest/app_spawn_test_helper.cpp +++ b/test/unittest/app_spawn_test_helper.cpp @@ -563,7 +563,7 @@ AppSpawningCtx *AppSpawnTestHelper::GetAppProperty(AppSpawnClientHandle handle, block->buffer + bufferStart, block->currentIndex - bufferStart); if (ret != 0) { AppSpawnReqMsgFree(reqHandle); - DeleteAppSpawnMsg(msgNode); + DeleteAppSpawnMsg(&msgNode); return nullptr; } currIndex += block->currentIndex - bufferStart; @@ -577,10 +577,10 @@ AppSpawningCtx *AppSpawnTestHelper::GetAppProperty(AppSpawnClientHandle handle, // delete reqHandle AppSpawnReqMsgFree(reqHandle); int ret = DecodeAppSpawnMsg(msgNode); - APPSPAWN_CHECK(ret == 0, DeleteAppSpawnMsg(msgNode); + APPSPAWN_CHECK(ret == 0, DeleteAppSpawnMsg(&msgNode); return nullptr, "Decode msg fail"); AppSpawningCtx *property = CreateAppSpawningCtx(); - APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, DeleteAppSpawnMsg(msgNode); + APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, DeleteAppSpawnMsg(&msgNode); return nullptr); property->message = msgNode; SetDefaultTestData(); -- Gitee From e166144d800afb6d9b7fd7a763cd7d25c554cf99 Mon Sep 17 00:00:00 2001 From: GengYinzong Date: Thu, 13 Feb 2025 23:55:12 -0800 Subject: [PATCH 139/148] fix Signed-off-by: GengYinzong --- modules/common/appspawn_adapter.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/common/appspawn_adapter.cpp b/modules/common/appspawn_adapter.cpp index 65c81b25..e53b3af4 100644 --- a/modules/common/appspawn_adapter.cpp +++ b/modules/common/appspawn_adapter.cpp @@ -192,16 +192,19 @@ int SetSeccompFilter(const AppSpawnMgr *content, const AppSpawningCtx *property) #ifdef SECCOMP_PRIVILEGE if (IsDeveloperModeOpen()) { + // Enable high permission seccomp policy for hishell in developer mode. if (CheckAppMsgFlagsSet(property, APP_FLAGS_GET_ALL_PROCESSES) != 0) { appName = APP_PRIVILEGE; } } #endif + // Set seccomp policy for input method security mode. if (CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX) != 0) { appName = IMF_EXTENTOIN_NAME; } + // Set seccomp policy for atomic service process. if (CheckAppMsgFlagsSet(property, APP_FLAGS_ATOMIC_SERVICE) != 0) { appName = APP_ATOMIC; } -- Gitee From c2f5e54c7cf7bb43b6c24ba3b0feb531653d3f29 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Fri, 14 Feb 2025 14:18:19 +0800 Subject: [PATCH 140/148] sync code for appspawn Signed-off-by: nianyuu --- modules/nweb_adapter/nwebspawn_adapter.cpp | 8 +---- modules/sandbox/appspawn_sandbox.c | 32 +++++++++---------- modules/sandbox/sandbox_shared_mount.cpp | 11 +++---- service/hnp/installer/README_zh.md | 14 ++++---- service/hnp/installer/api_hnp.md | 6 ++-- standard/appspawn_service.c | 3 +- .../nweb_spawn_service_test.cpp | 27 ---------------- 7 files changed, 33 insertions(+), 68 deletions(-) diff --git a/modules/nweb_adapter/nwebspawn_adapter.cpp b/modules/nweb_adapter/nwebspawn_adapter.cpp index f3af3945..6a54d3d0 100644 --- a/modules/nweb_adapter/nwebspawn_adapter.cpp +++ b/modules/nweb_adapter/nwebspawn_adapter.cpp @@ -34,12 +34,6 @@ #include "seccomp_policy.h" #endif -#ifndef APPSPAWN_TEST -#define APPSPAWN_STATIC static -#else -#define APPSPAWN_STATIC -#endif - namespace { #if defined(webview_arm64) const std::string ARK_WEB_CORE_HAP_LIB_PATH = @@ -57,7 +51,7 @@ namespace { const std::string WEB_RENDER_LIB_NAME = "libnweb_render.so"; } // namespace -APPSPAWN_STATIC bool SetSeccompPolicyForRenderer(void *nwebRenderHandle) +static bool SetSeccompPolicyForRenderer(void *nwebRenderHandle) { #ifdef WITH_SECCOMP if (IsEnableSeccomp()) { diff --git a/modules/sandbox/appspawn_sandbox.c b/modules/sandbox/appspawn_sandbox.c index beb7edc5..1b5dfd02 100644 --- a/modules/sandbox/appspawn_sandbox.c +++ b/modules/sandbox/appspawn_sandbox.c @@ -226,7 +226,6 @@ static int InitSandboxContext(SandboxContext *context, context->sandboxShared = packageNode->section.sandboxShared; } context->message = property->message; - context->sandboxNsFlags = CLONE_NEWNS; if (NeedNetworkIsolated(context, property)) { @@ -591,24 +590,23 @@ static void MountDir(AppSpawnMsgDacInfo *info, const char *bundleName, const cha } const int userIdBase = UID_BASE; - size_t allPathSize = strlen(rootPath) + strlen(targetPath) + strlen(bundleName) + 2; - allPathSize += USER_ID_SIZE; - char *path = (char *)malloc(sizeof(char) * (allPathSize)); - (void)memset_s(path, allPathSize, 0, allPathSize); - APPSPAWN_CHECK(path != NULL, return, "Failed to malloc path"); - int len = sprintf_s(path, allPathSize, "%s%u/%s%s", rootPath, info->uid / userIdBase, bundleName, targetPath); - APPSPAWN_CHECK(len > 0 && ((size_t)len < allPathSize), free(path); - return, "Failed to get sandbox path"); + char path[MAX_SANDBOX_BUFFER] = {0}; + int ret = snprintf_s(path, MAX_SANDBOX_BUFFER, MAX_SANDBOX_BUFFER - 1, "%s%u/%s%s", rootPath, + info->uid / userIdBase, bundleName, targetPath); + if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s path failed, errno %{public}d", errno); + return; + } if (access(path, F_OK) == 0) { - free(path); return; } - MakeDirRec(path, DIR_MODE, 1); + ret = MakeDirRec(path, DIR_MODE, 1); + APPSPAWN_CHECK(ret == 0, return, "mkdir %{public}s failed, ret %{public}d", path, ret); + if (mount(path, path, NULL, MS_BIND | MS_REC, NULL) != 0) { APPSPAWN_LOGI("bind mount %{public}s failed, error %{public}d", path, errno); - free(path); return; } if (mount(NULL, path, NULL, MS_SHARED, NULL) != 0) { @@ -616,8 +614,6 @@ static void MountDir(AppSpawnMsgDacInfo *info, const char *bundleName, const cha } else { APPSPAWN_LOGI("mount path %{public}s to shared success", path); } - - free(path); } static const MountSharedTemplate MOUNT_SHARED_MAP[] = { @@ -637,12 +633,14 @@ static int MountInShared(const AppSpawnMsgDacInfo *info, const char *rootPath, c int ret = snprintf_s(path, MAX_SANDBOX_BUFFER, MAX_SANDBOX_BUFFER - 1, "%s/%u/app-root/%s", rootPath, info->uid / UID_BASE, target); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s path failed, errno %{public}d", errno); return APPSPAWN_ERROR_UTILS_MEM_FAIL; } char currentUserPath[MAX_SANDBOX_BUFFER] = {0}; ret = snprintf_s(currentUserPath, MAX_SANDBOX_BUFFER, MAX_SANDBOX_BUFFER - 1, "%s/currentUser", path); if (ret <= 0) { + APPSPAWN_LOGE("snprintf_s currentUserPath failed, errno %{public}d", errno); return APPSPAWN_ERROR_UTILS_MEM_FAIL; } @@ -652,6 +650,7 @@ static int MountInShared(const AppSpawnMsgDacInfo *info, const char *rootPath, c ret = MakeDirRec(path, DIR_MODE, 1); if (ret != 0) { + APPSPAWN_LOGE("mkdir %{public}s failed, ret %{public}d", path, ret); return APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL; } @@ -683,6 +682,7 @@ static int SharedMountInSharefs(const AppSpawnMsgDacInfo *info, const char *root ret = MakeDirRec(target, DIR_MODE, 1); if (ret != 0) { + APPSPAWN_LOGE("mkdir %{public}s failed, ret %{public}d", target, ret); return APPSPAWN_SANDBOX_ERROR_MKDIR_FAIL; } @@ -766,6 +766,8 @@ static void MountDirToShared(const SandboxContext *context, AppSpawnSandboxCfg * return; } + UpdateStorageDir(context, sandbox, info); + MountDir(info, appRootName, rootPath, nwebPath); MountDir(info, appRootName, rootPath, nwebTmpPath); @@ -773,8 +775,6 @@ static void MountDirToShared(const SandboxContext *context, AppSpawnSandboxCfg * return; } - UpdateStorageDir(context, sandbox, info); - int length = sizeof(MOUNT_SHARED_MAP) / sizeof(MOUNT_SHARED_MAP[0]); for (int i = 0; i < length; i++) { if (MOUNT_SHARED_MAP[i].permission == NULL) { diff --git a/modules/sandbox/sandbox_shared_mount.cpp b/modules/sandbox/sandbox_shared_mount.cpp index dd30935a..56d52446 100644 --- a/modules/sandbox/sandbox_shared_mount.cpp +++ b/modules/sandbox/sandbox_shared_mount.cpp @@ -152,7 +152,6 @@ static int DoSharedMount(const SharedMountArgs *arg) static void GetMountInfo(std::vector &sharedMounts, AppDacInfo *info, const std::string &bundleName) { - APPSPAWN_LOGI("Get mountinfo %{public}s start", bundleName.c_str()); std::ifstream file("/proc/self/mountinfo"); if (!file.is_open()) { APPSPAWN_LOGE("Failed to open mountinfo, errno: %{public}d", errno); @@ -167,7 +166,7 @@ static void GetMountInfo(std::vector &sharedMounts, AppDacInfo *inf } } file.close(); - APPSPAWN_LOGW("Get mountinfo %{public}s end", bundleName.c_str()); + APPSPAWN_LOGI("Get mountinfo %{public}s end", bundleName.c_str()); } static bool IsSandboxPathShared(const std::vector &sharedMounts, const std::string &sandboxPath) @@ -193,7 +192,7 @@ static int MountEl1Bundle(const AppSpawningCtx *property, const AppDacInfo *info /* /mnt/sandbox///data/storage/el1/bundle */ char targetPath[PATH_MAX_LEN] = {0}; - ret = snprintf_s(targetPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%d/%s/data/storage/el1/bundle", + ret = snprintf_s(targetPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "/mnt/sandbox/%u/%s/data/storage/el1/bundle", info->uid/ UID_BASE, bundleName); if (ret <= 0) { APPSPAWN_LOGE("snprintf el1 bundle sandbox path failed, errno %{public}d", errno); @@ -445,7 +444,7 @@ static int AddDataGroupItemToQueue(AppSpawnMgr *content, const std::string &srcP } dataGroupNode->srcPath.pathLen = strlen(dataGroupNode->srcPath.path); dataGroupNode->destPath.pathLen = strlen(dataGroupNode->destPath.path); - ListNode *node = OH_ListFind(&content->dataGroupCtxQueue, (void*)dataGroupNode, DataGroupCtxNodeCompare); + ListNode *node = OH_ListFind(&content->dataGroupCtxQueue, (void *)dataGroupNode, DataGroupCtxNodeCompare); if (node != nullptr) { APPSPAWN_LOGI("DataGroupCtxNode %{public}s is exist", dataGroupNode->srcPath.path); return 0; @@ -547,7 +546,7 @@ int UpdateDataGroupDirs(AppSpawnMgr *content) while (node != &content->dataGroupCtxQueue) { DataGroupCtx *dataGroupNode = (DataGroupCtx *)ListEntry(node, DataGroupCtx, node); char sandboxPath[PATH_MAX_LEN] = {0}; - int ret = snprintf_s(sandboxPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s/%s", dataGroupNode->destPath.path, + int ret = snprintf_s(sandboxPath, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s%s", dataGroupNode->destPath.path, dataGroupNode->dataGroupUuid); if (ret <= 0) { APPSPAWN_LOGE("snprintf_s sandboxPath: %{public}s failed, errno %{public}d", @@ -567,7 +566,6 @@ int UpdateDataGroupDirs(AppSpawnMgr *content) if (ret != 0) { APPSPAWN_LOGE("Shared mount %{public}s to %{public}s failed, errno %{public}d", args.srcPath, sandboxPath, ret); - return APPSPAWN_SANDBOX_ERROR_MOUNT_FAIL; } node = node->next; } @@ -634,4 +632,3 @@ MODULE_CONSTRUCTOR(void) (void)AddServerStageHook(STAGE_SERVER_LOCK, HOOK_PRIO_COMMON, UpdateDataGroupDirs); #endif } - diff --git a/service/hnp/installer/README_zh.md b/service/hnp/installer/README_zh.md index bbf53414..d06cda79 100644 --- a/service/hnp/installer/README_zh.md +++ b/service/hnp/installer/README_zh.md @@ -20,7 +20,7 @@ Native软件包安装就是将从应用市场下载解压出来的hnp包安装到鸿蒙PC设备上。当前提供接口调用以及hnp命令行两种方式进行安装。 - 1) hnp帮助命令 hnp -h。 +1) hnp帮助命令 hnp -h: ``` usage:hnp [-u ][-p ][-i ][-f][-s ][-a ] @@ -141,7 +141,7 @@ b. 强制安装会将已安装的软件先卸载掉之后再安装当前新的 c. 批量安装应用的hnp软件时如果中间安装出错,则直接退出安装流程返回,之前已安装的软件继续保留。 -3) 接口调用安装。 +3) 接口调用安装: 安装接口原型: ``` @@ -172,7 +172,7 @@ c. 批量安装应用的hnp软件时如果中间安装出错,则直接退出 Native软件包卸载就是将已安装到系统上的Native软件进行卸载。当期望卸载的软件正在运行时,则卸载失败。当前提供接口调用以及命令行两种方式进行卸载。 - 1) hnp命令行卸载: +1) hnp命令行卸载: ``` hnp uninstall -u [系统用户ID] -p [hap包名] ``` @@ -187,13 +187,13 @@ c. 批量安装应用的hnp软件时如果中间安装出错,则直接退出 baidu应用下hnp软件卸载: hnp uninstall -u 100 -p baidu - 卸载之前已经安装的baidu应用下所有hnp软件。100为安装所在的系统用户ID。 + 卸载之前已经安装的baidu应用下所有hnp软件,100为安装所在的系统用户ID。 执行成功观察点: 观察点1:之前baidu应用安装的时候分别安装了公有和私有的hnpsample软件,所以本次卸载需要观察以下之前安装的软件目录“hnpsample.org”是否已删除。 公有软件: - /data/app/el1/bundle/100/hnppublic/hnpsample.org。 + /data/app/el1/bundle/100/hnppublic/hnpsample.org 私有软件: - /data/app/el1/bundle/100/hnp/baidu/hnpsample.org。 + /data/app/el1/bundle/100/hnp/baidu/hnpsample.org 观察点2:查看/data/service/el1/startup/hnp_info.json安装管理文件中对应baidu这一hap节点信息是否删除。 ``` @@ -203,7 +203,7 @@ a. 如果公有hnp软件被其它应用所共有,则卸载本应用不会删 b. 公有hnp软件卸载前会判断该软件是否正在运行,如果正在运行则会卸载失败。私有hnp软件因为其所属应用已经卸载,不存在正在使用的情况,因此私有软件不用校验是否正在运行。 -2) 接口调用卸载。 +2) 接口调用卸载: 卸载接口原型: ``` diff --git a/service/hnp/installer/api_hnp.md b/service/hnp/installer/api_hnp.md index 075b2d4c..0ac512b8 100644 --- a/service/hnp/installer/api_hnp.md +++ b/service/hnp/installer/api_hnp.md @@ -12,7 +12,7 @@ ### 结构体定义 -NA。 +NA. ### 函数 @@ -79,9 +79,9 @@ int NativeUnInstallHnp(const char *userId, const char *packageName); 参数: - userId:用户ID; + userId:用户ID。 - packageName:hap应用软件包名; + packageName:hap应用软件包名。 **返回:** diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 8ca1bb10..3401316c 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -51,8 +51,9 @@ #define PARAM_BUFFER_SIZE 10 #define PATH_SIZE 256 #define FD_PATH_SIZE 128 -#define APPSPAWN_MSG_USER_CHECK_COUNT 4 + #define PREFORK_PROCESS "apppool" +#define APPSPAWN_MSG_USER_CHECK_COUNT 4 #define USER_ID_MIN_VALUE 100 #define USER_ID_MAX_VALUE 10736 #define LOCK_STATUS_PARAM_SIZE 64 diff --git a/test/unittest/app_spawn_standard_test/nweb_spawn_service_test.cpp b/test/unittest/app_spawn_standard_test/nweb_spawn_service_test.cpp index 3eb8d62a..ce549992 100644 --- a/test/unittest/app_spawn_standard_test/nweb_spawn_service_test.cpp +++ b/test/unittest/app_spawn_standard_test/nweb_spawn_service_test.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include @@ -38,9 +37,6 @@ using namespace testing; using namespace testing::ext; using namespace OHOS; -APPSPAWN_STATIC int RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client); -APPSPAWN_STATIC bool SetSeccompPolicyForRenderer(void *nwebRenderHandle); - namespace OHOS { class NWebSpawnServiceTest : public testing::Test { public: @@ -502,27 +498,4 @@ HWTEST_F(NWebSpawnServiceTest, NWeb_Spawn_Msg_008, TestSize.Level0) } ASSERT_EQ(ret, 0); } - -namespace { -#if defined(webview_arm64) - const std::string NWEB_HAP_LIB_PATH = "/data/storage/el1/bundle/nweb/libs/arm64"; -#elif defined(webview_x86_64) - const std::string NWEB_HAP_LIB_PATH = "/data/storage/el1/bundle/nweb/libs/x86_64"; -#else - const std::string NWEB_HAP_LIB_PATH = "/data/storage/el1/bundle/nweb/libs/arm"; -#endif -} - -HWTEST_F(NWebSpawnServiceTest, NWeb_Spawn_nwebspawn_adapter, TestSize.Level0) -{ - AppSpawnContent content; - int ret = RunChildProcessor(&content, nullptr); - ASSERT_EQ(ret, -1); - - const std::string renderLibDir = NWEB_HAP_LIB_PATH + "/libnweb_render.so"; - void *nwebRenderHandle = dlopen(renderLibDir.c_str(), RTLD_NOW | RTLD_GLOBAL); - ASSERT_EQ((nwebRenderHandle != nullptr), 1); - bool res = SetSeccompPolicyForRenderer(nwebRenderHandle); - ASSERT_FALSE(res); -} } // namespace OHOS -- Gitee From 30cd592880e7ba9efa2cf6a97395ae1f0a0e19d1 Mon Sep 17 00:00:00 2001 From: lianghaofei Date: Mon, 17 Feb 2025 20:09:43 +0800 Subject: [PATCH 141/148] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E6=8C=89=E9=9C=80=E9=85=8D=E7=BD=AEcgroup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lianghaofei --- appspawn.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appspawn.cfg b/appspawn.cfg index a0b61fc7..461c71b7 100644 --- a/appspawn.cfg +++ b/appspawn.cfg @@ -12,6 +12,7 @@ "name" : "init", "cmds" : [ "mkdir /dev/pids", + "mkdir /dev/pids/native", "mount cgroup none /dev/pids pids", "chown root appspawn /dev/pids", "chown root appspawn /dev/pids/tasks", @@ -34,6 +35,7 @@ "uid" : "root", "gid" : ["root"], "setuid" : true, + "cgroup" : true, "socket" : [{ "name" : "AppSpawn", "family" : "AF_LOCAL", -- Gitee From 957f53ba0b8f6757722e5bf86493c92c4f98a441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Wed, 19 Feb 2025 11:09:29 +0800 Subject: [PATCH 142/148] add auto test for appspawn base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- .../sub_startup_appspawn_base_0100.json | 14 ++++ .../sub_startup_appspawn_base_0100.py | 49 +++++++++++ .../sub_startup_appspawn_base_0200.json | 14 ++++ .../sub_startup_appspawn_base_0200.py | 61 ++++++++++++++ .../sub_startup_appspawn_base_0300.json | 14 ++++ .../sub_startup_appspawn_base_0300.py | 61 ++++++++++++++ .../sub_startup_appspawn_base_0400.json | 14 ++++ .../sub_startup_appspawn_base_0400.py | 64 ++++++++++++++ .../sub_startup_appspawn_base_0500.json | 14 ++++ .../sub_startup_appspawn_base_0500.py | 57 +++++++++++++ .../sub_startup_appspawn_base_0600.json | 14 ++++ .../sub_startup_appspawn_base_0600.py | 84 +++++++++++++++++++ 12 files changed, 460 insertions(+) create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.json create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.json create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.json create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.json create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.json create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.json create mode 100644 test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.json new file mode 100644 index 00000000..1e0f7a44 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_BASE/SubStartupAppspawnBase0100.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py new file mode 100644 index 00000000..865b43d1 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py @@ -0,0 +1,49 @@ +# 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 + + +class SubStartupAppspawnBase0100(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.shell("power-shell timeout -o 86400000") + + def process(self): + process_list = ["appspawn", "nwebspawn"] + for process in process_list: + pid = self.driver.System.get_pid(process) + self.driver.Assert.equal(type(pid), int) + + def teardown(self): + Step("收尾工作.................") diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.json new file mode 100644 index 00000000..87570d7f --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_BASE/SubStartupAppspawnBase0200.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py new file mode 100644 index 00000000..591824be --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py @@ -0,0 +1,61 @@ +# 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 SubStartupAppspawnBase0200(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.shell("power-shell timeout -o 86400000") + + def process(self): + Step("安装测试hap并打开") + bundle_name = "com.example.myapplication" + hap_path = Common.sourcepath('test.hap', "SUB_STARTUP_APPSPAWN_BASE") + hap = self.driver.AppManager.has_app(bundle_name) + if hap: + self.driver.AppManager.uninstall_app(bundle_name) + self.driver.AppManager.install_app(hap_path) + else: + self.driver.AppManager.install_app(hap_path) + self.driver.AppManager.start_app(bundle_name) + + result = self.driver.shell("ps -efZ|grep %s|grep -v grep" % bundle_name).split() + for i in ["u:r:debug_hap:s0", bundle_name]: + self.driver.Assert.contains(result, i) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.uninstall_app(bundle_name) \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.json new file mode 100644 index 00000000..22c6ede8 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_BASE/SubStartupAppspawnBase0300.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py new file mode 100644 index 00000000..114cc9d8 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py @@ -0,0 +1,61 @@ +# 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 SubStartupAppspawnBase0300(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.shell("power-shell timeout -o 86400000") + + def process(self): + Step("安装测试hap并打开") + bundle_name = "com.example.myapplication" + hap_path = Common.sourcepath('asan.hap', "SUB_STARTUP_APPSPAWN_BASE") + hap = self.driver.AppManager.has_app(bundle_name) + if hap: + self.driver.AppManager.uninstall_app(bundle_name) + self.driver.AppManager.install_app(hap_path) + else: + self.driver.AppManager.install_app(hap_path) + self.driver.AppManager.start_app(bundle_name) + + result = self.driver.shell("ps -efZ|grep %s|grep -v grep" % bundle_name).split() + for i in ["u:r:debug_hap:s0", bundle_name]: + self.driver.Assert.contains(result, i) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.uninstall_app(bundle_name) \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.json new file mode 100644 index 00000000..3830b000 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_BASE/SubStartupAppspawnBase0400.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py new file mode 100644 index 00000000..1c16d6d9 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py @@ -0,0 +1,64 @@ +# 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 SubStartupAppspawnBase0400(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.shell("power-shell timeout -o 86400000") + + def process(self): + Step("安装测试hap并打开") + bundle_name = "com.example.myapplication" + for hap in ['nweb.hap', 'nweb_asan.hap']: + hap_path = Common.sourcepath(hap, "SUB_STARTUP_APPSPAWN_BASE") + hap = self.driver.AppManager.has_app(bundle_name) + if hap: + self.driver.AppManager.uninstall_app(bundle_name) + self.driver.AppManager.install_app(hap_path) + else: + self.driver.AppManager.install_app(hap_path) + self.driver.AppManager.start_app(bundle_name) + + result_dict = self.driver.shell("ps -efZ|grep %s|grep -v grep" % bundle_name).split("\n") + for result in result_dict: + if result.endswith("%s:render" % bundle_name): + result_render = result + self.driver.Assert.contains(result_render.split(), "u:r:isolated_render:s0") + self.driver.AppManager.uninstall_app(bundle_name) + + def teardown(self): + Step("收尾工作.................") diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.json new file mode 100644 index 00000000..b825cf19 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_BASE/SubStartupAppspawnBase0500.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py new file mode 100644 index 00000000..36a52c83 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py @@ -0,0 +1,57 @@ +# 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 SubStartupAppspawnBase0500(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.shell("power-shell timeout -o 86400000") + + def process(self): + Step("安装测试hap并打开") + bundle_name = "com.app.hmos.inputmethod" + self.driver.AppManager.start_app(bundle_name) + pid = self.driver.System.get_pid(bundle_name) + for path in ["base", "database"]: + for i in range(1, 5): + result01 = self.driver.Storage.has_dir("/proc/%d/root/data/storage/el%d/%s" % (pid, i, path)) + result02 = self.driver.Storage.has_dir("/data/app/el%d/100/%s" % (i, path)) + self.driver.Assert.equal(result01, True) + self.driver.Assert.equal(result02, True) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.stop_app(bundle_name) \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.json b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.json new file mode 100644 index 00000000..1b007eb5 --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "SUB_STARTUP_APPSPAWN_BASE/SubStartupAppspawnBase0600.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py new file mode 100644 index 00000000..6cc8158d --- /dev/null +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py @@ -0,0 +1,84 @@ +# 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 SubStartupAppspawnBase0600(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.shell("power-shell timeout -o 86400000") + + def process(self): + Step("安装测试hap并打开") + bundle_name = "com.ohos.mytest" + clone_bundle_name = "com.ohos.mytest1" + hap_path = Common.sourcepath("mytest.hap", "SUB_STARTUP_APPSPAWN_BASE") + hap = self.driver.AppManager.has_app(bundle_name) + if hap: + self.driver.AppManager.uninstall_app(bundle_name) + self.driver.AppManager.install_app(hap_path) + else: + self.driver.AppManager.install_app(hap_path) + self.driver.AppManager.start_app(bundle_name) + + for text in ["安装克隆应用", "startAbilityByAppIndex"]: + self.driver.touch(BY.text(text)) + + dict01 = { + bundle_name: "master.txt", + clone_bundle_name: "slave.txt" + } + + dict02 = { + bundle_name: "slave.txt", + clone_bundle_name: "master.txt" + } + + for i, txt in dict01.items(): + pid = self.driver.System.get_pid(i) + if i == clone_bundle_name: + self.driver.shell("touch /data/app/el2/100/base/+clone-1+%s/%s" % (bundle_name, txt)) + else: + self.driver.shell("touch /data/app/el2/100/base/%s/%s" % (i, txt)) + result = self.driver.Storage.has_file("/proc/%d/root/data/storage/el2/base/%s" % (pid, txt)) + self.driver.Assert.equal(result, True) + + for i, txt in dict02.items(): + pid = self.driver.System.get_pid(i) + result = self.driver.Storage.has_file("/proc/%d/root/data/storage/el2/base/%s" % (pid, txt)) + self.driver.Assert.equal(result, False) + + def teardown(self): + Step("收尾工作.................") + self.driver.AppManager.uninstall_app(bundle_name) \ No newline at end of file -- Gitee From 137eef523a29bacf45a28c5d6baaedee78645e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Wed, 19 Feb 2025 16:36:26 +0800 Subject: [PATCH 143/148] =?UTF-8?q?fix:=20=E8=A1=A5=E5=85=85=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- .../app_spawn_interface_test.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 143190a2..3edef90a 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 @@ -637,4 +637,20 @@ HWTEST_F(AppSpawnInterfaceTest, App_SpawnListenCloseSet_001, TestSize.Level0) int ret = SpawnListenCloseSet(); EXPECT_EQ(ret, 0); } + +/** + * @brief 测试接口:AppSpawnClientSendUserLockStatus + * + */ +HWTEST_F(AppSpawnInterfaceTest, AppSpawnClientSendUserLockStatus_001, TestSize.Level0) +{ + int ret = AppSpawnClientSendUserLockStatus(0, true); + EXPECT_NE(ret, 0); + ret = AppSpawnClientSendUserLockStatus(0, false); + EXPECT_NE(ret, 0); + ret = AppSpawnClientSendUserLockStatus(100, true); + EXPECT_NE(ret, 0); + ret = AppSpawnClientSendUserLockStatus(100, false); + EXPECT_NE(ret, 0); +} } // namespace OHOS -- Gitee From 231f449471d95bdf50a4055f7fca998071c4dd8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BE=BE?= Date: Thu, 20 Feb 2025 10:25:38 +0800 Subject: [PATCH 144/148] fix codecheck for appspawn autotest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王达 --- .../sub_startup_appspawn_appclone_0100.py | 8 +++++--- .../sub_startup_appspawn_appclone_0200.py | 8 +++++--- .../sub_startup_appspawn_appclone_0300.py | 8 +++++--- .../sub_startup_appspawn_appclone_0400.py | 4 +++- .../sub_startup_appspawn_appclone_0600.py | 2 ++ .../sub_startup_appspawn_appclone_0700.py | 2 ++ .../sub_startup_appspawn_appclone_0900.py | 2 ++ .../sub_startup_appspawn_atomservice_0100.py | 6 ++++-- .../sub_startup_appspawn_atomservice_0200.py | 6 ++++-- .../sub_startup_appspawn_atomservice_0300.py | 6 ++++-- .../sub_startup_appspawn_atomservice_0400.py | 6 ++++-- .../sub_startup_appspawn_base_0100.py | 2 ++ .../sub_startup_appspawn_base_0200.py | 2 ++ .../sub_startup_appspawn_base_0300.py | 2 ++ .../sub_startup_appspawn_base_0400.py | 2 ++ .../sub_startup_appspawn_base_0500.py | 2 ++ .../sub_startup_appspawn_base_0600.py | 6 ++++-- 17 files changed, 54 insertions(+), 20 deletions(-) diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py index 2e6e4a81..02b7cf07 100644 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0100.py @@ -1,3 +1,5 @@ +#!/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. @@ -56,15 +58,15 @@ class SubStartupAppspawnAppclone0100(TestCase): self.driver.touch(BY.text("安装克隆应用")) self.driver.touch(BY.text("startAbilityByAppIndex")) Step("步骤4:分身应用的源目录新建123.txt") - self.driver.shell("touch /data/app/el2/100/database/+clone-1+com.ohos.mytest/123.txt") + self.driver.shell("touch ../data/app/el2/100/database/+clone-1+com.ohos.mytest/123.txt") Step("步骤5:分身应用沙盒路径是否存在123.txt") cpid = self.driver.System.get_pid("com.ohos.mytest1") - result1 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % cpid) + result1 = self.driver.shell("ls ../proc/%d/root/data/storage/el2/database" % cpid) Step("步骤6:预期结果校验") self.driver.Assert.contains(result1, "123.txt") Step("步骤7:主应用沙盒路径是否存在123.txt") pid = self.driver.System.get_pid("com.ohos.mytest") - result2 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % pid) + result2 = self.driver.shell("ls ../proc/%d/root/data/storage/el2/database" % pid) Step("步骤6:预期结果校验") if ("123.txt" in result2): raise AssertionError() diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py index 196615e9..9b3d61fa 100644 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0200.py @@ -1,3 +1,5 @@ +#!/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. @@ -56,15 +58,15 @@ class SubStartupAppspawnAppclone0200(TestCase): self.driver.touch(BY.text("安装克隆应用")) self.driver.touch(BY.text("startAbilityByAppIndex")) Step("步骤4:分身应用的源目录新建123.txt") - self.driver.shell("touch /data/app/el2/100/database/com.ohos.mytest/abc.txt") + self.driver.shell("touch ../data/app/el2/100/database/com.ohos.mytest/abc.txt") Step("步骤5:主应用沙盒路径是否存在abc.txt") cpid = self.driver.System.get_pid("com.ohos.mytest") - result1 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % cpid) + result1 = self.driver.shell("ls ../proc/%d/root/data/storage/el2/database" % cpid) Step("步骤6:预期结果校验") self.driver.Assert.contains(result1, "abc.txt") Step("步骤7:分身应用沙盒路径是否存在abc.txt") pid = self.driver.System.get_pid("com.ohos.mytest1") - result2 = self.driver.shell("ls /proc/%d/root/data/storage/el2/database" % pid) + result2 = self.driver.shell("ls ../proc/%d/root/data/storage/el2/database" % pid) Step("步骤6:预期结果校验") if ("abc.txt" in result2): raise AssertionError() diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py index c4633080..50104a8d 100644 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0300.py @@ -1,3 +1,5 @@ +#!/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. @@ -44,9 +46,9 @@ class SubStartupAppspawnAppclone0300(TestCase): def build_shell_command(i, path, bundle_name, j): if bundle_name == "com.example.intaketest": - result01 = self.driver.shell("ls /data/app/el%d/100/%s/%s" % (i, path, bundle_name)) + result01 = self.driver.shell("ls ../data/app/el%d/100/%s/%s" % (i, path, bundle_name)) elif bundle_name == "com.example.intaketest%d" % j: - result01 = self.driver.shell("ls /data/app/el%d/100/%s/+clone-%d+com.example.intaketest" + result01 = self.driver.shell("ls ../data/app/el%d/100/%s/+clone-%d+com.example.intaketest" % (i, path, j)) return None @@ -92,7 +94,7 @@ class SubStartupAppspawnAppclone0300(TestCase): for j in range(1, 6): for bundle_name, pid in pid_bundlename_dict.items(): result01 = build_shell_command(i, "base", bundle_name, j) - result02 = self.driver.shell("ls /proc/%d/root/data/storage/el%d/%s" % (pid, i, "base")) + result02 = self.driver.shell("ls ../proc/%d/root/data/storage/el%d/%s" % (pid, i, "base")) self.driver.Assert.equal(result01, result02) def teardown(self): diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py index faf80d3c..ab2bc2f3 100644 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0400.py @@ -1,3 +1,5 @@ +#!/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. @@ -73,7 +75,7 @@ class SubStartupAppspawnAppclone0400(TestCase): self.driver.touch(BY.text("IntakeTest%d" % (i - 1))) self.driver.go_home() - self.driver.shell("touch /data/app/el2/100/base/%s/test.txt" % bundle_name) + self.driver.shell("touch ../data/app/el2/100/base/%s/test.txt" % bundle_name) has_file01 = self.driver.Storage.has_file("/data/app/el2/100/base/%s/test.txt" % bundle_name) self.driver.Assert.equal(has_file01, True) for i in range(1, 6): diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py index 8c3036be..86b739a5 100644 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0600.py @@ -1,3 +1,5 @@ +#!/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. diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py index 6a1d075f..80968a3f 100644 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0700.py @@ -1,3 +1,5 @@ +#!/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. diff --git a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py index 63d87c4c..53236409 100644 --- a/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py +++ b/test/autotest/sub_startup_appspawn_appclone/sub_startup_appspawn_appclone_0900.py @@ -1,3 +1,5 @@ +#!/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. 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 index fa6f0aa7..8ed54e46 100644 --- 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 @@ -1,3 +1,5 @@ +#!/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. @@ -79,7 +81,7 @@ class SubStartupAppspawnAtomservice0100(TestCase): 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") + 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 @@ -88,7 +90,7 @@ class SubStartupAppspawnAtomservice0100(TestCase): 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") + 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 diff --git a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py index 5442712b..f4202551 100644 --- a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0200.py @@ -1,3 +1,5 @@ +#!/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. @@ -121,7 +123,7 @@ class SubStartupAppspawnAtomservice0200(TestCase): Step("校验UGO、所有者、所属组、selinux标签一致") for i in range(1, 5): - hap_detail = self.driver.shell("ls -lZ /data/app/el%d/100/%s" % (i, "base")).split("\n") + 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 @@ -132,7 +134,7 @@ class SubStartupAppspawnAtomservice0200(TestCase): 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") + 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 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 index aaf35b8d..9001688a 100644 --- 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 @@ -1,3 +1,5 @@ +#!/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. @@ -55,8 +57,8 @@ class SubStartupAppspawnAtomservice0300(TestCase): 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)) + 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): diff --git a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py index d2f3086e..8d8a0ea7 100644 --- a/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py +++ b/test/autotest/sub_startup_appspawn_atomservice/sub_startup_appspawn_atomservice_0400.py @@ -1,3 +1,5 @@ +#!/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. @@ -102,8 +104,8 @@ class SubStartupAppspawnAtomservice0400(TestCase): 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)) + 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) self.exit_account() diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py index 865b43d1..71e6c7a1 100644 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0100.py @@ -1,3 +1,5 @@ +#!/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. diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py index 591824be..2fb7a988 100644 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0200.py @@ -1,3 +1,5 @@ +#!/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. diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py index 114cc9d8..d376968c 100644 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0300.py @@ -1,3 +1,5 @@ +#!/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. diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py index 1c16d6d9..77ca024b 100644 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0400.py @@ -1,3 +1,5 @@ +#!/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. diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py index 36a52c83..efec5734 100644 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0500.py @@ -1,3 +1,5 @@ +#!/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. diff --git a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py index 6cc8158d..112c9a18 100644 --- a/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py +++ b/test/autotest/sub_startup_appspawn_base/sub_startup_appspawn_base_0600.py @@ -1,3 +1,5 @@ +#!/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. @@ -68,9 +70,9 @@ class SubStartupAppspawnBase0600(TestCase): for i, txt in dict01.items(): pid = self.driver.System.get_pid(i) if i == clone_bundle_name: - self.driver.shell("touch /data/app/el2/100/base/+clone-1+%s/%s" % (bundle_name, txt)) + self.driver.shell("touch ../data/app/el2/100/base/+clone-1+%s/%s" % (bundle_name, txt)) else: - self.driver.shell("touch /data/app/el2/100/base/%s/%s" % (i, txt)) + self.driver.shell("touch ../data/app/el2/100/base/%s/%s" % (i, txt)) result = self.driver.Storage.has_file("/proc/%d/root/data/storage/el2/base/%s" % (pid, txt)) self.driver.Assert.equal(result, True) -- Gitee From 005dd8c1c768e5f9493792484a6682e023ab8d16 Mon Sep 17 00:00:00 2001 From: wangfenging Date: Wed, 19 Feb 2025 15:29:59 +0800 Subject: [PATCH 145/148] Adjust whether to mount as shared attribute Signed-off-by: wangfenging --- modules/sandbox/sandbox_shared_mount.cpp | 74 +++++++----------------- 1 file changed, 20 insertions(+), 54 deletions(-) diff --git a/modules/sandbox/sandbox_shared_mount.cpp b/modules/sandbox/sandbox_shared_mount.cpp index 56d52446..feade830 100644 --- a/modules/sandbox/sandbox_shared_mount.cpp +++ b/modules/sandbox/sandbox_shared_mount.cpp @@ -150,34 +150,14 @@ static int DoSharedMount(const SharedMountArgs *arg) return 0; } -static void GetMountInfo(std::vector &sharedMounts, AppDacInfo *info, const std::string &bundleName) +static bool SetSandboxPathShared(const std::string &sandboxPath) { - std::ifstream file("/proc/self/mountinfo"); - if (!file.is_open()) { - APPSPAWN_LOGE("Failed to open mountinfo, errno: %{public}d", errno); - return; - } - - std::string line; - while (std::getline(file, line)) { - if ((line.find(info->uid / UID_BASE) != std::string::npos) && (line.find(bundleName) != std::string::npos) && - (line.find("shared:") != std::string::npos)) { - sharedMounts.push_back(line); - } - } - file.close(); - APPSPAWN_LOGI("Get mountinfo %{public}s end", bundleName.c_str()); -} - -static bool IsSandboxPathShared(const std::vector &sharedMounts, const std::string &sandboxPath) -{ - std::regex mountPoint(sandboxPath); - for (const auto &sharedMount : sharedMounts) { - if (std::regex_search(sharedMount, mountPoint)) { - return true; - } + int ret = mount(nullptr, sandboxPath.c_str(), nullptr, MS_SHARED, nullptr); + if (ret != 0) { + APPSPAWN_LOGW("Need to mount %{public}s to shared, errno %{public}d", sandboxPath.c_str(), errno); + return false; } - return false; + return true; } static int MountEl1Bundle(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName) @@ -227,8 +207,7 @@ static int MountEl1Bundle(const AppSpawningCtx *property, const AppDacInfo *info return ret; } -static int MountWithFileMgr(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName, - std::vector &sharedMounts) +static int MountWithFileMgr(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName) { /* /mnt/user//nosharefs/docs */ char nosharefsDocsDir[PATH_MAX_LEN] = {0}; @@ -249,7 +228,7 @@ static int MountWithFileMgr(const AppSpawningCtx *property, const AppDacInfo *in } // Check whether the directory is a shared mount point - if (IsSandboxPathShared(sharedMounts, storageUserPath)) { + if (SetSandboxPathShared(storageUserPath)) { APPSPAWN_LOGI("shared mountpoint is exist"); return 0; } @@ -275,8 +254,7 @@ static int MountWithFileMgr(const AppSpawningCtx *property, const AppDacInfo *in return ret; } -static int MountWithOther(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName, - std::vector &sharedMounts) +static int MountWithOther(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName) { /* /mnt/user//sharefs/docs */ char sharefsDocsDir[PATH_MAX_LEN] = {0}; @@ -297,7 +275,7 @@ static int MountWithOther(const AppSpawningCtx *property, const AppDacInfo *info } // Check whether the directory is a shared mount point - if (IsSandboxPathShared(sharedMounts, storageUserPath)) { + if (SetSandboxPathShared(storageUserPath)) { APPSPAWN_LOGI("shared mountpoint is exist"); return 0; } @@ -331,18 +309,17 @@ static int MountWithOther(const AppSpawningCtx *property, const AppDacInfo *info return ret; } -static void MountStorageUsers(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName, - std::vector &sharedMounts) +static void MountStorageUsers(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName) { int ret = 0; int index = GetPermissionIndex(nullptr, "ohos.permission.FILE_ACCESS_MANAGER"); int checkRes = CheckAppPermissionFlagSet(property, static_cast(index)); if (checkRes == 0) { /* mount /mnt/user//sharefs/docs to /mnt/sandbox///storage/Users */ - ret = MountWithOther(property, info, bundleName, sharedMounts); + ret = MountWithOther(property, info, bundleName); } else { /* mount /mnt/user//nosharefs/docs to /mnt/sandbox///storage/Users */ - ret = MountWithFileMgr(property, info, bundleName, sharedMounts); + ret = MountWithFileMgr(property, info, bundleName); } if (ret != 0) { APPSPAWN_LOGE("Update %{public}s storage dir failed, ret %{public}d", @@ -353,7 +330,7 @@ static void MountStorageUsers(const AppSpawningCtx *property, const AppDacInfo * } static int MountSharedMapItem(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName, - const char *sandboxPathItem, std::vector &sharedMounts) + const char *sandboxPathItem) { /* /mnt/sandbox///data/storage/el */ char sandboxPath[PATH_MAX_LEN] = {0}; @@ -365,7 +342,7 @@ static int MountSharedMapItem(const AppSpawningCtx *property, const AppDacInfo * } // Check whether the directory is a shared mount point - if (IsSandboxPathShared(sharedMounts, sandboxPath)) { + if (SetSandboxPathShared(sandboxPath)) { APPSPAWN_LOGI("shared mountpoint is exist"); return 0; } @@ -391,18 +368,17 @@ static int MountSharedMapItem(const AppSpawningCtx *property, const AppDacInfo * return ret; } -static void MountSharedMap(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName, - std::vector &sharedMounts) +static void MountSharedMap(const AppSpawningCtx *property, const AppDacInfo *info, const char *bundleName) { int length = sizeof(MOUNT_SHARED_MAP) / sizeof(MOUNT_SHARED_MAP[0]); for (int i = 0; i < length; i++) { if (MOUNT_SHARED_MAP[i].permission == nullptr) { - MountSharedMapItem(property, info, bundleName, MOUNT_SHARED_MAP[i].sandboxPath, sharedMounts); + MountSharedMapItem(property, info, bundleName, MOUNT_SHARED_MAP[i].sandboxPath); } else { int index = GetPermissionIndex(nullptr, MOUNT_SHARED_MAP[i].permission); APPSPAWN_LOGV("mount dir on lock mountPermissionFlags %{public}d", index); if (CheckAppPermissionFlagSet(property, static_cast(index))) { - MountSharedMapItem(property, info, bundleName, MOUNT_SHARED_MAP[i].sandboxPath, sharedMounts); + MountSharedMapItem(property, info, bundleName, MOUNT_SHARED_MAP[i].sandboxPath); } } } @@ -592,20 +568,10 @@ static void MountDirToShared(AppSpawnMgr *content, const AppSpawningCtx *propert return; } - struct timespec checkStart = {0}; - clock_gettime(CLOCK_MONOTONIC, &checkStart); - - std::vector sharedMounts; - GetMountInfo(sharedMounts, info, std::string(bundleInfo->bundleName)); - MountSharedMap(property, info, bundleInfo->bundleName, sharedMounts); - MountStorageUsers(property, info, bundleInfo->bundleName, sharedMounts); + MountSharedMap(property, info, bundleInfo->bundleName); + MountStorageUsers(property, info, bundleInfo->bundleName); ParseDataGroupList(content, property, info, bundleInfo); - struct timespec checkEnd = {0}; - clock_gettime(CLOCK_MONOTONIC, &checkEnd); - uint64_t diff = DiffTime(&checkStart, &checkEnd); - APPSPAWN_LOGI("Check %{public}s mount status use time %{public}" PRId64" us", bundleInfo->bundleName, diff); - std::string lockSbxPathStamp = "/mnt/sandbox/" + std::to_string(info->uid / UID_BASE) + "/"; lockSbxPathStamp += CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX_TYPE) ? "isolated/" : ""; lockSbxPathStamp += bundleInfo->bundleName; -- Gitee From 62d01f66f8755d55d9e99addce3deaf320a503a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Fri, 21 Feb 2025 14:20:26 +0800 Subject: [PATCH 146/148] remove developer mode in hnp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- interfaces/innerkits/hnp/src/hnp_api.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/interfaces/innerkits/hnp/src/hnp_api.c b/interfaces/innerkits/hnp/src/hnp_api.c index 2f303234..62b4245a 100644 --- a/interfaces/innerkits/hnp/src/hnp_api.c +++ b/interfaces/innerkits/hnp/src/hnp_api.c @@ -164,11 +164,6 @@ int NativeInstallHnp(const char *userId, const char *hnpRootPath, const HapInfo char *apcEnv[MAX_ENV_NUM] = {0}; int index = 0; - if (!IsDeveloperModeOpen()) { - HNPAPI_LOG("\r\n [HNP API] native package install not in developer mode"); - return HNP_API_NOT_IN_DEVELOPER_MODE; - } - if ((userId == NULL) || (hnpRootPath == NULL) || (hapInfo == NULL)) { return HNP_API_ERRNO_PARAM_INVALID; } @@ -207,11 +202,6 @@ int NativeUnInstallHnp(const char *userId, const char *packageName) char *apcEnv[MAX_ENV_NUM] = {0}; int index = 0; - if (!IsDeveloperModeOpen()) { - HNPAPI_LOG("\r\n [HNP API] native package uninstall not in developer mode"); - return HNP_API_NOT_IN_DEVELOPER_MODE; - } - if ((userId == NULL) || (packageName == NULL)) { return HNP_API_ERRNO_PARAM_INVALID; } -- Gitee From a2fffda4e23f604da05953b123d7a470c72f8a5e Mon Sep 17 00:00:00 2001 From: wangfeng Date: Thu, 6 Feb 2025 21:21:22 +0800 Subject: [PATCH 147/148] add datagroup uttest cases Signed-off-by: wangfeng --- .../app_spawn_sandbox_test.cpp | 475 ++++++++++++++++++ 1 file changed, 475 insertions(+) diff --git a/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp index aa417ed0..5d6bba80 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp @@ -28,6 +28,7 @@ #include "app_spawn_stub.h" #include "app_spawn_test_helper.h" +#include "sandbox_shared_mount.h" using namespace testing; using namespace testing::ext; @@ -1550,4 +1551,478 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_AppExtension_009, TestSize.Level DeleteAppSpawningCtx(spawningCtx); AppSpawnClientDestroy(clientHandle); } + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_01 + * @tc.desc: [IsValidDataGroupItem] input valid param + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_01, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_01 start"; + char dataGroupInfoListStr[] = R"( + { + "gid": "1002", + "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840", + "dataGroupId": "43200", + "uuid": "49c016e6-065a-abd1-5867-b1f91114f840" + } + )"; + nlohmann::json j_config = nlohmann::json::parse(dataGroupInfoListStr); + bool ret = IsValidDataGroupItem(j_config); + EXPECT_TRUE(ret); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_01 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_02 + * @tc.desc: [IsValidDataGroupItem] input valid param in json array + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_02, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_02 start"; + char dataGroupInfoListStr[] = R"([ + { + "gid": "1002", + "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840", + "dataGroupId": "43200", + "uuid": "49c016e6-065a-abd1-5867-b1f91114f840" + }, + { + "gid": "1002", + "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840", + "dataGroupId": "43200", + "uuid": "49c016e6-065a-abd1-5867-b1f91114f840" + } + ])"; + nlohmann::json j_config = nlohmann::json::parse(dataGroupInfoListStr); + bool ret = false; + for (auto& item : j_config) { + ret = IsValidDataGroupItem(item); + if (ret != true) { + break; + } + } + EXPECT_TRUE(ret); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_02 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_03 + * @tc.desc: [IsValidDataGroupItem] input valid param, datagroupId is not string type + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_03, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_03 start"; + char dataGroupInfoListStr[] = R"( + { + "gid": "1002", + "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840", + "dataGroupId": 43200, + "uuid": "49c016e6-065a-abd1-5867-b1f91114f840" + } + )"; + nlohmann::json j_config = nlohmann::json::parse(dataGroupInfoListStr); + bool ret = IsValidDataGroupItem(j_config); + EXPECT_FALSE(ret); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_03 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_04 + * @tc.desc: [IsValidDataGroupItem] input valid param, gid is not string type + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_04, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_04 start"; + char dataGroupInfoListStr[] = R"( + { + "gid": 1002, + "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840", + "dataGroupId": "43200", + "uuid": "49c016e6-065a-abd1-5867-b1f91114f840" + } + )"; + nlohmann::json j_config = nlohmann::json::parse(dataGroupInfoListStr); + bool ret = IsValidDataGroupItem(j_config); + EXPECT_FALSE(ret); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_04 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_05 + * @tc.desc: [IsValidDataGroupItem] input valid param, dir is not string type + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_05, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_05 start"; + char dataGroupInfoListStr[] = R"( + { + "gid": "1002", + "dir": 100, + "dataGroupId": "43200", + "uuid": "49c016e6-065a-abd1-5867-b1f91114f840" + } + )"; + nlohmann::json j_config = nlohmann::json::parse(dataGroupInfoListStr); + bool ret = IsValidDataGroupItem(j_config); + EXPECT_FALSE(ret); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_05 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_06 + * @tc.desc: [IsValidDataGroupItem] input valid param, uuid is not string type + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_06, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_06 start"; + char dataGroupInfoListStr[] = R"( + { + "gid": "1002", + "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840", + "dataGroupId": "43200", + "uuid": 124 + } + )"; + nlohmann::json j_config = nlohmann::json::parse(dataGroupInfoListStr); + bool ret = IsValidDataGroupItem(j_config); + EXPECT_FALSE(ret); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_06 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_07 + * @tc.desc: [IsValidDataGroupItem] input valid param, datagroupId and gid is not string type + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_07, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_07 start"; + char dataGroupInfoListStr[] = R"( + { + "gid": 1002, + "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840", + "dataGroupId": 43200, + "uuid": "49c016e6-065a-abd1-5867-b1f91114f840" + } + )"; + nlohmann::json j_config = nlohmann::json::parse(dataGroupInfoListStr); + bool ret = IsValidDataGroupItem(j_config); + EXPECT_FALSE(ret); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_07 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_08 + * @tc.desc: [IsValidDataGroupItem] input valid param, datagroupId and dir is not string type + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_08, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_08 start"; + char dataGroupInfoListStr[] = R"( + { + "gid": "1002", + "dir": 100, + "dataGroupId": 43200, + "uuid": "49c016e6-065a-abd1-5867-b1f91114f840" + } + )"; + nlohmann::json j_config = nlohmann::json::parse(dataGroupInfoListStr); + bool ret = IsValidDataGroupItem(j_config); + EXPECT_FALSE(ret); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_08 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_09 + * @tc.desc: [IsValidDataGroupItem] input valid param, datagroupId and uuid is not string type + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_09, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_09 start"; + char dataGroupInfoListStr[] = R"( + { + "gid": "1002", + "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840", + "dataGroupId": 43200, + "uuid": 124 + } + )"; + nlohmann::json j_config = nlohmann::json::parse(dataGroupInfoListStr); + bool ret = IsValidDataGroupItem(j_config); + EXPECT_FALSE(ret); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_09 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_10 + * @tc.desc: [IsValidDataGroupItem] input valid param, gid and dir is not string type + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_10, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_10 start"; + char dataGroupInfoListStr[] = R"( + { + "gid": 1002, + "dir": 100, + "dataGroupId": "43200", + "uuid": "49c016e6-065a-abd1-5867-b1f91114f840" + } + )"; + nlohmann::json j_config = nlohmann::json::parse(dataGroupInfoListStr); + bool ret = IsValidDataGroupItem(j_config); + EXPECT_FALSE(ret); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_10 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_11 + * @tc.desc: [IsValidDataGroupItem] input valid param, gid and uuid is not string type + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_11, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_11 start"; + char dataGroupInfoListStr[] = R"( + { + "gid": 1002, + "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840", + "dataGroupId": "43200", + "uuid": 124 + } + )"; + nlohmann::json j_config = nlohmann::json::parse(dataGroupInfoListStr); + bool ret = IsValidDataGroupItem(j_config); + EXPECT_FALSE(ret); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_11 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_12 + * @tc.desc: [IsValidDataGroupItem] input valid param, dir and uuid is not string type + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_12, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_12 start"; + char dataGroupInfoListStr[] = R"( + { + "gid": "1002", + "dir": 100, + "dataGroupId": "43200", + "uuid": 124 + } + )"; + nlohmann::json j_config = nlohmann::json::parse(dataGroupInfoListStr); + bool ret = IsValidDataGroupItem(j_config); + EXPECT_FALSE(ret); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_12 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_13 + * @tc.desc: [GetElxInfoFromDir] input valid, the directory contains el2. + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_13, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_13 start"; + std::string str = "/data/storage/el2/group/"; + int res = GetElxInfoFromDir(str.c_str()); + EXPECT_EQ(res, EL2); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_13 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_14 + * @tc.desc: [GetElxInfoFromDir] input valid, the directory contains el3. + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_14, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_14 start"; + std::string str = "/data/storage/el3/group/"; + int res = GetElxInfoFromDir(str.c_str()); + EXPECT_EQ(res, EL3); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_14 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_15 + * @tc.desc: [GetElxInfoFromDir] input valid, the directory contains el4. + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_15, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_15 start"; + std::string str = "/data/storage/el4/group/"; + int res = GetElxInfoFromDir(str.c_str()); + EXPECT_EQ(res, EL4); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_15 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_16 + * @tc.desc: [GetElxInfoFromDir] input valid, the directory contains el5. + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_16, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_16 start"; + std::string str = "/data/storage/el5/group/"; + int res = GetElxInfoFromDir(str.c_str()); + EXPECT_EQ(res, EL5); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_16 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_17 + * @tc.desc: [GetElxInfoFromDir] input invalid, the directory don't contains el2~el5, contains el0. + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_17, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_17 start"; + std::string str = "/data/storage/el0/group/"; + int res = GetElxInfoFromDir(str.c_str()); + EXPECT_EQ(res, ELX_MAX); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_17 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_18 + * @tc.desc: [GetElxInfoFromDir] input invalid, the directory don't contains el2~el5, contains el6. + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_18, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_18 start"; + std::string str = "/data/storage/el6/group/"; + int res = GetElxInfoFromDir(str.c_str()); + EXPECT_EQ(res, ELX_MAX); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_18 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_19 + * @tc.desc: [GetElxInfoFromDir] input invalid, the directory don't contains el2~el5, param is null. + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_19, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_19 start"; + int res = GetElxInfoFromDir(nullptr); + EXPECT_EQ(res, ELX_MAX); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_19 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_20 + * @tc.desc: [GetDataGroupArgTemplate] input invalid, the category is between el2 and el5, category is EL2. + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_20, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_20 start"; + const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(EL2); + ASSERT_EQ(templateItem != nullptr, 1); + int res = strcmp(templateItem->elxName, "el2"); + EXPECT_EQ(res, 0); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_20 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_21 + * @tc.desc: [GetDataGroupArgTemplate] input invalid, the category is between el2 and el5, category is EL3. + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_21, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_21 start"; + const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(EL3); + ASSERT_EQ(templateItem != nullptr, 1); + int res = strcmp(templateItem->elxName, "el3"); + EXPECT_EQ(res, 0); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_21 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_22 + * @tc.desc: [GetDataGroupArgTemplate] input invalid, the category is between el2 and el5, category is EL4. + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_22, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_22 start"; + const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(EL4); + ASSERT_EQ(templateItem != nullptr, 1); + int res = strcmp(templateItem->elxName, "el4"); + EXPECT_EQ(res, 0); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_22 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_23 + * @tc.desc: [GetDataGroupArgTemplate] input invalid, the category is between el2 and el5, category is EL5. + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_23, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_23 start"; + const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(EL5); + ASSERT_EQ(templateItem != nullptr, 1); + int res = strcmp(templateItem->elxName, "el5"); + EXPECT_EQ(res, 0); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_23 end"; +} + +/** + * @tc.name: App_Spawn_Sandbox_Shared_Mount_24 + * @tc.desc: [GetDataGroupArgTemplate] input invalid, the category is between el2 and el5, category is 6. + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_24, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_24 start"; + const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(6); + int res = -1; + if (templateItem == nullptr) { + res = 0; + } + EXPECT_EQ(res, 0); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_Shared_Mount_24 end"; +} } // namespace OHOS -- Gitee From 6c0cc34daa50c29b12f7d9d6f2f46b752839a9be Mon Sep 17 00:00:00 2001 From: sandee Date: Tue, 25 Feb 2025 20:16:06 +0800 Subject: [PATCH 148/148] Support 2.0 Runtime in AppSpawn Issue: https://gitee.com/openharmony/startup_appspawn/issues/IBIXEM Signed-off-by: sandee Change-Id: I2b1d74c8b59a6d00e451190a7aa751d956bce79c --- modules/ace_adapter/ace_adapter.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/ace_adapter/ace_adapter.cpp b/modules/ace_adapter/ace_adapter.cpp index 37da3a22..464d7ad8 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -95,6 +95,13 @@ static void PreloadModule(void) return; } + options.lang = OHOS::AbilityRuntime::Runtime::Language::STS; + auto stsRuntime = OHOS::AbilityRuntime::Runtime::Create(options); + if (!stsRuntime) { + APPSPAWN_LOGE("LoadExtendLib: Failed to create sts runtime"); + return; + } + ParseJsonContext context = {}; (void)ParseJsonConfig("etc/appspawn", PRELOAD_JSON_CONFIG.c_str(), GetModuleSet, &context); for (std::string moduleName : context.modules) { -- Gitee