Merge pull request !3185 from 杨浩/0926ut
This commit is contained in:
openharmony_ci 2024-09-27 06:11:55 +00:00 committed by Gitee
commit 507255516f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 479 additions and 34 deletions

View File

@ -38,7 +38,7 @@ struct extheader_v1 {
uint64_t part_size;
};
static void AllocDmName(const char *name, char *nameRofs, const uint64_t nameRofsLen,
INIT_STATIC void AllocDmName(const char *name, char *nameRofs, const uint64_t nameRofsLen,
char *nameExt4, const uint64_t nameExt4Len)
{
if (snprintf_s(nameRofs, nameRofsLen, nameRofsLen - 1, "%s_erofs", name) < 0) {
@ -69,7 +69,7 @@ static void AllocDmName(const char *name, char *nameRofs, const uint64_t nameRof
BEGET_LOGI("alloc dm namerofs:[%s], nameext4:[%s]", nameRofs, nameExt4);
}
static uint64_t LookupErofsEnd(const char *dev)
INIT_STATIC uint64_t LookupErofsEnd(const char *dev)
{
int fd = -1;
fd = open(dev, O_RDONLY | O_LARGEFILE);
@ -102,7 +102,7 @@ static uint64_t LookupErofsEnd(const char *dev)
return erofsSize;
}
static uint64_t GetImgSize(const char *dev, uint64_t offset)
INIT_STATIC uint64_t GetImgSize(const char *dev, uint64_t offset)
{
int fd = -1;
fd = open(dev, O_RDONLY | O_LARGEFILE);
@ -134,7 +134,7 @@ static uint64_t GetImgSize(const char *dev, uint64_t offset)
return header.part_size;
}
static uint64_t GetFsSize(int fd)
INIT_STATIC uint64_t GetFsSize(int fd)
{
struct stat st;
if (fstat(fd, &st) == -1) {
@ -164,7 +164,7 @@ static uint64_t GetFsSize(int fd)
return size;
}
static uint64_t GetBlockSize(const char *dev)
INIT_STATIC uint64_t GetBlockSize(const char *dev)
{
int fd = -1;
fd = open(dev, O_RDONLY | O_LARGEFILE);
@ -179,7 +179,7 @@ static uint64_t GetBlockSize(const char *dev)
}
/* 字节对齐函数基于alignment进行字节对齐 */
static uint64_t AlignTo(uint64_t base, uint64_t alignment)
INIT_STATIC uint64_t AlignTo(uint64_t base, uint64_t alignment)
{
if (alignment == 0) {
return base;
@ -187,7 +187,7 @@ static uint64_t AlignTo(uint64_t base, uint64_t alignment)
return (((base - 1) / alignment + 1) * alignment);
}
static int GetMapperAddr(const char *dev, uint64_t *start, uint64_t *length)
INIT_STATIC int GetMapperAddr(const char *dev, uint64_t *start, uint64_t *length)
{
/* 获取EROFS文件系统大小 */
*start = LookupErofsEnd(dev);
@ -230,7 +230,7 @@ static int GetMapperAddr(const char *dev, uint64_t *start, uint64_t *length)
return 0;
}
static int ConstructLinearTarget(DmVerityTarget *target, const char *dev, uint64_t mapStart, uint64_t mapLength)
INIT_STATIC int ConstructLinearTarget(DmVerityTarget *target, const char *dev, uint64_t mapStart, uint64_t mapLength)
{
if (target == NULL || dev == NULL) {
return -1;
@ -253,7 +253,7 @@ static int ConstructLinearTarget(DmVerityTarget *target, const char *dev, uint64
return 0;
}
static void DestoryLinearTarget(DmVerityTarget *target)
INIT_STATIC void DestoryLinearTarget(DmVerityTarget *target)
{
if (target != NULL && target->paras != NULL) {
free(target->paras);
@ -261,7 +261,7 @@ static void DestoryLinearTarget(DmVerityTarget *target)
}
}
static int GetOverlayDevice(FstabItem *item, char *devRofs, const uint32_t devRofsLen,
INIT_STATIC int GetOverlayDevice(FstabItem *item, char *devRofs, const uint32_t devRofsLen,
char *devExt4, const uint32_t devExt4Len)
{
uint64_t mapStart;
@ -312,7 +312,7 @@ exit:
return rc;
}
static int MountRofsDevice(const char *dev, const char *mnt)
INIT_STATIC int MountRofsDevice(const char *dev, const char *mnt)
{
int rc = 0;
int retryCount = 3;
@ -382,7 +382,7 @@ int MountExt4Device(const char *dev, const char *mnt, bool isFirstMount)
return ret;
}
static void UnlinkMountPoint(const char *mountPoint)
INIT_STATIC void UnlinkMountPoint(const char *mountPoint)
{
struct stat statInfo;
if (!lstat(mountPoint, &statInfo)) {
@ -392,7 +392,7 @@ static void UnlinkMountPoint(const char *mountPoint)
}
}
static int MountPartitionDevice(FstabItem *item, const char *devRofs, const char *devExt4)
INIT_STATIC int MountPartitionDevice(FstabItem *item, const char *devRofs, const char *devExt4)
{
UnlinkMountPoint(item->mountPoint);
if (mkdir(item->mountPoint, MODE_MKDIR) && (errno != EEXIST)) {

View File

@ -22,15 +22,6 @@
#include "fs_manager/fs_manager.h"
#include "erofs_remount_overlay.h"
#define MODEM_DRIVER_MNT_PATH "/vendor/modem/modem_driver"
#define MODEM_VENDOR_MNT_PATH "/vendor/modem/modem_vendor"
#define MODEM_FW_MNT_PATH "/vendor/modem/modem_fw"
#define MODEM_DRIVER_EXCHANGE_PATH "/mnt/driver_exchange"
#define MODEM_VENDOR_EXCHANGE_PATH "/mnt/vendor_exchange"
#define MODEM_FW_EXCHANGE_PATH "/mnt/fw_exchange"
#define REMOUNT_RESULT_PATH "/data/service/el1/startup/remount/"
#define REMOUNT_RESULT_FLAG "/data/service/el1/startup/remount/remount.result.done"
int GetRemountResult(void)
{
int fd = open(REMOUNT_RESULT_FLAG, O_RDONLY);
@ -87,7 +78,7 @@ void SetRemountResultFlag(bool result)
BEGET_LOGI("set remount result flag successfully");
}
static int Modem2Exchange(const char *modemPath, const char *exchangePath)
INIT_STATIC int Modem2Exchange(const char *modemPath, const char *exchangePath)
{
int ret;
ret = mkdir(exchangePath, MODE_MKDIR);
@ -107,7 +98,7 @@ static int Modem2Exchange(const char *modemPath, const char *exchangePath)
return ret;
}
static int Exchange2Modem(const char *modemPath, const char *exchangePath)
INIT_STATIC int Exchange2Modem(const char *modemPath, const char *exchangePath)
{
int ret;
struct stat statInfo;

View File

@ -16,6 +16,7 @@
#ifndef EROFS_MOUNT_OVERLAY_H
#define EROFS_MOUNT_OVERLAY_H
#include "fs_manager/fs_manager.h"
#include "erofs_overlay_common.h"
#ifdef __cplusplus

View File

@ -24,6 +24,15 @@ extern "C" {
#endif
#endif
#define MODEM_DRIVER_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/modem/modem_driver"
#define MODEM_VENDOR_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/modem/modem_vendor"
#define MODEM_FW_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/modem/modem_fw"
#define MODEM_DRIVER_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/driver_exchange"
#define MODEM_VENDOR_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/vendor_exchange"
#define MODEM_FW_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/fw_exchange"
#define REMOUNT_RESULT_PATH STARTUP_INIT_UT_PATH"/data/service/el1/startup/remount/"
#define REMOUNT_RESULT_FLAG STARTUP_INIT_UT_PATH"/data/service/el1/startup/remount/remount.result.done"
#define REMOUNT_NONE 0
#define REMOUNT_SUCC 1
#define REMOUNT_FAIL 2

View File

@ -24,6 +24,16 @@
#include "beget_ext.h"
#ifndef STARTUP_INIT_TEST
#ifndef INIT_STATIC
#define INIT_STATIC static
#endif
#else
#ifndef INIT_STATIC
#define INIT_STATIC
#endif
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {

View File

@ -35,7 +35,7 @@
#define ROOT_MOUNT_DIR "/"
#define SYSTEM_DIR "/usr"
static bool MntNeedRemount(const char *mnt)
INIT_STATIC bool MntNeedRemount(const char *mnt)
{
char *remountPath[] = {
"/", "/vendor", "/sys_prod", "/chip_prod", "/preload", "/cust", "/version", "/patch_hw"
@ -48,7 +48,7 @@ static bool MntNeedRemount(const char *mnt)
return false;
}
static bool IsSkipRemount(const struct mntent mentry)
INIT_STATIC bool IsSkipRemount(const struct mntent mentry)
{
if (mentry.mnt_type == NULL || mentry.mnt_dir == NULL) {
return true;
@ -66,7 +66,7 @@ static bool IsSkipRemount(const struct mntent mentry)
return false;
}
static int ExecCommand(int argc, char **argv)
INIT_STATIC int ExecCommand(int argc, char **argv)
{
INIT_CHECK(!(argc == 0 || argv == NULL || argv[0] == NULL), return -1);
@ -87,7 +87,7 @@ static int ExecCommand(int argc, char **argv)
return WEXITSTATUS(status);
}
static int GetDevSize(const char *fsBlkDev, uint64_t *devSize)
INIT_STATIC int GetDevSize(const char *fsBlkDev, uint64_t *devSize)
{
int fd = -1;
fd = open(fsBlkDev, O_RDONLY);
@ -106,7 +106,7 @@ static int GetDevSize(const char *fsBlkDev, uint64_t *devSize)
return 0;
}
static int FormatExt4(const char *fsBlkDev, const char *fsMntPoint)
INIT_STATIC int FormatExt4(const char *fsBlkDev, const char *fsMntPoint)
{
uint64_t devSize;
int ret = GetDevSize(fsBlkDev, &devSize);
@ -143,21 +143,21 @@ static int FormatExt4(const char *fsBlkDev, const char *fsMntPoint)
return 0;
}
static void OverlayRemountPre(const char *mnt)
INIT_STATIC void OverlayRemountPre(const char *mnt)
{
if (strcmp(mnt, MNT_VENDOR) == 0) {
OverlayRemountVendorPre();
}
}
static void OverlayRemountPost(const char *mnt)
INIT_STATIC void OverlayRemountPost(const char *mnt)
{
if (strcmp(mnt, MNT_VENDOR) == 0) {
OverlayRemountVendorPost();
}
}
static bool DoRemount(struct mntent *mentry, bool *result)
INIT_STATIC bool DoRemount(struct mntent *mentry, bool *result)
{
int devNum = 0;
char *mnt = NULL;
@ -211,7 +211,7 @@ static bool DoRemount(struct mntent *mentry, bool *result)
return true;
}
static bool DirectoryExists(const char *path)
INIT_STATIC bool DirectoryExists(const char *path)
{
struct stat sb;
return stat(path, &sb) != -1 && S_ISDIR(sb.st_mode);
@ -255,7 +255,7 @@ int RootOverlaySetup(void)
return 0;
}
static bool DoSystemRemount(struct mntent *mentry, bool *result)
INIT_STATIC bool DoSystemRemount(struct mntent *mentry, bool *result)
{
int devNum = 0;
int ret = 0;

View File

@ -35,10 +35,14 @@ extern "C" {
#define UNUSED(x) (void)(x)
#ifndef STARTUP_INIT_TEST
#ifndef INIT_STATIC
#define INIT_STATIC static
#endif
#else
#ifndef INIT_STATIC
#define INIT_STATIC
#endif
#endif
void SystemInit(void);
void LogInit(void);

View File

@ -50,6 +50,9 @@ ohos_unittest("init_unittest") {
"//base/startup/init/interfaces/innerkits/fd_holder/fd_holder.c",
"//base/startup/init/interfaces/innerkits/fd_holder/fd_holder_internal.c",
"//base/startup/init/interfaces/innerkits/file/init_file.c",
"//base/startup/init/interfaces/innerkits/fs_manager/erofs_overlay/erofs_mount_overlay.c",
"//base/startup/init/interfaces/innerkits/fs_manager/erofs_overlay/erofs_overlay_common.c",
"//base/startup/init/interfaces/innerkits/fs_manager/erofs_overlay/erofs_remount_overlay.c",
"//base/startup/init/interfaces/innerkits/fs_manager/fstab.c",
"//base/startup/init/interfaces/innerkits/fs_manager/fstab_mount.c",
"//base/startup/init/interfaces/innerkits/fs_manager/switch_root/switch_root.c",
@ -58,6 +61,7 @@ ohos_unittest("init_unittest") {
"//base/startup/init/interfaces/innerkits/syspara/param_comm.c",
"//base/startup/init/interfaces/innerkits/syspara/parameter.c",
"//base/startup/init/interfaces/innerkits/syspara/sysversion.c",
"//base/startup/init/remount/remount_overlay.c",
"//base/startup/init/services/begetctl/begetctl_cmd.c",
"//base/startup/init/services/begetctl/bootchart_cmd.c",
"//base/startup/init/services/begetctl/dump_service.c",
@ -172,6 +176,10 @@ ohos_unittest("init_unittest") {
include_dirs = [
"//base/startup/init/interfaces/innerkits/fs_manager/switch_root/include",
"//base/startup/init/interfaces/innerkits/fs_manager/erofs_overlay/include",
"//base/startup/init/interfaces/innerkits/fs_manager/libfs_dm/include",
"//base/startup/init/interfaces/innerkits/include/fs_manager",
"//base/startup/init/remount/include",
]
defines = []
@ -195,6 +203,9 @@ ohos_unittest("init_unittest") {
sources += [
"begetctl/begetctl_unittest.cpp",
"deviceinfo/DeviceInfoUnittest.cpp",
"fs_manager/erofs/erofs_common_unittest.cpp",
"fs_manager/erofs/erofs_mount_unittest.cpp",
"fs_manager/erofs/erofs_remount_unittest.cpp",
"init/cmds_unittest.cpp",
"init/group_unittest.cpp",
"init/init_reboot_unittest.cpp",
@ -220,6 +231,7 @@ ohos_unittest("init_unittest") {
"param/param_unittest.cpp",
"param/paramservice_unittest.cpp",
"param/trigger_unittest.cpp",
"remount/remount_overlay_unittest.cpp",
"syspara/syspara_unittest.cpp",
"ueventd/ueventd_config_unittest.cpp",
"ueventd/ueventd_event_unittest.cpp",

View File

@ -0,0 +1,102 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "erofs_overlay_common.h"
#include "securec.h"
#include "param_stub.h"
using namespace std;
using namespace testing::ext;
namespace init_ut {
class ErofsCommonOverlayUnitTest : public testing::Test {
public:
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
void SetUp(void) {};
void TearDown(void) {};
};
HWTEST_F(ErofsCommonOverlayUnitTest, Init_IsOverlayEnable_001, TestSize.Level0)
{
const char *cmdLine;
cmdLine = "test=test";
CreateTestFile(BOOT_CMD_LINE, cmdLine);
bool ret = IsOverlayEnable();
EXPECT_EQ(ret, false);
remove(BOOT_CMD_LINE);
cmdLine = "oemmode=test";
CreateTestFile(BOOT_CMD_LINE, cmdLine);
ret = IsOverlayEnable();
EXPECT_EQ(ret, false);
remove(BOOT_CMD_LINE);
cmdLine = "oemmode=test buildvariant=user";
CreateTestFile(BOOT_CMD_LINE, cmdLine);
ret = IsOverlayEnable();
EXPECT_EQ(ret, false);
remove(BOOT_CMD_LINE);
cmdLine = "oemmode=test buildvariant=eng";
CreateTestFile(BOOT_CMD_LINE, cmdLine);
ret = IsOverlayEnable();
EXPECT_EQ(ret, true);
int ret2 = remove(BOOT_CMD_LINE);
PrepareCmdLineData();
}
HWTEST_F(ErofsCommonOverlayUnitTest, Init_IsOverlayCheckExt4_001, TestSize.Level0)
{
bool ret = CheckIsExt4(STARTUP_INIT_UT_PATH "/data/notexistfile", 0);
EXPECT_EQ(ret, false);
const char *fileName = STARTUP_INIT_UT_PATH "/data/ext4_super_block";
CheckAndCreateDir(fileName);
ret = CheckIsExt4(fileName, 0);
EXPECT_EQ(ret, false);
int fd = open(fileName, O_WRONLY);
struct ext4_super_block super;
super.s_magic = EXT4_SUPER_MAGIC;
write(fd, &super, sizeof(ext4_super_block));
ret = CheckIsExt4(fileName, 0);
EXPECT_EQ(ret, false);
write(fd, &super, sizeof(ext4_super_block));
ret = CheckIsExt4(fileName, 0);
remove(fileName);
}
HWTEST_F(ErofsCommonOverlayUnitTest, Init_IsOverlayCheckErofs_001, TestSize.Level0)
{
bool ret = CheckIsErofs(STARTUP_INIT_UT_PATH"/data/notexistfile");
EXPECT_EQ(ret, false);
const char *fileName = STARTUP_INIT_UT_PATH "/data/erofsfile";
CheckAndCreateDir(fileName);
ret = CheckIsErofs(fileName);
EXPECT_EQ(ret, false);
int fd = open(fileName, O_WRONLY);
struct ext4_super_block super;
super.s_magic = EXT4_SUPER_MAGIC;
write(fd, &super, sizeof(ext4_super_block));
ret = CheckIsErofs(fileName);
EXPECT_EQ(ret, false);
write(fd, &super, sizeof(ext4_super_block));
ret = CheckIsErofs(fileName);
remove(fileName);
}
}

View File

@ -0,0 +1,68 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "erofs_mount_overlay.h"
#include "securec.h"
#include "param_stub.h"
#include "init_utils.h"
using namespace std;
using namespace testing::ext;
namespace init_ut {
class ErofsMountUnitTest : public testing::Test {
public:
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
void SetUp(void) {};
void TearDown(void) {};
};
HWTEST_F(ErofsMountUnitTest, Init_AllocDmName_001, TestSize.Level0)
{
char nameExt4[MAX_BUFFER_LEN] = {0};
char nameRofs[MAX_BUFFER_LEN] = {0};
const char *devName = STARTUP_INIT_UT_PATH"/data/erofs/mount/rofs";
AllocDmName(devName, nameRofs, MAX_BUFFER_LEN, nameExt4, MAX_BUFFER_LEN);
}
HWTEST_F(ErofsMountUnitTest, Init_LookupErofsEnd_001, TestSize.Level0)
{
const char *devMount = STARTUP_INIT_UT_PATH"/data/erofs/mount/lookup";
int ret = LookupErofsEnd(devMount);
EXPECT_EQ(ret, 0);
mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
CheckAndCreatFile(devMount, mode);
int fd = open(devMount, O_WRONLY | O_TRUNC);
void *data = calloc(1, EROFS_SUPER_BLOCK_START_POSITION);
ret = write(fd, data, EROFS_SUPER_BLOCK_START_POSITION);
EXPECT_EQ(ret, EROFS_SUPER_BLOCK_START_POSITION);
close(fd);
free(data);
ret = LookupErofsEnd(devMount);
EXPECT_EQ(ret, 0);
struct erofs_super_block sb;
sb.magic = EROFS_SUPER_MAGIC;
sb.blocks = 1;
data = calloc(1, sizeof(sb));
memcpy_s(data, EROFS_SUPER_BLOCK_START_POSITION, &sb, sizeof(sb));
fd = open(devMount, O_WRONLY | O_APPEND);
ret = write(fd, data, sizeof(sb));
EXPECT_EQ(ret, sizeof(sb));
close(fd);
free(data);
ret = LookupErofsEnd(devMount);
EXPECT_NE(ret, 0);
remove(devMount);
}
}

View File

@ -0,0 +1,109 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "erofs_remount_overlay.h"
#include "securec.h"
#include "param_stub.h"
#include "fs_manager.h"
using namespace std;
using namespace testing::ext;
namespace init_ut {
class ErofsRemountUnitTest : public testing::Test {
public:
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
void SetUp(void) {};
void TearDown(void) {};
};
HWTEST_F(ErofsRemountUnitTest, Init_GetRemountResult_001, TestSize.Level0)
{
const char *cmdLine;
rmdir(REMOUNT_RESULT_PATH);
SetRemountResultFlag(true);
CheckAndCreateDir(REMOUNT_RESULT_FLAG);
SetRemountResultFlag(false);
SetRemountResultFlag(true);
rmdir(REMOUNT_RESULT_PATH);
}
HWTEST_F(ErofsRemountUnitTest, Init_Modem2Exchange_001, TestSize.Level0)
{
const char *srcPath = STARTUP_INIT_UT_PATH"/data/modem2Exchange";
const char *targetPath = STARTUP_INIT_UT_PATH"/data/modem2Exchangetarget";
CheckAndCreateDir(srcPath);
CheckAndCreateDir(targetPath);
SetStubResult(STUB_MOUNT, -1);
int ret = Modem2Exchange(srcPath, targetPath);
EXPECT_EQ(ret, -1);
SetStubResult(STUB_MOUNT, 0);
ret = Modem2Exchange(srcPath, targetPath);
EXPECT_EQ(ret, 0);
rmdir(srcPath);
rmdir(targetPath);
}
HWTEST_F(ErofsRemountUnitTest, Init_ExchangeToMode_001, TestSize.Level0)
{
const char *srcPath = STARTUP_INIT_UT_PATH"/data/Exchange2Mode";
const char *targetPath = STARTUP_INIT_UT_PATH"/data/Exchange2Modetarget";
int ret = Exchange2Modem(srcPath, targetPath);
EXPECT_EQ(ret, 0);
CheckAndCreateDir(srcPath);
CheckAndCreateDir(targetPath);
SetStubResult(STUB_MOUNT, 0);
SetStubResult(STUB_UMOUNT, 0);
ret = Exchange2Modem(srcPath, targetPath);
EXPECT_EQ(ret, 0);
CheckAndCreateDir(targetPath);
SetStubResult(STUB_MOUNT, -1);
SetStubResult(STUB_UMOUNT, -1);
Exchange2Modem(srcPath, targetPath);
EXPECT_EQ(ret, 0);
rmdir(srcPath);
rmdir(targetPath);
}
HWTEST_F(ErofsRemountUnitTest, Init_OverlayRemountVendorPre_001, TestSize.Level0)
{
CheckAndCreateDir(MODEM_DRIVER_MNT_PATH);
CheckAndCreateDir(MODEM_VENDOR_MNT_PATH);
CheckAndCreateDir(MODEM_FW_MNT_PATH);
OverlayRemountVendorPre();
rmdir(MODEM_DRIVER_MNT_PATH);
rmdir(MODEM_VENDOR_MNT_PATH);
rmdir(MODEM_FW_MNT_PATH);
OverlayRemountVendorPost();
}
HWTEST_F(ErofsRemountUnitTest, Init_RemountOverlayTest_001, TestSize.Level0)
{
int ret = RemountOverlay();
EXPECT_EQ(ret, 0);
}
}

View File

@ -75,6 +75,8 @@ typedef enum {
STUB_SPRINTF,
STUB_MOUNT,
STUB_MKNODE,
STUB_EXECV,
STUB_UMOUNT,
STUB_MAX
} STUB_TYPE;
void SetStubResult(STUB_TYPE type, int result);
@ -97,7 +99,26 @@ int DoRebootShutdown(int id, const char *name, int argc, const char **argv);
int DoRebootFlashed(int id, const char *name, int argc, const char **argv);
int DoRebootOther(int id, const char *name, int argc, const char **argv);
//remount_overlay
bool MntNeedRemount(const char *mnt);
bool IsSkipRemount(const struct mntent mentry);
int ExecCommand(int argc, char **argv);
int GetDevSize(const char *fsBlkDev, uint64_t *devSize);
int FormatExt4(const char *fsBlkDev, const char *fsMntPoint);
void OverlayRemountPre(const char *mnt);
void OverlayRemountPost(const char *mnt);
bool DoRemount(struct mntent *mentry, bool *result);
bool DirectoryExists(const char *path);
bool DoSystemRemount(struct mntent *mentry, bool *result);
//remount
int Modem2Exchange(const char *modemPath, const char *exchangePath);
int Exchange2Modem(const char *modemPath, const char *exchangePath);
SubInitContext *GetSubInitContext(InitContextType type);
uint64_t LookupErofsEnd(const char *dev);
void AllocDmName(const char *name, char *nameRofs, const uint64_t nameRofsLen,
char *nameExt4, const uint64_t nameExt4Len);
#endif
#ifdef __cplusplus
#if __cplusplus

View File

@ -0,0 +1,117 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "remount_overlay.h"
#include "securec.h"
#include "param_stub.h"
#include "mntent.h"
using namespace std;
using namespace testing::ext;
namespace init_ut {
class RemountOverlayUnitTest : public testing::Test {
public:
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
void SetUp(void) {};
void TearDown(void) {};
};
HWTEST_F(RemountOverlayUnitTest, Init_MntNeedRemountTest_001, TestSize.Level0)
{
char *path = "/test";
bool ret = MntNeedRemount(path);
EXPECT_EQ(ret, false);
char *path2 = "/";
ret = MntNeedRemount(path2);
EXPECT_EQ(ret, true);
}
HWTEST_F(RemountOverlayUnitTest, Init_IsSkipRemountTest_001, TestSize.Level0)
{
struct mntent mentry;
bool ret = IsSkipRemount(mentry);
EXPECT_EQ(ret, true);
mentry.mnt_type = "ufs";
mentry.mnt_dir = "test";
ret = IsSkipRemount(mentry);
EXPECT_EQ(ret, true);
mentry.mnt_dir = "/";
ret = IsSkipRemount(mentry);
EXPECT_EQ(ret, true);
mentry.mnt_type = "er11ofs";
ret = IsSkipRemount(mentry);
EXPECT_EQ(ret, true);
mentry.mnt_type = "erofs";
mentry.mnt_fsname = "/dev/block/ndm-";
ret = IsSkipRemount(mentry);
EXPECT_EQ(ret, true);
mentry.mnt_fsname = "/dev/block/dm-1";
ret = IsSkipRemount(mentry);
EXPECT_EQ(ret, false);
}
HWTEST_F(RemountOverlayUnitTest, Init_ExecCommand_001, TestSize.Level0)
{
char *nullArgv[] = {NULL}; // A valid command
int result = ExecCommand(0, nullArgv);
EXPECT_NE(result, 0); // Expect success
char *validArgv[] = {"/bin/ls", NULL}; // A valid command
result = ExecCommand(1, validArgv);
EXPECT_NE(result, 0); // Expect success
char *invalidArgv[] = {"/notexit/ls", NULL}; // A valid command
result = ExecCommand(1, invalidArgv);
EXPECT_NE(result, 0); // Expect success
}
HWTEST_F(RemountOverlayUnitTest, Init_GetDevSizeTest_001, TestSize.Level0)
{
const char *fileName = "";
int ret = GetDevSize(fileName, NULL);
EXPECT_EQ(ret, -1);
fileName = STARTUP_INIT_UT_PATH "/data/getDevSize";
CheckAndCreateDir(fileName);
ret = GetDevSize(fileName, NULL);
EXPECT_EQ(ret, -1);
uint64_t devSize;
ret = GetDevSize(fileName, &devSize);
EXPECT_NE(ret, 0);
remove(fileName);
}
HWTEST_F(RemountOverlayUnitTest, Init_FormatExt4Test_001, TestSize.Level0)
{
const char *fileName = "";
int ret = GetDevSize(fileName, NULL);
EXPECT_EQ(ret, -1);
fileName = STARTUP_INIT_UT_PATH "/data/getDevSize";
CheckAndCreateDir(fileName);
ret = GetDevSize(fileName, NULL);
EXPECT_EQ(ret, -1);
uint64_t devSize;
ret = GetDevSize(fileName, &devSize);
EXPECT_NE(ret, 0);
remove(fileName);
}
}

View File

@ -386,6 +386,7 @@ HWTEST_F(SysparaUnitTest, parameterTest0017, TestSize.Level0)
EXPECT_GT(GetDistributionOSApiVersion(), 0);
printf("distributionOS name =%s\n", GetDistributionOSReleaseType());
EXPECT_STRNE(GetDistributionOSReleaseType(), nullptr);
printf("distributionOS name =%s\n", GetDistributionOSApiName());
}
#endif