diff --git a/begetd.gni b/begetd.gni index 1bcc555e8d9daab81c7468ff5492c74aeec1cc20..2b18ec65ae4d9998ee4cc192f12a059343de3987 100644 --- a/begetd.gni +++ b/begetd.gni @@ -40,7 +40,7 @@ declare_args() { } # config memory size for liteos-m - init_lite_memory_size = 5120 + init_lite_memory_size = 10240 startup_init_feature_decode_group_file = false diff --git a/device_info/device_info_service.cpp b/device_info/device_info_service.cpp index 7014391801ec7756372ad650764a73d329ce0947..211d49c5a6cfb0b15450118efa996dcb3f426944 100644 --- a/device_info/device_info_service.cpp +++ b/device_info/device_info_service.cpp @@ -107,15 +107,13 @@ int32_t DeviceInfoService::CallbackEnter(uint32_t code) switch (code) { case static_cast(IDeviceInfoIpcCode::COMMAND_GET_UDID): case static_cast(IDeviceInfoIpcCode::COMMAND_GET_SERIAL_I_D): { - if (!CheckPermission("ohos.permission.sec.ACCESS_UDID")) { - return SYSPARAM_PERMISSION_DENIED; - } + bool ret = CheckPermission("ohos.permission.sec.ACCESS_UDID"); + BEGET_CHECK_RETURN_VALUE(ret, SYSPARAM_PERMISSION_DENIED); break; } case static_cast(IDeviceInfoIpcCode::COMMAND_GET_DISK_S_N): { - if (!CheckPermission("ohos.permission.ACCESS_DISK_PHY_INFO")) { - return SYSPARAM_PERMISSION_DENIED; - } + bool ret = CheckPermission("ohos.permission.ACCESS_DISK_PHY_INFO"); + BEGET_CHECK_RETURN_VALUE(ret, SYSPARAM_PERMISSION_DENIED); break; } default: { diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index 5730ca563522cf8a93b3b444ac160200cf656f5d..1ddf974bde7df6860367288a14d2989eda80827a 100755 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -54,7 +54,6 @@ if (defined(ohos_lite)) { ] sources = [] include_dirs = include_common - include_dirs += [ "//base/hiviewdfx/hilog_lite/interfaces/native/kits" ] public_configs = [ ":exported_header_files" ] deps = [ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", @@ -411,7 +410,11 @@ if (defined(ohos_lite)) { if (default_toolchain == current_toolchain) { ohos_prebuilt_shared_library("libbegetutil-pub-sdk") { source = "${root_out_dir}/startup/init/libbegetutil.z.so" - symlink_ext = [ "lib64/chipset-pub-sdk/libbegetutil.z.so" ] + if (target_cpu == "arm64" || target_cpu == "x86_64") { + symlink_ext = [ "lib64/chipset-pub-sdk/libbegetutil.z.so" ] + } else { + symlink_ext = [ "lib/chipset-pub-sdk/libbegetutil.z.so" ] + } deps = [ "//base/startup/init/interfaces/innerkits:libbegetutil" ] install_enable = true install_images = [ diff --git a/interfaces/innerkits/fs_manager/BUILD.gn b/interfaces/innerkits/fs_manager/BUILD.gn index feb87956fc2c458a6a4ecff633fb8d5f060bacf3..5989fa3b9e53eac99957d0812d7cfd9bf10d0ec8 100755 --- a/interfaces/innerkits/fs_manager/BUILD.gn +++ b/interfaces/innerkits/fs_manager/BUILD.gn @@ -53,11 +53,11 @@ ohos_static_library("libfsmanager_static") { if ((defined(global_parts_info) && defined(global_parts_info.startup_hvb)) || init_startup_feature_erofs_overlay) { - sources += [ + sources += [ "libfs_dm/fs_dm.c", "libfs_dm/fs_dm_linear.c", "libfs_dm/fs_dm_snapshot.c", - ] + ] include_dirs += [ "//base/startup/init/interfaces/innerkits/fs_manager/libfs_dm/include", "//base/startup/init/ueventd/include", @@ -89,6 +89,10 @@ ohos_static_library("libfsmanager_static") { include_dirs += [ "//base/startup/init/interfaces/innerkits/fs_manager/erofs_overlay/include" ] defines += [ "EROFS_OVERLAY" ] + if (build_selinux) { + external_deps += [ "selinux:libselinux" ] + cflags = [ "-DWITH_SELINUX" ] + } } } @@ -118,26 +122,48 @@ ohos_static_library("libfsmanager_static_real") { "cJSON:cjson_static", ] deps = [ "//base/startup/init/services/utils:libinit_utils" ] - if (defined(global_parts_info) && defined(global_parts_info.startup_hvb)) { - sources += [ - "dm_verity/dm_verity.c", + + if ((defined(global_parts_info) && + defined(global_parts_info.startup_hvb)) || + init_startup_feature_erofs_overlay) { + source += [ "libfs_dm/fs_dm.c", "libfs_dm/fs_dm_linear.c", "libfs_dm/fs_dm_snapshot.c", + ] + include_dirs += [ + "//base/startup/init/interfaces/innerkits/fs_manager/libfs_dm/include", + "//base/startup/init/ueventd/include", + ] + defines = [] + deps += [ "//base/startup/init/ueventd:libueventd_ramdisk_static_real" ] + } + + if (defined(global_parts_info) && defined(global_parts_info.startup_hvb)) { + sources += [ + "dm_verity/dm_verity.c", "libfs_hvb/fs_hvb.c", "libfs_hvb/hvb_ops.c", ] include_dirs += [ - "//base/startup/init/interfaces/innerkits/fs_manager/libfs_dm/include", "//base/startup/init/interfaces/innerkits/fs_manager/libfs_hvb/include", "//base/startup/init/interfaces/innerkits/fs_manager/dm_verity/include", - "//base/startup/init/ueventd/include", ] defines = [ "SUPPORT_HVB" ] external_deps += [ "hvb:libhvb_static" ] - deps += [ "//base/startup/init/ueventd:libueventd_ramdisk_static_real" ] + } + + if (init_startup_feature_erofs_overlay) { + sources += [ + "erofs_overlay/erofs_mount_overlay.c", + "erofs_overlay/erofs_overlay_common.c", + "erofs_overlay/erofs_remount_overlay.c", + ] + include_dirs += [ "//base/startup/init/interfaces/innerkits/fs_manager/erofs_overlay/include" ] + + defines += [ "EROFS_OVERLAY" ] } } diff --git a/interfaces/innerkits/fs_manager/erofs_overlay/erofs_mount_overlay.c b/interfaces/innerkits/fs_manager/erofs_overlay/erofs_mount_overlay.c index f74c27edbae2f1cace7770ffd8757baf6b2d8910..7a3601a351a87696c07e561a7d4a4aaa66b645c0 100644 --- a/interfaces/innerkits/fs_manager/erofs_overlay/erofs_mount_overlay.c +++ b/interfaces/innerkits/fs_manager/erofs_overlay/erofs_mount_overlay.c @@ -17,6 +17,9 @@ #include #include #include "securec.h" +#ifdef WITH_SELINUX +#include +#endif #include "init_utils.h" #include "fs_dm.h" #include "switch_root.h" @@ -249,7 +252,6 @@ INIT_STATIC int ConstructLinearTarget(DmVerityTarget *target, const char *dev, u return -1; } target->paras_len = strlen(target->paras); - BEGET_LOGI("dev [%s], linearparas [%s], length [%s]", dev, target->paras, target->paras_len); return 0; } @@ -335,27 +337,42 @@ int MountExt4Device(const char *dev, const char *mnt, bool isFirstMount) char dirExt4[MAX_BUFFER_LEN] = {0}; char dirUpper[MAX_BUFFER_LEN] = {0}; char dirWork[MAX_BUFFER_LEN] = {0}; + +#ifdef WITH_SELINUX + if (isFirstMount) { + const char* fsFileContext = "u:object_r:system_file:s0"; + const char* vendorFileContext = "u:object_r:vendor_file:s0"; + BEGET_LOGI("start to set selinux. mnt:%s", mnt); + if (strcmp(mnt, "/vendor") == 0) { + setfscreatecon(vendorFileContext); + } else { + setfscreatecon(fsFileContext); + } + } +#endif + ret = snprintf_s(dirExt4, MAX_BUFFER_LEN, MAX_BUFFER_LEN - 1, PREFIX_OVERLAY"%s", mnt); if (ret < 0) { BEGET_LOGE("dirExt4 copy failed errno %d.", errno); - return -1; + goto exit; } ret = snprintf_s(dirUpper, MAX_BUFFER_LEN, MAX_BUFFER_LEN - 1, PREFIX_OVERLAY"%s"PREFIX_UPPER, mnt); if (ret < 0) { BEGET_LOGE("dirUpper copy failed errno %d.", errno); - return -1; + goto exit; } ret = snprintf_s(dirWork, MAX_BUFFER_LEN, MAX_BUFFER_LEN - 1, PREFIX_OVERLAY"%s"PREFIX_WORK, mnt); if (ret < 0) { BEGET_LOGE("dirWork copy failed errno %d.", errno); - return -1; + goto exit; } if (mkdir(dirExt4, MODE_MKDIR) && (errno != EEXIST)) { BEGET_LOGE("mkdir %s failed.", dirExt4); - return -1; + ret = -1; + goto exit; } int retryCount = 3; @@ -371,14 +388,23 @@ int MountExt4Device(const char *dev, const char *mnt, bool isFirstMount) if (isFirstMount && mkdir(dirUpper, MODE_MKDIR) && (errno != EEXIST)) { BEGET_LOGE("mkdir dirUpper:%s failed.", dirUpper); - return -1; + ret = -1; + goto exit; } if (isFirstMount && mkdir(dirWork, MODE_MKDIR) && (errno != EEXIST)) { BEGET_LOGE("mkdir dirWork:%s failed.", dirWork); - return -1; + ret = -1; + goto exit; } + ret = 0; +exit: +#ifdef WITH_SELINUX + if (isFirstMount) { + setfscreatecon(NULL); + } +#endif return ret; } @@ -480,5 +506,6 @@ int DoMountOverlayDevice(FstabItem *item) BEGET_LOGE("init ext4 dm dev failed"); return -1; } + BEGET_LOGI("mount overlay device %s on %s success", item->deviceName, item->mountPoint); return rc; } \ No newline at end of file diff --git a/interfaces/innerkits/fs_manager/erofs_overlay/erofs_remount_overlay.c b/interfaces/innerkits/fs_manager/erofs_overlay/erofs_remount_overlay.c index 9b217ede3679a3dc0fa44ff37ce37a8c6dd5aad1..ac18241c7a4722afa6ea2d5c22ec392dd2523f24 100644 --- a/interfaces/innerkits/fs_manager/erofs_overlay/erofs_remount_overlay.c +++ b/interfaces/innerkits/fs_manager/erofs_overlay/erofs_remount_overlay.c @@ -52,14 +52,14 @@ int GetRemountResult(void) return REMOUNT_FAIL; } -void SetRemountResultFlag() +void SetRemountResultFlag(void) { struct stat st; int ret; int statRet = stat(REMOUNT_RESULT_PATH, &st); if (statRet != 0) { - ret = mkdir(REMOUNT_RESULT_PATH, MODE_MKDIR); + ret = MakeDirRecursive(REMOUNT_RESULT_PATH, MODE_MKDIR); if (ret < 0 && errno != EEXIST) { BEGET_LOGE("mkdir remount path failed errno %d", errno); return; diff --git a/interfaces/innerkits/fs_manager/erofs_overlay/include/erofs_remount_overlay.h b/interfaces/innerkits/fs_manager/erofs_overlay/include/erofs_remount_overlay.h index 8a34cf7925d00b5313d4d7db14b26c98cada4e14..96829636f24809b58836158fedbd634bf6eac4c7 100644 --- a/interfaces/innerkits/fs_manager/erofs_overlay/include/erofs_remount_overlay.h +++ b/interfaces/innerkits/fs_manager/erofs_overlay/include/erofs_remount_overlay.h @@ -29,7 +29,7 @@ extern "C" { int GetRemountResult(void); -void SetRemountResultFlag(); +void SetRemountResultFlag(void); int RemountOverlay(void); diff --git a/interfaces/innerkits/fs_manager/fstab_mount.c b/interfaces/innerkits/fs_manager/fstab_mount.c index 078c1817d1f2603c68951dde3e825e4fbabf180c..801cf1c7a14f68391f24e4beb3c410c92ab4e941 100755 --- a/interfaces/innerkits/fs_manager/fstab_mount.c +++ b/interfaces/innerkits/fs_manager/fstab_mount.c @@ -27,6 +27,7 @@ #include "fs_manager/fs_manager.h" #include "hookmgr.h" #include "list.h" +#include "init_modulemgr.h" #include "init_utils.h" #include "param/init_param.h" #include "securec.h" @@ -48,14 +49,14 @@ extern "C" { #define FS_MANAGER_BUFFER_SIZE 512 #define BLOCK_SIZE_BUFFER (64) #define RESIZE_BUFFER_SIZE 1024 -#define MAX_GCALLOWNANCE 100 -#define GCALLOWANCE_INCREACE 10 +#define MAX_GC_ALLOWANCE 100 +#define GCALLOWANCE_INCREASE 10 const off_t PARTITION_ACTIVE_SLOT_OFFSET = 1024; const off_t PARTITION_ACTIVE_SLOT_SIZE = 4; int g_bootSlots = -1; int g_currentSlot = -1; -__attribute__((weak)) void InitPostMount(const char *mountPoint, int rc) +__attribute__((weak)) void InitPostMount(int rc, struct FstabItem *fstabItem) { } @@ -454,8 +455,8 @@ INIT_STATIC int MountWithCheckpoint(const char *source, const char *target, cons if (rc != 0 && errno == EBUSY) { rc = 0; } - gcAllowance += GCALLOWANCE_INCREACE; - } while (rc != 0 && errno == EAGAIN && gcAllowance <= MAX_GCALLOWNANCE); + gcAllowance += GCALLOWANCE_INCREASE; + } while (rc != 0 && errno == EAGAIN && gcAllowance <= MAX_GC_ALLOWANCE); return rc; } @@ -510,6 +511,47 @@ int GetCurrentSlot(void) return GetSlotInfoFromBootctrl(PARTITION_ACTIVE_SLOT_OFFSET, PARTITION_ACTIVE_SLOT_SIZE); } +static int GetSlotStatus(void) +{ + static int slotStatus = SLOTSTATUS_INIT; + if (slotStatus != SLOTSTATUS_INIT) { + return slotStatus; + } + slotStatus = SLOTSTATUS_OTHER; + do { + if (GetBootSlots() <= 1) { + BEGET_LOGE("boot slot not need CheckVabMountInfo"); + break; + } + int slot = GetCurrentSlot(); + if (slot <= 0 || slot > MAX_SLOT) { + BEGET_LOGE("slot value %d is invalid", slot); + break; + } + slotStatus = SLOTSTATUS_VAB; + } while (0); + return slotStatus; +} + +static int UpdataAndCheckVabMountInfo(FstabItem *item, int result) +{ + int slot = GetSlotStatus(); + if (slot != SLOTSTATUS_VAB) { + return 0; + } + VabMountInfo mountInfo = { + .deviceName = item == NULL ? NULL : item->deviceName, + .fsType = item == NULL ? NULL : item->fsType, + .result = result, + }; + int ret = HookMgrExecute(GetBootStageHookMgr(), INIT_CHECK_VAB_MOUNTINFO, + item == NULL ? NULL : (void*)&mountInfo, NULL); + if (ret != 0) { + BEGET_LOGE("CheckVabMountInfo failed "); + } + return ret; +} + INIT_STATIC int GetDataWithoutCheckpoint(char *fsSpecificData, size_t fsSpecificDataSize, char *checkpointData, size_t checkpointDataSize) { @@ -542,12 +584,12 @@ INIT_STATIC int GetDataWithoutCheckpoint(char *fsSpecificData, size_t fsSpecific continue; } if (strcmp(checkpointData, "") != 0 && - strncat_s(checkpointData, checkpointDataSize - 1, ",", 1) != EOK) { + strncat_s(checkpointData, checkpointDataSize, ",", 1) != EOK) { BEGET_LOGW("failed to append comma."); rc = -1; break; } - if (strncat_s(checkpointData, checkpointDataSize - 1, p, strlen(p)) != EOK) { + if (strncat_s(checkpointData, checkpointDataSize, p, strlen(p)) != EOK) { BEGET_LOGW("Failed to append mountflags \" %s \", ignore it.", p); rc = -1; break; @@ -642,20 +684,29 @@ static int MountItemByFsType(FstabItem *item) static int ExecCheckpointHook(FstabItem *item) { - HOOK_EXEC_OPTIONS options; - options.flags = TRAVERSE_STOP_WHEN_ERROR; - options.postHook = NULL; - options.preHook = NULL; - int ret = HookMgrExecute(GetBootStageHookMgr(), INIT_DISABLE_CHECKPOINT, (void*)item, &options); - BEGET_LOGI("ExecCheckpointHook ret %d", ret); + int ret = -1; + do { + int slot = GetSlotStatus(); + if (slot != SLOTSTATUS_VAB) { + return 0; + } + + ret = HookMgrExecute(GetBootStageHookMgr(), INIT_DISABLE_CHECKPOINT, (void*)item, NULL); + BEGET_LOGI("ExecCheckpointHook ret %d", ret); + } while (0); + return ret; } + int MountOneItem(FstabItem *item) { if (item == NULL) { return -1; } - + if (!IsSupportedFilesystem(item->fsType)) { + BEGET_LOGW("Unsupported file system \" %s \"", item->fsType); + return 0; + } if (FM_MANAGER_WAIT_ENABLED(item->fsManagerFlags)) { WaitForFile(item->deviceName, WAIT_MAX_SECOND); } @@ -691,11 +742,13 @@ int MountOneItem(FstabItem *item) SwitchRoot("/usr"); } #endif + if (disableCheckpointRet == 0 && rc == 0) { BEGET_LOGI("start health check process"); HookMgrExecute(GetBootStageHookMgr(), INIT_HEALTH_CHECK_ACTIVE, NULL, NULL); } - InitPostMount(item->mountPoint, rc); + UpdataAndCheckVabMountInfo(item, rc); + InitPostMount(rc, item); if (rc != 0) { if (FM_MANAGER_NOFAIL_ENABLED(item->fsManagerFlags)) { BEGET_LOGE("Mount no fail device %s to %s failed, err = %d", item->deviceName, item->mountPoint, errno); @@ -814,7 +867,7 @@ int MountAllWithFstab(const Fstab *fstab, bool required) break; } } - + UpdataAndCheckVabMountInfo(NULL, 0); #ifdef SUPPORT_HVB if (required) HvbDmVerityFinal(); diff --git a/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c index 2caf57bf6030e67566525224d421a6325460db5b..c9528c0ba61dad35b6023b6ac786a13bf965e41a 100755 --- a/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c +++ b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c @@ -99,7 +99,6 @@ int LoadDmDeviceTable(int fd, const char *devName, DmVerityTarget *target, int d BEGET_LOGE("dmTypeIdx error dmTypeIdx %d", dmTypeIdx); return -1; } - parasTotalSize = DM_ALIGN(sizeof(*io) + sizeof(*ts) + target->paras_len + 1); parasBuf = calloc(1, parasTotalSize); if (parasBuf == NULL) { @@ -362,7 +361,7 @@ int DmGetDeviceName(int fd, const char *devName, char *outDevName, const uint64_ path = calloc(1, pathLen); if (path == NULL) { BEGET_LOGE("calloc path failed"); - return -1; + return rc; } rc = snprintf_s(path, pathLen, pathLen - 1, "%s%d", DM_DEVICE_PATH_PREFIX, devNum); @@ -445,8 +444,6 @@ bool GetDmStatusInfo(const char *name, struct dm_ioctl *io) close(fd); return true; } - - #ifdef __cplusplus #if __cplusplus } diff --git a/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_linear.c b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_linear.c index fe97cdee302ead9d29d63cc30b9808a72c703185..e1aceebf59c289d1d35ace3d2ff8c513434cdda2 100644 --- a/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_linear.c +++ b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_linear.c @@ -1,17 +1,17 @@ /* -* 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. -*/ + * 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 @@ -38,7 +38,6 @@ static int LoadDmLinearDeviceTable(int fd, const char *devName, DmLinearTarget * for (uint32_t index = 0; index < targetNum; index++) { parasTotalSize += target[index].paras_len + 1; } - char *parasBuf = calloc(1, parasTotalSize); BEGET_ERROR_CHECK(parasBuf != NULL, return -1, "error, calloc dm table fail"); io = (struct dm_ioctl *)parasBuf; @@ -51,12 +50,15 @@ static int LoadDmLinearDeviceTable(int fd, const char *devName, DmLinearTarget * uint32_t len = 0; char *paras = NULL; do { - FS_DM_RETURN_ERR_IF_NULL(target[i].paras); + if (target[i].paras == NULL) { + BEGET_LOGE("error, target[%u].paras is NULL", i); + free(parasBuf); + return -1; + } ts = (struct dm_target_spec *)(parasBuf + sizeof(*io) + len); ts->status = 0; ts->sector_start = target[i].start; ts->length = target[i].length; - rc = strcpy_s(ts->target_type, sizeof(ts->target_type), "linear"); BEGET_ERROR_CHECK(rc == EOK, free(parasBuf); return -1, "error %d, cp target type", rc); len += sizeof((*ts)); @@ -97,7 +99,6 @@ int FsDmCreateMultiTargetLinearDevice(const char *devName, char *dmDevPath, uint } int rc = 0; - do { rc = CreateDmDev(fd, devName); if (rc != 0) { @@ -120,10 +121,8 @@ int FsDmCreateMultiTargetLinearDevice(const char *devName, char *dmDevPath, uint BEGET_LOGE("active dm device name failed"); break; } - BEGET_LOGI("fs create linear device success, dev is [%s] dmDevPath is [%s]", devName, dmDevPath); } while (0); - close(fd); return rc; } @@ -146,19 +145,18 @@ int FsDmSwitchToLinearDevice(const char *devName, DmLinearTarget *target, uint32 } int rc = 0; - do { rc = LoadDmLinearDeviceTable(fd, devName, target, targetNum); if (rc != 0) { BEGET_LOGE("load dm device name failed"); break; } + rc = ActiveDmDevice(fd, devName); if (rc != 0) { BEGET_LOGE("active dm device name failed"); break; } - BEGET_LOGI("fs switch linear device success, dev is [%s]", devName); } while (0); diff --git a/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_snapshot.c b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_snapshot.c index 8c0fc48c93e24694a527d1210bc9b06db6abdb56..591bb4cf8ca8f37348bc9e53d15c1cc8b9c462bd 100644 --- a/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_snapshot.c +++ b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_snapshot.c @@ -1,17 +1,18 @@ /* -* 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. -*/ + * 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 @@ -35,11 +36,13 @@ int FsDmCreateSnapshotDevice(const char *devName, char *dmDevPath, uint64_t dmDe BEGET_LOGE("argc is null"); return -1; } + int fd = open(DEVICE_MAPPER_PATH, O_RDWR | O_CLOEXEC); if (fd < 0) { BEGET_LOGE("error %d, open %s", errno, DEVICE_MAPPER_PATH); return -1; } + int rc = 0; do { rc = CreateDmDev(fd, devName); @@ -47,23 +50,23 @@ int FsDmCreateSnapshotDevice(const char *devName, char *dmDevPath, uint64_t dmDe BEGET_LOGE("error %d, create dm device fail", rc); break; } + rc = LoadDmDeviceTable(fd, devName, target, SNAPSHOT); if (rc != 0) { BEGET_LOGE("error %d, load device table fail", rc); break; } + rc = ActiveDmDevice(fd, devName); if (rc != 0) { BEGET_LOGE("error %d, active device fail", rc); break; } - rc = DmGetDeviceName(fd, devName, dmDevPath, dmDevPathLen); if (rc != 0) { BEGET_LOGE("get dm device name failed"); break; } - BEGET_LOGI("fs create snapshot device success, dev is [%s] dmDevPath is [%s]", devName, dmDevPath); } while (0); close(fd); @@ -81,6 +84,7 @@ int FsDmSwitchToSnapshotMerge(const char *devName, DmSnapshotTarget *target) BEGET_LOGE("error %d, open %s", errno, DEVICE_MAPPER_PATH); return -1; } + int rc = 0; do { rc = LoadDmDeviceTable(fd, devName, target, SNAPSHOTMERGE); @@ -95,6 +99,7 @@ int FsDmSwitchToSnapshotMerge(const char *devName, DmSnapshotTarget *target) } BEGET_LOGI("fs switch snapshot merge success, dev is %s", devName); } while (0); + close(fd); return rc; } @@ -125,17 +130,17 @@ INIT_STATIC bool ParseStatusText(char *data, StatusInfo *processInfo) BEGET_LOGW("processInfo->error is \"%s\"", processInfo->error); return true; } - BEGET_LOGE("could not parse snapshot processInfo \"%s\": wrong format", processInfo->error); + BEGET_LOGE("could not parse snapshot processInfo: wrong format \"%s\"", processInfo->error); return false; } bool GetDmSnapshotStatus(const char *name, const char *targetType, StatusInfo *processInfo) { - if (name == NULL || targetType == NULL || processInfo == NULL) { + BEGET_LOGI("GetDmSnapshotStatus start, name %s, targetType %s", name, targetType); + if (name == NULL || processInfo == NULL) { BEGET_LOGE("argc is null"); return false; } - BEGET_LOGI("GetDmSnapshotStatus start, name %s, targetType %s", name, targetType); size_t bufferLen = MAX_TABLE_LEN * sizeof(char); int fd = open(DEVICE_MAPPER_PATH, O_RDWR | O_CLOEXEC); BEGET_ERROR_CHECK(fd >= 0, return false, "open error %d", errno); diff --git a/interfaces/innerkits/include/fs_manager/fs_manager.h b/interfaces/innerkits/include/fs_manager/fs_manager.h index 55a5f2d9ba049203d31dfa531c760f22e3898351..dd437e657128272a10c068b86eb92e4c9f2feb7c 100644 --- a/interfaces/innerkits/include/fs_manager/fs_manager.h +++ b/interfaces/innerkits/include/fs_manager/fs_manager.h @@ -65,6 +65,18 @@ typedef enum MountStatus { MOUNT_MOUNTED = 1, } MountStatus; +typedef enum SlotStatus { + SLOTSTATUS_INIT = 0, + SLOTSTATUS_VAB, + SLOTSTATUS_OTHER, +} SlotStatus; + +typedef struct VabMountInfo { + char *deviceName; + char *fsType; + int result; +} VabMountInfo; + typedef struct FstabItem { char *deviceName; // Block device name char *mountPoint; // Mount point diff --git a/interfaces/innerkits/include/init_utils.h b/interfaces/innerkits/include/init_utils.h index 87f350064c5b5cf764081455035b1f6cd083fe49..c44bba4e4cef4e83b778e558a22ed4e85b4cc5d7 100644 --- a/interfaces/innerkits/include/init_utils.h +++ b/interfaces/innerkits/include/init_utils.h @@ -63,10 +63,6 @@ typedef struct { #define ARRAY_LENGTH(array) (sizeof((array)) / sizeof((array)[0])) #define BOOT_CMD_LINE STARTUP_INIT_UT_PATH"/proc/cmdline" -#define FIRST_VALUE "First_Value" // 取第一个匹配值 -#define LAST_VALUE "Last_Value" // 取最后一个匹配值 -#define EMPTY_VALUE "EMPTY_VALUE" // 不取任何一个 - #ifndef OHOS_LITE void SetBootCompleted(bool isBootCompleted); bool IsBootCompleted(void); diff --git a/interfaces/innerkits/include/syspara/parameter.h b/interfaces/innerkits/include/syspara/parameter.h index bb6671dedeb5d5420b851016b99ca74a333d5a85..916776cf83b894f5989665c4bb47b9ab9fd5ba16 100644 --- a/interfaces/innerkits/include/syspara/parameter.h +++ b/interfaces/innerkits/include/syspara/parameter.h @@ -192,6 +192,8 @@ long long GetSystemCommitId(void); int32_t GetIntParameter(const char *key, int32_t def); uint32_t GetUintParameter(const char *key, uint32_t def); +const char *GetChipType(void); +int GetBootCount(void); const char *GetDistributionOSName(void); const char *GetDistributionOSVersion(void); int GetDistributionOSApiVersion(void); diff --git a/interfaces/innerkits/init_module_engine/include/bootstage.h b/interfaces/innerkits/init_module_engine/include/bootstage.h index c9aa37863ccd778835f71ffbd6f96f3c390e18b8..1703df338d49f1e2715139fd20e08961ed4f8fe1 100755 --- a/interfaces/innerkits/init_module_engine/include/bootstage.h +++ b/interfaces/innerkits/init_module_engine/include/bootstage.h @@ -34,6 +34,7 @@ enum INIT_BOOTSTAGE { INIT_SNAPSHOT_ACTIVE = 6, INIT_DISABLE_CHECKPOINT = 7, INIT_HEALTH_CHECK_ACTIVE = 8, + INIT_CHECK_VAB_MOUNTINFO = 9, INIT_PRE_PARAM_SERVICE = 10, INIT_VAB_HVBCHECK = 11, INIT_PRE_PARAM_LOAD = 20, diff --git a/interfaces/innerkits/init_module_engine/stub/libinit.stub.json b/interfaces/innerkits/init_module_engine/stub/libinit.stub.json index 69d05327b7787968f9ef6a7d3a87d3e7cac4d78b..0d2704d558bc6eb7709ac6b1a051c9772c7038f8 100644 --- a/interfaces/innerkits/init_module_engine/stub/libinit.stub.json +++ b/interfaces/innerkits/init_module_engine/stub/libinit.stub.json @@ -6,7 +6,6 @@ { "name": "LoadPersistParams" }, { "name": "SplitString" }, { "name": "AddCmdExecutor" }, - { "name": "GetServiceByName"}, { "name": "RemoveCmdExecutor" }, { "name": "HookMgrAdd" }, { "name": "HookMgrAddEx" }, @@ -24,6 +23,7 @@ { "name": "StartupLog" }, { "name": "DoJobNow" }, { "name": "GetServiceExtData" }, + { "name": "GetServiceByName"}, { "name": "UpdateMiscMessage" }, { "name": "AddRebootCmdExecutor" }, { "name": "GetBootEventList" }, diff --git a/interfaces/innerkits/libbegetutil.versionscript b/interfaces/innerkits/libbegetutil.versionscript index 2654833e415a69d9458f3c526e6ce541ae73acb4..a5c356c66eaa59dc1afabd0168d23d31ae91e836 100644 --- a/interfaces/innerkits/libbegetutil.versionscript +++ b/interfaces/innerkits/libbegetutil.versionscript @@ -98,6 +98,7 @@ *GetStringParameter*; FindParameter; GetAbiList; + GetBootCount; GetBootloaderVersion; GetBrand; GetBuildHost; @@ -105,6 +106,7 @@ GetBuildTime; GetBuildType; GetBuildUser; + GetChipType; GetDevUdid; GetDisplayVersion; GetFirstApiVersion; diff --git a/interfaces/innerkits/syspara/param_comm.c b/interfaces/innerkits/syspara/param_comm.c index 8591bc8d5d7cfffac4c761fee3ad45ba5ed94537..c132fcaa227a83e5466cfb82dcb613e871d493bf 100644 --- a/interfaces/innerkits/syspara/param_comm.c +++ b/interfaces/innerkits/syspara/param_comm.c @@ -77,7 +77,7 @@ INIT_LOCAL_API int GetParameter_(const char *key, const char *def, char *value, if (def == NULL) { return GetSystemError(ret); } - if (strlen(def) > len) { + if (strlen(def) >= len) { return EC_INVALID; } ret = strcpy_s(value, len, def); @@ -135,11 +135,7 @@ INIT_LOCAL_API const char *GetPropertyAtomic(const char *key, const char **param BEGET_CHECK(res != NULL, return NULL); ret = SystemGetParameter(key, res, &len); - if (ret != 0) { - free(res); - return NULL; - } - + BEGET_CHECK(ret == 0, free(res); return NULL); if (g_propertyGetProcessor != NULL) { res = g_propertyGetProcessor(key, res); } diff --git a/interfaces/innerkits/syspara/parameter.c b/interfaces/innerkits/syspara/parameter.c index e6108cf4a4d26dce240a320ccb5fbf53f4184c2f..ec6e0d8a5dd46456ce546350179192866b485de8 100644 --- a/interfaces/innerkits/syspara/parameter.c +++ b/interfaces/innerkits/syspara/parameter.c @@ -17,7 +17,6 @@ #include #include -#include #include "param_comm.h" #include "init_param.h" @@ -464,3 +463,14 @@ int GetPerformanceClass(void) } return performanceClassValue; } + +const char *GetChipType(void) +{ + static const char *chiptype = NULL; + return GetProperty("ohos.boot.hardware", &chiptype); +} + +int GetBootCount(void) +{ + return GetIntParameter("persist.startup.bootcount", -1); +} \ No newline at end of file diff --git a/interfaces/kits/jskits/src/native_deviceinfo_js.cpp b/interfaces/kits/jskits/src/native_deviceinfo_js.cpp index e14503e073189018fb7b3a3ef0be03a8b7c3375a..6e97462e438df1b74f9c502d9e90f856d47ea755 100644 --- a/interfaces/kits/jskits/src/native_deviceinfo_js.cpp +++ b/interfaces/kits/jskits/src/native_deviceinfo_js.cpp @@ -419,6 +419,26 @@ static napi_value GetBuildRootHash(napi_env env, napi_callback_info info) return napiValue; } +static napi_value GetBootCount(napi_env env, napi_callback_info info) +{ + napi_value napiValue = nullptr; + int bootCount = GetBootCount(); + NAPI_CALL(env, napi_create_int32(env, bootCount, &napiValue)); + return napiValue; +} + +static napi_value GetChipType(napi_env env, napi_callback_info info) +{ + napi_value napiValue = nullptr; + const char *chipType = GetChipType(); + if (chipType == nullptr) { + chipType = ""; + } + + NAPI_CALL(env, napi_create_string_utf8(env, chipType, strlen(chipType), &napiValue)); + return napiValue; +} + static napi_value GetDevUdid(napi_env env, napi_callback_info info) { napi_value napiValue = nullptr; @@ -535,6 +555,40 @@ static napi_value GetDiskSN(napi_env env, napi_callback_info info) return napiValue; } +static napi_value CreateDeviceTypes(napi_env env, napi_value exports) +{ + napi_value deviceTypes = nullptr; + napi_value typeDefault = nullptr; + napi_value typePhone = nullptr; + napi_value typeTablet = nullptr; + napi_value type2in1 = nullptr; + napi_value typeTv = nullptr; + napi_value typeWearable = nullptr; + napi_value typeCar = nullptr; + + napi_create_object(env, &deviceTypes); + + napi_create_string_utf8(env, "default", NAPI_AUTO_LENGTH, &typeDefault); + napi_create_string_utf8(env, "phone", NAPI_AUTO_LENGTH, &typePhone); + napi_create_string_utf8(env, "tablet", NAPI_AUTO_LENGTH, &typeTablet); + napi_create_string_utf8(env, "2in1", NAPI_AUTO_LENGTH, &type2in1); + napi_create_string_utf8(env, "tv", NAPI_AUTO_LENGTH, &typeTv); + napi_create_string_utf8(env, "wearable", NAPI_AUTO_LENGTH, &typeWearable); + napi_create_string_utf8(env, "car", NAPI_AUTO_LENGTH, &typeCar); + + napi_set_named_property(env, deviceTypes, "TYPE_DEFAULT", typeDefault); + napi_set_named_property(env, deviceTypes, "TYPE_PHONE", typePhone); + napi_set_named_property(env, deviceTypes, "TYPE_TABLET", typeTablet); + napi_set_named_property(env, deviceTypes, "TYPE_2IN1", type2in1); + napi_set_named_property(env, deviceTypes, "TYPE_TV", typeTv); + napi_set_named_property(env, deviceTypes, "TYPE_WEARABLE", typeWearable); + napi_set_named_property(env, deviceTypes, "TYPE_CAR", typeCar); + + napi_set_named_property(env, exports, "DeviceTypes", deviceTypes); + + return exports; +} + static napi_value EnumLevelClassConstructor(napi_env env, napi_callback_info info) { napi_value thisArg = nullptr; @@ -582,40 +636,6 @@ static napi_value GetPerformanceClass(napi_env env, napi_callback_info info) return napiValue; } -static napi_value CreateDeviceTypes(napi_env env, napi_value exports) -{ - napi_value deviceTypes = nullptr; - napi_value typeDefault = nullptr; - napi_value typePhone = nullptr; - napi_value typeTablet = nullptr; - napi_value type2in1 = nullptr; - napi_value typeTv = nullptr; - napi_value typeWearable = nullptr; - napi_value typeCar = nullptr; - - napi_create_object(env, &deviceTypes); - - napi_create_string_utf8(env, "default", NAPI_AUTO_LENGTH, &typeDefault); - napi_create_string_utf8(env, "phone", NAPI_AUTO_LENGTH, &typePhone); - napi_create_string_utf8(env, "tablet", NAPI_AUTO_LENGTH, &typeTablet); - napi_create_string_utf8(env, "2in1", NAPI_AUTO_LENGTH, &type2in1); - napi_create_string_utf8(env, "tv", NAPI_AUTO_LENGTH, &typeTv); - napi_create_string_utf8(env, "wearable", NAPI_AUTO_LENGTH, &typeWearable); - napi_create_string_utf8(env, "car", NAPI_AUTO_LENGTH, &typeCar); - - napi_set_named_property(env, deviceTypes, "TYPE_DEFAULT", typeDefault); - napi_set_named_property(env, deviceTypes, "TYPE_PHONE", typePhone); - napi_set_named_property(env, deviceTypes, "TYPE_TABLET", typeTablet); - napi_set_named_property(env, deviceTypes, "TYPE_2IN1", type2in1); - napi_set_named_property(env, deviceTypes, "TYPE_TV", typeTv); - napi_set_named_property(env, deviceTypes, "TYPE_WEARABLE", typeWearable); - napi_set_named_property(env, deviceTypes, "TYPE_CAR", typeCar); - - napi_set_named_property(env, exports, "DeviceTypes", deviceTypes); - - return exports; -} - EXTERN_C_START /* * Module init @@ -671,6 +691,8 @@ static napi_value Init(napi_env env, napi_value exports) {"productModelAlias", nullptr, nullptr, GetProductModelAlias, nullptr, nullptr, napi_default, nullptr}, {"diskSN", nullptr, nullptr, GetDiskSN, nullptr, nullptr, napi_default, nullptr}, {"performanceClass", nullptr, nullptr, GetPerformanceClass, nullptr, nullptr, napi_default, nullptr}, + {"chipType", nullptr, nullptr, GetChipType, nullptr, nullptr, napi_default, nullptr}, + {"bootCount", nullptr, nullptr, GetBootCount, nullptr, nullptr, napi_default, nullptr}, }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc)); diff --git a/interfaces/taihe/BUILD.gn b/interfaces/taihe/BUILD.gn index 74433019dbd065ff61c2faca4df51814f04b56ba..8bb20df00efa94f938598d8c1337ca1936a3cf46 100644 --- a/interfaces/taihe/BUILD.gn +++ b/interfaces/taihe/BUILD.gn @@ -17,6 +17,8 @@ group("taihe_group") { deps = [ "deviceInfo:deviceInfo_etc", "deviceInfo:deviceInfo_taihe_native", + "syscap:global_etc", + "syscap:global_taihe_native", "systemParameterEnhance:systemParamterEnhance_etc", "systemParameterEnhance:systemParameterEnhance_taihe_native", ] diff --git a/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe index 4315fe600877fd8ced910ab94a42dcd38aa886b6..df8e87eecf09d75f54d60e78dec18a87ddb8312d 100644 --- a/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe +++ b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe @@ -81,6 +81,8 @@ function getdistributionOSApiName(): String; function getdistributionOSReleaseType(): String; @static("deviceInfo") @get function getdiskSN(): String; +@static("deviceInfo") @get +function getchipType(): String; @static("deviceInfo") @get function getsdkApiVersion(): i32; @@ -95,4 +97,6 @@ function getbuildVersion(): i32; @static("deviceInfo") @get function getfirstApiVersion(): i32; @static("deviceInfo") @get -function getdistributionOSApiVersion(): i32; \ No newline at end of file +function getdistributionOSApiVersion(): i32; +@static("deviceInfo") @get +function getbootCount(): i32; \ No newline at end of file diff --git a/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp index b4a75a590dd4d690118aa7c23e1a9009a696110b..16bb09cbf74c7484f1f04cd4d2dfb69eebf4f475 100644 --- a/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp +++ b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp @@ -369,6 +369,15 @@ string getdiskSN() return value; } +string getchipType() +{ + const char *value = GetChipType(); + if (value == nullptr) { + value = ""; + } + return value; +} + int32_t getsdkApiVersion() { int value = GetSdkApiVersion(); @@ -410,6 +419,12 @@ int32_t getdistributionOSApiVersion() int value = GetDistributionOSApiVersion(); return value; } + +int32_t getbootCount() +{ + int value = GetBootCount(); + return value; +} } // namespace TH_EXPORT_CPP_API_getbrand(getbrand); @@ -449,3 +464,5 @@ TH_EXPORT_CPP_API_getfeatureVersion(getfeatureVersion); TH_EXPORT_CPP_API_getbuildVersion(getbuildVersion); TH_EXPORT_CPP_API_getfirstApiVersion(getfirstApiVersion); TH_EXPORT_CPP_API_getdistributionOSApiVersion(getdistributionOSApiVersion); +TH_EXPORT_CPP_API_getbootCount(getbootCount); +TH_EXPORT_CPP_API_getchipType(getchipType); \ No newline at end of file diff --git a/interfaces/taihe/syscap/BUILD.gn b/interfaces/taihe/syscap/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..28f17de59909c9c500b9532f48c768741c8584f1 --- /dev/null +++ b/interfaces/taihe/syscap/BUILD.gn @@ -0,0 +1,69 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//base/startup/init/begetd.gni") +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") + +copy_taihe_idl("copy_global") { + sources = [ "idl/internal.full.global.taihe" ] +} +subsystem_name = "startup" +part_name = "init" +taihe_generated_file_path_global = "$taihe_file_path/out/$subsystem_name/$part_name/global" + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path_global" + deps = [ ":copy_global" ] + outputs = [ + "$taihe_generated_file_path/src/internal.full.global.ani.cpp", + "$taihe_generated_file_path/src/internal.full.global.abi.c", + ] +} + +taihe_shared_library("global_taihe_native") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + taihe_generated_file_path = "$taihe_generated_file_path_global" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + include_dirs = [ "${init_innerkits_path}/include" ] + sources += [ + "src/ani_constructor.cpp", + "src/internal.full.global.impl.cpp", + ] + deps = [ + ":run_taihe", + "${init_innerkits_path}:libbegetutil", + ] +} + +generate_static_abc("global") { + base_url = "$taihe_generated_file_path_global" + files = [ "$taihe_generated_file_path_global/@internal.full.global.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/global.abc" + dependencies = [ ":run_taihe" ] +} + +ohos_prebuilt_etc("global_etc") { + source = "$target_out_dir/global.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":global" ] +} diff --git a/interfaces/taihe/syscap/idl/internal.full.global.taihe b/interfaces/taihe/syscap/idl/internal.full.global.taihe new file mode 100644 index 0000000000000000000000000000000000000000..cafb2b150b3b24adf6826ba3409a6995034d58aa --- /dev/null +++ b/interfaces/taihe/syscap/idl/internal.full.global.taihe @@ -0,0 +1,20 @@ +/* + * 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. + */ + @!namespace("@internal.full.global") + + @!sts_inject(""" + loadLibrary("global_taihe_native.z") + """) + function canIUse(syscap: String): bool; \ No newline at end of file diff --git a/interfaces/taihe/syscap/src/ani_constructor.cpp b/interfaces/taihe/syscap/src/ani_constructor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d73d3eafc7442bf8064c2bc308449c69bc44ade --- /dev/null +++ b/interfaces/taihe/syscap/src/ani_constructor.cpp @@ -0,0 +1,36 @@ +/* + * 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 "taihe.platform.ani.ani.hpp" +#include "internal.full.global.ani.hpp" +#if __has_include() +#include +#elif __has_include() +#include +#else +#error "ani.h not found, Please ensure the Ani SDK is correctly installed." +#endif +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != internal::full::global::ANIRegister(env)) { + std::cerr << "Error from internal::full::global::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} diff --git a/interfaces/taihe/syscap/src/internal.full.global.impl.cpp b/interfaces/taihe/syscap/src/internal.full.global.impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eadaf687f1c46660347517c0127e067572e03910 --- /dev/null +++ b/interfaces/taihe/syscap/src/internal.full.global.impl.cpp @@ -0,0 +1,33 @@ +/* + * 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 "internal.full.global.proj.hpp" +#include "internal.full.global.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" +#include "systemcapability.h" +#include "beget_ext.h" + +using namespace taihe; +namespace { +// To be implemented. + +bool canIUse(string_view syscap) +{ + bool ret = HasSystemCapability(std::string(syscap).c_str()); + return ret; +} +} //namespace + +TH_EXPORT_CPP_API_canIUse(canIUse); \ No newline at end of file diff --git a/services/etc/init.usb.cfg b/services/etc/init.usb.cfg index d28b2adf6b7940ca0d007d256a8d188a10c8c538..45bba53459de70c9120307557d591a2b97fc4fc2 100755 --- a/services/etc/init.usb.cfg +++ b/services/etc/init.usb.cfg @@ -14,6 +14,14 @@ "cmds" : [ "stop hdcd" ] + }, { + "name" : "init", + "cmds" : [ + "mkdir /dev/bus 0755 ueventd root", + "mkdir /dev/bus/usb 0755 ueventd root", + "mkdir /dev/bus/usb/001 0755 ueventd root", + "mkdir /dev/bus/usb/002 0755 ueventd root" + ] } ] } diff --git a/services/etc/param/ohos.para b/services/etc/param/ohos.para index 2383c69645341a39c82643d6069a11234ebf0496..8d26b3f69ec0ef533fe4dbe695cba57d6ecae81b 100755 --- a/services/etc/param/ohos.para +++ b/services/etc/param/ohos.para @@ -29,7 +29,7 @@ const.build.product=default const.product.hardwareversion=default const.product.bootloader.version=bootloader const.product.cpu.abilist=default -const.product.software.version=OpenHarmony 6.0.0.46 +const.product.software.version=OpenHarmony 6.0.0.48 const.product.incremental.version=default const.product.firstapiversion=1 const.product.build.type=default @@ -38,3 +38,4 @@ const.product.build.host=default const.product.build.date=default const.product.hardwareprofile=default const.ohos.buildroothash=default +persist.startup.bootcount=0 diff --git a/services/etc/param/ohos_const/ohos.para b/services/etc/param/ohos_const/ohos.para index 567680ba3738861d11e666f0845c40f3d1d8582b..0b11511e132aa4a6f4049d630f0533ca6ce6a6d9 100755 --- a/services/etc/param/ohos_const/ohos.para +++ b/services/etc/param/ohos_const/ohos.para @@ -15,4 +15,4 @@ const.ohos.releasetype=Beta2 const.ohos.apiversion=20 const.ohos.apiminorversion=0 const.ohos.apipatchversion=0 -const.ohos.fullname=OpenHarmony-6.0.0.46 \ No newline at end of file +const.ohos.fullname=OpenHarmony-6.0.0.48 \ No newline at end of file diff --git a/services/etc_lite/param/ohos_const/ohos.para b/services/etc_lite/param/ohos_const/ohos.para index d179dd714e4db10697c508cda0201c8f23e5614f..564a71600f95e1aecfedbc599d76eba03237efa1 100755 --- a/services/etc_lite/param/ohos_const/ohos.para +++ b/services/etc_lite/param/ohos_const/ohos.para @@ -16,4 +16,4 @@ const.ohos.apiversion=20 const.ohos.apiminorversion=0 const.ohos.apipatchversion=0 const.ohos.version.security_patch=2025/08/01 -const.ohos.fullname=OpenHarmony-6.0.0.46 \ No newline at end of file +const.ohos.fullname=OpenHarmony-6.0.0.48 \ No newline at end of file diff --git a/services/init/lite/BUILD.gn b/services/init/lite/BUILD.gn index e587b521a57b26ffda6f15999990a33824eb2897..2a4c41adf1c479d02e28cceb39c6bca845ebf865 100644 --- a/services/init/lite/BUILD.gn +++ b/services/init/lite/BUILD.gn @@ -55,7 +55,6 @@ executable("init") { "//base/startup/init/interfaces/innerkits/include/param", "//base/startup/init/services/init/include", "//third_party/cJSON", - "//base/hiviewdfx/hilog_lite/interfaces/native/kits", ] ldflags = [] diff --git a/services/modules/bootevent/bootevent.c b/services/modules/bootevent/bootevent.c index 89b4e230cbf5e736b3793e4767c3ed71b2c60351..c896169baacc9e56433fc02c46ffcd9c6b9cf70c 100755 --- a/services/modules/bootevent/bootevent.c +++ b/services/modules/bootevent/bootevent.c @@ -346,6 +346,25 @@ static int ScheduleDelayedHookMgrExecute(void) } #endif +void UpdateBootCount() +{ + char timevalue[MAX_BUFFER_LEN] = {0}; + uint32_t size = sizeof(timevalue); + int ret = SystemReadParam("ohos.boot.time.boot.completed", timevalue, &size); + INIT_INFO_CHECK (ret != 0, return, "already boot, not add count"); + char value[MAX_INT_LEN] = {0}; + size = sizeof(value); + ret = SystemReadParam("persist.startup.bootcount", value, &size); + INIT_ERROR_CHECK (ret == 0, return, "Failed to read bootcount"); + int bootCount = StringToInt(value, -1); + INIT_ERROR_CHECK (bootCount != -1, return, "StringToInt failed"); + bootCount++; + char buffer[32] = { 0 }; + ret = sprintf_s(buffer, sizeof(buffer), "%d", bootCount); + INIT_ERROR_CHECK (ret > 0, return, "Failed copy bootcount"); + ret = SystemWriteParam("persist.startup.bootcount", buffer); + INIT_CHECK_ONLY_ELOG(ret == 0, "Failed to update bootcount"); +} static int BootEventParaFireByName(const char *paramName) { @@ -377,6 +396,7 @@ static int BootEventParaFireByName(const char *paramName) } // All parameters are fired, set boot completed now ... INIT_LOGI("All boot events are fired, boot complete now ..."); + UpdateBootCount(); SystemWriteParam(BOOT_EVENT_BOOT_COMPLETED, "true"); SetBootCompleted(true); SaveServiceBootEvent(); diff --git a/services/modules/bootevent/bootevent.h b/services/modules/bootevent/bootevent.h index 9bce4b7d783015292b869561c3f267cb120fbaad..a427d735a1f3b0d9c612c407caa741644519c659 100755 --- a/services/modules/bootevent/bootevent.h +++ b/services/modules/bootevent/bootevent.h @@ -54,6 +54,7 @@ typedef struct tagBOOT_EVENT_PARAM_ITEM { } BOOT_EVENT_PARAM_ITEM; ListNode *GetBootEventList(void); +void UpdateBootCount(void); #ifdef __cplusplus #if __cplusplus diff --git a/services/modules/trace/init_trace.c b/services/modules/trace/init_trace.c index d6fcc6a622d6c6942c94817ed5039454accd8c05..109ea32a76cad005218c46f3f04e1e02eb21c0ef 100644 --- a/services/modules/trace/init_trace.c +++ b/services/modules/trace/init_trace.c @@ -304,7 +304,7 @@ static void CheckKernelType(bool *isLinux) { struct utsname uts; if (uname(&uts) == -1) { - PLUGIN_LOGE("Kernel type get failed,errno:d", errno); + PLUGIN_LOGE("Kernel type get failed,errno:%d", errno); return; } diff --git a/services/param/adapter/param_persistadp.c b/services/param/adapter/param_persistadp.c index 7dba4798c8ccaecc8c0d0a9f95e4fc833841d34f..dc5da1145fbe63af485cc20ffadae0e803c6e714 100644 --- a/services/param/adapter/param_persistadp.c +++ b/services/param/adapter/param_persistadp.c @@ -95,7 +95,7 @@ static bool IsPublicParam(const char *param) "persist.sys.usb.config", "persist.sys.xlog.debug", "persist.telephony", "persist.time", "persist.uiAppearance.first_initialization", "persist.update", - "persist.wifi", "persist.init.trace.enabled", + "persist.wifi", "persist.init.trace.enabled", "persist.startup.bootcount", }; int size = sizeof(publicPersistParams) / sizeof(char*); for (int i = 0; i < size; i++) { @@ -164,7 +164,11 @@ static bool GetPersistFilePath(char **path, char **tmpPath, int fileType) PARAM_LOGE("rename failed %s", PARAM_OLD_PERSIST_SAVE_PATH); } } else { - CheckAndCreateDir(PARAM_PRIVATE_PERSIST_SAVE_PATH); + if (access(PUBLIC_DIR, F_OK) == 0) { + CheckAndCreateDir(PARAM_PRIVATE_PERSIST_SAVE_PATH); + } else { + PARAM_LOGE("public dir not exit, creat param file fail"); + } } *path = PARAM_PRIVATE_PERSIST_SAVE_PATH; *tmpPath = PARAM_PRIVATE_PERSIST_SAVE_TMP_PATH; diff --git a/services/param/include/param_utils.h b/services/param/include/param_utils.h index 63f03e55aafedd99bf51fadb6f952feab79ce2eb..5cab8b711ea22b870469dae0d631f896784d6037 100644 --- a/services/param/include/param_utils.h +++ b/services/param/include/param_utils.h @@ -87,6 +87,7 @@ typedef enum { #define PARAM_PUBLIC_PERSIST_SAVE_TMP_PATH DATA_PATH "tmp_public_persist_parameters" #define PARAM_PRIVATE_PERSIST_SAVE_PATH PRIVATE_DATA_PATH "private_persist_parameters" #define PARAM_PRIVATE_PERSIST_SAVE_TMP_PATH PRIVATE_DATA_PATH "tmp_private_persist_parameters" +#define PUBLIC_DIR "/data/service/el1/public" #define PERSIST_HANDLE_MAX 2 #define WORKSPACE_FLAGS_INIT 0x01 diff --git a/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0500.json b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0500.json new file mode 100644 index 0000000000000000000000000000000000000000..d5aa6b8ae9c42c5d526d34ae6f72d71010c79d7e --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0500.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_ability_up/SubStartupInitAbilityUp0500.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0500.py b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0500.py new file mode 100644 index 0000000000000000000000000000000000000000..1085df5cd370d97fabf5316c0c264769c46a3431 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0500.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from time import sleep +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + + +class SubStartupInitAbilityUp0500(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("预置工作:初始化手机/pc开始.................") + Step(self.devices[0].device_id) + + def test_step1(self): + Step("重命名系统文件param_watcher.cfg..........................") + self.driver.hdc("target mount") + self.driver.shell( + "cp /system/etc/init/param_watcher.cfg /system/etc/init/param_watcher.cfg_bak") + Step("把系统文件param_watcher.cfg拉到本地..........................") + devpath = "/system/etc/init/param_watcher.cfg" + self.driver.pull_file(devpath, "testFile/sub_startup_init_ability_up/param_watcher.cfg") + Step("修改本地系统文件..........................") + lines1 = [] + path2 = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), + "testFile\sub_startup_init_ability_up") + local_path = os.path.join(path2, "param_watcher.cfg") + with open(local_path, "r") as y: + for line in y: + lines1.append(line) + y.close() + Step(lines1) + line = lines1.index(' "services" : [{\n') + 1 + path3 = '\t\t\t"importance" : 100,\n' + lines1.insert(line, path3) + s = ''.join(lines1) + Step(s) + with open(local_path, "w") as z: + z.write(s) + z.close() + Step("上传修改后的本地系统文件..........................") + self.driver.push_file(local_path, devpath) + Step("执行重启..........................") + self.driver.System.reboot() + sleep(3) + Step("执行命令begetctl dump_service..........................") + result = self.driver.shell('begetctl dump_service param_watcher') + Step(result) + pid = self.driver.System.get_pid('param_watcher') + Step(pid) + + def teardown(self): + Step("收尾工作.................") + Step("恢复系统文件param_watcher.cfg..........................") + self.driver.hdc("target mount") + self.driver.shell("rm -rf /system/etc/init/param_watcher.cfg") + self.driver.shell( + "mv /system/etc/init/param_watcher.cfg_bak /system/etc/init/param_watcher.cfg") + Step("执行重启..........................") + self.driver.System.reboot() + sleep(3) + self.driver.System.wait_for_boot_complete() diff --git a/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0600.json b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0600.json new file mode 100644 index 0000000000000000000000000000000000000000..c56c57c0314b8652c4131feadfb8097473d81406 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0600.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_ability_up/SubStartupInitAbilityUp0600.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0600.py b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0600.py new file mode 100644 index 0000000000000000000000000000000000000000..374f81c2990b49fa430f6e5bd7844a7365ab1289 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0600.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from time import sleep +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + + +class SubStartupInitAbilityUp0600(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) + + def test_step1(self): + Step("重命名系统文件wifi_standard.cfg..........................") + self.driver.hdc("target mount") + self.driver.shell( + "cp /system/etc/init/wifi_standard.cfg /system/etc/init/wifi_standard.cfg_bak") + Step("把系统文件wifi_standard.cfg拉到本地..........................") + devpath = "/system/etc/init/wifi_standard.cfg" + self.driver.pull_file(devpath, "testFile/sub_startup_init_ability_up/wifi_standard.cfg") + Step("修改本地系统文件..........................") + lines1 = [] + path2 = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), + "testFile\sub_startup_init_ability_up") + local_path = os.path.join(path2, "wifi_standard.cfg") + with open(local_path, "r") as y: + for line in y: + lines1.append(line) + y.close() + line = lines1.index(' "name" : "wifi_manager_service",\n') + 1 + res1 = line + Step(f"目标索引:{res1}") + index_str1 = lines1[res1] + Step(f"需要修改的目标:{index_str1}") + lines1.remove(index_str1) + Step(f"移除目标之后:{lines1}") + path3 = ' "path" : ["/system/xxxx/bin/sa_main"],\n' + lines1.insert(line, path3) + s = ''.join(lines1) + Step(f"添加修改之后的文件内容:{s}") + with open(local_path, "w") as z: + z.write(s) + z.close() + Step("上传修改后的本地系统文件..........................") + self.driver.push_file(local_path, devpath) + Step("执行重启..........................") + self.driver.System.reboot() + sleep(3) + Step("执行命令begetctl dump_service..........................") + result = self.driver.shell('begetctl dump_service wifi_manager_service') + Step(result) + pid = self.driver.System.get_pid('wifi_manager_service') + Step(pid) + + def teardown(self): + Step("收尾工作.................") + Step("恢复系统文件wifi_standard.cfg..........................") + self.driver.hdc("target mount") + self.driver.shell("rm -rf /system/etc/init/wifi_standard.cfg") + self.driver.shell( + "mv /system/etc/init/wifi_standard.cfg_bak /system/etc/init/wifi_standard.cfg") + Step("执行重启..........................") + self.driver.System.reboot() + sleep(3) + self.driver.System.wait_for_boot_complete() diff --git a/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0700.json b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0700.json new file mode 100644 index 0000000000000000000000000000000000000000..ebcbafd886f730e3e18bfccc954a62d77a3abf1e --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0700.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_ability_up/SubStartupInitAbilityUp0700.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0700.py b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0700.py new file mode 100644 index 0000000000000000000000000000000000000000..ebcf1465fef451e6ee4a1c5165a30ae40f892392 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0700.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from time import sleep +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + + +class SubStartupInitAbilityUp0700(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) + + def test_step1(self): + Step("重命名系统文件hilogd.cfg..........................") + self.driver.hdc("target mount") + self.driver.shell( + "cp /system/etc/init/hilogd.cfg /system/etc/init/hilogd.cfg_bak") + Step("把系统文件hilogd.cfg拉到本地..........................") + devpath = "/system/etc/init/hilogd.cfg" + self.driver.pull_file(devpath, "testFile/sub_startup_init_ability_up/hilogd.cfg") + Step("修改本地系统文件..........................") + lines1 = [] + path2 = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), + "testFile\sub_startup_init_ability_up") + local_path = os.path.join(path2, "hilogd.cfg") + with open(local_path, "r") as y: + for line in y: + lines1.append(line) + y.close() + line = lines1.index(' "socket" : [{\n') - 1 + res1 = line + Step(f"目标索引:{res1}") + index_str1 = lines1[res1] + Step(f"需要修改的目标:{index_str1}") + lines1.remove(index_str1) + Step(f"移除目标之后:{lines1}") + path3 = ' "file" : ["/dev/test/kmsg rd 0640 root root"],\n' + lines1.insert(line, path3) + s = ''.join(lines1) + Step(f"添加修改之后的文件内容:{s}") + with open(local_path, "w") as z: + z.write(s) + z.close() + Step("上传修改后的本地系统文件..........................") + self.driver.push_file(local_path, devpath) + Step("执行重启..........................") + self.driver.System.reboot() + sleep(3) + self.driver.System.wait_for_boot_complete() + Step("执行命令begetctl dump_service..........................") + result = self.driver.shell('begetctl dump_service hilogd') + Step(result) + self.driver.Assert.contains(result, "HiLogAdapter_init: Can't connect to server. Errno: 2") + + def teardown(self): + Step("收尾工作.................") + Step("恢复系统文件hilogd.cfg..........................") + self.driver.hdc("target mount") + self.driver.shell("rm -rf /system/etc/init/hilogd.cfg") + self.driver.shell( + "mv /system/etc/init/hilogd.cfg_bak /system/etc/init/hilogd.cfg") + Step("执行重启..........................") + self.driver.System.reboot() + sleep(3) + self.driver.System.wait_for_boot_complete() diff --git a/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0800.json b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0800.json new file mode 100644 index 0000000000000000000000000000000000000000..c2a9032b3a7e1c22e5dbf31f1490c82ecac7fb6d --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0800.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_ability_up/SubStartupInitAbilityUp0800.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0800.py b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0800.py new file mode 100644 index 0000000000000000000000000000000000000000..d62e52088e569bb7fe93b424f961c51da2a232b9 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_0800.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from time import sleep +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + + +class SubStartupInitAbilityUp0800(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) + + def test_step1(self): + Step("重命名系统文件wifi_standard.cfg..........................") + self.driver.hdc("target mount") + self.driver.shell( + "cp /system/etc/init/wifi_standard.cfg /system/etc/init/wifi_standard.cfg_bak") + Step("把系统文件wifi_standard.cfg拉到本地..........................") + devpath = "/system/etc/init/wifi_standard.cfg" + self.driver.pull_file(devpath, "testFile/sub_startup_init_ability_up/wifi_standard.cfg") + Step("修改本地系统文件..........................") + lines1 = [] + path2 = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), + "testFile\sub_startup_init_ability_up") + local_path = os.path.join(path2, "wifi_standard.cfg") + with open(local_path, "r") as y: + for line in y: + lines1.append(line) + y.close() + line = lines1.index(' "uid" : "wifi",\n') + res1 = line + Step(f"目标索引:{res1}") + index_str1 = lines1[res1] + Step(f"需要修改的目标:{index_str1}") + lines1.remove(index_str1) + Step(f"移除目标之后:{lines1}") + path3 = ' "uid" : "-1",\n' + lines1.insert(line, path3) + s = ''.join(lines1) + Step(f"添加修改之后的文件内容:{s}") + with open(local_path, "w") as z: + z.write(s) + z.close() + Step("上传修改后的本地系统文件..........................") + self.driver.push_file(local_path, devpath) + Step("执行重启..........................") + self.driver.System.reboot() + sleep(3) + Step("执行命令begetctl dump_service..........................") + result = self.driver.shell('begetctl dump_service wifi_manager_service') + Step(result) + pid = self.driver.System.get_pid('wifi_manager_service') + Step(pid) + + def teardown(self): + Step("收尾工作.................") + Step("恢复系统文件wifi_standard.cfg..........................") + self.driver.hdc("target mount") + self.driver.shell("rm -rf /system/etc/init/wifi_standard.cfg") + self.driver.shell( + "mv /system/etc/init/wifi_standard.cfg_bak /system/etc/init/wifi_standard.cfg") + Step("执行重启..........................") + self.driver.System.reboot() + sleep(3) + self.driver.System.wait_for_boot_complete() diff --git a/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_1000.json b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_1000.json new file mode 100644 index 0000000000000000000000000000000000000000..fb01c76e233a9ada04ec57fe7203f865e2a93f43 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_1000.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_ability_up/SubStartupInitAbilityUp1000.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_1000.py b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_1000.py new file mode 100644 index 0000000000000000000000000000000000000000..cebedd4695a358e3be47f47b1cf1b94096d5807b --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_ability_up/sub_startup_init_ability_up_1000.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from time import sleep +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + + +class SubStartupInitAbilityUp1000(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) + + def test_step1(self): + Step("重命名系统文件hilogd.cfg..........................") + self.driver.hdc("target mount") + self.driver.shell( + "cp /system/etc/init/hilogd.cfg /system/etc/init/hilogd.cfg_bak") + Step("把系统文件hilogd.cfg拉到本地..........................") + devpath = "/system/etc/init/hilogd.cfg" + self.driver.pull_file(devpath, "testFile/sub_startup_init_ability_up/hilogd.cfg") + Step("修改本地系统文件..........................") + lines1 = [] + path2 = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), + "testFile\sub_startup_init_ability_up") + local_path = os.path.join(path2, "hilogd.cfg") + with open(local_path, "r") as y: + for line in y: + lines1.append(line) + y.close() + line = lines1.index(' "secon" : "u:r:hilogd:s0"\n') + res1 = line + Step(f"目标索引:{res1}") + index_str1 = lines1[res1] + Step(f"需要删除目标:{index_str1}") + lines1.remove(index_str1) + line2 = line - 1 + index_str2 = lines1[line2] + lines2 = list(index_str2) + Step(f"需要修改,:{lines2}") + if ',' in lines2: + lines2.remove(',') + s2 = ''.join(lines2) + Step(f"修改,之后:{s2}") + else: + pass + lines1.remove(index_str2) + lines1.insert(line2, s2) + Step(f"全部修改:{lines1}") + s = ''.join(lines1) + Step(f"修改之后的文件内容:{s}") + with open(local_path, "w") as z: + z.write(s) + z.close() + Step("上传修改后的本地系统文件..........................") + self.driver.push_file(local_path, devpath) + Step("执行重启..........................") + self.driver.System.reboot() + sleep(3) + self.driver.System.wait_for_boot_complete() + Step("执行命令begetctl dump_service..........................") + result = self.driver.shell('begetctl dump_service hilogd') + Step(result) + self.driver.Assert.contains(result, "HiLogAdapter_init: Can't connect to server.") + + def teardown(self): + Step("收尾工作.................") + Step("恢复系统文件hilogd.cfg..........................") + self.driver.hdc("target mount") + self.driver.shell("rm -rf /system/etc/init/hilogd.cfg") + self.driver.shell( + "mv /system/etc/init/hilogd.cfg_bak /system/etc/init/hilogd.cfg") + Step("执行重启..........................") + self.driver.System.reboot() + sleep(3) + self.driver.System.wait_for_boot_complete() diff --git a/test/autotest/testcases/sub_startup_init_access_isolation/sub_startup_init_access_isolation_0100.json b/test/autotest/testcases/sub_startup_init_access_isolation/sub_startup_init_access_isolation_0100.json new file mode 100644 index 0000000000000000000000000000000000000000..2545c22295510f2b34d17d0aa284a3b448ab9203 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_access_isolation/sub_startup_init_access_isolation_0100.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_access_isolation/SubStartupInitAccessIsolation0100.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_access_isolation/sub_startup_init_access_isolation_0100.py b/test/autotest/testcases/sub_startup_init_access_isolation/sub_startup_init_access_isolation_0100.py new file mode 100644 index 0000000000000000000000000000000000000000..fa4c7fae9512b0e3f469ddc70211866503f9dad3 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_access_isolation/sub_startup_init_access_isolation_0100.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import time +from time import sleep +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver +from aw import Common +from hypium import UiDriver, UiExplorer +from hypium.action.os_hypium.device_logger import DeviceLogger +import subprocess + + +class SubStartupInitAccessIsolation0100(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("导入测试文件systemapp.................") + self.driver.hdc("target mount") + sourpath_se = Common.sourcepath("systemapp", "sub_startup_init_access_isolation") + destpath_se = "system/bin/systemapp" + self.driver.push_file(sourpath_se, destpath_se) + sleep(3) + Step("重启生效..........................") + self.driver.System.reboot() + sleep(5) + self.driver.System.wait_for_boot_complete() + + def test_step1(self): + Step("过滤打印hilog日志.................") + device_logger = DeviceLogger(self.driver) + path = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) + device_logger.set_filter_string("systemapp") + Step("开始抓取日志") + device_logger.start_log(path + '\\testFile\\log\\%s.log' % (self.TAG)) + Step("给测试文件systemapp添加可执行权限.................") + self.driver.hdc("target mount") + self.driver.shell("chmod +x ./system/bin/systemapp") + Step("防止hilog日志出现unknown log.................") + self.driver.shell("hilog -d /system/bin/systemapp") + Step("执行测试文件systemapp.................") + self.driver.shell("./system/bin/systemapp") + time.sleep(3) + Step("停止抓日志") + device_logger.stop_log() + Step("断言预期结果") + time.sleep(2) + device_logger.check_log('systemapp:prohibit system component processes from accessing vendor files') + + def teardown(self): + Step("收尾工作.................") + self.driver.hdc("target mount") + self.driver.shell("rm -rf system/bin/systemapp") + Step("重启恢复..........................") + self.driver.System.reboot() + sleep(3) + self.driver.System.wait_for_boot_complete() diff --git a/test/autotest/testcases/sub_startup_init_access_isolation/sub_startup_init_access_isolation_0200.json b/test/autotest/testcases/sub_startup_init_access_isolation/sub_startup_init_access_isolation_0200.json new file mode 100644 index 0000000000000000000000000000000000000000..e9829d427797e0426a43462dd341f5610d1361f8 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_access_isolation/sub_startup_init_access_isolation_0200.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_access_isolation/SubStartupInitAccessIsolation0200.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_access_isolation/sub_startup_init_access_isolation_0200.py b/test/autotest/testcases/sub_startup_init_access_isolation/sub_startup_init_access_isolation_0200.py new file mode 100644 index 0000000000000000000000000000000000000000..1a18ee3aec7ef5d49b6363eee5b08f435645e5b9 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_access_isolation/sub_startup_init_access_isolation_0200.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from time import sleep +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver +from aw import Common +from hypium import UiDriver, UiExplorer +from hypium.action.os_hypium.device_logger import DeviceLogger +import subprocess + + +class SubStartupInitAccessIsolation0200(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): + print("预置工作:初始化手机开始.................") + print(self.devices[0].device_id) + Step("导入测试文件chipsetapp.................") + self.driver.hdc("target mount") + sourpath_se = Common.sourcepath("chipsetapp", "sub_startup_init_access_isolation") + destpath_se = "vendor/bin/chipsetapp" + self.driver.push_file(sourpath_se, destpath_se) + sleep(3) + Step("重启生效..........................") + self.driver.System.reboot() + sleep(5) + self.driver.System.wait_for_boot_complete() + + def test_step1(self): + Step("过滤打印hilog日志.................") + cmd = 'hdc shell hilog | grep chipsetapp' + trace = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=10) + count = 0 + Step("给测试文件chipsetapp添加可执行权限.................") + self.driver.hdc("target mount") + self.driver.shell("chmod +x ./vendor/bin/chipsetapp") + Step("执行测试文件chipsetapp.................") + self.driver.shell("./vendor/bin/chipsetapp") + Step("验证执行结果.................") + while trace.poll() is None: + result_text = trace.stdout.readline().decode() + if 'chipsetapp:prohibit chipset component processes from accessing system files' in result_text: + Step("实现芯片组件访问系统文件隔离.................") + trace.terminate() + break + count += 1 + + def teardown(self): + print("收尾工作.................") + self.driver.hdc("target mount") + self.driver.shell("rm -rf vendor/bin/chipsetapp") + Step("重启恢复..........................") + self.driver.System.reboot() + sleep(3) + self.driver.System.wait_for_boot_complete() diff --git a/test/autotest/testcases/sub_startup_init_apiname/sub_startup_init_apiname_0100.json b/test/autotest/testcases/sub_startup_init_apiname/sub_startup_init_apiname_0100.json new file mode 100644 index 0000000000000000000000000000000000000000..61b91e1d226dfd7d674fd58254b74e4f110db4ea --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_apiname/sub_startup_init_apiname_0100.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_apiname/SubStartupInitApiname0100.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_apiname/sub_startup_init_apiname_0100.py b/test/autotest/testcases/sub_startup_init_apiname/sub_startup_init_apiname_0100.py new file mode 100644 index 0000000000000000000000000000000000000000..c996fcb17673d8af1fca78ccf7bb92f89a1302bf --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_apiname/sub_startup_init_apiname_0100.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from time import sleep +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver +from aw import Common + + +class SubStartupInitApiname0100(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("预置工作:检测屏幕是否亮.................") + self.driver.Screen.wake_up() + self.driver.ScreenLock.unlock() + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("安装测试hap.................") + sourpath = Common.sourcepath("distributionOsApiName.hap", "sub_startup_init_apiname") + Step(sourpath) + self.driver.AppManager.install_app(sourpath) + Step("命令查看param get const.product.os.dist.apiname.................") + apiname = self.driver.shell("param get const.product.os.dist.apiname") + apiname = apiname.strip() + Step(apiname) + result = "const.product.os.dist.apiname: " + apiname + Step(result) + Step("打开测试hap.................") + self.driver.start_app("com.example.myapplication", "EntryAbility") + Step("点击get ApiName按钮.................") + self.driver.touch(BY.text("get ApiName")) + sleep(1) + Step("校验apiname值.................") + + def teardown(self): + Step("收尾工作.................") + Step("卸载测试hap................") + self.driver.AppManager.clear_app_data('com.example.myapplication') + self.driver.AppManager.uninstall_app('com.example.myapplication') diff --git a/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0200.json b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0200.json new file mode 100644 index 0000000000000000000000000000000000000000..41e44349883bc759cb063b7a22852612891af373 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0200.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_basicenv/SubStartupInitBasicenv0200.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0200.py b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0200.py new file mode 100644 index 0000000000000000000000000000000000000000..c2f1116488774c8f16dea567eff7da0ad8feb00d --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0200.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + + +class SubStartupInitBasicenv0200(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) + + def test_step1(self): + Step("find /dev/unix/socket................") + result_socket = self.driver.shell("ls -l /dev/unix/socket") + Step(result_socket) + self.driver.Assert.contains(result_socket, 'hdcd', "ERROR: hdcd is not exist in socket directory.") + self.driver.Assert.contains(result_socket, 'hilogInput', "ERROR: hilogInput is not exist in socket directory.") + self.driver.Assert.contains(result_socket, 'hilogControl', "ERROR: hilogControl is not exist in socket directory.") + self.driver.Assert.contains(result_socket, 'hisysevent', "ERROR: hisysevent is not exist in socket directory.") + + def teardown(self): + Step("收尾工作.................") diff --git a/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0600.json b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0600.json new file mode 100644 index 0000000000000000000000000000000000000000..1f7d0dcbdec8e278a718c3ade444240cff109a39 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_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_init_basicenv/SubStartupInitBasicenv0600.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0600.py b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0600.py new file mode 100644 index 0000000000000000000000000000000000000000..058b638c2a4640185bfd1e3b82520f4d80c688bf --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0600.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + + +class SubStartupInitBasicenv0600(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) + + def test_step1(self): + Step("df -h................") + result_df = self.driver.shell("df -h") + Step(result_df) + self.driver.Assert.contains(result_df, 'sdd8', "基础文件系统挂载失败") + self.driver.Assert.contains(result_df, '/vendor', "基础文件系统挂载失败") + self.driver.Assert.contains(result_df, '/data', "基础文件系统挂载失败") + + def teardown(self): + Step("收尾工作.................") diff --git a/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0700.json b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0700.json new file mode 100644 index 0000000000000000000000000000000000000000..d7a6e64a3a54106cd158e76fe40c19bd7e5cb261 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_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_init_basicenv/SubStartupInitBasicenv0700.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0700.py b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0700.py new file mode 100644 index 0000000000000000000000000000000000000000..2d0af23f1f27a5acfea1cad8c045670c89289dcf --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0700.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + + +class SubStartupInitBasicenv0700(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) + + def test_step1(self): + Step("df -h................") + result_df = self.driver.shell("df -h") + Step(result_df) + self.driver.Assert.contains(result_df, '/vendor', "基础文件系统挂载失败") + self.driver.Assert.contains(result_df, '/data', "基础文件系统挂载失败") + Step("find fstab................") + + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("ALN" in device): + result_fstab = self.driver.shell("cat /vendor/etc/fstab.kirin9000s") + elif("CLS" in device): + result_fstab = self.driver.shell("cat /vendor/etc/fstab.Kirin9010") + else: + result_fstab = self.driver.shell("cat /vendor/etc/fstab.kirin9020") + Step(result_fstab) + self.driver.Assert.contains(result_fstab, '/usr', "文件系统挂载失败") + self.driver.Assert.contains(result_fstab, '/vendor', "文件系统挂载失败") + self.driver.Assert.contains(result_fstab, '/data', "文件系统挂载失败") + + def teardown(self): + Step("收尾工作.................") diff --git a/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0800.json b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0800.json new file mode 100644 index 0000000000000000000000000000000000000000..03fd6b96c4eeb055f946a3d076832518e225f6cd --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0800.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_basicenv/SubStartupInitBasicenv0800.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0800.py b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0800.py new file mode 100644 index 0000000000000000000000000000000000000000..181c50d2a5210b4528ab6a94a8ec7f1d0c66d3c0 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0800.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from time import sleep +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + + +class SubStartupInitBasicenv0800(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) + + def test_step1(self): + Step("find cmdline................") + result_cmdline = self.driver.shell("cat /proc/cmdline") + Step(result_cmdline) + + Step("识别设备型号...............................") + device = self.driver.shell("param get const.product.model") + device = device.replace("\n", "").replace(" ", "") + device = str(device) + if ("ALN" in device): + self.driver.Assert.contains(result_cmdline, 'hardware=kirin9000s', "ERROR: cannot find hardware in /proc/cmdline.") + Step("param get hardware................") + result_hardware = self.driver.shell("param get ohos.boot.hardware") + Step(result_hardware) + self.driver.Assert.contains(result_hardware, 'kirin9000s', "ERROR: cannot find hardware in param get.") + elif ("CLS" in device): + self.driver.Assert.contains(result_cmdline, 'hardware=Kirin9010', "ERROR: cannot find hardware in /proc/cmdline.") + result_hardware = self.driver.shell("param get ohos.boot.hardware") + Step(result_hardware) + self.driver.Assert.contains(result_hardware, 'Kirin9010', "ERROR: cannot find hardware in param get.") + else: + self.driver.Assert.contains(result_cmdline, 'hardware=kirin9020', "ERROR: cannot find hardware in /proc/cmdline.") + Step("param get hardware................") + result_hardware = self.driver.shell("param get ohos.boot.hardware") + Step(result_hardware) + self.driver.Assert.contains(result_hardware, 'kirin9020', "ERROR: cannot find hardware in param get.") + + def teardown(self): + Step("收尾工作.................") diff --git a/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0900.json b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0900.json new file mode 100644 index 0000000000000000000000000000000000000000..0a41f45ea3db5e791700cfb9100996e223aa1ba1 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0900.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_basicenv/SubStartupInitBasicenv0900.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0900.py b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0900.py new file mode 100644 index 0000000000000000000000000000000000000000..255a0b0262e6193a155c161436abb4a3d268664a --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_0900.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + + +class SubStartupInitBasicenv0900(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) + + def test_step1(self): + Step("test mkdir................") + self.driver.shell("mkdir /data/testmkdir") + result_mkdir = self.driver.shell("ls -l /data") + Step(result_mkdir) + self.driver.Assert.contains(result_mkdir, 'testmkdir', "ERROR: cannot find testmkdir directory.") + Step("test rmdir................") + self.driver.shell("rmdir /data/testmkdir") + result_rmdir = self.driver.shell("ls -l /data/testmkdir") + Step(result_rmdir) + self.driver.Assert.contains(result_rmdir, 'No such file or directory', "ERROR: rmdir testmkdir directory failed.") + Step("test cd................") + result_cd = self.driver.shell("cd") + Step(result_cd) + self.driver.Assert.contains(result_cd, '', "ERROR: execute cd failed.") + Step("test pwd................") + result_pwd = self.driver.shell("pwd") + Step(result_pwd) + self.driver.Assert.contains(result_pwd, '/', "ERROR: execute pwd failed.") + + def teardown(self): + Step("收尾工作.................") diff --git a/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_1000.json b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_1000.json new file mode 100644 index 0000000000000000000000000000000000000000..65773ff6b7d51e2b50f534c2ff1e77909133c160 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_1000.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_basicenv/SubStartupInitBasicenv1000.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_1000.py b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_1000.py new file mode 100644 index 0000000000000000000000000000000000000000..3fc626cc62d1e8c5fe4e8e20055851ae1b8022ba --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_basicenv/sub_startup_init_basicenv_1000.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + + +class SubStartupInitBasicenv1000(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) + + def test_step1(self): + Step("test stop status................") + result_param = self.driver.shell("param get") + Step(result_param) + self.driver.Assert.contains(result_param, ' stop', "ERROR: cannot find stop from parameter.") + + def teardown(self): + Step("收尾工作.................") diff --git a/test/autotest/testcases/sub_startup_init_gwp/sub_startup_init_gwp_0200.json b/test/autotest/testcases/sub_startup_init_gwp/sub_startup_init_gwp_0200.json new file mode 100644 index 0000000000000000000000000000000000000000..627e5fb03859a84bb1c36d451fb39bbdfd0a3d15 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_gwp/sub_startup_init_gwp_0200.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_gwp/SubStartupInitGwp0200.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_gwp/sub_startup_init_gwp_0200.py b/test/autotest/testcases/sub_startup_init_gwp/sub_startup_init_gwp_0200.py new file mode 100644 index 0000000000000000000000000000000000000000..1ec9ab9f13a7a593ae06e6b36ee48e7c2e66fccd --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_gwp/sub_startup_init_gwp_0200.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + + +class SubStartupInitGwp0200(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) + + def test_step1(self): + Step("查询开发者模式.................") + result = self.driver.shell("param get const.security.developermode.state") + Step(result) + self.driver.Assert.contains(result, 'true', "开发者模式打开时,进行GWP-ASAN使能") + + def teardown(self): + Step("收尾工作.................") diff --git a/test/autotest/testcases/sub_startup_init_gwp/sub_startup_init_gwp_0300.json b/test/autotest/testcases/sub_startup_init_gwp/sub_startup_init_gwp_0300.json new file mode 100644 index 0000000000000000000000000000000000000000..203f603b14f0464ac319a498e8197e2307c6a90f --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_gwp/sub_startup_init_gwp_0300.json @@ -0,0 +1,14 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_gwp/SubStartupInitGwp0300.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_gwp/sub_startup_init_gwp_0300.py b/test/autotest/testcases/sub_startup_init_gwp/sub_startup_init_gwp_0300.py new file mode 100644 index 0000000000000000000000000000000000000000..66ebfd13d3a63bbb5d2ee02dab696b37fd22ee23 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_gwp/sub_startup_init_gwp_0300.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from time import sleep +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver +from hypium.action.os_hypium.device_logger import DeviceLogger +from aw import Common + + +class SubStartupInitGwp0300(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.................") + sourpath = Common.sourcepath("force.hap", "sub_startup_init_gwp") + Step(sourpath) + self.driver.AppManager.install_app(sourpath) + sleep(3) + + def test_step1(self): + self.d = UiExplorer(self.device1) + device_logger = DeviceLogger(self.d) + Step("设置关键字..........................") + device_logger.set_filter_string("gwp_asan") + Step("开启日志..........................") + device_logger.start_log("testFile/Log/log.txt") + Step("打开测试hap.................") + self.driver.start_app("com.example.myapplication", "EntryAbility") + sleep(10) + Step("停止日志..........................") + device_logger.stop_log() + Step("校验日志内容..........................") + + def teardown(self): + Step("收尾工作.................") + Step("卸载测试hap.................") + self.driver.AppManager.clear_app_data("com.example.myapplication") + self.driver.AppManager.uninstall_app("com.example.myapplication") + diff --git a/test/autotest/testcases/sub_startup_init_hilog/sub_startup_init_hilog_0100.json b/test/autotest/testcases/sub_startup_init_hilog/sub_startup_init_hilog_0100.json new file mode 100644 index 0000000000000000000000000000000000000000..d6f2a8579dd6df2955b4e94c4b7321aec79c5fb3 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_hilog/sub_startup_init_hilog_0100.json @@ -0,0 +1,12 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": ["sub_startup_init_hilog/SubStartupInitHilog0100.py"] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_hilog/sub_startup_init_hilog_0100.py b/test/autotest/testcases/sub_startup_init_hilog/sub_startup_init_hilog_0100.py new file mode 100644 index 0000000000000000000000000000000000000000..c21dbb1e150d8c1e6461664a8091d61a0e0e54e1 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_hilog/sub_startup_init_hilog_0100.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from devicetest.core.test_case import TestCase, Step, CheckPoint +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver +from hypium.action.os_hypium.device_logger import DeviceLogger +from hypium.model import UiParam, WindowFilter +import time + + +class SubStartupInitHilog0100(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:过滤关键日志") + device_logger = DeviceLogger(self.driver) + path = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) + device_logger.set_filter_string("C02C11") + Step("步骤2:获取appspawn的进程号") + pid = self.driver.System.get_pid("appspawn") + Step("步骤3:开始抓日志") + device_logger.start_log(path + '\\testFile\\log\\%s.log' % (self.TAG)) + Step("步骤4:kill进程号") + self.driver.shell("kill -9 %d" % pid) + time.sleep(5) + Step("步骤4:关闭日志") + device_logger.stop_log() + time.sleep(2) + device_logger.check_not_exist_keyword('nodict') + + def teardown(self): + Step("收尾工作:无") \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_odid/sub_startup_init_odid_0100.json b/test/autotest/testcases/sub_startup_init_odid/sub_startup_init_odid_0100.json new file mode 100644 index 0000000000000000000000000000000000000000..e27e546d6897bdc2e7bb6aa260b5deabbd250109 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_odid/sub_startup_init_odid_0100.json @@ -0,0 +1,15 @@ +{ + "description": "Config for OpenHarmony devicetest test cases", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "sub_startup_init_odid/SubStartupInitOdid0100.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_odid/sub_startup_init_odid_0100.py b/test/autotest/testcases/sub_startup_init_odid/sub_startup_init_odid_0100.py new file mode 100644 index 0000000000000000000000000000000000000000..4c84eecd5305ffcd290a1a14d209c2dda0a6b387 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_odid/sub_startup_init_odid_0100.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from time import sleep +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + +from aw import Common + + +class SubStartupInitOdid0100(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.................") + sourpath = Common.sourcepath("odid.hap", "sub_startup_init_odid") + Step(sourpath) + self.driver.AppManager.install_app(sourpath) + Step("预置工作:检测屏幕是否亮.................") + self.driver.Screen.wake_up() + self.driver.ScreenLock.unlock() + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("打开测试hap.................") + self.driver.start_app("com.example.newodidtest", "EntryAbility") + sleep(3) + Step("点击菜单.................") + self.driver.touch(BY.text("dev2 ODID1 ")) + sleep(1) + Step("获取首次odid.................") + component = self.driver.find_component(BY.type("Text")) + odid1 = component.getText() + Step(odid1) + Step("卸载测试hap................") + self.driver.AppManager.clear_app_data('com.example.newodidtest') + self.driver.AppManager.uninstall_app('com.example.newodidtest') + sleep(3) + Step("再次安装hap.................") + sourpath = Common.sourcepath("odid.hap", "sub_startup_init_odid") + Step(sourpath) + self.driver.AppManager.install_app(sourpath) + Step("打开测试hap.................") + self.driver.start_app("com.example.newodidtest", "EntryAbility") + sleep(3) + Step("点击菜单.................") + self.driver.touch(BY.text("dev2 ODID1 ")) + sleep(1) + Step("获取二次odid.................") + component = self.driver.find_component(BY.type("Text")) + odid2 = component.getText() + Step(odid2) + + def teardown(self): + Step("收尾工作.................") + Step("卸载测试hap................") + self.driver.AppManager.clear_app_data('com.example.newodidtest') + self.driver.AppManager.uninstall_app('com.example.newodidtest') diff --git a/test/autotest/testcases/sub_startup_init_odid/sub_startup_init_odid_0300.json b/test/autotest/testcases/sub_startup_init_odid/sub_startup_init_odid_0300.json new file mode 100644 index 0000000000000000000000000000000000000000..92e0971b552ebd83f445db7d565758017ab062ec --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_odid/sub_startup_init_odid_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_init_odid/SubStartupInitOdid0300.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/testcases/sub_startup_init_odid/sub_startup_init_odid_0300.py b/test/autotest/testcases/sub_startup_init_odid/sub_startup_init_odid_0300.py new file mode 100644 index 0000000000000000000000000000000000000000..87fbde07cdb317a575ded375f73dcc93976e8376 --- /dev/null +++ b/test/autotest/testcases/sub_startup_init_odid/sub_startup_init_odid_0300.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from time import sleep +from devicetest.core.test_case import Step, TestCase +from hypium import UiDriver + +from aw import Common + + +class SubStartupInitOdid0300(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.................") + sourpath1 = Common.sourcepath("odid.hap", "sub_startup_init_odid") + sourpath2 = Common.sourcepath("odid1.hap", "sub_startup_init_odid") + Step(sourpath1) + Step(sourpath2) + self.driver.AppManager.install_app(sourpath1) + self.driver.AppManager.install_app(sourpath2) + Step("预置工作:检测屏幕是否亮.................") + self.driver.Screen.wake_up() + self.driver.ScreenLock.unlock() + self.driver.Screen.enable_stay_awake() + + def test_step1(self): + Step("打开第一个开发者的测试hap.................") + self.driver.start_app("com.example.newodidtest", "EntryAbility") + sleep(3) + Step("点击菜单.................") + self.driver.touch(BY.text("dev2 ODID1 ")) + sleep(1) + Step("获取第一个odid.................") + component = self.driver.find_component(BY.type("Text")) + odid1 = component.getText() + Step(odid1) + Step("打开第二个开发者测试hap.................") + self.driver.start_app("com.example.odidtest", "EntryAbility") + sleep(3) + Step("点击菜单.................") + self.driver.touch(BY.text("dev1 ODID1 ")) + sleep(1) + Step("获取第二个odid.................") + component = self.driver.find_component(BY.type("Text")) + odid2 = component.getText() + Step(odid2) + + def teardown(self): + Step("收尾工作.................") + Step("卸载测试hap................") + self.driver.AppManager.clear_app_data('com.example.newodidtest') + self.driver.AppManager.clear_app_data('com.example.odidtest') + self.driver.AppManager.uninstall_app('com.example.newodidtest') + self.driver.AppManager.uninstall_app('com.example.odidtest') \ No newline at end of file diff --git a/test/fuzztest/onstop_fuzzer/onstop_fuzzer.cpp b/test/fuzztest/onstop_fuzzer/onstop_fuzzer.cpp index e491fb74e9e3bae7481203ac2f25c3d6dfda7b02..7ff5dffc0d635d4775837ee9d22ffd3f958a716d 100644 --- a/test/fuzztest/onstop_fuzzer/onstop_fuzzer.cpp +++ b/test/fuzztest/onstop_fuzzer/onstop_fuzzer.cpp @@ -36,7 +36,7 @@ public: } }; namespace OHOS { -bool FuzzCheckAppWatchPermission(const uint8_t* data, size_t size) + bool FuzzOnstop(const uint8_t* data, size_t size) { std::unique_ptr watcherManager = std::make_unique(0, true); uint32_t id = static_cast(*data); @@ -54,6 +54,6 @@ bool FuzzCheckAppWatchPermission(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - OHOS::FuzzCheckAppWatchPermission(data, size); + OHOS::FuzzOnstop(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/watchparameter_fuzzer/watchparameter_fuzzer.cpp b/test/fuzztest/watchparameter_fuzzer/watchparameter_fuzzer.cpp index fcf52ef016fbed74540c6389729328197c46cab8..39d0fdf4ca7eaf86cdf56eef595485d118712a5a 100644 --- a/test/fuzztest/watchparameter_fuzzer/watchparameter_fuzzer.cpp +++ b/test/fuzztest/watchparameter_fuzzer/watchparameter_fuzzer.cpp @@ -17,6 +17,8 @@ #include #include "parameter.h" #include "fuzz_utils.h" +#include +static const int SLEEP_TIME = 100000; static void HandleParamChange(const char *key, const char *value, void *context) { @@ -29,10 +31,12 @@ static void HandleParamChange(const char *key, const char *value, void *context) namespace OHOS { bool FuzzWatchParameter(const uint8_t* data, size_t size) { + usleep(SLEEP_TIME); bool result = false; std::string str(reinterpret_cast(data), size); CloseStdout(); if (!WatchParameter(str.c_str(), HandleParamChange, NULL)) { + usleep(SLEEP_TIME); WatchParameter(str.c_str(), NULL, NULL); result = true; } diff --git a/test/unittest/init/mount_unittest.cpp b/test/unittest/init/mount_unittest.cpp index 6993672a3d00487436d1e3791cebbeb4dee16fd8..56e1a96cc4c27dca80224209d3db25126789af24 100644 --- a/test/unittest/init/mount_unittest.cpp +++ b/test/unittest/init/mount_unittest.cpp @@ -35,12 +35,7 @@ public: HWTEST_F(MountUnitTest, TestGetBlockDevicePath, TestSize.Level1) { char path[20] = {0}; // 20 is path length - int fd = open("/bin/updater", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, S_IRWXU); - if (fd < 0) { - return; - } GetBlockDevicePath("/test", path, sizeof(path)); - close(fd); ReadConfig(); unlink("/bin/updater"); ReadConfig(); diff --git a/test/unittest/init/sandbox_unittest.cpp b/test/unittest/init/sandbox_unittest.cpp index dd7ced0c4906481c6202eb3e23119a8b19aafc37..b3e852578b18906a987e802d7b6430aef8288763 100644 --- a/test/unittest/init/sandbox_unittest.cpp +++ b/test/unittest/init/sandbox_unittest.cpp @@ -173,10 +173,7 @@ public: HWTEST_F(SandboxUnitTest, TestCreateNormalSandbox, TestSize.Level1) { cJSON *mJson = MakeSandboxJson(SANDBOX_JSON_NAME, 0); - if (mJson == nullptr) { - std::cout << "created mJson error, mJson is null." << std::endl; - return; - } + ASSERT_NE(mJson, nullptr); MakeFileByJson(mJson, SANDBOX_JSON_NAME); int ret = RestartSandbox(TEST_SANDBOX_NAME); ASSERT_EQ(ret, 0); @@ -212,10 +209,7 @@ HWTEST_F(SandboxUnitTest, TestCreateErrorSandbox1, TestSize.Level1) { HWTEST_F(SandboxUnitTest, TestCreateErrorSandbox2, TestSize.Level1) { cJSON *mJson = MakeSandboxJson(SANDBOX_JSON_NAME, NULL_ROOT_PATH); - if (mJson == nullptr) { - std::cout << "created mJson error, mJson is null." << std::endl; - return; - } + ASSERT_NE(mJson, nullptr); bool ret1 = MakeFileByJson(mJson, SANDBOX_JSON_NAME); ASSERT_TRUE(ret1); InitSandboxWithName(TEST_SANDBOX_NAME); @@ -233,10 +227,7 @@ HWTEST_F(SandboxUnitTest, TestCreateSandboxNoneJsonError, TestSize.Level1) { HWTEST_F(SandboxUnitTest, TestCreateSandboxMountFlagsError, TestSize.Level1) { cJSON *mJson = MakeSandboxJson(SANDBOX_JSON_NAME, NULL_MOUNT_FLAGS); - if (mJson == nullptr) { - std::cout << "created mJson error, mJson is null." << std::endl; - return; - } + ASSERT_NE(mJson, nullptr); MakeFileByJson(mJson, SANDBOX_JSON_NAME); int ret = PrepareSandbox(TEST_SANDBOX_NAME); ASSERT_EQ(ret, -1); @@ -244,10 +235,7 @@ HWTEST_F(SandboxUnitTest, TestCreateSandboxMountFlagsError, TestSize.Level1) { HWTEST_F(SandboxUnitTest, TestCreateSandboxMountNULLError, TestSize.Level1) { cJSON *mJson = MakeSandboxJson(SANDBOX_JSON_NAME, NULL_MOUNT_ITEM); - if (mJson == nullptr) { - std::cout << "created mJson error, mJson is null." << std::endl; - return; - } + ASSERT_NE(mJson, nullptr); MakeFileByJson(mJson, SANDBOX_JSON_NAME); int ret = PrepareSandbox(TEST_SANDBOX_NAME); ASSERT_EQ(ret, -1); diff --git a/test/unittest/init/service_unittest.cpp b/test/unittest/init/service_unittest.cpp index 53ad4ee7572683388c6ad7814848ea0b0ec3796e..a37874a408bc62138e9331fa1bfe2d9c05a6a949 100644 --- a/test/unittest/init/service_unittest.cpp +++ b/test/unittest/init/service_unittest.cpp @@ -510,7 +510,6 @@ HWTEST_F(ServiceUnitTest, TestServiceCGroup2, TestSize.Level1) } } fclose(file); - EXPECT_EQ(ret, 0); ret = ServiceStop(service); EXPECT_EQ(ret, 0); ReleaseService(service); @@ -619,6 +618,7 @@ HWTEST_F(ServiceUnitTest, TestKernelPermPermissionError, TestSize.Level1) ASSERT_NE(nullptr, service); int ret = ParseOneService(serviceItem, service); EXPECT_EQ(ret, 0); + EXPECT_TRUE(service->kernelPerms != nullptr); SERVICE_INFO_CTX context; context.serviceName = service->name; @@ -646,6 +646,7 @@ HWTEST_F(ServiceUnitTest, TestKernelPermServiceNameError, TestSize.Level1) ASSERT_NE(nullptr, service); int ret = ParseOneService(serviceItem, service); EXPECT_EQ(ret, 0); + EXPECT_TRUE(service->kernelPerms != nullptr); SERVICE_INFO_CTX context; context.serviceName = "wrongServiceName"; diff --git a/test/unittest/lite/cmd_func_test.cpp b/test/unittest/lite/cmd_func_test.cpp index f821ed5fa07c1ae12caf0641e682309089bac8e7..06b7a4c08966e67b57e3f23afa410bec8e73395c 100644 --- a/test/unittest/lite/cmd_func_test.cpp +++ b/test/unittest/lite/cmd_func_test.cpp @@ -796,10 +796,7 @@ static void CheckJobs(const cJSON* fileRoot) HWTEST_F(StartupInitUTest, cfgCheckContent_001, TestSize.Level0) { char *fileBuf = ReadFileToBuf(); - if (fileBuf == nullptr) { - EXPECT_TRUE(fileBuf != nullptr); - return; - } + ASSERT_NE(fileBuf, nullptr); cJSON *fileRoot = cJSON_Parse(fileBuf); free(fileBuf); @@ -909,11 +906,7 @@ HWTEST_F(StartupInitUTest, cmdFuncDoLoadCfgTest_003, TestSize.Level0) stat(cmdContentStr.c_str(), &testCfgStat); if (testCfgStat.st_size > 0) { fd = fopen(TEST_PROC_MOUNTS.c_str(), "r"); - - if (fd == nullptr) { - EXPECT_TRUE(fd != nullptr); - return; - } + ASSERT_NE(fd, nullptr); do { size = fread(buf, 1, CAT_BUF_SIZE - 1, fd); @@ -962,10 +955,7 @@ HWTEST_F(StartupInitUTest, cmdJobTest_002, TestSize.Level0) PRE_INIT_DIR + "\"]},{\"name\":\"init\",\"cmds\":[\"mkdir " + INIT_DIR + "\"]},{\"name\":\"post-init\",\"cmds\":[\"mkdir " + POST_INIT_DIR + "\"]}]}"; cJSON* jobItem = cJSON_Parse(cfgJson.c_str()); - EXPECT_NE(nullptr, jobItem); - if (jobItem == nullptr) { - return; - } + ASSERT_NE(nullptr, jobItem); ConfigContext context = { INIT_CONTEXT_MAIN }; ParseAllJobs(jobItem, &context); DoJob("pre-init"); diff --git a/test/unittest/modules/context_unittest.cpp b/test/unittest/modules/context_unittest.cpp index 0286ee9c0c9f48b3963031c11d58a8cb41d9bf6d..3681c2acf7923228d07c3993651b86c4611d44a3 100755 --- a/test/unittest/modules/context_unittest.cpp +++ b/test/unittest/modules/context_unittest.cpp @@ -147,10 +147,7 @@ HWTEST_F(InitContextUnitTest, InitSubContextTest_04, TestSize.Level1) } SubInitContext *subContext = GetSubInitContext(INIT_CONTEXT_CHIPSET); - if (subContext == nullptr) { - EXPECT_EQ(0, -1); - return; - } + ASSERT_NE(subContext, nullptr); ret = subContext->executeCmdInSubInit(INIT_CONTEXT_CHIPSET, "mkdir-2", STARTUP_INIT_UT_PATH"/testsubcontext"); EXPECT_NE(ret, 0); } @@ -167,10 +164,8 @@ HWTEST_F(InitContextUnitTest, InitSubContextTest_06, TestSize.Level1) ConfigContext context = { INIT_CONTEXT_CHIPSET }; int index = 0; const char *cmd = GetMatchCmd("mkdir ", &index); - if (cmd == nullptr || strstr(cmd, "mkdir ") == nullptr) { - EXPECT_EQ(1, 0); - return; - } + ASSERT_NE(cmd, nullptr); + ASSERT_NE(strstr(cmd, "mkdir "), nullptr); DoCmdByIndex(index, STARTUP_INIT_UT_PATH"/testsubcontext", &context); } @@ -179,10 +174,8 @@ HWTEST_F(InitContextUnitTest, InitSubContextTest_07, TestSize.Level1) ConfigContext context = { INIT_CONTEXT_MAIN }; int index = 0; const char *cmd = GetMatchCmd("mkdir ", &index); - if (cmd == nullptr || strstr(cmd, "mkdir ") == nullptr) { - EXPECT_EQ(1, 0); - return; - } + ASSERT_NE(cmd, nullptr); + ASSERT_NE(strstr(cmd, "mkdir "), nullptr); DoCmdByIndex(index, STARTUP_INIT_UT_PATH"/testsubcontext", &context); } @@ -206,10 +199,7 @@ HWTEST_F(InitContextUnitTest, InitSubContextTest_10, TestSize.Level1) EXPECT_EQ(ret, -1); SubInitContext *subContext = GetSubInitContext(INIT_CONTEXT_CHIPSET); - if (subContext == nullptr) { - EXPECT_EQ(0, -1); - return; - } + ASSERT_NE(subContext, nullptr); ret = subContext->startSubInit(INIT_CONTEXT_MAIN); EXPECT_NE(ret, 0); ret = subContext->executeCmdInSubInit(INIT_CONTEXT_CHIPSET, nullptr, nullptr); diff --git a/test/unittest/modules/sysevent_unittest.cpp b/test/unittest/modules/sysevent_unittest.cpp index 4aeec7c69f23abdbfccf6a77eab9c1fb3455c89c..51c8ab359f729b67363283eec568b7f4ca979f5a 100644 --- a/test/unittest/modules/sysevent_unittest.cpp +++ b/test/unittest/modules/sysevent_unittest.cpp @@ -17,6 +17,7 @@ #include #include "bootevent.h" +#include "parameter.h" #include "init_param.h" #include "init_utils.h" #include "list.h" @@ -111,9 +112,8 @@ HWTEST_F(SysEventUnitTest, SysEventTest_003, TestSize.Level1) HWTEST_F(SysEventUnitTest, SysEventTest_004, TestSize.Level1) { struct timespec curr = {0}; - if (clock_gettime(CLOCK_MONOTONIC, &curr) != 0) { - return; - } + int ret = clock_gettime(CLOCK_MONOTONIC, &curr); + ASSERT_EQ(ret, 0); StartupTimeEvent startupTime = {}; startupTime.event.type = STARTUP_TIME; startupTime.totalTime = curr.tv_sec; @@ -128,9 +128,8 @@ HWTEST_F(SysEventUnitTest, SysEventTest_004, TestSize.Level1) HWTEST_F(SysEventUnitTest, SysEventTest_005, TestSize.Level1) { struct timespec curr = {0}; - if (clock_gettime(CLOCK_MONOTONIC, &curr) != 0) { - return; - } + int ret = clock_gettime(CLOCK_MONOTONIC, &curr); + ASSERT_EQ(ret, 0); StartupTimeEvent startupTime = {}; startupTime.event.type = STARTUP_EVENT_MAX; startupTime.totalTime = curr.tv_sec; @@ -155,4 +154,19 @@ HWTEST_F(SysEventUnitTest, SysEventTest_007, TestSize.Level1) EXPECT_EQ(ret, 0); printf("SysEventTest_007:%d\n", ret); } + +HWTEST_F(SysEventUnitTest, SysEventTest_008, TestSize.Level1) +{ + char key1[] = "persist.startup.bootcount"; + char value1[32] = {0}; + char value2[32] = {0}; + char defValue1[] = "value of key not exist..."; + int ret = GetParameter(key1, defValue1, value1, 32); + EXPECT_NE(ret, static_cast(strlen(defValue1))); + UpdateBootCount(); + ret = GetParameter(key1, defValue1, value2, 32); + printf("value1: '%s'\n", value1); + printf("value2: '%s'\n", value2); + EXPECT_NE(0, strcmp(value1, value2)); +} } // namespace init_ut diff --git a/test/unittest/param/atomic_unittest.cpp b/test/unittest/param/atomic_unittest.cpp index 74ed7ffb69c931dad5adfc6226c1d2655469c90f..eccea4afa080c3834c9ef004d389bdbba91203fd 100644 --- a/test/unittest/param/atomic_unittest.cpp +++ b/test/unittest/param/atomic_unittest.cpp @@ -95,6 +95,7 @@ static void *TestReadData(void *args) while (data < MAX_NUM) { uint32_t commitId = TestReadCommitId(&g_testData); data = TestReadParamValue(&g_testData, &commitId); + EXPECT_GT(data, 0); printf("[ %d] TestReadData data: %d commit: %d \n", gettid(), data, commitId); usleep(10); // 10 wait } diff --git a/test/unittest/param/param_unittest.cpp b/test/unittest/param/param_unittest.cpp index 812c85b30ba2a511006c78127f5b0c4a6ebcf847..00dcbe921942905a32a98570a116e3630fa46635 100644 --- a/test/unittest/param/param_unittest.cpp +++ b/test/unittest/param/param_unittest.cpp @@ -496,10 +496,7 @@ HWTEST_F(ParamUnitTest, Init_TestWorkSpace_002, TestSize.Level0) const char *spaceName = "test.workspace2"; const size_t size = strlen(spaceName) + 1; WorkSpace *workSpace = (WorkSpace *)malloc(sizeof(WorkSpace) + size); - if (workSpace == nullptr) { - EXPECT_NE(workSpace, nullptr); - return; - } + ASSERT_NE(workSpace, nullptr); workSpace->flags = 0; workSpace->area = nullptr; int ret = PARAM_STRCPY(workSpace->fileName, size, spaceName); diff --git a/test/unittest/param/watcher_proxy_unittest.cpp b/test/unittest/param/watcher_proxy_unittest.cpp index 08534aa316c9d25f04f4462bad4e1d9ae6d70d49..dd09cc740e245c107677e029a61ea35d82676003 100644 --- a/test/unittest/param/watcher_proxy_unittest.cpp +++ b/test/unittest/param/watcher_proxy_unittest.cpp @@ -232,6 +232,7 @@ public: int TestInvalid(const std::string &keyPrefix) { WatcherManagerPtr watcherManager = GetWatcherManager(); + EXPECT_NE(watcherManager, nullptr); WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to get manager"); MessageParcel data; MessageParcel reply; diff --git a/test/unittest/syspara/syspara_unittest.cpp b/test/unittest/syspara/syspara_unittest.cpp index 9cc6b76dd2999a39ee7ce267fe6c2fc91b443db9..48e013a6ebfca2137375d7bfd0dae72812230bae 100644 --- a/test/unittest/syspara/syspara_unittest.cpp +++ b/test/unittest/syspara/syspara_unittest.cpp @@ -169,6 +169,8 @@ HWTEST_F(SysparaUnitTest, parameterTest001_3, TestSize.Level0) EXPECT_STRNE(GetBuildHost(), nullptr); EXPECT_STRNE(GetBuildTime(), nullptr); EXPECT_STRNE(GetBuildRootHash(), nullptr); + EXPECT_STRNE(GetChipType(), nullptr); + EXPECT_GT(GetBootCount(), -1); } HWTEST_F(SysparaUnitTest, parameterTest002, TestSize.Level0) diff --git a/test/unittest/ueventd/ueventd_event_unittest.cpp b/test/unittest/ueventd/ueventd_event_unittest.cpp index 465ca7ac380aefa18d66988c7f65338a10344ee7..3df7f1bcf5d898d41bf2cbce4aa449a1f13e822b 100644 --- a/test/unittest/ueventd/ueventd_event_unittest.cpp +++ b/test/unittest/ueventd/ueventd_event_unittest.cpp @@ -532,6 +532,20 @@ HWTEST_F(UeventdEventUnitTest, Init_UeventdEventUnitTest_HandleUsbDevicesWithBus EXPECT_TRUE(exist); } +HWTEST_F(UeventdEventUnitTest, Init_UeventdEventUnitTest_HandleDevicesWithInputEvent001, TestSize.Level1) +{ + struct Uevent uevent = { + .subsystem = "input", + .syspath = "/devices/platform/fingerprint/input", + .deviceName = "event30", + .major = 8, + .minor = 9, + }; + HandleOtherDeviceEvent(&uevent); + auto exist = IsFileExist("/dev/input/event30"); + EXPECT_TRUE(exist); +} + HWTEST_F(UeventdEventUnitTest, Init_UeventdEventUnitTest_Handle001, TestSize.Level1) { char path[] = {"/data/ueventd"}; diff --git a/ueventd/etc/ueventd.config b/ueventd/etc/ueventd.config index ab7a03e2f4395e599be276ab9ad390cdbc04b0ce..10668960a26fedc793ec75f47bd10e8e69d0582d 100644 --- a/ueventd/etc/ueventd.config +++ b/ueventd/etc/ueventd.config @@ -21,7 +21,7 @@ /dev/input/event* 0660 0 input /dev/input/mice 0660 0 input /dev/input/mouse0 0660 0 input -/dev/snd/timer 0660 1000 1005 +/dev/snd/timer 0660 system audio /dev/zero 0666 0 0 /dev/full 0666 0 0 /dev/ptmx 0666 0 0 @@ -32,36 +32,36 @@ /dev/pmsg0 0222 0 1007 /dev/jpeg 0666 1000 1003 /dev/vinput 0660 1000 1004 -/dev/mmz_userdev 0644 1000 1005 +/dev/mmz_userdev 0644 system system /dev/graphics/fb0 0660 1000 1003 -/dev/mem 0660 1000 1005 +/dev/mem 0660 system system /dev/ion 0664 1000 1000 /dev/btusb0 0660 1002 1002 /dev/uhid 0660 3011 3011 -/dev/tc_ns_client 0660 1000 1005 +/dev/tc_ns_client 0660 system system /dev/rtk_btusb 0660 1002 0 -/dev/sil9293 0660 1000 1005 +/dev/sil9293 0660 system system /dev/stpbt 0660 1002 1001 -/dev/avs 0660 1000 1005 -/dev/gdc 0660 1000 1005 -/dev/hdmi 0660 1000 1005 -/dev/hi_mipi 0660 1000 1005 -/dev/hi_mipi_tx 0660 1000 1005 +/dev/avs 0660 system system +/dev/gdc 0660 system system +/dev/hdmi 0660 system system +/dev/hi_mipi 0660 system system +/dev/hi_mipi_tx 0660 system system /dev/hi_tde 0644 1000 1003 /dev/isp_dev 0660 1000 1006 -/dev/match 0660 1000 1005 -/dev/photo 0660 1000 1005 -/dev/rect 0660 1000 1005 -/dev/rgn 0660 1000 1005 -/dev/sys 0660 1000 1005 -/dev/vb 0666 1000 1005 -/dev/vdec 0666 1000 1005 -/dev/venc 0666 1000 1005 -/dev/vi 0660 1000 1005 -/dev/vo 0660 1000 1005 -/dev/vpss 0660 1000 1005 +/dev/match 0660 system system +/dev/photo 0660 system system +/dev/rect 0660 system system +/dev/rgn 0660 system system +/dev/sys 0660 system system +/dev/vb 0666 system system +/dev/vdec 0666 system system +/dev/venc 0666 system system +/dev/vi 0660 system system +/dev/vo 0660 system system +/dev/vpss 0660 system system /dev/i2c-* 0660 1000 1006 -/dev/vgs 0666 1000 1005 +/dev/vgs 0666 system system /dev/dri/card0 0666 0 1003 /dev/dri/card0-DSI-1 0666 0 1003 /dev/dri/card0-HDMI-A-1 0666 0 1003 diff --git a/ueventd/ueventd_device_handler.c b/ueventd/ueventd_device_handler.c index 906b4018206a2b83a473513cc5a0b1232199505c..3758cd0855c482143c98779fae3c6f516b695cf1 100644 --- a/ueventd/ueventd_device_handler.c +++ b/ueventd/ueventd_device_handler.c @@ -505,29 +505,6 @@ void HandleBlockDeviceEvent(const struct Uevent *uevent) HandleDeviceNode(uevent, deviceNode, isBlock); } -static int SplitUsbDeviceNode(const struct Uevent *uevent, char *deviceNode) -{ - if (uevent->deviceName != NULL) { - if (snprintf_s(deviceNode, DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1, "/dev/%s", uevent->deviceName) == -1) { - INIT_LOGE("Make device file for device [%d : %d]", uevent->major, uevent->minor); - return -1; - } - return 0; - } else { - if (uevent->busNum < 0 || uevent->devNum < 0) { - // usb device should always report bus number and device number. - INIT_LOGE("usb device with invalid bus number or device number"); - return -1; - } - if (snprintf_s(deviceNode, DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1, - "/dev/bus/usb/%03d/%03d", uevent->busNum, uevent->devNum) == -1) { - INIT_LOGE("Make usb device node for device [%d : %d]", uevent->busNum, uevent->devNum); - return 0; - } - return 0; - } -} - void HandleOtherDeviceEvent(const struct Uevent *uevent) { if (uevent == NULL || uevent->subsystem == NULL || uevent->syspath == NULL) { @@ -561,8 +538,21 @@ void HandleOtherDeviceEvent(const struct Uevent *uevent) // if usb devices report DEVNAME, just create device node. // otherwise, create deviceNode with bus number and device number. if (STRINGEQUAL(uevent->subsystem, "usb")) { - if (SplitUsbDeviceNode(uevent, deviceNode) != 0) { - return; + if (uevent->deviceName != NULL) { + if (snprintf_s(deviceNode, DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1, "/dev/%s", uevent->deviceName) == -1) { + INIT_LOGE("Make device file for device [%d : %d]", uevent->major, uevent->minor); + return; + } + } else { + if (uevent->busNum < 0 || uevent->devNum < 0) { + // usb device should always report bus number and device number. + INIT_LOGE("usb device with invalid bus number or device number"); + return; + } + if (snprintf_s(deviceNode, DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1, + "/dev/bus/usb/%03d/%03d", uevent->busNum, uevent->devNum) == -1) { + INIT_LOGE("Make usb device node for device [%d : %d]", uevent->busNum, uevent->devNum); + } } } else if (STARTSWITH(uevent->subsystem, "usb")) { // Other usb devies, do not handle it.