提交 bddfb1ca 编写于 作者: L laiguizhong

add unittest cases

Signed-off-by: Nlaiguizhong <laiguizhong@huawei.com>
Change-Id: I1eb7e0345be45f0c42d9f4b037efb3680db11edd
上级 1a027101
......@@ -48,7 +48,7 @@
#endif
#ifdef STARTUP_INIT_TEST
#define SANDBOX_TEST_CONFIG_FILE "/system/etc/sandbox/test-sandbox.json"
#define SANDBOX_TEST_CONFIG_FILE "/data/init_ut/test-sandbox.json"
#endif
#define SANDBOX_MOUNT_FLAGS_MS_BIND "bind"
......@@ -86,10 +86,10 @@ static const struct SandboxMountFlags g_flags[] = {
}
};
static sandbox_t g_systemSandbox;
static sandbox_t g_chipsetSandbox;
static sandbox_t g_systemSandbox = {};
static sandbox_t g_chipsetSandbox = {};
#ifdef STARTUP_INIT_TEST
static sandbox_t g_testSandbox;
static sandbox_t g_testSandbox = {};
#endif
struct SandboxMap {
......@@ -122,9 +122,7 @@ static unsigned long GetSandboxMountFlags(cJSON *item)
{
BEGET_ERROR_CHECK(item != NULL, return 0, "Invalid parameter.");
char *str = cJSON_GetStringValue(item);
if (str == NULL) {
return 0;
}
BEGET_CHECK(str != NULL, return 0);
for (size_t i = 0; i < ARRAY_LENGTH(g_flags); i++) {
if (strcmp(str, g_flags[i].flag) == 0) {
return g_flags[i].value;
......@@ -137,9 +135,7 @@ typedef int (*AddInfoToSandboxCallback)(sandbox_t *sandbox, cJSON *item, const c
static int AddMountInfoToSandbox(sandbox_t *sandbox, cJSON *item, const char *type)
{
if (sandbox == NULL || item == NULL || type == NULL) {
return -1;
}
BEGET_CHECK(!(sandbox == NULL || item == NULL || type == NULL), return -1);
char *srcPath = cJSON_GetStringValue(cJSON_GetObjectItem(item, SANDBOX_SOURCE));
BEGET_ERROR_CHECK(srcPath != NULL, return 0, "Get src-path is null");
char *dstPath = cJSON_GetStringValue(cJSON_GetObjectItem(item, SANDBOX_TARGET));
......@@ -182,13 +178,8 @@ static int AddMountInfoToSandbox(sandbox_t *sandbox, cJSON *item, const char *ty
static int AddSymbolLinksToSandbox(sandbox_t *sandbox, cJSON *item, const char *type)
{
if (sandbox == NULL || item == NULL || type == NULL) {
return -1;
}
if (strcmp(type, SANDBOX_SYMLINK_TAG) != 0) {
BEGET_LOGE("Type is not sandbox symbolLink.");
return -1;
}
BEGET_CHECK(!(sandbox == NULL || item == NULL || type == NULL), return -1);
BEGET_ERROR_CHECK(strcmp(type, SANDBOX_SYMLINK_TAG) == 0, return -1, "Type is not sandbox symbolLink.");
char *target = cJSON_GetStringValue(cJSON_GetObjectItem(item, SANDBOX_SYMLINK_TARGET));
BEGET_ERROR_CHECK(target != NULL, return 0, "Get target-name is null");
char *name = cJSON_GetStringValue(cJSON_GetObjectItem(item, SANDBOX_SYMLINK_NAME));
......@@ -211,25 +202,14 @@ static int AddSymbolLinksToSandbox(sandbox_t *sandbox, cJSON *item, const char *
static int GetSandboxInfo(sandbox_t *sandbox, cJSON *root, const char *itemName)
{
if (sandbox == NULL || root == NULL || itemName == NULL) {
BEGET_LOGE("Get sandbox mount info with invalid argument");
return -1;
}
BEGET_ERROR_CHECK(!(sandbox == NULL || root == NULL || itemName == NULL), return -1,
"Get sandbox mount info with invalid argument");
cJSON *obj = cJSON_GetObjectItem(root, itemName);
if (obj == NULL) {
BEGET_LOGE("Cannot find item \' %s \' in sandbox config", itemName);
return 0;
}
if (!cJSON_IsArray(obj)) {
BEGET_LOGE("%s with invalid type, should be array", itemName);
return 0;
}
BEGET_ERROR_CHECK(obj != NULL, return 0, "Cannot find item \' %s \' in sandbox config", itemName);
BEGET_ERROR_CHECK(cJSON_IsArray(obj), return 0, "%s with invalid type, should be array", itemName);
int counts = cJSON_GetArraySize(obj);
if (counts <= 0) {
BEGET_LOGE("Item %s array size is zero.", itemName);
return 0;
}
BEGET_ERROR_CHECK(!(counts <= 0), return 0, "Item %s array size is zero.", itemName);
AddInfoToSandboxCallback func = NULL;
if (strcmp(itemName, SANDBOX_MOUNT_PATH_TAG) == 0) {
func = AddMountInfoToSandbox;
......@@ -244,20 +224,14 @@ static int GetSandboxInfo(sandbox_t *sandbox, cJSON *root, const char *itemName)
for (int i = 0; i < counts; i++) {
cJSON *item = cJSON_GetArrayItem(obj, i);
BEGET_ERROR_CHECK(item != NULL, return -1, "Failed get json array item %d", i);
if (func(sandbox, item, itemName) < 0) {
BEGET_LOGE("Failed add info to sandbox.");
return -1;
}
BEGET_ERROR_CHECK(!(func(sandbox, item, itemName) < 0), return -1, "Failed add info to sandbox.");
}
return 0;
}
static int ParseSandboxConfig(cJSON *root, sandbox_t *sandbox)
{
if ((root == NULL) || (sandbox == NULL)) {
BEGET_LOGE("Invaild parameter.");
return -1;
}
BEGET_ERROR_CHECK(!(root == NULL || sandbox == NULL), return -1, "Invaild parameter.");
cJSON *sandboxRoot = cJSON_GetObjectItem(root, SANDBOX_ROOT_TAG);
BEGET_ERROR_CHECK(sandboxRoot != NULL, return -1,
......@@ -269,27 +243,18 @@ static int ParseSandboxConfig(cJSON *root, sandbox_t *sandbox)
BEGET_ERROR_CHECK(sandbox->rootPath != NULL, return -1,
"Get sandbox root path out of memory");
}
if (GetSandboxInfo(sandbox, root, SANDBOX_MOUNT_PATH_TAG) < 0) {
BEGET_LOGE("config info %s error", SANDBOX_MOUNT_PATH_TAG);
return -1;
}
if (GetSandboxInfo(sandbox, root, SANDBOX_MOUNT_FILE_TAG) < 0) {
BEGET_LOGE("config info %s error", SANDBOX_MOUNT_FILE_TAG);
return -1;
}
if (GetSandboxInfo(sandbox, root, SANDBOX_SYMLINK_TAG) < 0) {
BEGET_LOGE("config info %s error", SANDBOX_SYMLINK_TAG);
return -1;
}
BEGET_ERROR_CHECK(!(GetSandboxInfo(sandbox, root, SANDBOX_MOUNT_PATH_TAG) < 0), return -1,
"config info %s error", SANDBOX_MOUNT_PATH_TAG);
BEGET_ERROR_CHECK(!(GetSandboxInfo(sandbox, root, SANDBOX_MOUNT_FILE_TAG) < 0), return -1,
"config info %s error", SANDBOX_MOUNT_FILE_TAG);
BEGET_ERROR_CHECK(!(GetSandboxInfo(sandbox, root, SANDBOX_SYMLINK_TAG) < 0), return -1,
"config info %s error", SANDBOX_SYMLINK_TAG);
return 0;
}
static const struct SandboxMap *GetSandboxMapByName(const char *name)
{
if (name == NULL) {
BEGET_LOGE("Sandbox map name is NULL.");
return NULL;
}
BEGET_ERROR_CHECK(name != NULL, return NULL, "Sandbox map name is NULL.");
int len = ARRAY_LENGTH(g_map);
for (int i = 0; i < len; i++) {
if (strcmp(g_map[i].name, name) == 0) {
......@@ -301,10 +266,8 @@ static const struct SandboxMap *GetSandboxMapByName(const char *name)
static void InitSandbox(sandbox_t *sandbox, const char *sandboxConfig, const char *name)
{
if (sandbox == NULL || sandboxConfig == NULL || name == NULL) {
BEGET_LOGE("Init sandbox with invalid arguments");
return;
}
BEGET_ERROR_CHECK(!(sandbox == NULL || sandboxConfig == NULL || name == NULL), return,
"Init sandbox with invalid arguments");
if (sandbox->isCreated) {
BEGET_LOGE("Sandbox %s has created.", name);
return;
......@@ -313,15 +276,9 @@ static void InitSandbox(sandbox_t *sandbox, const char *sandboxConfig, const cha
return;
}
sandbox->ns = GetNamespaceFd("/proc/self/ns/mnt");
if (sandbox->ns < 0) {
BEGET_LOGE("Get sandbox namespace fd is failed");
return;
}
BEGET_ERROR_CHECK(!(sandbox->ns < 0), return, "Get sandbox namespace fd is failed");
if (strcpy_s(sandbox->name, MAX_BUFFER_LEN - 1, name) != 0) {
BEGET_LOGE("Failed to copy sandbox name");
return;
}
BEGET_ERROR_CHECK(strcpy_s(sandbox->name, MAX_BUFFER_LEN - 1, name) == 0, return, "Failed to copy sandbox name");
// parse json config
char *contents = ReadFileToBuf(sandboxConfig);
......@@ -346,10 +303,8 @@ static int CheckAndMakeDir(const char *dir, mode_t mode)
return 0;
} else {
if (errno == ENOENT) {
if (MakeDirRecursive(dir, mode) != 0) {
BEGET_LOGE("Failed MakeDirRecursive %s, err=%d", dir, errno);
return -1;
}
BEGET_ERROR_CHECK(MakeDirRecursive(dir, mode) == 0, return -1,
"Failed MakeDirRecursive %s, err=%d", dir, errno);
} else {
BEGET_LOGW("Failed to access mount point \' %s \', err = %d", dir, errno);
return -1;
......@@ -365,34 +320,27 @@ static int BindMount(const char *source, const char *target, unsigned long flags
errno = EINVAL;
return -1;
}
unsigned long tmpflags = flags;
mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
if (tag == SANDBOX_TAG_MOUNT_PATH) {
if (CheckAndMakeDir(target, mode) != 0) {
BEGET_LOGE("Failed make %s dir.", target);
return -1;
}
BEGET_ERROR_CHECK(CheckAndMakeDir(target, mode) == 0, return -1, "Failed make %s dir.", target);
} else if (tag == SANDBOX_TAG_MOUNT_FILE) {
if (CheckAndCreatFile(target, mode) != 0) {
BEGET_LOGE("Failed make %s file.", target);
return -1;
}
BEGET_ERROR_CHECK(CheckAndCreatFile(target, mode) == 0, return -1, "Failed make %s file.", target);
} else {
BEGET_LOGE("Tag is error.");
return -1;
}
if ((flags & MS_BIND) == 0) {
BEGET_LOGW("Not configure bind, must configure bind flag.");
flags |= MS_BIND;
}
BEGET_WARNING_CHECK((tmpflags & MS_BIND) != 0, tmpflags |= MS_BIND,
"Not configure bind, must configure bind flag.");
if ((flags & MS_REC) == 0) {
if ((tmpflags & MS_REC) == 0) {
BEGET_LOGW("Not configure rec, must configure rec flag.");
flags |= MS_REC;
tmpflags |= MS_REC;
}
// do mount
if (mount(source, target, NULL, flags, NULL) != 0) {
if (mount(source, target, NULL, tmpflags, NULL) != 0) {
BEGET_LOGE("Failed to bind mount \' %s \' to \' %s \', err = %d", source, target, errno);
if (errno != ENOTDIR) { // mount errno is 'Not a directory' can ignore
return -1;
......@@ -404,10 +352,7 @@ static int BindMount(const char *source, const char *target, unsigned long flags
static bool IsValidSandbox(sandbox_t *sandbox)
{
if (sandbox == NULL) {
BEGET_LOGE("preparing sandbox with invalid argument");
return false;
}
BEGET_ERROR_CHECK(sandbox != NULL, return false, "preparing sandbox with invalid argument");
if (sandbox->rootPath == NULL) {
return false;
......@@ -421,17 +366,13 @@ static int MountSandboxInfo(const mountlist_t *mounts, const char *rootPath, San
if (mounts == NULL) {
return 0;
}
if (mounts->info == NULL) {
return 0;
}
BEGET_CHECK(mounts->info != NULL, return 0);
while (mounts != NULL) {
mount_t *mount = mounts->info;
char *source = mount->source;
char target[PATH_MAX] = {};
if (snprintf_s(target, PATH_MAX, PATH_MAX - 1, "%s%s", rootPath, mount->target) < 0) {
BEGET_LOGE("Failed snprintf_s err=%d", errno);
return -1;
}
BEGET_ERROR_CHECK(!(snprintf_s(target, PATH_MAX, PATH_MAX - 1, "%s%s", rootPath, mount->target) < 0),
return -1, "Failed snprintf_s err=%d", errno);
int rc = BindMount(source, target, mount->flags, tag);
BEGET_ERROR_CHECK(rc == 0, return -1, "Failed bind mount %s to %s.", source, target);
mounts = mounts->next;
......@@ -441,19 +382,13 @@ static int MountSandboxInfo(const mountlist_t *mounts, const char *rootPath, San
static int LinkSandboxInfo(const linklist_t *links, const char *rootPath)
{
if (links == NULL) {
return 0;
}
if (links->info == NULL) {
return 0;
}
BEGET_CHECK(links != NULL, return 0);
BEGET_CHECK(links->info != NULL, return 0);
while (links != NULL) {
linker_t *link = links->info;
char linkName[PATH_MAX] = {0};
if (snprintf_s(linkName, PATH_MAX, PATH_MAX - 1, "%s%s", rootPath, link->linkName) < 0) {
BEGET_LOGE("Failed snprintf_s err=%d", errno);
return -1;
}
BEGET_ERROR_CHECK(!(snprintf_s(linkName, PATH_MAX, PATH_MAX - 1, "%s%s", rootPath, link->linkName) < 0),
return -1, "Failed snprintf_s err=%d", errno);
int rc = symlink(link->target, linkName);
if (rc != 0) {
if (errno == EEXIST) {
......@@ -487,20 +422,14 @@ int PrepareSandbox(const char *name)
// 1) walk through all mounts and do bind mount
rc = MountSandboxInfo(sandbox->pathMounts, sandbox->rootPath, SANDBOX_TAG_MOUNT_PATH);
if (rc < 0) {
return -1;
}
BEGET_CHECK(!(rc < 0), return -1);
rc = MountSandboxInfo(sandbox->fileMounts, sandbox->rootPath, SANDBOX_TAG_MOUNT_FILE);
if (rc < 0) {
return -1;
}
BEGET_CHECK(!(rc < 0), return -1);
// 2) walk through all links and do symbol link
rc = LinkSandboxInfo(sandbox->links, sandbox->rootPath);
if (rc < 0) {
return -1;
}
BEGET_CHECK(!(rc < 0), return -1);
BEGET_ERROR_CHECK(chdir(sandbox->rootPath) == 0, return -1, "Change to %s, err = %d", sandbox->rootPath, errno);
BEGET_ERROR_CHECK(syscall(SYS_pivot_root, sandbox->rootPath, sandbox->rootPath) == 0, return -1,
......@@ -606,17 +535,18 @@ void DestroySandbox(const char *name)
}
sandbox_t *sandbox = map->sandbox;
if (sandbox == NULL) {
return;
}
BEGET_CHECK(sandbox != NULL, return);
if (sandbox->rootPath != NULL) {
free(sandbox->rootPath);
sandbox->rootPath = NULL;
}
FreeLinks(sandbox->links);
sandbox->links = NULL;
FreeMounts(sandbox->fileMounts);
sandbox->fileMounts = NULL;
FreeMounts(sandbox->pathMounts);
sandbox->pathMounts = NULL;
if (sandbox->ns > 0) {
(void)close(sandbox->ns);
}
......@@ -637,18 +567,14 @@ int EnterSandbox(const char *name)
}
sandbox_t *sandbox = map->sandbox;
if (sandbox == NULL) {
return -1;
}
BEGET_CHECK(sandbox != NULL, return -1);
if (sandbox->isCreated == false) {
BEGET_LOGE("Sandbox %s has not been created.", name);
return -1;
}
if (sandbox->ns > 0) {
if (SetNamespace(sandbox->ns, CLONE_NEWNS) < 0) {
BEGET_LOGE("Cannot enter mount namespace for sandbox \' %s \', err=%d.", name, errno);
return -1;
}
BEGET_ERROR_CHECK(!(SetNamespace(sandbox->ns, CLONE_NEWNS) < 0), return -1,
"Cannot enter mount namespace for sandbox \' %s \', err=%d.", name, errno);
} else {
BEGET_LOGE("Sandbox \' %s \' namespace fd is invalid.", name);
return -1;
......
......@@ -25,9 +25,7 @@ static int g_defaultNs;
int GetNamespaceFd(const char *nsPath)
{
if (nsPath == NULL) {
return -1;
}
BEGET_CHECK(nsPath != NULL, return -1);
int ns = open(nsPath, O_RDONLY | O_CLOEXEC);
if (ns < 0) {
BEGET_LOGE("Open default namespace failed, err=%d", errno);
......@@ -66,18 +64,14 @@ int SetNamespace(int nsFd, int nsType)
void InitDefaultNamespace(void)
{
if (g_defaultNs > 0) {
(void)close(g_defaultNs);
}
BEGET_CHECK(!(g_defaultNs > 0), (void)close(g_defaultNs));
g_defaultNs = GetNamespaceFd("/proc/self/ns/mnt");
return;
}
int EnterDefaultNamespace(void)
{
if (g_defaultNs < 0) {
return -1;
}
BEGET_CHECK(!(g_defaultNs < 0), return -1);
return SetNamespace(g_defaultNs, CLONE_NEWNS);
}
......
......@@ -310,10 +310,12 @@ void EnterServiceSandbox(Service *service)
}
}
INIT_CHECK_ONLY_ELOG(unsetenv("UV_THREADPOOL_SIZE") == 0, "set UV_THREADPOOL_SIZE error : %d.", errno);
#ifndef STARTUP_INIT_TEST
char *argv[] = { (char *)"/bin/sh", NULL };
INIT_CHECK_ONLY_ELOG(execv(argv[0], argv) == 0,
"service %s execv sh failed! err %d.", service->name, errno);
_exit(PROCESS_EXIT_CODE);
#endif
}
int ServiceStart(Service *service)
......
......@@ -20,6 +20,7 @@
#include "param_trie.h"
#include "securec.h"
#include "param_utils.h"
ParamNode *SystemCheckMatchParamWait(const char *name, const char *value)
{
......@@ -257,7 +258,7 @@ static char *BuildKey(const char *format, ...)
return NULL;
}
static char *GetServiceCtrlName(const char *name, const char *value)
PARAM_STATIC char *GetServiceCtrlName(const char *name, const char *value)
{
static char *ctrlParam[] = {
"ohos.ctl.start",
......
......@@ -30,7 +30,7 @@ config("utest_config") {
ldflags = [ "--coverage" ]
}
ohos_unittest("init_ut") {
ohos_unittest("init_unittest") {
module_out_path = "startup/init"
sources = [
"//base/startup/init_lite/device_info/device_info.cpp",
......@@ -278,7 +278,7 @@ ohos_unittest("init_ut") {
group("init_test") {
testonly = true
deps = [
":init_ut",
":init_unittest",
"//base/startup/init_lite/test/moduletest:paramtestmodule",
]
}
......@@ -153,7 +153,8 @@ HWTEST_F(InitGroupManagerUnitTest, TestHashMap, TestSize.Level1)
TestHashNode *tmp = HASHMAP_ENTRY(node, TestHashNode, node);
EXPECT_EQ(strcmp(tmp->name, act), 0);
}
HashMapTraverse(handle, nullptr, nullptr);
HashMapIsEmpty(handle);
HashMapTraverse(handle, [](const HashNode *node, const void *context) {return;}, nullptr);
HashMapDestory(handle);
}
......@@ -298,7 +299,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestAddService2, TestSize.Level1)
ASSERT_NE(nullptr, fileRoot);
ParseAllServices(fileRoot);
cJSON_Delete(fileRoot);
DumpAllServices();
Service *service = GetServiceByName("test-service6");
ASSERT_NE(service, nullptr);
workspace->groupMode = GROUP_BOOT;
......
......@@ -120,8 +120,8 @@ cJSON *MakeSandboxJson(const char *sandboxFileName, const int MODE)
}
cJSON_AddItemToObject(mJsonMtBdPth_Itm, MOUNT_BIND_PATHS[MOUNT_FLAG_COUNT], mJsonMtBdPthItmSdxFlg);
}
if (MODE != NULL_MOUNT) {
cJSON_AddItemToObject(mJsonMtBdFlItm, SANDBOX_CONFIG[1], cJSON_CreateString("/data/init_ut/testsandboxfile"));
// Append items to mount-bind-files
cJSON_AddItemToArray(mJsonMtBdFl, mJsonMtBdFlItm);
// assemble symbol-links items
......@@ -143,7 +143,7 @@ cJSON *MakeSandboxJson(const char *sandboxFileName, const int MODE)
bool MakeFileByJson(cJSON * mJson, const char *sandboxFileName)
{
const std::string sandboxJsonPth = std::string("/etc/sandbox/") + std::string(sandboxFileName);
const std::string sandboxJsonPth = std::string("/data/init_ut/") + std::string(sandboxFileName);
const char* cSandboxJsonPth = sandboxJsonPth.c_str();
int fd = open(cSandboxJsonPth, O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (fd < 0) {
......
......@@ -273,7 +273,7 @@ HWTEST_F(ServiceUnitTest, TestServiceExec, TestSize.Level1)
service->pathArgs.count = 1;
const char *path = "/data/init_ut/test_service_release";
service->pathArgs.argv[0] = strdup(path);
EnterServiceSandbox(service);
service->importance = 20;
int ret = ServiceExec(service);
EXPECT_EQ(ret, 0);
......
......@@ -71,5 +71,8 @@ HWTEST_F(UtilsUnitTest, TestUtilsApi, TestSize.Level0)
EXPECT_EQ(sec, 1);
EXPECT_EQ(WriteAll(2, "test", strlen("test")), 4);
GetRandom();
mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
CheckAndCreatFile("/data/init_ut/testcreatfile", mode);
CheckAndCreatFile("/data/init_ut/nodir/testcreatfile", mode);
}
} // namespace init_ut
......@@ -30,7 +30,7 @@
extern "C" {
#endif
#endif
int LoadParamFromCmdLine(void);
static int g_testPermissionResult = DAC_RESULT_PERMISSION;
void SetTestPermissionResult(int result)
{
......@@ -338,6 +338,22 @@ static const char *g_triggerData = "{"
"}";
#endif
void PrepareCmdLineHasSn()
{
// for cmdline
const char *cmdLineHasSnroot = "bootgroup=device.charge.group earlycon=uart8250,mmio32,0xfe660000 "
"root=PARTUUID=614e0000-0000 rw rootwait rootfstype=ext4 console=ttyFIQ0 hardware=rk3568"
" BOOT_IMAGE=/kernel ohos.boot.sn=/test init=/init ohos.required_mount.system="
"/dev/block/platform/soc/10100000.himci.eMMC/by-name/misc@none@none@none@wait,required";
CreateTestFile(BOOT_CMD_LINE, cmdLineHasSnroot);
LoadParamFromCmdLine();
const char *cmdLineHasntSn = "bootgroup=device.charge.group earlycon=uart8250,mmio32,0xfe660000 "
"root=PARTUUID=614e0000-0000 rw rootwait rootfstype=ext4 console=ttyFIQ0 hardware=rk3568"
" BOOT_IMAGE=/kernel init=/init ohos.required_mount.system="
"/dev/block/platform/soc/10100000.himci.eMMC/by-name/misc@none@none@none@wait,required";
CreateTestFile(BOOT_CMD_LINE, cmdLineHasntSn);
}
void PrepareInitUnitTestEnv(void)
{
static int evnOk = 0;
......@@ -353,13 +369,7 @@ void PrepareInitUnitTestEnv(void)
EnableInitLog(INIT_DEBUG);
#if !(defined __LITEOS_A__ || defined __LITEOS_M__)
// for cmdline
const char *cmdLine = "bootgroup=device.charge.group earlycon=uart8250,mmio32,0xfe660000 "
"root=PARTUUID=614e0000-0000 rw rootwait rootfstype=ext4 console=ttyFIQ0 hardware=rk3568"
" BOOT_IMAGE=/kernel init=/init "
"/dev/block/platform/soc/10100000.himci.eMMC/by-name/misc@none@none@none@wait,required";
CreateTestFile(BOOT_CMD_LINE, cmdLine);
PrepareCmdLineHasSn();
// for dac
std::string dacData = "ohos.servicectrl. = system:servicectrl:0775 \n";
dacData += "test.permission. = root:root:0770\n";
......
......@@ -27,6 +27,7 @@ using namespace std;
extern "C" {
int WorkSpaceNodeCompare(const HashNode *node1, const HashNode *node2);
char *GetServiceCtrlName(const char *name, const char *value);
}
static void OnClose(ParamTaskPtr client)
......@@ -416,4 +417,10 @@ HWTEST_F(ParamUnitTest, TestLinuxRWLock, TestSize.Level0)
free(workspace1);
free(workspace2);
}
HWTEST_F(ParamUnitTest, TestGetServiceCtlName, TestSize.Level0)
{
EXPECT_STREQ(GetServiceCtrlName("ohos.startup.powerctrl", "reboot,updater"), "ohos.servicectrl.reboot.updater");
EXPECT_STREQ(GetServiceCtrlName("ohos.ctl.stop", "test"), "ohos.servicectrl.test");
EXPECT_STREQ(GetServiceCtrlName("ohos.servicectrl.stop", "test"), "ohos.servicectrl.stop.test");
}
}
......@@ -22,7 +22,9 @@
using namespace testing::ext;
using namespace std;
extern "C" {
void OpenPermissionWorkSpace(void);
}
namespace init_ut {
class SelinuxUnitTest : public ::testing::Test {
public:
......@@ -184,5 +186,6 @@ HWTEST_F(SelinuxUnitTest, TestClientDacCheckParaPermission, TestSize.Level0)
SelinuxUnitTest test;
test.TestClientSelinuxCheckParaPermissionWrite("aaa.bbb.bbb.ccc", "user:group1:r");
test.TestClientSelinuxCheckParaPermissionRead("aaa.bbb.bbb.ccc", "user:group1:r");
OpenPermissionWorkSpace();
}
}
\ No newline at end of file
......@@ -87,6 +87,7 @@ public:
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(IWatcher::GetDescriptor());
data.WriteString(name);
data.WriteString("watcherId");
......
......@@ -47,7 +47,7 @@ hdc_shell_cmd "mount -o remount,rw /"
ut_target_path="/data/init_ut"
echo "Remove ${ut_target_path}"
hdc_shell_cmd "rm -rf ${ut_target_path}"
hdc_shell_cmd "rm /bin/init_ut"
hdc_shell_cmd "rm /bin/init_unittest"
echo "Create ${ut_target_path}"
hdc_shell_cmd "umask 022"
......@@ -80,19 +80,19 @@ hdc_push_cmd ${ohos_root}/base/startup/init_lite/test/unittest/test_data/trigger
sleep 0.2
hdc_push_cmd ${ohos_root}/base/startup/init_lite/test/unittest/test_data/proc/cmdline /data/init_ut/proc/cmdline
sleep 0.25
hdc file send ${ohos_root}/out/rk3568/tests/unittest/startup/init/init_ut /data/init_ut/init_ut
hdc file send ${ohos_root}/out/rk3568/tests/unittest/startup/init/init_unittest /data/init_ut/init_unittest
sleep 0.25
hdc_shell_cmd "cp /data/init_ut/init_ut /bin/init_ut"
hdc_shell_cmd "cp /data/init_ut/init_unittest /bin/init_unittest"
hdc_shell_cmd "chmod 777 /data/init_ut/* -R"
sleep 0.2
hdc_shell_cmd "chmod 777 /bin/init_ut"
hdc_shell_cmd "chmod 777 /bin/init_unittest"
hdc_shell_cmd "export GCOV_PREFIX=${ut_target_path}/coverage&&export GCOV_PREFIX_STRIP=15&&init_ut"
hdc_shell_cmd "export GCOV_PREFIX=${ut_target_path}/coverage&&export GCOV_PREFIX_STRIP=15&&init_unittest"
sleep 0.2
if [ $? -ne 0 ]; then
echo "Execute init_ut in device failed. please check the log"
echo "Execute init_unittest in device failed. please check the log"
fi
echo "Running init unittests end..."
echo "Ready to generate coverage..."
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册